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/solid_reactive_wide.h"
45 #include "rgb_matrix_animations/solid_reactive_cross.h"
46 #include "rgb_matrix_animations/solid_reactive_nexus.h"
47 #include "rgb_matrix_animations/splash_anim.h"
48 #include "rgb_matrix_animations/solid_splash_anim.h"
49 #include "rgb_matrix_animations/breathing_anim.h"
51 #ifndef RGB_DISABLE_AFTER_TIMEOUT
52 #define RGB_DISABLE_AFTER_TIMEOUT 0
55 #ifndef RGB_DISABLE_WHEN_USB_SUSPENDED
56 #define RGB_DISABLE_WHEN_USB_SUSPENDED false
59 #ifndef EECONFIG_RGB_MATRIX
60 #define EECONFIG_RGB_MATRIX EECONFIG_RGBLIGHT
63 #if !defined(RGB_MATRIX_MAXIMUM_BRIGHTNESS) || RGB_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX
64 #undef RGB_MATRIX_MAXIMUM_BRIGHTNESS
65 #define RGB_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX
68 #if !defined(RGB_MATRIX_HUE_STEP)
69 #define RGB_MATRIX_HUE_STEP 8
72 #if !defined(RGB_MATRIX_SAT_STEP)
73 #define RGB_MATRIX_SAT_STEP 16
76 #if !defined(RGB_MATRIX_VAL_STEP)
77 #define RGB_MATRIX_VAL_STEP 16
80 #if !defined(RGB_MATRIX_SPD_STEP)
81 #define RGB_MATRIX_SPD_STEP 16
84 bool g_suspend_state = false;
86 rgb_config_t rgb_matrix_config;
88 rgb_counters_t g_rgb_counters;
89 static uint32_t rgb_counters_buffer;
91 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
92 last_hit_t g_last_hit_tracker;
93 static last_hit_t last_hit_buffer;
94 #endif // RGB_MATRIX_KEYREACTIVE_ENABLED
96 uint32_t eeconfig_read_rgb_matrix(void) {
97 return eeprom_read_dword(EECONFIG_RGB_MATRIX);
100 void eeconfig_update_rgb_matrix(uint32_t val) {
101 eeprom_update_dword(EECONFIG_RGB_MATRIX, val);
104 void eeconfig_update_rgb_matrix_default(void) {
105 dprintf("eeconfig_update_rgb_matrix_default\n");
106 rgb_matrix_config.enable = 1;
107 #ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
108 rgb_matrix_config.mode = RGB_MATRIX_CYCLE_LEFT_RIGHT;
110 // fallback to solid colors if RGB_MATRIX_CYCLE_LEFT_RIGHT is disabled in userspace
111 rgb_matrix_config.mode = RGB_MATRIX_SOLID_COLOR;
113 rgb_matrix_config.hue = 0;
114 rgb_matrix_config.sat = UINT8_MAX;
115 rgb_matrix_config.val = RGB_MATRIX_MAXIMUM_BRIGHTNESS;
116 rgb_matrix_config.speed = UINT8_MAX / 2;
117 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
120 void eeconfig_debug_rgb_matrix(void) {
121 dprintf("rgb_matrix_config eprom\n");
122 dprintf("rgb_matrix_config.enable = %d\n", rgb_matrix_config.enable);
123 dprintf("rgb_matrix_config.mode = %d\n", rgb_matrix_config.mode);
124 dprintf("rgb_matrix_config.hue = %d\n", rgb_matrix_config.hue);
125 dprintf("rgb_matrix_config.sat = %d\n", rgb_matrix_config.sat);
126 dprintf("rgb_matrix_config.val = %d\n", rgb_matrix_config.val);
127 dprintf("rgb_matrix_config.speed = %d\n", rgb_matrix_config.speed);
130 uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) {
131 // TODO: This is kinda expensive, fix this soonish
132 uint8_t led_count = 0;
133 for (uint8_t i = 0; i < DRIVER_LED_TOTAL && led_count < LED_HITS_TO_REMEMBER; i++) {
134 matrix_co_t matrix_co = g_rgb_leds[i].matrix_co;
135 if (row == matrix_co.row && column == matrix_co.col) {
136 led_i[led_count] = i;
143 void rgb_matrix_update_pwm_buffers(void) {
144 rgb_matrix_driver.flush();
147 void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) {
148 #ifdef RGB_MATRIX_EXTRA_TOG
149 const bool is_key = g_rgb_leds[index].matrix_co.raw != 0xff;
151 (rgb_matrix_config.enable == RGB_ZONE_KEYS && !is_key) ||
152 (rgb_matrix_config.enable == RGB_ZONE_UNDER && is_key)
154 rgb_matrix_driver.set_color(index, 0, 0, 0);
159 rgb_matrix_driver.set_color(index, red, green, blue);
162 void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) {
163 #ifdef RGB_MATRIX_EXTRA_TOG
164 for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
165 rgb_matrix_set_color(i, red, green, blue);
168 rgb_matrix_driver.set_color_all(red, green, blue);
172 bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) {
173 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
174 uint8_t led[LED_HITS_TO_REMEMBER];
175 uint8_t led_count = 0;
177 #if defined(RGB_MATRIX_KEYRELEASES)
178 if (!record->event.pressed) {
179 led_count = rgb_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led);
180 g_rgb_counters.any_key_hit = 0;
182 #elif defined(RGB_MATRIX_KEYPRESSES)
183 if (record->event.pressed) {
184 led_count = rgb_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led);
185 g_rgb_counters.any_key_hit = 0;
187 #endif // defined(RGB_MATRIX_KEYRELEASES)
189 if (last_hit_buffer.count + led_count > LED_HITS_TO_REMEMBER) {
190 memcpy(&last_hit_buffer.x[0], &last_hit_buffer.x[led_count], LED_HITS_TO_REMEMBER - led_count);
191 memcpy(&last_hit_buffer.y[0], &last_hit_buffer.y[led_count], LED_HITS_TO_REMEMBER - led_count);
192 memcpy(&last_hit_buffer.tick[0], &last_hit_buffer.tick[led_count], (LED_HITS_TO_REMEMBER - led_count) * 2); // 16 bit
193 memcpy(&last_hit_buffer.index[0], &last_hit_buffer.index[led_count], LED_HITS_TO_REMEMBER - led_count);
194 last_hit_buffer.count--;
197 for(uint8_t i = 0; i < led_count; i++) {
198 uint8_t index = last_hit_buffer.count;
199 last_hit_buffer.x[index] = g_rgb_leds[led[i]].point.x;
200 last_hit_buffer.y[index] = g_rgb_leds[led[i]].point.y;
201 last_hit_buffer.index[index] = led[i];
202 last_hit_buffer.tick[index] = 0;
203 last_hit_buffer.count++;
205 #endif // RGB_MATRIX_KEYREACTIVE_ENABLED
209 void rgb_matrix_test(void) {
210 // Mask out bits 4 and 5
211 // Increase the factor to make the test animation slower (and reduce to make it faster)
213 switch ( (g_rgb_counters.tick & (0b11 << factor)) >> factor )
216 rgb_matrix_set_color_all( 20, 0, 0 );
220 rgb_matrix_set_color_all( 0, 20, 0 );
224 rgb_matrix_set_color_all( 0, 0, 20 );
228 rgb_matrix_set_color_all( 20, 20, 20 );
234 static bool rgb_matrix_none(effect_params_t* params) {
239 RGB_MATRIX_USE_LIMITS(led_min, led_max);
240 for (uint8_t i = led_min; i < led_max; i++) {
241 rgb_matrix_set_color(i, 0, 0, 0);
243 return led_max < DRIVER_LED_TOTAL;
246 static uint8_t rgb_last_enable = UINT8_MAX;
247 static uint8_t rgb_last_effect = UINT8_MAX;
248 static effect_params_t rgb_effect_params = { 0, 0 };
249 static rgb_task_states rgb_task_state = SYNCING;
251 static void rgb_task_timers(void) {
252 // Update double buffer timers
253 uint16_t deltaTime = timer_elapsed32(rgb_counters_buffer);
254 rgb_counters_buffer = timer_read32();
255 if (g_rgb_counters.any_key_hit < UINT32_MAX) {
256 if (UINT32_MAX - deltaTime < g_rgb_counters.any_key_hit) {
257 g_rgb_counters.any_key_hit = UINT32_MAX;
259 g_rgb_counters.any_key_hit += deltaTime;
263 // Update double buffer last hit timers
264 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
265 uint8_t count = last_hit_buffer.count;
266 for (uint8_t i = 0; i < count; ++i) {
267 if (UINT16_MAX - deltaTime < last_hit_buffer.tick[i]) {
268 last_hit_buffer.count--;
271 last_hit_buffer.tick[i] += deltaTime;
273 #endif // RGB_MATRIX_KEYREACTIVE_ENABLED
276 static void rgb_task_sync(void) {
278 if (timer_elapsed32(g_rgb_counters.tick) >= RGB_MATRIX_LED_FLUSH_LIMIT)
279 rgb_task_state = STARTING;
282 static void rgb_task_start(void) {
284 rgb_effect_params.iter = 0;
286 // update double buffers
287 g_rgb_counters.tick = rgb_counters_buffer;
288 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
289 g_last_hit_tracker = last_hit_buffer;
290 #endif // RGB_MATRIX_KEYREACTIVE_ENABLED
293 rgb_task_state = RENDERING;
296 static void rgb_task_render(uint8_t effect) {
297 bool rendering = false;
298 rgb_effect_params.init = (effect != rgb_last_effect) || (rgb_matrix_config.enable != rgb_last_enable);
300 // each effect can opt to do calculations
301 // and/or request PWM buffer updates.
303 case RGB_MATRIX_NONE:
304 rendering = rgb_matrix_none(&rgb_effect_params);
307 case RGB_MATRIX_SOLID_COLOR:
308 rendering = rgb_matrix_solid_color(&rgb_effect_params); // Max 1ms Avg 0ms
310 #ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS
311 case RGB_MATRIX_ALPHAS_MODS:
312 rendering = rgb_matrix_alphas_mods(&rgb_effect_params); // Max 2ms Avg 1ms
314 #endif // DISABLE_RGB_MATRIX_ALPHAS_MODS
315 #ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
316 case RGB_MATRIX_GRADIENT_UP_DOWN:
317 rendering = rgb_matrix_gradient_up_down(&rgb_effect_params); // Max 4ms Avg 3ms
319 #endif // DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
320 #ifndef DISABLE_RGB_MATRIX_BREATHING
321 case RGB_MATRIX_BREATHING:
322 rendering = rgb_matrix_breathing(&rgb_effect_params); // Max 1ms Avg 0ms
324 #endif // DISABLE_RGB_MATRIX_BREATHING
325 #ifndef DISABLE_RGB_MATRIX_CYCLE_ALL
326 case RGB_MATRIX_CYCLE_ALL:
327 rendering = rgb_matrix_cycle_all(&rgb_effect_params); // Max 4ms Avg 3ms
329 #endif // DISABLE_RGB_MATRIX_CYCLE_ALL
330 #ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
331 case RGB_MATRIX_CYCLE_LEFT_RIGHT:
332 rendering = rgb_matrix_cycle_left_right(&rgb_effect_params); // Max 4ms Avg 3ms
334 #endif // DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
335 #ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
336 case RGB_MATRIX_CYCLE_UP_DOWN:
337 rendering = rgb_matrix_cycle_up_down(&rgb_effect_params); // Max 4ms Avg 3ms
339 #endif // DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
340 #ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
341 case RGB_MATRIX_RAINBOW_MOVING_CHEVRON:
342 rendering = rgb_matrix_rainbow_moving_chevron(&rgb_effect_params); // Max 4ms Avg 3ms
344 #endif // DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
345 #ifndef DISABLE_RGB_MATRIX_DUAL_BEACON
346 case RGB_MATRIX_DUAL_BEACON:
347 rendering = rgb_matrix_dual_beacon(&rgb_effect_params); // Max 4ms Avg 3ms
349 #endif // DISABLE_RGB_MATRIX_DUAL_BEACON
350 #ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON
351 case RGB_MATRIX_RAINBOW_BEACON:
352 rendering = rgb_matrix_rainbow_beacon(&rgb_effect_params); // Max 4ms Avg 3ms
354 #endif // DISABLE_RGB_MATRIX_RAINBOW_BEACON
355 #ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
356 case RGB_MATRIX_RAINBOW_PINWHEELS:
357 rendering = rgb_matrix_rainbow_pinwheels(&rgb_effect_params); // Max 4ms Avg 3ms
359 #endif // DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
360 #ifndef DISABLE_RGB_MATRIX_RAINDROPS
361 case RGB_MATRIX_RAINDROPS:
362 rendering = rgb_matrix_raindrops(&rgb_effect_params); // Max 1ms Avg 0ms
364 #endif // DISABLE_RGB_MATRIX_RAINDROPS
365 #ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
366 case RGB_MATRIX_JELLYBEAN_RAINDROPS:
367 rendering = rgb_matrix_jellybean_raindrops(&rgb_effect_params); // Max 1ms Avg 0ms
369 #endif // DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
370 #ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN
371 case RGB_MATRIX_DIGITAL_RAIN:
372 rendering = rgb_matrix_digital_rain(&rgb_effect_params); // Max 9ms Avg 8ms | this is expensive, fix it
374 #endif // DISABLE_RGB_MATRIX_DIGITAL_RAIN
375 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
376 #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
377 case RGB_MATRIX_SOLID_REACTIVE_SIMPLE:
378 rendering = rgb_matrix_solid_reactive_simple(&rgb_effect_params);// Max 4ms Avg 3ms
381 #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE
382 case RGB_MATRIX_SOLID_REACTIVE:
383 rendering = rgb_matrix_solid_reactive(&rgb_effect_params); // Max 4ms Avg 3ms
385 #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE
386 #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE
387 case RGB_MATRIX_SOLID_REACTIVE_WIDE:
388 rendering = rgb_matrix_solid_reactive_wide(&rgb_effect_params); // Max ?? ms Avg ?? ms
390 #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE
391 #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE
392 case RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE:
393 rendering = rgb_matrix_solid_reactive_multiwide(&rgb_effect_params); // Max ?? ms Avg ?? ms
395 #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE
396 #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS
397 case RGB_MATRIX_SOLID_REACTIVE_CROSS:
398 rendering = rgb_matrix_solid_reactive_cross(&rgb_effect_params); // Max ?? ms Avg ?? ms
400 #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS
401 #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS
402 case RGB_MATRIX_SOLID_REACTIVE_MULTICROSS:
403 rendering = rgb_matrix_solid_reactive_multicross(&rgb_effect_params); // Max ?? ms Avg ?? ms
405 #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS
406 #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS
407 case RGB_MATRIX_SOLID_REACTIVE_NEXUS:
408 rendering = rgb_matrix_solid_reactive_nexus(&rgb_effect_params); // Max ?? ms Avg ?? ms
410 #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS
411 #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS
412 case RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS:
413 rendering = rgb_matrix_solid_reactive_multinexus(&rgb_effect_params); // Max ?? ms Avg ?? ms
415 #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS
416 #ifndef DISABLE_RGB_MATRIX_SPLASH
417 case RGB_MATRIX_SPLASH:
418 rendering = rgb_matrix_splash(&rgb_effect_params); // Max 5ms Avg 3ms
420 #endif // DISABLE_RGB_MATRIX_SPLASH
421 #ifndef DISABLE_RGB_MATRIX_MULTISPLASH
422 case RGB_MATRIX_MULTISPLASH:
423 rendering = rgb_matrix_multisplash(&rgb_effect_params); // Max 10ms Avg 5ms
425 #endif // DISABLE_RGB_MATRIX_MULTISPLASH
426 #ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH
427 case RGB_MATRIX_SOLID_SPLASH:
428 rendering = rgb_matrix_solid_splash(&rgb_effect_params); // Max 5ms Avg 3ms
430 #endif // DISABLE_RGB_MATRIX_SOLID_SPLASH
431 #ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
432 case RGB_MATRIX_SOLID_MULTISPLASH:
433 rendering = rgb_matrix_solid_multisplash(&rgb_effect_params); // Max 10ms Avg 5ms
435 #endif // DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
436 #endif // RGB_MATRIX_KEYREACTIVE_ENABLED
438 // Factory default magic value
441 rgb_task_state = FLUSHING;
446 rgb_effect_params.iter++;
450 rgb_task_state = FLUSHING;
451 if (!rgb_effect_params.init && effect == RGB_MATRIX_NONE) {
452 // We only need to flush once if we are RGB_MATRIX_NONE
453 rgb_task_state = SYNCING;
458 static void rgb_task_flush(uint8_t effect) {
459 // update last trackers after the first full render so we can init over several frames
460 rgb_last_effect = effect;
461 rgb_last_enable = rgb_matrix_config.enable;
463 // update pwm buffers
464 rgb_matrix_update_pwm_buffers();
467 rgb_task_state = SYNCING;
470 void rgb_matrix_task(void) {
473 // Ideally we would also stop sending zeros to the LED driver PWM buffers
474 // while suspended and just do a software shutdown. This is a cheap hack for now.
475 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));
476 uint8_t effect = suspend_backlight || !rgb_matrix_config.enable ? 0 : rgb_matrix_config.mode;
478 switch (rgb_task_state) {
483 rgb_task_render(effect);
486 rgb_task_flush(effect);
493 if (!suspend_backlight) {
494 rgb_matrix_indicators();
498 void rgb_matrix_indicators(void) {
499 rgb_matrix_indicators_kb();
500 rgb_matrix_indicators_user();
503 __attribute__((weak))
504 void rgb_matrix_indicators_kb(void) {}
506 __attribute__((weak))
507 void rgb_matrix_indicators_user(void) {}
509 void rgb_matrix_init(void) {
510 rgb_matrix_driver.init();
512 // TODO: put the 1 second startup delay here?
514 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
515 g_last_hit_tracker.count = 0;
516 for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) {
517 g_last_hit_tracker.tick[i] = UINT16_MAX;
520 last_hit_buffer.count = 0;
521 for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) {
522 last_hit_buffer.tick[i] = UINT16_MAX;
524 #endif // RGB_MATRIX_KEYREACTIVE_ENABLED
526 if (!eeconfig_is_enabled()) {
527 dprintf("rgb_matrix_init_drivers eeconfig is not enabled.\n");
529 eeconfig_update_rgb_matrix_default();
532 rgb_matrix_config.raw = eeconfig_read_rgb_matrix();
533 rgb_matrix_config.speed = UINT8_MAX / 2; //EECONFIG needs to be increased to support this
534 if (!rgb_matrix_config.mode) {
535 dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n");
536 eeconfig_update_rgb_matrix_default();
537 rgb_matrix_config.raw = eeconfig_read_rgb_matrix();
539 eeconfig_debug_rgb_matrix(); // display current eeprom values
542 void rgb_matrix_set_suspend_state(bool state) {
543 g_suspend_state = state;
546 void rgb_matrix_toggle(void) {
547 rgb_matrix_config.enable++;
548 if (!rgb_matrix_config.enable) {
549 rgb_task_state = STARTING;
551 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
554 void rgb_matrix_enable(void) {
555 rgb_matrix_config.enable = 1;
556 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
559 void rgb_matrix_enable_noeeprom(void) {
560 rgb_matrix_config.enable = 1;
563 void rgb_matrix_disable(void) {
564 rgb_matrix_config.enable = 0;
565 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
568 void rgb_matrix_disable_noeeprom(void) {
569 rgb_matrix_config.enable = 0;
572 void rgb_matrix_step(void) {
573 rgb_matrix_config.mode++;
574 if (rgb_matrix_config.mode >= RGB_MATRIX_EFFECT_MAX)
575 rgb_matrix_config.mode = 1;
576 rgb_task_state = STARTING;
577 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
580 void rgb_matrix_step_reverse(void) {
581 rgb_matrix_config.mode--;
582 if (rgb_matrix_config.mode < 1)
583 rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1;
584 rgb_task_state = STARTING;
585 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
588 void rgb_matrix_increase_hue(void) {
589 rgb_matrix_config.hue += RGB_MATRIX_HUE_STEP;
590 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
593 void rgb_matrix_decrease_hue(void) {
594 rgb_matrix_config.hue -= RGB_MATRIX_HUE_STEP;
595 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
598 void rgb_matrix_increase_sat(void) {
599 rgb_matrix_config.sat = qadd8(rgb_matrix_config.sat, RGB_MATRIX_SAT_STEP);
600 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
603 void rgb_matrix_decrease_sat(void) {
604 rgb_matrix_config.sat = qsub8(rgb_matrix_config.sat, RGB_MATRIX_SAT_STEP);
605 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
608 void rgb_matrix_increase_val(void) {
609 rgb_matrix_config.val = qadd8(rgb_matrix_config.val, RGB_MATRIX_VAL_STEP);
610 if (rgb_matrix_config.val > RGB_MATRIX_MAXIMUM_BRIGHTNESS)
611 rgb_matrix_config.val = RGB_MATRIX_MAXIMUM_BRIGHTNESS;
612 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
615 void rgb_matrix_decrease_val(void) {
616 rgb_matrix_config.val = qsub8(rgb_matrix_config.val, RGB_MATRIX_VAL_STEP);
617 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
620 void rgb_matrix_increase_speed(void) {
621 rgb_matrix_config.speed = qadd8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP);
622 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this
625 void rgb_matrix_decrease_speed(void) {
626 rgb_matrix_config.speed = qsub8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP);
627 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this
630 void rgb_matrix_mode(uint8_t mode) {
631 rgb_matrix_config.mode = mode;
632 rgb_task_state = STARTING;
633 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
636 void rgb_matrix_mode_noeeprom(uint8_t mode) {
637 rgb_matrix_config.mode = mode;
640 uint8_t rgb_matrix_get_mode(void) {
641 return rgb_matrix_config.mode;
644 void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val) {
645 rgb_matrix_sethsv_noeeprom(hue, sat, val);
646 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
649 void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) {
650 rgb_matrix_config.hue = hue;
651 rgb_matrix_config.sat = sat;
652 rgb_matrix_config.val = val;
653 if (rgb_matrix_config.val > RGB_MATRIX_MAXIMUM_BRIGHTNESS)
654 rgb_matrix_config.val = RGB_MATRIX_MAXIMUM_BRIGHTNESS;