diff options
Diffstat (limited to 'quantum/rgb_matrix')
| -rw-r--r-- | quantum/rgb_matrix/rgb_matrix.c | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/quantum/rgb_matrix/rgb_matrix.c b/quantum/rgb_matrix/rgb_matrix.c index 8f00b4087..0c9ef8f7a 100644 --- a/quantum/rgb_matrix/rgb_matrix.c +++ b/quantum/rgb_matrix/rgb_matrix.c | |||
| @@ -31,14 +31,6 @@ 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 | |||
| 42 | __attribute__((weak)) RGB rgb_matrix_hsv_to_rgb(HSV hsv) { return hsv_to_rgb(hsv); } | 34 | __attribute__((weak)) RGB rgb_matrix_hsv_to_rgb(HSV hsv) { return hsv_to_rgb(hsv); } |
| 43 | 35 | ||
| 44 | // Generic effect runners | 36 | // Generic effect runners |
| @@ -128,7 +120,6 @@ last_hit_t g_last_hit_tracker; | |||
| 128 | 120 | ||
| 129 | // internals | 121 | // internals |
| 130 | static bool suspend_state = false; | 122 | static bool suspend_state = false; |
| 131 | static bool rgb_update_eeprom = false; | ||
| 132 | static uint8_t rgb_last_enable = UINT8_MAX; | 123 | static uint8_t rgb_last_enable = UINT8_MAX; |
| 133 | static uint8_t rgb_last_effect = UINT8_MAX; | 124 | static uint8_t rgb_last_effect = UINT8_MAX; |
| 134 | static effect_params_t rgb_effect_params = {0, LED_FLAG_ALL, false}; | 125 | static effect_params_t rgb_effect_params = {0, LED_FLAG_ALL, false}; |
| @@ -148,9 +139,7 @@ static last_hit_t last_hit_buffer; | |||
| 148 | const uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT; | 139 | const uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT; |
| 149 | #endif | 140 | #endif |
| 150 | 141 | ||
| 151 | void eeconfig_read_rgb_matrix(void) { eeprom_read_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); } | 142 | EECONFIG_DEBOUNCE_HELPER(rgb_matrix, EECONFIG_RGB_MATRIX, rgb_matrix_config); |
| 152 | |||
| 153 | void eeconfig_update_rgb_matrix(void) { eeprom_update_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); } | ||
| 154 | 143 | ||
| 155 | void eeconfig_update_rgb_matrix_default(void) { | 144 | void eeconfig_update_rgb_matrix_default(void) { |
| 156 | dprintf("eeconfig_update_rgb_matrix_default\n"); | 145 | dprintf("eeconfig_update_rgb_matrix_default\n"); |
| @@ -159,7 +148,7 @@ void eeconfig_update_rgb_matrix_default(void) { | |||
| 159 | rgb_matrix_config.hsv = (HSV){RGB_MATRIX_STARTUP_HUE, RGB_MATRIX_STARTUP_SAT, RGB_MATRIX_STARTUP_VAL}; | 148 | rgb_matrix_config.hsv = (HSV){RGB_MATRIX_STARTUP_HUE, RGB_MATRIX_STARTUP_SAT, RGB_MATRIX_STARTUP_VAL}; |
| 160 | rgb_matrix_config.speed = RGB_MATRIX_STARTUP_SPD; | 149 | rgb_matrix_config.speed = RGB_MATRIX_STARTUP_SPD; |
| 161 | rgb_matrix_config.flags = LED_FLAG_ALL; | 150 | rgb_matrix_config.flags = LED_FLAG_ALL; |
| 162 | eeconfig_update_rgb_matrix(); | 151 | eeconfig_flush_rgb_matrix(true); |
| 163 | } | 152 | } |
| 164 | 153 | ||
| 165 | void eeconfig_debug_rgb_matrix(void) { | 154 | void eeconfig_debug_rgb_matrix(void) { |
| @@ -314,9 +303,8 @@ static void rgb_task_timers(void) { | |||
| 314 | } | 303 | } |
| 315 | 304 | ||
| 316 | static void rgb_task_sync(void) { | 305 | static void rgb_task_sync(void) { |
| 306 | eeconfig_flush_rgb_matrix(false); | ||
| 317 | // next task | 307 | // next task |
| 318 | if (rgb_update_eeprom) eeconfig_update_rgb_matrix(); | ||
| 319 | rgb_update_eeprom = false; | ||
| 320 | if (sync_timer_elapsed32(g_rgb_timer) >= RGB_MATRIX_LED_FLUSH_LIMIT) rgb_task_state = STARTING; | 308 | if (sync_timer_elapsed32(g_rgb_timer) >= RGB_MATRIX_LED_FLUSH_LIMIT) rgb_task_state = STARTING; |
| 321 | } | 309 | } |
| 322 | 310 | ||
| @@ -491,7 +479,7 @@ void rgb_matrix_init(void) { | |||
| 491 | eeconfig_update_rgb_matrix_default(); | 479 | eeconfig_update_rgb_matrix_default(); |
| 492 | } | 480 | } |
| 493 | 481 | ||
| 494 | eeconfig_read_rgb_matrix(); | 482 | eeconfig_init_rgb_matrix(); |
| 495 | if (!rgb_matrix_config.mode) { | 483 | if (!rgb_matrix_config.mode) { |
| 496 | dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n"); | 484 | dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n"); |
| 497 | eeconfig_update_rgb_matrix_default(); | 485 | eeconfig_update_rgb_matrix_default(); |
| @@ -514,7 +502,7 @@ bool rgb_matrix_get_suspend_state(void) { return suspend_state; } | |||
| 514 | void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) { | 502 | void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) { |
| 515 | rgb_matrix_config.enable ^= 1; | 503 | rgb_matrix_config.enable ^= 1; |
| 516 | rgb_task_state = STARTING; | 504 | rgb_task_state = STARTING; |
| 517 | rgb_eeconfig_update(write_to_eeprom); | 505 | eeconfig_flag_rgb_matrix(write_to_eeprom); |
| 518 | dprintf("rgb matrix toggle [%s]: rgb_matrix_config.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.enable); | 506 | dprintf("rgb matrix toggle [%s]: rgb_matrix_config.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.enable); |
| 519 | } | 507 | } |
| 520 | void rgb_matrix_toggle_noeeprom(void) { rgb_matrix_toggle_eeprom_helper(false); } | 508 | void rgb_matrix_toggle_noeeprom(void) { rgb_matrix_toggle_eeprom_helper(false); } |
| @@ -522,7 +510,7 @@ void rgb_matrix_toggle(void) { rgb_matrix_toggle_eeprom_helper(true); } | |||
| 522 | 510 | ||
| 523 | void rgb_matrix_enable(void) { | 511 | void rgb_matrix_enable(void) { |
| 524 | rgb_matrix_enable_noeeprom(); | 512 | rgb_matrix_enable_noeeprom(); |
| 525 | rgb_eeconfig_update(true); | 513 | eeconfig_flag_rgb_matrix(true); |
| 526 | } | 514 | } |
| 527 | 515 | ||
| 528 | void rgb_matrix_enable_noeeprom(void) { | 516 | void rgb_matrix_enable_noeeprom(void) { |
| @@ -532,7 +520,7 @@ void rgb_matrix_enable_noeeprom(void) { | |||
| 532 | 520 | ||
| 533 | void rgb_matrix_disable(void) { | 521 | void rgb_matrix_disable(void) { |
| 534 | rgb_matrix_disable_noeeprom(); | 522 | rgb_matrix_disable_noeeprom(); |
| 535 | rgb_eeconfig_update(true); | 523 | eeconfig_flag_rgb_matrix(true); |
| 536 | } | 524 | } |
| 537 | 525 | ||
| 538 | void rgb_matrix_disable_noeeprom(void) { | 526 | void rgb_matrix_disable_noeeprom(void) { |
| @@ -554,7 +542,7 @@ void rgb_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { | |||
| 554 | rgb_matrix_config.mode = mode; | 542 | rgb_matrix_config.mode = mode; |
| 555 | } | 543 | } |
| 556 | rgb_task_state = STARTING; | 544 | rgb_task_state = STARTING; |
| 557 | rgb_eeconfig_update(write_to_eeprom); | 545 | eeconfig_flag_rgb_matrix(write_to_eeprom); |
| 558 | dprintf("rgb matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.mode); | 546 | dprintf("rgb matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.mode); |
| 559 | } | 547 | } |
| 560 | void rgb_matrix_mode_noeeprom(uint8_t mode) { rgb_matrix_mode_eeprom_helper(mode, false); } | 548 | void rgb_matrix_mode_noeeprom(uint8_t mode) { rgb_matrix_mode_eeprom_helper(mode, false); } |
| @@ -583,7 +571,7 @@ void rgb_matrix_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, boo | |||
| 583 | rgb_matrix_config.hsv.h = hue; | 571 | rgb_matrix_config.hsv.h = hue; |
| 584 | rgb_matrix_config.hsv.s = sat; | 572 | rgb_matrix_config.hsv.s = sat; |
| 585 | rgb_matrix_config.hsv.v = (val > RGB_MATRIX_MAXIMUM_BRIGHTNESS) ? RGB_MATRIX_MAXIMUM_BRIGHTNESS : val; | 573 | rgb_matrix_config.hsv.v = (val > RGB_MATRIX_MAXIMUM_BRIGHTNESS) ? RGB_MATRIX_MAXIMUM_BRIGHTNESS : val; |
| 586 | rgb_eeconfig_update(write_to_eeprom); | 574 | eeconfig_flag_rgb_matrix(write_to_eeprom); |
| 587 | 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); | 575 | 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); |
| 588 | } | 576 | } |
| 589 | void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { rgb_matrix_sethsv_eeprom_helper(hue, sat, val, false); } | 577 | void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { rgb_matrix_sethsv_eeprom_helper(hue, sat, val, false); } |
| @@ -620,7 +608,7 @@ void rgb_matrix_decrease_val(void) { rgb_matrix_decrease_val_helper(true); } | |||
| 620 | 608 | ||
| 621 | void rgb_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { | 609 | void rgb_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { |
| 622 | rgb_matrix_config.speed = speed; | 610 | rgb_matrix_config.speed = speed; |
| 623 | rgb_eeconfig_update(write_to_eeprom); | 611 | eeconfig_flag_rgb_matrix(write_to_eeprom); |
| 624 | dprintf("rgb matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.speed); | 612 | dprintf("rgb matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.speed); |
| 625 | } | 613 | } |
| 626 | void rgb_matrix_set_speed_noeeprom(uint8_t speed) { rgb_matrix_set_speed_eeprom_helper(speed, false); } | 614 | void rgb_matrix_set_speed_noeeprom(uint8_t speed) { rgb_matrix_set_speed_eeprom_helper(speed, false); } |
