]> git.donarmstrong.com Git - qmk_firmware.git/blob - quantum/rgb_matrix.h
Updated rgb_led struct field modifier to flags (#5619)
[qmk_firmware.git] / quantum / rgb_matrix.h
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
19 #ifndef RGB_MATRIX_H
20 #define RGB_MATRIX_H
21
22 #include <stdint.h>
23 #include <stdbool.h>
24 #include "rgb_matrix_types.h"
25 #include "color.h"
26 #include "quantum.h"
27 #include "rgblight_list.h"
28
29 #ifdef IS31FL3731
30   #include "is31fl3731.h"
31 #elif defined (IS31FL3733)
32   #include "is31fl3733.h"
33 #elif defined (IS31FL3737)
34   #include "is31fl3737.h"
35 #elif defined (WS2812)
36   #include "ws2812.h"
37 #endif
38
39 #ifndef RGB_MATRIX_LED_FLUSH_LIMIT
40   #define RGB_MATRIX_LED_FLUSH_LIMIT 16
41 #endif
42
43 #ifndef RGB_MATRIX_LED_PROCESS_LIMIT
44   #define RGB_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5
45 #endif
46
47 #if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL
48 #define RGB_MATRIX_USE_LIMITS(min, max) uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter; \
49   uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; \
50   if (max > DRIVER_LED_TOTAL) \
51     max = DRIVER_LED_TOTAL;
52 #else
53 #define RGB_MATRIX_USE_LIMITS(min, max) uint8_t min = 0; \
54   uint8_t max = DRIVER_LED_TOTAL;
55 #endif
56
57 #define RGB_MATRIX_TEST_LED_FLAGS() if (!HAS_ANY_FLAGS(g_rgb_leds[i].flags, params->flags)) continue
58
59 extern rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
60
61 typedef struct
62 {
63         HSV color;
64         uint8_t index;
65 } rgb_indicator;
66
67 enum rgb_matrix_effects {
68   RGB_MATRIX_NONE = 0,
69         RGB_MATRIX_SOLID_COLOR = 1,
70 #ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS
71   RGB_MATRIX_ALPHAS_MODS,
72 #endif // DISABLE_RGB_MATRIX_ALPHAS_MODS
73 #ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
74   RGB_MATRIX_GRADIENT_UP_DOWN,
75 #endif // DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
76 #ifndef DISABLE_RGB_MATRIX_BREATHING
77   RGB_MATRIX_BREATHING,
78 #endif // DISABLE_RGB_MATRIX_BREATHING
79 #ifndef DISABLE_RGB_MATRIX_CYCLE_ALL
80   RGB_MATRIX_CYCLE_ALL,
81 #endif // DISABLE_RGB_MATRIX_CYCLE_ALL
82 #ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
83   RGB_MATRIX_CYCLE_LEFT_RIGHT,
84 #endif // DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
85 #ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
86   RGB_MATRIX_CYCLE_UP_DOWN,
87 #endif // DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
88 #ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
89   RGB_MATRIX_RAINBOW_MOVING_CHEVRON,
90 #endif // DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
91 #ifndef DISABLE_RGB_MATRIX_DUAL_BEACON
92   RGB_MATRIX_DUAL_BEACON,
93 #endif // DISABLE_RGB_MATRIX_DUAL_BEACON
94 #ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON
95   RGB_MATRIX_RAINBOW_BEACON,
96 #endif // DISABLE_RGB_MATRIX_RAINBOW_BEACON
97 #ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
98   RGB_MATRIX_RAINBOW_PINWHEELS,
99 #endif // DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
100 #ifndef DISABLE_RGB_MATRIX_RAINDROPS
101   RGB_MATRIX_RAINDROPS,
102 #endif // DISABLE_RGB_MATRIX_RAINDROPS
103 #ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
104   RGB_MATRIX_JELLYBEAN_RAINDROPS,
105 #endif // DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
106 #ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN
107   RGB_MATRIX_DIGITAL_RAIN,
108 #endif // DISABLE_RGB_MATRIX_DIGITAL_RAIN
109 #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
110 #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
111   RGB_MATRIX_SOLID_REACTIVE_SIMPLE,
112 #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
113 #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE
114   RGB_MATRIX_SOLID_REACTIVE,
115 #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE
116 #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE
117   RGB_MATRIX_SOLID_REACTIVE_WIDE,
118 #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE
119 #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE
120   RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE,
121 #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE
122 #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS
123   RGB_MATRIX_SOLID_REACTIVE_CROSS,
124 #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS
125 #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS
126   RGB_MATRIX_SOLID_REACTIVE_MULTICROSS,
127 #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS
128 #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS
129   RGB_MATRIX_SOLID_REACTIVE_NEXUS,
130 #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS
131 #ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS
132   RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS,
133 #endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS
134 #ifndef DISABLE_RGB_MATRIX_SPLASH
135   RGB_MATRIX_SPLASH,
136 #endif // DISABLE_RGB_MATRIX_SPLASH
137 #ifndef DISABLE_RGB_MATRIX_MULTISPLASH
138   RGB_MATRIX_MULTISPLASH,
139 #endif // DISABLE_RGB_MATRIX_MULTISPLASH
140 #ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH
141   RGB_MATRIX_SOLID_SPLASH,
142 #endif // DISABLE_RGB_MATRIX_SOLID_SPLASH
143 #ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
144   RGB_MATRIX_SOLID_MULTISPLASH,
145 #endif // DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
146 #endif // RGB_MATRIX_KEYREACTIVE_ENABLED
147
148 #if defined(RGB_MATRIX_CUSTOM_KB) || defined(RGB_MATRIX_CUSTOM_USER)
149   #define RGB_MATRIX_EFFECT(name, ...) RGB_MATRIX_CUSTOM_##name,
150   #ifdef RGB_MATRIX_CUSTOM_KB
151     #include "rgb_matrix_kb.inc"
152   #endif
153   #ifdef RGB_MATRIX_CUSTOM_USER
154     #include "rgb_matrix_user.inc"
155   #endif
156   #undef RGB_MATRIX_EFFECT
157 #endif
158
159   RGB_MATRIX_EFFECT_MAX
160 };
161
162 uint8_t rgb_matrix_map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led_i);
163
164 void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue );
165 void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue );
166
167 // This runs after another backlight effect and replaces
168 // colors already set
169 void rgb_matrix_indicators(void);
170 void rgb_matrix_indicators_kb(void);
171 void rgb_matrix_indicators_user(void);
172
173 void rgb_matrix_init(void);
174 void rgb_matrix_setup_drivers(void);
175
176 void rgb_matrix_set_suspend_state(bool state);
177 void rgb_matrix_set_indicator_state(uint8_t state);
178
179
180 void rgb_matrix_task(void);
181
182 // This should not be called from an interrupt
183 // (eg. from a timer interrupt).
184 // Call this while idle (in between matrix scans).
185 // If the buffer is dirty, it will update the driver with the buffer.
186 void rgb_matrix_update_pwm_buffers(void);
187
188 bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record);
189
190 void rgb_matrix_increase(void);
191 void rgb_matrix_decrease(void);
192
193 // void *backlight_get_key_color_eeprom_address(uint8_t led);
194 // void backlight_get_key_color( uint8_t led, HSV *hsv );
195 // void backlight_set_key_color( uint8_t row, uint8_t column, HSV hsv );
196
197 void rgb_matrix_toggle(void);
198 void rgb_matrix_enable(void);
199 void rgb_matrix_enable_noeeprom(void);
200 void rgb_matrix_disable(void);
201 void rgb_matrix_disable_noeeprom(void);
202 void rgb_matrix_step(void);
203 void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val);
204 void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val);
205 void rgb_matrix_step_reverse(void);
206 void rgb_matrix_increase_hue(void);
207 void rgb_matrix_decrease_hue(void);
208 void rgb_matrix_increase_sat(void);
209 void rgb_matrix_decrease_sat(void);
210 void rgb_matrix_increase_val(void);
211 void rgb_matrix_decrease_val(void);
212 void rgb_matrix_increase_speed(void);
213 void rgb_matrix_decrease_speed(void);
214 led_flags_t rgb_matrix_get_flags(void);
215 void rgb_matrix_set_flags(led_flags_t flags);
216 void rgb_matrix_mode(uint8_t mode);
217 void rgb_matrix_mode_noeeprom(uint8_t mode);
218 uint8_t rgb_matrix_get_mode(void);
219
220 #ifndef RGBLIGHT_ENABLE
221 #define rgblight_toggle() rgb_matrix_toggle()
222 #define rgblight_enable() rgb_matrix_enable()
223 #define rgblight_enable_noeeprom() rgb_matrix_enable_noeeprom()
224 #define rgblight_disable() rgb_matrix_disable()
225 #define rgblight_disable_noeeprom() rgb_matrix_disable_noeeprom()
226 #define rgblight_step() rgb_matrix_step()
227 #define rgblight_sethsv(hue, sat, val) rgb_matrix_sethsv(hue, sat, val)
228 #define rgblight_sethsv_noeeprom(hue, sat, val) rgb_matrix_sethsv_noeeprom(hue, sat, val)
229 #define rgblight_step_reverse() rgb_matrix_step_reverse()
230 #define rgblight_increase_hue() rgb_matrix_increase_hue()
231 #define rgblight_decrease_hue() rgb_matrix_decrease_hue()
232 #define rgblight_increase_sat() rgb_matrix_increase_sat()
233 #define rgblight_decrease_sat() rgb_matrix_decrease_sat()
234 #define rgblight_increase_val() rgb_matrix_increase_val()
235 #define rgblight_decrease_val() rgb_matrix_decrease_val()
236 #define rgblight_increase_speed() rgb_matrix_increase_speed()
237 #define rgblight_decrease_speed() rgb_matrix_decrease_speed()
238 #define rgblight_mode(mode) rgb_matrix_mode(mode)
239 #define rgblight_mode_noeeprom(mode) rgb_matrix_mode_noeeprom(mode)
240 #define rgblight_get_mode() rgb_matrix_get_mode()
241
242 #endif
243
244 typedef struct {
245     /* Perform any initialisation required for the other driver functions to work. */
246     void (*init)(void);
247     /* Set the colour of a single LED in the buffer. */
248     void (*set_color)(int index, uint8_t r, uint8_t g, uint8_t b);
249     /* Set the colour of all LEDS on the keyboard in the buffer. */
250     void (*set_color_all)(uint8_t r, uint8_t g, uint8_t b);
251     /* Flush any buffered changes to the hardware. */
252     void (*flush)(void);
253 } rgb_matrix_driver_t;
254
255 extern const rgb_matrix_driver_t rgb_matrix_driver;
256
257 #endif