rgb_matrix.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. #define RGB_MATRIX_TEST_LED_FLAGS() if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) continue
  51. enum rgb_matrix_effects {
  52. RGB_MATRIX_NONE = 0,
  53. // --------------------------------------
  54. // -----Begin rgb effect enum macros-----
  55. #define RGB_MATRIX_EFFECT(name, ...) RGB_MATRIX_##name,
  56. #include "rgb_matrix_animations/rgb_matrix_effects.inc"
  57. #undef RGB_MATRIX_EFFECT
  58. #if defined(RGB_MATRIX_CUSTOM_KB) || defined(RGB_MATRIX_CUSTOM_USER)
  59. #define RGB_MATRIX_EFFECT(name, ...) RGB_MATRIX_CUSTOM_##name,
  60. #ifdef RGB_MATRIX_CUSTOM_KB
  61. #include "rgb_matrix_kb.inc"
  62. #endif
  63. #ifdef RGB_MATRIX_CUSTOM_USER
  64. #include "rgb_matrix_user.inc"
  65. #endif
  66. #undef RGB_MATRIX_EFFECT
  67. #endif
  68. // --------------------------------------
  69. // -----End rgb effect enum macros-------
  70. RGB_MATRIX_EFFECT_MAX
  71. };
  72. void eeconfig_update_rgb_matrix_default(void);
  73. uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i);
  74. uint8_t rgb_matrix_map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led_i);
  75. void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue );
  76. void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue );
  77. bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record);
  78. void rgb_matrix_task(void);
  79. // This runs after another backlight effect and replaces
  80. // colors already set
  81. void rgb_matrix_indicators(void);
  82. void rgb_matrix_indicators_kb(void);
  83. void rgb_matrix_indicators_user(void);
  84. void rgb_matrix_init(void);
  85. void rgb_matrix_set_suspend_state(bool state);
  86. void rgb_matrix_toggle(void);
  87. void rgb_matrix_enable(void);
  88. void rgb_matrix_enable_noeeprom(void);
  89. void rgb_matrix_disable(void);
  90. void rgb_matrix_disable_noeeprom(void);
  91. void rgb_matrix_step(void);
  92. void rgb_matrix_step_reverse(void);
  93. void rgb_matrix_increase_hue(void);
  94. void rgb_matrix_decrease_hue(void);
  95. void rgb_matrix_increase_sat(void);
  96. void rgb_matrix_decrease_sat(void);
  97. void rgb_matrix_increase_val(void);
  98. void rgb_matrix_decrease_val(void);
  99. void rgb_matrix_increase_speed(void);
  100. void rgb_matrix_decrease_speed(void);
  101. led_flags_t rgb_matrix_get_flags(void);
  102. void rgb_matrix_set_flags(led_flags_t flags);
  103. void rgb_matrix_mode(uint8_t mode);
  104. void rgb_matrix_mode_noeeprom(uint8_t mode);
  105. uint8_t rgb_matrix_get_mode(void);
  106. void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val);
  107. void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val);
  108. #ifndef RGBLIGHT_ENABLE
  109. #define rgblight_toggle() rgb_matrix_toggle()
  110. #define rgblight_enable() rgb_matrix_enable()
  111. #define rgblight_enable_noeeprom() rgb_matrix_enable_noeeprom()
  112. #define rgblight_disable() rgb_matrix_disable()
  113. #define rgblight_disable_noeeprom() rgb_matrix_disable_noeeprom()
  114. #define rgblight_step() rgb_matrix_step()
  115. #define rgblight_sethsv(hue, sat, val) rgb_matrix_sethsv(hue, sat, val)
  116. #define rgblight_sethsv_noeeprom(hue, sat, val) rgb_matrix_sethsv_noeeprom(hue, sat, val)
  117. #define rgblight_step_reverse() rgb_matrix_step_reverse()
  118. #define rgblight_increase_hue() rgb_matrix_increase_hue()
  119. #define rgblight_decrease_hue() rgb_matrix_decrease_hue()
  120. #define rgblight_increase_sat() rgb_matrix_increase_sat()
  121. #define rgblight_decrease_sat() rgb_matrix_decrease_sat()
  122. #define rgblight_increase_val() rgb_matrix_increase_val()
  123. #define rgblight_decrease_val() rgb_matrix_decrease_val()
  124. #define rgblight_increase_speed() rgb_matrix_increase_speed()
  125. #define rgblight_decrease_speed() rgb_matrix_decrease_speed()
  126. #define rgblight_mode(mode) rgb_matrix_mode(mode)
  127. #define rgblight_mode_noeeprom(mode) rgb_matrix_mode_noeeprom(mode)
  128. #define rgblight_get_mode() rgb_matrix_get_mode()
  129. #endif
  130. typedef struct {
  131. /* Perform any initialisation required for the other driver functions to work. */
  132. void (*init)(void);
  133. /* Set the colour of a single LED in the buffer. */
  134. void (*set_color)(int index, uint8_t r, uint8_t g, uint8_t b);
  135. /* Set the colour of all LEDS on the keyboard in the buffer. */
  136. void (*set_color_all)(uint8_t r, uint8_t g, uint8_t b);
  137. /* Flush any buffered changes to the hardware. */
  138. void (*flush)(void);
  139. } rgb_matrix_driver_t;
  140. extern const rgb_matrix_driver_t rgb_matrix_driver;
  141. extern rgb_config_t rgb_matrix_config;
  142. extern bool g_suspend_state;
  143. extern rgb_counters_t g_rgb_counters;
  144. extern led_config_t g_led_config;
  145. #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
  146. extern last_hit_t g_last_hit_tracker;
  147. #endif
  148. #ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS
  149. extern uint8_t rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS];
  150. #endif
  151. #endif