rgb_matrix.c 17 KB

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