You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

579 lines
18 KiB

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