aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--quantum/eeconfig.h26
-rw-r--r--quantum/led_matrix/led_matrix.c32
-rw-r--r--quantum/rgb_matrix/rgb_matrix.c32
3 files changed, 46 insertions, 44 deletions
diff --git a/quantum/eeconfig.h b/quantum/eeconfig.h
index bd39971b2..22d874273 100644
--- a/quantum/eeconfig.h
+++ b/quantum/eeconfig.h
@@ -111,3 +111,29 @@ void eeconfig_update_haptic(uint32_t val);
111 111
112bool eeconfig_read_handedness(void); 112bool eeconfig_read_handedness(void);
113void eeconfig_update_handedness(bool val); 113void eeconfig_update_handedness(bool val);
114
115#define EECONFIG_DEBOUNCE_HELPER(name, offset, config) \
116 static uint8_t dirty_##name = false; \
117 \
118 static inline void eeconfig_init_##name(void) { \
119 eeprom_read_block(&config, offset, sizeof(config)); \
120 dirty_##name = false; \
121 } \
122 static inline void eeconfig_flush_##name(bool force) { \
123 if (force || dirty_##name) { \
124 eeprom_update_block(&config, offset, sizeof(config)); \
125 dirty_##name = false; \
126 } \
127 } \
128 static inline void eeconfig_flush_##name##_task(uint16_t timeout) { \
129 static uint16_t flush_timer = 0; \
130 if (timer_elapsed(flush_timer) > timeout) { \
131 eeconfig_flush_##name(false); \
132 flush_timer = timer_read(); \
133 } \
134 } \
135 static inline void eeconfig_flag_##name(bool v) { dirty_##name |= v; } \
136 static inline void eeconfig_write_##name(typeof(config) conf) { \
137 memcpy(&config, &conf, sizeof(config)); \
138 eeconfig_flag_##name(true); \
139 }
diff --git a/quantum/led_matrix/led_matrix.c b/quantum/led_matrix/led_matrix.c
index 50510e49a..2f0086d36 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};
33const led_point_t k_led_matrix_center = LED_MATRIX_CENTER; 33const 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
109static bool suspend_state = false; 101static bool suspend_state = false;
110static bool led_update_eeprom = false;
111static uint8_t led_last_enable = UINT8_MAX; 102static uint8_t led_last_enable = UINT8_MAX;
112static uint8_t led_last_effect = UINT8_MAX; 103static uint8_t led_last_effect = UINT8_MAX;
113static effect_params_t led_effect_params = {0, LED_FLAG_ALL, false}; 104static effect_params_t led_effect_params = {0, LED_FLAG_ALL, false};
@@ -127,9 +118,7 @@ static last_hit_t last_hit_buffer;
127const uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT; 118const uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT;
128#endif 119#endif
129 120
130void eeconfig_read_led_matrix(void) { eeprom_read_block(&led_matrix_eeconfig, EECONFIG_LED_MATRIX, sizeof(led_matrix_eeconfig)); } 121EECONFIG_DEBOUNCE_HELPER(led_matrix, EECONFIG_LED_MATRIX, led_matrix_eeconfig);
131
132void eeconfig_update_led_matrix(void) { eeprom_update_block(&led_matrix_eeconfig, EECONFIG_LED_MATRIX, sizeof(led_matrix_eeconfig)); }
133 122
134void eeconfig_update_led_matrix_default(void) { 123void eeconfig_update_led_matrix_default(void) {
135 dprintf("eeconfig_update_led_matrix_default\n"); 124 dprintf("eeconfig_update_led_matrix_default\n");
@@ -138,7 +127,7 @@ void eeconfig_update_led_matrix_default(void) {
138 led_matrix_eeconfig.val = LED_MATRIX_STARTUP_VAL; 127 led_matrix_eeconfig.val = LED_MATRIX_STARTUP_VAL;
139 led_matrix_eeconfig.speed = LED_MATRIX_STARTUP_SPD; 128 led_matrix_eeconfig.speed = LED_MATRIX_STARTUP_SPD;
140 led_matrix_eeconfig.flags = LED_FLAG_ALL; 129 led_matrix_eeconfig.flags = LED_FLAG_ALL;
141 eeconfig_update_led_matrix(); 130 eeconfig_flush_led_matrix(true);
142} 131}
143 132
144void eeconfig_debug_led_matrix(void) { 133void eeconfig_debug_led_matrix(void) {
@@ -279,9 +268,8 @@ static void led_task_timers(void) {
279} 268}
280 269
281static void led_task_sync(void) { 270static void led_task_sync(void) {
271 eeconfig_flush_led_matrix(false);
282 // next task 272 // 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; 273 if (sync_timer_elapsed32(g_led_timer) >= LED_MATRIX_LED_FLUSH_LIMIT) led_task_state = STARTING;
286} 274}
287 275
@@ -449,7 +437,7 @@ void led_matrix_init(void) {
449 eeconfig_update_led_matrix_default(); 437 eeconfig_update_led_matrix_default();
450 } 438 }
451 439
452 eeconfig_read_led_matrix(); 440 eeconfig_init_led_matrix();
453 if (!led_matrix_eeconfig.mode) { 441 if (!led_matrix_eeconfig.mode) {
454 dprintf("led_matrix_init_drivers led_matrix_eeconfig.mode = 0. Write default values to EEPROM.\n"); 442 dprintf("led_matrix_init_drivers led_matrix_eeconfig.mode = 0. Write default values to EEPROM.\n");
455 eeconfig_update_led_matrix_default(); 443 eeconfig_update_led_matrix_default();
@@ -472,7 +460,7 @@ bool led_matrix_get_suspend_state(void) { return suspend_state; }
472void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) { 460void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) {
473 led_matrix_eeconfig.enable ^= 1; 461 led_matrix_eeconfig.enable ^= 1;
474 led_task_state = STARTING; 462 led_task_state = STARTING;
475 led_eeconfig_update(write_to_eeprom); 463 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); 464 dprintf("led matrix toggle [%s]: led_matrix_eeconfig.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.enable);
477} 465}
478void led_matrix_toggle_noeeprom(void) { led_matrix_toggle_eeprom_helper(false); } 466void led_matrix_toggle_noeeprom(void) { led_matrix_toggle_eeprom_helper(false); }
@@ -480,7 +468,7 @@ void led_matrix_toggle(void) { led_matrix_toggle_eeprom_helper(true); }
480 468
481void led_matrix_enable(void) { 469void led_matrix_enable(void) {
482 led_matrix_enable_noeeprom(); 470 led_matrix_enable_noeeprom();
483 led_eeconfig_update(true); 471 eeconfig_flag_led_matrix(true);
484} 472}
485 473
486void led_matrix_enable_noeeprom(void) { 474void led_matrix_enable_noeeprom(void) {
@@ -490,7 +478,7 @@ void led_matrix_enable_noeeprom(void) {
490 478
491void led_matrix_disable(void) { 479void led_matrix_disable(void) {
492 led_matrix_disable_noeeprom(); 480 led_matrix_disable_noeeprom();
493 led_eeconfig_update(true); 481 eeconfig_flag_led_matrix(true);
494} 482}
495 483
496void led_matrix_disable_noeeprom(void) { 484void led_matrix_disable_noeeprom(void) {
@@ -512,7 +500,7 @@ void led_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) {
512 led_matrix_eeconfig.mode = mode; 500 led_matrix_eeconfig.mode = mode;
513 } 501 }
514 led_task_state = STARTING; 502 led_task_state = STARTING;
515 led_eeconfig_update(write_to_eeprom); 503 eeconfig_flag_led_matrix(write_to_eeprom);
516 dprintf("led matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.mode); 504 dprintf("led matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.mode);
517} 505}
518void led_matrix_mode_noeeprom(uint8_t mode) { led_matrix_mode_eeprom_helper(mode, false); } 506void led_matrix_mode_noeeprom(uint8_t mode) { led_matrix_mode_eeprom_helper(mode, false); }
@@ -539,7 +527,7 @@ void led_matrix_set_val_eeprom_helper(uint8_t val, bool write_to_eeprom) {
539 return; 527 return;
540 } 528 }
541 led_matrix_eeconfig.val = (val > LED_MATRIX_MAXIMUM_BRIGHTNESS) ? LED_MATRIX_MAXIMUM_BRIGHTNESS : val; 529 led_matrix_eeconfig.val = (val > LED_MATRIX_MAXIMUM_BRIGHTNESS) ? LED_MATRIX_MAXIMUM_BRIGHTNESS : val;
542 led_eeconfig_update(write_to_eeprom); 530 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); 531 dprintf("led matrix set val [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.val);
544} 532}
545void led_matrix_set_val_noeeprom(uint8_t val) { led_matrix_set_val_eeprom_helper(val, false); } 533void led_matrix_set_val_noeeprom(uint8_t val) { led_matrix_set_val_eeprom_helper(val, false); }
@@ -557,7 +545,7 @@ void led_matrix_decrease_val(void) { led_matrix_decrease_val_helper(true); }
557 545
558void led_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { 546void led_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) {
559 led_matrix_eeconfig.speed = speed; 547 led_matrix_eeconfig.speed = speed;
560 led_eeconfig_update(write_to_eeprom); 548 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); 549 dprintf("led matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.speed);
562} 550}
563void led_matrix_set_speed_noeeprom(uint8_t speed) { led_matrix_set_speed_eeprom_helper(speed, false); } 551void led_matrix_set_speed_noeeprom(uint8_t speed) { led_matrix_set_speed_eeprom_helper(speed, false); }
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};
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,7 @@ 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
153void eeconfig_update_rgb_matrix(void) { eeprom_update_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); }
154 143
155void eeconfig_update_rgb_matrix_default(void) { 144void 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
165void eeconfig_debug_rgb_matrix(void) { 154void eeconfig_debug_rgb_matrix(void) {
@@ -314,9 +303,8 @@ static void rgb_task_timers(void) {
314} 303}
315 304
316static void rgb_task_sync(void) { 305static 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; }
514void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) { 502void 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}
520void rgb_matrix_toggle_noeeprom(void) { rgb_matrix_toggle_eeprom_helper(false); } 508void 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
523void rgb_matrix_enable(void) { 511void 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
528void rgb_matrix_enable_noeeprom(void) { 516void rgb_matrix_enable_noeeprom(void) {
@@ -532,7 +520,7 @@ void rgb_matrix_enable_noeeprom(void) {
532 520
533void rgb_matrix_disable(void) { 521void 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
538void rgb_matrix_disable_noeeprom(void) { 526void 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}
560void rgb_matrix_mode_noeeprom(uint8_t mode) { rgb_matrix_mode_eeprom_helper(mode, false); } 548void 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}
589void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { rgb_matrix_sethsv_eeprom_helper(hue, sat, val, false); } 577void 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
621void rgb_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { 609void 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}
626void rgb_matrix_set_speed_noeeprom(uint8_t speed) { rgb_matrix_set_speed_eeprom_helper(speed, false); } 614void rgb_matrix_set_speed_noeeprom(uint8_t speed) { rgb_matrix_set_speed_eeprom_helper(speed, false); }