]> git.donarmstrong.com Git - qmk_firmware.git/blob - quantum/rgb_matrix.c
Switching rgb_config_t to use HSV struct
[qmk_firmware.git] / quantum / rgb_matrix.c
1 /* Copyright 2017 Jason Williams
2  * Copyright 2017 Jack Humbert
3  * Copyright 2018 Yiancar
4  *
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.
9  *
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.
14  *
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/>.
17  */
18
19
20 #include "rgb_matrix.h"
21 #include "progmem.h"
22 #include "config.h"
23 #include "eeprom.h"
24 #include <string.h>
25 #include <math.h>
26
27 #include "lib/lib8tion/lib8tion.h"
28
29 #ifndef RGB_MATRIX_CENTER
30   const point_t k_rgb_matrix_center = { 112, 32 };
31 #else
32   const point_t k_rgb_matrix_center = RGB_MATRIX_CENTER;
33 #endif
34
35 // Generic effect runners
36 #include "rgb_matrix_runners/effect_runner_dx_dy_dist.h"
37 #include "rgb_matrix_runners/effect_runner_dx_dy.h"
38 #include "rgb_matrix_runners/effect_runner_i.h"
39 #include "rgb_matrix_runners/effect_runner_sin_cos_i.h"
40 #include "rgb_matrix_runners/effect_runner_reactive.h"
41 #include "rgb_matrix_runners/effect_runner_reactive_splash.h"
42
43 // ------------------------------------------
44 // -----Begin rgb effect includes macros-----
45 #define RGB_MATRIX_EFFECT(name)
46 #define RGB_MATRIX_CUSTOM_EFFECT_IMPLS
47
48 #include "rgb_matrix_animations/rgb_matrix_effects.inc"
49 #ifdef RGB_MATRIX_CUSTOM_KB
50     #include "rgb_matrix_kb.inc"
51 #endif
52 #ifdef RGB_MATRIX_CUSTOM_USER
53     #include "rgb_matrix_user.inc"
54 #endif
55
56 #undef RGB_MATRIX_CUSTOM_EFFECT_IMPLS
57 #undef RGB_MATRIX_EFFECT
58 // -----End rgb effect includes macros-------
59 // ------------------------------------------
60
61 #ifndef RGB_DISABLE_AFTER_TIMEOUT
62   #define RGB_DISABLE_AFTER_TIMEOUT 0
63 #endif
64
65 #ifndef RGB_DISABLE_WHEN_USB_SUSPENDED
66   #define RGB_DISABLE_WHEN_USB_SUSPENDED false
67 #endif
68
69 #ifndef EECONFIG_RGB_MATRIX
70   #define EECONFIG_RGB_MATRIX EECONFIG_RGBLIGHT
71 #endif
72
73 #if !defined(RGB_MATRIX_MAXIMUM_BRIGHTNESS) || RGB_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX
74   #undef RGB_MATRIX_MAXIMUM_BRIGHTNESS
75   #define RGB_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX
76 #endif
77
78 #if !defined(RGB_MATRIX_HUE_STEP)
79   #define RGB_MATRIX_HUE_STEP 8
80 #endif
81
82 #if !defined(RGB_MATRIX_SAT_STEP)
83   #define RGB_MATRIX_SAT_STEP 16
84 #endif
85
86 #if !defined(RGB_MATRIX_VAL_STEP)
87   #define RGB_MATRIX_VAL_STEP 16
88 #endif
89
90 #if !defined(RGB_MATRIX_SPD_STEP)
91   #define RGB_MATRIX_SPD_STEP 16
92 #endif
93
94 #if !defined(RGB_MATRIX_STARTUP_MODE)
95   #ifndef DISABLE_RGB_MATRIX_CYCLE_ALL
96     #define RGB_MATRIX_STARTUP_MODE RGB_MATRIX_CYCLE_LEFT_RIGHT
97   #else
98     // fallback to solid colors if RGB_MATRIX_CYCLE_LEFT_RIGHT is disabled in userspace
99     #define RGB_MATRIX_STARTUP_MODE RGB_MATRIX_SOLID_COLOR
100   #endif
101 #endif
102
103 bool g_suspend_state = false;
104
105 rgb_config_t rgb_matrix_config;
106
107 rgb_counters_t g_rgb_counters;
108 static uint32_t rgb_counters_buffer;
109
110 #ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS
111 uint8_t rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS] = {{0}};
112 #endif
113
114 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
115   last_hit_t g_last_hit_tracker;
116   static last_hit_t last_hit_buffer;
117 #endif // RGB_MATRIX_KEYREACTIVE_ENABLED
118
119 uint32_t eeconfig_read_rgb_matrix(void) {
120   return eeprom_read_dword(EECONFIG_RGB_MATRIX);
121 }
122
123 void eeconfig_update_rgb_matrix(uint32_t val) {
124   eeprom_update_dword(EECONFIG_RGB_MATRIX, val);
125 }
126
127 void eeconfig_update_rgb_matrix_default(void) {
128   dprintf("eeconfig_update_rgb_matrix_default\n");
129   rgb_matrix_config.enable = 1;
130   rgb_matrix_config.mode = RGB_MATRIX_STARTUP_MODE;
131   rgb_matrix_config.hsv = (HSV){ 0,  UINT8_MAX, RGB_MATRIX_MAXIMUM_BRIGHTNESS };
132   rgb_matrix_config.speed = UINT8_MAX / 2;
133   eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
134 }
135
136 void eeconfig_debug_rgb_matrix(void) {
137   dprintf("rgb_matrix_config eprom\n");
138   dprintf("rgb_matrix_config.enable = %d\n", rgb_matrix_config.enable);
139   dprintf("rgb_matrix_config.mode = %d\n", rgb_matrix_config.mode);
140   dprintf("rgb_matrix_config.hsv.h = %d\n", rgb_matrix_config.hsv.h);
141   dprintf("rgb_matrix_config.hsv.s = %d\n", rgb_matrix_config.hsv.s);
142   dprintf("rgb_matrix_config.hsv.v = %d\n", rgb_matrix_config.hsv.v);
143   dprintf("rgb_matrix_config.speed = %d\n", rgb_matrix_config.speed);
144 }
145
146 __attribute__ ((weak))
147 uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i) {
148   return 0;
149 }
150
151 uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) {
152   uint8_t led_count = rgb_matrix_map_row_column_to_led_kb(row, column, led_i);
153   uint8_t led_index = g_led_config.matrix_co[row][column];
154   if (led_index != NO_LED) {
155     led_i[led_count] = led_index;
156     led_count++;
157   }
158   return led_count;
159 }
160
161 void rgb_matrix_update_pwm_buffers(void) {
162   rgb_matrix_driver.flush();
163 }
164
165 void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) {
166   rgb_matrix_driver.set_color(index, red, green, blue);
167 }
168
169 void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) {
170   rgb_matrix_driver.set_color_all(red, green, blue);
171 }
172
173 bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) {
174 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
175   uint8_t led[LED_HITS_TO_REMEMBER];
176   uint8_t led_count = 0;
177
178 #if defined(RGB_MATRIX_KEYRELEASES)
179   if (!record->event.pressed) {
180     led_count = rgb_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led);
181     g_rgb_counters.any_key_hit = 0;
182   }
183 #elif defined(RGB_MATRIX_KEYPRESSES)
184   if (record->event.pressed) {
185     led_count = rgb_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led);
186     g_rgb_counters.any_key_hit = 0;
187   }
188 #endif // defined(RGB_MATRIX_KEYRELEASES)
189
190   if (last_hit_buffer.count + led_count > LED_HITS_TO_REMEMBER) {
191     memcpy(&last_hit_buffer.x[0], &last_hit_buffer.x[led_count], LED_HITS_TO_REMEMBER - led_count);
192     memcpy(&last_hit_buffer.y[0], &last_hit_buffer.y[led_count], LED_HITS_TO_REMEMBER - led_count);
193     memcpy(&last_hit_buffer.tick[0], &last_hit_buffer.tick[led_count], (LED_HITS_TO_REMEMBER - led_count) * 2); // 16 bit
194     memcpy(&last_hit_buffer.index[0], &last_hit_buffer.index[led_count], LED_HITS_TO_REMEMBER - led_count);
195     last_hit_buffer.count--;
196   }
197
198   for(uint8_t i = 0; i < led_count; i++) {
199     uint8_t index = last_hit_buffer.count;
200     last_hit_buffer.x[index] = g_led_config.point[led[i]].x;
201     last_hit_buffer.y[index] = g_led_config.point[led[i]].y;
202     last_hit_buffer.index[index] = led[i];
203     last_hit_buffer.tick[index] = 0;
204     last_hit_buffer.count++;
205   }
206 #endif // RGB_MATRIX_KEYREACTIVE_ENABLED
207
208 #if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP)
209   if (rgb_matrix_config.mode == RGB_MATRIX_TYPING_HEATMAP) {
210     process_rgb_matrix_typing_heatmap(record);
211   }
212 #endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP)
213
214   return true;
215 }
216
217 void rgb_matrix_test(void) {
218   // Mask out bits 4 and 5
219   // Increase the factor to make the test animation slower (and reduce to make it faster)
220   uint8_t factor = 10;
221   switch ( (g_rgb_counters.tick & (0b11 << factor)) >> factor )
222   {
223     case 0: {
224       rgb_matrix_set_color_all( 20, 0, 0 );
225       break;
226     }
227     case 1: {
228       rgb_matrix_set_color_all( 0, 20, 0 );
229       break;
230     }
231     case 2: {
232       rgb_matrix_set_color_all( 0, 0, 20 );
233       break;
234     }
235     case 3: {
236       rgb_matrix_set_color_all( 20, 20, 20 );
237       break;
238     }
239   }
240 }
241
242 static bool rgb_matrix_none(effect_params_t* params) {
243   if (!params->init) {
244     return false;
245   }
246
247   RGB_MATRIX_USE_LIMITS(led_min, led_max);
248   for (uint8_t i = led_min; i < led_max; i++) {
249     rgb_matrix_set_color(i, 0, 0, 0);
250   }
251   return led_max < DRIVER_LED_TOTAL;
252 }
253
254 static uint8_t rgb_last_enable = UINT8_MAX;
255 static uint8_t rgb_last_effect = UINT8_MAX;
256 static effect_params_t rgb_effect_params = { 0, 0xFF };
257 static rgb_task_states rgb_task_state = SYNCING;
258
259 static void rgb_task_timers(void) {
260   // Update double buffer timers
261   uint16_t deltaTime = timer_elapsed32(rgb_counters_buffer);
262   rgb_counters_buffer = timer_read32();
263   if (g_rgb_counters.any_key_hit < UINT32_MAX) {
264     if (UINT32_MAX - deltaTime < g_rgb_counters.any_key_hit) {
265       g_rgb_counters.any_key_hit = UINT32_MAX;
266     } else {
267       g_rgb_counters.any_key_hit += deltaTime;
268     }
269   }
270
271   // Update double buffer last hit timers
272 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
273   uint8_t count = last_hit_buffer.count;
274   for (uint8_t i = 0; i < count; ++i) {
275     if (UINT16_MAX - deltaTime < last_hit_buffer.tick[i]) {
276       last_hit_buffer.count--;
277       continue;
278     }
279     last_hit_buffer.tick[i] += deltaTime;
280   }
281 #endif // RGB_MATRIX_KEYREACTIVE_ENABLED
282 }
283
284 static void rgb_task_sync(void) {
285   // next task
286   if (timer_elapsed32(g_rgb_counters.tick) >= RGB_MATRIX_LED_FLUSH_LIMIT)
287     rgb_task_state = STARTING;
288 }
289
290 static void rgb_task_start(void) {
291   // reset iter
292   rgb_effect_params.iter = 0;
293
294   // update double buffers
295   g_rgb_counters.tick = rgb_counters_buffer;
296 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
297   g_last_hit_tracker = last_hit_buffer;
298 #endif // RGB_MATRIX_KEYREACTIVE_ENABLED
299
300   // next task
301   rgb_task_state = RENDERING;
302 }
303
304 static void rgb_task_render(uint8_t effect) {
305   bool rendering = false;
306   rgb_effect_params.init = (effect != rgb_last_effect) || (rgb_matrix_config.enable != rgb_last_enable);
307
308   // each effect can opt to do calculations
309   // and/or request PWM buffer updates.
310   switch (effect) {
311     case RGB_MATRIX_NONE:
312       rendering = rgb_matrix_none(&rgb_effect_params);
313       break;
314
315 // ---------------------------------------------
316 // -----Begin rgb effect switch case macros-----
317 #define RGB_MATRIX_EFFECT(name, ...) \
318     case RGB_MATRIX_##name: \
319       rendering = name(&rgb_effect_params); \
320       break;
321 #include "rgb_matrix_animations/rgb_matrix_effects.inc"
322 #undef RGB_MATRIX_EFFECT
323
324 #if defined(RGB_MATRIX_CUSTOM_KB) || defined(RGB_MATRIX_CUSTOM_USER)
325   #define RGB_MATRIX_EFFECT(name, ...) \
326     case RGB_MATRIX_CUSTOM_##name: \
327       rendering = name(&rgb_effect_params); \
328       break;
329   #ifdef RGB_MATRIX_CUSTOM_KB
330     #include "rgb_matrix_kb.inc"
331   #endif
332   #ifdef RGB_MATRIX_CUSTOM_USER
333     #include "rgb_matrix_user.inc"
334   #endif
335   #undef RGB_MATRIX_EFFECT
336 #endif
337 // -----End rgb effect switch case macros-------
338 // ---------------------------------------------
339
340     // Factory default magic value
341     case UINT8_MAX: {
342         rgb_matrix_test();
343         rgb_task_state = FLUSHING;
344       }
345       return;
346   }
347
348   rgb_effect_params.iter++;
349
350   // next task
351   if (!rendering) {
352     rgb_task_state = FLUSHING;
353     if (!rgb_effect_params.init && effect == RGB_MATRIX_NONE) {
354       // We only need to flush once if we are RGB_MATRIX_NONE
355       rgb_task_state = SYNCING;
356     }
357   }
358 }
359
360 static void rgb_task_flush(uint8_t effect) {
361   // update last trackers after the first full render so we can init over several frames
362   rgb_last_effect = effect;
363   rgb_last_enable = rgb_matrix_config.enable;
364
365   // update pwm buffers
366   rgb_matrix_update_pwm_buffers();
367
368   // next task
369   rgb_task_state = SYNCING;
370 }
371
372 void rgb_matrix_task(void) {
373   rgb_task_timers();
374
375   // Ideally we would also stop sending zeros to the LED driver PWM buffers
376   // while suspended and just do a software shutdown. This is a cheap hack for now.
377   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));
378   uint8_t effect = suspend_backlight || !rgb_matrix_config.enable ? 0 : rgb_matrix_config.mode;
379
380   switch (rgb_task_state) {
381     case STARTING:
382       rgb_task_start();
383       break;
384     case RENDERING:
385       rgb_task_render(effect);
386       break;
387     case FLUSHING:
388       rgb_task_flush(effect);
389       break;
390     case SYNCING:
391       rgb_task_sync();
392       break;
393   }
394
395   if (!suspend_backlight) {
396     rgb_matrix_indicators();
397   }
398 }
399
400 void rgb_matrix_indicators(void) {
401   rgb_matrix_indicators_kb();
402   rgb_matrix_indicators_user();
403 }
404
405 __attribute__((weak))
406 void rgb_matrix_indicators_kb(void) {}
407
408 __attribute__((weak))
409 void rgb_matrix_indicators_user(void) {}
410
411 void rgb_matrix_init(void) {
412   rgb_matrix_driver.init();
413
414   // TODO: put the 1 second startup delay here?
415
416 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
417   g_last_hit_tracker.count = 0;
418   for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) {
419     g_last_hit_tracker.tick[i] = UINT16_MAX;
420   }
421
422   last_hit_buffer.count = 0;
423   for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) {
424     last_hit_buffer.tick[i] = UINT16_MAX;
425   }
426 #endif // RGB_MATRIX_KEYREACTIVE_ENABLED
427
428   if (!eeconfig_is_enabled()) {
429     dprintf("rgb_matrix_init_drivers eeconfig is not enabled.\n");
430     eeconfig_init();
431     eeconfig_update_rgb_matrix_default();
432   }
433
434   rgb_matrix_config.raw = eeconfig_read_rgb_matrix();
435   rgb_matrix_config.speed = UINT8_MAX / 2; //EECONFIG needs to be increased to support this
436   if (!rgb_matrix_config.mode) {
437     dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n");
438     eeconfig_update_rgb_matrix_default();
439     rgb_matrix_config.raw = eeconfig_read_rgb_matrix();
440   }
441   eeconfig_debug_rgb_matrix(); // display current eeprom values
442 }
443
444 void rgb_matrix_set_suspend_state(bool state) {
445   g_suspend_state = state;
446 }
447
448 void rgb_matrix_toggle(void) {
449   rgb_matrix_config.enable ^= 1;
450   rgb_task_state = STARTING;
451   eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
452 }
453
454 void rgb_matrix_enable(void) {
455   rgb_matrix_enable_noeeprom();
456   eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
457 }
458
459 void rgb_matrix_enable_noeeprom(void) {
460   if (!rgb_matrix_config.enable)
461     rgb_task_state = STARTING;
462   rgb_matrix_config.enable = 1;
463 }
464
465 void rgb_matrix_disable(void) {
466   rgb_matrix_disable_noeeprom();
467   eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
468 }
469
470 void rgb_matrix_disable_noeeprom(void) {
471   if (rgb_matrix_config.enable)
472     rgb_task_state = STARTING;
473   rgb_matrix_config.enable = 0;
474 }
475
476 void rgb_matrix_step(void) {
477   rgb_matrix_config.mode++;
478   if (rgb_matrix_config.mode >= RGB_MATRIX_EFFECT_MAX)
479     rgb_matrix_config.mode = 1;
480   rgb_task_state = STARTING;
481   eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
482 }
483
484 void rgb_matrix_step_reverse(void) {
485   rgb_matrix_config.mode--;
486   if (rgb_matrix_config.mode < 1)
487     rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1;
488   rgb_task_state = STARTING;
489   eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
490 }
491
492 void rgb_matrix_increase_hue(void) {
493   rgb_matrix_config.hsv.h += RGB_MATRIX_HUE_STEP;
494   eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
495 }
496
497 void rgb_matrix_decrease_hue(void) {
498   rgb_matrix_config.hsv.h -= RGB_MATRIX_HUE_STEP;
499   eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
500 }
501
502 void rgb_matrix_increase_sat(void) {
503   rgb_matrix_config.hsv.s = qadd8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP);
504   eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
505 }
506
507 void rgb_matrix_decrease_sat(void) {
508   rgb_matrix_config.hsv.s = qsub8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP);
509   eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
510 }
511
512 void rgb_matrix_increase_val(void) {
513   rgb_matrix_config.hsv.v = qadd8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP);
514   if (rgb_matrix_config.hsv.v > RGB_MATRIX_MAXIMUM_BRIGHTNESS)
515     rgb_matrix_config.hsv.v = RGB_MATRIX_MAXIMUM_BRIGHTNESS;
516   eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
517 }
518
519 void rgb_matrix_decrease_val(void) {
520   rgb_matrix_config.hsv.v = qsub8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP);
521   eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
522 }
523
524 void rgb_matrix_increase_speed(void) {
525   rgb_matrix_config.speed = qadd8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP);
526   eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this
527 }
528
529 void rgb_matrix_decrease_speed(void) {
530   rgb_matrix_config.speed = qsub8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP);
531   eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this
532 }
533
534 led_flags_t rgb_matrix_get_flags(void) {
535   return rgb_effect_params.flags;
536 }
537
538 void rgb_matrix_set_flags(led_flags_t flags) {
539   rgb_effect_params.flags = flags;
540 }
541
542 void rgb_matrix_mode(uint8_t mode) {
543   rgb_matrix_config.mode = mode;
544   rgb_task_state = STARTING;
545   eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
546 }
547
548 void rgb_matrix_mode_noeeprom(uint8_t mode) {
549   rgb_matrix_config.mode = mode;
550 }
551
552 uint8_t rgb_matrix_get_mode(void) {
553   return rgb_matrix_config.mode;
554 }
555
556 void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val) {
557   rgb_matrix_sethsv_noeeprom(hue, sat, val);
558   eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
559 }
560
561 void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) {
562   rgb_matrix_config.hsv.h = hue;
563   rgb_matrix_config.hsv.s = sat;
564   rgb_matrix_config.hsv.v = val;
565   if (rgb_matrix_config.hsv.v > RGB_MATRIX_MAXIMUM_BRIGHTNESS)
566     rgb_matrix_config.hsv.v = RGB_MATRIX_MAXIMUM_BRIGHTNESS;
567 }