rgb_matrix.h 7.8 KB

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