Commit | Line | Data |
---|---|---|
48a992f1 W |
1 | /* Copyright 2017 Jason Williams (Wilba) |
2 | * | |
3 | * This program is free software: you can redistribute it and/or modify | |
4 | * it under the terms of the GNU General Public License as published by | |
5 | * the Free Software Foundation, either version 2 of the License, or | |
6 | * (at your option) any later version. | |
7 | * | |
8 | * This program is distributed in the hope that it will be useful, | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | * GNU General Public License for more details. | |
12 | * | |
13 | * You should have received a copy of the GNU General Public License | |
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
15 | */ | |
48a992f1 | 16 | |
2ce3025b | 17 | #if defined(RGB_BACKLIGHT_ZEAL60) || defined(RGB_BACKLIGHT_ZEAL65) || defined(RGB_BACKLIGHT_M60_A) || defined(RGB_BACKLIGHT_M6_B) || defined(RGB_BACKLIGHT_KOYU) || defined(RGB_BACKLIGHT_HS60) || defined(RGB_BACKLIGHT_NK65) || defined(RGB_BACKLIGHT_U80_A) || defined(RGB_BACKLIGHT_DAWN60) |
48a992f1 | 18 | #else |
2ce3025b | 19 | #error None of the following was defined: RGB_BACKLIGHT_ZEAL60, RGB_BACKLIGHT_ZEAL65, RGB_BACKLIGHT_M60_A, RGB_BACKLIGHT_M6_B, RGB_BACKLIGHT_KOYU, RGB_BACKLIGHT_HS60, RGB_BACKLIGHT_NK65, RGB_BACKLIGHT_U80_A, RGB_BACKLIGHT_DAWN60 |
48a992f1 W |
20 | #endif |
21 | ||
2bfac351 | 22 | #ifndef MAX |
23 | #define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) | |
24 | #endif | |
25 | ||
26 | #ifndef MIN | |
27 | #define MIN(a,b) ((a) < (b)? (a): (b)) | |
28 | #endif | |
29 | ||
2dea540a | 30 | #include "quantum.h" |
bffbb4b4 W |
31 | #include "wt_rgb_backlight.h" |
32 | #include "wt_rgb_backlight_api.h" | |
33 | #include "wt_rgb_backlight_keycodes.h" | |
48a992f1 | 34 | |
acd3e79a | 35 | #if !defined(RGB_BACKLIGHT_HS60) && !defined(RGB_BACKLIGHT_NK65) |
48a992f1 | 36 | #include <avr/interrupt.h> |
2bfac351 | 37 | #include "drivers/avr/i2c_master.h" |
38 | #else | |
39 | #include "ch.h" | |
40 | #include "hal.h" | |
41 | #include "drivers/arm/i2c_master.h" | |
2bfac351 | 42 | #endif |
320822d7 | 43 | |
2ce3025b X |
44 | #if defined(RGB_BACKLIGHT_DAWN60) |
45 | #include "drivers/avr/ws2812.h" | |
46 | LED_TYPE g_ws2812_leds[WS2812_LED_TOTAL]; | |
47 | #endif | |
48 | ||
48a992f1 | 49 | #include "progmem.h" |
48a992f1 | 50 | #include "quantum/color.h" |
320822d7 W |
51 | #include "tmk_core/common/eeprom.h" |
52 | ||
53 | #include "via.h" // uses only the EEPROM address | |
54 | #define RGB_BACKLIGHT_CONFIG_EEPROM_ADDR (VIA_EEPROM_CUSTOM_CONFIG_ADDR) | |
2dea540a | 55 | |
acd3e79a | 56 | #if defined(RGB_BACKLIGHT_M6_B) |
2dea540a W |
57 | #include "drivers/issi/is31fl3218.h" |
58 | #define BACKLIGHT_LED_COUNT 6 | |
acd3e79a | 59 | #elif defined(RGB_BACKLIGHT_HS60) |
2bfac351 | 60 | #include "drivers/issi/is31fl3733.h" |
61 | #define BACKLIGHT_LED_COUNT 64 | |
acd3e79a | 62 | #elif defined(RGB_BACKLIGHT_NK65) |
63 | #include "drivers/issi/is31fl3733.h" | |
64 | #define BACKLIGHT_LED_COUNT 69 | |
2dea540a | 65 | #else |
48a992f1 | 66 | #include "drivers/issi/is31fl3731.h" |
bffbb4b4 W |
67 | #if defined(RGB_BACKLIGHT_U80_A) |
68 | #define BACKLIGHT_LED_COUNT 108 | |
2ce3025b X |
69 | #elif defined(RGB_BACKLIGHT_DAWN60) |
70 | #define BACKLIGHT_LED_COUNT 84 //64 + 20 | |
bffbb4b4 | 71 | #else |
2dea540a W |
72 | #define BACKLIGHT_LED_COUNT 72 |
73 | #endif | |
bffbb4b4 | 74 | #endif |
48a992f1 W |
75 | |
76 | #define BACKLIGHT_EFFECT_MAX 10 | |
77 | ||
78 | backlight_config g_config = { | |
acd3e79a | 79 | .use_split_backspace = RGB_BACKLIGHT_USE_SPLIT_BACKSPACE, |
80 | .use_split_left_shift = RGB_BACKLIGHT_USE_SPLIT_LEFT_SHIFT, | |
81 | .use_split_right_shift = RGB_BACKLIGHT_USE_SPLIT_RIGHT_SHIFT, | |
82 | .use_7u_spacebar = RGB_BACKLIGHT_USE_7U_SPACEBAR, | |
83 | .use_iso_enter = RGB_BACKLIGHT_USE_ISO_ENTER, | |
84 | .disable_hhkb_blocker_leds = RGB_BACKLIGHT_DISABLE_HHKB_BLOCKER_LEDS, | |
85 | .disable_when_usb_suspended = RGB_BACKLIGHT_DISABLE_WHEN_USB_SUSPENDED, | |
86 | .disable_after_timeout = RGB_BACKLIGHT_DISABLE_AFTER_TIMEOUT, | |
87 | .brightness = RGB_BACKLIGHT_BRIGHTNESS, | |
88 | .effect = RGB_BACKLIGHT_EFFECT, | |
89 | .effect_speed = RGB_BACKLIGHT_EFFECT_SPEED, | |
90 | .color_1 = RGB_BACKLIGHT_COLOR_1, | |
91 | .color_2 = RGB_BACKLIGHT_COLOR_2, | |
92 | .caps_lock_indicator = RGB_BACKLIGHT_CAPS_LOCK_INDICATOR, | |
93 | .layer_1_indicator = RGB_BACKLIGHT_LAYER_1_INDICATOR, | |
94 | .layer_2_indicator = RGB_BACKLIGHT_LAYER_2_INDICATOR, | |
95 | .layer_3_indicator = RGB_BACKLIGHT_LAYER_3_INDICATOR, | |
96 | .alphas_mods = { | |
97 | RGB_BACKLIGHT_ALPHAS_MODS_ROW_0, | |
98 | RGB_BACKLIGHT_ALPHAS_MODS_ROW_1, | |
99 | RGB_BACKLIGHT_ALPHAS_MODS_ROW_2, | |
100 | RGB_BACKLIGHT_ALPHAS_MODS_ROW_3, | |
101 | RGB_BACKLIGHT_ALPHAS_MODS_ROW_4 }, | |
d7f1e072 | 102 | #if defined(RGB_BACKLIGHT_M6_B) |
acd3e79a | 103 | .custom_color = { { 0, 255 }, { 43, 255 }, { 85, 255 }, { 128, 255 }, { 171, 255 }, { 213, 255 } } |
d7f1e072 | 104 | #endif |
48a992f1 W |
105 | }; |
106 | ||
107 | bool g_suspend_state = false; | |
108 | uint8_t g_indicator_state = 0; | |
109 | ||
110 | // Global tick at 20 Hz | |
111 | uint32_t g_tick = 0; | |
112 | ||
113 | // Ticks since this key was last hit. | |
2dea540a | 114 | uint8_t g_key_hit[BACKLIGHT_LED_COUNT]; |
48a992f1 W |
115 | |
116 | // Ticks since any key was last hit. | |
117 | uint32_t g_any_key_hit = 0; | |
118 | ||
2bfac351 | 119 | #if defined(RGB_BACKLIGHT_HS60) |
120 | ||
121 | // This is a 7-bit address, that gets left-shifted and bit 0 | |
122 | // set to 0 for write, 1 for read (as per I2C protocol) | |
123 | // ADDR_2 is not needed. it is here as a dummy | |
124 | #define ISSI_ADDR_1 0x50 | |
2bfac351 | 125 | |
126 | const is31_led g_is31_leds[DRIVER_LED_TOTAL] = { | |
127 | /* Refer to IS31 manual for these locations | |
128 | * driver | |
129 | * | R location | |
130 | * | | G location | |
131 | * | | | B location | |
132 | * | | | | */ | |
133 | {0, B_1, A_1, C_1}, //LA1 | |
134 | {0, E_1, D_1, F_1}, //LA2 | |
135 | {0, H_1, G_1, I_1}, //LA3 | |
136 | {0, K_1, J_1, L_1}, //LA4 | |
137 | {0, B_2, A_2, C_2}, //LA5 | |
138 | {0, E_2, D_2, F_2}, //LA6 | |
139 | {0, H_2, G_2, I_2}, //LA7 | |
140 | {0, K_2, J_2, L_2}, //LA8 | |
141 | {0, B_3, A_3, C_3}, //LA9 | |
142 | {0, E_3, D_3, F_3}, //LA10 | |
143 | {0, H_3, G_3, I_3}, //LA11 | |
144 | {0, K_3, J_3, L_3}, //LA12 | |
145 | {0, B_4, A_4, C_4}, //LA13 | |
146 | {0, E_4, D_4, F_4}, //LA14 | |
147 | {0, H_4, G_4, I_4}, //LA15 | |
148 | {0, K_4, J_4, L_4}, //LA16 | |
149 | {0, B_5, A_5, C_5}, //LA17 | |
150 | {0, E_5, D_5, F_5}, //LA18 | |
151 | {0, H_5, G_5, I_5}, //LA19 | |
152 | {0, K_5, J_5, L_5}, //LA20 | |
153 | {0, B_6, A_6, C_6}, //LA21 | |
154 | {0, E_6, D_6, F_6}, //LA22 | |
155 | {0, H_6, G_6, I_6}, //LA23 | |
156 | {0, K_6, J_6, L_6}, //LA24 | |
157 | {0, B_7, A_7, C_7}, //LA25 | |
158 | {0, E_7, D_7, F_7}, //LA26 | |
159 | {0, H_7, G_7, I_7}, //LA27 | |
160 | {0, K_7, J_7, L_7}, //LA28 | |
161 | {0, B_8, A_8, C_8}, //LA29 | |
162 | {0, E_8, D_8, F_8}, //LA30 | |
163 | {0, H_8, G_8, I_8}, //LA31 | |
164 | {0, K_8, J_8, L_8}, //LA32 | |
165 | {0, B_9, A_9, C_9}, //LA33 | |
166 | {0, E_9, D_9, F_9}, //LA34 | |
167 | {0, H_9, G_9, I_9}, //LA35 | |
168 | {0, K_9, J_9, L_9}, //LA36 | |
169 | {0, B_10, A_10, C_10}, //LA37 | |
170 | {0, E_10, D_10, F_10}, //LA38 | |
171 | {0, H_10, G_10, I_10}, //LA39 | |
172 | {0, K_10, J_10, L_10}, //LA40 | |
173 | {0, B_11, A_11, C_11}, //LA41 | |
174 | {0, E_11, D_11, F_11}, //LA42 | |
175 | {0, H_11, G_11, I_11}, //LA43 | |
176 | {0, K_11, J_11, L_11}, //LA44 | |
177 | {0, B_12, A_12, C_12}, //LA45 | |
178 | {0, E_12, D_12, F_12}, //LA46 | |
179 | {0, H_12, G_12, I_12}, //LA47 | |
180 | {0, K_12, J_12, L_12}, //LA48 | |
181 | {0, B_13, A_13, C_13}, //LA49 | |
182 | {0, E_13, D_13, F_13}, //LA50 | |
183 | {0, H_13, G_13, I_13}, //LA51 | |
184 | {0, K_13, J_13, L_13}, //LA52 | |
185 | {0, B_14, A_14, C_14}, //LA53 | |
186 | {0, E_14, D_14, F_14}, //LA54 | |
187 | {0, H_14, G_14, I_14}, //LA55 | |
188 | {0, K_14, J_14, L_14}, //LA56 | |
189 | {0, B_15, A_15, C_15}, //LA57 | |
190 | {0, E_15, D_15, F_15}, //LA58 | |
191 | {0, H_15, G_15, I_15}, //LA59 | |
192 | {0, K_15, J_15, L_15}, //LA60 | |
193 | {0, B_16, A_16, C_16}, //LA61 | |
194 | {0, E_16, D_16, F_16}, //LA62 | |
195 | {0, H_16, G_16, I_16}, //LA63 | |
196 | {0, K_16, J_16, L_16}, //LA64 | |
197 | }; | |
198 | ||
acd3e79a | 199 | #elif defined(RGB_BACKLIGHT_NK65) |
200 | ||
201 | // This is a 7-bit address, that gets left-shifted and bit 0 | |
202 | // set to 0 for write, 1 for read (as per I2C protocol) | |
203 | // ADDR_2 is not needed. it is here as a dummy | |
204 | #define ISSI_ADDR_1 0x50 | |
205 | #define ISSI_ADDR_2 0x52 | |
206 | ||
207 | const is31_led g_is31_leds[DRIVER_LED_TOTAL] = { | |
208 | /* Refer to IS31 manual for these locations | |
209 | * driver | |
210 | * | R location | |
211 | * | | G location | |
212 | * | | | B location | |
213 | * | | | | */ | |
214 | {0, B_1, A_1, C_1}, //LA1 | |
215 | {0, E_1, D_1, F_1}, //LA2 | |
216 | {0, H_1, G_1, I_1}, //LA3 | |
217 | {0, K_1, J_1, L_1}, //LA4 | |
218 | {0, B_2, A_2, C_2}, //LA5 | |
219 | {0, E_2, D_2, F_2}, //LA6 | |
220 | {0, H_2, G_2, I_2}, //LA7 | |
221 | {0, K_2, J_2, L_2}, //LA8 | |
222 | {0, B_3, A_3, C_3}, //LA9 | |
223 | {0, E_3, D_3, F_3}, //LA10 | |
224 | {0, H_3, G_3, I_3}, //LA11 | |
225 | {0, K_3, J_3, L_3}, //LA12 | |
226 | {0, B_4, A_4, C_4}, //LA13 | |
227 | {0, E_4, D_4, F_4}, //LA14 | |
228 | {0, H_4, G_4, I_4}, //LA15 | |
229 | {0, K_4, J_4, L_4}, //LA16 | |
230 | {0, B_5, A_5, C_5}, //LA17 | |
231 | {0, E_5, D_5, F_5}, //LA18 | |
232 | {0, H_5, G_5, I_5}, //LA19 | |
233 | {0, K_5, J_5, L_5}, //LA20 | |
234 | {0, B_6, A_6, C_6}, //LA21 | |
235 | {0, E_6, D_6, F_6}, //LA22 | |
236 | {0, H_6, G_6, I_6}, //LA23 | |
237 | {0, K_6, J_6, L_6}, //LA24 | |
238 | {0, B_7, A_7, C_7}, //LA25 | |
239 | {0, E_7, D_7, F_7}, //LA26 | |
240 | {0, H_7, G_7, I_7}, //LA27 | |
241 | {0, K_7, J_7, L_7}, //LA28 | |
242 | {0, B_8, A_8, C_8}, //LA29 | |
243 | {0, E_8, D_8, F_8}, //LA30 | |
244 | {0, H_8, G_8, I_8}, //LA31 | |
245 | {0, K_8, J_8, L_8}, //LA32 | |
246 | {0, B_9, A_9, C_9}, //LA33 | |
247 | {0, E_9, D_9, F_9}, //LA34 | |
248 | {0, H_9, G_9, I_9}, //LA35 | |
249 | {0, K_9, J_9, L_9}, //LA36 | |
250 | {0, B_10, A_10, C_10}, //LA37 | |
251 | {0, E_10, D_10, F_10}, //LA38 | |
252 | {0, H_10, G_10, I_10}, //LA39 | |
253 | {0, K_10, J_10, L_10}, //LA40 | |
254 | {0, B_11, A_11, C_11}, //LA41 | |
255 | {0, E_11, D_11, F_11}, //LA42 | |
256 | {0, H_11, G_11, I_11}, //LA43 | |
257 | {0, K_11, J_11, L_11}, //LA44 | |
258 | {0, B_12, A_12, C_12}, //LA45 | |
259 | {0, E_12, D_12, F_12}, //LA46 | |
260 | {0, H_12, G_12, I_12}, //LA47 | |
261 | {0, K_12, J_12, L_12}, //LA48 | |
262 | {0, B_13, A_13, C_13}, //LA49 | |
263 | {0, E_13, D_13, F_13}, //LA50 | |
264 | {0, H_13, G_13, I_13}, //LA51 | |
265 | {0, K_13, J_13, L_13}, //LA52 | |
266 | {0, B_14, A_14, C_14}, //LA53 | |
267 | {0, E_14, D_14, F_14}, //LA54 | |
268 | {0, H_14, G_14, I_14}, //LA55 | |
269 | {0, K_14, J_14, L_14}, //LA56 | |
270 | {0, B_15, A_15, C_15}, //LA57 | |
271 | {0, E_15, D_15, F_15}, //LA58 | |
272 | {0, H_15, G_15, I_15}, //LA59 | |
273 | {0, K_15, J_15, L_15}, //LA60 | |
274 | {0, B_16, A_16, C_16}, //LA61 | |
275 | {0, E_16, D_16, F_16}, //LA62 | |
276 | {0, H_16, G_16, I_16}, //LA63 | |
277 | {0, K_16, J_16, L_16}, //LA64 | |
278 | ||
279 | {1, B_1, A_1, C_1}, //LB1 | |
280 | {1, E_1, D_1, F_1}, //LB2 | |
281 | {1, H_1, G_1, I_1}, //LB3 | |
282 | {1, K_1, J_1, L_1}, //LB4 | |
283 | {1, B_2, A_2, C_2}, //LB5 | |
284 | {1, E_2, D_2, F_2}, //LB6 | |
285 | {1, H_2, G_2, I_2}, //LB7 | |
286 | {1, K_2, J_2, L_2}, //LB8 | |
287 | {1, B_3, A_3, C_3}, //LB9 | |
288 | {1, E_3, D_3, F_3}, //LB10 | |
289 | {1, H_3, G_3, I_3}, //LB11 | |
290 | {1, K_3, J_3, L_3}, //LB12 | |
291 | {1, B_4, A_4, C_4}, //LB13 | |
292 | {1, E_4, D_4, F_4}, //LB14 | |
293 | {1, H_4, G_4, I_4}, //LB15 | |
294 | {1, K_4, J_4, L_4}, //LB16 | |
295 | {1, B_5, A_5, C_5}, //LB17 | |
296 | {1, E_5, D_5, F_5}, //LB18 | |
297 | {1, H_5, G_5, I_5}, //LB19 | |
298 | {1, K_5, J_5, L_5}, //LB20 | |
299 | {1, B_6, A_6, C_6}, //LB21 | |
300 | {1, E_6, D_6, F_6}, //LB22 | |
301 | {1, H_6, G_6, I_6}, //LB23 | |
302 | {1, K_6, J_6, L_6}, //LB24 | |
303 | {1, B_7, A_7, C_7}, //LB25 | |
304 | {1, E_7, D_7, F_7}, //LB26 | |
305 | {1, H_7, G_7, I_7}, //LB27 | |
306 | {1, K_7, J_7, L_7}, //LB28 | |
307 | {1, B_8, A_8, C_8}, //LB29 | |
308 | {1, E_8, D_8, F_8}, //LB30 | |
309 | {1, H_8, G_8, I_8}, //LB31 | |
310 | {1, K_8, J_8, L_8}, //LB32 | |
311 | {1, B_9, A_9, C_9}, //LB33 | |
312 | {1, E_9, D_9, F_9}, //LB34 | |
313 | {1, H_9, G_9, I_9}, //LB35 | |
314 | {1, K_9, J_9, L_9}, //LB36 | |
315 | {1, B_10, A_10, C_10}, //LB37 | |
316 | {1, E_10, D_10, F_10}, //LB38 | |
317 | {1, H_10, G_10, I_10}, //LB39 | |
318 | {1, K_10, J_10, L_10}, //LB40 | |
319 | {1, B_11, A_11, C_11}, //LB41 | |
320 | {1, E_11, D_11, F_11}, //LB42 | |
321 | {1, H_11, G_11, I_11}, //LB43 | |
322 | {1, K_11, J_11, L_11}, //LB44 | |
323 | {1, B_12, A_12, C_12}, //LB45 | |
324 | {1, E_12, D_12, F_12}, //LB46 | |
325 | {1, H_12, G_12, I_12}, //LB47 | |
326 | {1, K_12, J_12, L_12}, //LB48 | |
327 | {1, B_13, A_13, C_13}, //LB49 | |
328 | {1, E_13, D_13, F_13}, //LB50 | |
329 | {1, H_13, G_13, I_13}, //LB51 | |
330 | {1, K_13, J_13, L_13}, //LB52 | |
331 | {1, B_14, A_14, C_14}, //LB53 | |
332 | {1, E_14, D_14, F_14}, //LB54 | |
333 | {1, H_14, G_14, I_14}, //LB55 | |
334 | {1, K_14, J_14, L_14}, //LB56 | |
335 | {1, B_15, A_15, C_15}, //LB57 | |
336 | {1, E_15, D_15, F_15}, //LB58 | |
337 | {1, H_15, G_15, I_15}, //LB59 | |
338 | {1, K_15, J_15, L_15}, //LB60 | |
339 | {1, B_16, A_16, C_16}, //LB61 | |
340 | {1, E_16, D_16, F_16}, //LB62 | |
341 | {1, H_16, G_16, I_16}, //LB63 | |
342 | {1, K_16, J_16, L_16}, //LB64 | |
343 | }; | |
344 | ||
bffbb4b4 W |
345 | #elif defined(RGB_BACKLIGHT_U80_A) |
346 | ||
347 | // U80-A prototype uses 3 ISSI drivers | |
348 | #define ISSI_ADDR_1 0x74 // 11101[00] <- GND | |
349 | #define ISSI_ADDR_2 0x76 // 11101[10] <- SDA | |
350 | #define ISSI_ADDR_3 0x75 // 11101[01] <- SCL | |
351 | ||
352 | const is31_led g_is31_leds[DRIVER_LED_TOTAL] = { | |
353 | /* Refer to IS31 manual for these locations | |
354 | * driver | |
355 | * | R location | |
356 | * | | G location | |
357 | * | | | B location | |
358 | * | | | | */ | |
359 | {0, C2_1, C3_1, C4_1}, // LA0 | |
360 | {0, C1_1, C3_2, C4_2}, // LA1 | |
361 | {0, C1_2, C2_2, C4_3}, // LA2 | |
362 | {0, C1_3, C2_3, C3_3}, // LA3 | |
363 | {0, C1_4, C2_4, C3_4}, // LA4 | |
364 | {0, C1_5, C2_5, C3_5}, // LA5 | |
365 | {0, C1_6, C2_6, C3_6}, // LA6 | |
366 | {0, C1_7, C2_7, C3_7}, // LA7 | |
367 | {0, C1_8, C2_8, C3_8}, // LA8 | |
368 | {0, C9_1, C8_1, C7_1}, // LA9 | |
369 | {0, C9_2, C8_2, C7_2}, // LA10 | |
370 | {0, C9_3, C8_3, C7_3}, // LA11 | |
371 | {0, C9_4, C8_4, C7_4}, // LA12 | |
372 | {0, C9_5, C8_5, C7_5}, // LA13 | |
373 | {0, C9_6, C8_6, C7_6}, // LA14 | |
374 | {0, C9_7, C8_7, C6_6}, // LA15 | |
375 | {0, C9_8, C7_7, C6_7}, // LA16 | |
376 | {0, C8_8, C7_8, C6_8}, // LA17 | |
377 | ||
378 | {0, C2_9, C3_9, C4_9}, // LB0 | |
379 | {0, C1_9, C3_10, C4_10}, // LB1 | |
380 | {0, C1_10, C2_10, C4_11}, // LB2 | |
381 | {0, C1_11, C2_11, C3_11}, // LB3 | |
382 | {0, C1_12, C2_12, C3_12}, // LB4 | |
383 | {0, C1_13, C2_13, C3_13}, // LB5 | |
384 | {0, C1_14, C2_14, C3_14}, // LB6 | |
385 | {0, C1_15, C2_15, C3_15}, // LB7 | |
386 | {0, C1_16, C2_16, C3_16}, // LB8 | |
387 | {0, C9_9, C8_9, C7_9}, // LB9 | |
388 | {0, C9_10, C8_10, C7_10}, // LB10 | |
389 | {0, C9_11, C8_11, C7_11}, // LB11 | |
390 | {0, C9_12, C8_12, C7_12}, // LB12 | |
391 | {0, C9_13, C8_13, C7_13}, // LB13 | |
392 | {0, C9_14, C8_14, C7_14}, // LB14 | |
393 | {0, C9_15, C8_15, C6_14}, // LB15 | |
394 | {0, C9_16, C7_15, C6_15}, // LB16 | |
395 | {0, C8_16, C7_16, C6_16}, // LB17 | |
396 | ||
397 | {1, C2_1, C3_1, C4_1}, // LC0 | |
398 | {1, C1_1, C3_2, C4_2}, // LC1 | |
399 | {1, C1_2, C2_2, C4_3}, // LC2 | |
400 | {1, C1_3, C2_3, C3_3}, // LC3 | |
401 | {1, C1_4, C2_4, C3_4}, // LC4 | |
402 | {1, C1_5, C2_5, C3_5}, // LC5 | |
403 | {1, C1_6, C2_6, C3_6}, // LC6 | |
404 | {1, C1_7, C2_7, C3_7}, // LC7 | |
405 | {1, C1_8, C2_8, C3_8}, // LC8 | |
406 | {1, C9_1, C8_1, C7_1}, // LC9 | |
407 | {1, C9_2, C8_2, C7_2}, // LC10 | |
408 | {1, C9_3, C8_3, C7_3}, // LC11 | |
409 | {1, C9_4, C8_4, C7_4}, // LC12 | |
410 | {1, C9_5, C8_5, C7_5}, // LC13 | |
411 | {1, C9_6, C8_6, C7_6}, // LC14 | |
412 | {1, C9_7, C8_7, C6_6}, // LC15 | |
413 | {1, C9_8, C7_7, C6_7}, // LC16 | |
414 | {1, C8_8, C7_8, C6_8}, // LC17 | |
415 | ||
416 | {1, C2_9, C3_9, C4_9}, // LD0 | |
417 | {1, C1_9, C3_10, C4_10}, // LD1 | |
418 | {1, C1_10, C2_10, C4_11}, // LD2 | |
419 | {1, C1_11, C2_11, C3_11}, // LD3 | |
420 | {1, C1_12, C2_12, C3_12}, // LD4 | |
421 | {1, C1_13, C2_13, C3_13}, // LD5 | |
422 | {1, C1_14, C2_14, C3_14}, // LD6 | |
423 | {1, C1_15, C2_15, C3_15}, // LD7 | |
424 | {1, C1_16, C2_16, C3_16}, // LD8 | |
425 | {1, C9_9, C8_9, C7_9}, // LD9 | |
426 | {1, C9_10, C8_10, C7_10}, // LD10 | |
427 | {1, C9_11, C8_11, C7_11}, // LD11 | |
428 | {1, C9_12, C8_12, C7_12}, // LD12 | |
429 | {1, C9_13, C8_13, C7_13}, // LD13 | |
430 | {1, C9_14, C8_14, C7_14}, // LD14 | |
431 | {1, C9_15, C8_15, C6_14}, // LD15 | |
432 | {1, C9_16, C7_15, C6_15}, // LD16 | |
433 | {1, C8_16, C7_16, C6_16}, // LD17 | |
434 | ||
435 | {2, C2_1, C3_1, C4_1}, // LE0 | |
436 | {2, C1_1, C3_2, C4_2}, // LE1 | |
437 | {2, C1_2, C2_2, C4_3}, // LE2 | |
438 | {2, C1_3, C2_3, C3_3}, // LE3 | |
439 | {2, C1_4, C2_4, C3_4}, // LE4 | |
440 | {2, C1_5, C2_5, C3_5}, // LE5 | |
441 | {2, C1_6, C2_6, C3_6}, // LE6 | |
442 | {2, C1_7, C2_7, C3_7}, // LE7 | |
443 | {2, C1_8, C2_8, C3_8}, // LE8 | |
444 | {2, C9_1, C8_1, C7_1}, // LE9 | |
445 | {2, C9_2, C8_2, C7_2}, // LE10 | |
446 | {2, C9_3, C8_3, C7_3}, // LE11 | |
447 | {2, C9_4, C8_4, C7_4}, // LE12 | |
448 | {2, C9_5, C8_5, C7_5}, // LE13 | |
449 | {2, C9_6, C8_6, C7_6}, // LE14 | |
450 | {2, C9_7, C8_7, C6_6}, // LE15 | |
451 | {2, C9_8, C7_7, C6_7}, // LE16 | |
452 | {2, C8_8, C7_8, C6_8}, // LE17 | |
453 | ||
454 | {2, C2_9, C3_9, C4_9}, // LF0 | |
455 | {2, C1_9, C3_10, C4_10}, // LF1 | |
456 | {2, C1_10, C2_10, C4_11}, // LF2 | |
457 | {2, C1_11, C2_11, C3_11}, // LF3 | |
458 | {2, C1_12, C2_12, C3_12}, // LF4 | |
459 | {2, C1_13, C2_13, C3_13}, // LF5 | |
460 | {2, C1_14, C2_14, C3_14}, // LF6 | |
461 | {2, C1_15, C2_15, C3_15}, // LF7 | |
462 | {2, C1_16, C2_16, C3_16}, // LF8 | |
463 | {2, C9_9, C8_9, C7_9}, // LF9 | |
464 | {2, C9_10, C8_10, C7_10}, // LF10 | |
465 | {2, C9_11, C8_11, C7_11}, // LF11 | |
466 | {2, C9_12, C8_12, C7_12}, // LF12 | |
467 | {2, C9_13, C8_13, C7_13}, // LF13 | |
468 | {2, C9_14, C8_14, C7_14}, // LF14 | |
469 | {2, C9_15, C8_15, C6_14}, // LF15 | |
470 | {2, C9_16, C7_15, C6_15}, // LF16 | |
471 | {2, C8_16, C7_16, C6_16}, // LF17 | |
472 | }; | |
2ce3025b X |
473 | #elif defined(RGB_BACKLIGHT_DAWN60) |
474 | // This is a 7-bit address, that gets left-shifted and bit 0 | |
475 | // set to 0 for write, 1 for read (as per I2C protocol) | |
476 | #define ISSI_ADDR_1 0x74 | |
477 | #define ISSI_ADDR_2 0x76 | |
478 | ||
479 | const is31_led g_is31_leds[DRIVER_LED_TOTAL] = { | |
480 | /* Refer to IS31 manual for these locations | |
481 | * driver | |
482 | * | R location | |
483 | * | | G location | |
484 | * | | | B location | |
485 | * | | | | */ | |
486 | {0, C1_1, C3_2, C4_2}, //A1 | |
487 | {0, C1_2, C2_2, C4_3}, //A2 | |
488 | {0, C1_3, C2_3, C3_3}, //A3 | |
489 | {0, C1_4, C2_4, C3_4}, //A4 | |
490 | {0, C1_5, C2_5, C3_5}, //A5 | |
491 | {0, C1_6, C2_6, C3_6}, //A6 | |
492 | {0, C1_7, C2_7, C3_7}, //A7 | |
493 | {0, C1_8, C2_8, C3_8}, //A8 | |
494 | {0, C9_1, C8_1, C7_1}, //A9 | |
495 | {0, C9_2, C8_2, C7_2}, //A10 | |
496 | {0, C9_3, C8_3, C7_3}, //A11 | |
497 | {0, C9_4, C8_4, C7_4}, //A12 | |
498 | {0, C9_5, C8_5, C7_5}, //A13 | |
499 | {0, C9_6, C8_6, C7_6}, //A14 | |
500 | {0, C9_7, C8_7, C6_6}, //A15 | |
501 | {0, C9_8, C7_7, C6_7}, //A16 | |
502 | ||
503 | {0, C1_9, C3_10, C4_10}, //B1 | |
504 | {0, C1_10, C2_10, C4_11}, //B2 | |
505 | {0, C1_11, C2_11, C3_11}, //B3 | |
506 | {0, C1_12, C2_12, C3_12}, //B4 | |
507 | {0, C1_13, C2_13, C3_13}, //B5 | |
508 | {0, C1_14, C2_14, C3_14}, //B6 | |
509 | {0, C1_15, C2_15, C3_15}, //B7 | |
510 | {0, C1_16, C2_16, C3_16}, //B8 | |
511 | {0, C9_9, C8_9, C7_9}, //B9 | |
512 | {0, C9_10, C8_10, C7_10}, //B10 | |
513 | {0, C9_11, C8_11, C7_11}, //B11 | |
514 | {0, C9_12, C8_12, C7_12}, //B12 | |
515 | {0, C9_13, C8_13, C7_13}, //B13 | |
516 | {0, C9_14, C8_14, C7_14}, //B14 | |
517 | {0, C9_15, C8_15, C6_14}, //B15 | |
518 | {0, C9_16, C7_15, C6_15}, //B16 | |
519 | ||
520 | {1, C1_1, C3_2, C4_2}, //C1 | |
521 | {1, C1_2, C2_2, C4_3}, //C2 | |
522 | {1, C1_3, C2_3, C3_3}, //C3 | |
523 | {1, C1_4, C2_4, C3_4}, //C4 | |
524 | {1, C1_5, C2_5, C3_5}, //C5 | |
525 | {1, C1_6, C2_6, C3_6}, //C6 | |
526 | {1, C1_7, C2_7, C3_7}, //C7 | |
527 | {1, C1_8, C2_8, C3_8}, //C8 | |
528 | {1, C9_1, C8_1, C7_1}, //C9 | |
529 | {1, C9_2, C8_2, C7_2}, //C10 | |
530 | {1, C9_3, C8_3, C7_3}, //C11 | |
531 | {1, C9_4, C8_4, C7_4}, //C12 | |
532 | {1, C9_5, C8_5, C7_5}, //C13 | |
533 | {1, C9_6, C8_6, C7_6}, //C14 | |
534 | {1, C9_7, C8_7, C6_6}, //C15 | |
535 | {1, C9_8, C7_7, C6_7}, //C16 | |
536 | ||
537 | {1, C1_9, C3_10, C4_10}, //D1 | |
538 | {1, C1_10, C2_10, C4_11}, //D2 | |
539 | {1, C1_11, C2_11, C3_11}, //D3 | |
540 | {1, C1_12, C2_12, C3_12}, //D4 | |
541 | {1, C1_13, C2_13, C3_13}, //D5 | |
542 | {1, C1_14, C2_14, C3_14}, //D6 | |
543 | {1, C1_15, C2_15, C3_15}, //D7 | |
544 | {1, C1_16, C2_16, C3_16}, //D8 | |
545 | {1, C9_9, C8_9, C7_9}, //D9 | |
546 | {1, C9_10, C8_10, C7_10}, //D10 | |
547 | {1, C9_11, C8_11, C7_11}, //D11 | |
548 | {1, C9_12, C8_12, C7_12}, //D12 | |
549 | {1, C9_13, C8_13, C7_13}, //D13 | |
550 | {1, C9_14, C8_14, C7_14}, //D14 | |
551 | {1, C9_15, C8_15, C6_14}, //D15 | |
552 | {1, C9_16, C7_15, C6_15} //D16 | |
553 | }; | |
2bfac351 | 554 | #elif !defined(RGB_BACKLIGHT_M6_B) |
48a992f1 W |
555 | // This is a 7-bit address, that gets left-shifted and bit 0 |
556 | // set to 0 for write, 1 for read (as per I2C protocol) | |
557 | #define ISSI_ADDR_1 0x74 | |
558 | #define ISSI_ADDR_2 0x76 | |
559 | ||
560 | const is31_led g_is31_leds[DRIVER_LED_TOTAL] = { | |
561 | /* Refer to IS31 manual for these locations | |
562 | * driver | |
563 | * | R location | |
564 | * | | G location | |
565 | * | | | B location | |
566 | * | | | | */ | |
acd3e79a | 567 | {0, C2_1, C3_1, C4_1}, // LA0 |
568 | {0, C1_1, C3_2, C4_2}, // LA1 | |
569 | {0, C1_2, C2_2, C4_3}, // LA2 | |
570 | {0, C1_3, C2_3, C3_3}, // LA3 | |
571 | {0, C1_4, C2_4, C3_4}, // LA4 | |
572 | {0, C1_5, C2_5, C3_5}, // LA5 | |
573 | {0, C1_6, C2_6, C3_6}, // LA6 | |
574 | {0, C1_7, C2_7, C3_7}, // LA7 | |
575 | {0, C1_8, C2_8, C3_8}, // LA8 | |
576 | {0, C9_1, C8_1, C7_1}, // LA9 | |
577 | {0, C9_2, C8_2, C7_2}, // LA10 | |
578 | {0, C9_3, C8_3, C7_3}, // LA11 | |
579 | {0, C9_4, C8_4, C7_4}, // LA12 | |
580 | {0, C9_5, C8_5, C7_5}, // LA13 | |
581 | {0, C9_6, C8_6, C7_6}, // LA14 | |
582 | {0, C9_7, C8_7, C6_6}, // LA15 | |
583 | {0, C9_8, C7_7, C6_7}, // LA16 | |
584 | {0, C8_8, C7_8, C6_8}, // LA17 | |
585 | ||
586 | {0, C2_9, C3_9, C4_9}, // LB0 | |
587 | {0, C1_9, C3_10, C4_10}, // LB1 | |
588 | {0, C1_10, C2_10, C4_11}, // LB2 | |
589 | {0, C1_11, C2_11, C3_11}, // LB3 | |
590 | {0, C1_12, C2_12, C3_12}, // LB4 | |
591 | {0, C1_13, C2_13, C3_13}, // LB5 | |
592 | {0, C1_14, C2_14, C3_14}, // LB6 | |
593 | {0, C1_15, C2_15, C3_15}, // LB7 | |
594 | {0, C1_16, C2_16, C3_16}, // LB8 | |
595 | {0, C9_9, C8_9, C7_9}, // LB9 | |
596 | {0, C9_10, C8_10, C7_10}, // LB10 | |
597 | {0, C9_11, C8_11, C7_11}, // LB11 | |
598 | {0, C9_12, C8_12, C7_12}, // LB12 | |
599 | {0, C9_13, C8_13, C7_13}, // LB13 | |
600 | {0, C9_14, C8_14, C7_14}, // LB14 | |
601 | {0, C9_15, C8_15, C6_14}, // LB15 | |
602 | {0, C9_16, C7_15, C6_15}, // LB16 | |
603 | {0, C8_16, C7_16, C6_16}, // LB17 | |
604 | ||
605 | {1, C2_1, C3_1, C4_1}, // LC0 | |
606 | {1, C1_1, C3_2, C4_2}, // LC1 | |
607 | {1, C1_2, C2_2, C4_3}, // LC2 | |
608 | {1, C1_3, C2_3, C3_3}, // LC3 | |
609 | {1, C1_4, C2_4, C3_4}, // LC4 | |
610 | {1, C1_5, C2_5, C3_5}, // LC5 | |
611 | {1, C1_6, C2_6, C3_6}, // LC6 | |
612 | {1, C1_7, C2_7, C3_7}, // LC7 | |
613 | {1, C1_8, C2_8, C3_8}, // LC8 | |
614 | {1, C9_1, C8_1, C7_1}, // LC9 | |
615 | {1, C9_2, C8_2, C7_2}, // LC10 | |
616 | {1, C9_3, C8_3, C7_3}, // LC11 | |
617 | {1, C9_4, C8_4, C7_4}, // LC12 | |
618 | {1, C9_5, C8_5, C7_5}, // LC13 | |
619 | {1, C9_6, C8_6, C7_6}, // LC14 | |
620 | {1, C9_7, C8_7, C6_6}, // LC15 | |
621 | {1, C9_8, C7_7, C6_7}, // LC16 | |
622 | {1, C8_8, C7_8, C6_8}, // LC17 | |
623 | ||
624 | {1, C2_9, C3_9, C4_9}, // LD0 | |
625 | {1, C1_9, C3_10, C4_10}, // LD1 | |
626 | {1, C1_10, C2_10, C4_11}, // LD2 | |
627 | {1, C1_11, C2_11, C3_11}, // LD3 | |
628 | {1, C1_12, C2_12, C3_12}, // LD4 | |
629 | {1, C1_13, C2_13, C3_13}, // LD5 | |
630 | {1, C1_14, C2_14, C3_14}, // LD6 | |
631 | {1, C1_15, C2_15, C3_15}, // LD7 | |
632 | {1, C1_16, C2_16, C3_16}, // LD8 | |
633 | {1, C9_9, C8_9, C7_9}, // LD9 | |
634 | {1, C9_10, C8_10, C7_10}, // LD10 | |
635 | {1, C9_11, C8_11, C7_11}, // LD11 | |
636 | {1, C9_12, C8_12, C7_12}, // LD12 | |
637 | {1, C9_13, C8_13, C7_13}, // LD13 | |
638 | {1, C9_14, C8_14, C7_14}, // LD14 | |
639 | {1, C9_15, C8_15, C6_14}, // LD15 | |
640 | {1, C9_16, C7_15, C6_15}, // LD16 | |
641 | {1, C8_16, C7_16, C6_16}, // LD17 | |
48a992f1 | 642 | }; |
2dea540a | 643 | #endif // !defined(RGB_BACKLIGHT_M6_B) |
48a992f1 W |
644 | |
645 | ||
646 | typedef struct Point { | |
acd3e79a | 647 | uint8_t x; |
648 | uint8_t y; | |
48a992f1 W |
649 | } Point; |
650 | ||
651 | ||
652 | // index in range 0..71 (LA0..LA17, LB0..LB17, LC0..LC17, LD0..LD17) | |
653 | // point values in range x=0..224 y=0..64 | |
654 | // origin is center of top-left key (i.e Esc) | |
acd3e79a | 655 | #if defined(RGB_BACKLIGHT_ZEAL65) |
2dea540a | 656 | const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = { |
acd3e79a | 657 | // LA0..LA17 |
658 | {120,16}, {104,16}, {88,16}, {72,16}, {56,16}, {40,16}, {24,16}, {4,16}, {4,32}, | |
659 | {128,0}, {112,0}, {96,0}, {80,0}, {64,0}, {48,0}, {32,0}, {16,0}, {0,0}, | |
660 | // LB0..LB17 | |
661 | {144,0}, {160,0}, {176,0}, {192,0}, {216,0}, {224,0}, {240,0}, {240,16}, {240,32}, | |
662 | {136,16}, {152,16}, {168,16}, {184,16}, {200,16}, {220,16}, {240,48}, {240,64}, {224,64}, | |
663 | // LC0..LC17 | |
664 | {96,64}, {100,48}, {84,48}, {68,48}, {52,48}, {36,48}, {255,255}, {48,60}, {28,64}, | |
665 | {108,32}, {92,32}, {76,32}, {60,32}, {44,32}, {28,32}, {20,44}, {10,48}, {4,64}, | |
666 | // LD0..LD17 | |
667 | {124,32}, {140,32}, {156,32}, {172,32}, {188,32}, {214,32}, {180,48}, {202,48}, {224,48}, | |
668 | {116,48}, {132,48}, {148,48}, {164,48}, {255,255}, {144,60}, {164,64}, {188,64}, {208,64} | |
48a992f1 | 669 | }; |
2dea540a | 670 | const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = { |
acd3e79a | 671 | // LA0..LA17 |
672 | {64,128}, {75,132}, {84,145}, {91,164}, {97,187}, {102,213}, {105,242}, {109,255}, {128,243}, | |
673 | {61,255}, {67,255}, {72,255}, {77,255}, {82,255}, {86,255}, {90,255}, {93,255}, {96,255}, | |
674 | // LB0..LB17 | |
675 | {56,255}, {51,255}, {46,255}, {42,255}, {37,255}, {35,255}, {32,255}, {19,255}, {0,255}, | |
676 | {53,132}, {44,145}, {37,164}, {31,187}, {26,213}, {22,249}, {237,255}, {224,255}, {221,255}, | |
677 | // LC0..LC17 | |
678 | {184,255}, {179,135}, {170,149}, {163,169}, {157,193}, {153,220}, {255,255}, {167,255}, {165,255}, | |
679 | {128,26}, {128,60}, {128,94}, {128,128}, {128,162}, {128,196}, {145,233}, {148,255}, {161,255}, | |
680 | // LD0..LD17 | |
681 | {0,9}, {0,43}, {0,77}, {0,111}, {0,145}, {0,201}, {224,181}, {230,217}, {235,255}, | |
682 | {189,128}, {200,131}, {210,141}, {218,159}, {255,255}, {201,228}, {206,255}, {213,255}, {218,255} | |
d7f1e072 | 683 | }; |
acd3e79a | 684 | #elif defined(RGB_BACKLIGHT_KOYU) |
d7f1e072 | 685 | const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = { |
acd3e79a | 686 | // LA0..LA17 |
687 | {120,16}, {104,16}, {88,16}, {72,16}, {56,16}, {40,16}, {24,16}, {4,16}, {4,32}, | |
688 | {128,0}, {112,0}, {96,0}, {80,0}, {64,0}, {48,0}, {32,0}, {16,0}, {0,0}, | |
689 | // LB0..LB17 | |
690 | {144,0}, {160,0}, {176,0}, {192,0}, {208,0}, {224,0}, {240,0}, {240,16}, {240,32}, | |
691 | {136,16}, {152,16}, {168,16}, {184,16}, {200,16}, {220,16}, {240,48}, {240,64}, {224,64}, | |
692 | // LC0..LC17 | |
693 | {112,64}, {100,48}, {84,48}, {68,48}, {52,48}, {36,48}, {64,60}, {44,60}, {24,64}, | |
694 | {108,32}, {92,32}, {76,32}, {60,32}, {44,32}, {28,32}, {255,255}, {10,48}, {4,64}, | |
695 | // LD0..LD17 | |
696 | {124,32}, {140,32}, {156,32}, {172,32}, {188,32}, {214,32}, {180,48}, {202,48}, {224,48}, | |
697 | {116,48}, {132,48}, {148,48}, {164,48}, {255,255}, {160,60}, {180,64}, {208,64}, {255,255} | |
d7f1e072 W |
698 | }; |
699 | const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = { | |
acd3e79a | 700 | // LA0..LA17 |
701 | {64,128}, {75,132}, {84,145}, {91,164}, {97,187}, {102,213}, {105,242}, {109,255}, {128,243}, | |
702 | {61,255}, {67,255}, {72,255}, {77,255}, {82,255}, {86,255}, {90,255}, {93,255}, {96,255}, | |
703 | // LB0..LB17 | |
704 | {56,255}, {51,255}, {46,255}, {42,255}, {38,255}, {35,255}, {32,255}, {19,255}, {0,255}, | |
705 | {53,132}, {44,145}, {37,164}, {31,187}, {26,213}, {22,249}, {237,255}, {224,255}, {221,255}, | |
706 | // LC0..LC17 | |
707 | {189,255}, {179,135}, {170,149}, {163,169}, {157,193}, {153,220}, {172,252}, {169,255}, {165,255}, | |
708 | {128,26}, {128,60}, {128,94}, {128,128}, {128,162}, {128,196}, {255,255}, {148,255}, {161,255}, | |
709 | // LD0..LD17 | |
710 | {0,9}, {0,43}, {0,77}, {0,111}, {0,145}, {0,201}, {224,181}, {230,217}, {235,255}, | |
711 | {189,128}, {200,131}, {210,141}, {218,159}, {255,255}, {207,238}, {211,255}, {218,255}, {255,255} | |
48a992f1 | 712 | }; |
acd3e79a | 713 | #elif defined(RGB_BACKLIGHT_ZEAL60) || defined(RGB_BACKLIGHT_M60_A) |
2dea540a | 714 | const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = { |
acd3e79a | 715 | // LA0..LA17 |
716 | {120,16}, {104,16}, {88,16}, {72,16}, {56,16}, {40,16}, {24,16}, {4,16}, {4,32}, | |
717 | {128,0}, {112,0}, {96,0}, {80,0}, {64,0}, {48,0}, {32,0}, {16,0}, {0,0}, | |
718 | // LB0..LB17 | |
719 | {144,0}, {160,0}, {176,0}, {192,0}, {216,0}, {224,0}, {255,255}, {255,255}, {255,255}, | |
720 | {136,16}, {152,16}, {168,16}, {184,16}, {200,16}, {220,16}, {255,255}, {255,255}, {255,255}, | |
721 | // LC0..LC17 | |
722 | {102,64}, {100,48}, {84,48}, {68,48}, {52,48}, {36,48}, {60,64}, {43,64}, {23,64}, | |
723 | {108,32}, {92,32}, {76,32}, {60,32}, {44,32}, {28,32}, {20,48}, {2,48}, {3,64}, | |
724 | // LD0..LD17 | |
725 | {124,32}, {140,32}, {156,32}, {172,32}, {188,32}, {214,32}, {180,48}, {210,48}, {224,48}, | |
726 | {116,48}, {132,48}, {148,48}, {164,48}, {144,64}, {161,64}, {181,64}, {201,64}, {221,64} | |
48a992f1 | 727 | }; |
2dea540a | 728 | const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = { |
acd3e79a | 729 | // LA0..LA17 |
bffbb4b4 W |
730 | {58,129}, {70,129}, {80,139}, {89,157}, {96,181}, {101,208}, {105,238}, {109,255}, {128,247}, |
731 | {58,255}, {64,255}, {70,255}, {75,255}, {80,255}, {85,255}, {89,255}, {93,255}, {96,255}, | |
acd3e79a | 732 | // LB0..LB17 |
733 | {53,255}, {48,255}, {43,255}, {39,255}, {34,255}, {32,255}, {255,255}, {255,255}, {255,255}, | |
734 | {48,139}, {39,157}, {32,181}, {27,208}, {23,238}, {19,255}, {255,255}, {255,255}, {255,255}, | |
735 | // LC0..LC17 | |
736 | {188,255}, {183,131}, {173,143}, {165,163}, {159,188}, {154,216}, {172,252}, {170,255}, {165,255}, | |
737 | {128,9}, {128,46}, {128,82}, {128,119}, {128,155}, {128,192}, {150,244}, {147,255}, {161,255}, | |
738 | // LD0..LD17 | |
739 | {0,27}, {0,64}, {0,101}, {0,137}, {0,174}, {255,233}, {228,201}, {235,255}, {237,255}, | |
740 | {195,128}, {206,136}, {215,152}, {222,175}, {205,234}, {209,255}, {214,255}, {219,255}, {223,255} | |
48a992f1 | 741 | }; |
bffbb4b4 W |
742 | #elif defined(RGB_BACKLIGHT_U80_A) |
743 | const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = { | |
744 | // Thse are scaled by 14.5 per U | |
745 | // LA0..LA17 | |
746 | {109,36}, {94,36}, {80,36}, {65,36}, {51,36}, {36,36}, {22,36}, {4,36}, {5,51}, | |
747 | {116,22}, {102,22}, {87,22}, {73,22}, {58,22}, {44,22}, {29,22}, {15,22}, {0,22}, | |
748 | // LB0..LB17 | |
749 | {131,22}, {145,22}, {160,22}, {174,22}, {196,22}, {0,0}, {0,0}, {0,0}, {0,0}, | |
750 | {123,36}, {138,36}, {152,36}, {167,36}, {181,36}, {199,36}, {0,0}, {0,0}, {0,0}, | |
751 | // LC0..LC17 | |
752 | {102,80}, {91,65}, {76,65}, {62,65}, {47,65}, {33,65}, {58,76}, {40,80}, {22,80}, | |
753 | {98,51}, {83,51}, {69,51}, {54,51}, {40,51}, {25,51}, {0,0}, {9,65}, {4,80}, | |
754 | // LD0..LD17 | |
755 | {112,51}, {127,51}, {141,51}, {156,51}, {170,51}, {194,51}, {163,65}, {190,65}, {0,0}, | |
756 | {105,65}, {120,65}, {134,65}, {149,65}, {0,0}, {145,76}, {163,80}, {181,80}, {199,80}, | |
757 | // LE0..LE17 | |
758 | {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, | |
759 | {73,0}, {94,0}, {109,0}, {123,0}, {138,0}, {58,0}, {44,0}, {29,0}, {0,0}, | |
760 | // LF0..LF17 | |
761 | {160,0}, {174,0}, {189,0}, {203,0}, {225,0}, {239,0}, {254,0}, {254,22}, {254,36}, | |
762 | {239,22}, {239,36}, {225,22}, {225,36}, {0,0}, {239,65}, {225,80}, {239,80}, {254,80} | |
763 | }; | |
764 | const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = { | |
765 | // LA0..LA17 | |
766 | {59,129}, {69,129}, {80,138}, {88,154}, {95,175}, {100,200}, {104,227}, {107,255}, {128,226}, | |
767 | {59,255}, {64,255}, {69,255}, {75,255}, {80,255}, {84,255}, {88,255}, {91,255}, {95,255}, | |
768 | // LB0..LB17 | |
769 | {53,255}, {48,255}, {44,255}, {40,255}, {35,255}, {255,255}, {255,255}, {255,255}, {255,255}, | |
770 | {48,138}, {40,154}, {33,175}, {28,200}, {24,227}, {21,255}, {255,255}, {255,255}, {255,255}, | |
771 | // LC0..LC17 | |
772 | {192,255}, {184,131}, {174,141}, {166,159}, {160,181}, {155,207}, {174,244}, {171,255}, {166,255}, | |
773 | {128,9}, {128,43}, {128,77}, {128,111}, {128,145}, {128,179}, {255,255}, {150,252}, {162,255}, | |
774 | // LD0..LD17 | |
775 | {0,26}, {0,60}, {0,94}, {0,128}, {0,162}, {0,218}, {227,193}, {234,245}, {255,255}, | |
776 | {195,128}, {205,135}, {214,149}, {221,169}, {255,255}, {210,244}, {213,255}, {218,255}, {222,255}, | |
777 | // LE0..LE17 | |
778 | {255,255}, {255,255}, {255,255}, {255,255}, {255,255}, {255,255}, {255,255}, {255,255}, {255,255}, | |
779 | {70,255}, {66,255}, {62,255}, {59,255}, {56,255}, {73,255}, {76,255}, {79,255}, {84,255}, | |
780 | // LF0..LF17 | |
781 | {52,255}, {49,255}, {47,255}, {44,255}, {41,255}, {38,255}, {37,255}, {25,255}, {14,255}, | |
782 | {27,255}, {15,255}, {29,255}, {17,255}, {255,255}, {241,255}, {227,255}, {229,255}, {231,255} | |
783 | }; | |
acd3e79a | 784 | #elif defined(RGB_BACKLIGHT_HS60) && defined(HS60_ANSI) |
2bfac351 | 785 | const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = { |
acd3e79a | 786 | // LA1..LA47 |
787 | {0,0}, {4,16}, {6,32}, {10,48}, {16,0}, {24,16}, {28,32}, {36,48}, {32,0}, {40,16}, {44,32}, {52,48}, | |
788 | {48,0}, {56,16}, {60,32}, {68,48}, {64,0}, {72,16}, {76,32}, {84,48}, {80,0}, {88,16}, {92,32}, {100,48}, | |
789 | {96,0}, {104,16}, {108,32}, {116,48}, {112,0}, {120,16}, {124,32}, {132,48}, {128,0}, {136,16}, {140,32}, | |
790 | {148,48}, {144,0}, {152,16}, {156,32}, {164,48}, {160,0}, {168,16}, {172,32}, {180,48}, {176,0}, {184, 16}, {188,32}, | |
791 | {255,255},// LA48 does not exist, dummy | |
792 | // LA49..LA50 | |
793 | {192,0}, {200,16}, | |
794 | {255,255},// LA51 does not exit, dummy | |
795 | // LA52..LA60 | |
796 | {210,48}, {216,0}, {220,16}, {214,32}, {222,64}, {2,64}, {22,64}, {42,64}, {102,64}, | |
797 | {255,255},// LA61 does not exit, dummy | |
798 | {162,64}, {182,64}, {202,64} | |
2bfac351 | 799 | }; |
800 | const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = { | |
acd3e79a | 801 | // LA1..LA47 |
802 | {96,255}, {109,255}, {128,242}, {148,255}, {93,255}, {105,238}, {128,192}, {154,216}, {89,255}, {101,208}, {128,155}, {159,188}, | |
803 | {85,255}, {96,181}, {128,119}, {165,163}, {81,255}, {89,157}, {128,82}, {173,143}, {75,255}, {81,139}, {128,46}, {183,131}, | |
804 | {70,255}, {70,129}, {129,9}, {195,128}, {64,255}, {58,129}, {255,27}, {206,136}, {58,255}, {47,139}, {255,64}, {215,152}, | |
805 | {53,255}, {39,157}, {255,101}, {222,175}, {47,255}, {32,181}, {255,137}, {228,201}, {43,255}, {27,208}, {255, 174}, | |
806 | {255,255},// LA48 does not exist, dummy | |
807 | // LA49..LA50 | |
808 | {39,255}, {23,238}, | |
809 | {255,255},// LA51 does not exit, dummy | |
810 | // LA52..LA60 | |
811 | {235,255}, {33,255}, {19,255}, {255,233}, {224,255}, {160,255}, {164,255}, {169,255}, {188,255}, | |
812 | {255,255},// LA61 does not exit, dummy | |
813 | {209,255}, {215,255}, {220,255} | |
2bfac351 | 814 | }; |
acd3e79a | 815 | #elif defined(RGB_BACKLIGHT_HS60) && defined(HS60_HHKB) |
2bfac351 | 816 | const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = { |
acd3e79a | 817 | // LA1..LA60 |
818 | {0,0}, {4,16}, {6,32}, {10,48}, {16,0}, {24,16}, {28,32}, {36,48}, {32,0}, {40,16}, {44,32}, {52,48}, | |
819 | {48,0}, {56,16}, {60,32}, {68,48}, {64,0}, {72,16}, {76,32}, {84,48}, {80,0}, {88,16}, {92,32}, {100,48}, | |
820 | {96,0}, {104,16}, {108,32}, {116,48}, {112,0}, {120,16}, {124,32}, {132,48}, {128,0}, {136,16}, {140,32}, | |
821 | {148,48}, {144,0}, {152,16}, {156,32}, {164,48}, {160,0}, {168,16}, {172,32}, {180,48}, {176,0}, {184, 16}, {188,32}, | |
822 | {224,0}, {192,0}, {200,16}, {202,48}, {224,48}, {208,0}, {220,16}, {214,32}, {220,64}, {4,64}, {24,64}, {44,64}, {112,64}, | |
823 | {255,255}, {255,255}, // LA61..LA62 does not exit, dummy | |
824 | // LA63..LA64 | |
825 | {180,64}, {200,64} | |
2bfac351 | 826 | }; |
827 | const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = { | |
acd3e79a | 828 | // LA1..LA60 |
829 | {96,255}, {109,255}, {128,242}, {148,255}, {93,255}, {105,238}, {128,192}, {154,216}, {89,255}, {101,208}, {128,155}, {159,188}, | |
830 | {85,255}, {96,181}, {128,119}, {165,163}, {81,255}, {89,157}, {128,82}, {173,143}, {75,255}, {81,139}, {128,46}, {183,131}, | |
831 | {70,255}, {70,129}, {129,9}, {195,128}, {64,255}, {58,129}, {255,27}, {206,136}, {58,255}, {47,139}, {255,64}, {215,152}, | |
832 | {53,255}, {39,157}, {255,101}, {222,175}, {47,255}, {32,181}, {255,137}, {228,201}, {43,255}, {27,208}, {255, 174}, {32,255}, | |
833 | {39,255}, {23,238}, {233,242}, {237,255}, {35,255}, {19,255}, {255,233}, {223,255}, {161,255}, {165,255}, {170,255}, {192,255}, | |
834 | {255,255}, {255,255}, // LA61..LA62 does not exit, dummy | |
835 | // LA63..LA64 | |
836 | {214,255}, {219,255} | |
2bfac351 | 837 | }; |
acd3e79a | 838 | #elif defined(RGB_BACKLIGHT_HS60) //HS60_ISO |
2bfac351 | 839 | const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = { |
acd3e79a | 840 | // LA1..LA50 |
841 | {0,0}, {4,16}, {6,32}, {2,48}, {16,0}, {24,16}, {28,32}, {36,48}, {32,0}, {40,16}, {44,32}, {52,48}, {48,0}, | |
842 | {56,16}, {60,32}, {68,48}, {64,0}, {72,16}, {76,32}, {84,48}, {80,0}, {88,16}, {92,32}, {100,48}, {96,0}, {104,16}, | |
843 | {108,32}, {116,48}, {112,0}, {120,16}, {124,32}, {132,48}, {128,0}, {136,16}, {140,32}, {148,48}, {144,0}, {152,16}, | |
844 | {156,32}, {164,48}, {160,0}, {168,16}, {172,32}, {180,48}, {176,0}, {184, 16}, {188,32}, {20,48}, {192,0}, {200,16}, | |
845 | {255,255},// LA51 does not exit, dummy | |
846 | // LA52..LA60 | |
847 | {210,48}, {216,0}, {220,16}, {222,24}, {222,64}, {2,64}, {22,64}, {42,64}, {102,64}, | |
848 | {255,255},// LA61 does not exit, dummy | |
849 | {162,64}, {182,64}, {202,64} | |
2bfac351 | 850 | }; |
851 | const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = { | |
acd3e79a | 852 | // LA1..LA50 |
853 | {96,255}, {109,255}, {128,242}, {147,255}, {93,255}, {105,238}, {128,192}, {154,216}, {89,255}, {101,208}, {128,155}, {159,188}, {85,255}, | |
854 | {96,181}, {128,119}, {165,163}, {81,255}, {89,157}, {128,82}, {173,143}, {75,255}, {81,139}, {128,46}, {183,131}, {70,255}, {70,129}, | |
855 | {129,9}, {195,128}, {64,255}, {58,129}, {255,27}, {206,136}, {58,255}, {47,139}, {255,64}, {215,152}, {53,255}, {39,157}, {255,101}, | |
856 | {222,175}, {47,255}, {32,181}, {255,137}, {228,201}, {43,255}, {27,208}, {255, 174}, {150,246}, {39,255}, {23,238}, | |
857 | {255,255},// LA51 does not exit, dummy | |
858 | // LA52..LA60 | |
859 | {235,255}, {33,255}, {19,255}, {10,255}, {224,255}, {160,255}, {164,255}, {169,255}, {188,255}, | |
860 | {255,255},// LA61 does not exit, dummy | |
861 | {209,255}, {215,255}, {220,255} | |
2bfac351 | 862 | }; |
acd3e79a | 863 | #elif defined(RGB_BACKLIGHT_NK65) |
864 | const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = { | |
865 | // LA1..LA60 | |
866 | {0,0}, {4,16}, {6,32}, {10,48}, {16,0}, {24,16}, {28,32}, {36,48}, {32,0}, {40,16}, {44,32}, {52,48}, | |
867 | {48,0}, {56,16}, {60,32}, {68,48}, {64,0}, {72,16}, {76,32}, {84,48}, {80,0}, {88,16}, {92,32}, {100,48}, | |
868 | {96,0}, {104,16}, {108,32}, {116,48}, {112,0}, {120,16}, {124,32}, {132,48}, {128,0}, {136,16}, {140,32}, | |
869 | {148,48}, {144,0}, {152,16}, {156,32}, {164,48}, {160,0}, {168,16}, {172,32}, {180,48}, {176,0}, {184, 16}, {188,32}, | |
870 | {160,64}, {192,0}, {200,16}, {210,48}, {224,48}, {216,0}, {220,16}, {214,32}, {224,64}, {2,64}, {22,64}, {42,64}, {102,64}, | |
871 | {255,255},// LA61 does not exit, dummy | |
872 | //LA62..LB5 | |
873 | {176,64}, {192,64}, {208,64}, {240,0}, {240,16}, {240,48}, {240,64}, {240,32} | |
874 | }; | |
875 | const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = { | |
876 | // LA1..LA60 | |
877 | {96,255}, {109,255}, {128,242}, {148,255}, {93,255}, {105,238}, {128,192}, {154,216}, {89,255}, {101,208}, {128,155}, {159,188}, | |
878 | {85,255}, {96,181}, {128,119}, {165,163}, {81,255}, {89,157}, {128,82}, {173,143}, {75,255}, {81,139}, {128,46}, {183,131}, | |
879 | {70,255}, {70,129}, {129,9}, {195,128}, {64,255}, {58,129}, {255,27}, {206,136}, {58,255}, {47,139}, {255,64}, {215,152}, | |
880 | {53,255}, {39,157}, {255,101}, {222,175}, {47,255}, {32,181}, {255,137}, {228,201}, {43,255}, {27,208}, {255, 174}, | |
881 | {208,255}, {39,255}, {23,238}, {235,255}, {235,255}, {33,255}, {19,255}, {255,233}, {224,255}, {160,255}, {164,255}, {169,255}, {188,255}, | |
882 | {255,255},// LA61 does not exit, dummy | |
883 | //LA62..LB5 | |
5e43f879 | 884 | {221,255}, {225,255}, {229,255}, {22,255}, {12,255}, {244,255}, {234,255}, {255,255} |
acd3e79a | 885 | }; |
886 | #elif defined(RGB_BACKLIGHT_M6_B) | |
2dea540a W |
887 | // M6-B is really simple: |
888 | // 0 3 5 | |
889 | // 1 2 4 | |
890 | const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = { | |
acd3e79a | 891 | {0,0}, {0,16}, {16,16}, {16,0}, {32,16}, {32,0} |
2dea540a W |
892 | }; |
893 | const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = { | |
acd3e79a | 894 | {160,255}, {96,255}, {77,255}, {179,255}, {51,255}, {205,255} |
2dea540a | 895 | }; |
2ce3025b X |
896 | #elif defined(RGB_BACKLIGHT_DAWN60) |
897 | const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = { | |
898 | // LA1..LA16 | |
899 | {104, 16}, {88 , 16}, {72 , 16}, {56 , 16}, {40 , 16}, {24 , 16}, {4 , 16}, {6 , 32}, | |
900 | {112, 0}, {96 , 0}, {80 , 0}, {64 , 0}, {48 , 0}, {32 , 0}, {16 , 0}, {0 , 0}, | |
901 | ||
902 | // LB1..LB16 | |
903 | {128, 0}, {144, 0}, {160, 0}, {176, 0}, {192, 0}, {208, 0}, {224, 0}, {214, 32}, | |
904 | {120, 16}, {136, 16}, {152, 16}, {168, 16}, {184, 16}, {200, 16}, {220, 16}, {224, 48}, | |
905 | ||
906 | // LC1..LC16 | |
907 | {100, 48}, {84 , 48}, {68 , 48}, {52 , 48}, {36 , 48}, {102, 64}, {42 , 64}, {22 , 64}, | |
908 | {108, 32}, {92 , 32}, {76 , 32}, {60 , 32}, {44 , 32}, {28 , 32}, {10 , 48}, {2 , 64}, | |
909 | ||
910 | // LD1..LD16 | |
911 | {124, 32}, {140, 32}, {156, 32}, {172, 32}, {188, 32}, {180, 48}, {202, 48}, {224, 64}, | |
912 | {116, 48}, {132, 48}, {148, 48}, {164, 48}, {160, 64}, {176, 64}, {192, 64}, {208, 64}, | |
913 | ||
914 | //RGB UNDERGLOW | |
915 | {27 , 3}, {64 , 3}, {100, 3}, {137, 3}, {173, 3}, {209, 3}, {242, 4}, {255, 8}, {255,32}, {255,64}, | |
916 | {241,64}, {212,64}, {173,64}, {137,64}, {100,64}, {63 ,64}, {28 ,64}, {0 ,64}, {0 ,32}, {0 , 8}, //20 | |
917 | }; | |
918 | ||
919 | const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = { | |
920 | //LA1..LA16 | |
921 | {70,129}, {80,139}, {89,157}, {96,181}, {101,208}, {105,238}, {109,255}, {128,247}, | |
922 | {64,255}, {70,255}, {75,255}, {80,255}, {85,255}, {89,255}, {93,255}, {96,255}, | |
923 | //LB1..LB16 | |
924 | {58,255}, {53,255}, {48,255}, {43,255}, {39,255}, {34,255}, {32,255}, {255,233}, | |
925 | {58,129}, {48,139}, {39,157}, {32,181}, {27,208}, {23,238}, {19,255}, {237,255}, | |
926 | //LC1..LC16 | |
927 | {183,131}, {173,143}, {165,163}, {159,188}, {154,216}, {188,255}, {170,255}, {165,255}, | |
928 | {128,9}, {128,46}, {128,82}, {128,119}, {128,155}, {128,192}, {147,255}, {161,255}, | |
929 | //LD1..LD16 | |
930 | {0,27}, {0,64}, {0,101}, {0,137}, {0,174}, {228,201}, {235,255}, {224,255}, | |
931 | {195,128}, {206,136}, {215,152}, {222,175}, {208,255}, {213,255}, {217, 255}, {222,225}, | |
932 | ||
933 | //UNDERGLOW, {A,D} | |
934 | //1 - 10 | |
935 | {91,255}, {84,255}, {74,255}, {60,255}, {48,255}, {39,255}, {32,255}, {27,255}, {0,255}, {236,255}, | |
936 | //11 - 20 | |
937 | {234,255}, {222,255}, {213,255}, {197,255}, {180,255}, {167,255}, {152,255}, {147,255}, {128,255}, {101,255} | |
938 | }; | |
939 | ||
48a992f1 W |
940 | #endif |
941 | ||
942 | // This may seem counter-intuitive, but it's quite flexible. | |
943 | // For each LED, get it's position to decide what color to make it. | |
944 | // This solves the issue of LEDs (and switches) not aligning to a grid, | |
945 | // or having a large "bitmap" and sampling them. | |
946 | void map_led_to_point( uint8_t index, Point *point ) | |
947 | { | |
acd3e79a | 948 | // Slightly messy way to get Point structs out of progmem. |
949 | uint8_t *addr = (uint8_t*)&g_map_led_to_point[index]; | |
950 | point->x = pgm_read_byte(addr); | |
951 | point->y = pgm_read_byte(addr+1); | |
48a992f1 | 952 | |
acd3e79a | 953 | #if defined(RGB_BACKLIGHT_M6_B) || defined(RGB_BACKLIGHT_HS60) || defined(RGB_BACKLIGHT_NK65) |
954 | return; | |
2dea540a W |
955 | #endif |
956 | ||
acd3e79a | 957 | switch (index) |
958 | { | |
2ce3025b | 959 | #if !defined(RGB_BACKLIGHT_DAWN60) |
acd3e79a | 960 | case 18+4: // LB4A |
961 | if ( g_config.use_split_backspace ) | |
962 | point->x -= 8; | |
963 | break; | |
2ce3025b | 964 | #endif |
acd3e79a | 965 | #if defined(RGB_BACKLIGHT_ZEAL60) |
966 | case 18+14: // LB14A | |
967 | if ( g_config.use_iso_enter ) | |
968 | point->y += 8; // extremely pedantic | |
969 | break; | |
970 | case 54+5: // LD5A | |
971 | if ( !g_config.use_iso_enter ) | |
972 | point->x -= 10; | |
973 | break; | |
974 | case 36+16: // LC16A | |
975 | if ( !g_config.use_split_left_shift ) | |
976 | point->x += 8; | |
977 | break; | |
2dea540a | 978 | #endif |
acd3e79a | 979 | #if defined(RGB_BACKLIGHT_ZEAL60) || defined(RGB_BACKLIGHT_M60_A) |
980 | case 36+0: // LC0A | |
981 | if ( g_config.use_7u_spacebar ) | |
982 | point->x += 10; | |
983 | break; | |
984 | case 36+6: // LC6A | |
985 | if ( g_config.use_7u_spacebar ) | |
986 | point->x += 4; | |
987 | break; | |
988 | case 54+7: // LD7A | |
989 | if ( !g_config.use_split_right_shift ) | |
990 | point->x -= 8; | |
991 | break; | |
2ce3025b X |
992 | #endif |
993 | #if defined(RGB_BACKLIGHT_DAWN60) | |
994 | case 15+6: // LB6A | |
995 | if ( !g_config.use_split_backspace ) | |
996 | point->x += 8; | |
997 | break; | |
998 | case 31+6: // LC6A | |
999 | if ( g_config.use_7u_spacebar ) | |
1000 | point->x = 112; | |
1001 | break; | |
1002 | case 47+16: // LD16A | |
1003 | if ( g_config.use_7u_spacebar ) | |
1004 | point->x -= 8; | |
1005 | break; | |
1006 | case 47+6: // LD6A | |
1007 | if ( g_config.use_split_right_shift ) | |
1008 | point->x += 6; | |
1009 | break; | |
1010 | case 47+7: // LD7A | |
1011 | if ( g_config.use_split_right_shift ) | |
1012 | point->x += 6; | |
1013 | break; | |
2dea540a | 1014 | #endif |
acd3e79a | 1015 | } |
48a992f1 W |
1016 | } |
1017 | ||
1018 | void map_led_to_point_polar( uint8_t index, Point *point ) | |
1019 | { | |
acd3e79a | 1020 | // Slightly messy way to get Point structs out of progmem. |
1021 | uint8_t *addr = (uint8_t*)&g_map_led_to_point_polar[index]; | |
1022 | point->x = pgm_read_byte(addr); | |
1023 | point->y = pgm_read_byte(addr+1); | |
48a992f1 W |
1024 | } |
1025 | ||
1026 | // | |
1027 | // Maps switch matrix coordinate (row,col) to LED index | |
1028 | // | |
1029 | ||
1030 | ||
acd3e79a | 1031 | #if defined(RGB_BACKLIGHT_ZEAL65) |
d7f1e072 | 1032 | // Note: Left spacebar stab is at 4,2 (LC7) |
48a992f1 W |
1033 | // Right spacebar stab is at 4,9 (D14) |
1034 | // | |
1035 | // A17, A16, A15, A14, A13, A12, A11, A10, A9, B0, B1, B2, B3, B4, B6 | |
1036 | // A7, A6, A5, A4, A3, A2, A1, A0, B9, B10, B11, B12, B13, B14, B7 | |
1037 | // A8, C14, C13, C12, C11, C10, C9, D0, D1, D2, D3, D4, D5, B5, B8 | |
1038 | // C16, C15, C5, C4, C3, C2, C1, D9, D10, D11, D12, D6, D7, D8, B15 | |
1039 | // C17, C8, C7, ---, ---, ---, ---, C0, ---, D14, D15, D16, D17, B17, B16 | |
1040 | const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = { | |
acd3e79a | 1041 | { 0+17, 0+16, 0+15, 0+14, 0+13, 0+12, 0+11, 0+10, 0+9, 18+0, 18+1, 18+2, 18+3, 18+4, 18+6 }, |
1042 | { 0+7, 0+6, 0+5, 0+4, 0+3, 0+2, 0+1, 0+0, 18+9, 18+10, 18+11, 18+12, 18+13, 18+14, 18+7 }, | |
1043 | { 0+8, 36+14, 36+13, 36+12, 36+11, 36+10, 36+9, 54+0, 54+1, 54+2, 54+3, 54+4, 54+5, 18+5, 18+8 }, | |
1044 | { 36+16, 36+15, 36+5, 36+4, 36+3, 36+2, 36+1, 54+9, 54+10, 54+11, 54+12, 54+6, 54+7, 54+8, 18+15 }, | |
1045 | { 36+17, 36+8, 36+7, 255, 255, 255, 255, 36+0, 255, 54+14, 54+15, 54+16, 54+17, 18+17, 18+16 } | |
48a992f1 | 1046 | }; |
d7f1e072 W |
1047 | #elif defined(RGB_BACKLIGHT_KOYU) |
1048 | // Note: Left spacebar stab is at 4,4 (LC6) | |
1049 | // Right spacebar stab is at 4,10 (D14) | |
1050 | // | |
1051 | // A17, A16, A15, A14, A13, A12, A11, A10, A9, B0, B1, B2, B3, B4, B6 | |
1052 | // A7, A6, A5, A4, A3, A2, A1, A0, B9, B10, B11, B12, B13, B14, B7 | |
1053 | // A8, C14, C13, C12, C11, C10, C9, D0, D1, D2, D3, D4, D5, B5, B8 | |
1054 | // C16, C15, C5, C4, C3, C2, C1, D9, D10, D11, D12, D6, D7, D8, B15 | |
1055 | // C17, C8, C7, C6, ---, ---, ---, C0, ---, ---, D14, D15, D16, B17, B16 | |
1056 | const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = { | |
acd3e79a | 1057 | { 0+17, 0+16, 0+15, 0+14, 0+13, 0+12, 0+11, 0+10, 0+9, 18+0, 18+1, 18+2, 18+3, 18+4, 18+6 }, |
1058 | { 0+7, 0+6, 0+5, 0+4, 0+3, 0+2, 0+1, 0+0, 18+9, 18+10, 18+11, 18+12, 18+13, 18+14, 18+7 }, | |
1059 | { 0+8, 36+14, 36+13, 36+12, 36+11, 36+10, 36+9, 54+0, 54+1, 54+2, 54+3, 54+4, 54+5, 18+5, 18+8 }, | |
1060 | { 36+16, 36+15, 36+5, 36+4, 36+3, 36+2, 36+1, 54+9, 54+10, 54+11, 54+12, 54+6, 54+7, 54+8, 18+15 }, | |
1061 | { 36+17, 36+8, 36+7, 36+6, 255, 255, 255, 36+0, 255, 255, 54+14, 54+15, 54+16, 18+17, 18+16 } | |
d7f1e072 | 1062 | }; |
acd3e79a | 1063 | #elif defined(RGB_BACKLIGHT_ZEAL60) || defined(RGB_BACKLIGHT_M60_A) |
48a992f1 W |
1064 | // Note: Left spacebar stab is at 4,3 (LC6) |
1065 | // Right spacebar stab is at 4,9 (LD13) or 4,10 (LD14) | |
1066 | // | |
1067 | // A17, A16, A15, A14, A13, A12, A11, A10, A9, B0, B1, B2, B3, B4, | |
1068 | // A7, A6, A5, A4, A3, A2, A1, A0, B9, B10, B11, B12, B13, B14, | |
1069 | // A8, C14, C13, C12, C11, C10, C9, D0, D1, D2, D3, D4, D5, B5, | |
1070 | // C16, C15, C5, C4, C3, C2, C1, D9, D10, D11, D12, D6, D7, D8, | |
1071 | // C17, C8, C7, C6, ---, ---, ---, C0, ---, D13, D14, D15, D16, D17, | |
1072 | const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = { | |
acd3e79a | 1073 | { 0+17, 0+16, 0+15, 0+14, 0+13, 0+12, 0+11, 0+10, 0+9, 18+0, 18+1, 18+2, 18+3, 18+4 }, |
1074 | { 0+7, 0+6, 0+5, 0+4, 0+3, 0+2, 0+1, 0+0, 18+9, 18+10, 18+11, 18+12, 18+13, 18+14 }, | |
1075 | { 0+8, 36+14, 36+13, 36+12, 36+11, 36+10, 36+9, 54+0, 54+1, 54+2, 54+3, 54+4, 54+5, 18+5 }, | |
1076 | { 36+16, 36+15, 36+5, 36+4, 36+3, 36+2, 36+1, 54+9, 54+10, 54+11, 54+12, 54+6, 54+7, 54+8 }, | |
1077 | { 36+17, 36+8, 36+7, 36+6, 255, 255, 255, 36+0, 255, 54+13, 54+14, 54+15, 54+16, 54+17 } | |
48a992f1 | 1078 | }; |
bffbb4b4 W |
1079 | #elif defined(RGB_BACKLIGHT_U80_A) |
1080 | // Note: Left spacebar stab is at 5,3 (LC6) | |
1081 | // Right spacebar stab is at 5,10 (LD14) | |
1082 | const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = { | |
1083 | { 72+17, 72+16, 72+15, 72+14, 72+9, 72+10, 72+11, 72+12, 72+13, 90+0, 90+1, 90+2, 90+3, 255, 90+4, 90+5, 90+6 }, | |
1084 | { 0+17, 0+16, 0+15, 0+14, 0+13, 0+12, 0+11, 0+10, 0+9, 18+0, 18+1, 18+2, 18+3, 18+4, 90+11, 90+9, 90+7 }, | |
1085 | { 0+7, 0+6, 0+5, 0+4, 0+3, 0+2, 0+1, 0+0, 18+9, 18+10, 18+11, 18+12, 18+13, 18+14, 90+12, 90+10, 90+8 }, | |
1086 | { 0+8, 36+14, 36+13, 36+12, 36+11, 36+10, 36+9, 54+0, 54+1, 54+2, 54+3, 54+4, 54+5, 255, 255, 255, 255 }, | |
1087 | { 36+16, 255, 36+5, 36+4, 36+3, 36+2, 36+1, 54+9, 54+10, 54+11, 54+12, 54+6, 54+7, 255, 255, 90+14, 255 }, | |
1088 | { 36+17, 36+8, 36+7, 36+6, 255, 255, 255, 36+0, 255, 255, 54+14, 54+15, 54+16, 54+17, 90+15, 90+16, 90+17 } | |
1089 | }; | |
acd3e79a | 1090 | #elif defined(RGB_BACKLIGHT_HS60) && defined(HS60_ANSI) |
2bfac351 | 1091 | // |
1092 | // LA1, LA5, LA9, LA13, LA17, LA21, LA25, LA29, LA33, LA37, LA41, LA45, LA49, LA53, | |
1093 | // LA2, LA6, LA10, LA14, LA18, LA22, LA26, LA30, LA34, LA38, LA42, LA46, LA50, ---, | |
1094 | // LA3, LA7, LA11, LA15, LA19, LA23, LA27, LA31, LA35, LA39, LA43, LA47, LA54, LA55, | |
1095 | // LA4, ---, LA8, LA12, LA16, LA20, LA24, LA28, LA32, LA36, LA40, LA44, ---, LA52, | |
1096 | // LA57, LA58, LA59, ---, ---, ---, LA60, ---, ---, ---, LA62, LA63, LA64, LA56 | |
1097 | const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = { | |
acd3e79a | 1098 | { 1-1, 5-1, 9-1, 13-1, 17-1, 21-1, 25-1, 29-1, 33-1, 37-1, 41-1, 45-1, 49-1, 53-1 }, |
1099 | { 2-1, 6-1, 10-1, 14-1, 18-1, 22-1, 26-1, 30-1, 34-1, 38-1, 42-1, 46-1, 50-1, 255 }, | |
1100 | { 3-1, 7-1, 11-1, 15-1, 19-1, 23-1, 27-1, 31-1, 35-1, 39-1, 43-1, 47-1, 54-1, 55-1 }, | |
1101 | { 4-1, 255, 8-1, 12-1, 16-1, 20-1, 24-1, 28-1, 32-1, 36-1, 40-1, 44-1, 255, 52-1 }, | |
1102 | { 57-1, 58-1, 59-1, 255, 255, 255, 60-1, 255, 255, 255, 62-1, 63-1, 64-1, 56-1 } | |
2bfac351 | 1103 | }; |
acd3e79a | 1104 | #elif defined(RGB_BACKLIGHT_HS60) && defined(HS60_HHKB) |
2bfac351 | 1105 | // |
1106 | // LA1, LA5, LA9, LA13, LA17, LA21, LA25, LA29, LA33, LA37, LA41, LA45, LA49, LA53, | |
1107 | // LA2, LA6, LA10, LA14, LA18, LA22, LA26, LA30, LA34, LA38, LA42, LA46, LA50, LA48, | |
1108 | // LA3, LA7, LA11, LA15, LA19, LA23, LA27, LA31, LA35, LA39, LA43, LA47, LA54, LA55, | |
1109 | // LA4, ---, LA8, LA12, LA16, LA20, LA24, LA28, LA32, LA36, LA40, LA44, LA51, LA52, | |
1110 | // LA57, LA58, LA59, ---, ---, ---, LA60, ---, ---, ---, ---, LA63, LA64, LA56 | |
1111 | const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = { | |
acd3e79a | 1112 | { 1-1, 5-1, 9-1, 13-1, 17-1, 21-1, 25-1, 29-1, 33-1, 37-1, 41-1, 45-1, 49-1, 53-1 }, |
1113 | { 2-1, 6-1, 10-1, 14-1, 18-1, 22-1, 26-1, 30-1, 34-1, 38-1, 42-1, 46-1, 50-1, 48-1 }, | |
1114 | { 3-1, 7-1, 11-1, 15-1, 19-1, 23-1, 27-1, 31-1, 35-1, 39-1, 43-1, 47-1, 54-1, 55-1 }, | |
1115 | { 4-1, 255, 8-1, 12-1, 16-1, 20-1, 24-1, 28-1, 32-1, 36-1, 40-1, 44-1, 51-1, 52-1 }, | |
1116 | { 57-1, 58-1, 59-1, 255, 255, 255, 60-1, 255, 255, 255, 255, 63-1, 64-1, 56-1 } | |
2bfac351 | 1117 | }; |
acd3e79a | 1118 | #elif defined(RGB_BACKLIGHT_HS60) //HS60_ISO |
2bfac351 | 1119 | // |
1120 | // LA1, LA5, LA9, LA13, LA17, LA21, LA25, LA29, LA33, LA37, LA41, LA45, LA49, LA53, | |
1121 | // LA2, LA6, LA10, LA14, LA18, LA22, LA26, LA30, LA34, LA38, LA42, LA46, LA50, ---, | |
1122 | // LA3, LA7, LA11, LA15, LA19, LA23, LA27, LA31, LA35, LA39, LA43, LA47, LA54, LA55, | |
1123 | // LA4, LA48, LA8, LA12, LA16, LA20, LA24, LA28, LA32, LA36, LA40, LA44, ---, LA52, | |
1124 | // LA57, LA58, LA59, ---, ---, ---, LA60, ---, ---, ---, LA62, LA63, LA64, LA56 | |
1125 | const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = { | |
acd3e79a | 1126 | { 1-1, 5-1, 9-1, 13-1, 17-1, 21-1, 25-1, 29-1, 33-1, 37-1, 41-1, 45-1, 49-1, 53-1 }, |
1127 | { 2-1, 6-1, 10-1, 14-1, 18-1, 22-1, 26-1, 30-1, 34-1, 38-1, 42-1, 46-1, 50-1, 255 }, | |
1128 | { 3-1, 7-1, 11-1, 15-1, 19-1, 23-1, 27-1, 31-1, 35-1, 39-1, 43-1, 47-1, 54-1, 55-1 }, | |
1129 | { 4-1, 48-1, 8-1, 12-1, 16-1, 20-1, 24-1, 28-1, 32-1, 36-1, 40-1, 44-1, 255, 52-1 }, | |
1130 | { 57-1, 58-1, 59-1, 255, 255, 255, 60-1, 255, 255, 255, 62-1, 63-1, 64-1, 56-1 } | |
1131 | }; | |
1132 | #elif defined(RGB_BACKLIGHT_NK65) | |
1133 | // | |
1134 | // LA1, LA5, LA9, LA13, LA17, LA21, LA25, LA29, LA33, LA37, LA41, LA45, LA49, LA53, LB1, | |
1135 | // LA2, LA6, LA10, LA14, LA18, LA22, LA26, LA30, LA34, LA38, LA42, LA46, LA50, ---, LB2, | |
1136 | // LA3, LA7, LA11, LA15, LA19, LA23, LA27, LA31, LA35, LA39, LA43, LA47, LA54, LA55, LB5, | |
1137 | // LA4, ---, LA8, LA12, LA16, LA20, LA24, LA28, LA32, LA36, LA40, LA44, LA51, LA52, LB3, | |
1138 | // LA57, LA58, LA59, ---, ---, ---, LA60, ---, ---, LA48, LA62, LA63, LA64, LA56, LB4 | |
1139 | const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = { | |
1140 | { 1-1, 5-1, 9-1, 13-1, 17-1, 21-1, 25-1, 29-1, 33-1, 37-1, 41-1, 45-1, 49-1, 53-1, 1+64-1 }, | |
1141 | { 2-1, 6-1, 10-1, 14-1, 18-1, 22-1, 26-1, 30-1, 34-1, 38-1, 42-1, 46-1, 50-1, 255, 2+64-1 }, | |
1142 | { 3-1, 7-1, 11-1, 15-1, 19-1, 23-1, 27-1, 31-1, 35-1, 39-1, 43-1, 47-1, 54-1, 55-1, 5+64-1 }, | |
1143 | { 4-1, 255, 8-1, 12-1, 16-1, 20-1, 24-1, 28-1, 32-1, 36-1, 40-1, 44-1, 51-1, 52-1, 3+64-1 }, | |
1144 | { 57-1, 58-1, 59-1, 255, 255, 255, 60-1, 255, 255, 48-1, 62-1, 63-1, 64-1, 56-1, 4+64-1 } | |
2bfac351 | 1145 | }; |
acd3e79a | 1146 | #elif defined(RGB_BACKLIGHT_M6_B) |
2dea540a W |
1147 | // M6-B is really simple: |
1148 | // 0 3 5 | |
1149 | // 1 2 4 | |
1150 | const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = { | |
acd3e79a | 1151 | { 0, 3, 5, 1, 2, 4 } |
2dea540a | 1152 | }; |
2ce3025b X |
1153 | #elif defined(RGB_BACKLIGHT_DAWN60) |
1154 | //Dawn60 | |
1155 | // A16, A15, A14, A13, A12, A11, A10, A9, B1, B2, B3, B4, B5, B6, | |
1156 | // A7, A6, A5, A4, A3, A2, A1, B9, B10, B11, B12, B13, B14, B15, | |
1157 | // A8, C14, C13, C12, C11, C10, C9, D1, D2, D3, D4, D5, B8, B7, | |
1158 | // C15, C5, C4, C3, C2, C1, D9, D10, D11, D12, ---, D6, D7, B16, | |
1159 | // C16, C8, C7, ---, ---, C6, ---, ---, ---, D13, D14, D15, D16, D8, | |
1160 | const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = { | |
1161 | { -1+16, -1+15, -1+14, -1+13, -1+12, -1+11, -1+10, -1+9 , 15+1 , 15+2 , 15+3 , 15+4 , 15+5 , 15+6 }, | |
1162 | { -1+7 , -1+6 , -1+5 , -1+4 , -1+3 , -1+2 , -1 +1, 15+9 , 15+10, 15+11, 15+12, 15+13, 15+14, 15+15}, | |
1163 | { -1+8 , 31+14, 31+13, 31+12, 31+11, 31+10, 31+9 , 47+1 , 47+2 , 47+3 , 47+4 , 47+5 , 15+8 , 15+7 }, | |
1164 | { 31+15, 31+5 , 31+4 , 31+3 , 31+2 , 31+1 , 47+9 , 47+10, 47+11, 47+12, 255 ,47+6 , 47+7 , 15+16}, | |
1165 | { 31+16, 31+8 , 31+7 , 255 , 255 , 31+6 , 255 , 255 , 255 , 47+13, 47+14, 47+15, 47+16, 47+8 } | |
1166 | }; | |
48a992f1 W |
1167 | #endif |
1168 | ||
1169 | void map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led ) | |
1170 | { | |
acd3e79a | 1171 | *led = 255; |
1172 | if ( row < MATRIX_ROWS && column < MATRIX_COLS ) | |
1173 | { | |
1174 | *led = pgm_read_byte(&g_map_row_column_to_led[row][column]); | |
1175 | } | |
48a992f1 W |
1176 | } |
1177 | ||
1178 | void backlight_update_pwm_buffers(void) | |
1179 | { | |
acd3e79a | 1180 | #if defined(RGB_BACKLIGHT_M6_B) |
1181 | IS31FL3218_update_pwm_buffers(); | |
1182 | #elif defined(RGB_BACKLIGHT_HS60) | |
1183 | IS31FL3733_update_pwm_buffers( ISSI_ADDR_1, 0 ); | |
1184 | IS31FL3733_update_led_control_registers( ISSI_ADDR_1, 0 ); | |
1185 | #elif defined(RGB_BACKLIGHT_NK65) | |
1186 | IS31FL3733_update_pwm_buffers( ISSI_ADDR_1, 0 ); | |
1187 | IS31FL3733_update_pwm_buffers( ISSI_ADDR_2, 1 ); | |
1188 | IS31FL3733_update_led_control_registers( ISSI_ADDR_1, 0 ); | |
1189 | IS31FL3733_update_led_control_registers( ISSI_ADDR_2, 1 ); | |
bffbb4b4 W |
1190 | #elif defined(RGB_BACKLIGHT_U80_A) |
1191 | static uint8_t driver = 0; | |
1192 | switch ( driver ) | |
1193 | { | |
1194 | case 0: | |
1195 | IS31FL3731_update_pwm_buffers( ISSI_ADDR_1, 0 ); | |
1196 | break; | |
1197 | case 1: | |
1198 | IS31FL3731_update_pwm_buffers( ISSI_ADDR_2, 1 ); | |
1199 | break; | |
1200 | case 2: | |
1201 | IS31FL3731_update_pwm_buffers( ISSI_ADDR_3, 2 ); | |
1202 | break; | |
1203 | } | |
1204 | if ( ++driver > 2 ) | |
1205 | { | |
1206 | driver = 0; | |
1207 | } | |
2dea540a | 1208 | #else |
bffbb4b4 W |
1209 | IS31FL3731_update_pwm_buffers( ISSI_ADDR_1, 0 ); |
1210 | IS31FL3731_update_pwm_buffers( ISSI_ADDR_2, 1 ); | |
1211 | IS31FL3731_update_led_control_registers( ISSI_ADDR_1, 0 ); | |
1212 | IS31FL3731_update_led_control_registers( ISSI_ADDR_2, 1 ); | |
2dea540a | 1213 | #endif |
48a992f1 W |
1214 | } |
1215 | ||
1216 | void backlight_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ) | |
1217 | { | |
acd3e79a | 1218 | #if defined(RGB_BACKLIGHT_M6_B) |
1219 | IS31FL3218_set_color( index, red, green, blue ); | |
1220 | #elif defined(RGB_BACKLIGHT_HS60) || defined(RGB_BACKLIGHT_NK65) | |
1221 | IS31FL3733_set_color( index, red, green, blue ); | |
2ce3025b X |
1222 | #elif defined(RGB_BACKLIGHT_DAWN60) |
1223 | if( index < DRIVER_LED_TOTAL ) { | |
1224 | IS31FL3731_set_color( index, red, green, blue ); | |
1225 | } else { | |
1226 | g_ws2812_leds[index - DRIVER_LED_TOTAL].r = red; | |
1227 | g_ws2812_leds[index - DRIVER_LED_TOTAL].g = green; | |
1228 | g_ws2812_leds[index - DRIVER_LED_TOTAL].b = blue; | |
1229 | ws2812_setleds(g_ws2812_leds, WS2812_LED_TOTAL); | |
1230 | } | |
2dea540a | 1231 | #else |
acd3e79a | 1232 | IS31FL3731_set_color( index, red, green, blue ); |
2dea540a | 1233 | #endif |
48a992f1 W |
1234 | } |
1235 | ||
1236 | void backlight_set_color_all( uint8_t red, uint8_t green, uint8_t blue ) | |
1237 | { | |
acd3e79a | 1238 | #if defined(RGB_BACKLIGHT_M6_B) |
1239 | IS31FL3218_set_color_all( red, green, blue ); | |
1240 | #elif defined(RGB_BACKLIGHT_HS60) || defined(RGB_BACKLIGHT_NK65) | |
1241 | IS31FL3733_set_color_all( red, green, blue ); | |
2ce3025b X |
1242 | #elif defined(RGB_BACKLIGHT_DAWN60) |
1243 | IS31FL3731_set_color_all( red, green, blue ); | |
1244 | for (uint8_t i = 0; i < WS2812_LED_TOTAL; i++) { | |
1245 | g_ws2812_leds[i].r = red; | |
1246 | g_ws2812_leds[i].g = green; | |
1247 | g_ws2812_leds[i].b = blue; | |
1248 | } | |
1249 | ws2812_setleds(g_ws2812_leds, WS2812_LED_TOTAL); | |
2dea540a | 1250 | #else |
acd3e79a | 1251 | IS31FL3731_set_color_all( red, green, blue ); |
2dea540a | 1252 | #endif |
48a992f1 W |
1253 | } |
1254 | ||
1255 | void backlight_set_key_hit(uint8_t row, uint8_t column) | |
1256 | { | |
acd3e79a | 1257 | uint8_t led; |
1258 | map_row_column_to_led(row,column,&led); | |
1259 | g_key_hit[led] = 0; | |
48a992f1 | 1260 | |
acd3e79a | 1261 | g_any_key_hit = 0; |
48a992f1 W |
1262 | } |
1263 | ||
acd3e79a | 1264 | #if !defined(RGB_BACKLIGHT_HS60) && !defined(RGB_BACKLIGHT_NK65) |
48a992f1 W |
1265 | // This is (F_CPU/1024) / 20 Hz |
1266 | // = 15625 Hz / 20 Hz | |
1267 | // = 781 | |
1268 | #define TIMER3_TOP 781 | |
1269 | ||
1270 | void backlight_timer_init(void) | |
1271 | { | |
acd3e79a | 1272 | static uint8_t backlight_timer_is_init = 0; |
1273 | if ( backlight_timer_is_init ) | |
1274 | { | |
1275 | return; | |
1276 | } | |
1277 | backlight_timer_is_init = 1; | |
1278 | ||
1279 | // Timer 3 setup | |
1280 | TCCR3B = _BV(WGM32) | // CTC mode OCR3A as TOP | |
1281 | _BV(CS32) | _BV(CS30); // prescale by /1024 | |
1282 | // Set TOP value | |
1283 | uint8_t sreg = SREG; | |
1284 | cli(); | |
1285 | ||
1286 | OCR3AH = (TIMER3_TOP >> 8) & 0xff; | |
1287 | OCR3AL = TIMER3_TOP & 0xff; | |
1288 | SREG = sreg; | |
48a992f1 W |
1289 | } |
1290 | ||
1291 | void backlight_timer_enable(void) | |
1292 | { | |
acd3e79a | 1293 | TIMSK3 |= _BV(OCIE3A); |
48a992f1 W |
1294 | } |
1295 | ||
1296 | void backlight_timer_disable(void) | |
1297 | { | |
acd3e79a | 1298 | TIMSK3 &= ~_BV(OCIE3A); |
48a992f1 | 1299 | } |
2bfac351 | 1300 | #else //STM32, use GPT with TIM4. Enable in halconf.h |
1301 | static void gpt_backlight_timer_task(GPTDriver *gptp); | |
1302 | // Timer setup at 200Khz, callback at 10k ticks = 20Hz | |
1303 | static GPTConfig gpt4cfg1 = { | |
acd3e79a | 1304 | .frequency = 200000U, |
1305 | .callback = gpt_backlight_timer_task | |
2bfac351 | 1306 | }; |
1307 | ||
1308 | void backlight_timer_init(void) | |
1309 | { | |
acd3e79a | 1310 | gptStart(&GPTD4, &gpt4cfg1); |
2bfac351 | 1311 | } |
1312 | ||
1313 | void backlight_timer_enable(void) | |
1314 | { | |
acd3e79a | 1315 | gptStartContinuous(&GPTD4, 10000); |
2bfac351 | 1316 | } |
1317 | ||
1318 | void backlight_timer_disable(void) | |
1319 | { | |
acd3e79a | 1320 | gptStopTimer(&GPTD4); |
2bfac351 | 1321 | } |
acd3e79a | 1322 | #endif //!defined(RGB_BACKLIGHT_HS60) && !defined(RGB_BACKLIGHT_NK65) |
48a992f1 W |
1323 | |
1324 | void backlight_set_suspend_state(bool state) | |
1325 | { | |
acd3e79a | 1326 | g_suspend_state = state; |
48a992f1 W |
1327 | } |
1328 | ||
1329 | void backlight_set_indicator_state(uint8_t state) | |
1330 | { | |
acd3e79a | 1331 | g_indicator_state = state; |
48a992f1 W |
1332 | } |
1333 | ||
1334 | void backlight_effect_rgb_test(void) | |
1335 | { | |
acd3e79a | 1336 | // Mask out bits 4 and 5 |
1337 | // This 2-bit value will stay the same for 16 ticks. | |
1338 | switch ( (g_tick & 0x30) >> 4 ) | |
1339 | { | |
1340 | case 0: | |
1341 | { | |
1342 | backlight_set_color_all( 255, 0, 0 ); | |
1343 | break; | |
1344 | } | |
1345 | case 1: | |
1346 | { | |
1347 | backlight_set_color_all( 0, 255, 0 ); | |
1348 | break; | |
1349 | } | |
1350 | case 2: | |
1351 | { | |
1352 | backlight_set_color_all( 0, 0, 255 ); | |
1353 | break; | |
1354 | } | |
1355 | case 3: | |
1356 | { | |
1357 | backlight_set_color_all( 255, 255, 255 ); | |
1358 | break; | |
1359 | } | |
1360 | } | |
48a992f1 W |
1361 | } |
1362 | ||
2dea540a | 1363 | #if defined(RGB_DEBUGGING_ONLY) |
48a992f1 W |
1364 | // This tests the LEDs |
1365 | // Note that it will change the LED control registers | |
1366 | // in the LED drivers, and leave them in an invalid | |
1367 | // state for other backlight effects. | |
1368 | // ONLY USE THIS FOR TESTING LEDS! | |
1369 | void backlight_effect_single_LED_test(void) | |
1370 | { | |
acd3e79a | 1371 | static uint8_t color = 0; // 0,1,2 for R,G,B |
1372 | static uint8_t row = 0; | |
1373 | static uint8_t column = 0; | |
1374 | ||
1375 | static uint8_t tick = 0; | |
1376 | tick++; | |
1377 | ||
1378 | if ( tick > 2 ) | |
1379 | { | |
1380 | tick = 0; | |
1381 | column++; | |
1382 | } | |
1383 | if ( column > 14 ) | |
1384 | { | |
1385 | column = 0; | |
1386 | row++; | |
1387 | } | |
1388 | if ( row > 4 ) | |
1389 | { | |
1390 | row = 0; | |
1391 | color++; | |
1392 | } | |
1393 | if ( color > 2 ) | |
1394 | { | |
1395 | color = 0; | |
1396 | } | |
1397 | ||
1398 | uint8_t led; | |
1399 | map_row_column_to_led( row, column, &led ); | |
1400 | backlight_set_color_all( 255, 255, 255 ); | |
1401 | backlight_test_led( led, color==0, color==1, color==2 ); | |
48a992f1 | 1402 | } |
2dea540a | 1403 | #endif // defined(RGB_DEBUGGING_ONLY) |
48a992f1 W |
1404 | |
1405 | // All LEDs off | |
1406 | void backlight_effect_all_off(void) | |
1407 | { | |
acd3e79a | 1408 | backlight_set_color_all( 0, 0, 0 ); |
48a992f1 W |
1409 | } |
1410 | ||
1411 | // Solid color | |
1412 | void backlight_effect_solid_color(void) | |
1413 | { | |
acd3e79a | 1414 | HSV hsv = { .h = g_config.color_1.h, .s = g_config.color_1.s, .v = g_config.brightness }; |
1415 | RGB rgb = hsv_to_rgb( hsv ); | |
1416 | backlight_set_color_all( rgb.r, rgb.g, rgb.b ); | |
48a992f1 W |
1417 | } |
1418 | ||
1419 | // alphas = color1, mods = color2 | |
1420 | void backlight_effect_alphas_mods(void) | |
1421 | { | |
acd3e79a | 1422 | RGB rgb1 = hsv_to_rgb( (HSV){ .h = g_config.color_1.h, .s = g_config.color_1.s, .v = g_config.brightness } ); |
1423 | RGB rgb2 = hsv_to_rgb( (HSV){ .h = g_config.color_2.h, .s = g_config.color_2.s, .v = g_config.brightness } ); | |
bffbb4b4 | 1424 | bool is_alpha = false; |
acd3e79a | 1425 | for ( int row = 0; row < MATRIX_ROWS; row++ ) |
1426 | { | |
1427 | for ( int column = 0; column < MATRIX_COLS; column++ ) | |
1428 | { | |
1429 | uint8_t index; | |
1430 | map_row_column_to_led( row, column, &index ); | |
1431 | if ( index < BACKLIGHT_LED_COUNT ) | |
1432 | { | |
bffbb4b4 W |
1433 | #if defined(RGB_BACKLIGHT_U80_A) |
1434 | if ( row == 0 ) | |
1435 | { | |
1436 | is_alpha = ( column < 16 ) && (( 0b1110000111100001 & (1<<column) ) == 0); | |
1437 | } | |
1438 | else | |
1439 | { | |
1440 | is_alpha = ( column < 16 ) && (( g_config.alphas_mods[row-1] & (1<<column) ) == 0); | |
1441 | } | |
1442 | #else | |
1443 | is_alpha = ( g_config.alphas_mods[row] & (1<<column) ) == 0; | |
1444 | #endif | |
1445 | if ( is_alpha ) | |
acd3e79a | 1446 | { |
1447 | backlight_set_color( index, rgb1.r, rgb1.g, rgb1.b ); | |
1448 | } | |
1449 | else | |
1450 | { | |
1451 | backlight_set_color( index, rgb2.r, rgb2.g, rgb2.b ); | |
1452 | } | |
1453 | } | |
1454 | } | |
1455 | } | |
2ce3025b X |
1456 | #if defined(RGB_BACKLIGHT_DAWN60) |
1457 | for (int i = 0; i < WS2812_LED_TOTAL; i++) { | |
1458 | if ((RGB_UNDERGLOW_ALPHA_TOP_START <= i && i <= RGB_UNDERGLOW_ALPHA_TOP_END) || | |
1459 | (RGB_UNDERGLOW_ALPHA_BOT_START <= i && i <= RGB_UNDERGLOW_ALPHA_BOT_END)) { | |
1460 | backlight_set_color(i + DRIVER_LED_TOTAL, rgb1.r, rgb1.g, rgb1.b); | |
1461 | } else { | |
1462 | backlight_set_color(i + DRIVER_LED_TOTAL, rgb2.r, rgb2.g, rgb2.b); | |
1463 | } | |
1464 | } | |
1465 | #endif | |
48a992f1 W |
1466 | } |
1467 | ||
1468 | void backlight_effect_gradient_up_down(void) | |
1469 | { | |
acd3e79a | 1470 | int16_t h1 = g_config.color_1.h; |
1471 | int16_t h2 = g_config.color_2.h; | |
1472 | int16_t deltaH = h2 - h1; | |
1473 | ||
1474 | // Take the shortest path between hues | |
1475 | if ( deltaH > 127 ) | |
1476 | { | |
1477 | deltaH -= 256; | |
1478 | } | |
1479 | else if ( deltaH < -127 ) | |
1480 | { | |
1481 | deltaH += 256; | |
1482 | } | |
1483 | // Divide delta by 4, this gives the delta per row | |
1484 | deltaH /= 4; | |
1485 | ||
1486 | int16_t s1 = g_config.color_1.s; | |
1487 | int16_t s2 = g_config.color_2.s; | |
1488 | int16_t deltaS = ( s2 - s1 ) / 4; | |
1489 | ||
1490 | HSV hsv = { .h = 0, .s = 255, .v = g_config.brightness }; | |
1491 | RGB rgb; | |
1492 | Point point; | |
1493 | for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ ) | |
1494 | { | |
1495 | map_led_to_point( i, &point ); | |
1496 | // The y range will be 0..64, map this to 0..4 | |
1497 | uint8_t y = (point.y>>4); | |
1498 | // Relies on hue being 8-bit and wrapping | |
1499 | hsv.h = g_config.color_1.h + ( deltaH * y ); | |
1500 | hsv.s = g_config.color_1.s + ( deltaS * y ); | |
1501 | rgb = hsv_to_rgb( hsv ); | |
2ce3025b | 1502 | |
acd3e79a | 1503 | backlight_set_color( i, rgb.r, rgb.g, rgb.b ); |
1504 | } | |
48a992f1 W |
1505 | } |
1506 | ||
1507 | void backlight_effect_raindrops(bool initialize) | |
1508 | { | |
acd3e79a | 1509 | int16_t h1 = g_config.color_1.h; |
1510 | int16_t h2 = g_config.color_2.h; | |
1511 | int16_t deltaH = h2 - h1; | |
1512 | deltaH /= 4; | |
1513 | ||
1514 | // Take the shortest path between hues | |
1515 | if ( deltaH > 127 ) | |
1516 | { | |
1517 | deltaH -= 256; | |
1518 | } | |
1519 | else if ( deltaH < -127 ) | |
1520 | { | |
1521 | deltaH += 256; | |
1522 | } | |
1523 | ||
1524 | int16_t s1 = g_config.color_1.s; | |
1525 | int16_t s2 = g_config.color_2.s; | |
1526 | int16_t deltaS = ( s2 - s1 ) / 4; | |
1527 | ||
1528 | HSV hsv; | |
1529 | RGB rgb; | |
1530 | ||
1531 | // Change one LED every tick | |
1532 | uint8_t led_to_change = ( g_tick & 0x000 ) == 0 ? rand() % BACKLIGHT_LED_COUNT : 255; | |
1533 | ||
1534 | for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ ) | |
1535 | { | |
1536 | // If initialize, all get set to random colors | |
1537 | // If not, all but one will stay the same as before. | |
1538 | if ( initialize || i == led_to_change ) | |
1539 | { | |
1540 | hsv.h = h1 + ( deltaH * ( rand() & 0x03 ) ); | |
1541 | hsv.s = s1 + ( deltaS * ( rand() & 0x03 ) ); | |
1542 | // Override brightness with global brightness control | |
2ce3025b | 1543 | hsv.v = g_config.brightness; |
acd3e79a | 1544 | |
1545 | rgb = hsv_to_rgb( hsv ); | |
1546 | backlight_set_color( i, rgb.r, rgb.g, rgb.b ); | |
1547 | } | |
1548 | } | |
48a992f1 W |
1549 | } |
1550 | ||
1551 | void backlight_effect_cycle_all(void) | |
1552 | { | |
acd3e79a | 1553 | uint8_t offset = ( g_tick << g_config.effect_speed ) & 0xFF; |
1554 | ||
1555 | // Relies on hue being 8-bit and wrapping | |
1556 | for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ ) | |
1557 | { | |
1558 | uint16_t offset2 = g_key_hit[i]<<2; | |
2ce3025b | 1559 | #if !defined(RGB_BACKLIGHT_HS60) && !defined(RGB_BACKLIGHT_NK65) && !defined(RGB_BACKLIGHT_DAWN60) |
acd3e79a | 1560 | // stabilizer LEDs use spacebar hits |
1561 | if ( i == 36+6 || i == 54+13 || // LC6, LD13 | |
1562 | ( g_config.use_7u_spacebar && i == 54+14 ) ) // LD14 | |
1563 | { | |
1564 | offset2 = g_key_hit[36+0]<<2; | |
1565 | } | |
1566 | #endif | |
1567 | offset2 = (offset2<=63) ? (63-offset2) : 0; | |
1568 | ||
1569 | HSV hsv = { .h = offset+offset2, .s = 255, .v = g_config.brightness }; | |
1570 | RGB rgb = hsv_to_rgb( hsv ); | |
1571 | backlight_set_color( i, rgb.r, rgb.g, rgb.b ); | |
1572 | } | |
48a992f1 W |
1573 | } |
1574 | ||
1575 | void backlight_effect_cycle_left_right(void) | |
1576 | { | |
acd3e79a | 1577 | uint8_t offset = ( g_tick << g_config.effect_speed ) & 0xFF; |
1578 | HSV hsv = { .h = 0, .s = 255, .v = g_config.brightness }; | |
1579 | RGB rgb; | |
1580 | Point point; | |
1581 | for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ ) | |
1582 | { | |
1583 | uint16_t offset2 = g_key_hit[i]<<2; | |
2ce3025b | 1584 | #if !defined(RGB_BACKLIGHT_HS60) && !defined(RGB_BACKLIGHT_NK65) && !defined(RGB_BACKLIGHT_DAWN60) |
acd3e79a | 1585 | // stabilizer LEDs use spacebar hits |
1586 | if ( i == 36+6 || i == 54+13 || // LC6, LD13 | |
1587 | ( g_config.use_7u_spacebar && i == 54+14 ) ) // LD14 | |
1588 | { | |
1589 | offset2 = g_key_hit[36+0]<<2; | |
1590 | } | |
1591 | #endif | |
1592 | offset2 = (offset2<=63) ? (63-offset2) : 0; | |
1593 | ||
1594 | map_led_to_point( i, &point ); | |
1595 | // Relies on hue being 8-bit and wrapping | |
1596 | hsv.h = point.x + offset + offset2; | |
1597 | rgb = hsv_to_rgb( hsv ); | |
1598 | backlight_set_color( i, rgb.r, rgb.g, rgb.b ); | |
1599 | } | |
48a992f1 W |
1600 | } |
1601 | ||
1602 | void backlight_effect_cycle_up_down(void) | |
1603 | { | |
acd3e79a | 1604 | uint8_t offset = ( g_tick << g_config.effect_speed ) & 0xFF; |
1605 | HSV hsv = { .h = 0, .s = 255, .v = g_config.brightness }; | |
1606 | RGB rgb; | |
1607 | Point point; | |
1608 | for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ ) | |
1609 | { | |
1610 | uint16_t offset2 = g_key_hit[i]<<2; | |
2ce3025b | 1611 | #if !defined(RGB_BACKLIGHT_HS60) && !defined(RGB_BACKLIGHT_NK65) && !defined(RGB_BACKLIGHT_DAWN60) |
acd3e79a | 1612 | // stabilizer LEDs use spacebar hits |
1613 | if ( i == 36+6 || i == 54+13 || // LC6, LD13 | |
1614 | ( g_config.use_7u_spacebar && i == 54+14 ) ) // LD14 | |
1615 | { | |
1616 | offset2 = g_key_hit[36+0]<<2; | |
1617 | } | |
1618 | #endif | |
1619 | offset2 = (offset2<=63) ? (63-offset2) : 0; | |
1620 | ||
1621 | map_led_to_point( i, &point ); | |
1622 | // Relies on hue being 8-bit and wrapping | |
1623 | hsv.h = point.y + offset + offset2; | |
1624 | rgb = hsv_to_rgb( hsv ); | |
1625 | backlight_set_color( i, rgb.r, rgb.g, rgb.b ); | |
1626 | } | |
48a992f1 W |
1627 | } |
1628 | ||
1629 | void backlight_effect_jellybean_raindrops( bool initialize ) | |
1630 | { | |
acd3e79a | 1631 | HSV hsv; |
1632 | RGB rgb; | |
1633 | ||
1634 | // Change one LED every tick | |
1635 | uint8_t led_to_change = ( g_tick & 0x000 ) == 0 ? rand() % BACKLIGHT_LED_COUNT : 255; | |
1636 | ||
1637 | for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ ) | |
1638 | { | |
1639 | // If initialize, all get set to random colors | |
1640 | // If not, all but one will stay the same as before. | |
1641 | if ( initialize || i == led_to_change ) | |
1642 | { | |
1643 | hsv.h = rand() & 0xFF; | |
1644 | hsv.s = rand() & 0xFF; | |
1645 | // Override brightness with global brightness control | |
1646 | hsv.v = g_config.brightness;; | |
1647 | ||
1648 | rgb = hsv_to_rgb( hsv ); | |
1649 | backlight_set_color( i, rgb.r, rgb.g, rgb.b ); | |
1650 | } | |
1651 | } | |
48a992f1 W |
1652 | } |
1653 | ||
1654 | void backlight_effect_cycle_radial1(void) | |
1655 | { | |
acd3e79a | 1656 | uint8_t offset = ( g_tick << g_config.effect_speed ) & 0xFF; |
1657 | HSV hsv = { .h = 0, .s = 255, .v = g_config.brightness }; | |
1658 | RGB rgb; | |
1659 | Point point; | |
1660 | for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ ) | |
1661 | { | |
1662 | map_led_to_point_polar( i, &point ); | |
1663 | // Relies on hue being 8-bit and wrapping | |
1664 | hsv.h = point.x + offset; | |
1665 | hsv.s = point.y; | |
1666 | rgb = hsv_to_rgb( hsv ); | |
1667 | backlight_set_color( i, rgb.r, rgb.g, rgb.b ); | |
1668 | } | |
48a992f1 W |
1669 | } |
1670 | ||
1671 | void backlight_effect_cycle_radial2(void) | |
1672 | { | |
acd3e79a | 1673 | uint8_t offset = ( g_tick << g_config.effect_speed ) & 0xFF; |
1674 | ||
1675 | HSV hsv = { .h = 0, .s = g_config.color_1.s, .v = g_config.brightness }; | |
1676 | RGB rgb; | |
1677 | Point point; | |
1678 | for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ ) | |
1679 | { | |
1680 | map_led_to_point_polar( i, &point ); | |
1681 | uint8_t offset2 = offset + point.x; | |
1682 | if ( offset2 & 0x80 ) | |
1683 | { | |
1684 | offset2 = ~offset2; | |
1685 | } | |
1686 | offset2 = offset2 >> 2; | |
1687 | hsv.h = g_config.color_1.h + offset2; | |
1688 | hsv.s = 127 + ( point.y >> 1 ); | |
1689 | rgb = hsv_to_rgb( hsv ); | |
1690 | backlight_set_color( i, rgb.r, rgb.g, rgb.b ); | |
1691 | } | |
48a992f1 W |
1692 | } |
1693 | ||
d7f1e072 W |
1694 | #if defined(RGB_BACKLIGHT_M6_B) |
1695 | void backlight_effect_custom_colors(void) | |
48a992f1 | 1696 | { |
acd3e79a | 1697 | RGB rgb; |
1698 | for ( uint8_t i = 0; i < 6; i++ ) | |
1699 | { | |
1700 | HSV hsv = { .h = g_config.custom_color[i].h, .s = g_config.custom_color[i].s, .v = g_config.brightness }; | |
1701 | rgb = hsv_to_rgb( hsv ); | |
1702 | uint8_t led; | |
1703 | map_row_column_to_led( 0, i, &led ); | |
1704 | backlight_set_color( led, rgb.r, rgb.g, rgb.b ); | |
1705 | } | |
d7f1e072 W |
1706 | } |
1707 | #endif | |
1708 | ||
1709 | void backlight_effect_indicators_set_colors( uint8_t index, HS color ) | |
1710 | { | |
acd3e79a | 1711 | HSV hsv = { .h = color.h, .s = color.s, .v = g_config.brightness }; |
1712 | RGB rgb = hsv_to_rgb( hsv ); | |
1713 | if ( index == 254 ) | |
1714 | { | |
1715 | backlight_set_color_all( rgb.r, rgb.g, rgb.b ); | |
1716 | } | |
1717 | else | |
1718 | { | |
1719 | backlight_set_color( index, rgb.r, rgb.g, rgb.b ); | |
1720 | ||
1721 | // If the spacebar LED is the indicator, | |
1722 | // do the same for the spacebar stabilizers | |
1723 | if ( index == 36+0 ) // LC0 | |
1724 | { | |
1725 | #if defined(RGB_BACKLIGHT_ZEAL65) | |
1726 | backlight_set_color( 36+7, rgb.r, rgb.g, rgb.b ); // LC7 | |
1727 | backlight_set_color( 54+14, rgb.r, rgb.g, rgb.b ); // LD14 | |
1728 | #elif defined(RGB_BACKLIGHT_KOYU) | |
1729 | backlight_set_color( 36+6, rgb.r, rgb.g, rgb.b ); // LC6 | |
1730 | backlight_set_color( 54+14, rgb.r, rgb.g, rgb.b ); // LD14 | |
1731 | #elif defined(RGB_BACKLIGHT_ZEAL60) || defined(RGB_BACKLIGHT_M60_A) | |
1732 | backlight_set_color( 36+6, rgb.r, rgb.g, rgb.b ); // LC6 | |
1733 | backlight_set_color( 54+13, rgb.r, rgb.g, rgb.b ); // LD13 | |
1734 | if ( g_config.use_7u_spacebar ) | |
1735 | { | |
1736 | backlight_set_color( 54+14, rgb.r, rgb.g, rgb.b ); // LD14 | |
1737 | } | |
48a992f1 | 1738 | #endif |
acd3e79a | 1739 | } |
1740 | } | |
48a992f1 W |
1741 | } |
1742 | ||
1743 | // This runs after another backlight effect and replaces | |
1744 | // colors already set | |
1745 | void backlight_effect_indicators(void) | |
1746 | { | |
acd3e79a | 1747 | if ( g_config.caps_lock_indicator.index != 255 && |
1748 | ( g_indicator_state & (1<<USB_LED_CAPS_LOCK) ) ) | |
1749 | { | |
1750 | backlight_effect_indicators_set_colors( g_config.caps_lock_indicator.index, g_config.caps_lock_indicator.color ); | |
1751 | } | |
acd3e79a | 1752 | // This if/else if structure allows higher layers to |
1753 | // override lower ones. If we set layer 3's indicator | |
1754 | // to none, then it will NOT show layer 2 or layer 1 | |
1755 | // indicators, even if those layers are on via the | |
1756 | // MO13/MO23 Fn combo magic. | |
1757 | // | |
1758 | // Basically we want to handle the case where layer 3 is | |
1759 | // still the backlight configuration layer and we don't | |
1760 | // want "all LEDs" indicators hiding the backlight effect, | |
1761 | // but still allow end users to do whatever they want. | |
1762 | if ( IS_LAYER_ON(3) ) | |
1763 | { | |
1764 | if ( g_config.layer_3_indicator.index != 255 ) | |
1765 | { | |
1766 | backlight_effect_indicators_set_colors( g_config.layer_3_indicator.index, g_config.layer_3_indicator.color ); | |
1767 | } | |
1768 | } | |
1769 | else if ( IS_LAYER_ON(2) ) | |
1770 | { | |
1771 | if ( g_config.layer_2_indicator.index != 255 ) | |
1772 | { | |
1773 | backlight_effect_indicators_set_colors( g_config.layer_2_indicator.index, g_config.layer_2_indicator.color ); | |
1774 | } | |
1775 | } | |
1776 | else if ( IS_LAYER_ON(1) ) | |
1777 | { | |
1778 | if ( g_config.layer_1_indicator.index != 255 ) | |
1779 | { | |
1780 | backlight_effect_indicators_set_colors( g_config.layer_1_indicator.index, g_config.layer_1_indicator.color ); | |
1781 | } | |
1782 | } | |
48a992f1 W |
1783 | } |
1784 | ||
acd3e79a | 1785 | #if !defined(RGB_BACKLIGHT_HS60) && !defined(RGB_BACKLIGHT_NK65) |
48a992f1 | 1786 | ISR(TIMER3_COMPA_vect) |
2bfac351 | 1787 | #else //STM32 interrupt |
1788 | static void gpt_backlight_timer_task(GPTDriver *gptp) | |
1789 | #endif | |
48a992f1 | 1790 | { |
acd3e79a | 1791 | // delay 1 second before driving LEDs or doing anything else |
1792 | static uint8_t startup_tick = 0; | |
1793 | if ( startup_tick < 20 ) | |
1794 | { | |
1795 | startup_tick++; | |
1796 | return; | |
1797 | } | |
1798 | ||
1799 | g_tick++; | |
1800 | ||
1801 | if ( g_any_key_hit < 0xFFFFFFFF ) | |
1802 | { | |
1803 | g_any_key_hit++; | |
1804 | } | |
1805 | ||
1806 | for ( int led = 0; led < BACKLIGHT_LED_COUNT; led++ ) | |
1807 | { | |
1808 | if ( g_key_hit[led] < 255 ) | |
1809 | { | |
1810 | g_key_hit[led]++; | |
1811 | } | |
1812 | } | |
1813 | ||
1814 | // Factory default magic value | |
1815 | if ( g_config.effect == 255 ) | |
1816 | { | |
1817 | backlight_effect_rgb_test(); | |
1818 | return; | |
1819 | } | |
1820 | ||
1821 | // Ideally we would also stop sending zeros to the LED driver PWM buffers | |
1822 | // while suspended and just do a software shutdown. This is a cheap hack for now. | |
1823 | bool suspend_backlight = ((g_suspend_state && g_config.disable_when_usb_suspended) || | |
1824 | (g_config.disable_after_timeout > 0 && g_any_key_hit > g_config.disable_after_timeout * 60 * 20)); | |
1825 | uint8_t effect = suspend_backlight ? 0 : g_config.effect; | |
1826 | ||
1827 | // Keep track of the effect used last time, | |
1828 | // detect change in effect, so each effect can | |
1829 | // have an optional initialization. | |
1830 | static uint8_t effect_last = 255; | |
1831 | bool initialize = effect != effect_last; | |
1832 | effect_last = effect; | |
1833 | ||
1834 | // this gets ticked at 20 Hz. | |
1835 | // each effect can opt to do calculations | |
1836 | // and/or request PWM buffer updates. | |
1837 | switch ( effect ) | |
1838 | { | |
1839 | case 0: | |
1840 | backlight_effect_all_off(); | |
1841 | break; | |
1842 | case 1: | |
1843 | backlight_effect_solid_color(); | |
1844 | break; | |
1845 | case 2: | |
d7f1e072 | 1846 | #if defined(RGB_BACKLIGHT_M6_B) |
acd3e79a | 1847 | backlight_effect_custom_colors(); |
d7f1e072 | 1848 | #else |
acd3e79a | 1849 | backlight_effect_alphas_mods(); |
d7f1e072 | 1850 | #endif |
acd3e79a | 1851 | break; |
1852 | case 3: | |
1853 | backlight_effect_gradient_up_down(); | |
1854 | break; | |
1855 | case 4: | |
1856 | backlight_effect_raindrops( initialize ); | |
1857 | break; | |
1858 | case 5: | |
1859 | backlight_effect_cycle_all(); | |
1860 | break; | |
1861 | case 6: | |
1862 | backlight_effect_cycle_left_right(); | |
1863 | break; | |
1864 | case 7: | |
1865 | backlight_effect_cycle_up_down(); | |
1866 | break; | |
1867 | case 8: | |
1868 | backlight_effect_jellybean_raindrops( initialize ); | |
1869 | break; | |
1870 | case 9: | |
1871 | backlight_effect_cycle_radial1(); | |
1872 | break; | |
1873 | case 10: | |
1874 | backlight_effect_cycle_radial2(); | |
1875 | break; | |
1876 | default: | |
1877 | backlight_effect_all_off(); | |
1878 | break; | |
1879 | } | |
1880 | ||
1881 | if ( ! suspend_backlight ) | |
1882 | { | |
2dea540a | 1883 | #if !defined(RGB_BACKLIGHT_M6_B) |
acd3e79a | 1884 | backlight_effect_indicators(); |
2dea540a | 1885 | #endif |
acd3e79a | 1886 | } |
48a992f1 W |
1887 | } |
1888 | ||
1889 | void backlight_set_indicator_index( uint8_t *index, uint8_t row, uint8_t column ) | |
1890 | { | |
acd3e79a | 1891 | if ( row >= MATRIX_ROWS ) |
1892 | { | |
1893 | // Special value, 255=none, 254=all | |
1894 | *index = row; | |
1895 | } | |
1896 | else | |
1897 | { | |
1898 | map_row_column_to_led( row, column, index ); | |
1899 | } | |
48a992f1 W |
1900 | } |
1901 | ||
6734cd9c W |
1902 | void backlight_get_indicator_row_col( uint8_t index, uint8_t *row, uint8_t *column ) |
1903 | { | |
acd3e79a | 1904 | if ( index == 255 || index == 254 ) |
1905 | { | |
1906 | // Special value, 255=none, 254=all | |
1907 | *row = index; | |
1908 | *column = 0; | |
1909 | return; | |
1910 | } | |
1911 | for ( uint8_t r = 0; r < MATRIX_ROWS; r++ ) | |
1912 | { | |
1913 | for ( uint8_t c = 0; c < MATRIX_COLS; c++ ) | |
1914 | { | |
1915 | uint8_t i = 255; | |
1916 | map_row_column_to_led( r, c, &i ); | |
1917 | if ( i == index ) | |
1918 | { | |
1919 | *row = r; | |
1920 | *column = c; | |
1921 | return; | |
1922 | } | |
1923 | } | |
1924 | } | |
6734cd9c W |
1925 | } |
1926 | ||
48a992f1 | 1927 | // Some helpers for setting/getting HSV |
d7f1e072 | 1928 | void _set_color( HS *color, uint8_t *data ) |
48a992f1 | 1929 | { |
acd3e79a | 1930 | color->h = data[0]; |
1931 | color->s = data[1]; | |
48a992f1 W |
1932 | } |
1933 | ||
d7f1e072 | 1934 | void _get_color( HS *color, uint8_t *data ) |
48a992f1 | 1935 | { |
acd3e79a | 1936 | data[0] = color->h; |
1937 | data[1] = color->s; | |
48a992f1 W |
1938 | } |
1939 | ||
1940 | void backlight_config_set_value( uint8_t *data ) | |
1941 | { | |
acd3e79a | 1942 | bool reinitialize = false; |
1943 | uint8_t *value_id = &(data[0]); | |
1944 | uint8_t *value_data = &(data[1]); | |
1945 | switch ( *value_id ) | |
1946 | { | |
48a992f1 | 1947 | #if defined (RGB_BACKLIGHT_ZEAL60) || defined(RGB_BACKLIGHT_ZEAL65) |
acd3e79a | 1948 | case id_use_split_backspace: |
1949 | { | |
1950 | g_config.use_split_backspace = (bool)*value_data; | |
1951 | reinitialize = true; | |
1952 | break; | |
1953 | } | |
48a992f1 W |
1954 | #endif |
1955 | #if defined (RGB_BACKLIGHT_ZEAL60) | |
acd3e79a | 1956 | case id_use_split_left_shift: |
1957 | { | |
1958 | g_config.use_split_left_shift = (bool)*value_data; | |
1959 | reinitialize = true; | |
1960 | break; | |
1961 | } | |
1962 | case id_use_split_right_shift: | |
1963 | { | |
1964 | g_config.use_split_right_shift = (bool)*value_data; | |
1965 | reinitialize = true; | |
1966 | break; | |
1967 | } | |
1968 | case id_use_7u_spacebar: | |
1969 | { | |
1970 | g_config.use_7u_spacebar = (bool)*value_data; | |
1971 | reinitialize = true; | |
1972 | break; | |
1973 | } | |
1974 | case id_use_iso_enter: | |
1975 | { | |
1976 | g_config.use_iso_enter = (bool)*value_data; | |
1977 | reinitialize = true; | |
1978 | break; | |
1979 | } | |
1980 | case id_disable_hhkb_blocker_leds: | |
1981 | { | |
1982 | g_config.disable_hhkb_blocker_leds = (bool)*value_data; | |
1983 | reinitialize = true; | |
1984 | break; | |
1985 | } | |
48a992f1 | 1986 | #endif |
acd3e79a | 1987 | case id_disable_when_usb_suspended: |
1988 | { | |
1989 | g_config.disable_when_usb_suspended = (bool)*value_data; | |
1990 | break; | |
1991 | } | |
1992 | case id_disable_after_timeout: | |
1993 | { | |
1994 | g_config.disable_after_timeout = *value_data; | |
1995 | break; | |
1996 | } | |
1997 | case id_brightness: | |
1998 | { | |
1999 | g_config.brightness = *value_data; | |
2000 | break; | |
2001 | } | |
2002 | case id_effect: | |
2003 | { | |
2004 | g_config.effect = *value_data; | |
2005 | break; | |
2006 | } | |
2007 | case id_effect_speed: | |
2008 | { | |
2009 | g_config.effect_speed = *value_data; | |
2010 | break; | |
2011 | } | |
2012 | case id_color_1: | |
2013 | { | |
2014 | _set_color( &(g_config.color_1), value_data ); | |
2015 | break; | |
2016 | } | |
2017 | case id_color_2: | |
2018 | { | |
2019 | _set_color( &(g_config.color_2), value_data ); | |
2020 | break; | |
2021 | } | |
2022 | case id_caps_lock_indicator_color: | |
2023 | { | |
2024 | _set_color( &(g_config.caps_lock_indicator.color), value_data ); | |
2025 | break; | |
2026 | } | |
2027 | case id_caps_lock_indicator_row_col: | |
2028 | { | |
2029 | backlight_set_indicator_index( &(g_config.caps_lock_indicator.index), value_data[0], value_data[1] ); | |
2030 | break; | |
2031 | } | |
2032 | case id_layer_1_indicator_color: | |
2033 | { | |
2034 | _set_color( &(g_config.layer_1_indicator.color), value_data ); | |
2035 | break; | |
2036 | } | |
2037 | case id_layer_1_indicator_row_col: | |
2038 | { | |
2039 | backlight_set_indicator_index( &(g_config.layer_1_indicator.index), value_data[0], value_data[1] ); | |
2040 | break; | |
2041 | } | |
2042 | case id_layer_2_indicator_color: | |
2043 | { | |
2044 | _set_color( &(g_config.layer_2_indicator.color), value_data ); | |
2045 | break; | |
2046 | } | |
2047 | case id_layer_2_indicator_row_col: | |
2048 | { | |
2049 | backlight_set_indicator_index( &(g_config.layer_2_indicator.index), value_data[0], value_data[1] ); | |
2050 | break; | |
2051 | } | |
2052 | case id_layer_3_indicator_color: | |
2053 | { | |
2054 | _set_color( &(g_config.layer_3_indicator.color), value_data ); | |
2055 | break; | |
2056 | } | |
2057 | case id_layer_3_indicator_row_col: | |
2058 | { | |
2059 | backlight_set_indicator_index( &(g_config.layer_3_indicator.index), value_data[0], value_data[1] ); | |
2060 | break; | |
2061 | } | |
2062 | case id_alphas_mods: | |
2063 | { | |
2064 | for ( int i=0; i<5; i++ ) | |
2065 | { | |
2066 | g_config.alphas_mods[i] = ( *(value_data+i*2) << 8 ) | ( *(value_data+i*2+1) ); | |
2067 | } | |
2068 | } | |
d7f1e072 | 2069 | #if defined(RGB_BACKLIGHT_M6_B) |
acd3e79a | 2070 | case id_custom_color: |
2071 | { | |
2072 | uint8_t index = value_data[0]; | |
2073 | if ( index >= 0 && index <= 6 ) | |
2074 | { | |
2075 | _set_color( &(g_config.custom_color[index]), &(value_data[1]) ); | |
2076 | } | |
2077 | } | |
d7f1e072 | 2078 | #endif |
acd3e79a | 2079 | } |
48a992f1 | 2080 | |
acd3e79a | 2081 | if ( reinitialize ) |
2082 | { | |
2083 | backlight_init_drivers(); | |
2084 | } | |
48a992f1 W |
2085 | } |
2086 | ||
2087 | void backlight_config_get_value( uint8_t *data ) | |
2088 | { | |
acd3e79a | 2089 | uint8_t *value_id = &(data[0]); |
2090 | uint8_t *value_data = &(data[1]); | |
2091 | switch ( *value_id ) | |
2092 | { | |
2093 | case id_use_split_backspace: | |
2094 | { | |
2095 | *value_data = ( g_config.use_split_backspace ? 1 : 0 ); | |
2096 | break; | |
2097 | } | |
2098 | case id_use_split_left_shift: | |
2099 | { | |
2100 | *value_data = ( g_config.use_split_left_shift ? 1 : 0 ); | |
2101 | break; | |
2102 | } | |
2103 | case id_use_split_right_shift: | |
2104 | { | |
2105 | *value_data = ( g_config.use_split_right_shift ? 1 : 0 ); | |
2106 | break; | |
2107 | } | |
2108 | case id_use_7u_spacebar: | |
2109 | { | |
2110 | *value_data = ( g_config.use_7u_spacebar ? 1 : 0 ); | |
2111 | break; | |
2112 | } | |
2113 | case id_use_iso_enter: | |
2114 | { | |
2115 | *value_data = ( g_config.use_iso_enter ? 1 : 0 ); | |
2116 | break; | |
2117 | } | |
2118 | case id_disable_when_usb_suspended: | |
2119 | { | |
2120 | *value_data = ( g_config.disable_when_usb_suspended ? 1 : 0 ); | |
2121 | break; | |
2122 | } | |
2123 | case id_disable_hhkb_blocker_leds: | |
2124 | { | |
2125 | *value_data = ( g_config.disable_hhkb_blocker_leds ? 1 : 0 ); | |
2126 | break; | |
2127 | } | |
2128 | case id_disable_after_timeout: | |
2129 | { | |
2130 | *value_data = g_config.disable_after_timeout; | |
2131 | break; | |
2132 | } | |
2133 | case id_brightness: | |
2134 | { | |
2135 | *value_data = g_config.brightness; | |
2136 | break; | |
2137 | } | |
2138 | case id_effect: | |
2139 | { | |
2140 | *value_data = g_config.effect; | |
2141 | break; | |
2142 | } | |
2143 | case id_effect_speed: | |
2144 | { | |
2145 | *value_data = g_config.effect_speed; | |
2146 | break; | |
2147 | } | |
2148 | case id_color_1: | |
2149 | { | |
2150 | _get_color( &(g_config.color_1), value_data ); | |
2151 | break; | |
2152 | } | |
2153 | case id_color_2: | |
2154 | { | |
2155 | _get_color( &(g_config.color_2), value_data ); | |
2156 | break; | |
2157 | } | |
2158 | case id_caps_lock_indicator_color: | |
2159 | { | |
2160 | _get_color( &(g_config.caps_lock_indicator.color), value_data ); | |
2161 | break; | |
2162 | } | |
2163 | case id_caps_lock_indicator_row_col: | |
2164 | { | |
2165 | backlight_get_indicator_row_col( g_config.caps_lock_indicator.index, &(value_data[0]), &(value_data[1]) ); | |
2166 | break; | |
2167 | } | |
2168 | case id_layer_1_indicator_color: | |
2169 | { | |
2170 | _get_color( &(g_config.layer_1_indicator.color), value_data ); | |
2171 | break; | |
2172 | } | |
2173 | case id_layer_1_indicator_row_col: | |
2174 | { | |
2175 | backlight_get_indicator_row_col( g_config.layer_1_indicator.index, &(value_data[0]), &(value_data[1]) ); | |
2176 | break; | |
2177 | } | |
2178 | case id_layer_2_indicator_color: | |
2179 | { | |
2180 | _get_color( &(g_config.layer_2_indicator.color), value_data ); | |
2181 | break; | |
2182 | } | |
2183 | case id_layer_2_indicator_row_col: | |
2184 | { | |
2185 | backlight_get_indicator_row_col( g_config.layer_2_indicator.index, &(value_data[0]), &(value_data[1]) ); | |
2186 | break; | |
2187 | } | |
2188 | case id_layer_3_indicator_color: | |
2189 | { | |
2190 | _get_color( &(g_config.layer_3_indicator.color), value_data ); | |
2191 | break; | |
2192 | } | |
2193 | case id_layer_3_indicator_row_col: | |
2194 | { | |
2195 | backlight_get_indicator_row_col( g_config.layer_3_indicator.index, &(value_data[0]), &(value_data[1]) ); | |
2196 | break; | |
2197 | } | |
2198 | case id_alphas_mods: | |
2199 | { | |
2200 | for ( int i=0; i<5; i++ ) | |
2201 | { | |
2202 | *(value_data+i*2) = g_config.alphas_mods[i] >> 8; | |
2203 | *(value_data+i*2+1) = g_config.alphas_mods[i] & 0xFF; | |
2204 | } | |
2205 | } | |
d7f1e072 | 2206 | #if defined(RGB_BACKLIGHT_M6_B) |
acd3e79a | 2207 | case id_custom_color: |
2208 | { | |
2209 | uint8_t index = value_data[0]; | |
2210 | if ( index >= 0 && index <= 6 ) | |
2211 | { | |
2212 | _get_color( &(g_config.custom_color[index]), &(value_data[1]) ); | |
2213 | } | |
2214 | } | |
d7f1e072 | 2215 | #endif |
acd3e79a | 2216 | } |
48a992f1 W |
2217 | } |
2218 | ||
2219 | void backlight_config_set_alphas_mods( uint16_t *alphas_mods ) | |
2220 | { | |
acd3e79a | 2221 | for ( int i=0; i<5; i++ ) |
2222 | { | |
2223 | g_config.alphas_mods[i] = alphas_mods[i]; | |
2224 | } | |
48a992f1 | 2225 | |
acd3e79a | 2226 | backlight_config_save(); |
48a992f1 W |
2227 | } |
2228 | ||
2229 | void backlight_config_load(void) | |
2230 | { | |
acd3e79a | 2231 | eeprom_read_block( &g_config, ((void*)RGB_BACKLIGHT_CONFIG_EEPROM_ADDR), sizeof(backlight_config) ); |
48a992f1 W |
2232 | } |
2233 | ||
2234 | void backlight_config_save(void) | |
2235 | { | |
acd3e79a | 2236 | eeprom_update_block( &g_config, ((void*)RGB_BACKLIGHT_CONFIG_EEPROM_ADDR), sizeof(backlight_config) ); |
48a992f1 W |
2237 | } |
2238 | ||
2239 | void backlight_init_drivers(void) | |
2240 | { | |
acd3e79a | 2241 | // Initialize I2C |
2242 | i2c_init(); | |
2dea540a W |
2243 | |
2244 | #if defined(RGB_BACKLIGHT_M6_B) | |
acd3e79a | 2245 | IS31FL3218_init(); |
2bfac351 | 2246 | #elif defined(RGB_BACKLIGHT_HS60) |
acd3e79a | 2247 | IS31FL3733_init( ISSI_ADDR_1, 0 ); |
2248 | ||
2249 | for ( int index = 0; index < DRIVER_LED_TOTAL; index++ ) | |
2250 | { | |
2251 | #if defined(HS60_ANSI) | |
2252 | bool enabled = !( ( index == 48-1 ) || //LA48 | |
2253 | ( index == 51-1 ) || //LA51 | |
2254 | ( index == 61-1 ) ); //LA61 | |
2255 | #elif defined(HS60_HHKB) | |
2256 | bool enabled = !( ( index == 61-1 ) || //LA61 | |
2257 | ( index == 62-1 ) ); //LA62 | |
2bfac351 | 2258 | #else //HS60_ISO |
acd3e79a | 2259 | bool enabled = !( ( index == 51-1 ) || //LA51 |
2260 | ( index == 61-1 ) ); //LA61 | |
2bfac351 | 2261 | #endif |
acd3e79a | 2262 | // This only caches it for later |
2263 | IS31FL3733_set_led_control_register( index, enabled, enabled, enabled ); | |
2264 | } | |
2265 | // This actually updates the LED drivers | |
2266 | IS31FL3733_update_led_control_registers( ISSI_ADDR_1, 0 ); | |
2267 | #elif defined(RGB_BACKLIGHT_NK65) | |
2268 | IS31FL3733_init( ISSI_ADDR_1, 0 ); | |
2269 | IS31FL3733_init( ISSI_ADDR_2, 0 ); | |
2270 | ||
2271 | for ( int index = 0; index < DRIVER_LED_TOTAL; index++ ) | |
2272 | { | |
2273 | bool enabled = !( ( index == 61-1 ) || //LA61 | |
2274 | ( index > 6+64-1 ) ); //LB7-LB64 | |
2275 | // This only caches it for later | |
2276 | IS31FL3733_set_led_control_register( index, enabled, enabled, enabled ); | |
2277 | } | |
2278 | IS31FL3733_set_led_control_register( 7+64-1, 0, 1, 0 ); //Enable LB7 green enable for indicators | |
2279 | // This actually updates the LED drivers | |
2280 | IS31FL3733_update_led_control_registers( ISSI_ADDR_1, 0 ); | |
2281 | IS31FL3733_update_led_control_registers( ISSI_ADDR_2, 1 ); | |
2dea540a | 2282 | #else |
acd3e79a | 2283 | IS31FL3731_init( ISSI_ADDR_1 ); |
2284 | IS31FL3731_init( ISSI_ADDR_2 ); | |
2285 | ||
bffbb4b4 W |
2286 | #if defined(RGB_BACKLIGHT_U80_A) |
2287 | IS31FL3731_init( ISSI_ADDR_3 ); | |
2288 | #endif | |
2289 | ||
2290 | // Experimental feature, not in configuration yet | |
2291 | #if defined(RGB_BACKLIGHT_ZEAL60) | |
2292 | bool disable_spacebar_stab_leds = false; | |
2293 | #endif | |
2294 | ||
acd3e79a | 2295 | for ( int index = 0; index < DRIVER_LED_TOTAL; index++ ) |
2296 | { | |
2297 | // OR the possible "disabled" cases together, then NOT the result to get the enabled state | |
2298 | // LC6 LD13 not present on Zeal65 | |
2299 | #if defined(RGB_BACKLIGHT_ZEAL65) | |
2300 | bool enabled = !( ( index == 18+5 && !g_config.use_split_backspace ) || // LB5 | |
2301 | ( index == 36+6 ) || // LC6 | |
2302 | ( index == 54+13 ) ); // LD13 | |
2303 | #elif defined(RGB_BACKLIGHT_KOYU) | |
2304 | bool enabled = !( ( index == 36+15 ) || // LC15 | |
2305 | ( index == 54+13 ) || // LD13 | |
2306 | ( index == 54+17 ) ); // LD17 | |
2307 | #elif defined(RGB_BACKLIGHT_M60_A) | |
2308 | bool enabled = !( | |
2309 | // LB6 LB7 LB8 LB15 LB16 LB17 not present on M60-A | |
2310 | ( index == 18+6 ) || // LB6 | |
2311 | ( index == 18+7 ) || // LB7 | |
2312 | ( index == 18+8 ) || // LB8 | |
2313 | ( index == 18+15 ) || // LB15 | |
2314 | ( index == 18+16 ) || // LB16 | |
2315 | ( index == 18+17 ) || // LB17 | |
2316 | // HHKB blockers (LC17, LD17) and ISO extra keys (LC15,LD13) not present on M60-A | |
2317 | ( index == 36+17 ) || // LC17 | |
2318 | ( index == 54+17 ) || // LD17 | |
2319 | ( index == 36+15 ) || // LC15 | |
2320 | ( index == 54+13 ) ); // LD13 | |
2321 | #elif defined(RGB_BACKLIGHT_ZEAL60) | |
2322 | // LB6 LB7 LB8 LB15 LB16 LB17 not present on Zeal60 | |
2323 | bool enabled = !( ( index == 18+5 && !g_config.use_split_backspace ) || // LB5 | |
2324 | ( index == 36+15 && !g_config.use_split_left_shift ) || // LC15 | |
2325 | ( index == 54+8 && !g_config.use_split_right_shift ) || // LD8 | |
2326 | ( index == 54+13 && g_config.use_7u_spacebar ) || // LD13 | |
2327 | ( index == 36+17 && g_config.disable_hhkb_blocker_leds ) || // LC17 | |
2328 | ( index == 54+17 && g_config.disable_hhkb_blocker_leds ) || // LD17 | |
2329 | ( index == 18+6 ) || // LB6 | |
2330 | ( index == 18+7 ) || // LB7 | |
2331 | ( index == 18+8 ) || // LB8 | |
2332 | ( index == 18+15 ) || // LB15 | |
2333 | ( index == 18+16 ) || // LB16 | |
bffbb4b4 W |
2334 | ( index == 18+17 ) || // LB17 |
2335 | ( index == 36+6 && disable_spacebar_stab_leds ) || // LC6 | |
2336 | ( index == 54+13 && disable_spacebar_stab_leds ) || // LD13 | |
2337 | ( index == 54+14 && disable_spacebar_stab_leds && g_config.use_7u_spacebar ) ); // LD14 | |
2338 | #elif defined(RGB_BACKLIGHT_U80_A) | |
2339 | // LB5, LB6, LB7, LB8, LB15, LB16, LB17, LC15, LD8, LD13, LE0-LE8, LF13 | |
2340 | bool enabled = !( | |
2341 | ( index == 18+5 ) || // LB5 | |
2342 | ( index == 18+6 ) || // LB6 | |
2343 | ( index == 18+7 ) || // LB7 | |
2344 | ( index == 18+8 ) || // LB8 | |
2345 | ( index == 18+15 ) || // LB15 | |
2346 | ( index == 18+16 ) || // LB16 | |
2347 | ( index == 18+16 ) || // LB17 | |
2348 | ( index == 36+15 ) || // LC15 | |
2349 | ( index == 54+8 ) || // LD8 | |
2350 | ( index == 54+13 ) || // LD13 | |
2351 | ( index >= 72+0 && index <= 72+8 ) || // LE0-LE8 | |
2352 | ( index == 90+13 ) ); // LF13 | |
2ce3025b X |
2353 | #elif defined(RGB_BACKLIGHT_DAWN60) |
2354 | bool enabled = !( ( index == 15+7 && !g_config.use_split_backspace ) || //other backspace | |
2355 | ( index == 47+13 && g_config.use_7u_spacebar ) || //LD13 | |
2356 | ( index == 47+15 && g_config.use_7u_spacebar ) ); //LD15 | |
48a992f1 | 2357 | #endif |
acd3e79a | 2358 | // This only caches it for later |
2359 | IS31FL3731_set_led_control_register( index, enabled, enabled, enabled ); | |
2360 | } | |
2361 | // This actually updates the LED drivers | |
bffbb4b4 W |
2362 | IS31FL3731_update_led_control_registers( ISSI_ADDR_1, 0 ); |
2363 | IS31FL3731_update_led_control_registers( ISSI_ADDR_2, 1 ); | |
2364 | #if defined(RGB_BACKLIGHT_U80_A) | |
2365 | IS31FL3731_update_led_control_registers( ISSI_ADDR_3, 2 ); | |
2366 | #endif | |
2dea540a | 2367 | #endif // !defined(RGB_BACKLIGHT_M6_B) |
48a992f1 | 2368 | |
acd3e79a | 2369 | // TODO: put the 1 second startup delay here? |
48a992f1 | 2370 | |
acd3e79a | 2371 | // clear the key hits |
2372 | for ( int led=0; led<BACKLIGHT_LED_COUNT; led++ ) | |
2373 | { | |
2374 | g_key_hit[led] = 255; | |
2375 | } | |
48a992f1 W |
2376 | } |
2377 | ||
2378 | bool process_record_backlight(uint16_t keycode, keyrecord_t *record) | |
2379 | { | |
acd3e79a | 2380 | // Record keypresses for backlight effects |
2381 | if ( record->event.pressed ) | |
2382 | { | |
2383 | backlight_set_key_hit( record->event.key.row, record->event.key.col ); | |
2384 | } | |
2385 | ||
2386 | switch(keycode) | |
2387 | { | |
2388 | case BR_INC: | |
2389 | if (record->event.pressed) | |
2390 | { | |
2391 | backlight_brightness_increase(); | |
2392 | } | |
2393 | return false; | |
2394 | break; | |
2395 | case BR_DEC: | |
2396 | if (record->event.pressed) | |
2397 | { | |
2398 | backlight_brightness_decrease(); | |
2399 | } | |
2400 | return false; | |
2401 | break; | |
2402 | case EF_INC: | |
2403 | if (record->event.pressed) | |
2404 | { | |
2405 | backlight_effect_increase(); | |
2406 | } | |
2407 | return false; | |
2408 | break; | |
2409 | case EF_DEC: | |
2410 | if (record->event.pressed) | |
2411 | { | |
2412 | backlight_effect_decrease(); | |
2413 | } | |
2414 | return false; | |
2415 | break; | |
2416 | case ES_INC: | |
2417 | if (record->event.pressed) | |
2418 | { | |
2419 | backlight_effect_speed_increase(); | |
2420 | } | |
2421 | return false; | |
2422 | break; | |
2423 | case ES_DEC: | |
2424 | if (record->event.pressed) | |
2425 | { | |
2426 | backlight_effect_speed_decrease(); | |
2427 | } | |
2428 | return false; | |
2429 | break; | |
2430 | case H1_INC: | |
2431 | if (record->event.pressed) | |
2432 | { | |
2433 | backlight_color_1_hue_increase(); | |
2434 | } | |
2435 | return false; | |
2436 | break; | |
2437 | case H1_DEC: | |
2438 | if (record->event.pressed) | |
2439 | { | |
2440 | backlight_color_1_hue_decrease(); | |
2441 | } | |
2442 | return false; | |
2443 | break; | |
2444 | case S1_INC: | |
2445 | if (record->event.pressed) | |
2446 | { | |
2447 | backlight_color_1_sat_increase(); | |
2448 | } | |
2449 | return false; | |
2450 | break; | |
2451 | case S1_DEC: | |
2452 | if (record->event.pressed) | |
2453 | { | |
2454 | backlight_color_1_sat_decrease(); | |
2455 | break; | |
2456 | } | |
2457 | return false; | |
2458 | break; | |
2459 | case H2_INC: | |
2460 | if (record->event.pressed) | |
2461 | { | |
2462 | backlight_color_2_hue_increase(); | |
2463 | } | |
2464 | return false; | |
2465 | break; | |
2466 | case H2_DEC: | |
2467 | if (record->event.pressed) | |
2468 | { | |
2469 | backlight_color_2_hue_decrease(); | |
2470 | } | |
2471 | return false; | |
2472 | break; | |
2473 | case S2_INC: | |
2474 | if (record->event.pressed) | |
2475 | { | |
2476 | backlight_color_2_sat_increase(); | |
2477 | } | |
2478 | return false; | |
2479 | break; | |
2480 | case S2_DEC: | |
2481 | if (record->event.pressed) | |
2482 | { | |
2483 | backlight_color_2_sat_decrease(); | |
2484 | break; | |
2485 | } | |
2486 | return false; | |
2487 | break; | |
2488 | } | |
2489 | ||
2490 | return true; | |
48a992f1 W |
2491 | } |
2492 | ||
2493 | // Deals with the messy details of incrementing an integer | |
2494 | uint8_t increment( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) | |
2495 | { | |
acd3e79a | 2496 | int16_t new_value = value; |
2497 | new_value += step; | |
2498 | return MIN( MAX( new_value, min ), max ); | |
48a992f1 W |
2499 | } |
2500 | ||
2501 | uint8_t decrement( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) | |
2502 | { | |
acd3e79a | 2503 | int16_t new_value = value; |
2504 | new_value -= step; | |
2505 | return MIN( MAX( new_value, min ), max ); | |
48a992f1 W |
2506 | } |
2507 | ||
2508 | void backlight_effect_increase(void) | |
2509 | { | |
acd3e79a | 2510 | g_config.effect = increment( g_config.effect, 1, 0, BACKLIGHT_EFFECT_MAX ); |
2511 | backlight_config_save(); | |
48a992f1 W |
2512 | } |
2513 | ||
2514 | void backlight_effect_decrease(void) | |
2515 | { | |
acd3e79a | 2516 | g_config.effect = decrement( g_config.effect, 1, 0, BACKLIGHT_EFFECT_MAX ); |
2517 | backlight_config_save(); | |
48a992f1 W |
2518 | } |
2519 | ||
2520 | void backlight_effect_speed_increase(void) | |
2521 | { | |
acd3e79a | 2522 | g_config.effect_speed = increment( g_config.effect_speed, 1, 0, 3 ); |
2523 | backlight_config_save(); | |
48a992f1 W |
2524 | } |
2525 | ||
2526 | void backlight_effect_speed_decrease(void) | |
2527 | { | |
acd3e79a | 2528 | g_config.effect_speed = decrement( g_config.effect_speed, 1, 0, 3 ); |
2529 | backlight_config_save(); | |
48a992f1 W |
2530 | } |
2531 | ||
2532 | void backlight_brightness_increase(void) | |
2533 | { | |
acd3e79a | 2534 | g_config.brightness = increment( g_config.brightness, 8, 0, 255 ); |
2535 | backlight_config_save(); | |
48a992f1 W |
2536 | } |
2537 | ||
2538 | void backlight_brightness_decrease(void) | |
2539 | { | |
acd3e79a | 2540 | g_config.brightness = decrement( g_config.brightness, 8, 0, 255 ); |
2541 | backlight_config_save(); | |
48a992f1 W |
2542 | } |
2543 | ||
2544 | void backlight_color_1_hue_increase(void) | |
2545 | { | |
acd3e79a | 2546 | g_config.color_1.h = increment( g_config.color_1.h, 8, 0, 255 ); |
2547 | backlight_config_save(); | |
48a992f1 W |
2548 | } |
2549 | ||
2550 | void backlight_color_1_hue_decrease(void) | |
2551 | { | |
acd3e79a | 2552 | g_config.color_1.h = decrement( g_config.color_1.h, 8, 0, 255 ); |
2553 | backlight_config_save(); | |
48a992f1 W |
2554 | } |
2555 | ||
2556 | void backlight_color_1_sat_increase(void) | |
2557 | { | |
acd3e79a | 2558 | g_config.color_1.s = increment( g_config.color_1.s, 8, 0, 255 ); |
2559 | backlight_config_save(); | |
48a992f1 W |
2560 | } |
2561 | ||
2562 | void backlight_color_1_sat_decrease(void) | |
2563 | { | |
acd3e79a | 2564 | g_config.color_1.s = decrement( g_config.color_1.s, 8, 0, 255 ); |
2565 | backlight_config_save(); | |
48a992f1 W |
2566 | } |
2567 | ||
2568 | void backlight_color_2_hue_increase(void) | |
2569 | { | |
acd3e79a | 2570 | g_config.color_2.h = increment( g_config.color_2.h, 8, 0, 255 ); |
2571 | backlight_config_save(); | |
48a992f1 W |
2572 | } |
2573 | ||
2574 | void backlight_color_2_hue_decrease(void) | |
2575 | { | |
acd3e79a | 2576 | g_config.color_2.h = decrement( g_config.color_2.h, 8, 0, 255 ); |
2577 | backlight_config_save(); | |
48a992f1 W |
2578 | } |
2579 | ||
2580 | void backlight_color_2_sat_increase(void) | |
2581 | { | |
acd3e79a | 2582 | g_config.color_2.s = increment( g_config.color_2.s, 8, 0, 255 ); |
2583 | backlight_config_save(); | |
48a992f1 W |
2584 | } |
2585 | ||
2586 | void backlight_color_2_sat_decrease(void) | |
2587 | { | |
acd3e79a | 2588 | g_config.color_2.s = decrement( g_config.color_2.s, 8, 0, 255 ); |
2589 | backlight_config_save(); | |
48a992f1 W |
2590 | } |
2591 | ||
2dea540a | 2592 | #if defined(RGB_DEBUGGING_ONLY) |
48a992f1 W |
2593 | void backlight_test_led( uint8_t index, bool red, bool green, bool blue ) |
2594 | { | |
acd3e79a | 2595 | for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ ) |
2596 | { | |
2597 | if ( i == index ) | |
2598 | { | |
2599 | IS31FL3731_set_led_control_register( i, red, green, blue ); | |
2600 | } | |
2601 | else | |
2602 | { | |
2603 | IS31FL3731_set_led_control_register( i, false, false, false ); | |
2604 | } | |
2605 | } | |
48a992f1 W |
2606 | } |
2607 | ||
2608 | void backlight_debug_led( bool state ) | |
2609 | { | |
acd3e79a | 2610 | if (state) |
2611 | { | |
2612 | // Output high. | |
2613 | DDRE |= (1<<6); | |
2614 | PORTE |= (1<<6); | |
2615 | } | |
2616 | else | |
2617 | { | |
2618 | // Output low. | |
2619 | DDRE &= ~(1<<6); | |
2620 | PORTE &= ~(1<<6); | |
2621 | } | |
48a992f1 | 2622 | } |
2bfac351 | 2623 | #endif // defined(RGB_DEBUGGING_ONLY) |
48a992f1 | 2624 | |
2ce3025b | 2625 |