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.c41
1 files changed, 12 insertions, 29 deletions
diff --git a/quantum/rgb_matrix/rgb_matrix.c b/quantum/rgb_matrix/rgb_matrix.c
index 8f00b4087..558c7bd41 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) {
@@ -187,14 +178,7 @@ uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *l
187 178
188void rgb_matrix_update_pwm_buffers(void) { rgb_matrix_driver.flush(); } 179void rgb_matrix_update_pwm_buffers(void) { rgb_matrix_driver.flush(); }
189 180
190void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { 181void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { rgb_matrix_driver.set_color(index, red, green, blue); }
191#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
192 if (!is_keyboard_left() && index >= k_rgb_matrix_split[0])
193 rgb_matrix_driver.set_color(index - k_rgb_matrix_split[0], red, green, blue);
194 else if (is_keyboard_left() && index < k_rgb_matrix_split[0])
195#endif
196 rgb_matrix_driver.set_color(index, red, green, blue);
197}
198 182
199void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { 183void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
200#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) 184#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
@@ -314,9 +298,8 @@ static void rgb_task_timers(void) {
314} 298}
315 299
316static void rgb_task_sync(void) { 300static void rgb_task_sync(void) {
301 eeconfig_flush_rgb_matrix(false);
317 // next task 302 // 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; 303 if (sync_timer_elapsed32(g_rgb_timer) >= RGB_MATRIX_LED_FLUSH_LIMIT) rgb_task_state = STARTING;
321} 304}
322 305
@@ -491,7 +474,7 @@ void rgb_matrix_init(void) {
491 eeconfig_update_rgb_matrix_default(); 474 eeconfig_update_rgb_matrix_default();
492 } 475 }
493 476
494 eeconfig_read_rgb_matrix(); 477 eeconfig_init_rgb_matrix();
495 if (!rgb_matrix_config.mode) { 478 if (!rgb_matrix_config.mode) {
496 dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n"); 479 dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n");
497 eeconfig_update_rgb_matrix_default(); 480 eeconfig_update_rgb_matrix_default();
@@ -514,7 +497,7 @@ bool rgb_matrix_get_suspend_state(void) { return suspend_state; }
514void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) { 497void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) {
515 rgb_matrix_config.enable ^= 1; 498 rgb_matrix_config.enable ^= 1;
516 rgb_task_state = STARTING; 499 rgb_task_state = STARTING;
517 rgb_eeconfig_update(write_to_eeprom); 500 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); 501 dprintf("rgb matrix toggle [%s]: rgb_matrix_config.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.enable);
519} 502}
520void rgb_matrix_toggle_noeeprom(void) { rgb_matrix_toggle_eeprom_helper(false); } 503void rgb_matrix_toggle_noeeprom(void) { rgb_matrix_toggle_eeprom_helper(false); }
@@ -522,7 +505,7 @@ void rgb_matrix_toggle(void) { rgb_matrix_toggle_eeprom_helper(true); }
522 505
523void rgb_matrix_enable(void) { 506void rgb_matrix_enable(void) {
524 rgb_matrix_enable_noeeprom(); 507 rgb_matrix_enable_noeeprom();
525 rgb_eeconfig_update(true); 508 eeconfig_flag_rgb_matrix(true);
526} 509}
527 510
528void rgb_matrix_enable_noeeprom(void) { 511void rgb_matrix_enable_noeeprom(void) {
@@ -532,7 +515,7 @@ void rgb_matrix_enable_noeeprom(void) {
532 515
533void rgb_matrix_disable(void) { 516void rgb_matrix_disable(void) {
534 rgb_matrix_disable_noeeprom(); 517 rgb_matrix_disable_noeeprom();
535 rgb_eeconfig_update(true); 518 eeconfig_flag_rgb_matrix(true);
536} 519}
537 520
538void rgb_matrix_disable_noeeprom(void) { 521void rgb_matrix_disable_noeeprom(void) {
@@ -554,7 +537,7 @@ void rgb_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) {
554 rgb_matrix_config.mode = mode; 537 rgb_matrix_config.mode = mode;
555 } 538 }
556 rgb_task_state = STARTING; 539 rgb_task_state = STARTING;
557 rgb_eeconfig_update(write_to_eeprom); 540 eeconfig_flag_rgb_matrix(write_to_eeprom);
558 dprintf("rgb matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.mode); 541 dprintf("rgb matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.mode);
559} 542}
560void rgb_matrix_mode_noeeprom(uint8_t mode) { rgb_matrix_mode_eeprom_helper(mode, false); } 543void rgb_matrix_mode_noeeprom(uint8_t mode) { rgb_matrix_mode_eeprom_helper(mode, false); }
@@ -583,7 +566,7 @@ void rgb_matrix_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, boo
583 rgb_matrix_config.hsv.h = hue; 566 rgb_matrix_config.hsv.h = hue;
584 rgb_matrix_config.hsv.s = sat; 567 rgb_matrix_config.hsv.s = sat;
585 rgb_matrix_config.hsv.v = (val > RGB_MATRIX_MAXIMUM_BRIGHTNESS) ? RGB_MATRIX_MAXIMUM_BRIGHTNESS : val; 568 rgb_matrix_config.hsv.v = (val > RGB_MATRIX_MAXIMUM_BRIGHTNESS) ? RGB_MATRIX_MAXIMUM_BRIGHTNESS : val;
586 rgb_eeconfig_update(write_to_eeprom); 569 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); 570 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} 571}
589void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { rgb_matrix_sethsv_eeprom_helper(hue, sat, val, false); } 572void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { rgb_matrix_sethsv_eeprom_helper(hue, sat, val, false); }
@@ -620,7 +603,7 @@ void rgb_matrix_decrease_val(void) { rgb_matrix_decrease_val_helper(true); }
620 603
621void rgb_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { 604void rgb_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) {
622 rgb_matrix_config.speed = speed; 605 rgb_matrix_config.speed = speed;
623 rgb_eeconfig_update(write_to_eeprom); 606 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); 607 dprintf("rgb matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.speed);
625} 608}
626void rgb_matrix_set_speed_noeeprom(uint8_t speed) { rgb_matrix_set_speed_eeprom_helper(speed, false); } 609void rgb_matrix_set_speed_noeeprom(uint8_t speed) { rgb_matrix_set_speed_eeprom_helper(speed, false); }