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_LEFT_RIGHT
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 #ifdef RGB_MATRIX_EXTRA_TOG
146 const bool is_key = g_rgb_leds[index].matrix_co.raw != 0xff;
148 (rgb_matrix_config.enable == RGB_ZONE_KEYS && !is_key) ||
149 (rgb_matrix_config.enable == RGB_ZONE_UNDER && is_key)
151 rgb_matrix_driver.set_color(index, 0, 0, 0);
156 rgb_matrix_driver.set_color(index, red, green, blue);
159 void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) {
160 #ifdef RGB_MATRIX_EXTRA_TOG
161 for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
162 rgb_matrix_set_color(i, red, green, blue);
165 rgb_matrix_driver.set_color_all(red, green, blue);
169 bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) {
170 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
171 uint8_t led[LED_HITS_TO_REMEMBER];
172 uint8_t led_count = 0;
174 #if defined(RGB_MATRIX_KEYRELEASES)
175 if (!record->event.pressed) {
176 led_count = rgb_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led);
177 g_rgb_counters.any_key_hit = 0;
179 #elif defined(RGB_MATRIX_KEYPRESSES)
180 if (record->event.pressed) {
181 led_count = rgb_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led);
182 g_rgb_counters.any_key_hit = 0;
184 #endif // defined(RGB_MATRIX_KEYRELEASES)
186 if (last_hit_buffer.count + led_count > LED_HITS_TO_REMEMBER) {
187 memcpy(&last_hit_buffer.x[0], &last_hit_buffer.x[led_count], LED_HITS_TO_REMEMBER - led_count);
188 memcpy(&last_hit_buffer.y[0], &last_hit_buffer.y[led_count], LED_HITS_TO_REMEMBER - led_count);
189 memcpy(&last_hit_buffer.tick[0], &last_hit_buffer.tick[led_count], (LED_HITS_TO_REMEMBER - led_count) * 2); // 16 bit
190 memcpy(&last_hit_buffer.index[0], &last_hit_buffer.index[led_count], LED_HITS_TO_REMEMBER - led_count);
191 last_hit_buffer.count--;
194 for(uint8_t i = 0; i < led_count; i++) {
195 uint8_t index = last_hit_buffer.count;
196 last_hit_buffer.x[index] = g_rgb_leds[led[i]].point.x;
197 last_hit_buffer.y[index] = g_rgb_leds[led[i]].point.y;
198 last_hit_buffer.index[index] = led[i];
199 last_hit_buffer.tick[index] = 0;
200 last_hit_buffer.count++;
202 #endif // RGB_MATRIX_KEYREACTIVE_ENABLED
206 void rgb_matrix_test(void) {
207 // Mask out bits 4 and 5
208 // Increase the factor to make the test animation slower (and reduce to make it faster)
210 switch ( (g_rgb_counters.tick & (0b11 << factor)) >> factor )
213 rgb_matrix_set_color_all( 20, 0, 0 );
217 rgb_matrix_set_color_all( 0, 20, 0 );
221 rgb_matrix_set_color_all( 0, 0, 20 );
225 rgb_matrix_set_color_all( 20, 20, 20 );
231 static bool rgb_matrix_none(effect_params_t* params) {
236 RGB_MATRIX_USE_LIMITS(led_min, led_max);
237 for (uint8_t i = led_min; i < led_max; i++) {
238 rgb_matrix_set_color(i, 0, 0, 0);
240 return led_max < DRIVER_LED_TOTAL;
243 static uint8_t rgb_last_enable = UINT8_MAX;
244 static uint8_t rgb_last_effect = UINT8_MAX;
245 static effect_params_t rgb_effect_params = { 0, 0 };
246 static rgb_task_states rgb_task_state = SYNCING;
248 static void rgb_task_timers(void) {
249 // Update double buffer timers
250 uint16_t deltaTime = timer_elapsed32(rgb_counters_buffer);
251 rgb_counters_buffer = timer_read32();
252 if (g_rgb_counters.any_key_hit < UINT32_MAX) {
253 if (UINT32_MAX - deltaTime < g_rgb_counters.any_key_hit) {
254 g_rgb_counters.any_key_hit = UINT32_MAX;
256 g_rgb_counters.any_key_hit += deltaTime;
260 // Update double buffer last hit timers
261 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
262 uint8_t count = last_hit_buffer.count;
263 for (uint8_t i = 0; i < count; ++i) {
264 if (UINT16_MAX - deltaTime < last_hit_buffer.tick[i]) {
265 last_hit_buffer.count--;
268 last_hit_buffer.tick[i] += deltaTime;
270 #endif // RGB_MATRIX_KEYREACTIVE_ENABLED
273 static void rgb_task_sync(void) {
275 if (timer_elapsed32(g_rgb_counters.tick) >= RGB_MATRIX_LED_FLUSH_LIMIT)
276 rgb_task_state = STARTING;
279 static void rgb_task_start(void) {
281 rgb_effect_params.iter = 0;
283 // update double buffers
284 g_rgb_counters.tick = rgb_counters_buffer;
285 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
286 g_last_hit_tracker = last_hit_buffer;
287 #endif // RGB_MATRIX_KEYREACTIVE_ENABLED
290 rgb_task_state = RENDERING;
293 static void rgb_task_render(uint8_t effect) {
294 bool rendering = false;
295 rgb_effect_params.init = (effect != rgb_last_effect) || (rgb_matrix_config.enable != rgb_last_enable);
297 // each effect can opt to do calculations
298 // and/or request PWM buffer updates.
300 case RGB_MATRIX_NONE:
301 rendering = rgb_matrix_none(&rgb_effect_params);
304 case RGB_MATRIX_SOLID_COLOR:
305 rendering = rgb_matrix_solid_color(&rgb_effect_params); // Max 1ms Avg 0ms
307 #ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS
308 case RGB_MATRIX_ALPHAS_MODS:
309 rendering = rgb_matrix_alphas_mods(&rgb_effect_params); // Max 2ms Avg 1ms
311 #endif // DISABLE_RGB_MATRIX_ALPHAS_MODS
312 #ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
313 case RGB_MATRIX_GRADIENT_UP_DOWN:
314 rendering = rgb_matrix_gradient_up_down(&rgb_effect_params); // Max 4ms Avg 3ms
316 #endif // DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
317 #ifndef DISABLE_RGB_MATRIX_BREATHING
318 case RGB_MATRIX_BREATHING:
319 rendering = rgb_matrix_breathing(&rgb_effect_params); // Max 1ms Avg 0ms
321 #endif // DISABLE_RGB_MATRIX_BREATHING
322 #ifndef DISABLE_RGB_MATRIX_CYCLE_ALL
323 case RGB_MATRIX_CYCLE_ALL:
324 rendering = rgb_matrix_cycle_all(&rgb_effect_params); // Max 4ms Avg 3ms
326 #endif // DISABLE_RGB_MATRIX_CYCLE_ALL
327 #ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
328 case RGB_MATRIX_CYCLE_LEFT_RIGHT:
329 rendering = rgb_matrix_cycle_left_right(&rgb_effect_params); // Max 4ms Avg 3ms
331 #endif // DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
332 #ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
333 case RGB_MATRIX_CYCLE_UP_DOWN:
334 rendering = rgb_matrix_cycle_up_down(&rgb_effect_params); // Max 4ms Avg 3ms
336 #endif // DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
337 #ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
338 case RGB_MATRIX_RAINBOW_MOVING_CHEVRON:
339 rendering = rgb_matrix_rainbow_moving_chevron(&rgb_effect_params); // Max 4ms Avg 3ms
341 #endif // DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
342 #ifndef DISABLE_RGB_MATRIX_DUAL_BEACON
343 case RGB_MATRIX_DUAL_BEACON:
344 rendering = rgb_matrix_dual_beacon(&rgb_effect_params); // Max 4ms Avg 3ms
346 #endif // DISABLE_RGB_MATRIX_DUAL_BEACON
347 #ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON
348 case RGB_MATRIX_RAINBOW_BEACON:
349 rendering = rgb_matrix_rainbow_beacon(&rgb_effect_params); // Max 4ms Avg 3ms
351 #endif // DISABLE_RGB_MATRIX_RAINBOW_BEACON
352 #ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
353 case RGB_MATRIX_RAINBOW_PINWHEELS:
354 rendering = rgb_matrix_rainbow_pinwheels(&rgb_effect_params); // Max 4ms Avg 3ms
356 #endif // DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
357 #ifndef DISABLE_RGB_MATRIX_RAINDROPS
358 case RGB_MATRIX_RAINDROPS:
359 rendering = rgb_matrix_raindrops(&rgb_effect_params); // Max 1ms Avg 0ms
361 #endif // DISABLE_RGB_MATRIX_RAINDROPS
362 #ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
363 case RGB_MATRIX_JELLYBEAN_RAINDROPS:
364 rendering = rgb_matrix_jellybean_raindrops(&rgb_effect_params); // Max 1ms Avg 0ms
366 #endif // DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
367 #ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN
368 case RGB_MATRIX_DIGITAL_RAIN:
369 rendering = rgb_matrix_digital_rain(&rgb_effect_params); // Max 9ms Avg 8ms | this is expensive, fix it
371 #endif // DISABLE_RGB_MATRIX_DIGITAL_RAIN
372 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
373 #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
374 case RGB_MATRIX_SOLID_REACTIVE_SIMPLE:
375 rendering = rgb_matrix_solid_reactive_simple(&rgb_effect_params);// Max 4ms Avg 3ms
378 #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE
379 case RGB_MATRIX_SOLID_REACTIVE:
380 rendering = rgb_matrix_solid_reactive(&rgb_effect_params); // Max 4ms Avg 3ms
382 #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE
383 #ifndef DISABLE_RGB_MATRIX_SPLASH
384 case RGB_MATRIX_SPLASH:
385 rendering = rgb_matrix_splash(&rgb_effect_params); // Max 5ms Avg 3ms
387 #endif // DISABLE_RGB_MATRIX_SPLASH
388 #ifndef DISABLE_RGB_MATRIX_MULTISPLASH
389 case RGB_MATRIX_MULTISPLASH:
390 rendering = rgb_matrix_multisplash(&rgb_effect_params); // Max 10ms Avg 5ms
392 #endif // DISABLE_RGB_MATRIX_MULTISPLASH
393 #ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH
394 case RGB_MATRIX_SOLID_SPLASH:
395 rendering = rgb_matrix_solid_splash(&rgb_effect_params); // Max 5ms Avg 3ms
397 #endif // DISABLE_RGB_MATRIX_SOLID_SPLASH
398 #ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
399 case RGB_MATRIX_SOLID_MULTISPLASH:
400 rendering = rgb_matrix_solid_multisplash(&rgb_effect_params); // Max 10ms Avg 5ms
402 #endif // DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
403 #endif // RGB_MATRIX_KEYREACTIVE_ENABLED
405 // Factory default magic value
408 rgb_task_state = FLUSHING;
413 rgb_effect_params.iter++;
417 rgb_task_state = FLUSHING;
418 if (!rgb_effect_params.init && effect == RGB_MATRIX_NONE) {
419 // We only need to flush once if we are RGB_MATRIX_NONE
420 rgb_task_state = SYNCING;
425 static void rgb_task_flush(uint8_t effect) {
426 // update last trackers after the first full render so we can init over several frames
427 rgb_last_effect = effect;
428 rgb_last_enable = rgb_matrix_config.enable;
430 // update pwm buffers
431 rgb_matrix_update_pwm_buffers();
434 rgb_task_state = SYNCING;
437 void rgb_matrix_task(void) {
440 // Ideally we would also stop sending zeros to the LED driver PWM buffers
441 // while suspended and just do a software shutdown. This is a cheap hack for now.
442 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));
443 uint8_t effect = suspend_backlight || !rgb_matrix_config.enable ? 0 : rgb_matrix_config.mode;
445 switch (rgb_task_state) {
450 rgb_task_render(effect);
453 rgb_task_flush(effect);
460 if (!suspend_backlight) {
461 rgb_matrix_indicators();
465 void rgb_matrix_indicators(void) {
466 rgb_matrix_indicators_kb();
467 rgb_matrix_indicators_user();
470 __attribute__((weak))
471 void rgb_matrix_indicators_kb(void) {}
473 __attribute__((weak))
474 void rgb_matrix_indicators_user(void) {}
476 void rgb_matrix_init(void) {
477 rgb_matrix_driver.init();
479 // TODO: put the 1 second startup delay here?
481 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
482 g_last_hit_tracker.count = 0;
483 for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) {
484 g_last_hit_tracker.tick[i] = UINT16_MAX;
487 last_hit_buffer.count = 0;
488 for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) {
489 last_hit_buffer.tick[i] = UINT16_MAX;
491 #endif // RGB_MATRIX_KEYREACTIVE_ENABLED
493 if (!eeconfig_is_enabled()) {
494 dprintf("rgb_matrix_init_drivers eeconfig is not enabled.\n");
496 eeconfig_update_rgb_matrix_default();
499 rgb_matrix_config.raw = eeconfig_read_rgb_matrix();
500 rgb_matrix_config.speed = UINT8_MAX / 2; //EECONFIG needs to be increased to support this
501 if (!rgb_matrix_config.mode) {
502 dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n");
503 eeconfig_update_rgb_matrix_default();
504 rgb_matrix_config.raw = eeconfig_read_rgb_matrix();
506 eeconfig_debug_rgb_matrix(); // display current eeprom values
509 void rgb_matrix_set_suspend_state(bool state) {
510 g_suspend_state = state;
513 void rgb_matrix_toggle(void) {
514 rgb_matrix_config.enable++;
515 if (!rgb_matrix_config.enable) {
516 rgb_task_state = STARTING;
518 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
521 void rgb_matrix_enable(void) {
522 rgb_matrix_config.enable = 1;
523 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
526 void rgb_matrix_enable_noeeprom(void) {
527 rgb_matrix_config.enable = 1;
530 void rgb_matrix_disable(void) {
531 rgb_matrix_config.enable = 0;
532 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
535 void rgb_matrix_disable_noeeprom(void) {
536 rgb_matrix_config.enable = 0;
539 void rgb_matrix_step(void) {
540 rgb_matrix_config.mode++;
541 if (rgb_matrix_config.mode >= RGB_MATRIX_EFFECT_MAX)
542 rgb_matrix_config.mode = 1;
543 rgb_task_state = STARTING;
544 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
547 void rgb_matrix_step_reverse(void) {
548 rgb_matrix_config.mode--;
549 if (rgb_matrix_config.mode < 1)
550 rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1;
551 rgb_task_state = STARTING;
552 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
555 void rgb_matrix_increase_hue(void) {
556 rgb_matrix_config.hue += RGB_MATRIX_HUE_STEP;
557 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
560 void rgb_matrix_decrease_hue(void) {
561 rgb_matrix_config.hue -= RGB_MATRIX_HUE_STEP;
562 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
565 void rgb_matrix_increase_sat(void) {
566 rgb_matrix_config.sat = qadd8(rgb_matrix_config.sat, RGB_MATRIX_SAT_STEP);
567 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
570 void rgb_matrix_decrease_sat(void) {
571 rgb_matrix_config.sat = qsub8(rgb_matrix_config.sat, RGB_MATRIX_SAT_STEP);
572 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
575 void rgb_matrix_increase_val(void) {
576 rgb_matrix_config.val = qadd8(rgb_matrix_config.val, RGB_MATRIX_VAL_STEP);
577 if (rgb_matrix_config.val > RGB_MATRIX_MAXIMUM_BRIGHTNESS)
578 rgb_matrix_config.val = RGB_MATRIX_MAXIMUM_BRIGHTNESS;
579 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
582 void rgb_matrix_decrease_val(void) {
583 rgb_matrix_config.val = qsub8(rgb_matrix_config.val, RGB_MATRIX_VAL_STEP);
584 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
587 void rgb_matrix_increase_speed(void) {
588 rgb_matrix_config.speed = qadd8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP);
589 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this
592 void rgb_matrix_decrease_speed(void) {
593 rgb_matrix_config.speed = qsub8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP);
594 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this
597 void rgb_matrix_mode(uint8_t mode) {
598 rgb_matrix_config.mode = mode;
599 rgb_task_state = STARTING;
600 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
603 void rgb_matrix_mode_noeeprom(uint8_t mode) {
604 rgb_matrix_config.mode = mode;
607 uint8_t rgb_matrix_get_mode(void) {
608 return rgb_matrix_config.mode;
611 void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val) {
612 rgb_matrix_sethsv_noeeprom(hue, sat, val);
613 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
616 void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) {
617 rgb_matrix_config.hue = hue;
618 rgb_matrix_config.sat = sat;
619 rgb_matrix_config.val = val;
620 if (rgb_matrix_config.val > RGB_MATRIX_MAXIMUM_BRIGHTNESS)
621 rgb_matrix_config.val = RGB_MATRIX_MAXIMUM_BRIGHTNESS;