rgb_matrix.c 17 KB

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