aboutsummaryrefslogtreecommitdiff
path: root/quantum/led_matrix/led_matrix.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/led_matrix/led_matrix.c')
-rw-r--r--quantum/led_matrix/led_matrix.c577
1 files changed, 577 insertions, 0 deletions
diff --git a/quantum/led_matrix/led_matrix.c b/quantum/led_matrix/led_matrix.c
new file mode 100644
index 000000000..32788866c
--- /dev/null
+++ b/quantum/led_matrix/led_matrix.c
@@ -0,0 +1,577 @@
1/* Copyright 2017 Jason Williams
2 * Copyright 2017 Jack Humbert
3 * Copyright 2018 Yiancar
4 * Copyright 2019 Clueboard
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "led_matrix.h"
21#include "progmem.h"
22#include "config.h"
23#include "eeprom.h"
24#include <string.h>
25#include <math.h>
26#include "led_tables.h"
27
28#include <lib/lib8tion/lib8tion.h>
29
30#ifndef LED_MATRIX_CENTER
31const led_point_t k_led_matrix_center = {112, 32};
32#else
33const led_point_t k_led_matrix_center = LED_MATRIX_CENTER;
34#endif
35
36// clang-format off
37#ifndef LED_MATRIX_IMMEDIATE_EEPROM
38# define led_eeconfig_update(v) led_update_eeprom |= v
39#else
40# define led_eeconfig_update(v) if (v) eeconfig_update_led_matrix()
41#endif
42// clang-format on
43
44// Generic effect runners
45#include "led_matrix_runners.inc"
46
47// ------------------------------------------
48// -----Begin led effect includes macros-----
49#define LED_MATRIX_EFFECT(name)
50#define LED_MATRIX_CUSTOM_EFFECT_IMPLS
51
52#include "led_matrix_effects.inc"
53#ifdef LED_MATRIX_CUSTOM_KB
54# include "led_matrix_kb.inc"
55#endif
56#ifdef LED_MATRIX_CUSTOM_USER
57# include "led_matrix_user.inc"
58#endif
59
60#undef LED_MATRIX_CUSTOM_EFFECT_IMPLS
61#undef LED_MATRIX_EFFECT
62// -----End led effect includes macros-------
63// ------------------------------------------
64
65#if defined(LED_DISABLE_AFTER_TIMEOUT) && !defined(LED_DISABLE_TIMEOUT)
66# define LED_DISABLE_TIMEOUT (LED_DISABLE_AFTER_TIMEOUT * 1200UL)
67#endif
68
69#ifndef LED_DISABLE_TIMEOUT
70# define LED_DISABLE_TIMEOUT 0
71#endif
72
73#if !defined(LED_MATRIX_MAXIMUM_BRIGHTNESS) || LED_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX
74# undef LED_MATRIX_MAXIMUM_BRIGHTNESS
75# define LED_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX
76#endif
77
78#if !defined(LED_MATRIX_VAL_STEP)
79# define LED_MATRIX_VAL_STEP 8
80#endif
81
82#if !defined(LED_MATRIX_SPD_STEP)
83# define LED_MATRIX_SPD_STEP 16
84#endif
85
86#if !defined(LED_MATRIX_STARTUP_MODE)
87# define LED_MATRIX_STARTUP_MODE LED_MATRIX_SOLID
88#endif
89
90#if !defined(LED_MATRIX_STARTUP_VAL)
91# define LED_MATRIX_STARTUP_VAL LED_MATRIX_MAXIMUM_BRIGHTNESS
92#endif
93
94#if !defined(LED_MATRIX_STARTUP_SPD)
95# define LED_MATRIX_STARTUP_SPD UINT8_MAX / 2
96#endif
97
98// globals
99led_eeconfig_t led_matrix_eeconfig; // TODO: would like to prefix this with g_ for global consistancy, do this in another pr
100uint32_t g_led_timer;
101#ifdef LED_MATRIX_FRAMEBUFFER_EFFECTS
102uint8_t g_led_frame_buffer[MATRIX_ROWS][MATRIX_COLS] = {{0}};
103#endif // LED_MATRIX_FRAMEBUFFER_EFFECTS
104#ifdef LED_MATRIX_KEYREACTIVE_ENABLED
105last_hit_t g_last_hit_tracker;
106#endif // LED_MATRIX_KEYREACTIVE_ENABLED
107
108// internals
109static bool suspend_state = false;
110static bool led_update_eeprom = false;
111static uint8_t led_last_enable = UINT8_MAX;
112static uint8_t led_last_effect = UINT8_MAX;
113static effect_params_t led_effect_params = {0, LED_FLAG_ALL, false};
114static led_task_states led_task_state = SYNCING;
115#if LED_DISABLE_TIMEOUT > 0
116static uint32_t led_anykey_timer;
117#endif // LED_DISABLE_TIMEOUT > 0
118
119// double buffers
120static uint32_t led_timer_buffer;
121#ifdef LED_MATRIX_KEYREACTIVE_ENABLED
122static last_hit_t last_hit_buffer;
123#endif // LED_MATRIX_KEYREACTIVE_ENABLED
124
125// split led matrix
126#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
127const uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT;
128#endif
129
130void eeconfig_read_led_matrix(void) { eeprom_read_block(&led_matrix_eeconfig, EECONFIG_LED_MATRIX, sizeof(led_matrix_eeconfig)); }
131
132void eeconfig_update_led_matrix(void) { eeprom_update_block(&led_matrix_eeconfig, EECONFIG_LED_MATRIX, sizeof(led_matrix_eeconfig)); }
133
134void eeconfig_update_led_matrix_default(void) {
135 dprintf("eeconfig_update_led_matrix_default\n");
136 led_matrix_eeconfig.enable = 1;
137 led_matrix_eeconfig.mode = LED_MATRIX_STARTUP_MODE;
138 led_matrix_eeconfig.val = LED_MATRIX_STARTUP_VAL;
139 led_matrix_eeconfig.speed = LED_MATRIX_STARTUP_SPD;
140 led_matrix_eeconfig.flags = LED_FLAG_ALL;
141 eeconfig_update_led_matrix();
142}
143
144void eeconfig_debug_led_matrix(void) {
145 dprintf("led_matrix_eeconfig EEPROM\n");
146 dprintf("led_matrix_eeconfig.enable = %d\n", led_matrix_eeconfig.enable);
147 dprintf("led_matrix_eeconfig.mode = %d\n", led_matrix_eeconfig.mode);
148 dprintf("led_matrix_eeconfig.val = %d\n", led_matrix_eeconfig.val);
149 dprintf("led_matrix_eeconfig.speed = %d\n", led_matrix_eeconfig.speed);
150 dprintf("led_matrix_eeconfig.flags = %d\n", led_matrix_eeconfig.flags);
151}
152
153__attribute__((weak)) uint8_t led_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i) { return 0; }
154
155uint8_t led_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) {
156 uint8_t led_count = led_matrix_map_row_column_to_led_kb(row, column, led_i);
157 uint8_t led_index = g_led_config.matrix_co[row][column];
158 if (led_index != NO_LED) {
159 led_i[led_count] = led_index;
160 led_count++;
161 }
162 return led_count;
163}
164
165void led_matrix_update_pwm_buffers(void) { led_matrix_driver.flush(); }
166
167void led_matrix_set_value(int index, uint8_t value) {
168#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
169 if (!is_keyboard_left() && index >= k_led_matrix_split[0])
170# ifdef USE_CIE1931_CURVE
171 led_matrix_driver.set_value(index - k_led_matrix_split[0], pgm_read_byte(&CIE1931_CURVE[value]));
172# else
173 led_matrix_driver.set_value(index - k_led_matrix_split[0], value);
174# endif
175 else if (is_keyboard_left() && index < k_led_matrix_split[0])
176#endif
177#ifdef USE_CIE1931_CURVE
178 led_matrix_driver.set_value(index, pgm_read_byte(&CIE1931_CURVE[value]));
179#else
180 led_matrix_driver.set_value(index, value);
181#endif
182}
183
184void led_matrix_set_value_all(uint8_t value) {
185#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
186 for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) led_matrix_set_value(i, value);
187#else
188# ifdef USE_CIE1931_CURVE
189 led_matrix_driver.set_value_all(pgm_read_byte(&CIE1931_CURVE[value]));
190# else
191 led_matrix_driver.set_value_all(value);
192# endif
193#endif
194}
195
196void process_led_matrix(uint8_t row, uint8_t col, bool pressed) {
197#ifndef LED_MATRIX_SPLIT
198 if (!is_keyboard_master()) return;
199#endif
200#if LED_DISABLE_TIMEOUT > 0
201 led_anykey_timer = 0;
202#endif // LED_DISABLE_TIMEOUT > 0
203
204#ifdef LED_MATRIX_KEYREACTIVE_ENABLED
205 uint8_t led[LED_HITS_TO_REMEMBER];
206 uint8_t led_count = 0;
207
208# if defined(LED_MATRIX_KEYRELEASES)
209 if (!pressed)
210# elif defined(LED_MATRIX_KEYPRESSES)
211 if (pressed)
212# endif // defined(LED_MATRIX_KEYRELEASES)
213 {
214 led_count = led_matrix_map_row_column_to_led(row, col, led);
215 }
216
217 if (last_hit_buffer.count + led_count > LED_HITS_TO_REMEMBER) {
218 memcpy(&last_hit_buffer.x[0], &last_hit_buffer.x[led_count], LED_HITS_TO_REMEMBER - led_count);
219 memcpy(&last_hit_buffer.y[0], &last_hit_buffer.y[led_count], LED_HITS_TO_REMEMBER - led_count);
220 memcpy(&last_hit_buffer.tick[0], &last_hit_buffer.tick[led_count], (LED_HITS_TO_REMEMBER - led_count) * 2); // 16 bit
221 memcpy(&last_hit_buffer.index[0], &last_hit_buffer.index[led_count], LED_HITS_TO_REMEMBER - led_count);
222 last_hit_buffer.count--;
223 }
224
225 for (uint8_t i = 0; i < led_count; i++) {
226 uint8_t index = last_hit_buffer.count;
227 last_hit_buffer.x[index] = g_led_config.point[led[i]].x;
228 last_hit_buffer.y[index] = g_led_config.point[led[i]].y;
229 last_hit_buffer.index[index] = led[i];
230 last_hit_buffer.tick[index] = 0;
231 last_hit_buffer.count++;
232 }
233#endif // LED_MATRIX_KEYREACTIVE_ENABLED
234
235#if defined(LED_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_LED_MATRIX_TYPING_HEATMAP)
236 if (led_matrix_eeconfig.mode == LED_MATRIX_TYPING_HEATMAP) {
237 process_led_matrix_typing_heatmap(row, col);
238 }
239#endif // defined(LED_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_LED_MATRIX_TYPING_HEATMAP)
240}
241
242static bool led_matrix_none(effect_params_t *params) {
243 if (!params->init) {
244 return false;
245 }
246
247 led_matrix_set_value_all(0);
248 return false;
249}
250
251static void led_task_timers(void) {
252#if defined(LED_MATRIX_KEYREACTIVE_ENABLED) || LED_DISABLE_TIMEOUT > 0
253 uint32_t deltaTime = sync_timer_elapsed32(led_timer_buffer);
254#endif // defined(LED_MATRIX_KEYREACTIVE_ENABLED) || LED_DISABLE_TIMEOUT > 0
255 led_timer_buffer = sync_timer_read32();
256
257 // Update double buffer timers
258#if LED_DISABLE_TIMEOUT > 0
259 if (led_anykey_timer < UINT32_MAX) {
260 if (UINT32_MAX - deltaTime < led_anykey_timer) {
261 led_anykey_timer = UINT32_MAX;
262 } else {
263 led_anykey_timer += deltaTime;
264 }
265 }
266#endif // LED_DISABLE_TIMEOUT > 0
267
268 // Update double buffer last hit timers
269#ifdef LED_MATRIX_KEYREACTIVE_ENABLED
270 uint8_t count = last_hit_buffer.count;
271 for (uint8_t i = 0; i < count; ++i) {
272 if (UINT16_MAX - deltaTime < last_hit_buffer.tick[i]) {
273 last_hit_buffer.count--;
274 continue;
275 }
276 last_hit_buffer.tick[i] += deltaTime;
277 }
278#endif // LED_MATRIX_KEYREACTIVE_ENABLED
279}
280
281static void led_task_sync(void) {
282 // next task
283 if (led_update_eeprom) eeconfig_update_led_matrix();
284 led_update_eeprom = false;
285 if (sync_timer_elapsed32(g_led_timer) >= LED_MATRIX_LED_FLUSH_LIMIT) led_task_state = STARTING;
286}
287
288static void led_task_start(void) {
289 // reset iter
290 led_effect_params.iter = 0;
291
292 // update double buffers
293 g_led_timer = led_timer_buffer;
294#ifdef LED_MATRIX_KEYREACTIVE_ENABLED
295 g_last_hit_tracker = last_hit_buffer;
296#endif // LED_MATRIX_KEYREACTIVE_ENABLED
297
298 // next task
299 led_task_state = RENDERING;
300}
301
302static void led_task_render(uint8_t effect) {
303 bool rendering = false;
304 led_effect_params.init = (effect != led_last_effect) || (led_matrix_eeconfig.enable != led_last_enable);
305 if (led_effect_params.flags != led_matrix_eeconfig.flags) {
306 led_effect_params.flags = led_matrix_eeconfig.flags;
307 led_matrix_set_value_all(0);
308 }
309
310 // each effect can opt to do calculations
311 // and/or request PWM buffer updates.
312 switch (effect) {
313 case LED_MATRIX_NONE:
314 rendering = led_matrix_none(&led_effect_params);
315 break;
316
317// ---------------------------------------------
318// -----Begin led effect switch case macros-----
319#define LED_MATRIX_EFFECT(name, ...) \
320 case LED_MATRIX_##name: \
321 rendering = name(&led_effect_params); \
322 break;
323#include "led_matrix_effects.inc"
324#undef LED_MATRIX_EFFECT
325
326#if defined(LED_MATRIX_CUSTOM_KB) || defined(LED_MATRIX_CUSTOM_USER)
327# define LED_MATRIX_EFFECT(name, ...) \
328 case LED_MATRIX_CUSTOM_##name: \
329 rendering = name(&led_effect_params); \
330 break;
331# ifdef LED_MATRIX_CUSTOM_KB
332# include "led_matrix_kb.inc"
333# endif
334# ifdef LED_MATRIX_CUSTOM_USER
335# include "led_matrix_user.inc"
336# endif
337# undef LED_MATRIX_EFFECT
338#endif
339 // -----End led effect switch case macros-------
340 // ---------------------------------------------
341 }
342
343 led_effect_params.iter++;
344
345 // next task
346 if (!rendering) {
347 led_task_state = FLUSHING;
348 if (!led_effect_params.init && effect == LED_MATRIX_NONE) {
349 // We only need to flush once if we are LED_MATRIX_NONE
350 led_task_state = SYNCING;
351 }
352 }
353}
354
355static void led_task_flush(uint8_t effect) {
356 // update last trackers after the first full render so we can init over several frames
357 led_last_effect = effect;
358 led_last_enable = led_matrix_eeconfig.enable;
359
360 // update pwm buffers
361 led_matrix_update_pwm_buffers();
362
363 // next task
364 led_task_state = SYNCING;
365}
366
367void led_matrix_task(void) {
368 led_task_timers();
369
370 // Ideally we would also stop sending zeros to the LED driver PWM buffers
371 // while suspended and just do a software shutdown. This is a cheap hack for now.
372 bool suspend_backlight = suspend_state ||
373#if LED_DISABLE_TIMEOUT > 0
374 (led_anykey_timer > (uint32_t)LED_DISABLE_TIMEOUT) ||
375#endif // LED_DISABLE_TIMEOUT > 0
376 false;
377
378 uint8_t effect = suspend_backlight || !led_matrix_eeconfig.enable ? 0 : led_matrix_eeconfig.mode;
379
380 switch (led_task_state) {
381 case STARTING:
382 led_task_start();
383 break;
384 case RENDERING:
385 led_task_render(effect);
386 if (effect) {
387 led_matrix_indicators();
388 led_matrix_indicators_advanced(&led_effect_params);
389 }
390 break;
391 case FLUSHING:
392 led_task_flush(effect);
393 break;
394 case SYNCING:
395 led_task_sync();
396 break;
397 }
398}
399
400void led_matrix_indicators(void) {
401 led_matrix_indicators_kb();
402 led_matrix_indicators_user();
403}
404
405__attribute__((weak)) void led_matrix_indicators_kb(void) {}
406
407__attribute__((weak)) void led_matrix_indicators_user(void) {}
408
409void led_matrix_indicators_advanced(effect_params_t *params) {
410 /* special handling is needed for "params->iter", since it's already been incremented.
411 * Could move the invocations to led_task_render, but then it's missing a few checks
412 * and not sure which would be better. Otherwise, this should be called from
413 * led_task_render, right before the iter++ line.
414 */
415#if defined(LED_MATRIX_LED_PROCESS_LIMIT) && LED_MATRIX_LED_PROCESS_LIMIT > 0 && LED_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL
416 uint8_t min = LED_MATRIX_LED_PROCESS_LIMIT * (params->iter - 1);
417 uint8_t max = min + LED_MATRIX_LED_PROCESS_LIMIT;
418 if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL;
419#else
420 uint8_t min = 0;
421 uint8_t max = DRIVER_LED_TOTAL;
422#endif
423 led_matrix_indicators_advanced_kb(min, max);
424 led_matrix_indicators_advanced_user(min, max);
425}
426
427__attribute__((weak)) void led_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {}
428
429__attribute__((weak)) void led_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {}
430
431void led_matrix_init(void) {
432 led_matrix_driver.init();
433
434#ifdef LED_MATRIX_KEYREACTIVE_ENABLED
435 g_last_hit_tracker.count = 0;
436 for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) {
437 g_last_hit_tracker.tick[i] = UINT16_MAX;
438 }
439
440 last_hit_buffer.count = 0;
441 for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) {
442 last_hit_buffer.tick[i] = UINT16_MAX;
443 }
444#endif // LED_MATRIX_KEYREACTIVE_ENABLED
445
446 if (!eeconfig_is_enabled()) {
447 dprintf("led_matrix_init_drivers eeconfig is not enabled.\n");
448 eeconfig_init();
449 eeconfig_update_led_matrix_default();
450 }
451
452 eeconfig_read_led_matrix();
453 if (!led_matrix_eeconfig.mode) {
454 dprintf("led_matrix_init_drivers led_matrix_eeconfig.mode = 0. Write default values to EEPROM.\n");
455 eeconfig_update_led_matrix_default();
456 }
457 eeconfig_debug_led_matrix(); // display current eeprom values
458}
459
460void led_matrix_set_suspend_state(bool state) {
461#ifdef LED_DISABLE_WHEN_USB_SUSPENDED
462 if (state) {
463 led_matrix_set_value_all(0); // turn off all LEDs when suspending
464 }
465 suspend_state = state;
466#endif
467}
468
469bool led_matrix_get_suspend_state(void) { return suspend_state; }
470
471void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) {
472 led_matrix_eeconfig.enable ^= 1;
473 led_task_state = STARTING;
474 led_eeconfig_update(write_to_eeprom);
475 dprintf("led matrix toggle [%s]: led_matrix_eeconfig.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.enable);
476}
477void led_matrix_toggle_noeeprom(void) { led_matrix_toggle_eeprom_helper(false); }
478void led_matrix_toggle(void) { led_matrix_toggle_eeprom_helper(true); }
479
480void led_matrix_enable(void) {
481 led_matrix_enable_noeeprom();
482 led_eeconfig_update(true);
483}
484
485void led_matrix_enable_noeeprom(void) {
486 if (!led_matrix_eeconfig.enable) led_task_state = STARTING;
487 led_matrix_eeconfig.enable = 1;
488}
489
490void led_matrix_disable(void) {
491 led_matrix_disable_noeeprom();
492 led_eeconfig_update(true);
493}
494
495void led_matrix_disable_noeeprom(void) {
496 if (led_matrix_eeconfig.enable) led_task_state = STARTING;
497 led_matrix_eeconfig.enable = 0;
498}
499
500uint8_t led_matrix_is_enabled(void) { return led_matrix_eeconfig.enable; }
501
502void led_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) {
503 if (!led_matrix_eeconfig.enable) {
504 return;
505 }
506 if (mode < 1) {
507 led_matrix_eeconfig.mode = 1;
508 } else if (mode >= LED_MATRIX_EFFECT_MAX) {
509 led_matrix_eeconfig.mode = LED_MATRIX_EFFECT_MAX - 1;
510 } else {
511 led_matrix_eeconfig.mode = mode;
512 }
513 led_task_state = STARTING;
514 led_eeconfig_update(write_to_eeprom);
515 dprintf("led matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.mode);
516}
517void led_matrix_mode_noeeprom(uint8_t mode) { led_matrix_mode_eeprom_helper(mode, false); }
518void led_matrix_mode(uint8_t mode) { led_matrix_mode_eeprom_helper(mode, true); }
519
520uint8_t led_matrix_get_mode(void) { return led_matrix_eeconfig.mode; }
521
522void led_matrix_step_helper(bool write_to_eeprom) {
523 uint8_t mode = led_matrix_eeconfig.mode + 1;
524 led_matrix_mode_eeprom_helper((mode < LED_MATRIX_EFFECT_MAX) ? mode : 1, write_to_eeprom);
525}
526void led_matrix_step_noeeprom(void) { led_matrix_step_helper(false); }
527void led_matrix_step(void) { led_matrix_step_helper(true); }
528
529void led_matrix_step_reverse_helper(bool write_to_eeprom) {
530 uint8_t mode = led_matrix_eeconfig.mode - 1;
531 led_matrix_mode_eeprom_helper((mode < 1) ? LED_MATRIX_EFFECT_MAX - 1 : mode, write_to_eeprom);
532}
533void led_matrix_step_reverse_noeeprom(void) { led_matrix_step_reverse_helper(false); }
534void led_matrix_step_reverse(void) { led_matrix_step_reverse_helper(true); }
535
536void led_matrix_set_val_eeprom_helper(uint8_t val, bool write_to_eeprom) {
537 if (!led_matrix_eeconfig.enable) {
538 return;
539 }
540 led_matrix_eeconfig.val = (val > LED_MATRIX_MAXIMUM_BRIGHTNESS) ? LED_MATRIX_MAXIMUM_BRIGHTNESS : val;
541 led_eeconfig_update(write_to_eeprom);
542 dprintf("led matrix set val [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.val);
543}
544void led_matrix_set_val_noeeprom(uint8_t val) { led_matrix_set_val_eeprom_helper(val, false); }
545void led_matrix_set_val(uint8_t val) { led_matrix_set_val_eeprom_helper(val, true); }
546
547uint8_t led_matrix_get_val(void) { return led_matrix_eeconfig.val; }
548
549void led_matrix_increase_val_helper(bool write_to_eeprom) { led_matrix_set_val_eeprom_helper(qadd8(led_matrix_eeconfig.val, LED_MATRIX_VAL_STEP), write_to_eeprom); }
550void led_matrix_increase_val_noeeprom(void) { led_matrix_increase_val_helper(false); }
551void led_matrix_increase_val(void) { led_matrix_increase_val_helper(true); }
552
553void led_matrix_decrease_val_helper(bool write_to_eeprom) { led_matrix_set_val_eeprom_helper(qsub8(led_matrix_eeconfig.val, LED_MATRIX_VAL_STEP), write_to_eeprom); }
554void led_matrix_decrease_val_noeeprom(void) { led_matrix_decrease_val_helper(false); }
555void led_matrix_decrease_val(void) { led_matrix_decrease_val_helper(true); }
556
557void led_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) {
558 led_matrix_eeconfig.speed = speed;
559 led_eeconfig_update(write_to_eeprom);
560 dprintf("led matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.speed);
561}
562void led_matrix_set_speed_noeeprom(uint8_t speed) { led_matrix_set_speed_eeprom_helper(speed, false); }
563void led_matrix_set_speed(uint8_t speed) { led_matrix_set_speed_eeprom_helper(speed, true); }
564
565uint8_t led_matrix_get_speed(void) { return led_matrix_eeconfig.speed; }
566
567void led_matrix_increase_speed_helper(bool write_to_eeprom) { led_matrix_set_speed_eeprom_helper(qadd8(led_matrix_eeconfig.speed, LED_MATRIX_SPD_STEP), write_to_eeprom); }
568void led_matrix_increase_speed_noeeprom(void) { led_matrix_increase_speed_helper(false); }
569void led_matrix_increase_speed(void) { led_matrix_increase_speed_helper(true); }
570
571void led_matrix_decrease_speed_helper(bool write_to_eeprom) { led_matrix_set_speed_eeprom_helper(qsub8(led_matrix_eeconfig.speed, LED_MATRIX_SPD_STEP), write_to_eeprom); }
572void led_matrix_decrease_speed_noeeprom(void) { led_matrix_decrease_speed_helper(false); }
573void led_matrix_decrease_speed(void) { led_matrix_decrease_speed_helper(true); }
574
575led_flags_t led_matrix_get_flags(void) { return led_matrix_eeconfig.flags; }
576
577void led_matrix_set_flags(led_flags_t flags) { led_matrix_eeconfig.flags = flags; }