rgb_matrix.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 struct
  46. {
  47. HSV color;
  48. uint8_t index;
  49. } rgb_indicator;
  50. typedef union {
  51. uint32_t raw;
  52. struct {
  53. bool enable :1;
  54. uint8_t mode :6;
  55. uint16_t hue :9;
  56. uint8_t sat :8;
  57. uint8_t val :8;
  58. uint8_t speed :8;//EECONFIG needs to be increased to support this
  59. };
  60. } rgb_config_t;
  61. enum rgb_matrix_effects {
  62. RGB_MATRIX_SOLID_COLOR = 1,
  63. #ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS
  64. RGB_MATRIX_ALPHAS_MODS,
  65. #endif
  66. #ifndef DISABLE_RGB_MATRIX_DUAL_BEACON
  67. RGB_MATRIX_DUAL_BEACON,
  68. #endif
  69. #ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
  70. RGB_MATRIX_GRADIENT_UP_DOWN,
  71. #endif
  72. #ifndef DISABLE_RGB_MATRIX_RAINDROPS
  73. RGB_MATRIX_RAINDROPS,
  74. #endif
  75. #ifndef DISABLE_RGB_MATRIX_CYCLE_ALL
  76. RGB_MATRIX_CYCLE_ALL,
  77. #endif
  78. #ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
  79. RGB_MATRIX_CYCLE_LEFT_RIGHT,
  80. #endif
  81. #ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
  82. RGB_MATRIX_CYCLE_UP_DOWN,
  83. #endif
  84. #ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON
  85. RGB_MATRIX_RAINBOW_BEACON,
  86. #endif
  87. #ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
  88. RGB_MATRIX_RAINBOW_PINWHEELS,
  89. #endif
  90. #ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
  91. RGB_MATRIX_RAINBOW_MOVING_CHEVRON,
  92. #endif
  93. #ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
  94. RGB_MATRIX_JELLYBEAN_RAINDROPS,
  95. #endif
  96. #ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN
  97. RGB_MATRIX_DIGITAL_RAIN,
  98. #endif
  99. #ifdef RGB_MATRIX_KEYPRESSES
  100. #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE
  101. RGB_MATRIX_SOLID_REACTIVE,
  102. #endif
  103. #ifndef DISABLE_RGB_MATRIX_SPLASH
  104. RGB_MATRIX_SPLASH,
  105. #endif
  106. #ifndef DISABLE_RGB_MATRIX_MULTISPLASH
  107. RGB_MATRIX_MULTISPLASH,
  108. #endif
  109. #ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH
  110. RGB_MATRIX_SOLID_SPLASH,
  111. #endif
  112. #ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
  113. RGB_MATRIX_SOLID_MULTISPLASH,
  114. #endif
  115. #endif
  116. RGB_MATRIX_EFFECT_MAX
  117. };
  118. void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue );
  119. // This runs after another backlight effect and replaces
  120. // colors already set
  121. void rgb_matrix_indicators(void);
  122. void rgb_matrix_indicators_kb(void);
  123. void rgb_matrix_indicators_user(void);
  124. void rgb_matrix_init(void);
  125. void rgb_matrix_setup_drivers(void);
  126. void rgb_matrix_set_suspend_state(bool state);
  127. void rgb_matrix_set_indicator_state(uint8_t state);
  128. void rgb_matrix_task(void);
  129. // This should not be called from an interrupt
  130. // (eg. from a timer interrupt).
  131. // Call this while idle (in between matrix scans).
  132. // If the buffer is dirty, it will update the driver with the buffer.
  133. void rgb_matrix_update_pwm_buffers(void);
  134. bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record);
  135. void rgb_matrix_increase(void);
  136. void rgb_matrix_decrease(void);
  137. // void *backlight_get_key_color_eeprom_address(uint8_t led);
  138. // void backlight_get_key_color( uint8_t led, HSV *hsv );
  139. // void backlight_set_key_color( uint8_t row, uint8_t column, HSV hsv );
  140. uint32_t rgb_matrix_get_tick(void);
  141. void rgblight_toggle(void);
  142. void rgblight_step(void);
  143. void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val);
  144. void rgblight_step_reverse(void);
  145. void rgblight_increase_hue(void);
  146. void rgblight_decrease_hue(void);
  147. void rgblight_increase_sat(void);
  148. void rgblight_decrease_sat(void);
  149. void rgblight_increase_val(void);
  150. void rgblight_decrease_val(void);
  151. void rgblight_increase_speed(void);
  152. void rgblight_decrease_speed(void);
  153. void rgblight_mode(uint8_t mode);
  154. uint32_t rgblight_get_mode(void);
  155. typedef struct {
  156. /* Perform any initialisation required for the other driver functions to work. */
  157. void (*init)(void);
  158. /* Set the colour of a single LED in the buffer. */
  159. void (*set_color)(int index, uint8_t r, uint8_t g, uint8_t b);
  160. /* Set the colour of all LEDS on the keyboard in the buffer. */
  161. void (*set_color_all)(uint8_t r, uint8_t g, uint8_t b);
  162. /* Flush any buffered changes to the hardware. */
  163. void (*flush)(void);
  164. } rgb_matrix_driver_t;
  165. extern const rgb_matrix_driver_t rgb_matrix_driver;
  166. #endif