1 /* Copyright 2017 Jason Williams
2 * Copyright 2017 Jack Humbert
3 * Copyright 2018 Yiancar
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "rgb_matrix.h"
27 #include "lib/lib8tion/lib8tion.h"
29 #include "rgb_matrix_animations/solid_color_anim.h"
30 #include "rgb_matrix_animations/alpha_mods_anim.h"
31 #include "rgb_matrix_animations/dual_beacon_anim.h"
32 #include "rgb_matrix_animations/gradient_up_down_anim.h"
33 #include "rgb_matrix_animations/raindrops_anim.h"
34 #include "rgb_matrix_animations/cycle_all_anim.h"
35 #include "rgb_matrix_animations/cycle_left_right_anim.h"
36 #include "rgb_matrix_animations/cycle_up_down_anim.h"
37 #include "rgb_matrix_animations/rainbow_beacon_anim.h"
38 #include "rgb_matrix_animations/rainbow_pinwheels_anim.h"
39 #include "rgb_matrix_animations/rainbow_moving_chevron_anim.h"
40 #include "rgb_matrix_animations/jellybean_raindrops_anim.h"
41 #include "rgb_matrix_animations/digital_rain_anim.h"
42 #include "rgb_matrix_animations/solid_reactive_simple_anim.h"
43 #include "rgb_matrix_animations/solid_reactive_anim.h"
44 #include "rgb_matrix_animations/splash_anim.h"
45 #include "rgb_matrix_animations/solid_splash_anim.h"
46 #include "rgb_matrix_animations/breathing_anim.h"
48 #ifndef RGB_DISABLE_AFTER_TIMEOUT
49 #define RGB_DISABLE_AFTER_TIMEOUT 0
52 #ifndef RGB_DISABLE_WHEN_USB_SUSPENDED
53 #define RGB_DISABLE_WHEN_USB_SUSPENDED false
56 #ifndef EECONFIG_RGB_MATRIX
57 #define EECONFIG_RGB_MATRIX EECONFIG_RGBLIGHT
60 #if !defined(RGB_MATRIX_MAXIMUM_BRIGHTNESS) || RGB_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX
61 #undef RGB_MATRIX_MAXIMUM_BRIGHTNESS
62 #define RGB_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX
65 #if !defined(RGB_MATRIX_HUE_STEP)
66 #define RGB_MATRIX_HUE_STEP 8
69 #if !defined(RGB_MATRIX_SAT_STEP)
70 #define RGB_MATRIX_SAT_STEP 16
73 #if !defined(RGB_MATRIX_VAL_STEP)
74 #define RGB_MATRIX_VAL_STEP 16
77 #if !defined(RGB_MATRIX_SPD_STEP)
78 #define RGB_MATRIX_SPD_STEP 16
81 bool g_suspend_state = false;
83 rgb_config_t rgb_matrix_config;
85 rgb_counters_t g_rgb_counters;
86 static uint32_t rgb_counters_buffer;
88 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
89 last_hit_t g_last_hit_tracker;
90 static last_hit_t last_hit_buffer;
91 #endif // RGB_MATRIX_KEYREACTIVE_ENABLED
93 uint32_t eeconfig_read_rgb_matrix(void) {
94 return eeprom_read_dword(EECONFIG_RGB_MATRIX);
97 void eeconfig_update_rgb_matrix(uint32_t val) {
98 eeprom_update_dword(EECONFIG_RGB_MATRIX, val);
101 void eeconfig_update_rgb_matrix_default(void) {
102 dprintf("eeconfig_update_rgb_matrix_default\n");
103 rgb_matrix_config.enable = 1;
104 #ifndef DISABLE_RGB_MATRIX_CYCLE_ALL
105 rgb_matrix_config.mode = RGB_MATRIX_CYCLE_LEFT_RIGHT;
107 // fallback to solid colors if RGB_MATRIX_CYCLE_LEFT_RIGHT is disabled in userspace
108 rgb_matrix_config.mode = RGB_MATRIX_SOLID_COLOR;
110 rgb_matrix_config.hue = 0;
111 rgb_matrix_config.sat = UINT8_MAX;
112 rgb_matrix_config.val = RGB_MATRIX_MAXIMUM_BRIGHTNESS;
113 rgb_matrix_config.speed = UINT8_MAX / 2;
114 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
117 void eeconfig_debug_rgb_matrix(void) {
118 dprintf("rgb_matrix_config eprom\n");
119 dprintf("rgb_matrix_config.enable = %d\n", rgb_matrix_config.enable);
120 dprintf("rgb_matrix_config.mode = %d\n", rgb_matrix_config.mode);
121 dprintf("rgb_matrix_config.hue = %d\n", rgb_matrix_config.hue);
122 dprintf("rgb_matrix_config.sat = %d\n", rgb_matrix_config.sat);
123 dprintf("rgb_matrix_config.val = %d\n", rgb_matrix_config.val);
124 dprintf("rgb_matrix_config.speed = %d\n", rgb_matrix_config.speed);
127 uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) {
128 // TODO: This is kinda expensive, fix this soonish
129 uint8_t led_count = 0;
130 for (uint8_t i = 0; i < DRIVER_LED_TOTAL && led_count < LED_HITS_TO_REMEMBER; i++) {
131 matrix_co_t matrix_co = g_rgb_leds[i].matrix_co;
132 if (row == matrix_co.row && column == matrix_co.col) {
133 led_i[led_count] = i;
140 void rgb_matrix_update_pwm_buffers(void) {
141 rgb_matrix_driver.flush();
144 void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) {
145 rgb_matrix_driver.set_color(index, red, green, blue);
148 void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) {
149 rgb_matrix_driver.set_color_all(red, green, blue);
152 bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) {
153 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
154 uint8_t led[LED_HITS_TO_REMEMBER];
155 uint8_t led_count = 0;
157 #if defined(RGB_MATRIX_KEYRELEASES)
158 if (!record->event.pressed) {
159 led_count = rgb_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led);
160 g_rgb_counters.any_key_hit = 0;
162 #elif defined(RGB_MATRIX_KEYPRESSES)
163 if (record->event.pressed) {
164 led_count = rgb_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led);
165 g_rgb_counters.any_key_hit = 0;
167 #endif // defined(RGB_MATRIX_KEYRELEASES)
169 if (last_hit_buffer.count + led_count > LED_HITS_TO_REMEMBER) {
170 memcpy(&last_hit_buffer.x[0], &last_hit_buffer.x[led_count], LED_HITS_TO_REMEMBER - led_count);
171 memcpy(&last_hit_buffer.y[0], &last_hit_buffer.y[led_count], LED_HITS_TO_REMEMBER - led_count);
172 memcpy(&last_hit_buffer.tick[0], &last_hit_buffer.tick[led_count], (LED_HITS_TO_REMEMBER - led_count) * 2); // 16 bit
173 memcpy(&last_hit_buffer.index[0], &last_hit_buffer.index[led_count], LED_HITS_TO_REMEMBER - led_count);
174 last_hit_buffer.count--;
177 for(uint8_t i = 0; i < led_count; i++) {
178 uint8_t index = last_hit_buffer.count;
179 last_hit_buffer.x[index] = g_rgb_leds[led[i]].point.x;
180 last_hit_buffer.y[index] = g_rgb_leds[led[i]].point.y;
181 last_hit_buffer.index[index] = led[i];
182 last_hit_buffer.tick[index] = 0;
183 last_hit_buffer.count++;
185 #endif // RGB_MATRIX_KEYREACTIVE_ENABLED
189 void rgb_matrix_test(void) {
190 // Mask out bits 4 and 5
191 // Increase the factor to make the test animation slower (and reduce to make it faster)
193 switch ( (g_rgb_counters.tick & (0b11 << factor)) >> factor )
196 rgb_matrix_set_color_all( 20, 0, 0 );
200 rgb_matrix_set_color_all( 0, 20, 0 );
204 rgb_matrix_set_color_all( 0, 0, 20 );
208 rgb_matrix_set_color_all( 20, 20, 20 );
214 static bool rgb_matrix_none(effect_params_t* params) {
219 RGB_MATRIX_USE_LIMITS(led_min, led_max);
220 for (uint8_t i = led_min; i < led_max; i++) {
221 rgb_matrix_set_color(i, 0, 0, 0);
223 return led_max < DRIVER_LED_TOTAL;
226 static uint8_t rgb_last_enable = UINT8_MAX;
227 static uint8_t rgb_last_effect = UINT8_MAX;
228 static effect_params_t rgb_effect_params = { 0, 0 };
229 static rgb_task_states rgb_task_state = SYNCING;
231 static void rgb_task_timers(void) {
232 // Update double buffer timers
233 uint16_t deltaTime = timer_elapsed32(rgb_counters_buffer);
234 rgb_counters_buffer = timer_read32();
235 if (g_rgb_counters.any_key_hit < UINT32_MAX) {
236 if (UINT32_MAX - deltaTime < g_rgb_counters.any_key_hit) {
237 g_rgb_counters.any_key_hit = UINT32_MAX;
239 g_rgb_counters.any_key_hit += deltaTime;
243 // Update double buffer last hit timers
244 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
245 uint8_t count = last_hit_buffer.count;
246 for (uint8_t i = 0; i < count; ++i) {
247 if (UINT16_MAX - deltaTime < last_hit_buffer.tick[i]) {
248 last_hit_buffer.count--;
251 last_hit_buffer.tick[i] += deltaTime;
253 #endif // RGB_MATRIX_KEYREACTIVE_ENABLED
256 static void rgb_task_sync(void) {
258 if (timer_elapsed32(g_rgb_counters.tick) >= RGB_MATRIX_LED_FLUSH_LIMIT)
259 rgb_task_state = STARTING;
262 static void rgb_task_start(void) {
264 rgb_effect_params.iter = 0;
266 // update double buffers
267 g_rgb_counters.tick = rgb_counters_buffer;
268 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
269 g_last_hit_tracker = last_hit_buffer;
270 #endif // RGB_MATRIX_KEYREACTIVE_ENABLED
273 rgb_task_state = RENDERING;
276 static void rgb_task_render(uint8_t effect) {
277 bool rendering = false;
278 rgb_effect_params.init = (effect != rgb_last_effect) || (rgb_matrix_config.enable != rgb_last_enable);
280 // each effect can opt to do calculations
281 // and/or request PWM buffer updates.
283 case RGB_MATRIX_NONE:
284 rendering = rgb_matrix_none(&rgb_effect_params);
287 case RGB_MATRIX_SOLID_COLOR:
288 rendering = rgb_matrix_solid_color(&rgb_effect_params); // Max 1ms Avg 0ms
290 #ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS
291 case RGB_MATRIX_ALPHAS_MODS:
292 rendering = rgb_matrix_alphas_mods(&rgb_effect_params); // Max 2ms Avg 1ms
294 #endif // DISABLE_RGB_MATRIX_ALPHAS_MODS
295 #ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
296 case RGB_MATRIX_GRADIENT_UP_DOWN:
297 rendering = rgb_matrix_gradient_up_down(&rgb_effect_params); // Max 4ms Avg 3ms
299 #endif // DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
300 #ifndef DISABLE_RGB_MATRIX_BREATHING
301 case RGB_MATRIX_BREATHING:
302 rendering = rgb_matrix_breathing(&rgb_effect_params); // Max 1ms Avg 0ms
304 #endif // DISABLE_RGB_MATRIX_BREATHING
305 #ifndef DISABLE_RGB_MATRIX_CYCLE_ALL
306 case RGB_MATRIX_CYCLE_ALL:
307 rendering = rgb_matrix_cycle_all(&rgb_effect_params); // Max 4ms Avg 3ms
309 #endif // DISABLE_RGB_MATRIX_CYCLE_ALL
310 #ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
311 case RGB_MATRIX_CYCLE_LEFT_RIGHT:
312 rendering = rgb_matrix_cycle_left_right(&rgb_effect_params); // Max 4ms Avg 3ms
314 #endif // DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
315 #ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
316 case RGB_MATRIX_CYCLE_UP_DOWN:
317 rendering = rgb_matrix_cycle_up_down(&rgb_effect_params); // Max 4ms Avg 3ms
319 #endif // DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
320 #ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
321 case RGB_MATRIX_RAINBOW_MOVING_CHEVRON:
322 rendering = rgb_matrix_rainbow_moving_chevron(&rgb_effect_params); // Max 4ms Avg 3ms
324 #endif // DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
325 #ifndef DISABLE_RGB_MATRIX_DUAL_BEACON
326 case RGB_MATRIX_DUAL_BEACON:
327 rendering = rgb_matrix_dual_beacon(&rgb_effect_params); // Max 4ms Avg 3ms
329 #endif // DISABLE_RGB_MATRIX_DUAL_BEACON
330 #ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON
331 case RGB_MATRIX_RAINBOW_BEACON:
332 rendering = rgb_matrix_rainbow_beacon(&rgb_effect_params); // Max 4ms Avg 3ms
334 #endif // DISABLE_RGB_MATRIX_RAINBOW_BEACON
335 #ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
336 case RGB_MATRIX_RAINBOW_PINWHEELS:
337 rendering = rgb_matrix_rainbow_pinwheels(&rgb_effect_params); // Max 4ms Avg 3ms
339 #endif // DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
340 #ifndef DISABLE_RGB_MATRIX_RAINDROPS
341 case RGB_MATRIX_RAINDROPS:
342 rendering = rgb_matrix_raindrops(&rgb_effect_params); // Max 1ms Avg 0ms
344 #endif // DISABLE_RGB_MATRIX_RAINDROPS
345 #ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
346 case RGB_MATRIX_JELLYBEAN_RAINDROPS:
347 rendering = rgb_matrix_jellybean_raindrops(&rgb_effect_params); // Max 1ms Avg 0ms
349 #endif // DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
350 #ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN
351 case RGB_MATRIX_DIGITAL_RAIN:
352 rendering = rgb_matrix_digital_rain(&rgb_effect_params); // Max 9ms Avg 8ms | this is expensive, fix it
354 #endif // DISABLE_RGB_MATRIX_DIGITAL_RAIN
355 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
356 #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
357 case RGB_MATRIX_SOLID_REACTIVE_SIMPLE:
358 rendering = rgb_matrix_solid_reactive_simple(&rgb_effect_params);// Max 4ms Avg 3ms
361 #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE
362 case RGB_MATRIX_SOLID_REACTIVE:
363 rendering = rgb_matrix_solid_reactive(&rgb_effect_params); // Max 4ms Avg 3ms
365 #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE
366 #ifndef DISABLE_RGB_MATRIX_SPLASH
367 case RGB_MATRIX_SPLASH:
368 rendering = rgb_matrix_splash(&rgb_effect_params); // Max 5ms Avg 3ms
370 #endif // DISABLE_RGB_MATRIX_SPLASH
371 #ifndef DISABLE_RGB_MATRIX_MULTISPLASH
372 case RGB_MATRIX_MULTISPLASH:
373 rendering = rgb_matrix_multisplash(&rgb_effect_params); // Max 10ms Avg 5ms
375 #endif // DISABLE_RGB_MATRIX_MULTISPLASH
376 #ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH
377 case RGB_MATRIX_SOLID_SPLASH:
378 rendering = rgb_matrix_solid_splash(&rgb_effect_params); // Max 5ms Avg 3ms
380 #endif // DISABLE_RGB_MATRIX_SOLID_SPLASH
381 #ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
382 case RGB_MATRIX_SOLID_MULTISPLASH:
383 rendering = rgb_matrix_solid_multisplash(&rgb_effect_params); // Max 10ms Avg 5ms
385 #endif // DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
386 #endif // RGB_MATRIX_KEYREACTIVE_ENABLED
388 // Factory default magic value
391 rgb_task_state = FLUSHING;
396 rgb_effect_params.iter++;
400 rgb_task_state = FLUSHING;
401 if (!rgb_effect_params.init && effect == RGB_MATRIX_NONE) {
402 // We only need to flush once if we are RGB_MATRIX_NONE
403 rgb_task_state = SYNCING;
408 static void rgb_task_flush(uint8_t effect) {
409 // update last trackers after the first full render so we can init over several frames
410 rgb_last_effect = effect;
411 rgb_last_enable = rgb_matrix_config.enable;
413 // update pwm buffers
414 rgb_matrix_update_pwm_buffers();
417 rgb_task_state = SYNCING;
420 void rgb_matrix_task(void) {
423 // Ideally we would also stop sending zeros to the LED driver PWM buffers
424 // while suspended and just do a software shutdown. This is a cheap hack for now.
425 bool suspend_backlight = ((g_suspend_state && RGB_DISABLE_WHEN_USB_SUSPENDED) || (RGB_DISABLE_AFTER_TIMEOUT > 0 && g_rgb_counters.any_key_hit > RGB_DISABLE_AFTER_TIMEOUT * 60 * 20));
426 uint8_t effect = suspend_backlight || !rgb_matrix_config.enable ? 0 : rgb_matrix_config.mode;
428 switch (rgb_task_state) {
433 rgb_task_render(effect);
436 rgb_task_flush(effect);
443 if (!suspend_backlight) {
444 rgb_matrix_indicators();
448 void rgb_matrix_indicators(void) {
449 rgb_matrix_indicators_kb();
450 rgb_matrix_indicators_user();
453 __attribute__((weak))
454 void rgb_matrix_indicators_kb(void) {}
456 __attribute__((weak))
457 void rgb_matrix_indicators_user(void) {}
459 void rgb_matrix_init(void) {
460 rgb_matrix_driver.init();
462 // TODO: put the 1 second startup delay here?
464 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
465 g_last_hit_tracker.count = 0;
466 for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) {
467 g_last_hit_tracker.tick[i] = UINT16_MAX;
470 last_hit_buffer.count = 0;
471 for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) {
472 last_hit_buffer.tick[i] = UINT16_MAX;
474 #endif // RGB_MATRIX_KEYREACTIVE_ENABLED
476 if (!eeconfig_is_enabled()) {
477 dprintf("rgb_matrix_init_drivers eeconfig is not enabled.\n");
479 eeconfig_update_rgb_matrix_default();
482 rgb_matrix_config.raw = eeconfig_read_rgb_matrix();
483 rgb_matrix_config.speed = UINT8_MAX / 2; //EECONFIG needs to be increased to support this
484 if (!rgb_matrix_config.mode) {
485 dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n");
486 eeconfig_update_rgb_matrix_default();
487 rgb_matrix_config.raw = eeconfig_read_rgb_matrix();
489 eeconfig_debug_rgb_matrix(); // display current eeprom values
492 void rgb_matrix_set_suspend_state(bool state) {
493 g_suspend_state = state;
496 void rgb_matrix_toggle(void) {
497 rgb_matrix_config.enable ^= 1;
498 if (!rgb_matrix_config.enable) {
499 rgb_task_state = STARTING;
501 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
504 void rgb_matrix_enable(void) {
505 rgb_matrix_config.enable = 1;
506 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
509 void rgb_matrix_enable_noeeprom(void) {
510 rgb_matrix_config.enable = 1;
513 void rgb_matrix_disable(void) {
514 rgb_matrix_config.enable = 0;
515 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
518 void rgb_matrix_disable_noeeprom(void) {
519 rgb_matrix_config.enable = 0;
522 void rgb_matrix_step(void) {
523 rgb_matrix_config.mode++;
524 if (rgb_matrix_config.mode >= RGB_MATRIX_EFFECT_MAX)
525 rgb_matrix_config.mode = 1;
526 rgb_task_state = STARTING;
527 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
530 void rgb_matrix_step_reverse(void) {
531 rgb_matrix_config.mode--;
532 if (rgb_matrix_config.mode < 1)
533 rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1;
534 rgb_task_state = STARTING;
535 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
538 void rgb_matrix_increase_hue(void) {
539 rgb_matrix_config.hue += RGB_MATRIX_HUE_STEP;
540 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
543 void rgb_matrix_decrease_hue(void) {
544 rgb_matrix_config.hue -= RGB_MATRIX_HUE_STEP;
545 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
548 void rgb_matrix_increase_sat(void) {
549 rgb_matrix_config.sat = qadd8(rgb_matrix_config.sat, RGB_MATRIX_SAT_STEP);
550 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
553 void rgb_matrix_decrease_sat(void) {
554 rgb_matrix_config.sat = qsub8(rgb_matrix_config.sat, RGB_MATRIX_SAT_STEP);
555 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
558 void rgb_matrix_increase_val(void) {
559 rgb_matrix_config.val = qadd8(rgb_matrix_config.val, RGB_MATRIX_VAL_STEP);
560 if (rgb_matrix_config.val > RGB_MATRIX_MAXIMUM_BRIGHTNESS)
561 rgb_matrix_config.val = RGB_MATRIX_MAXIMUM_BRIGHTNESS;
562 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
565 void rgb_matrix_decrease_val(void) {
566 rgb_matrix_config.val = qsub8(rgb_matrix_config.val, RGB_MATRIX_VAL_STEP);
567 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
570 void rgb_matrix_increase_speed(void) {
571 rgb_matrix_config.speed = qadd8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP);
572 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this
575 void rgb_matrix_decrease_speed(void) {
576 rgb_matrix_config.speed = qsub8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP);
577 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this
580 void rgb_matrix_mode(uint8_t mode) {
581 rgb_matrix_config.mode = mode;
582 rgb_task_state = STARTING;
583 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
586 void rgb_matrix_mode_noeeprom(uint8_t mode) {
587 rgb_matrix_config.mode = mode;
590 uint8_t rgb_matrix_get_mode(void) {
591 return rgb_matrix_config.mode;
594 void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val) {
595 rgb_matrix_sethsv_noeeprom(hue, sat, val);
596 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
599 void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) {
600 rgb_matrix_config.hue = hue;
601 rgb_matrix_config.sat = sat;
602 rgb_matrix_config.val = val;
603 if (rgb_matrix_config.val > RGB_MATRIX_MAXIMUM_BRIGHTNESS)
604 rgb_matrix_config.val = RGB_MATRIX_MAXIMUM_BRIGHTNESS;