aboutsummaryrefslogtreecommitdiff
path: root/quantum/rgb_matrix.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/rgb_matrix.c')
-rw-r--r--quantum/rgb_matrix.c61
1 files changed, 42 insertions, 19 deletions
diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c
index ec17b4d72..e716c6aad 100644
--- a/quantum/rgb_matrix.c
+++ b/quantum/rgb_matrix.c
@@ -26,9 +26,9 @@
26#include <lib/lib8tion/lib8tion.h> 26#include <lib/lib8tion/lib8tion.h>
27 27
28#ifndef RGB_MATRIX_CENTER 28#ifndef RGB_MATRIX_CENTER
29const point_t k_rgb_matrix_center = {112, 32}; 29const led_point_t k_rgb_matrix_center = {112, 32};
30#else 30#else
31const 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__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); }
@@ -67,8 +67,8 @@ __attribute__((weak)) RGB rgb_matrix_hsv_to_rgb(HSV hsv) { return hsv_to_rgb(hsv
67# define RGB_DISABLE_TIMEOUT 0 67# define RGB_DISABLE_TIMEOUT 0
68#endif 68#endif
69 69
70#ifndef RGB_DISABLE_WHEN_USB_SUSPENDED 70#if RGB_DISABLE_WHEN_USB_SUSPENDED == false
71# define RGB_DISABLE_WHEN_USB_SUSPENDED false 71# undef RGB_DISABLE_WHEN_USB_SUSPENDED
72#endif 72#endif
73 73
74#if !defined(RGB_MATRIX_MAXIMUM_BRIGHTNESS) || RGB_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX 74#if !defined(RGB_MATRIX_MAXIMUM_BRIGHTNESS) || RGB_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX
@@ -118,7 +118,6 @@ __attribute__((weak)) RGB rgb_matrix_hsv_to_rgb(HSV hsv) { return hsv_to_rgb(hsv
118#endif 118#endif
119 119
120// globals 120// globals
121bool g_suspend_state = false;
122rgb_config_t rgb_matrix_config; // TODO: would like to prefix this with g_ for global consistancy, do this in another pr 121rgb_config_t rgb_matrix_config; // TODO: would like to prefix this with g_ for global consistancy, do this in another pr
123uint32_t g_rgb_timer; 122uint32_t g_rgb_timer;
124#ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS 123#ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS
@@ -129,9 +128,10 @@ last_hit_t g_last_hit_tracker;
129#endif // RGB_MATRIX_KEYREACTIVE_ENABLED 128#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
130 129
131// internals 130// internals
131static bool suspend_state = false;
132static uint8_t rgb_last_enable = UINT8_MAX; 132static uint8_t rgb_last_enable = UINT8_MAX;
133static uint8_t rgb_last_effect = UINT8_MAX; 133static uint8_t rgb_last_effect = UINT8_MAX;
134static effect_params_t rgb_effect_params = {0, 0xFF}; 134static effect_params_t rgb_effect_params = {0, LED_FLAG_ALL, false};
135static rgb_task_states rgb_task_state = SYNCING; 135static rgb_task_states rgb_task_state = SYNCING;
136#if RGB_DISABLE_TIMEOUT > 0 136#if RGB_DISABLE_TIMEOUT > 0
137static uint32_t rgb_anykey_timer; 137static uint32_t rgb_anykey_timer;
@@ -143,6 +143,11 @@ static uint32_t rgb_timer_buffer;
143static last_hit_t last_hit_buffer; 143static last_hit_t last_hit_buffer;
144#endif // RGB_MATRIX_KEYREACTIVE_ENABLED 144#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
145 145
146// split rgb matrix
147#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
148const uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT;
149#endif
150
146void eeconfig_read_rgb_matrix(void) { eeprom_read_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); } 151void eeconfig_read_rgb_matrix(void) { eeprom_read_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); }
147 152
148void eeconfig_update_rgb_matrix(void) { eeprom_update_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); } 153void eeconfig_update_rgb_matrix(void) { eeprom_update_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); }
@@ -153,6 +158,7 @@ void eeconfig_update_rgb_matrix_default(void) {
153 rgb_matrix_config.mode = RGB_MATRIX_STARTUP_MODE; 158 rgb_matrix_config.mode = RGB_MATRIX_STARTUP_MODE;
154 rgb_matrix_config.hsv = (HSV){RGB_MATRIX_STARTUP_HUE, RGB_MATRIX_STARTUP_SAT, RGB_MATRIX_STARTUP_VAL}; 159 rgb_matrix_config.hsv = (HSV){RGB_MATRIX_STARTUP_HUE, RGB_MATRIX_STARTUP_SAT, RGB_MATRIX_STARTUP_VAL};
155 rgb_matrix_config.speed = RGB_MATRIX_STARTUP_SPD; 160 rgb_matrix_config.speed = RGB_MATRIX_STARTUP_SPD;
161 rgb_matrix_config.flags = LED_FLAG_ALL;
156 eeconfig_update_rgb_matrix(); 162 eeconfig_update_rgb_matrix();
157} 163}
158 164
@@ -164,6 +170,7 @@ void eeconfig_debug_rgb_matrix(void) {
164 dprintf("rgb_matrix_config.hsv.s = %d\n", rgb_matrix_config.hsv.s); 170 dprintf("rgb_matrix_config.hsv.s = %d\n", rgb_matrix_config.hsv.s);
165 dprintf("rgb_matrix_config.hsv.v = %d\n", rgb_matrix_config.hsv.v); 171 dprintf("rgb_matrix_config.hsv.v = %d\n", rgb_matrix_config.hsv.v);
166 dprintf("rgb_matrix_config.speed = %d\n", rgb_matrix_config.speed); 172 dprintf("rgb_matrix_config.speed = %d\n", rgb_matrix_config.speed);
173 dprintf("rgb_matrix_config.flags = %d\n", rgb_matrix_config.flags);
167} 174}
168 175
169__attribute__((weak)) uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i) { return 0; } 176__attribute__((weak)) uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i) { return 0; }
@@ -180,9 +187,22 @@ uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *l
180 187
181void rgb_matrix_update_pwm_buffers(void) { rgb_matrix_driver.flush(); } 188void rgb_matrix_update_pwm_buffers(void) { rgb_matrix_driver.flush(); }
182 189
183void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { rgb_matrix_driver.set_color(index, red, green, blue); } 190void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t 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}
184 198
185void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { rgb_matrix_driver.set_color_all(red, green, blue); } 199void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
200#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
201 for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) rgb_matrix_set_color(i, red, green, blue);
202#else
203 rgb_matrix_driver.set_color_all(red, green, blue);
204#endif
205}
186 206
187void process_rgb_matrix(uint8_t row, uint8_t col, bool pressed) { 207void process_rgb_matrix(uint8_t row, uint8_t col, bool pressed) {
188#ifndef RGB_MATRIX_SPLIT 208#ifndef RGB_MATRIX_SPLIT
@@ -315,6 +335,10 @@ static void rgb_task_start(void) {
315static void rgb_task_render(uint8_t effect) { 335static void rgb_task_render(uint8_t effect) {
316 bool rendering = false; 336 bool rendering = false;
317 rgb_effect_params.init = (effect != rgb_last_effect) || (rgb_matrix_config.enable != rgb_last_enable); 337 rgb_effect_params.init = (effect != rgb_last_effect) || (rgb_matrix_config.enable != rgb_last_enable);
338 if (rgb_effect_params.flags != rgb_matrix_config.flags) {
339 rgb_effect_params.flags = rgb_matrix_config.flags;
340 rgb_matrix_set_color_all(0, 0, 0);
341 }
318 342
319 // each effect can opt to do calculations 343 // each effect can opt to do calculations
320 // and/or request PWM buffer updates. 344 // and/or request PWM buffer updates.
@@ -385,14 +409,11 @@ void rgb_matrix_task(void) {
385 409
386 // Ideally we would also stop sending zeros to the LED driver PWM buffers 410 // Ideally we would also stop sending zeros to the LED driver PWM buffers
387 // while suspended and just do a software shutdown. This is a cheap hack for now. 411 // while suspended and just do a software shutdown. This is a cheap hack for now.
388 bool suspend_backlight = 412 bool suspend_backlight = suspend_state ||
389#if RGB_DISABLE_WHEN_USB_SUSPENDED == true
390 g_suspend_state ||
391#endif // RGB_DISABLE_WHEN_USB_SUSPENDED == true
392#if RGB_DISABLE_TIMEOUT > 0 413#if RGB_DISABLE_TIMEOUT > 0
393 (rgb_anykey_timer > (uint32_t)RGB_DISABLE_TIMEOUT) || 414 (rgb_anykey_timer > (uint32_t)RGB_DISABLE_TIMEOUT) ||
394#endif // RGB_DISABLE_TIMEOUT > 0 415#endif // RGB_DISABLE_TIMEOUT > 0
395 false; 416 false;
396 417
397 uint8_t effect = suspend_backlight || !rgb_matrix_config.enable ? 0 : rgb_matrix_config.mode; 418 uint8_t effect = suspend_backlight || !rgb_matrix_config.enable ? 0 : rgb_matrix_config.mode;
398 419
@@ -477,13 +498,15 @@ void rgb_matrix_init(void) {
477} 498}
478 499
479void rgb_matrix_set_suspend_state(bool state) { 500void rgb_matrix_set_suspend_state(bool state) {
480 if (RGB_DISABLE_WHEN_USB_SUSPENDED && state) { 501#ifdef RGB_DISABLE_WHEN_USB_SUSPENDED
502 if (state) {
481 rgb_matrix_set_color_all(0, 0, 0); // turn off all LEDs when suspending 503 rgb_matrix_set_color_all(0, 0, 0); // turn off all LEDs when suspending
482 } 504 }
483 g_suspend_state = state; 505 suspend_state = state;
506#endif
484} 507}
485 508
486bool rgb_matrix_get_suspend_state(void) { return g_suspend_state; } 509bool rgb_matrix_get_suspend_state(void) { return suspend_state; }
487 510
488void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) { 511void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) {
489 rgb_matrix_config.enable ^= 1; 512 rgb_matrix_config.enable ^= 1;
@@ -618,6 +641,6 @@ void rgb_matrix_decrease_speed_helper(bool write_to_eeprom) { rgb_matrix_set_spe
618void rgb_matrix_decrease_speed_noeeprom(void) { rgb_matrix_decrease_speed_helper(false); } 641void rgb_matrix_decrease_speed_noeeprom(void) { rgb_matrix_decrease_speed_helper(false); }
619void rgb_matrix_decrease_speed(void) { rgb_matrix_decrease_speed_helper(true); } 642void rgb_matrix_decrease_speed(void) { rgb_matrix_decrease_speed_helper(true); }
620 643
621led_flags_t rgb_matrix_get_flags(void) { return rgb_effect_params.flags; } 644led_flags_t rgb_matrix_get_flags(void) { return rgb_matrix_config.flags; }
622 645
623void rgb_matrix_set_flags(led_flags_t flags) { rgb_effect_params.flags = flags; } 646void rgb_matrix_set_flags(led_flags_t flags) { rgb_matrix_config.flags = flags; }