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