diff options
Diffstat (limited to 'quantum/rgb_matrix/rgb_matrix.h')
-rw-r--r-- | quantum/rgb_matrix/rgb_matrix.h | 228 |
1 files changed, 228 insertions, 0 deletions
diff --git a/quantum/rgb_matrix/rgb_matrix.h b/quantum/rgb_matrix/rgb_matrix.h new file mode 100644 index 000000000..28f07c84d --- /dev/null +++ b/quantum/rgb_matrix/rgb_matrix.h | |||
@@ -0,0 +1,228 @@ | |||
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 | #pragma once | ||
20 | |||
21 | #include <stdint.h> | ||
22 | #include <stdbool.h> | ||
23 | #include "rgb_matrix_types.h" | ||
24 | #include "color.h" | ||
25 | #include "quantum.h" | ||
26 | #include "rgblight_list.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 | #elif defined(IS31FL3741) | ||
35 | # include "is31fl3741.h" | ||
36 | #elif defined(AW20216) | ||
37 | # include "aw20216.h" | ||
38 | #elif defined(WS2812) | ||
39 | # include "ws2812.h" | ||
40 | #endif | ||
41 | |||
42 | #ifndef RGB_MATRIX_LED_FLUSH_LIMIT | ||
43 | # define RGB_MATRIX_LED_FLUSH_LIMIT 16 | ||
44 | #endif | ||
45 | |||
46 | #ifndef RGB_MATRIX_LED_PROCESS_LIMIT | ||
47 | # define RGB_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5 | ||
48 | #endif | ||
49 | |||
50 | #if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL | ||
51 | # define RGB_MATRIX_USE_LIMITS(min, max) \ | ||
52 | uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter; \ | ||
53 | uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; \ | ||
54 | if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL; | ||
55 | #else | ||
56 | # define RGB_MATRIX_USE_LIMITS(min, max) \ | ||
57 | uint8_t min = 0; \ | ||
58 | uint8_t max = DRIVER_LED_TOTAL; | ||
59 | #endif | ||
60 | |||
61 | #define RGB_MATRIX_INDICATOR_SET_COLOR(i, r, g, b) \ | ||
62 | if (i >= led_min && i <= led_max) { \ | ||
63 | rgb_matrix_set_color(i, r, g, b); \ | ||
64 | } | ||
65 | |||
66 | #define RGB_MATRIX_TEST_LED_FLAGS() \ | ||
67 | if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) continue | ||
68 | |||
69 | enum rgb_matrix_effects { | ||
70 | RGB_MATRIX_NONE = 0, | ||
71 | |||
72 | // -------------------------------------- | ||
73 | // -----Begin rgb effect enum macros----- | ||
74 | #define RGB_MATRIX_EFFECT(name, ...) RGB_MATRIX_##name, | ||
75 | #include "rgb_matrix_effects.inc" | ||
76 | #undef RGB_MATRIX_EFFECT | ||
77 | |||
78 | #if defined(RGB_MATRIX_CUSTOM_KB) || defined(RGB_MATRIX_CUSTOM_USER) | ||
79 | # define RGB_MATRIX_EFFECT(name, ...) RGB_MATRIX_CUSTOM_##name, | ||
80 | # ifdef RGB_MATRIX_CUSTOM_KB | ||
81 | # include "rgb_matrix_kb.inc" | ||
82 | # endif | ||
83 | # ifdef RGB_MATRIX_CUSTOM_USER | ||
84 | # include "rgb_matrix_user.inc" | ||
85 | # endif | ||
86 | # undef RGB_MATRIX_EFFECT | ||
87 | #endif | ||
88 | // -------------------------------------- | ||
89 | // -----End rgb effect enum macros------- | ||
90 | |||
91 | RGB_MATRIX_EFFECT_MAX | ||
92 | }; | ||
93 | |||
94 | void eeconfig_update_rgb_matrix_default(void); | ||
95 | void eeconfig_update_rgb_matrix(void); | ||
96 | |||
97 | uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i); | ||
98 | uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i); | ||
99 | |||
100 | void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); | ||
101 | void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue); | ||
102 | |||
103 | void process_rgb_matrix(uint8_t row, uint8_t col, bool pressed); | ||
104 | |||
105 | void rgb_matrix_task(void); | ||
106 | |||
107 | // This runs after another backlight effect and replaces | ||
108 | // colors already set | ||
109 | void rgb_matrix_indicators(void); | ||
110 | void rgb_matrix_indicators_kb(void); | ||
111 | void rgb_matrix_indicators_user(void); | ||
112 | |||
113 | void rgb_matrix_indicators_advanced(effect_params_t *params); | ||
114 | void rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max); | ||
115 | void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max); | ||
116 | |||
117 | void rgb_matrix_init(void); | ||
118 | |||
119 | void rgb_matrix_set_suspend_state(bool state); | ||
120 | bool rgb_matrix_get_suspend_state(void); | ||
121 | void rgb_matrix_toggle(void); | ||
122 | void rgb_matrix_toggle_noeeprom(void); | ||
123 | void rgb_matrix_enable(void); | ||
124 | void rgb_matrix_enable_noeeprom(void); | ||
125 | void rgb_matrix_disable(void); | ||
126 | void rgb_matrix_disable_noeeprom(void); | ||
127 | uint8_t rgb_matrix_is_enabled(void); | ||
128 | void rgb_matrix_mode(uint8_t mode); | ||
129 | void rgb_matrix_mode_noeeprom(uint8_t mode); | ||
130 | uint8_t rgb_matrix_get_mode(void); | ||
131 | void rgb_matrix_step(void); | ||
132 | void rgb_matrix_step_noeeprom(void); | ||
133 | void rgb_matrix_step_reverse(void); | ||
134 | void rgb_matrix_step_reverse_noeeprom(void); | ||
135 | void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val); | ||
136 | void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val); | ||
137 | HSV rgb_matrix_get_hsv(void); | ||
138 | uint8_t rgb_matrix_get_hue(void); | ||
139 | uint8_t rgb_matrix_get_sat(void); | ||
140 | uint8_t rgb_matrix_get_val(void); | ||
141 | void rgb_matrix_increase_hue(void); | ||
142 | void rgb_matrix_increase_hue_noeeprom(void); | ||
143 | void rgb_matrix_decrease_hue(void); | ||
144 | void rgb_matrix_decrease_hue_noeeprom(void); | ||
145 | void rgb_matrix_increase_sat(void); | ||
146 | void rgb_matrix_increase_sat_noeeprom(void); | ||
147 | void rgb_matrix_decrease_sat(void); | ||
148 | void rgb_matrix_decrease_sat_noeeprom(void); | ||
149 | void rgb_matrix_increase_val(void); | ||
150 | void rgb_matrix_increase_val_noeeprom(void); | ||
151 | void rgb_matrix_decrease_val(void); | ||
152 | void rgb_matrix_decrease_val_noeeprom(void); | ||
153 | void rgb_matrix_set_speed(uint8_t speed); | ||
154 | void rgb_matrix_set_speed_noeeprom(uint8_t speed); | ||
155 | uint8_t rgb_matrix_get_speed(void); | ||
156 | void rgb_matrix_increase_speed(void); | ||
157 | void rgb_matrix_increase_speed_noeeprom(void); | ||
158 | void rgb_matrix_decrease_speed(void); | ||
159 | void rgb_matrix_decrease_speed_noeeprom(void); | ||
160 | led_flags_t rgb_matrix_get_flags(void); | ||
161 | void rgb_matrix_set_flags(led_flags_t flags); | ||
162 | |||
163 | #ifndef RGBLIGHT_ENABLE | ||
164 | # define eeconfig_update_rgblight_current eeconfig_update_rgb_matrix | ||
165 | # define rgblight_toggle rgb_matrix_toggle | ||
166 | # define rgblight_toggle_noeeprom rgb_matrix_toggle_noeeprom | ||
167 | # define rgblight_enable rgb_matrix_enable | ||
168 | # define rgblight_enable_noeeprom rgb_matrix_enable_noeeprom | ||
169 | # define rgblight_disable rgb_matrix_disable | ||
170 | # define rgblight_disable_noeeprom rgb_matrix_disable_noeeprom | ||
171 | # define rgblight_is_enabled rgb_matrix_is_enabled | ||
172 | # define rgblight_mode rgb_matrix_mode | ||
173 | # define rgblight_mode_noeeprom rgb_matrix_mode_noeeprom | ||
174 | # define rgblight_get_mode rgb_matrix_get_mode | ||
175 | # define rgblight_get_hue rgb_matrix_get_hue | ||
176 | # define rgblight_get_sat rgb_matrix_get_sat | ||
177 | # define rgblight_get_val rgb_matrix_get_val | ||
178 | # define rgblight_get_hsv rgb_matrix_get_hsv | ||
179 | # define rgblight_step rgb_matrix_step | ||
180 | # define rgblight_step_noeeprom rgb_matrix_step_noeeprom | ||
181 | # define rgblight_step_reverse rgb_matrix_step_reverse | ||
182 | # define rgblight_step_reverse_noeeprom rgb_matrix_step_reverse_noeeprom | ||
183 | # define rgblight_sethsv rgb_matrix_sethsv | ||
184 | # define rgblight_sethsv_noeeprom rgb_matrix_sethsv_noeeprom | ||
185 | # define rgblight_increase_hue rgb_matrix_increase_hue | ||
186 | # define rgblight_increase_hue_noeeprom rgb_matrix_increase_hue_noeeprom | ||
187 | # define rgblight_decrease_hue rgb_matrix_decrease_hue | ||
188 | # define rgblight_decrease_hue_noeeprom rgb_matrix_decrease_hue_noeeprom | ||
189 | # define rgblight_increase_sat rgb_matrix_increase_sat | ||
190 | # define rgblight_increase_sat_noeeprom rgb_matrix_increase_sat_noeeprom | ||
191 | # define rgblight_decrease_sat rgb_matrix_decrease_sat | ||
192 | # define rgblight_decrease_sat_noeeprom rgb_matrix_decrease_sat_noeeprom | ||
193 | # define rgblight_increase_val rgb_matrix_increase_val | ||
194 | # define rgblight_increase_val_noeeprom rgb_matrix_increase_val_noeeprom | ||
195 | # define rgblight_decrease_val rgb_matrix_decrease_val | ||
196 | # define rgblight_decrease_val_noeeprom rgb_matrix_decrease_val_noeeprom | ||
197 | # define rgblight_set_speed rgb_matrix_set_speed | ||
198 | # define rgblight_set_speed_noeeprom rgb_matrix_set_speed_noeeprom | ||
199 | # define rgblight_get_speed rgb_matrix_get_speed | ||
200 | # define rgblight_increase_speed rgb_matrix_increase_speed | ||
201 | # define rgblight_increase_speed_noeeprom rgb_matrix_increase_speed_noeeprom | ||
202 | # define rgblight_decrease_speed rgb_matrix_decrease_speed | ||
203 | # define rgblight_decrease_speed_noeeprom rgb_matrix_decrease_speed_noeeprom | ||
204 | #endif | ||
205 | |||
206 | typedef struct { | ||
207 | /* Perform any initialisation required for the other driver functions to work. */ | ||
208 | void (*init)(void); | ||
209 | /* Set the colour of a single LED in the buffer. */ | ||
210 | void (*set_color)(int index, uint8_t r, uint8_t g, uint8_t b); | ||
211 | /* Set the colour of all LEDS on the keyboard in the buffer. */ | ||
212 | void (*set_color_all)(uint8_t r, uint8_t g, uint8_t b); | ||
213 | /* Flush any buffered changes to the hardware. */ | ||
214 | void (*flush)(void); | ||
215 | } rgb_matrix_driver_t; | ||
216 | |||
217 | extern const rgb_matrix_driver_t rgb_matrix_driver; | ||
218 | |||
219 | extern rgb_config_t rgb_matrix_config; | ||
220 | |||
221 | extern uint32_t g_rgb_timer; | ||
222 | extern led_config_t g_led_config; | ||
223 | #ifdef RGB_MATRIX_KEYREACTIVE_ENABLED | ||
224 | extern last_hit_t g_last_hit_tracker; | ||
225 | #endif | ||
226 | #ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS | ||
227 | extern uint8_t g_rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS]; | ||
228 | #endif | ||