aboutsummaryrefslogtreecommitdiff
path: root/quantum/led_matrix
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/led_matrix')
-rw-r--r--quantum/led_matrix/animations/alpha_mods_anim.h2
-rw-r--r--quantum/led_matrix/animations/breathing_anim.h2
-rw-r--r--quantum/led_matrix/animations/runners/effect_runner_dx_dy.h2
-rw-r--r--quantum/led_matrix/animations/runners/effect_runner_dx_dy_dist.h2
-rw-r--r--quantum/led_matrix/animations/runners/effect_runner_i.h2
-rw-r--r--quantum/led_matrix/animations/runners/effect_runner_reactive.h2
-rw-r--r--quantum/led_matrix/animations/runners/effect_runner_reactive_splash.h2
-rw-r--r--quantum/led_matrix/animations/runners/effect_runner_sin_cos_i.h2
-rw-r--r--quantum/led_matrix/animations/solid_anim.h2
-rw-r--r--quantum/led_matrix/led_matrix.c46
-rw-r--r--quantum/led_matrix/led_matrix.h45
-rw-r--r--quantum/led_matrix/led_matrix_drivers.c133
12 files changed, 124 insertions, 118 deletions
diff --git a/quantum/led_matrix/animations/alpha_mods_anim.h b/quantum/led_matrix/animations/alpha_mods_anim.h
index 14038cd08..c82b2aa38 100644
--- a/quantum/led_matrix/animations/alpha_mods_anim.h
+++ b/quantum/led_matrix/animations/alpha_mods_anim.h
@@ -17,7 +17,7 @@ bool ALPHAS_MODS(effect_params_t* params) {
17 led_matrix_set_value(i, val1); 17 led_matrix_set_value(i, val1);
18 } 18 }
19 } 19 }
20 return led_max < DRIVER_LED_TOTAL; 20 return led_matrix_check_finished_leds(led_max);
21} 21}
22 22
23# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS 23# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
diff --git a/quantum/led_matrix/animations/breathing_anim.h b/quantum/led_matrix/animations/breathing_anim.h
index e3f600c45..d9cc2de23 100644
--- a/quantum/led_matrix/animations/breathing_anim.h
+++ b/quantum/led_matrix/animations/breathing_anim.h
@@ -12,7 +12,7 @@ bool BREATHING(effect_params_t* params) {
12 LED_MATRIX_TEST_LED_FLAGS(); 12 LED_MATRIX_TEST_LED_FLAGS();
13 led_matrix_set_value(i, val); 13 led_matrix_set_value(i, val);
14 } 14 }
15 return led_max < DRIVER_LED_TOTAL; 15 return led_matrix_check_finished_leds(led_max);
16} 16}
17 17
18# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS 18# endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
diff --git a/quantum/led_matrix/animations/runners/effect_runner_dx_dy.h b/quantum/led_matrix/animations/runners/effect_runner_dx_dy.h
index ef97631b9..fa9b7dbbf 100644
--- a/quantum/led_matrix/animations/runners/effect_runner_dx_dy.h
+++ b/quantum/led_matrix/animations/runners/effect_runner_dx_dy.h
@@ -12,5 +12,5 @@ bool effect_runner_dx_dy(effect_params_t* params, dx_dy_f effect_func) {
12 int16_t dy = g_led_config.point[i].y - k_led_matrix_center.y; 12 int16_t dy = g_led_config.point[i].y - k_led_matrix_center.y;
13 led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, dx, dy, time)); 13 led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, dx, dy, time));
14 } 14 }
15 return led_max < DRIVER_LED_TOTAL; 15 return led_matrix_check_finished_leds(led_max);
16} 16}
diff --git a/quantum/led_matrix/animations/runners/effect_runner_dx_dy_dist.h b/quantum/led_matrix/animations/runners/effect_runner_dx_dy_dist.h
index 5ef5938be..061a5f07f 100644
--- a/quantum/led_matrix/animations/runners/effect_runner_dx_dy_dist.h
+++ b/quantum/led_matrix/animations/runners/effect_runner_dx_dy_dist.h
@@ -13,5 +13,5 @@ bool effect_runner_dx_dy_dist(effect_params_t* params, dx_dy_dist_f effect_func)
13 uint8_t dist = sqrt16(dx * dx + dy * dy); 13 uint8_t dist = sqrt16(dx * dx + dy * dy);
14 led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, dx, dy, dist, time)); 14 led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, dx, dy, dist, time));
15 } 15 }
16 return led_max < DRIVER_LED_TOTAL; 16 return led_matrix_check_finished_leds(led_max);
17} 17}
diff --git a/quantum/led_matrix/animations/runners/effect_runner_i.h b/quantum/led_matrix/animations/runners/effect_runner_i.h
index b3015759b..f6f8c0dee 100644
--- a/quantum/led_matrix/animations/runners/effect_runner_i.h
+++ b/quantum/led_matrix/animations/runners/effect_runner_i.h
@@ -10,5 +10,5 @@ bool effect_runner_i(effect_params_t* params, i_f effect_func) {
10 LED_MATRIX_TEST_LED_FLAGS(); 10 LED_MATRIX_TEST_LED_FLAGS();
11 led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, i, time)); 11 led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, i, time));
12 } 12 }
13 return led_max < DRIVER_LED_TOTAL; 13 return led_matrix_check_finished_leds(led_max);
14} 14}
diff --git a/quantum/led_matrix/animations/runners/effect_runner_reactive.h b/quantum/led_matrix/animations/runners/effect_runner_reactive.h
index 4369ea8c4..be3090aa5 100644
--- a/quantum/led_matrix/animations/runners/effect_runner_reactive.h
+++ b/quantum/led_matrix/animations/runners/effect_runner_reactive.h
@@ -22,7 +22,7 @@ bool effect_runner_reactive(effect_params_t* params, reactive_f effect_func) {
22 uint16_t offset = scale16by8(tick, led_matrix_eeconfig.speed); 22 uint16_t offset = scale16by8(tick, led_matrix_eeconfig.speed);
23 led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, offset)); 23 led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, offset));
24 } 24 }
25 return led_max < DRIVER_LED_TOTAL; 25 return led_matrix_check_finished_leds(led_max);
26} 26}
27 27
28#endif // LED_MATRIX_KEYREACTIVE_ENABLED 28#endif // LED_MATRIX_KEYREACTIVE_ENABLED
diff --git a/quantum/led_matrix/animations/runners/effect_runner_reactive_splash.h b/quantum/led_matrix/animations/runners/effect_runner_reactive_splash.h
index d6eb9731e..f6ffc825a 100644
--- a/quantum/led_matrix/animations/runners/effect_runner_reactive_splash.h
+++ b/quantum/led_matrix/animations/runners/effect_runner_reactive_splash.h
@@ -20,7 +20,7 @@ bool effect_runner_reactive_splash(uint8_t start, effect_params_t* params, react
20 } 20 }
21 led_matrix_set_value(i, scale8(val, led_matrix_eeconfig.val)); 21 led_matrix_set_value(i, scale8(val, led_matrix_eeconfig.val));
22 } 22 }
23 return led_max < DRIVER_LED_TOTAL; 23 return led_matrix_check_finished_leds(led_max);
24} 24}
25 25
26#endif // LED_MATRIX_KEYREACTIVE_ENABLED 26#endif // LED_MATRIX_KEYREACTIVE_ENABLED
diff --git a/quantum/led_matrix/animations/runners/effect_runner_sin_cos_i.h b/quantum/led_matrix/animations/runners/effect_runner_sin_cos_i.h
index 4a5219abd..3145e2713 100644
--- a/quantum/led_matrix/animations/runners/effect_runner_sin_cos_i.h
+++ b/quantum/led_matrix/animations/runners/effect_runner_sin_cos_i.h
@@ -12,5 +12,5 @@ bool effect_runner_sin_cos_i(effect_params_t* params, sin_cos_i_f effect_func) {
12 LED_MATRIX_TEST_LED_FLAGS(); 12 LED_MATRIX_TEST_LED_FLAGS();
13 led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, cos_value, sin_value, i, time)); 13 led_matrix_set_value(i, effect_func(led_matrix_eeconfig.val, cos_value, sin_value, i, time));
14 } 14 }
15 return led_max < DRIVER_LED_TOTAL; 15 return led_matrix_check_finished_leds(led_max);
16} 16}
diff --git a/quantum/led_matrix/animations/solid_anim.h b/quantum/led_matrix/animations/solid_anim.h
index 4c9e43c58..c728dbcc9 100644
--- a/quantum/led_matrix/animations/solid_anim.h
+++ b/quantum/led_matrix/animations/solid_anim.h
@@ -9,7 +9,7 @@ bool SOLID(effect_params_t* params) {
9 LED_MATRIX_TEST_LED_FLAGS(); 9 LED_MATRIX_TEST_LED_FLAGS();
10 led_matrix_set_value(i, val); 10 led_matrix_set_value(i, val);
11 } 11 }
12 return led_max < DRIVER_LED_TOTAL; 12 return led_matrix_check_finished_leds(led_max);
13} 13}
14 14
15#endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS 15#endif // LED_MATRIX_CUSTOM_EFFECT_IMPLS
diff --git a/quantum/led_matrix/led_matrix.c b/quantum/led_matrix/led_matrix.c
index 50510e49a..8d6a56f27 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,9 @@ 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 122
132void eeconfig_update_led_matrix(void) { eeprom_update_block(&led_matrix_eeconfig, EECONFIG_LED_MATRIX, sizeof(led_matrix_eeconfig)); } 123void eeconfig_update_led_matrix(void) { eeconfig_flush_led_matrix(true); }
133 124
134void eeconfig_update_led_matrix_default(void) { 125void eeconfig_update_led_matrix_default(void) {
135 dprintf("eeconfig_update_led_matrix_default\n"); 126 dprintf("eeconfig_update_led_matrix_default\n");
@@ -138,7 +129,7 @@ void eeconfig_update_led_matrix_default(void) {
138 led_matrix_eeconfig.val = LED_MATRIX_STARTUP_VAL; 129 led_matrix_eeconfig.val = LED_MATRIX_STARTUP_VAL;
139 led_matrix_eeconfig.speed = LED_MATRIX_STARTUP_SPD; 130 led_matrix_eeconfig.speed = LED_MATRIX_STARTUP_SPD;
140 led_matrix_eeconfig.flags = LED_FLAG_ALL; 131 led_matrix_eeconfig.flags = LED_FLAG_ALL;
141 eeconfig_update_led_matrix(); 132 eeconfig_flush_led_matrix(true);
142} 133}
143 134
144void eeconfig_debug_led_matrix(void) { 135void eeconfig_debug_led_matrix(void) {
@@ -165,20 +156,10 @@ uint8_t led_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *l
165void led_matrix_update_pwm_buffers(void) { led_matrix_driver.flush(); } 156void led_matrix_update_pwm_buffers(void) { led_matrix_driver.flush(); }
166 157
167void led_matrix_set_value(int index, uint8_t value) { 158void led_matrix_set_value(int index, uint8_t value) {
168#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
169 if (!is_keyboard_left() && index >= k_led_matrix_split[0])
170# ifdef USE_CIE1931_CURVE
171 led_matrix_driver.set_value(index - k_led_matrix_split[0], pgm_read_byte(&CIE1931_CURVE[value]));
172# else
173 led_matrix_driver.set_value(index - k_led_matrix_split[0], value);
174# endif
175 else if (is_keyboard_left() && index < k_led_matrix_split[0])
176#endif
177#ifdef USE_CIE1931_CURVE 159#ifdef USE_CIE1931_CURVE
178 led_matrix_driver.set_value(index, pgm_read_byte(&CIE1931_CURVE[value])); 160 value = pgm_read_byte(&CIE1931_CURVE[value]);
179#else
180 led_matrix_driver.set_value(index, value);
181#endif 161#endif
162 led_matrix_driver.set_value(index, value);
182} 163}
183 164
184void led_matrix_set_value_all(uint8_t value) { 165void led_matrix_set_value_all(uint8_t value) {
@@ -279,9 +260,8 @@ static void led_task_timers(void) {
279} 260}
280 261
281static void led_task_sync(void) { 262static void led_task_sync(void) {
263 eeconfig_flush_led_matrix(false);
282 // next task 264 // 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; 265 if (sync_timer_elapsed32(g_led_timer) >= LED_MATRIX_LED_FLUSH_LIMIT) led_task_state = STARTING;
286} 266}
287 267
@@ -449,7 +429,7 @@ void led_matrix_init(void) {
449 eeconfig_update_led_matrix_default(); 429 eeconfig_update_led_matrix_default();
450 } 430 }
451 431
452 eeconfig_read_led_matrix(); 432 eeconfig_init_led_matrix();
453 if (!led_matrix_eeconfig.mode) { 433 if (!led_matrix_eeconfig.mode) {
454 dprintf("led_matrix_init_drivers led_matrix_eeconfig.mode = 0. Write default values to EEPROM.\n"); 434 dprintf("led_matrix_init_drivers led_matrix_eeconfig.mode = 0. Write default values to EEPROM.\n");
455 eeconfig_update_led_matrix_default(); 435 eeconfig_update_led_matrix_default();
@@ -472,7 +452,7 @@ bool led_matrix_get_suspend_state(void) { return suspend_state; }
472void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) { 452void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) {
473 led_matrix_eeconfig.enable ^= 1; 453 led_matrix_eeconfig.enable ^= 1;
474 led_task_state = STARTING; 454 led_task_state = STARTING;
475 led_eeconfig_update(write_to_eeprom); 455 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); 456 dprintf("led matrix toggle [%s]: led_matrix_eeconfig.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.enable);
477} 457}
478void led_matrix_toggle_noeeprom(void) { led_matrix_toggle_eeprom_helper(false); } 458void led_matrix_toggle_noeeprom(void) { led_matrix_toggle_eeprom_helper(false); }
@@ -480,7 +460,7 @@ void led_matrix_toggle(void) { led_matrix_toggle_eeprom_helper(true); }
480 460
481void led_matrix_enable(void) { 461void led_matrix_enable(void) {
482 led_matrix_enable_noeeprom(); 462 led_matrix_enable_noeeprom();
483 led_eeconfig_update(true); 463 eeconfig_flag_led_matrix(true);
484} 464}
485 465
486void led_matrix_enable_noeeprom(void) { 466void led_matrix_enable_noeeprom(void) {
@@ -490,7 +470,7 @@ void led_matrix_enable_noeeprom(void) {
490 470
491void led_matrix_disable(void) { 471void led_matrix_disable(void) {
492 led_matrix_disable_noeeprom(); 472 led_matrix_disable_noeeprom();
493 led_eeconfig_update(true); 473 eeconfig_flag_led_matrix(true);
494} 474}
495 475
496void led_matrix_disable_noeeprom(void) { 476void led_matrix_disable_noeeprom(void) {
@@ -512,7 +492,7 @@ void led_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) {
512 led_matrix_eeconfig.mode = mode; 492 led_matrix_eeconfig.mode = mode;
513 } 493 }
514 led_task_state = STARTING; 494 led_task_state = STARTING;
515 led_eeconfig_update(write_to_eeprom); 495 eeconfig_flag_led_matrix(write_to_eeprom);
516 dprintf("led matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.mode); 496 dprintf("led matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.mode);
517} 497}
518void led_matrix_mode_noeeprom(uint8_t mode) { led_matrix_mode_eeprom_helper(mode, false); } 498void led_matrix_mode_noeeprom(uint8_t mode) { led_matrix_mode_eeprom_helper(mode, false); }
@@ -539,7 +519,7 @@ void led_matrix_set_val_eeprom_helper(uint8_t val, bool write_to_eeprom) {
539 return; 519 return;
540 } 520 }
541 led_matrix_eeconfig.val = (val > LED_MATRIX_MAXIMUM_BRIGHTNESS) ? LED_MATRIX_MAXIMUM_BRIGHTNESS : val; 521 led_matrix_eeconfig.val = (val > LED_MATRIX_MAXIMUM_BRIGHTNESS) ? LED_MATRIX_MAXIMUM_BRIGHTNESS : val;
542 led_eeconfig_update(write_to_eeprom); 522 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); 523 dprintf("led matrix set val [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.val);
544} 524}
545void led_matrix_set_val_noeeprom(uint8_t val) { led_matrix_set_val_eeprom_helper(val, false); } 525void led_matrix_set_val_noeeprom(uint8_t val) { led_matrix_set_val_eeprom_helper(val, false); }
@@ -557,7 +537,7 @@ void led_matrix_decrease_val(void) { led_matrix_decrease_val_helper(true); }
557 537
558void led_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { 538void led_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) {
559 led_matrix_eeconfig.speed = speed; 539 led_matrix_eeconfig.speed = speed;
560 led_eeconfig_update(write_to_eeprom); 540 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); 541 dprintf("led matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.speed);
562} 542}
563void led_matrix_set_speed_noeeprom(uint8_t speed) { led_matrix_set_speed_eeprom_helper(speed, false); } 543void led_matrix_set_speed_noeeprom(uint8_t speed) { led_matrix_set_speed_eeprom_helper(speed, false); }
diff --git a/quantum/led_matrix/led_matrix.h b/quantum/led_matrix/led_matrix.h
index a7a1c983f..538674443 100644
--- a/quantum/led_matrix/led_matrix.h
+++ b/quantum/led_matrix/led_matrix.h
@@ -38,14 +38,33 @@
38#endif 38#endif
39 39
40#if defined(LED_MATRIX_LED_PROCESS_LIMIT) && LED_MATRIX_LED_PROCESS_LIMIT > 0 && LED_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL 40#if defined(LED_MATRIX_LED_PROCESS_LIMIT) && LED_MATRIX_LED_PROCESS_LIMIT > 0 && LED_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL
41# define LED_MATRIX_USE_LIMITS(min, max) \ 41# if defined(LED_MATRIX_SPLIT)
42 uint8_t min = LED_MATRIX_LED_PROCESS_LIMIT * params->iter; \ 42# define LED_MATRIX_USE_LIMITS(min, max) \
43 uint8_t max = min + LED_MATRIX_LED_PROCESS_LIMIT; \ 43 uint8_t min = LED_MATRIX_LED_PROCESS_LIMIT * params->iter; \
44 if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL; 44 uint8_t max = min + LED_MATRIX_LED_PROCESS_LIMIT; \
45 if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL; \
46 uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT; \
47 if (is_keyboard_left() && (max > k_led_matrix_split[0])) max = k_led_matrix_split[0]; \
48 if (!(is_keyboard_left()) && (min < k_led_matrix_split[0])) min = k_led_matrix_split[0];
49# else
50# define LED_MATRIX_USE_LIMITS(min, max) \
51 uint8_t min = LED_MATRIX_LED_PROCESS_LIMIT * params->iter; \
52 uint8_t max = min + LED_MATRIX_LED_PROCESS_LIMIT; \
53 if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL;
54# endif
45#else 55#else
46# define LED_MATRIX_USE_LIMITS(min, max) \ 56# if defined(LED_MATRIX_SPLIT)
47 uint8_t min = 0; \ 57# define LED_MATRIX_USE_LIMITS(min, max) \
48 uint8_t max = DRIVER_LED_TOTAL; 58 uint8_t min = 0; \
59 uint8_t max = DRIVER_LED_TOTAL; \
60 const uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT; \
61 if (is_keyboard_left() && (max > k_led_matrix_split[0])) max = k_led_matrix_split[0]; \
62 if (!(is_keyboard_left()) && (min < k_led_matrix_split[0])) min = k_led_matrix_split[0];
63# else
64# define LED_MATRIX_USE_LIMITS(min, max) \
65 uint8_t min = 0; \
66 uint8_t max = DRIVER_LED_TOTAL;
67# endif
49#endif 68#endif
50 69
51#define LED_MATRIX_TEST_LED_FLAGS() \ 70#define LED_MATRIX_TEST_LED_FLAGS() \
@@ -147,6 +166,18 @@ typedef struct {
147 void (*flush)(void); 166 void (*flush)(void);
148} led_matrix_driver_t; 167} led_matrix_driver_t;
149 168
169static inline bool led_matrix_check_finished_leds(uint8_t led_idx) {
170#if defined(LED_MATRIX_SPLIT)
171 if (is_keyboard_left()) {
172 uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT;
173 return led_idx < k_led_matrix_split[0];
174 } else
175 return led_idx < DRIVER_LED_TOTAL;
176#else
177 return led_idx < DRIVER_LED_TOTAL;
178#endif
179}
180
150extern const led_matrix_driver_t led_matrix_driver; 181extern const led_matrix_driver_t led_matrix_driver;
151 182
152extern led_eeconfig_t led_matrix_eeconfig; 183extern led_eeconfig_t led_matrix_eeconfig;
diff --git a/quantum/led_matrix/led_matrix_drivers.c b/quantum/led_matrix/led_matrix_drivers.c
index 1d46b2c50..2157619a0 100644
--- a/quantum/led_matrix/led_matrix_drivers.c
+++ b/quantum/led_matrix/led_matrix_drivers.c
@@ -26,128 +26,123 @@
26 */ 26 */
27 27
28#if defined(IS31FL3731) || defined(IS31FL3733) 28#if defined(IS31FL3731) || defined(IS31FL3733)
29
30# include "i2c_master.h" 29# include "i2c_master.h"
31 30
32static void init(void) { 31static void init(void) {
33 i2c_init(); 32 i2c_init();
34# ifdef IS31FL3731 33
35# ifdef LED_DRIVER_ADDR_1 34# if defined(IS31FL3731)
36 IS31FL3731_init(LED_DRIVER_ADDR_1); 35 IS31FL3731_init(LED_DRIVER_ADDR_1);
37# endif 36# if defined(LED_DRIVER_ADDR_2)
38# ifdef LED_DRIVER_ADDR_2
39 IS31FL3731_init(LED_DRIVER_ADDR_2); 37 IS31FL3731_init(LED_DRIVER_ADDR_2);
40# endif 38# if defined(LED_DRIVER_ADDR_3)
41# ifdef LED_DRIVER_ADDR_3
42 IS31FL3731_init(LED_DRIVER_ADDR_3); 39 IS31FL3731_init(LED_DRIVER_ADDR_3);
43# endif 40# if defined(LED_DRIVER_ADDR_4)
44# ifdef LED_DRIVER_ADDR_4
45 IS31FL3731_init(LED_DRIVER_ADDR_4); 41 IS31FL3731_init(LED_DRIVER_ADDR_4);
46# endif 42# endif
47# else
48# ifdef LED_DRIVER_ADDR_1
49# ifndef LED_DRIVER_SYNC_1
50# define LED_DRIVER_SYNC_1 0
51# endif 43# endif
52 IS31FL3733_init(LED_DRIVER_ADDR_1, LED_DRIVER_SYNC_1);
53# endif 44# endif
54# ifdef LED_DRIVER_ADDR_2 45
55# ifndef LED_DRIVER_SYNC_2 46# elif defined(IS31FL3733)
47# if !defined(LED_DRIVER_SYNC_1)
48# define LED_DRIVER_SYNC_1 0
49# endif
50 IS31FL3733_init(LED_DRIVER_ADDR_1, LED_DRIVER_SYNC_1);
51# if defined(LED_DRIVER_ADDR_2)
52# if !defined(LED_DRIVER_SYNC_2)
56# define LED_DRIVER_SYNC_2 0 53# define LED_DRIVER_SYNC_2 0
57# endif 54# endif
58 IS31FL3733_init(LED_DRIVER_ADDR_2, LED_DRIVER_SYNC_2); 55 IS31FL3733_init(LED_DRIVER_ADDR_2, LED_DRIVER_SYNC_2);
59# endif 56# if defined(LED_DRIVER_ADDR_3)
60# ifdef LED_DRIVER_ADDR_3 57# if !defined(LED_DRIVER_SYNC_3)
61# ifndef LED_DRIVER_SYNC_3 58# define LED_DRIVER_SYNC_3 0
62# define LED_DRIVER_SYNC_3 0 59# endif
63# endif
64 IS31FL3733_init(LED_DRIVER_ADDR_3, LED_DRIVER_SYNC_3); 60 IS31FL3733_init(LED_DRIVER_ADDR_3, LED_DRIVER_SYNC_3);
65# endif 61# if defined(LED_DRIVER_ADDR_4)
66# ifdef LED_DRIVER_ADDR_4 62# if !defined(LED_DRIVER_SYNC_4)
67# ifndef LED_DRIVER_SYNC_4 63# define LED_DRIVER_SYNC_4 0
68# define LED_DRIVER_SYNC_4 0 64# endif
69# endif
70 IS31FL3733_init(LED_DRIVER_ADDR_4, LED_DRIVER_SYNC_4); 65 IS31FL3733_init(LED_DRIVER_ADDR_4, LED_DRIVER_SYNC_4);
66# endif
67# endif
71# endif 68# endif
72# endif 69# endif
73 70
74 for (int index = 0; index < DRIVER_LED_TOTAL; index++) { 71 for (int index = 0; index < DRIVER_LED_TOTAL; index++) {
75# ifdef IS31FL3731 72# if defined(IS31FL3731)
76 IS31FL3731_set_led_control_register(index, true); 73 IS31FL3731_set_led_control_register(index, true);
77# else 74# elif defined(IS31FL3733)
78 IS31FL3733_set_led_control_register(index, true); 75 IS31FL3733_set_led_control_register(index, true);
79# endif 76# endif
80 } 77 }
78
81// This actually updates the LED drivers 79// This actually updates the LED drivers
82# ifdef IS31FL3731 80# if defined(IS31FL3731)
83# ifdef LED_DRIVER_ADDR_1
84 IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_1, 0); 81 IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_1, 0);
85# endif 82# if defined(LED_DRIVER_ADDR_2)
86# ifdef LED_DRIVER_ADDR_2
87 IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_2, 1); 83 IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_2, 1);
88# endif 84# if defined(LED_DRIVER_ADDR_3)
89# ifdef LED_DRIVER_ADDR_3
90 IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_3, 2); 85 IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_3, 2);
91# endif 86# if defined(LED_DRIVER_ADDR_4)
92# ifdef LED_DRIVER_ADDR_4
93 IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_4, 3); 87 IS31FL3731_update_led_control_registers(LED_DRIVER_ADDR_4, 3);
88# endif
89# endif
94# endif 90# endif
95# else 91
96# ifdef LED_DRIVER_ADDR_1 92# elif defined(IS31FL3733)
97 IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_1, 0); 93 IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_1, 0);
98# endif 94# if defined(LED_DRIVER_ADDR_2)
99# ifdef LED_DRIVER_ADDR_2
100 IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_2, 1); 95 IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_2, 1);
101# endif 96# if defined(LED_DRIVER_ADDR_3)
102# ifdef LED_DRIVER_ADDR_3
103 IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_3, 2); 97 IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_3, 2);
104# endif 98# if defined(LED_DRIVER_ADDR_4)
105# ifdef LED_DRIVER_ADDR_4
106 IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_4, 3); 99 IS31FL3733_update_led_control_registers(LED_DRIVER_ADDR_4, 3);
100# endif
101# endif
107# endif 102# endif
108# endif 103# endif
109} 104}
110 105
106# if defined(IS31FL3731)
111static void flush(void) { 107static void flush(void) {
112# ifdef IS31FL3731
113# ifdef LED_DRIVER_ADDR_1
114 IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_1, 0); 108 IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_1, 0);
115# endif 109# if defined(LED_DRIVER_ADDR_2)
116# ifdef LED_DRIVER_ADDR_2
117 IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_2, 1); 110 IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_2, 1);
118# endif 111# if defined(LED_DRIVER_ADDR_3)
119# ifdef LED_DRIVER_ADDR_3
120 IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_3, 2); 112 IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_3, 2);
121# endif 113# if defined(LED_DRIVER_ADDR_4)
122# ifdef LED_DRIVER_ADDR_4
123 IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_4, 3); 114 IS31FL3731_update_pwm_buffers(LED_DRIVER_ADDR_4, 3);
115# endif
116# endif
124# endif 117# endif
125# else 118}
126# ifdef LED_DRIVER_ADDR_1 119
120const led_matrix_driver_t led_matrix_driver = {
121 .init = init,
122 .flush = flush,
123 .set_value = IS31FL3731_set_value,
124 .set_value_all = IS31FL3731_set_value_all,
125};
126
127# elif defined(IS31FL3733)
128static void flush(void) {
127 IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_1, 0); 129 IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_1, 0);
128# endif 130# if defined(LED_DRIVER_ADDR_2)
129# ifdef LED_DRIVER_ADDR_2
130 IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_2, 1); 131 IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_2, 1);
131# endif 132# if defined(LED_DRIVER_ADDR_3)
132# ifdef LED_DRIVER_ADDR_3
133 IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_3, 2); 133 IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_3, 2);
134# endif 134# if defined(LED_DRIVER_ADDR_4)
135# ifdef LED_DRIVER_ADDR_4
136 IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_4, 3); 135 IS31FL3733_update_pwm_buffers(LED_DRIVER_ADDR_4, 3);
136# endif
137# endif
137# endif 138# endif
138# endif
139} 139}
140 140
141const led_matrix_driver_t led_matrix_driver = { 141const led_matrix_driver_t led_matrix_driver = {
142 .init = init, 142 .init = init,
143 .flush = flush, 143 .flush = flush,
144# ifdef IS31FL3731
145 .set_value = IS31FL3731_set_value,
146 .set_value_all = IS31FL3731_set_value_all,
147# else
148 .set_value = IS31FL3733_set_value, 144 .set_value = IS31FL3733_set_value,
149 .set_value_all = IS31FL3733_set_value_all, 145 .set_value_all = IS31FL3733_set_value_all,
150# endif
151}; 146};
152 147# endif
153#endif 148#endif