rgb_matrix.h 6.6 KB

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