rgb_matrix.h 7.7 KB

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