led_matrix.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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. #include "led_matrix.h"
  20. #include "progmem.h"
  21. #include "config.h"
  22. #include "eeprom.h"
  23. #include <string.h>
  24. #include <math.h>
  25. #include "led_tables.h"
  26. #include <lib/lib8tion/lib8tion.h>
  27. #if defined(LED_DISABLE_AFTER_TIMEOUT) && !defined(LED_DISABLE_TIMEOUT)
  28. # define LED_DISABLE_TIMEOUT (LED_DISABLE_AFTER_TIMEOUT * 1200UL)
  29. #endif
  30. #ifndef LED_DISABLE_TIMEOUT
  31. # define LED_DISABLE_TIMEOUT 0
  32. #endif
  33. #ifndef LED_DISABLE_WHEN_USB_SUSPENDED
  34. # define LED_DISABLE_WHEN_USB_SUSPENDED false
  35. #endif
  36. #if !defined(LED_MATRIX_MAXIMUM_BRIGHTNESS) || LED_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX
  37. # undef LED_MATRIX_MAXIMUM_BRIGHTNESS
  38. # define LED_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX
  39. #endif
  40. #if !defined(LED_MATRIX_VAL_STEP)
  41. # define LED_MATRIX_VAL_STEP 8
  42. #endif
  43. #if !defined(LED_MATRIX_SPD_STEP)
  44. # define LED_MATRIX_SPD_STEP 16
  45. #endif
  46. #if !defined(LED_MATRIX_STARTUP_MODE)
  47. # define LED_MATRIX_STARTUP_MODE LED_MATRIX_UNIFORM_BRIGHTNESS
  48. #endif
  49. #if !defined(LED_MATRIX_STARTUP_VAL)
  50. # define LED_MATRIX_STARTUP_VAL LED_MATRIX_MAXIMUM_BRIGHTNESS
  51. #endif
  52. #if !defined(LED_MATRIX_STARTUP_SPD)
  53. # define LED_MATRIX_STARTUP_SPD UINT8_MAX / 2
  54. #endif
  55. // globals
  56. bool g_suspend_state = false;
  57. led_eeconfig_t led_matrix_eeconfig; // TODO: would like to prefix this with g_ for global consistancy, do this in another pr
  58. uint32_t g_led_timer;
  59. #ifdef LED_MATRIX_FRAMEBUFFER_EFFECTS
  60. uint8_t g_led_frame_buffer[MATRIX_ROWS][MATRIX_COLS] = {{0}};
  61. #endif // LED_MATRIX_FRAMEBUFFER_EFFECTS
  62. #ifdef LED_MATRIX_KEYREACTIVE_ENABLED
  63. last_hit_t g_last_hit_tracker;
  64. #endif // LED_MATRIX_KEYREACTIVE_ENABLED
  65. // internals
  66. static uint8_t led_last_enable = UINT8_MAX;
  67. static uint8_t led_last_effect = UINT8_MAX;
  68. static effect_params_t led_effect_params = {0, LED_FLAG_ALL, false};
  69. static led_task_states led_task_state = SYNCING;
  70. #if LED_DISABLE_TIMEOUT > 0
  71. static uint32_t led_anykey_timer;
  72. #endif // LED_DISABLE_TIMEOUT > 0
  73. // double buffers
  74. static uint32_t led_timer_buffer;
  75. #ifdef LED_MATRIX_KEYREACTIVE_ENABLED
  76. static last_hit_t last_hit_buffer;
  77. #endif // LED_MATRIX_KEYREACTIVE_ENABLED
  78. void eeconfig_read_led_matrix(void) { eeprom_read_block(&led_matrix_eeconfig, EECONFIG_LED_MATRIX, sizeof(led_matrix_eeconfig)); }
  79. void eeconfig_update_led_matrix(void) { eeprom_update_block(&led_matrix_eeconfig, EECONFIG_LED_MATRIX, sizeof(led_matrix_eeconfig)); }
  80. void eeconfig_update_led_matrix_default(void) {
  81. dprintf("eeconfig_update_led_matrix_default\n");
  82. led_matrix_eeconfig.enable = 1;
  83. led_matrix_eeconfig.mode = LED_MATRIX_STARTUP_MODE;
  84. led_matrix_eeconfig.val = LED_MATRIX_STARTUP_VAL;
  85. led_matrix_eeconfig.speed = LED_MATRIX_STARTUP_SPD;
  86. led_matrix_eeconfig.flags = LED_FLAG_ALL;
  87. eeconfig_update_led_matrix();
  88. }
  89. void eeconfig_debug_led_matrix(void) {
  90. dprintf("led_matrix_eeconfig EEPROM\n");
  91. dprintf("led_matrix_eeconfig.enable = %d\n", led_matrix_eeconfig.enable);
  92. dprintf("led_matrix_eeconfig.mode = %d\n", led_matrix_eeconfig.mode);
  93. dprintf("led_matrix_eeconfig.val = %d\n", led_matrix_eeconfig.val);
  94. dprintf("led_matrix_eeconfig.speed = %d\n", led_matrix_eeconfig.speed);
  95. dprintf("led_matrix_eeconfig.flags = %d\n", led_matrix_eeconfig.flags);
  96. }
  97. __attribute__((weak)) uint8_t led_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i) { return 0; }
  98. uint8_t led_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) {
  99. uint8_t led_count = led_matrix_map_row_column_to_led_kb(row, column, led_i);
  100. uint8_t led_index = g_led_config.matrix_co[row][column];
  101. if (led_index != NO_LED) {
  102. led_i[led_count] = led_index;
  103. led_count++;
  104. }
  105. return led_count;
  106. }
  107. void led_matrix_update_pwm_buffers(void) { led_matrix_driver.flush(); }
  108. void led_matrix_set_value(int index, uint8_t value) {
  109. #ifdef USE_CIE1931_CURVE
  110. led_matrix_driver.set_value(index, pgm_read_byte(&CIE1931_CURVE[value]));
  111. #else
  112. led_matrix_driver.set_value(index, value);
  113. #endif
  114. }
  115. void led_matrix_set_value_all(uint8_t value) {
  116. #ifdef USE_CIE1931_CURVE
  117. led_matrix_driver.set_value_all(pgm_read_byte(&CIE1931_CURVE[value]));
  118. #else
  119. led_matrix_driver.set_value_all(value);
  120. #endif
  121. }
  122. void process_led_matrix(uint8_t row, uint8_t col, bool pressed) {
  123. #if LED_DISABLE_TIMEOUT > 0
  124. led_anykey_timer = 0;
  125. #endif // LED_DISABLE_TIMEOUT > 0
  126. #ifdef LED_MATRIX_KEYREACTIVE_ENABLED
  127. uint8_t led[LED_HITS_TO_REMEMBER];
  128. uint8_t led_count = 0;
  129. # if defined(LED_MATRIX_KEYRELEASES)
  130. if (!pressed)
  131. # elif defined(LED_MATRIX_KEYPRESSES)
  132. if (pressed)
  133. # endif // defined(LED_MATRIX_KEYRELEASES)
  134. {
  135. led_count = led_matrix_map_row_column_to_led(row, col, led);
  136. }
  137. if (last_hit_buffer.count + led_count > LED_HITS_TO_REMEMBER) {
  138. memcpy(&last_hit_buffer.x[0], &last_hit_buffer.x[led_count], LED_HITS_TO_REMEMBER - led_count);
  139. memcpy(&last_hit_buffer.y[0], &last_hit_buffer.y[led_count], LED_HITS_TO_REMEMBER - led_count);
  140. memcpy(&last_hit_buffer.tick[0], &last_hit_buffer.tick[led_count], (LED_HITS_TO_REMEMBER - led_count) * 2); // 16 bit
  141. memcpy(&last_hit_buffer.index[0], &last_hit_buffer.index[led_count], LED_HITS_TO_REMEMBER - led_count);
  142. last_hit_buffer.count--;
  143. }
  144. for (uint8_t i = 0; i < led_count; i++) {
  145. uint8_t index = last_hit_buffer.count;
  146. last_hit_buffer.x[index] = g_led_config.point[led[i]].x;
  147. last_hit_buffer.y[index] = g_led_config.point[led[i]].y;
  148. last_hit_buffer.index[index] = led[i];
  149. last_hit_buffer.tick[index] = 0;
  150. last_hit_buffer.count++;
  151. }
  152. #endif // LED_MATRIX_KEYREACTIVE_ENABLED
  153. #if defined(LED_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_LED_MATRIX_TYPING_HEATMAP)
  154. if (led_matrix_eeconfig.mode == LED_MATRIX_TYPING_HEATMAP) {
  155. process_led_matrix_typing_heatmap(row, col);
  156. }
  157. #endif // defined(LED_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_LED_MATRIX_TYPING_HEATMAP)
  158. }
  159. static bool led_matrix_none(effect_params_t *params) {
  160. if (!params->init) {
  161. return false;
  162. }
  163. led_matrix_set_value_all(0);
  164. return false;
  165. }
  166. static bool led_matrix_uniform_brightness(effect_params_t *params) {
  167. LED_MATRIX_USE_LIMITS(led_min, led_max);
  168. uint8_t val = led_matrix_eeconfig.val;
  169. for (uint8_t i = led_min; i < led_max; i++) {
  170. LED_MATRIX_TEST_LED_FLAGS();
  171. led_matrix_set_value(i, val);
  172. }
  173. return led_max < DRIVER_LED_TOTAL;
  174. }
  175. static void led_task_timers(void) {
  176. #if defined(LED_MATRIX_KEYREACTIVE_ENABLED) || LED_DISABLE_TIMEOUT > 0
  177. uint32_t deltaTime = sync_timer_elapsed32(led_timer_buffer);
  178. #endif // defined(LED_MATRIX_KEYREACTIVE_ENABLED) || LED_DISABLE_TIMEOUT > 0
  179. led_timer_buffer = sync_timer_read32();
  180. // Update double buffer timers
  181. #if LED_DISABLE_TIMEOUT > 0
  182. if (led_anykey_timer < UINT32_MAX) {
  183. if (UINT32_MAX - deltaTime < led_anykey_timer) {
  184. led_anykey_timer = UINT32_MAX;
  185. } else {
  186. led_anykey_timer += deltaTime;
  187. }
  188. }
  189. #endif // LED_DISABLE_TIMEOUT > 0
  190. // Update double buffer last hit timers
  191. #ifdef LED_MATRIX_KEYREACTIVE_ENABLED
  192. uint8_t count = last_hit_buffer.count;
  193. for (uint8_t i = 0; i < count; ++i) {
  194. if (UINT16_MAX - deltaTime < last_hit_buffer.tick[i]) {
  195. last_hit_buffer.count--;
  196. continue;
  197. }
  198. last_hit_buffer.tick[i] += deltaTime;
  199. }
  200. #endif // LED_MATRIX_KEYREACTIVE_ENABLED
  201. }
  202. static void led_task_sync(void) {
  203. // next task
  204. if (sync_timer_elapsed32(g_led_timer) >= LED_MATRIX_LED_FLUSH_LIMIT) led_task_state = STARTING;
  205. }
  206. static void led_task_start(void) {
  207. // reset iter
  208. led_effect_params.iter = 0;
  209. // update double buffers
  210. g_led_timer = led_timer_buffer;
  211. #ifdef LED_MATRIX_KEYREACTIVE_ENABLED
  212. g_last_hit_tracker = last_hit_buffer;
  213. #endif // LED_MATRIX_KEYREACTIVE_ENABLED
  214. // next task
  215. led_task_state = RENDERING;
  216. }
  217. static void led_task_render(uint8_t effect) {
  218. bool rendering = false;
  219. led_effect_params.init = (effect != led_last_effect) || (led_matrix_eeconfig.enable != led_last_enable);
  220. if (led_effect_params.flags != led_matrix_eeconfig.flags) {
  221. led_effect_params.flags = led_matrix_eeconfig.flags;
  222. led_matrix_set_value_all(0);
  223. }
  224. // each effect can opt to do calculations
  225. // and/or request PWM buffer updates.
  226. switch (effect) {
  227. case LED_MATRIX_NONE:
  228. rendering = led_matrix_none(&led_effect_params);
  229. break;
  230. case LED_MATRIX_UNIFORM_BRIGHTNESS:
  231. rendering = led_matrix_uniform_brightness(&led_effect_params);
  232. break;
  233. }
  234. led_effect_params.iter++;
  235. // next task
  236. if (!rendering) {
  237. led_task_state = FLUSHING;
  238. if (!led_effect_params.init && effect == LED_MATRIX_NONE) {
  239. // We only need to flush once if we are LED_MATRIX_NONE
  240. led_task_state = SYNCING;
  241. }
  242. }
  243. }
  244. static void led_task_flush(uint8_t effect) {
  245. // update last trackers after the first full render so we can init over several frames
  246. led_last_effect = effect;
  247. led_last_enable = led_matrix_eeconfig.enable;
  248. // update pwm buffers
  249. led_matrix_update_pwm_buffers();
  250. // next task
  251. led_task_state = SYNCING;
  252. }
  253. void led_matrix_task(void) {
  254. led_task_timers();
  255. // Ideally we would also stop sending zeros to the LED driver PWM buffers
  256. // while suspended and just do a software shutdown. This is a cheap hack for now.
  257. bool suspend_backlight =
  258. #if LED_DISABLE_WHEN_USB_SUSPENDED == true
  259. g_suspend_state ||
  260. #endif // LED_DISABLE_WHEN_USB_SUSPENDED == true
  261. #if LED_DISABLE_TIMEOUT > 0
  262. (led_anykey_timer > (uint32_t)LED_DISABLE_TIMEOUT) ||
  263. #endif // LED_DISABLE_TIMEOUT > 0
  264. false;
  265. uint8_t effect = suspend_backlight || !led_matrix_eeconfig.enable ? 0 : led_matrix_eeconfig.mode;
  266. switch (led_task_state) {
  267. case STARTING:
  268. led_task_start();
  269. break;
  270. case RENDERING:
  271. led_task_render(effect);
  272. if (effect) {
  273. led_matrix_indicators();
  274. led_matrix_indicators_advanced(&led_effect_params);
  275. }
  276. break;
  277. case FLUSHING:
  278. led_task_flush(effect);
  279. break;
  280. case SYNCING:
  281. led_task_sync();
  282. break;
  283. }
  284. }
  285. void led_matrix_indicators(void) {
  286. led_matrix_indicators_kb();
  287. led_matrix_indicators_user();
  288. }
  289. __attribute__((weak)) void led_matrix_indicators_kb(void) {}
  290. __attribute__((weak)) void led_matrix_indicators_user(void) {}
  291. void led_matrix_indicators_advanced(effect_params_t *params) {
  292. /* special handling is needed for "params->iter", since it's already been incremented.
  293. * Could move the invocations to led_task_render, but then it's missing a few checks
  294. * and not sure which would be better. Otherwise, this should be called from
  295. * led_task_render, right before the iter++ line.
  296. */
  297. #if defined(LED_MATRIX_LED_PROCESS_LIMIT) && LED_MATRIX_LED_PROCESS_LIMIT > 0 && LED_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL
  298. uint8_t min = LED_MATRIX_LED_PROCESS_LIMIT * (params->iter - 1);
  299. uint8_t max = min + LED_MATRIX_LED_PROCESS_LIMIT;
  300. if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL;
  301. #else
  302. uint8_t min = 0;
  303. uint8_t max = DRIVER_LED_TOTAL;
  304. #endif
  305. led_matrix_indicators_advanced_kb(min, max);
  306. led_matrix_indicators_advanced_user(min, max);
  307. }
  308. __attribute__((weak)) void led_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {}
  309. __attribute__((weak)) void led_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {}
  310. void led_matrix_init(void) {
  311. led_matrix_driver.init();
  312. #ifdef LED_MATRIX_KEYREACTIVE_ENABLED
  313. g_last_hit_tracker.count = 0;
  314. for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) {
  315. g_last_hit_tracker.tick[i] = UINT16_MAX;
  316. }
  317. last_hit_buffer.count = 0;
  318. for (uint8_t i = 0; i < LED_HITS_TO_REMEMBER; ++i) {
  319. last_hit_buffer.tick[i] = UINT16_MAX;
  320. }
  321. #endif // LED_MATRIX_KEYREACTIVE_ENABLED
  322. if (!eeconfig_is_enabled()) {
  323. dprintf("led_matrix_init_drivers eeconfig is not enabled.\n");
  324. eeconfig_init();
  325. eeconfig_update_led_matrix_default();
  326. }
  327. eeconfig_read_led_matrix();
  328. if (!led_matrix_eeconfig.mode) {
  329. dprintf("led_matrix_init_drivers led_matrix_eeconfig.mode = 0. Write default values to EEPROM.\n");
  330. eeconfig_update_led_matrix_default();
  331. }
  332. eeconfig_debug_led_matrix(); // display current eeprom values
  333. }
  334. void led_matrix_set_suspend_state(bool state) {
  335. if (LED_DISABLE_WHEN_USB_SUSPENDED && state) {
  336. led_matrix_set_value_all(0); // turn off all LEDs when suspending
  337. }
  338. g_suspend_state = state;
  339. }
  340. bool led_matrix_get_suspend_state(void) { return g_suspend_state; }
  341. void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) {
  342. led_matrix_eeconfig.enable ^= 1;
  343. led_task_state = STARTING;
  344. if (write_to_eeprom) {
  345. eeconfig_update_led_matrix();
  346. }
  347. dprintf("led matrix toggle [%s]: led_matrix_eeconfig.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.enable);
  348. }
  349. void led_matrix_toggle_noeeprom(void) { led_matrix_toggle_eeprom_helper(false); }
  350. void led_matrix_toggle(void) { led_matrix_toggle_eeprom_helper(true); }
  351. void led_matrix_enable(void) {
  352. led_matrix_enable_noeeprom();
  353. eeconfig_update_led_matrix();
  354. }
  355. void led_matrix_enable_noeeprom(void) {
  356. if (!led_matrix_eeconfig.enable) led_task_state = STARTING;
  357. led_matrix_eeconfig.enable = 1;
  358. }
  359. void led_matrix_disable(void) {
  360. led_matrix_disable_noeeprom();
  361. eeconfig_update_led_matrix();
  362. }
  363. void led_matrix_disable_noeeprom(void) {
  364. if (led_matrix_eeconfig.enable) led_task_state = STARTING;
  365. led_matrix_eeconfig.enable = 0;
  366. }
  367. uint8_t led_matrix_is_enabled(void) { return led_matrix_eeconfig.enable; }
  368. void led_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) {
  369. if (!led_matrix_eeconfig.enable) {
  370. return;
  371. }
  372. if (mode < 1) {
  373. led_matrix_eeconfig.mode = 1;
  374. } else if (mode >= LED_MATRIX_EFFECT_MAX) {
  375. led_matrix_eeconfig.mode = LED_MATRIX_EFFECT_MAX - 1;
  376. } else {
  377. led_matrix_eeconfig.mode = mode;
  378. }
  379. led_task_state = STARTING;
  380. if (write_to_eeprom) {
  381. eeconfig_update_led_matrix();
  382. }
  383. dprintf("led matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.mode);
  384. }
  385. void led_matrix_mode_noeeprom(uint8_t mode) { led_matrix_mode_eeprom_helper(mode, false); }
  386. void led_matrix_mode(uint8_t mode) { led_matrix_mode_eeprom_helper(mode, true); }
  387. uint8_t led_matrix_get_mode(void) { return led_matrix_eeconfig.mode; }
  388. void led_matrix_step_helper(bool write_to_eeprom) {
  389. uint8_t mode = led_matrix_eeconfig.mode + 1;
  390. led_matrix_mode_eeprom_helper((mode < LED_MATRIX_EFFECT_MAX) ? mode : 1, write_to_eeprom);
  391. }
  392. void led_matrix_step_noeeprom(void) { led_matrix_step_helper(false); }
  393. void led_matrix_step(void) { led_matrix_step_helper(true); }
  394. void led_matrix_step_reverse_helper(bool write_to_eeprom) {
  395. uint8_t mode = led_matrix_eeconfig.mode - 1;
  396. led_matrix_mode_eeprom_helper((mode < 1) ? LED_MATRIX_EFFECT_MAX - 1 : mode, write_to_eeprom);
  397. }
  398. void led_matrix_step_reverse_noeeprom(void) { led_matrix_step_reverse_helper(false); }
  399. void led_matrix_step_reverse(void) { led_matrix_step_reverse_helper(true); }
  400. void led_matrix_set_val_eeprom_helper(uint8_t val, bool write_to_eeprom) {
  401. if (!led_matrix_eeconfig.enable) {
  402. return;
  403. }
  404. led_matrix_eeconfig.val = (val > LED_MATRIX_MAXIMUM_BRIGHTNESS) ? LED_MATRIX_MAXIMUM_BRIGHTNESS : val;
  405. if (write_to_eeprom) {
  406. eeconfig_update_led_matrix();
  407. }
  408. dprintf("led matrix set val [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.val);
  409. }
  410. void led_matrix_set_val_noeeprom(uint8_t val) { led_matrix_set_val_eeprom_helper(val, false); }
  411. void led_matrix_set_val(uint8_t val) { led_matrix_set_val_eeprom_helper(val, true); }
  412. uint8_t led_matrix_get_val(void) { return led_matrix_eeconfig.val; }
  413. void 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); }
  414. void led_matrix_increase_val_noeeprom(void) { led_matrix_increase_val_helper(false); }
  415. void led_matrix_increase_val(void) { led_matrix_increase_val_helper(true); }
  416. void 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); }
  417. void led_matrix_decrease_val_noeeprom(void) { led_matrix_decrease_val_helper(false); }
  418. void led_matrix_decrease_val(void) { led_matrix_decrease_val_helper(true); }
  419. void led_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) {
  420. led_matrix_eeconfig.speed = speed;
  421. if (write_to_eeprom) {
  422. eeconfig_update_led_matrix();
  423. }
  424. dprintf("led matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.speed);
  425. }
  426. void led_matrix_set_speed_noeeprom(uint8_t speed) { led_matrix_set_speed_eeprom_helper(speed, false); }
  427. void led_matrix_set_speed(uint8_t speed) { led_matrix_set_speed_eeprom_helper(speed, true); }
  428. uint8_t led_matrix_get_speed(void) { return led_matrix_eeconfig.speed; }
  429. void 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); }
  430. void led_matrix_increase_speed_noeeprom(void) { led_matrix_increase_speed_helper(false); }
  431. void led_matrix_increase_speed(void) { led_matrix_increase_speed_helper(true); }
  432. void 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); }
  433. void led_matrix_decrease_speed_noeeprom(void) { led_matrix_decrease_speed_helper(false); }
  434. void led_matrix_decrease_speed(void) { led_matrix_decrease_speed_helper(true); }
  435. led_flags_t led_matrix_get_flags(void) { return led_matrix_eeconfig.flags; }
  436. void led_matrix_set_flags(led_flags_t flags) { led_matrix_eeconfig.flags = flags; }