diff options
Diffstat (limited to 'quantum/rgb_matrix.c')
| -rw-r--r-- | quantum/rgb_matrix.c | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index ab8dbd849..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 |
| @@ -67,10 +75,6 @@ __attribute__((weak)) RGB rgb_matrix_hsv_to_rgb(HSV hsv) { return hsv_to_rgb(hsv | |||
| 67 | # define RGB_DISABLE_TIMEOUT 0 | 75 | # define RGB_DISABLE_TIMEOUT 0 |
| 68 | #endif | 76 | #endif |
| 69 | 77 | ||
| 70 | #if RGB_DISABLE_WHEN_USB_SUSPENDED != 1 | ||
| 71 | # undef RGB_DISABLE_WHEN_USB_SUSPENDED | ||
| 72 | #endif | ||
| 73 | |||
| 74 | #if !defined(RGB_MATRIX_MAXIMUM_BRIGHTNESS) || RGB_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX | 78 | #if !defined(RGB_MATRIX_MAXIMUM_BRIGHTNESS) || RGB_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX |
| 75 | # undef RGB_MATRIX_MAXIMUM_BRIGHTNESS | 79 | # undef RGB_MATRIX_MAXIMUM_BRIGHTNESS |
| 76 | # define RGB_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX | 80 | # define RGB_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX |
| @@ -129,6 +133,7 @@ last_hit_t g_last_hit_tracker; | |||
| 129 | 133 | ||
| 130 | // internals | 134 | // internals |
| 131 | static bool suspend_state = false; | 135 | static bool suspend_state = false; |
| 136 | static bool rgb_update_eeprom = false; | ||
| 132 | static uint8_t rgb_last_enable = UINT8_MAX; | 137 | static uint8_t rgb_last_enable = UINT8_MAX; |
| 133 | static uint8_t rgb_last_effect = UINT8_MAX; | 138 | static uint8_t rgb_last_effect = UINT8_MAX; |
| 134 | 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}; |
| @@ -315,6 +320,7 @@ static void rgb_task_timers(void) { | |||
| 315 | 320 | ||
| 316 | static void rgb_task_sync(void) { | 321 | static void rgb_task_sync(void) { |
| 317 | // next task | 322 | // next task |
| 323 | if (rgb_update_eeprom) eeconfig_update_rgb_matrix(); | ||
| 318 | 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; |
| 319 | } | 325 | } |
| 320 | 326 | ||
| @@ -511,9 +517,7 @@ bool rgb_matrix_get_suspend_state(void) { return suspend_state; } | |||
| 511 | void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) { | 517 | void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) { |
| 512 | rgb_matrix_config.enable ^= 1; | 518 | rgb_matrix_config.enable ^= 1; |
| 513 | rgb_task_state = STARTING; | 519 | rgb_task_state = STARTING; |
| 514 | if (write_to_eeprom) { | 520 | rgb_eeconfig_update(write_to_eeprom); |
| 515 | eeconfig_update_rgb_matrix(); | ||
| 516 | } | ||
| 517 | 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); |
| 518 | } | 522 | } |
| 519 | 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); } |
| @@ -521,7 +525,7 @@ void rgb_matrix_toggle(void) { rgb_matrix_toggle_eeprom_helper(true); } | |||
| 521 | 525 | ||
| 522 | void rgb_matrix_enable(void) { | 526 | void rgb_matrix_enable(void) { |
| 523 | rgb_matrix_enable_noeeprom(); | 527 | rgb_matrix_enable_noeeprom(); |
| 524 | eeconfig_update_rgb_matrix(); | 528 | rgb_eeconfig_update(true); |
| 525 | } | 529 | } |
| 526 | 530 | ||
| 527 | void rgb_matrix_enable_noeeprom(void) { | 531 | void rgb_matrix_enable_noeeprom(void) { |
| @@ -531,7 +535,7 @@ void rgb_matrix_enable_noeeprom(void) { | |||
| 531 | 535 | ||
| 532 | void rgb_matrix_disable(void) { | 536 | void rgb_matrix_disable(void) { |
| 533 | rgb_matrix_disable_noeeprom(); | 537 | rgb_matrix_disable_noeeprom(); |
| 534 | eeconfig_update_rgb_matrix(); | 538 | rgb_eeconfig_update(true); |
| 535 | } | 539 | } |
| 536 | 540 | ||
| 537 | void rgb_matrix_disable_noeeprom(void) { | 541 | void rgb_matrix_disable_noeeprom(void) { |
| @@ -553,9 +557,7 @@ void rgb_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { | |||
| 553 | rgb_matrix_config.mode = mode; | 557 | rgb_matrix_config.mode = mode; |
| 554 | } | 558 | } |
| 555 | rgb_task_state = STARTING; | 559 | rgb_task_state = STARTING; |
| 556 | if (write_to_eeprom) { | 560 | rgb_eeconfig_update(write_to_eeprom); |
| 557 | eeconfig_update_rgb_matrix(); | ||
| 558 | } | ||
| 559 | 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); |
| 560 | } | 562 | } |
| 561 | 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); } |
| @@ -584,9 +586,7 @@ void rgb_matrix_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, boo | |||
| 584 | rgb_matrix_config.hsv.h = hue; | 586 | rgb_matrix_config.hsv.h = hue; |
| 585 | rgb_matrix_config.hsv.s = sat; | 587 | rgb_matrix_config.hsv.s = sat; |
| 586 | 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; |
| 587 | if (write_to_eeprom) { | 589 | rgb_eeconfig_update(write_to_eeprom); |
| 588 | eeconfig_update_rgb_matrix(); | ||
| 589 | } | ||
| 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); | 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); |
| 591 | } | 591 | } |
| 592 | 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); } |
| @@ -623,9 +623,7 @@ void rgb_matrix_decrease_val(void) { rgb_matrix_decrease_val_helper(true); } | |||
| 623 | 623 | ||
| 624 | 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) { |
| 625 | rgb_matrix_config.speed = speed; | 625 | rgb_matrix_config.speed = speed; |
| 626 | if (write_to_eeprom) { | 626 | rgb_eeconfig_update(write_to_eeprom); |
| 627 | eeconfig_update_rgb_matrix(); | ||
| 628 | } | ||
| 629 | 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); |
| 630 | } | 628 | } |
| 631 | 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); } |
