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