rgb_matrix.c 16 KB

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