aboutsummaryrefslogtreecommitdiff
path: root/quantum/rgb_matrix/rgb_matrix.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/rgb_matrix/rgb_matrix.c')
-rw-r--r--quantum/rgb_matrix/rgb_matrix.c32
1 files changed, 11 insertions, 21 deletions
diff --git a/quantum/rgb_matrix/rgb_matrix.c b/quantum/rgb_matrix/rgb_matrix.c
index 8f00b4087..c260b6e1e 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};
31const led_point_t k_rgb_matrix_center = RGB_MATRIX_CENTER; 31const 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
130static bool suspend_state = false; 122static bool suspend_state = false;
131static bool rgb_update_eeprom = false;
132static uint8_t rgb_last_enable = UINT8_MAX; 123static uint8_t rgb_last_enable = UINT8_MAX;
133static uint8_t rgb_last_effect = UINT8_MAX; 124static uint8_t rgb_last_effect = UINT8_MAX;
134static effect_params_t rgb_effect_params = {0, LED_FLAG_ALL, false}; 125static effect_params_t rgb_effect_params = {0, LED_FLAG_ALL, false};
@@ -148,9 +139,9 @@ static last_hit_t last_hit_buffer;
148const uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT; 139const uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT;
149#endif 140#endif
150 141
151void eeconfig_read_rgb_matrix(void) { eeprom_read_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); } 142EECONFIG_DEBOUNCE_HELPER(rgb_matrix, EECONFIG_RGB_MATRIX, rgb_matrix_config);
152 143
153void eeconfig_update_rgb_matrix(void) { eeprom_update_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); } 144void eeconfig_update_rgb_matrix(void) { eeconfig_flush_rgb_matrix(true); }
154 145
155void eeconfig_update_rgb_matrix_default(void) { 146void eeconfig_update_rgb_matrix_default(void) {
156 dprintf("eeconfig_update_rgb_matrix_default\n"); 147 dprintf("eeconfig_update_rgb_matrix_default\n");
@@ -159,7 +150,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}; 150 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; 151 rgb_matrix_config.speed = RGB_MATRIX_STARTUP_SPD;
161 rgb_matrix_config.flags = LED_FLAG_ALL; 152 rgb_matrix_config.flags = LED_FLAG_ALL;
162 eeconfig_update_rgb_matrix(); 153 eeconfig_flush_rgb_matrix(true);
163} 154}
164 155
165void eeconfig_debug_rgb_matrix(void) { 156void eeconfig_debug_rgb_matrix(void) {
@@ -314,9 +305,8 @@ static void rgb_task_timers(void) {
314} 305}
315 306
316static void rgb_task_sync(void) { 307static void rgb_task_sync(void) {
308 eeconfig_flush_rgb_matrix(false);
317 // next task 309 // 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; 310 if (sync_timer_elapsed32(g_rgb_timer) >= RGB_MATRIX_LED_FLUSH_LIMIT) rgb_task_state = STARTING;
321} 311}
322 312
@@ -491,7 +481,7 @@ void rgb_matrix_init(void) {
491 eeconfig_update_rgb_matrix_default(); 481 eeconfig_update_rgb_matrix_default();
492 } 482 }
493 483
494 eeconfig_read_rgb_matrix(); 484 eeconfig_init_rgb_matrix();
495 if (!rgb_matrix_config.mode) { 485 if (!rgb_matrix_config.mode) {
496 dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n"); 486 dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n");
497 eeconfig_update_rgb_matrix_default(); 487 eeconfig_update_rgb_matrix_default();
@@ -514,7 +504,7 @@ bool rgb_matrix_get_suspend_state(void) { return suspend_state; }
514void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) { 504void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) {
515 rgb_matrix_config.enable ^= 1; 505 rgb_matrix_config.enable ^= 1;
516 rgb_task_state = STARTING; 506 rgb_task_state = STARTING;
517 rgb_eeconfig_update(write_to_eeprom); 507 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); 508 dprintf("rgb matrix toggle [%s]: rgb_matrix_config.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.enable);
519} 509}
520void rgb_matrix_toggle_noeeprom(void) { rgb_matrix_toggle_eeprom_helper(false); } 510void rgb_matrix_toggle_noeeprom(void) { rgb_matrix_toggle_eeprom_helper(false); }
@@ -522,7 +512,7 @@ void rgb_matrix_toggle(void) { rgb_matrix_toggle_eeprom_helper(true); }
522 512
523void rgb_matrix_enable(void) { 513void rgb_matrix_enable(void) {
524 rgb_matrix_enable_noeeprom(); 514 rgb_matrix_enable_noeeprom();
525 rgb_eeconfig_update(true); 515 eeconfig_flag_rgb_matrix(true);
526} 516}
527 517
528void rgb_matrix_enable_noeeprom(void) { 518void rgb_matrix_enable_noeeprom(void) {
@@ -532,7 +522,7 @@ void rgb_matrix_enable_noeeprom(void) {
532 522
533void rgb_matrix_disable(void) { 523void rgb_matrix_disable(void) {
534 rgb_matrix_disable_noeeprom(); 524 rgb_matrix_disable_noeeprom();
535 rgb_eeconfig_update(true); 525 eeconfig_flag_rgb_matrix(true);
536} 526}
537 527
538void rgb_matrix_disable_noeeprom(void) { 528void rgb_matrix_disable_noeeprom(void) {
@@ -554,7 +544,7 @@ void rgb_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) {
554 rgb_matrix_config.mode = mode; 544 rgb_matrix_config.mode = mode;
555 } 545 }
556 rgb_task_state = STARTING; 546 rgb_task_state = STARTING;
557 rgb_eeconfig_update(write_to_eeprom); 547 eeconfig_flag_rgb_matrix(write_to_eeprom);
558 dprintf("rgb matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.mode); 548 dprintf("rgb matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.mode);
559} 549}
560void rgb_matrix_mode_noeeprom(uint8_t mode) { rgb_matrix_mode_eeprom_helper(mode, false); } 550void rgb_matrix_mode_noeeprom(uint8_t mode) { rgb_matrix_mode_eeprom_helper(mode, false); }
@@ -583,7 +573,7 @@ void rgb_matrix_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, boo
583 rgb_matrix_config.hsv.h = hue; 573 rgb_matrix_config.hsv.h = hue;
584 rgb_matrix_config.hsv.s = sat; 574 rgb_matrix_config.hsv.s = sat;
585 rgb_matrix_config.hsv.v = (val > RGB_MATRIX_MAXIMUM_BRIGHTNESS) ? RGB_MATRIX_MAXIMUM_BRIGHTNESS : val; 575 rgb_matrix_config.hsv.v = (val > RGB_MATRIX_MAXIMUM_BRIGHTNESS) ? RGB_MATRIX_MAXIMUM_BRIGHTNESS : val;
586 rgb_eeconfig_update(write_to_eeprom); 576 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); 577 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} 578}
589void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { rgb_matrix_sethsv_eeprom_helper(hue, sat, val, false); } 579void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { rgb_matrix_sethsv_eeprom_helper(hue, sat, val, false); }
@@ -620,7 +610,7 @@ void rgb_matrix_decrease_val(void) { rgb_matrix_decrease_val_helper(true); }
620 610
621void rgb_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { 611void rgb_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) {
622 rgb_matrix_config.speed = speed; 612 rgb_matrix_config.speed = speed;
623 rgb_eeconfig_update(write_to_eeprom); 613 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); 614 dprintf("rgb matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.speed);
625} 615}
626void rgb_matrix_set_speed_noeeprom(uint8_t speed) { rgb_matrix_set_speed_eeprom_helper(speed, false); } 616void rgb_matrix_set_speed_noeeprom(uint8_t speed) { rgb_matrix_set_speed_eeprom_helper(speed, false); }