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 | |
parent | 3c790123ce23638cacc9cade86df25bcf6a981d5 (diff) | |
download | qmk_firmware-5b7cf9fdc86bf92b465565b2be5d501ea9529f37.tar.gz qmk_firmware-5b7cf9fdc86bf92b465565b2be5d501ea9529f37.zip |
RGB Matrix eeprom write limiting (#13238)
Diffstat (limited to 'quantum')
-rw-r--r-- | quantum/led_matrix.c | 30 | ||||
-rw-r--r-- | quantum/rgb_matrix.c | 30 |
2 files changed, 32 insertions, 28 deletions
diff --git a/quantum/led_matrix.c b/quantum/led_matrix.c index 942e6d7dc..e7e933e1d 100644 --- a/quantum/led_matrix.c +++ b/quantum/led_matrix.c | |||
@@ -33,6 +33,14 @@ const led_point_t k_led_matrix_center = {112, 32}; | |||
33 | const led_point_t k_led_matrix_center = LED_MATRIX_CENTER; | 33 | const led_point_t k_led_matrix_center = LED_MATRIX_CENTER; |
34 | #endif | 34 | #endif |
35 | 35 | ||
36 | // clang-format off | ||
37 | #ifndef LED_MATRIX_IMMEDIATE_EEPROM | ||
38 | # define led_eeconfig_update(v) led_update_eeprom |= v | ||
39 | #else | ||
40 | # define led_eeconfig_update(v) if (v) eeconfig_update_led_matrix() | ||
41 | #endif | ||
42 | // clang-format on | ||
43 | |||
36 | // Generic effect runners | 44 | // Generic effect runners |
37 | #include "led_matrix_runners/effect_runner_dx_dy_dist.h" | 45 | #include "led_matrix_runners/effect_runner_dx_dy_dist.h" |
38 | #include "led_matrix_runners/effect_runner_dx_dy.h" | 46 | #include "led_matrix_runners/effect_runner_dx_dy.h" |
@@ -104,6 +112,7 @@ last_hit_t g_last_hit_tracker; | |||
104 | 112 | ||
105 | // internals | 113 | // internals |
106 | static bool suspend_state = false; | 114 | static bool suspend_state = false; |
115 | static bool led_update_eeprom = false; | ||
107 | static uint8_t led_last_enable = UINT8_MAX; | 116 | static uint8_t led_last_enable = UINT8_MAX; |
108 | static uint8_t led_last_effect = UINT8_MAX; | 117 | static uint8_t led_last_effect = UINT8_MAX; |
109 | static effect_params_t led_effect_params = {0, LED_FLAG_ALL, false}; | 118 | static effect_params_t led_effect_params = {0, LED_FLAG_ALL, false}; |
@@ -276,6 +285,7 @@ static void led_task_timers(void) { | |||
276 | 285 | ||
277 | static void led_task_sync(void) { | 286 | static void led_task_sync(void) { |
278 | // next task | 287 | // next task |
288 | if (led_update_eeprom) eeconfig_update_led_matrix(); | ||
279 | if (sync_timer_elapsed32(g_led_timer) >= LED_MATRIX_LED_FLUSH_LIMIT) led_task_state = STARTING; | 289 | if (sync_timer_elapsed32(g_led_timer) >= LED_MATRIX_LED_FLUSH_LIMIT) led_task_state = STARTING; |
280 | } | 290 | } |
281 | 291 | ||
@@ -465,9 +475,7 @@ bool led_matrix_get_suspend_state(void) { return suspend_state; } | |||
465 | void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) { | 475 | void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) { |
466 | led_matrix_eeconfig.enable ^= 1; | 476 | led_matrix_eeconfig.enable ^= 1; |
467 | led_task_state = STARTING; | 477 | led_task_state = STARTING; |
468 | if (write_to_eeprom) { | 478 | led_eeconfig_update(write_to_eeprom); |
469 | eeconfig_update_led_matrix(); | ||
470 | } | ||
471 | dprintf("led matrix toggle [%s]: led_matrix_eeconfig.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.enable); | 479 | dprintf("led matrix toggle [%s]: led_matrix_eeconfig.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.enable); |
472 | } | 480 | } |
473 | void led_matrix_toggle_noeeprom(void) { led_matrix_toggle_eeprom_helper(false); } | 481 | void led_matrix_toggle_noeeprom(void) { led_matrix_toggle_eeprom_helper(false); } |
@@ -475,7 +483,7 @@ void led_matrix_toggle(void) { led_matrix_toggle_eeprom_helper(true); } | |||
475 | 483 | ||
476 | void led_matrix_enable(void) { | 484 | void led_matrix_enable(void) { |
477 | led_matrix_enable_noeeprom(); | 485 | led_matrix_enable_noeeprom(); |
478 | eeconfig_update_led_matrix(); | 486 | led_eeconfig_update(true); |
479 | } | 487 | } |
480 | 488 | ||
481 | void led_matrix_enable_noeeprom(void) { | 489 | void led_matrix_enable_noeeprom(void) { |
@@ -485,7 +493,7 @@ void led_matrix_enable_noeeprom(void) { | |||
485 | 493 | ||
486 | void led_matrix_disable(void) { | 494 | void led_matrix_disable(void) { |
487 | led_matrix_disable_noeeprom(); | 495 | led_matrix_disable_noeeprom(); |
488 | eeconfig_update_led_matrix(); | 496 | led_eeconfig_update(true); |
489 | } | 497 | } |
490 | 498 | ||
491 | void led_matrix_disable_noeeprom(void) { | 499 | void led_matrix_disable_noeeprom(void) { |
@@ -507,9 +515,7 @@ void led_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { | |||
507 | led_matrix_eeconfig.mode = mode; | 515 | led_matrix_eeconfig.mode = mode; |
508 | } | 516 | } |
509 | led_task_state = STARTING; | 517 | led_task_state = STARTING; |
510 | if (write_to_eeprom) { | 518 | led_eeconfig_update(write_to_eeprom); |
511 | eeconfig_update_led_matrix(); | ||
512 | } | ||
513 | dprintf("led matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.mode); | 519 | dprintf("led matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.mode); |
514 | } | 520 | } |
515 | void led_matrix_mode_noeeprom(uint8_t mode) { led_matrix_mode_eeprom_helper(mode, false); } | 521 | void led_matrix_mode_noeeprom(uint8_t mode) { led_matrix_mode_eeprom_helper(mode, false); } |
@@ -536,9 +542,7 @@ void led_matrix_set_val_eeprom_helper(uint8_t val, bool write_to_eeprom) { | |||
536 | return; | 542 | return; |
537 | } | 543 | } |
538 | led_matrix_eeconfig.val = (val > LED_MATRIX_MAXIMUM_BRIGHTNESS) ? LED_MATRIX_MAXIMUM_BRIGHTNESS : val; | 544 | led_matrix_eeconfig.val = (val > LED_MATRIX_MAXIMUM_BRIGHTNESS) ? LED_MATRIX_MAXIMUM_BRIGHTNESS : val; |
539 | if (write_to_eeprom) { | 545 | led_eeconfig_update(write_to_eeprom); |
540 | eeconfig_update_led_matrix(); | ||
541 | } | ||
542 | dprintf("led matrix set val [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.val); | 546 | dprintf("led matrix set val [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.val); |
543 | } | 547 | } |
544 | void led_matrix_set_val_noeeprom(uint8_t val) { led_matrix_set_val_eeprom_helper(val, false); } | 548 | void led_matrix_set_val_noeeprom(uint8_t val) { led_matrix_set_val_eeprom_helper(val, false); } |
@@ -556,9 +560,7 @@ void led_matrix_decrease_val(void) { led_matrix_decrease_val_helper(true); } | |||
556 | 560 | ||
557 | void led_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { | 561 | void led_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { |
558 | led_matrix_eeconfig.speed = speed; | 562 | led_matrix_eeconfig.speed = speed; |
559 | if (write_to_eeprom) { | 563 | led_eeconfig_update(write_to_eeprom); |
560 | eeconfig_update_led_matrix(); | ||
561 | } | ||
562 | dprintf("led matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.speed); | 564 | dprintf("led matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.speed); |
563 | } | 565 | } |
564 | void led_matrix_set_speed_noeeprom(uint8_t speed) { led_matrix_set_speed_eeprom_helper(speed, false); } | 566 | void led_matrix_set_speed_noeeprom(uint8_t speed) { led_matrix_set_speed_eeprom_helper(speed, false); } |
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); } |