diff options
Diffstat (limited to 'quantum/led_matrix/led_matrix.c')
| -rw-r--r-- | quantum/led_matrix/led_matrix.c | 46 |
1 files changed, 13 insertions, 33 deletions
diff --git a/quantum/led_matrix/led_matrix.c b/quantum/led_matrix/led_matrix.c index 50510e49a..8d6a56f27 100644 --- a/quantum/led_matrix/led_matrix.c +++ b/quantum/led_matrix/led_matrix.c | |||
| @@ -33,14 +33,6 @@ 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 | |||
| 44 | // Generic effect runners | 36 | // Generic effect runners |
| 45 | #include "led_matrix_runners.inc" | 37 | #include "led_matrix_runners.inc" |
| 46 | 38 | ||
| @@ -107,7 +99,6 @@ last_hit_t g_last_hit_tracker; | |||
| 107 | 99 | ||
| 108 | // internals | 100 | // internals |
| 109 | static bool suspend_state = false; | 101 | static bool suspend_state = false; |
| 110 | static bool led_update_eeprom = false; | ||
| 111 | static uint8_t led_last_enable = UINT8_MAX; | 102 | static uint8_t led_last_enable = UINT8_MAX; |
| 112 | static uint8_t led_last_effect = UINT8_MAX; | 103 | static uint8_t led_last_effect = UINT8_MAX; |
| 113 | static effect_params_t led_effect_params = {0, LED_FLAG_ALL, false}; | 104 | static effect_params_t led_effect_params = {0, LED_FLAG_ALL, false}; |
| @@ -127,9 +118,9 @@ static last_hit_t last_hit_buffer; | |||
| 127 | const uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT; | 118 | const uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT; |
| 128 | #endif | 119 | #endif |
| 129 | 120 | ||
| 130 | void eeconfig_read_led_matrix(void) { eeprom_read_block(&led_matrix_eeconfig, EECONFIG_LED_MATRIX, sizeof(led_matrix_eeconfig)); } | 121 | EECONFIG_DEBOUNCE_HELPER(led_matrix, EECONFIG_LED_MATRIX, led_matrix_eeconfig); |
| 131 | 122 | ||
| 132 | void eeconfig_update_led_matrix(void) { eeprom_update_block(&led_matrix_eeconfig, EECONFIG_LED_MATRIX, sizeof(led_matrix_eeconfig)); } | 123 | void eeconfig_update_led_matrix(void) { eeconfig_flush_led_matrix(true); } |
| 133 | 124 | ||
| 134 | void eeconfig_update_led_matrix_default(void) { | 125 | void eeconfig_update_led_matrix_default(void) { |
| 135 | dprintf("eeconfig_update_led_matrix_default\n"); | 126 | dprintf("eeconfig_update_led_matrix_default\n"); |
| @@ -138,7 +129,7 @@ void eeconfig_update_led_matrix_default(void) { | |||
| 138 | led_matrix_eeconfig.val = LED_MATRIX_STARTUP_VAL; | 129 | led_matrix_eeconfig.val = LED_MATRIX_STARTUP_VAL; |
| 139 | led_matrix_eeconfig.speed = LED_MATRIX_STARTUP_SPD; | 130 | led_matrix_eeconfig.speed = LED_MATRIX_STARTUP_SPD; |
| 140 | led_matrix_eeconfig.flags = LED_FLAG_ALL; | 131 | led_matrix_eeconfig.flags = LED_FLAG_ALL; |
| 141 | eeconfig_update_led_matrix(); | 132 | eeconfig_flush_led_matrix(true); |
| 142 | } | 133 | } |
| 143 | 134 | ||
| 144 | void eeconfig_debug_led_matrix(void) { | 135 | void eeconfig_debug_led_matrix(void) { |
| @@ -165,20 +156,10 @@ uint8_t led_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *l | |||
| 165 | void led_matrix_update_pwm_buffers(void) { led_matrix_driver.flush(); } | 156 | void led_matrix_update_pwm_buffers(void) { led_matrix_driver.flush(); } |
| 166 | 157 | ||
| 167 | void led_matrix_set_value(int index, uint8_t value) { | 158 | void led_matrix_set_value(int index, uint8_t value) { |
| 168 | #if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) | ||
| 169 | if (!is_keyboard_left() && index >= k_led_matrix_split[0]) | ||
| 170 | # ifdef USE_CIE1931_CURVE | ||
| 171 | led_matrix_driver.set_value(index - k_led_matrix_split[0], pgm_read_byte(&CIE1931_CURVE[value])); | ||
| 172 | # else | ||
| 173 | led_matrix_driver.set_value(index - k_led_matrix_split[0], value); | ||
| 174 | # endif | ||
| 175 | else if (is_keyboard_left() && index < k_led_matrix_split[0]) | ||
| 176 | #endif | ||
| 177 | #ifdef USE_CIE1931_CURVE | 159 | #ifdef USE_CIE1931_CURVE |
| 178 | led_matrix_driver.set_value(index, pgm_read_byte(&CIE1931_CURVE[value])); | 160 | value = pgm_read_byte(&CIE1931_CURVE[value]); |
| 179 | #else | ||
| 180 | led_matrix_driver.set_value(index, value); | ||
| 181 | #endif | 161 | #endif |
| 162 | led_matrix_driver.set_value(index, value); | ||
| 182 | } | 163 | } |
| 183 | 164 | ||
| 184 | void led_matrix_set_value_all(uint8_t value) { | 165 | void led_matrix_set_value_all(uint8_t value) { |
| @@ -279,9 +260,8 @@ static void led_task_timers(void) { | |||
| 279 | } | 260 | } |
| 280 | 261 | ||
| 281 | static void led_task_sync(void) { | 262 | static void led_task_sync(void) { |
| 263 | eeconfig_flush_led_matrix(false); | ||
| 282 | // next task | 264 | // next task |
| 283 | if (led_update_eeprom) eeconfig_update_led_matrix(); | ||
| 284 | led_update_eeprom = false; | ||
| 285 | if (sync_timer_elapsed32(g_led_timer) >= LED_MATRIX_LED_FLUSH_LIMIT) led_task_state = STARTING; | 265 | if (sync_timer_elapsed32(g_led_timer) >= LED_MATRIX_LED_FLUSH_LIMIT) led_task_state = STARTING; |
| 286 | } | 266 | } |
| 287 | 267 | ||
| @@ -449,7 +429,7 @@ void led_matrix_init(void) { | |||
| 449 | eeconfig_update_led_matrix_default(); | 429 | eeconfig_update_led_matrix_default(); |
| 450 | } | 430 | } |
| 451 | 431 | ||
| 452 | eeconfig_read_led_matrix(); | 432 | eeconfig_init_led_matrix(); |
| 453 | if (!led_matrix_eeconfig.mode) { | 433 | if (!led_matrix_eeconfig.mode) { |
| 454 | dprintf("led_matrix_init_drivers led_matrix_eeconfig.mode = 0. Write default values to EEPROM.\n"); | 434 | dprintf("led_matrix_init_drivers led_matrix_eeconfig.mode = 0. Write default values to EEPROM.\n"); |
| 455 | eeconfig_update_led_matrix_default(); | 435 | eeconfig_update_led_matrix_default(); |
| @@ -472,7 +452,7 @@ bool led_matrix_get_suspend_state(void) { return suspend_state; } | |||
| 472 | void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) { | 452 | void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) { |
| 473 | led_matrix_eeconfig.enable ^= 1; | 453 | led_matrix_eeconfig.enable ^= 1; |
| 474 | led_task_state = STARTING; | 454 | led_task_state = STARTING; |
| 475 | led_eeconfig_update(write_to_eeprom); | 455 | eeconfig_flag_led_matrix(write_to_eeprom); |
| 476 | dprintf("led matrix toggle [%s]: led_matrix_eeconfig.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.enable); | 456 | dprintf("led matrix toggle [%s]: led_matrix_eeconfig.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.enable); |
| 477 | } | 457 | } |
| 478 | void led_matrix_toggle_noeeprom(void) { led_matrix_toggle_eeprom_helper(false); } | 458 | void led_matrix_toggle_noeeprom(void) { led_matrix_toggle_eeprom_helper(false); } |
| @@ -480,7 +460,7 @@ void led_matrix_toggle(void) { led_matrix_toggle_eeprom_helper(true); } | |||
| 480 | 460 | ||
| 481 | void led_matrix_enable(void) { | 461 | void led_matrix_enable(void) { |
| 482 | led_matrix_enable_noeeprom(); | 462 | led_matrix_enable_noeeprom(); |
| 483 | led_eeconfig_update(true); | 463 | eeconfig_flag_led_matrix(true); |
| 484 | } | 464 | } |
| 485 | 465 | ||
| 486 | void led_matrix_enable_noeeprom(void) { | 466 | void led_matrix_enable_noeeprom(void) { |
| @@ -490,7 +470,7 @@ void led_matrix_enable_noeeprom(void) { | |||
| 490 | 470 | ||
| 491 | void led_matrix_disable(void) { | 471 | void led_matrix_disable(void) { |
| 492 | led_matrix_disable_noeeprom(); | 472 | led_matrix_disable_noeeprom(); |
| 493 | led_eeconfig_update(true); | 473 | eeconfig_flag_led_matrix(true); |
| 494 | } | 474 | } |
| 495 | 475 | ||
| 496 | void led_matrix_disable_noeeprom(void) { | 476 | void led_matrix_disable_noeeprom(void) { |
| @@ -512,7 +492,7 @@ void led_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { | |||
| 512 | led_matrix_eeconfig.mode = mode; | 492 | led_matrix_eeconfig.mode = mode; |
| 513 | } | 493 | } |
| 514 | led_task_state = STARTING; | 494 | led_task_state = STARTING; |
| 515 | led_eeconfig_update(write_to_eeprom); | 495 | eeconfig_flag_led_matrix(write_to_eeprom); |
| 516 | dprintf("led matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.mode); | 496 | dprintf("led matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.mode); |
| 517 | } | 497 | } |
| 518 | void led_matrix_mode_noeeprom(uint8_t mode) { led_matrix_mode_eeprom_helper(mode, false); } | 498 | void led_matrix_mode_noeeprom(uint8_t mode) { led_matrix_mode_eeprom_helper(mode, false); } |
| @@ -539,7 +519,7 @@ void led_matrix_set_val_eeprom_helper(uint8_t val, bool write_to_eeprom) { | |||
| 539 | return; | 519 | return; |
| 540 | } | 520 | } |
| 541 | led_matrix_eeconfig.val = (val > LED_MATRIX_MAXIMUM_BRIGHTNESS) ? LED_MATRIX_MAXIMUM_BRIGHTNESS : val; | 521 | led_matrix_eeconfig.val = (val > LED_MATRIX_MAXIMUM_BRIGHTNESS) ? LED_MATRIX_MAXIMUM_BRIGHTNESS : val; |
| 542 | led_eeconfig_update(write_to_eeprom); | 522 | eeconfig_flag_led_matrix(write_to_eeprom); |
| 543 | dprintf("led matrix set val [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.val); | 523 | dprintf("led matrix set val [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.val); |
| 544 | } | 524 | } |
| 545 | void led_matrix_set_val_noeeprom(uint8_t val) { led_matrix_set_val_eeprom_helper(val, false); } | 525 | void led_matrix_set_val_noeeprom(uint8_t val) { led_matrix_set_val_eeprom_helper(val, false); } |
| @@ -557,7 +537,7 @@ void led_matrix_decrease_val(void) { led_matrix_decrease_val_helper(true); } | |||
| 557 | 537 | ||
| 558 | void led_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { | 538 | void led_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { |
| 559 | led_matrix_eeconfig.speed = speed; | 539 | led_matrix_eeconfig.speed = speed; |
| 560 | led_eeconfig_update(write_to_eeprom); | 540 | eeconfig_flag_led_matrix(write_to_eeprom); |
| 561 | dprintf("led matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.speed); | 541 | dprintf("led matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.speed); |
| 562 | } | 542 | } |
| 563 | void led_matrix_set_speed_noeeprom(uint8_t speed) { led_matrix_set_speed_eeprom_helper(speed, false); } | 543 | void led_matrix_set_speed_noeeprom(uint8_t speed) { led_matrix_set_speed_eeprom_helper(speed, false); } |
