logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

rgb_matrix.h (10527B)


  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. #pragma once
  19. #include <stdint.h>
  20. #include <stdbool.h>
  21. #include "rgb_matrix_types.h"
  22. #include "rgb_matrix_drivers.h"
  23. #include "color.h"
  24. #include "keyboard.h"
  25. #ifndef RGB_MATRIX_TIMEOUT
  26. # define RGB_MATRIX_TIMEOUT 0
  27. #endif
  28. #ifndef RGB_MATRIX_MAXIMUM_BRIGHTNESS
  29. # define RGB_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX
  30. #endif
  31. #ifndef RGB_MATRIX_HUE_STEP
  32. # define RGB_MATRIX_HUE_STEP 8
  33. #endif
  34. #ifndef RGB_MATRIX_SAT_STEP
  35. # define RGB_MATRIX_SAT_STEP 16
  36. #endif
  37. #ifndef RGB_MATRIX_VAL_STEP
  38. # define RGB_MATRIX_VAL_STEP 16
  39. #endif
  40. #ifndef RGB_MATRIX_SPD_STEP
  41. # define RGB_MATRIX_SPD_STEP 16
  42. #endif
  43. #ifndef RGB_MATRIX_DEFAULT_ON
  44. # define RGB_MATRIX_DEFAULT_ON true
  45. #endif
  46. #ifndef RGB_MATRIX_DEFAULT_MODE
  47. # ifdef ENABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
  48. # define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_CYCLE_LEFT_RIGHT
  49. # else
  50. // fallback to solid colors if RGB_MATRIX_CYCLE_LEFT_RIGHT is disabled in userspace
  51. # define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_SOLID_COLOR
  52. # endif
  53. #endif
  54. #ifndef RGB_MATRIX_DEFAULT_HUE
  55. # define RGB_MATRIX_DEFAULT_HUE 0
  56. #endif
  57. #ifndef RGB_MATRIX_DEFAULT_SAT
  58. # define RGB_MATRIX_DEFAULT_SAT UINT8_MAX
  59. #endif
  60. #ifndef RGB_MATRIX_DEFAULT_VAL
  61. # define RGB_MATRIX_DEFAULT_VAL RGB_MATRIX_MAXIMUM_BRIGHTNESS
  62. #endif
  63. #ifndef RGB_MATRIX_DEFAULT_SPD
  64. # define RGB_MATRIX_DEFAULT_SPD UINT8_MAX / 2
  65. #endif
  66. #ifndef RGB_MATRIX_DEFAULT_FLAGS
  67. # define RGB_MATRIX_DEFAULT_FLAGS LED_FLAG_ALL
  68. #endif
  69. #ifndef RGB_MATRIX_LED_FLUSH_LIMIT
  70. # define RGB_MATRIX_LED_FLUSH_LIMIT 16
  71. #endif
  72. #ifndef RGB_MATRIX_LED_PROCESS_LIMIT
  73. # define RGB_MATRIX_LED_PROCESS_LIMIT ((RGB_MATRIX_LED_COUNT + 4) / 5)
  74. #endif
  75. struct rgb_matrix_limits_t {
  76. uint8_t led_min_index;
  77. uint8_t led_max_index;
  78. };
  79. struct rgb_matrix_limits_t rgb_matrix_get_limits(uint8_t iter);
  80. #define RGB_MATRIX_USE_LIMITS_ITER(min, max, iter) \
  81. struct rgb_matrix_limits_t limits = rgb_matrix_get_limits(iter); \
  82. uint8_t min = limits.led_min_index; \
  83. uint8_t max = limits.led_max_index; \
  84. (void)min; \
  85. (void)max;
  86. #define RGB_MATRIX_USE_LIMITS(min, max) RGB_MATRIX_USE_LIMITS_ITER(min, max, params->iter)
  87. #define RGB_MATRIX_INDICATOR_SET_COLOR(i, r, g, b) \
  88. if (i >= led_min && i < led_max) { \
  89. rgb_matrix_set_color(i, r, g, b); \
  90. }
  91. #define RGB_MATRIX_TEST_LED_FLAGS() \
  92. if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) continue
  93. enum rgb_matrix_effects {
  94. RGB_MATRIX_NONE = 0,
  95. // --------------------------------------
  96. // -----Begin rgb effect enum macros-----
  97. #define RGB_MATRIX_EFFECT(name, ...) RGB_MATRIX_##name,
  98. #include "rgb_matrix_effects.inc"
  99. #undef RGB_MATRIX_EFFECT
  100. #ifdef COMMUNITY_MODULES_ENABLE
  101. # define RGB_MATRIX_EFFECT(name, ...) RGB_MATRIX_COMMUNITY_MODULE_##name,
  102. # include "rgb_matrix_community_modules.inc"
  103. # undef RGB_MATRIX_EFFECT
  104. #endif
  105. #if defined(RGB_MATRIX_CUSTOM_KB) || defined(RGB_MATRIX_CUSTOM_USER)
  106. # define RGB_MATRIX_EFFECT(name, ...) RGB_MATRIX_CUSTOM_##name,
  107. # ifdef RGB_MATRIX_CUSTOM_KB
  108. # include "rgb_matrix_kb.inc"
  109. # endif
  110. # ifdef RGB_MATRIX_CUSTOM_USER
  111. # include "rgb_matrix_user.inc"
  112. # endif
  113. # undef RGB_MATRIX_EFFECT
  114. #endif
  115. // --------------------------------------
  116. // -----End rgb effect enum macros-------
  117. RGB_MATRIX_EFFECT_MAX
  118. };
  119. void eeconfig_update_rgb_matrix_default(void);
  120. void eeconfig_force_flush_rgb_matrix(void);
  121. uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i);
  122. uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i);
  123. int rgb_matrix_led_index(int index);
  124. void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
  125. void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
  126. void rgb_matrix_handle_key_event(uint8_t row, uint8_t col, bool pressed);
  127. void rgb_matrix_task(void);
  128. // This runs after another backlight effect and replaces
  129. // colors already set
  130. void rgb_matrix_indicators(void);
  131. bool rgb_matrix_indicators_kb(void);
  132. bool rgb_matrix_indicators_user(void);
  133. void rgb_matrix_indicators_advanced(effect_params_t *params);
  134. bool rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max);
  135. bool rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max);
  136. void rgb_matrix_init(void);
  137. void rgb_matrix_reload_from_eeprom(void);
  138. void rgb_matrix_set_suspend_state(bool state);
  139. bool rgb_matrix_get_suspend_state(void);
  140. void rgb_matrix_toggle(void);
  141. void rgb_matrix_toggle_noeeprom(void);
  142. void rgb_matrix_enable(void);
  143. void rgb_matrix_enable_noeeprom(void);
  144. void rgb_matrix_disable(void);
  145. void rgb_matrix_disable_noeeprom(void);
  146. uint8_t rgb_matrix_is_enabled(void);
  147. void rgb_matrix_mode(uint8_t mode);
  148. void rgb_matrix_mode_noeeprom(uint8_t mode);
  149. uint8_t rgb_matrix_get_mode(void);
  150. void rgb_matrix_step(void);
  151. void rgb_matrix_step_noeeprom(void);
  152. void rgb_matrix_step_reverse(void);
  153. void rgb_matrix_step_reverse_noeeprom(void);
  154. void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val);
  155. void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val);
  156. hsv_t rgb_matrix_get_hsv(void);
  157. uint8_t rgb_matrix_get_hue(void);
  158. uint8_t rgb_matrix_get_sat(void);
  159. uint8_t rgb_matrix_get_val(void);
  160. void rgb_matrix_increase_hue(void);
  161. void rgb_matrix_increase_hue_noeeprom(void);
  162. void rgb_matrix_decrease_hue(void);
  163. void rgb_matrix_decrease_hue_noeeprom(void);
  164. void rgb_matrix_increase_sat(void);
  165. void rgb_matrix_increase_sat_noeeprom(void);
  166. void rgb_matrix_decrease_sat(void);
  167. void rgb_matrix_decrease_sat_noeeprom(void);
  168. void rgb_matrix_increase_val(void);
  169. void rgb_matrix_increase_val_noeeprom(void);
  170. void rgb_matrix_decrease_val(void);
  171. void rgb_matrix_decrease_val_noeeprom(void);
  172. void rgb_matrix_set_speed(uint8_t speed);
  173. void rgb_matrix_set_speed_noeeprom(uint8_t speed);
  174. uint8_t rgb_matrix_get_speed(void);
  175. void rgb_matrix_increase_speed(void);
  176. void rgb_matrix_increase_speed_noeeprom(void);
  177. void rgb_matrix_decrease_speed(void);
  178. void rgb_matrix_decrease_speed_noeeprom(void);
  179. led_flags_t rgb_matrix_get_flags(void);
  180. void rgb_matrix_set_flags(led_flags_t flags);
  181. void rgb_matrix_set_flags_noeeprom(led_flags_t flags);
  182. void rgb_matrix_update_pwm_buffers(void);
  183. #ifndef RGBLIGHT_ENABLE
  184. # define eeconfig_update_rgblight_current eeconfig_force_flush_rgb_matrix
  185. # define rgblight_reload_from_eeprom rgb_matrix_reload_from_eeprom
  186. # define rgblight_toggle rgb_matrix_toggle
  187. # define rgblight_toggle_noeeprom rgb_matrix_toggle_noeeprom
  188. # define rgblight_enable rgb_matrix_enable
  189. # define rgblight_enable_noeeprom rgb_matrix_enable_noeeprom
  190. # define rgblight_disable rgb_matrix_disable
  191. # define rgblight_disable_noeeprom rgb_matrix_disable_noeeprom
  192. # define rgblight_is_enabled rgb_matrix_is_enabled
  193. # define rgblight_mode rgb_matrix_mode
  194. # define rgblight_mode_noeeprom rgb_matrix_mode_noeeprom
  195. # define rgblight_get_mode rgb_matrix_get_mode
  196. # define rgblight_get_hue rgb_matrix_get_hue
  197. # define rgblight_get_sat rgb_matrix_get_sat
  198. # define rgblight_get_val rgb_matrix_get_val
  199. # define rgblight_get_hsv rgb_matrix_get_hsv
  200. # define rgblight_step rgb_matrix_step
  201. # define rgblight_step_noeeprom rgb_matrix_step_noeeprom
  202. # define rgblight_step_reverse rgb_matrix_step_reverse
  203. # define rgblight_step_reverse_noeeprom rgb_matrix_step_reverse_noeeprom
  204. # define rgblight_sethsv rgb_matrix_sethsv
  205. # define rgblight_sethsv_noeeprom rgb_matrix_sethsv_noeeprom
  206. # define rgblight_increase_hue rgb_matrix_increase_hue
  207. # define rgblight_increase_hue_noeeprom rgb_matrix_increase_hue_noeeprom
  208. # define rgblight_decrease_hue rgb_matrix_decrease_hue
  209. # define rgblight_decrease_hue_noeeprom rgb_matrix_decrease_hue_noeeprom
  210. # define rgblight_increase_sat rgb_matrix_increase_sat
  211. # define rgblight_increase_sat_noeeprom rgb_matrix_increase_sat_noeeprom
  212. # define rgblight_decrease_sat rgb_matrix_decrease_sat
  213. # define rgblight_decrease_sat_noeeprom rgb_matrix_decrease_sat_noeeprom
  214. # define rgblight_increase_val rgb_matrix_increase_val
  215. # define rgblight_increase_val_noeeprom rgb_matrix_increase_val_noeeprom
  216. # define rgblight_decrease_val rgb_matrix_decrease_val
  217. # define rgblight_decrease_val_noeeprom rgb_matrix_decrease_val_noeeprom
  218. # define rgblight_set_speed rgb_matrix_set_speed
  219. # define rgblight_set_speed_noeeprom rgb_matrix_set_speed_noeeprom
  220. # define rgblight_get_speed rgb_matrix_get_speed
  221. # define rgblight_increase_speed rgb_matrix_increase_speed
  222. # define rgblight_increase_speed_noeeprom rgb_matrix_increase_speed_noeeprom
  223. # define rgblight_decrease_speed rgb_matrix_decrease_speed
  224. # define rgblight_decrease_speed_noeeprom rgb_matrix_decrease_speed_noeeprom
  225. #endif
  226. static inline bool rgb_matrix_check_finished_leds(uint8_t led_idx) {
  227. #if defined(RGB_MATRIX_SPLIT)
  228. if (is_keyboard_left()) {
  229. uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT;
  230. return led_idx < k_rgb_matrix_split[0];
  231. } else
  232. return led_idx < RGB_MATRIX_LED_COUNT;
  233. #else
  234. return led_idx < RGB_MATRIX_LED_COUNT;
  235. #endif
  236. }
  237. extern rgb_config_t rgb_matrix_config;
  238. extern uint32_t g_rgb_timer;
  239. extern led_config_t g_led_config;
  240. #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
  241. extern last_hit_t g_last_hit_tracker;
  242. #endif
  243. #ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS
  244. extern uint8_t g_rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS];
  245. #endif