rgb_matrix.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. #ifndef RGB_MATRIX_H
  19. #define RGB_MATRIX_H
  20. #include <stdint.h>
  21. #include <stdbool.h>
  22. #include "rgb_matrix_types.h"
  23. #include "color.h"
  24. #include "quantum.h"
  25. #include "rgblight_list.h"
  26. #ifdef IS31FL3731
  27. #include "is31fl3731.h"
  28. #elif defined (IS31FL3733)
  29. #include "is31fl3733.h"
  30. #elif defined (IS31FL3737)
  31. #include "is31fl3737.h"
  32. #elif defined (WS2812)
  33. #include "ws2812.h"
  34. #endif
  35. #ifndef RGB_MATRIX_LED_FLUSH_LIMIT
  36. #define RGB_MATRIX_LED_FLUSH_LIMIT 16
  37. #endif
  38. #ifndef RGB_MATRIX_LED_PROCESS_LIMIT
  39. #define RGB_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5
  40. #endif
  41. #if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL
  42. #define RGB_MATRIX_USE_LIMITS(min, max) uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter; \
  43. uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; \
  44. if (max > DRIVER_LED_TOTAL) \
  45. max = DRIVER_LED_TOTAL;
  46. #else
  47. #define RGB_MATRIX_USE_LIMITS(min, max) uint8_t min = 0; \
  48. uint8_t max = DRIVER_LED_TOTAL;
  49. #endif
  50. extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
  51. typedef struct
  52. {
  53. HSV color;
  54. uint8_t index;
  55. } rgb_indicator;
  56. enum rgb_matrix_effects {
  57. RGB_MATRIX_NONE = 0,
  58. RGB_MATRIX_SOLID_COLOR = 1,
  59. #ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS
  60. RGB_MATRIX_ALPHAS_MODS,
  61. #endif // DISABLE_RGB_MATRIX_ALPHAS_MODS
  62. #ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
  63. RGB_MATRIX_GRADIENT_UP_DOWN,
  64. #endif // DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
  65. #ifndef DISABLE_RGB_MATRIX_BREATHING
  66. RGB_MATRIX_BREATHING,
  67. #endif // DISABLE_RGB_MATRIX_BREATHING
  68. #ifndef DISABLE_RGB_MATRIX_CYCLE_ALL
  69. RGB_MATRIX_CYCLE_ALL,
  70. #endif // DISABLE_RGB_MATRIX_CYCLE_ALL
  71. #ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
  72. RGB_MATRIX_CYCLE_LEFT_RIGHT,
  73. #endif // DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
  74. #ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
  75. RGB_MATRIX_CYCLE_UP_DOWN,
  76. #endif // DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
  77. #ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
  78. RGB_MATRIX_RAINBOW_MOVING_CHEVRON,
  79. #endif // DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
  80. #ifndef DISABLE_RGB_MATRIX_DUAL_BEACON
  81. RGB_MATRIX_DUAL_BEACON,
  82. #endif // DISABLE_RGB_MATRIX_DUAL_BEACON
  83. #ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON
  84. RGB_MATRIX_RAINBOW_BEACON,
  85. #endif // DISABLE_RGB_MATRIX_RAINBOW_BEACON
  86. #ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
  87. RGB_MATRIX_RAINBOW_PINWHEELS,
  88. #endif // DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
  89. #ifndef DISABLE_RGB_MATRIX_RAINDROPS
  90. RGB_MATRIX_RAINDROPS,
  91. #endif // DISABLE_RGB_MATRIX_RAINDROPS
  92. #ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
  93. RGB_MATRIX_JELLYBEAN_RAINDROPS,
  94. #endif // DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
  95. #ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN
  96. RGB_MATRIX_DIGITAL_RAIN,
  97. #endif // DISABLE_RGB_MATRIX_DIGITAL_RAIN
  98. #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
  99. #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
  100. RGB_MATRIX_SOLID_REACTIVE_SIMPLE,
  101. #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
  102. #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE
  103. RGB_MATRIX_SOLID_REACTIVE,
  104. #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE
  105. #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE
  106. RGB_MATRIX_SOLID_REACTIVE_WIDE,
  107. #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE
  108. #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE
  109. RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE,
  110. #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE
  111. #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS
  112. RGB_MATRIX_SOLID_REACTIVE_CROSS,
  113. #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS
  114. #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS
  115. RGB_MATRIX_SOLID_REACTIVE_MULTICROSS,
  116. #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS
  117. #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS
  118. RGB_MATRIX_SOLID_REACTIVE_NEXUS,
  119. #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS
  120. #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS
  121. RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS,
  122. #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS
  123. #ifndef DISABLE_RGB_MATRIX_SPLASH
  124. RGB_MATRIX_SPLASH,
  125. #endif // DISABLE_RGB_MATRIX_SPLASH
  126. #ifndef DISABLE_RGB_MATRIX_MULTISPLASH
  127. RGB_MATRIX_MULTISPLASH,
  128. #endif // DISABLE_RGB_MATRIX_MULTISPLASH
  129. #ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH
  130. RGB_MATRIX_SOLID_SPLASH,
  131. #endif // DISABLE_RGB_MATRIX_SOLID_SPLASH
  132. #ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
  133. RGB_MATRIX_SOLID_MULTISPLASH,
  134. #endif // DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
  135. #endif // RGB_MATRIX_KEYREACTIVE_ENABLED
  136. #if defined(RGB_MATRIX_CUSTOM_KB) || defined(RGB_MATRIX_CUSTOM_USER)
  137. #define RGB_MATRIX_EFFECT(name, ...) RGB_MATRIX_CUSTOM_##name,
  138. #ifdef RGB_MATRIX_CUSTOM_KB
  139. #include "rgb_matrix_kb.inc"
  140. #endif
  141. #ifdef RGB_MATRIX_CUSTOM_USER
  142. #include "rgb_matrix_user.inc"
  143. #endif
  144. #undef RGB_MATRIX_EFFECT
  145. #endif
  146. RGB_MATRIX_EFFECT_MAX
  147. };
  148. uint8_t rgb_matrix_map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led_i);
  149. void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue );
  150. void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue );
  151. // This runs after another backlight effect and replaces
  152. // colors already set
  153. void rgb_matrix_indicators(void);
  154. void rgb_matrix_indicators_kb(void);
  155. void rgb_matrix_indicators_user(void);
  156. void rgb_matrix_init(void);
  157. void rgb_matrix_setup_drivers(void);
  158. void rgb_matrix_set_suspend_state(bool state);
  159. void rgb_matrix_set_indicator_state(uint8_t state);
  160. void rgb_matrix_task(void);
  161. // This should not be called from an interrupt
  162. // (eg. from a timer interrupt).
  163. // Call this while idle (in between matrix scans).
  164. // If the buffer is dirty, it will update the driver with the buffer.
  165. void rgb_matrix_update_pwm_buffers(void);
  166. bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record);
  167. void rgb_matrix_increase(void);
  168. void rgb_matrix_decrease(void);
  169. // void *backlight_get_key_color_eeprom_address(uint8_t led);
  170. // void backlight_get_key_color( uint8_t led, HSV *hsv );
  171. // void backlight_set_key_color( uint8_t row, uint8_t column, HSV hsv );
  172. void rgb_matrix_toggle(void);
  173. void rgb_matrix_enable(void);
  174. void rgb_matrix_enable_noeeprom(void);
  175. void rgb_matrix_disable(void);
  176. void rgb_matrix_disable_noeeprom(void);
  177. void rgb_matrix_step(void);
  178. void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val);
  179. void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val);
  180. void rgb_matrix_step_reverse(void);
  181. void rgb_matrix_increase_hue(void);
  182. void rgb_matrix_decrease_hue(void);
  183. void rgb_matrix_increase_sat(void);
  184. void rgb_matrix_decrease_sat(void);
  185. void rgb_matrix_increase_val(void);
  186. void rgb_matrix_decrease_val(void);
  187. void rgb_matrix_increase_speed(void);
  188. void rgb_matrix_decrease_speed(void);
  189. void rgb_matrix_mode(uint8_t mode);
  190. void rgb_matrix_mode_noeeprom(uint8_t mode);
  191. uint8_t rgb_matrix_get_mode(void);
  192. #ifndef RGBLIGHT_ENABLE
  193. #define rgblight_toggle() rgb_matrix_toggle()
  194. #define rgblight_enable() rgb_matrix_enable()
  195. #define rgblight_enable_noeeprom() rgb_matrix_enable_noeeprom()
  196. #define rgblight_disable() rgb_matrix_disable()
  197. #define rgblight_disable_noeeprom() rgb_matrix_disable_noeeprom()
  198. #define rgblight_step() rgb_matrix_step()
  199. #define rgblight_sethsv(hue, sat, val) rgb_matrix_sethsv(hue, sat, val)
  200. #define rgblight_sethsv_noeeprom(hue, sat, val) rgb_matrix_sethsv_noeeprom(hue, sat, val)
  201. #define rgblight_step_reverse() rgb_matrix_step_reverse()
  202. #define rgblight_increase_hue() rgb_matrix_increase_hue()
  203. #define rgblight_decrease_hue() rgb_matrix_decrease_hue()
  204. #define rgblight_increase_sat() rgb_matrix_increase_sat()
  205. #define rgblight_decrease_sat() rgb_matrix_decrease_sat()
  206. #define rgblight_increase_val() rgb_matrix_increase_val()
  207. #define rgblight_decrease_val() rgb_matrix_decrease_val()
  208. #define rgblight_increase_speed() rgb_matrix_increase_speed()
  209. #define rgblight_decrease_speed() rgb_matrix_decrease_speed()
  210. #define rgblight_mode(mode) rgb_matrix_mode(mode)
  211. #define rgblight_mode_noeeprom(mode) rgb_matrix_mode_noeeprom(mode)
  212. #define rgblight_get_mode() rgb_matrix_get_mode()
  213. #endif
  214. typedef struct {
  215. /* Perform any initialisation required for the other driver functions to work. */
  216. void (*init)(void);
  217. /* Set the colour of a single LED in the buffer. */
  218. void (*set_color)(int index, uint8_t r, uint8_t g, uint8_t b);
  219. /* Set the colour of all LEDS on the keyboard in the buffer. */
  220. void (*set_color_all)(uint8_t r, uint8_t g, uint8_t b);
  221. /* Flush any buffered changes to the hardware. */
  222. void (*flush)(void);
  223. } rgb_matrix_driver_t;
  224. extern const rgb_matrix_driver_t rgb_matrix_driver;
  225. #endif