diff options
author | XScorpion2 <rcalt2vt@gmail.com> | 2021-06-19 21:03:06 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-19 19:03:06 -0700 |
commit | 5b7cf9fdc86bf92b465565b2be5d501ea9529f37 (patch) | |
tree | 96195d31e1fb0a220024526f787f98a3ece810a7 /quantum/rgb_matrix.c | |
parent | 3c790123ce23638cacc9cade86df25bcf6a981d5 (diff) | |
download | qmk_firmware-5b7cf9fdc86bf92b465565b2be5d501ea9529f37.tar.gz qmk_firmware-5b7cf9fdc86bf92b465565b2be5d501ea9529f37.zip |
RGB Matrix eeprom write limiting (#13238)
Diffstat (limited to 'quantum/rgb_matrix.c')
-rw-r--r-- | quantum/rgb_matrix.c | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index 27f641797..3c5ddba93 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c | |||
@@ -31,6 +31,14 @@ const led_point_t k_rgb_matrix_center = {112, 32}; | |||
31 | const led_point_t k_rgb_matrix_center = RGB_MATRIX_CENTER; | 31 | const led_point_t k_rgb_matrix_center = RGB_MATRIX_CENTER; |
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | // clang-format off | ||
35 | #ifndef RGB_MATRIX_IMMEDIATE_EEPROM | ||
36 | # define rgb_eeconfig_update(v) rgb_update_eeprom |= v | ||
37 | #else | ||
38 | # define rgb_eeconfig_update(v) if (v) eeconfig_update_rgb_matrix() | ||
39 | #endif | ||
40 | // clang-format on | ||
41 | |||
34 | __attribute__((weak)) RGB rgb_matrix_hsv_to_rgb(HSV hsv) { return hsv_to_rgb(hsv); } | 42 | __attribute__((weak)) RGB rgb_matrix_hsv_to_rgb(HSV hsv) { return hsv_to_rgb(hsv); } |
35 | 43 | ||
36 | // Generic effect runners | 44 | // Generic effect runners |
@@ -125,6 +133,7 @@ last_hit_t g_last_hit_tracker; | |||
125 | 133 | ||
126 | // internals | 134 | // internals |
127 | static bool suspend_state = false; | 135 | static bool suspend_state = false; |
136 | static bool rgb_update_eeprom = false; | ||
128 | static uint8_t rgb_last_enable = UINT8_MAX; | 137 | static uint8_t rgb_last_enable = UINT8_MAX; |
129 | static uint8_t rgb_last_effect = UINT8_MAX; | 138 | static uint8_t rgb_last_effect = UINT8_MAX; |
130 | static effect_params_t rgb_effect_params = {0, LED_FLAG_ALL, false}; | 139 | static effect_params_t rgb_effect_params = {0, LED_FLAG_ALL, false}; |
@@ -311,6 +320,7 @@ static void rgb_task_timers(void) { | |||
311 | 320 | ||
312 | static void rgb_task_sync(void) { | 321 | static void rgb_task_sync(void) { |
313 | // next task | 322 | // next task |
323 | if (rgb_update_eeprom) eeconfig_update_rgb_matrix(); | ||
314 | if (sync_timer_elapsed32(g_rgb_timer) >= RGB_MATRIX_LED_FLUSH_LIMIT) rgb_task_state = STARTING; | 324 | if (sync_timer_elapsed32(g_rgb_timer) >= RGB_MATRIX_LED_FLUSH_LIMIT) rgb_task_state = STARTING; |
315 | } | 325 | } |
316 | 326 | ||
@@ -507,9 +517,7 @@ bool rgb_matrix_get_suspend_state(void) { return suspend_state; } | |||
507 | void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) { | 517 | void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) { |
508 | rgb_matrix_config.enable ^= 1; | 518 | rgb_matrix_config.enable ^= 1; |
509 | rgb_task_state = STARTING; | 519 | rgb_task_state = STARTING; |
510 | if (write_to_eeprom) { | 520 | rgb_eeconfig_update(write_to_eeprom); |
511 | eeconfig_update_rgb_matrix(); | ||
512 | } | ||
513 | dprintf("rgb matrix toggle [%s]: rgb_matrix_config.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.enable); | 521 | dprintf("rgb matrix toggle [%s]: rgb_matrix_config.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.enable); |
514 | } | 522 | } |
515 | void rgb_matrix_toggle_noeeprom(void) { rgb_matrix_toggle_eeprom_helper(false); } | 523 | void rgb_matrix_toggle_noeeprom(void) { rgb_matrix_toggle_eeprom_helper(false); } |
@@ -517,7 +525,7 @@ void rgb_matrix_toggle(void) { rgb_matrix_toggle_eeprom_helper(true); } | |||
517 | 525 | ||
518 | void rgb_matrix_enable(void) { | 526 | void rgb_matrix_enable(void) { |
519 | rgb_matrix_enable_noeeprom(); | 527 | rgb_matrix_enable_noeeprom(); |
520 | eeconfig_update_rgb_matrix(); | 528 | rgb_eeconfig_update(true); |
521 | } | 529 | } |
522 | 530 | ||
523 | void rgb_matrix_enable_noeeprom(void) { | 531 | void rgb_matrix_enable_noeeprom(void) { |
@@ -527,7 +535,7 @@ void rgb_matrix_enable_noeeprom(void) { | |||
527 | 535 | ||
528 | void rgb_matrix_disable(void) { | 536 | void rgb_matrix_disable(void) { |
529 | rgb_matrix_disable_noeeprom(); | 537 | rgb_matrix_disable_noeeprom(); |
530 | eeconfig_update_rgb_matrix(); | 538 | rgb_eeconfig_update(true); |
531 | } | 539 | } |
532 | 540 | ||
533 | void rgb_matrix_disable_noeeprom(void) { | 541 | void rgb_matrix_disable_noeeprom(void) { |
@@ -549,9 +557,7 @@ void rgb_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { | |||
549 | rgb_matrix_config.mode = mode; | 557 | rgb_matrix_config.mode = mode; |
550 | } | 558 | } |
551 | rgb_task_state = STARTING; | 559 | rgb_task_state = STARTING; |
552 | if (write_to_eeprom) { | 560 | rgb_eeconfig_update(write_to_eeprom); |
553 | eeconfig_update_rgb_matrix(); | ||
554 | } | ||
555 | dprintf("rgb matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.mode); | 561 | dprintf("rgb matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.mode); |
556 | } | 562 | } |
557 | void rgb_matrix_mode_noeeprom(uint8_t mode) { rgb_matrix_mode_eeprom_helper(mode, false); } | 563 | void rgb_matrix_mode_noeeprom(uint8_t mode) { rgb_matrix_mode_eeprom_helper(mode, false); } |
@@ -580,9 +586,7 @@ void rgb_matrix_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, boo | |||
580 | rgb_matrix_config.hsv.h = hue; | 586 | rgb_matrix_config.hsv.h = hue; |
581 | rgb_matrix_config.hsv.s = sat; | 587 | rgb_matrix_config.hsv.s = sat; |
582 | rgb_matrix_config.hsv.v = (val > RGB_MATRIX_MAXIMUM_BRIGHTNESS) ? RGB_MATRIX_MAXIMUM_BRIGHTNESS : val; | 588 | rgb_matrix_config.hsv.v = (val > RGB_MATRIX_MAXIMUM_BRIGHTNESS) ? RGB_MATRIX_MAXIMUM_BRIGHTNESS : val; |
583 | if (write_to_eeprom) { | 589 | rgb_eeconfig_update(write_to_eeprom); |
584 | eeconfig_update_rgb_matrix(); | ||
585 | } | ||
586 | 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); | 590 | 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); |
587 | } | 591 | } |
588 | void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { rgb_matrix_sethsv_eeprom_helper(hue, sat, val, false); } | 592 | void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { rgb_matrix_sethsv_eeprom_helper(hue, sat, val, false); } |
@@ -619,9 +623,7 @@ void rgb_matrix_decrease_val(void) { rgb_matrix_decrease_val_helper(true); } | |||
619 | 623 | ||
620 | void rgb_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { | 624 | void rgb_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { |
621 | rgb_matrix_config.speed = speed; | 625 | rgb_matrix_config.speed = speed; |
622 | if (write_to_eeprom) { | 626 | rgb_eeconfig_update(write_to_eeprom); |
623 | eeconfig_update_rgb_matrix(); | ||
624 | } | ||
625 | dprintf("rgb matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.speed); | 627 | dprintf("rgb matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.speed); |
626 | } | 628 | } |
627 | void rgb_matrix_set_speed_noeeprom(uint8_t speed) { rgb_matrix_set_speed_eeprom_helper(speed, false); } | 629 | void rgb_matrix_set_speed_noeeprom(uint8_t speed) { rgb_matrix_set_speed_eeprom_helper(speed, false); } |