rgb_matrix.c 16 KB

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