diff options
author | Tynan Beatty <38031130+tynanbe@users.noreply.github.com> | 2020-08-07 16:43:57 -0500 |
---|---|---|
committer | James Young <18669334+noroadsleft@users.noreply.github.com> | 2020-08-29 14:30:02 -0700 |
commit | e34eca361fdd9ff61b8827fec545202da179648c (patch) | |
tree | c8581b9d1b379f6d9703dd4e6a4597f8b3cf0c8d /quantum/rgb_matrix.c | |
parent | c990dc1e6cdcabbfe280d60e981f9e7cc733d5db (diff) | |
download | qmk_firmware-e34eca361fdd9ff61b8827fec545202da179648c.tar.gz qmk_firmware-e34eca361fdd9ff61b8827fec545202da179648c.zip |
Noeeprom functions for rgb_matrix (#9487)
* Add eeprom_helpers for toggle, mode, sethsv, speed; add set_speed; add noeeprom versions of toggle, step, hue, sat, val, and speed
* qmk cformat rgb_matrix
* Add rgb_matrix_set_speed and *_noeeprom functions
* Do not expose rgb_matrix_*_eeprom_helper functions
Diffstat (limited to 'quantum/rgb_matrix.c')
-rw-r--r-- | quantum/rgb_matrix.c | 155 |
1 files changed, 88 insertions, 67 deletions
diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index 615b4b0a7..802c5afce 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c | |||
@@ -155,7 +155,7 @@ void eeconfig_update_rgb_matrix_default(void) { | |||
155 | } | 155 | } |
156 | 156 | ||
157 | void eeconfig_debug_rgb_matrix(void) { | 157 | void eeconfig_debug_rgb_matrix(void) { |
158 | dprintf("rgb_matrix_config eprom\n"); | 158 | dprintf("rgb_matrix_config EEPROM\n"); |
159 | dprintf("rgb_matrix_config.enable = %d\n", rgb_matrix_config.enable); | 159 | dprintf("rgb_matrix_config.enable = %d\n", rgb_matrix_config.enable); |
160 | dprintf("rgb_matrix_config.mode = %d\n", rgb_matrix_config.mode); | 160 | dprintf("rgb_matrix_config.mode = %d\n", rgb_matrix_config.mode); |
161 | dprintf("rgb_matrix_config.hsv.h = %d\n", rgb_matrix_config.hsv.h); | 161 | dprintf("rgb_matrix_config.hsv.h = %d\n", rgb_matrix_config.hsv.h); |
@@ -462,11 +462,16 @@ void rgb_matrix_set_suspend_state(bool state) { | |||
462 | 462 | ||
463 | bool rgb_matrix_get_suspend_state(void) { return g_suspend_state; } | 463 | bool rgb_matrix_get_suspend_state(void) { return g_suspend_state; } |
464 | 464 | ||
465 | void rgb_matrix_toggle(void) { | 465 | void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) { |
466 | rgb_matrix_config.enable ^= 1; | 466 | rgb_matrix_config.enable ^= 1; |
467 | rgb_task_state = STARTING; | 467 | rgb_task_state = STARTING; |
468 | eeconfig_update_rgb_matrix(); | 468 | if (write_to_eeprom) { |
469 | eeconfig_update_rgb_matrix(); | ||
470 | } | ||
471 | dprintf("rgb matrix toggle [%s]: rgb_matrix_config.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.enable); | ||
469 | } | 472 | } |
473 | void rgb_matrix_toggle_noeeprom(void) { rgb_matrix_toggle_eeprom_helper(false); } | ||
474 | void rgb_matrix_toggle(void) { rgb_matrix_toggle_eeprom_helper(true); } | ||
470 | 475 | ||
471 | void rgb_matrix_enable(void) { | 476 | void rgb_matrix_enable(void) { |
472 | rgb_matrix_enable_noeeprom(); | 477 | rgb_matrix_enable_noeeprom(); |
@@ -490,90 +495,106 @@ void rgb_matrix_disable_noeeprom(void) { | |||
490 | 495 | ||
491 | uint8_t rgb_matrix_is_enabled(void) { return rgb_matrix_config.enable; } | 496 | uint8_t rgb_matrix_is_enabled(void) { return rgb_matrix_config.enable; } |
492 | 497 | ||
493 | void rgb_matrix_step(void) { | 498 | void rgb_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { |
494 | rgb_matrix_config.mode++; | 499 | if (!rgb_matrix_config.enable) { |
495 | if (rgb_matrix_config.mode >= RGB_MATRIX_EFFECT_MAX) rgb_matrix_config.mode = 1; | 500 | return; |
501 | } | ||
502 | if (mode < 1) { | ||
503 | rgb_matrix_config.mode = 1; | ||
504 | } else if (mode >= RGB_MATRIX_EFFECT_MAX) { | ||
505 | rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1; | ||
506 | } else { | ||
507 | rgb_matrix_config.mode = mode; | ||
508 | } | ||
496 | rgb_task_state = STARTING; | 509 | rgb_task_state = STARTING; |
497 | eeconfig_update_rgb_matrix(); | 510 | if (write_to_eeprom) { |
511 | eeconfig_update_rgb_matrix(); | ||
512 | } | ||
513 | dprintf("rgb matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.mode); | ||
498 | } | 514 | } |
515 | void rgb_matrix_mode_noeeprom(uint8_t mode) { rgb_matrix_mode_eeprom_helper(mode, false); } | ||
516 | void rgb_matrix_mode(uint8_t mode) { rgb_matrix_mode_eeprom_helper(mode, true); } | ||
499 | 517 | ||
500 | void rgb_matrix_step_reverse(void) { | 518 | uint8_t rgb_matrix_get_mode(void) { return rgb_matrix_config.mode; } |
501 | rgb_matrix_config.mode--; | ||
502 | if (rgb_matrix_config.mode < 1) rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1; | ||
503 | rgb_task_state = STARTING; | ||
504 | eeconfig_update_rgb_matrix(); | ||
505 | } | ||
506 | 519 | ||
507 | void rgb_matrix_increase_hue(void) { | 520 | void rgb_matrix_step_helper(bool write_to_eeprom) { |
508 | rgb_matrix_config.hsv.h += RGB_MATRIX_HUE_STEP; | 521 | uint8_t mode = rgb_matrix_config.mode + 1; |
509 | eeconfig_update_rgb_matrix(); | 522 | rgb_matrix_mode_eeprom_helper((mode < RGB_MATRIX_EFFECT_MAX) ? mode : 1, write_to_eeprom); |
510 | } | 523 | } |
524 | void rgb_matrix_step_noeeprom(void) { rgb_matrix_step_helper(false); } | ||
525 | void rgb_matrix_step(void) { rgb_matrix_step_helper(true); } | ||
511 | 526 | ||
512 | void rgb_matrix_decrease_hue(void) { | 527 | void rgb_matrix_step_reverse_helper(bool write_to_eeprom) { |
513 | rgb_matrix_config.hsv.h -= RGB_MATRIX_HUE_STEP; | 528 | uint8_t mode = rgb_matrix_config.mode - 1; |
514 | eeconfig_update_rgb_matrix(); | 529 | rgb_matrix_mode_eeprom_helper((mode < 1) ? RGB_MATRIX_EFFECT_MAX - 1 : mode, write_to_eeprom); |
515 | } | 530 | } |
531 | void rgb_matrix_step_reverse_noeeprom(void) { rgb_matrix_step_reverse_helper(false); } | ||
532 | void rgb_matrix_step_reverse(void) { rgb_matrix_step_reverse_helper(true); } | ||
516 | 533 | ||
517 | void rgb_matrix_increase_sat(void) { | 534 | void rgb_matrix_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom) { |
518 | rgb_matrix_config.hsv.s = qadd8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP); | 535 | if (!rgb_matrix_config.enable) { |
519 | eeconfig_update_rgb_matrix(); | 536 | return; |
520 | } | 537 | } |
521 | 538 | rgb_matrix_config.hsv.h = hue; | |
522 | void rgb_matrix_decrease_sat(void) { | 539 | rgb_matrix_config.hsv.s = sat; |
523 | rgb_matrix_config.hsv.s = qsub8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP); | 540 | rgb_matrix_config.hsv.v = (val > RGB_MATRIX_MAXIMUM_BRIGHTNESS) ? RGB_MATRIX_MAXIMUM_BRIGHTNESS : val; |
524 | eeconfig_update_rgb_matrix(); | 541 | if (write_to_eeprom) { |
542 | eeconfig_update_rgb_matrix(); | ||
543 | } | ||
544 | dprintf("rgb matrix set hsv [%s]: %u,%u,%u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v); | ||
525 | } | 545 | } |
546 | void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { rgb_matrix_sethsv_eeprom_helper(hue, sat, val, false); } | ||
547 | void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val) { rgb_matrix_sethsv_eeprom_helper(hue, sat, val, true); } | ||
526 | 548 | ||
527 | void rgb_matrix_increase_val(void) { | 549 | HSV rgb_matrix_get_hsv(void) { return rgb_matrix_config.hsv; } |
528 | rgb_matrix_config.hsv.v = qadd8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP); | 550 | uint8_t rgb_matrix_get_hue(void) { return rgb_matrix_config.hsv.h; } |
529 | if (rgb_matrix_config.hsv.v > RGB_MATRIX_MAXIMUM_BRIGHTNESS) rgb_matrix_config.hsv.v = RGB_MATRIX_MAXIMUM_BRIGHTNESS; | 551 | uint8_t rgb_matrix_get_sat(void) { return rgb_matrix_config.hsv.s; } |
530 | eeconfig_update_rgb_matrix(); | 552 | uint8_t rgb_matrix_get_val(void) { return rgb_matrix_config.hsv.v; } |
531 | } | ||
532 | 553 | ||
533 | void rgb_matrix_decrease_val(void) { | 554 | void rgb_matrix_increase_hue_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h + RGB_MATRIX_HUE_STEP, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v, write_to_eeprom); } |
534 | rgb_matrix_config.hsv.v = qsub8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP); | 555 | void rgb_matrix_increase_hue_noeeprom(void) { rgb_matrix_increase_hue_helper(false); } |
535 | eeconfig_update_rgb_matrix(); | 556 | void rgb_matrix_increase_hue(void) { rgb_matrix_increase_hue_helper(true); } |
536 | } | ||
537 | 557 | ||
538 | void rgb_matrix_increase_speed(void) { | 558 | void rgb_matrix_decrease_hue_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h - RGB_MATRIX_HUE_STEP, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v, write_to_eeprom); } |
539 | rgb_matrix_config.speed = qadd8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP); | 559 | void rgb_matrix_decrease_hue_noeeprom(void) { rgb_matrix_decrease_hue_helper(false); } |
540 | eeconfig_update_rgb_matrix(); | 560 | void rgb_matrix_decrease_hue(void) { rgb_matrix_decrease_hue_helper(true); } |
541 | } | ||
542 | 561 | ||
543 | void rgb_matrix_decrease_speed(void) { | 562 | void rgb_matrix_increase_sat_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, qadd8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP), rgb_matrix_config.hsv.v, write_to_eeprom); } |
544 | rgb_matrix_config.speed = qsub8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP); | 563 | void rgb_matrix_increase_sat_noeeprom(void) { rgb_matrix_increase_sat_helper(false); } |
545 | eeconfig_update_rgb_matrix(); | 564 | void rgb_matrix_increase_sat(void) { rgb_matrix_increase_sat_helper(true); } |
546 | } | ||
547 | 565 | ||
548 | uint8_t rgb_matrix_get_speed(void) { return rgb_matrix_config.speed; } | 566 | void rgb_matrix_decrease_sat_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, qsub8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP), rgb_matrix_config.hsv.v, write_to_eeprom); } |
567 | void rgb_matrix_decrease_sat_noeeprom(void) { rgb_matrix_decrease_sat_helper(false); } | ||
568 | void rgb_matrix_decrease_sat(void) { rgb_matrix_decrease_sat_helper(true); } | ||
549 | 569 | ||
550 | led_flags_t rgb_matrix_get_flags(void) { return rgb_effect_params.flags; } | 570 | void rgb_matrix_increase_val_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, qadd8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP), write_to_eeprom); } |
571 | void rgb_matrix_increase_val_noeeprom(void) { rgb_matrix_increase_val_helper(false); } | ||
572 | void rgb_matrix_increase_val(void) { rgb_matrix_increase_val_helper(true); } | ||
551 | 573 | ||
552 | void rgb_matrix_set_flags(led_flags_t flags) { rgb_effect_params.flags = flags; } | 574 | void rgb_matrix_decrease_val_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, qsub8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP), write_to_eeprom); } |
575 | void rgb_matrix_decrease_val_noeeprom(void) { rgb_matrix_decrease_val_helper(false); } | ||
576 | void rgb_matrix_decrease_val(void) { rgb_matrix_decrease_val_helper(true); } | ||
553 | 577 | ||
554 | void rgb_matrix_mode(uint8_t mode) { | 578 | void rgb_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { |
555 | rgb_matrix_config.mode = mode; | 579 | rgb_matrix_config.speed = speed; |
556 | rgb_task_state = STARTING; | 580 | if (write_to_eeprom) { |
557 | eeconfig_update_rgb_matrix(); | 581 | eeconfig_update_rgb_matrix(); |
582 | } | ||
583 | dprintf("rgb matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.speed); | ||
558 | } | 584 | } |
585 | void rgb_matrix_set_speed_noeeprom(uint8_t speed) { rgb_matrix_set_speed_eeprom_helper(speed, false); } | ||
586 | void rgb_matrix_set_speed(uint8_t speed) { rgb_matrix_set_speed_eeprom_helper(speed, true); } | ||
559 | 587 | ||
560 | void rgb_matrix_mode_noeeprom(uint8_t mode) { rgb_matrix_config.mode = mode; } | 588 | uint8_t rgb_matrix_get_speed(void) { return rgb_matrix_config.speed; } |
561 | 589 | ||
562 | uint8_t rgb_matrix_get_mode(void) { return rgb_matrix_config.mode; } | 590 | void rgb_matrix_increase_speed_helper(bool write_to_eeprom) { rgb_matrix_set_speed_eeprom_helper(qadd8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP), write_to_eeprom); } |
591 | void rgb_matrix_increase_speed_noeeprom(void) { rgb_matrix_increase_speed_helper(false); } | ||
592 | void rgb_matrix_increase_speed(void) { rgb_matrix_increase_speed_helper(true); } | ||
563 | 593 | ||
564 | void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val) { | 594 | void rgb_matrix_decrease_speed_helper(bool write_to_eeprom) { rgb_matrix_set_speed_eeprom_helper(qsub8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP), write_to_eeprom); } |
565 | rgb_matrix_sethsv_noeeprom(hue, sat, val); | 595 | void rgb_matrix_decrease_speed_noeeprom(void) { rgb_matrix_decrease_speed_helper(false); } |
566 | eeconfig_update_rgb_matrix(); | 596 | void rgb_matrix_decrease_speed(void) { rgb_matrix_decrease_speed_helper(true); } |
567 | } | ||
568 | 597 | ||
569 | void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { | 598 | led_flags_t rgb_matrix_get_flags(void) { return rgb_effect_params.flags; } |
570 | rgb_matrix_config.hsv.h = hue; | ||
571 | rgb_matrix_config.hsv.s = sat; | ||
572 | rgb_matrix_config.hsv.v = val; | ||
573 | if (rgb_matrix_config.hsv.v > RGB_MATRIX_MAXIMUM_BRIGHTNESS) rgb_matrix_config.hsv.v = RGB_MATRIX_MAXIMUM_BRIGHTNESS; | ||
574 | } | ||
575 | 599 | ||
576 | HSV rgb_matrix_get_hsv(void) { return rgb_matrix_config.hsv; } | 600 | void rgb_matrix_set_flags(led_flags_t flags) { rgb_effect_params.flags = flags; } |
577 | uint8_t rgb_matrix_get_hue(void) { return rgb_matrix_config.hsv.h; } | ||
578 | uint8_t rgb_matrix_get_sat(void) { return rgb_matrix_config.hsv.s; } | ||
579 | uint8_t rgb_matrix_get_val(void) { return rgb_matrix_config.hsv.v; } | ||