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