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/led_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/led_matrix.c')
| -rw-r--r-- | quantum/led_matrix.c | 30 |
1 files changed, 16 insertions, 14 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); } |
