1 /* Copyright 2017 Jason Williams (Wilba)
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.
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.
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/>.
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)
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
23 #define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
27 #define MIN(a,b) ((a) < (b)? (a): (b))
31 #include "wt_rgb_backlight.h"
32 #include "wt_rgb_backlight_api.h"
33 #include "wt_rgb_backlight_keycodes.h"
35 #if !defined(RGB_BACKLIGHT_HS60) && !defined(RGB_BACKLIGHT_NK65)
37 #include <util/delay.h>
38 #include <avr/interrupt.h>
39 #include "drivers/avr/i2c_master.h"
43 #include "drivers/arm/i2c_master.h"
44 #include "tmk_core/common/eeprom.h"
47 #include "quantum/color.h"
49 #if defined(RGB_BACKLIGHT_M6_B)
50 #include "drivers/issi/is31fl3218.h"
51 #define BACKLIGHT_LED_COUNT 6
52 #elif defined(RGB_BACKLIGHT_HS60)
53 #include "drivers/issi/is31fl3733.h"
54 #define BACKLIGHT_LED_COUNT 64
55 #elif defined(RGB_BACKLIGHT_NK65)
56 #include "drivers/issi/is31fl3733.h"
57 #define BACKLIGHT_LED_COUNT 69
59 #include "drivers/issi/is31fl3731.h"
60 #if defined(RGB_BACKLIGHT_U80_A)
61 #define BACKLIGHT_LED_COUNT 108
63 #define BACKLIGHT_LED_COUNT 72
67 #define BACKLIGHT_EFFECT_MAX 10
69 backlight_config g_config = {
70 .use_split_backspace = RGB_BACKLIGHT_USE_SPLIT_BACKSPACE,
71 .use_split_left_shift = RGB_BACKLIGHT_USE_SPLIT_LEFT_SHIFT,
72 .use_split_right_shift = RGB_BACKLIGHT_USE_SPLIT_RIGHT_SHIFT,
73 .use_7u_spacebar = RGB_BACKLIGHT_USE_7U_SPACEBAR,
74 .use_iso_enter = RGB_BACKLIGHT_USE_ISO_ENTER,
75 .disable_hhkb_blocker_leds = RGB_BACKLIGHT_DISABLE_HHKB_BLOCKER_LEDS,
76 .disable_when_usb_suspended = RGB_BACKLIGHT_DISABLE_WHEN_USB_SUSPENDED,
77 .disable_after_timeout = RGB_BACKLIGHT_DISABLE_AFTER_TIMEOUT,
78 .brightness = RGB_BACKLIGHT_BRIGHTNESS,
79 .effect = RGB_BACKLIGHT_EFFECT,
80 .effect_speed = RGB_BACKLIGHT_EFFECT_SPEED,
81 .color_1 = RGB_BACKLIGHT_COLOR_1,
82 .color_2 = RGB_BACKLIGHT_COLOR_2,
83 .caps_lock_indicator = RGB_BACKLIGHT_CAPS_LOCK_INDICATOR,
84 .layer_1_indicator = RGB_BACKLIGHT_LAYER_1_INDICATOR,
85 .layer_2_indicator = RGB_BACKLIGHT_LAYER_2_INDICATOR,
86 .layer_3_indicator = RGB_BACKLIGHT_LAYER_3_INDICATOR,
88 RGB_BACKLIGHT_ALPHAS_MODS_ROW_0,
89 RGB_BACKLIGHT_ALPHAS_MODS_ROW_1,
90 RGB_BACKLIGHT_ALPHAS_MODS_ROW_2,
91 RGB_BACKLIGHT_ALPHAS_MODS_ROW_3,
92 RGB_BACKLIGHT_ALPHAS_MODS_ROW_4 },
93 #if defined(RGB_BACKLIGHT_M6_B)
94 .custom_color = { { 0, 255 }, { 43, 255 }, { 85, 255 }, { 128, 255 }, { 171, 255 }, { 213, 255 } }
98 bool g_suspend_state = false;
99 uint8_t g_indicator_state = 0;
101 // Global tick at 20 Hz
104 // Ticks since this key was last hit.
105 uint8_t g_key_hit[BACKLIGHT_LED_COUNT];
107 // Ticks since any key was last hit.
108 uint32_t g_any_key_hit = 0;
110 #if defined(RGB_BACKLIGHT_HS60)
112 // This is a 7-bit address, that gets left-shifted and bit 0
113 // set to 0 for write, 1 for read (as per I2C protocol)
114 // ADDR_2 is not needed. it is here as a dummy
115 #define ISSI_ADDR_1 0x50
117 const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
118 /* Refer to IS31 manual for these locations
124 {0, B_1, A_1, C_1}, //LA1
125 {0, E_1, D_1, F_1}, //LA2
126 {0, H_1, G_1, I_1}, //LA3
127 {0, K_1, J_1, L_1}, //LA4
128 {0, B_2, A_2, C_2}, //LA5
129 {0, E_2, D_2, F_2}, //LA6
130 {0, H_2, G_2, I_2}, //LA7
131 {0, K_2, J_2, L_2}, //LA8
132 {0, B_3, A_3, C_3}, //LA9
133 {0, E_3, D_3, F_3}, //LA10
134 {0, H_3, G_3, I_3}, //LA11
135 {0, K_3, J_3, L_3}, //LA12
136 {0, B_4, A_4, C_4}, //LA13
137 {0, E_4, D_4, F_4}, //LA14
138 {0, H_4, G_4, I_4}, //LA15
139 {0, K_4, J_4, L_4}, //LA16
140 {0, B_5, A_5, C_5}, //LA17
141 {0, E_5, D_5, F_5}, //LA18
142 {0, H_5, G_5, I_5}, //LA19
143 {0, K_5, J_5, L_5}, //LA20
144 {0, B_6, A_6, C_6}, //LA21
145 {0, E_6, D_6, F_6}, //LA22
146 {0, H_6, G_6, I_6}, //LA23
147 {0, K_6, J_6, L_6}, //LA24
148 {0, B_7, A_7, C_7}, //LA25
149 {0, E_7, D_7, F_7}, //LA26
150 {0, H_7, G_7, I_7}, //LA27
151 {0, K_7, J_7, L_7}, //LA28
152 {0, B_8, A_8, C_8}, //LA29
153 {0, E_8, D_8, F_8}, //LA30
154 {0, H_8, G_8, I_8}, //LA31
155 {0, K_8, J_8, L_8}, //LA32
156 {0, B_9, A_9, C_9}, //LA33
157 {0, E_9, D_9, F_9}, //LA34
158 {0, H_9, G_9, I_9}, //LA35
159 {0, K_9, J_9, L_9}, //LA36
160 {0, B_10, A_10, C_10}, //LA37
161 {0, E_10, D_10, F_10}, //LA38
162 {0, H_10, G_10, I_10}, //LA39
163 {0, K_10, J_10, L_10}, //LA40
164 {0, B_11, A_11, C_11}, //LA41
165 {0, E_11, D_11, F_11}, //LA42
166 {0, H_11, G_11, I_11}, //LA43
167 {0, K_11, J_11, L_11}, //LA44
168 {0, B_12, A_12, C_12}, //LA45
169 {0, E_12, D_12, F_12}, //LA46
170 {0, H_12, G_12, I_12}, //LA47
171 {0, K_12, J_12, L_12}, //LA48
172 {0, B_13, A_13, C_13}, //LA49
173 {0, E_13, D_13, F_13}, //LA50
174 {0, H_13, G_13, I_13}, //LA51
175 {0, K_13, J_13, L_13}, //LA52
176 {0, B_14, A_14, C_14}, //LA53
177 {0, E_14, D_14, F_14}, //LA54
178 {0, H_14, G_14, I_14}, //LA55
179 {0, K_14, J_14, L_14}, //LA56
180 {0, B_15, A_15, C_15}, //LA57
181 {0, E_15, D_15, F_15}, //LA58
182 {0, H_15, G_15, I_15}, //LA59
183 {0, K_15, J_15, L_15}, //LA60
184 {0, B_16, A_16, C_16}, //LA61
185 {0, E_16, D_16, F_16}, //LA62
186 {0, H_16, G_16, I_16}, //LA63
187 {0, K_16, J_16, L_16}, //LA64
190 #elif defined(RGB_BACKLIGHT_NK65)
192 // This is a 7-bit address, that gets left-shifted and bit 0
193 // set to 0 for write, 1 for read (as per I2C protocol)
194 // ADDR_2 is not needed. it is here as a dummy
195 #define ISSI_ADDR_1 0x50
196 #define ISSI_ADDR_2 0x52
198 const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
199 /* Refer to IS31 manual for these locations
205 {0, B_1, A_1, C_1}, //LA1
206 {0, E_1, D_1, F_1}, //LA2
207 {0, H_1, G_1, I_1}, //LA3
208 {0, K_1, J_1, L_1}, //LA4
209 {0, B_2, A_2, C_2}, //LA5
210 {0, E_2, D_2, F_2}, //LA6
211 {0, H_2, G_2, I_2}, //LA7
212 {0, K_2, J_2, L_2}, //LA8
213 {0, B_3, A_3, C_3}, //LA9
214 {0, E_3, D_3, F_3}, //LA10
215 {0, H_3, G_3, I_3}, //LA11
216 {0, K_3, J_3, L_3}, //LA12
217 {0, B_4, A_4, C_4}, //LA13
218 {0, E_4, D_4, F_4}, //LA14
219 {0, H_4, G_4, I_4}, //LA15
220 {0, K_4, J_4, L_4}, //LA16
221 {0, B_5, A_5, C_5}, //LA17
222 {0, E_5, D_5, F_5}, //LA18
223 {0, H_5, G_5, I_5}, //LA19
224 {0, K_5, J_5, L_5}, //LA20
225 {0, B_6, A_6, C_6}, //LA21
226 {0, E_6, D_6, F_6}, //LA22
227 {0, H_6, G_6, I_6}, //LA23
228 {0, K_6, J_6, L_6}, //LA24
229 {0, B_7, A_7, C_7}, //LA25
230 {0, E_7, D_7, F_7}, //LA26
231 {0, H_7, G_7, I_7}, //LA27
232 {0, K_7, J_7, L_7}, //LA28
233 {0, B_8, A_8, C_8}, //LA29
234 {0, E_8, D_8, F_8}, //LA30
235 {0, H_8, G_8, I_8}, //LA31
236 {0, K_8, J_8, L_8}, //LA32
237 {0, B_9, A_9, C_9}, //LA33
238 {0, E_9, D_9, F_9}, //LA34
239 {0, H_9, G_9, I_9}, //LA35
240 {0, K_9, J_9, L_9}, //LA36
241 {0, B_10, A_10, C_10}, //LA37
242 {0, E_10, D_10, F_10}, //LA38
243 {0, H_10, G_10, I_10}, //LA39
244 {0, K_10, J_10, L_10}, //LA40
245 {0, B_11, A_11, C_11}, //LA41
246 {0, E_11, D_11, F_11}, //LA42
247 {0, H_11, G_11, I_11}, //LA43
248 {0, K_11, J_11, L_11}, //LA44
249 {0, B_12, A_12, C_12}, //LA45
250 {0, E_12, D_12, F_12}, //LA46
251 {0, H_12, G_12, I_12}, //LA47
252 {0, K_12, J_12, L_12}, //LA48
253 {0, B_13, A_13, C_13}, //LA49
254 {0, E_13, D_13, F_13}, //LA50
255 {0, H_13, G_13, I_13}, //LA51
256 {0, K_13, J_13, L_13}, //LA52
257 {0, B_14, A_14, C_14}, //LA53
258 {0, E_14, D_14, F_14}, //LA54
259 {0, H_14, G_14, I_14}, //LA55
260 {0, K_14, J_14, L_14}, //LA56
261 {0, B_15, A_15, C_15}, //LA57
262 {0, E_15, D_15, F_15}, //LA58
263 {0, H_15, G_15, I_15}, //LA59
264 {0, K_15, J_15, L_15}, //LA60
265 {0, B_16, A_16, C_16}, //LA61
266 {0, E_16, D_16, F_16}, //LA62
267 {0, H_16, G_16, I_16}, //LA63
268 {0, K_16, J_16, L_16}, //LA64
270 {1, B_1, A_1, C_1}, //LB1
271 {1, E_1, D_1, F_1}, //LB2
272 {1, H_1, G_1, I_1}, //LB3
273 {1, K_1, J_1, L_1}, //LB4
274 {1, B_2, A_2, C_2}, //LB5
275 {1, E_2, D_2, F_2}, //LB6
276 {1, H_2, G_2, I_2}, //LB7
277 {1, K_2, J_2, L_2}, //LB8
278 {1, B_3, A_3, C_3}, //LB9
279 {1, E_3, D_3, F_3}, //LB10
280 {1, H_3, G_3, I_3}, //LB11
281 {1, K_3, J_3, L_3}, //LB12
282 {1, B_4, A_4, C_4}, //LB13
283 {1, E_4, D_4, F_4}, //LB14
284 {1, H_4, G_4, I_4}, //LB15
285 {1, K_4, J_4, L_4}, //LB16
286 {1, B_5, A_5, C_5}, //LB17
287 {1, E_5, D_5, F_5}, //LB18
288 {1, H_5, G_5, I_5}, //LB19
289 {1, K_5, J_5, L_5}, //LB20
290 {1, B_6, A_6, C_6}, //LB21
291 {1, E_6, D_6, F_6}, //LB22
292 {1, H_6, G_6, I_6}, //LB23
293 {1, K_6, J_6, L_6}, //LB24
294 {1, B_7, A_7, C_7}, //LB25
295 {1, E_7, D_7, F_7}, //LB26
296 {1, H_7, G_7, I_7}, //LB27
297 {1, K_7, J_7, L_7}, //LB28
298 {1, B_8, A_8, C_8}, //LB29
299 {1, E_8, D_8, F_8}, //LB30
300 {1, H_8, G_8, I_8}, //LB31
301 {1, K_8, J_8, L_8}, //LB32
302 {1, B_9, A_9, C_9}, //LB33
303 {1, E_9, D_9, F_9}, //LB34
304 {1, H_9, G_9, I_9}, //LB35
305 {1, K_9, J_9, L_9}, //LB36
306 {1, B_10, A_10, C_10}, //LB37
307 {1, E_10, D_10, F_10}, //LB38
308 {1, H_10, G_10, I_10}, //LB39
309 {1, K_10, J_10, L_10}, //LB40
310 {1, B_11, A_11, C_11}, //LB41
311 {1, E_11, D_11, F_11}, //LB42
312 {1, H_11, G_11, I_11}, //LB43
313 {1, K_11, J_11, L_11}, //LB44
314 {1, B_12, A_12, C_12}, //LB45
315 {1, E_12, D_12, F_12}, //LB46
316 {1, H_12, G_12, I_12}, //LB47
317 {1, K_12, J_12, L_12}, //LB48
318 {1, B_13, A_13, C_13}, //LB49
319 {1, E_13, D_13, F_13}, //LB50
320 {1, H_13, G_13, I_13}, //LB51
321 {1, K_13, J_13, L_13}, //LB52
322 {1, B_14, A_14, C_14}, //LB53
323 {1, E_14, D_14, F_14}, //LB54
324 {1, H_14, G_14, I_14}, //LB55
325 {1, K_14, J_14, L_14}, //LB56
326 {1, B_15, A_15, C_15}, //LB57
327 {1, E_15, D_15, F_15}, //LB58
328 {1, H_15, G_15, I_15}, //LB59
329 {1, K_15, J_15, L_15}, //LB60
330 {1, B_16, A_16, C_16}, //LB61
331 {1, E_16, D_16, F_16}, //LB62
332 {1, H_16, G_16, I_16}, //LB63
333 {1, K_16, J_16, L_16}, //LB64
336 #elif defined(RGB_BACKLIGHT_U80_A)
338 // U80-A prototype uses 3 ISSI drivers
339 #define ISSI_ADDR_1 0x74 // 11101[00] <- GND
340 #define ISSI_ADDR_2 0x76 // 11101[10] <- SDA
341 #define ISSI_ADDR_3 0x75 // 11101[01] <- SCL
343 const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
344 /* Refer to IS31 manual for these locations
350 {0, C2_1, C3_1, C4_1}, // LA0
351 {0, C1_1, C3_2, C4_2}, // LA1
352 {0, C1_2, C2_2, C4_3}, // LA2
353 {0, C1_3, C2_3, C3_3}, // LA3
354 {0, C1_4, C2_4, C3_4}, // LA4
355 {0, C1_5, C2_5, C3_5}, // LA5
356 {0, C1_6, C2_6, C3_6}, // LA6
357 {0, C1_7, C2_7, C3_7}, // LA7
358 {0, C1_8, C2_8, C3_8}, // LA8
359 {0, C9_1, C8_1, C7_1}, // LA9
360 {0, C9_2, C8_2, C7_2}, // LA10
361 {0, C9_3, C8_3, C7_3}, // LA11
362 {0, C9_4, C8_4, C7_4}, // LA12
363 {0, C9_5, C8_5, C7_5}, // LA13
364 {0, C9_6, C8_6, C7_6}, // LA14
365 {0, C9_7, C8_7, C6_6}, // LA15
366 {0, C9_8, C7_7, C6_7}, // LA16
367 {0, C8_8, C7_8, C6_8}, // LA17
369 {0, C2_9, C3_9, C4_9}, // LB0
370 {0, C1_9, C3_10, C4_10}, // LB1
371 {0, C1_10, C2_10, C4_11}, // LB2
372 {0, C1_11, C2_11, C3_11}, // LB3
373 {0, C1_12, C2_12, C3_12}, // LB4
374 {0, C1_13, C2_13, C3_13}, // LB5
375 {0, C1_14, C2_14, C3_14}, // LB6
376 {0, C1_15, C2_15, C3_15}, // LB7
377 {0, C1_16, C2_16, C3_16}, // LB8
378 {0, C9_9, C8_9, C7_9}, // LB9
379 {0, C9_10, C8_10, C7_10}, // LB10
380 {0, C9_11, C8_11, C7_11}, // LB11
381 {0, C9_12, C8_12, C7_12}, // LB12
382 {0, C9_13, C8_13, C7_13}, // LB13
383 {0, C9_14, C8_14, C7_14}, // LB14
384 {0, C9_15, C8_15, C6_14}, // LB15
385 {0, C9_16, C7_15, C6_15}, // LB16
386 {0, C8_16, C7_16, C6_16}, // LB17
388 {1, C2_1, C3_1, C4_1}, // LC0
389 {1, C1_1, C3_2, C4_2}, // LC1
390 {1, C1_2, C2_2, C4_3}, // LC2
391 {1, C1_3, C2_3, C3_3}, // LC3
392 {1, C1_4, C2_4, C3_4}, // LC4
393 {1, C1_5, C2_5, C3_5}, // LC5
394 {1, C1_6, C2_6, C3_6}, // LC6
395 {1, C1_7, C2_7, C3_7}, // LC7
396 {1, C1_8, C2_8, C3_8}, // LC8
397 {1, C9_1, C8_1, C7_1}, // LC9
398 {1, C9_2, C8_2, C7_2}, // LC10
399 {1, C9_3, C8_3, C7_3}, // LC11
400 {1, C9_4, C8_4, C7_4}, // LC12
401 {1, C9_5, C8_5, C7_5}, // LC13
402 {1, C9_6, C8_6, C7_6}, // LC14
403 {1, C9_7, C8_7, C6_6}, // LC15
404 {1, C9_8, C7_7, C6_7}, // LC16
405 {1, C8_8, C7_8, C6_8}, // LC17
407 {1, C2_9, C3_9, C4_9}, // LD0
408 {1, C1_9, C3_10, C4_10}, // LD1
409 {1, C1_10, C2_10, C4_11}, // LD2
410 {1, C1_11, C2_11, C3_11}, // LD3
411 {1, C1_12, C2_12, C3_12}, // LD4
412 {1, C1_13, C2_13, C3_13}, // LD5
413 {1, C1_14, C2_14, C3_14}, // LD6
414 {1, C1_15, C2_15, C3_15}, // LD7
415 {1, C1_16, C2_16, C3_16}, // LD8
416 {1, C9_9, C8_9, C7_9}, // LD9
417 {1, C9_10, C8_10, C7_10}, // LD10
418 {1, C9_11, C8_11, C7_11}, // LD11
419 {1, C9_12, C8_12, C7_12}, // LD12
420 {1, C9_13, C8_13, C7_13}, // LD13
421 {1, C9_14, C8_14, C7_14}, // LD14
422 {1, C9_15, C8_15, C6_14}, // LD15
423 {1, C9_16, C7_15, C6_15}, // LD16
424 {1, C8_16, C7_16, C6_16}, // LD17
426 {2, C2_1, C3_1, C4_1}, // LE0
427 {2, C1_1, C3_2, C4_2}, // LE1
428 {2, C1_2, C2_2, C4_3}, // LE2
429 {2, C1_3, C2_3, C3_3}, // LE3
430 {2, C1_4, C2_4, C3_4}, // LE4
431 {2, C1_5, C2_5, C3_5}, // LE5
432 {2, C1_6, C2_6, C3_6}, // LE6
433 {2, C1_7, C2_7, C3_7}, // LE7
434 {2, C1_8, C2_8, C3_8}, // LE8
435 {2, C9_1, C8_1, C7_1}, // LE9
436 {2, C9_2, C8_2, C7_2}, // LE10
437 {2, C9_3, C8_3, C7_3}, // LE11
438 {2, C9_4, C8_4, C7_4}, // LE12
439 {2, C9_5, C8_5, C7_5}, // LE13
440 {2, C9_6, C8_6, C7_6}, // LE14
441 {2, C9_7, C8_7, C6_6}, // LE15
442 {2, C9_8, C7_7, C6_7}, // LE16
443 {2, C8_8, C7_8, C6_8}, // LE17
445 {2, C2_9, C3_9, C4_9}, // LF0
446 {2, C1_9, C3_10, C4_10}, // LF1
447 {2, C1_10, C2_10, C4_11}, // LF2
448 {2, C1_11, C2_11, C3_11}, // LF3
449 {2, C1_12, C2_12, C3_12}, // LF4
450 {2, C1_13, C2_13, C3_13}, // LF5
451 {2, C1_14, C2_14, C3_14}, // LF6
452 {2, C1_15, C2_15, C3_15}, // LF7
453 {2, C1_16, C2_16, C3_16}, // LF8
454 {2, C9_9, C8_9, C7_9}, // LF9
455 {2, C9_10, C8_10, C7_10}, // LF10
456 {2, C9_11, C8_11, C7_11}, // LF11
457 {2, C9_12, C8_12, C7_12}, // LF12
458 {2, C9_13, C8_13, C7_13}, // LF13
459 {2, C9_14, C8_14, C7_14}, // LF14
460 {2, C9_15, C8_15, C6_14}, // LF15
461 {2, C9_16, C7_15, C6_15}, // LF16
462 {2, C8_16, C7_16, C6_16}, // LF17
464 #elif !defined(RGB_BACKLIGHT_M6_B)
465 // This is a 7-bit address, that gets left-shifted and bit 0
466 // set to 0 for write, 1 for read (as per I2C protocol)
467 #define ISSI_ADDR_1 0x74
468 #define ISSI_ADDR_2 0x76
470 const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
471 /* Refer to IS31 manual for these locations
477 {0, C2_1, C3_1, C4_1}, // LA0
478 {0, C1_1, C3_2, C4_2}, // LA1
479 {0, C1_2, C2_2, C4_3}, // LA2
480 {0, C1_3, C2_3, C3_3}, // LA3
481 {0, C1_4, C2_4, C3_4}, // LA4
482 {0, C1_5, C2_5, C3_5}, // LA5
483 {0, C1_6, C2_6, C3_6}, // LA6
484 {0, C1_7, C2_7, C3_7}, // LA7
485 {0, C1_8, C2_8, C3_8}, // LA8
486 {0, C9_1, C8_1, C7_1}, // LA9
487 {0, C9_2, C8_2, C7_2}, // LA10
488 {0, C9_3, C8_3, C7_3}, // LA11
489 {0, C9_4, C8_4, C7_4}, // LA12
490 {0, C9_5, C8_5, C7_5}, // LA13
491 {0, C9_6, C8_6, C7_6}, // LA14
492 {0, C9_7, C8_7, C6_6}, // LA15
493 {0, C9_8, C7_7, C6_7}, // LA16
494 {0, C8_8, C7_8, C6_8}, // LA17
496 {0, C2_9, C3_9, C4_9}, // LB0
497 {0, C1_9, C3_10, C4_10}, // LB1
498 {0, C1_10, C2_10, C4_11}, // LB2
499 {0, C1_11, C2_11, C3_11}, // LB3
500 {0, C1_12, C2_12, C3_12}, // LB4
501 {0, C1_13, C2_13, C3_13}, // LB5
502 {0, C1_14, C2_14, C3_14}, // LB6
503 {0, C1_15, C2_15, C3_15}, // LB7
504 {0, C1_16, C2_16, C3_16}, // LB8
505 {0, C9_9, C8_9, C7_9}, // LB9
506 {0, C9_10, C8_10, C7_10}, // LB10
507 {0, C9_11, C8_11, C7_11}, // LB11
508 {0, C9_12, C8_12, C7_12}, // LB12
509 {0, C9_13, C8_13, C7_13}, // LB13
510 {0, C9_14, C8_14, C7_14}, // LB14
511 {0, C9_15, C8_15, C6_14}, // LB15
512 {0, C9_16, C7_15, C6_15}, // LB16
513 {0, C8_16, C7_16, C6_16}, // LB17
515 {1, C2_1, C3_1, C4_1}, // LC0
516 {1, C1_1, C3_2, C4_2}, // LC1
517 {1, C1_2, C2_2, C4_3}, // LC2
518 {1, C1_3, C2_3, C3_3}, // LC3
519 {1, C1_4, C2_4, C3_4}, // LC4
520 {1, C1_5, C2_5, C3_5}, // LC5
521 {1, C1_6, C2_6, C3_6}, // LC6
522 {1, C1_7, C2_7, C3_7}, // LC7
523 {1, C1_8, C2_8, C3_8}, // LC8
524 {1, C9_1, C8_1, C7_1}, // LC9
525 {1, C9_2, C8_2, C7_2}, // LC10
526 {1, C9_3, C8_3, C7_3}, // LC11
527 {1, C9_4, C8_4, C7_4}, // LC12
528 {1, C9_5, C8_5, C7_5}, // LC13
529 {1, C9_6, C8_6, C7_6}, // LC14
530 {1, C9_7, C8_7, C6_6}, // LC15
531 {1, C9_8, C7_7, C6_7}, // LC16
532 {1, C8_8, C7_8, C6_8}, // LC17
534 {1, C2_9, C3_9, C4_9}, // LD0
535 {1, C1_9, C3_10, C4_10}, // LD1
536 {1, C1_10, C2_10, C4_11}, // LD2
537 {1, C1_11, C2_11, C3_11}, // LD3
538 {1, C1_12, C2_12, C3_12}, // LD4
539 {1, C1_13, C2_13, C3_13}, // LD5
540 {1, C1_14, C2_14, C3_14}, // LD6
541 {1, C1_15, C2_15, C3_15}, // LD7
542 {1, C1_16, C2_16, C3_16}, // LD8
543 {1, C9_9, C8_9, C7_9}, // LD9
544 {1, C9_10, C8_10, C7_10}, // LD10
545 {1, C9_11, C8_11, C7_11}, // LD11
546 {1, C9_12, C8_12, C7_12}, // LD12
547 {1, C9_13, C8_13, C7_13}, // LD13
548 {1, C9_14, C8_14, C7_14}, // LD14
549 {1, C9_15, C8_15, C6_14}, // LD15
550 {1, C9_16, C7_15, C6_15}, // LD16
551 {1, C8_16, C7_16, C6_16}, // LD17
553 #endif // !defined(RGB_BACKLIGHT_M6_B)
556 typedef struct Point {
562 // index in range 0..71 (LA0..LA17, LB0..LB17, LC0..LC17, LD0..LD17)
563 // point values in range x=0..224 y=0..64
564 // origin is center of top-left key (i.e Esc)
565 #if defined(RGB_BACKLIGHT_ZEAL65)
566 const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
568 {120,16}, {104,16}, {88,16}, {72,16}, {56,16}, {40,16}, {24,16}, {4,16}, {4,32},
569 {128,0}, {112,0}, {96,0}, {80,0}, {64,0}, {48,0}, {32,0}, {16,0}, {0,0},
571 {144,0}, {160,0}, {176,0}, {192,0}, {216,0}, {224,0}, {240,0}, {240,16}, {240,32},
572 {136,16}, {152,16}, {168,16}, {184,16}, {200,16}, {220,16}, {240,48}, {240,64}, {224,64},
574 {96,64}, {100,48}, {84,48}, {68,48}, {52,48}, {36,48}, {255,255}, {48,60}, {28,64},
575 {108,32}, {92,32}, {76,32}, {60,32}, {44,32}, {28,32}, {20,44}, {10,48}, {4,64},
577 {124,32}, {140,32}, {156,32}, {172,32}, {188,32}, {214,32}, {180,48}, {202,48}, {224,48},
578 {116,48}, {132,48}, {148,48}, {164,48}, {255,255}, {144,60}, {164,64}, {188,64}, {208,64}
580 const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
582 {64,128}, {75,132}, {84,145}, {91,164}, {97,187}, {102,213}, {105,242}, {109,255}, {128,243},
583 {61,255}, {67,255}, {72,255}, {77,255}, {82,255}, {86,255}, {90,255}, {93,255}, {96,255},
585 {56,255}, {51,255}, {46,255}, {42,255}, {37,255}, {35,255}, {32,255}, {19,255}, {0,255},
586 {53,132}, {44,145}, {37,164}, {31,187}, {26,213}, {22,249}, {237,255}, {224,255}, {221,255},
588 {184,255}, {179,135}, {170,149}, {163,169}, {157,193}, {153,220}, {255,255}, {167,255}, {165,255},
589 {128,26}, {128,60}, {128,94}, {128,128}, {128,162}, {128,196}, {145,233}, {148,255}, {161,255},
591 {0,9}, {0,43}, {0,77}, {0,111}, {0,145}, {0,201}, {224,181}, {230,217}, {235,255},
592 {189,128}, {200,131}, {210,141}, {218,159}, {255,255}, {201,228}, {206,255}, {213,255}, {218,255}
594 #elif defined(RGB_BACKLIGHT_KOYU)
595 const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
597 {120,16}, {104,16}, {88,16}, {72,16}, {56,16}, {40,16}, {24,16}, {4,16}, {4,32},
598 {128,0}, {112,0}, {96,0}, {80,0}, {64,0}, {48,0}, {32,0}, {16,0}, {0,0},
600 {144,0}, {160,0}, {176,0}, {192,0}, {208,0}, {224,0}, {240,0}, {240,16}, {240,32},
601 {136,16}, {152,16}, {168,16}, {184,16}, {200,16}, {220,16}, {240,48}, {240,64}, {224,64},
603 {112,64}, {100,48}, {84,48}, {68,48}, {52,48}, {36,48}, {64,60}, {44,60}, {24,64},
604 {108,32}, {92,32}, {76,32}, {60,32}, {44,32}, {28,32}, {255,255}, {10,48}, {4,64},
606 {124,32}, {140,32}, {156,32}, {172,32}, {188,32}, {214,32}, {180,48}, {202,48}, {224,48},
607 {116,48}, {132,48}, {148,48}, {164,48}, {255,255}, {160,60}, {180,64}, {208,64}, {255,255}
609 const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
611 {64,128}, {75,132}, {84,145}, {91,164}, {97,187}, {102,213}, {105,242}, {109,255}, {128,243},
612 {61,255}, {67,255}, {72,255}, {77,255}, {82,255}, {86,255}, {90,255}, {93,255}, {96,255},
614 {56,255}, {51,255}, {46,255}, {42,255}, {38,255}, {35,255}, {32,255}, {19,255}, {0,255},
615 {53,132}, {44,145}, {37,164}, {31,187}, {26,213}, {22,249}, {237,255}, {224,255}, {221,255},
617 {189,255}, {179,135}, {170,149}, {163,169}, {157,193}, {153,220}, {172,252}, {169,255}, {165,255},
618 {128,26}, {128,60}, {128,94}, {128,128}, {128,162}, {128,196}, {255,255}, {148,255}, {161,255},
620 {0,9}, {0,43}, {0,77}, {0,111}, {0,145}, {0,201}, {224,181}, {230,217}, {235,255},
621 {189,128}, {200,131}, {210,141}, {218,159}, {255,255}, {207,238}, {211,255}, {218,255}, {255,255}
623 #elif defined(RGB_BACKLIGHT_ZEAL60) || defined(RGB_BACKLIGHT_M60_A)
624 const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
626 {120,16}, {104,16}, {88,16}, {72,16}, {56,16}, {40,16}, {24,16}, {4,16}, {4,32},
627 {128,0}, {112,0}, {96,0}, {80,0}, {64,0}, {48,0}, {32,0}, {16,0}, {0,0},
629 {144,0}, {160,0}, {176,0}, {192,0}, {216,0}, {224,0}, {255,255}, {255,255}, {255,255},
630 {136,16}, {152,16}, {168,16}, {184,16}, {200,16}, {220,16}, {255,255}, {255,255}, {255,255},
632 {102,64}, {100,48}, {84,48}, {68,48}, {52,48}, {36,48}, {60,64}, {43,64}, {23,64},
633 {108,32}, {92,32}, {76,32}, {60,32}, {44,32}, {28,32}, {20,48}, {2,48}, {3,64},
635 {124,32}, {140,32}, {156,32}, {172,32}, {188,32}, {214,32}, {180,48}, {210,48}, {224,48},
636 {116,48}, {132,48}, {148,48}, {164,48}, {144,64}, {161,64}, {181,64}, {201,64}, {221,64}
638 const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
640 {58,129}, {70,129}, {80,139}, {89,157}, {96,181}, {101,208}, {105,238}, {109,255}, {128,247},
641 {58,255}, {64,255}, {70,255}, {75,255}, {80,255}, {85,255}, {89,255}, {93,255}, {96,255},
643 {53,255}, {48,255}, {43,255}, {39,255}, {34,255}, {32,255}, {255,255}, {255,255}, {255,255},
644 {48,139}, {39,157}, {32,181}, {27,208}, {23,238}, {19,255}, {255,255}, {255,255}, {255,255},
646 {188,255}, {183,131}, {173,143}, {165,163}, {159,188}, {154,216}, {172,252}, {170,255}, {165,255},
647 {128,9}, {128,46}, {128,82}, {128,119}, {128,155}, {128,192}, {150,244}, {147,255}, {161,255},
649 {0,27}, {0,64}, {0,101}, {0,137}, {0,174}, {255,233}, {228,201}, {235,255}, {237,255},
650 {195,128}, {206,136}, {215,152}, {222,175}, {205,234}, {209,255}, {214,255}, {219,255}, {223,255}
652 #elif defined(RGB_BACKLIGHT_U80_A)
653 const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
654 // Thse are scaled by 14.5 per U
656 {109,36}, {94,36}, {80,36}, {65,36}, {51,36}, {36,36}, {22,36}, {4,36}, {5,51},
657 {116,22}, {102,22}, {87,22}, {73,22}, {58,22}, {44,22}, {29,22}, {15,22}, {0,22},
659 {131,22}, {145,22}, {160,22}, {174,22}, {196,22}, {0,0}, {0,0}, {0,0}, {0,0},
660 {123,36}, {138,36}, {152,36}, {167,36}, {181,36}, {199,36}, {0,0}, {0,0}, {0,0},
662 {102,80}, {91,65}, {76,65}, {62,65}, {47,65}, {33,65}, {58,76}, {40,80}, {22,80},
663 {98,51}, {83,51}, {69,51}, {54,51}, {40,51}, {25,51}, {0,0}, {9,65}, {4,80},
665 {112,51}, {127,51}, {141,51}, {156,51}, {170,51}, {194,51}, {163,65}, {190,65}, {0,0},
666 {105,65}, {120,65}, {134,65}, {149,65}, {0,0}, {145,76}, {163,80}, {181,80}, {199,80},
668 {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
669 {73,0}, {94,0}, {109,0}, {123,0}, {138,0}, {58,0}, {44,0}, {29,0}, {0,0},
671 {160,0}, {174,0}, {189,0}, {203,0}, {225,0}, {239,0}, {254,0}, {254,22}, {254,36},
672 {239,22}, {239,36}, {225,22}, {225,36}, {0,0}, {239,65}, {225,80}, {239,80}, {254,80}
674 const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
676 {59,129}, {69,129}, {80,138}, {88,154}, {95,175}, {100,200}, {104,227}, {107,255}, {128,226},
677 {59,255}, {64,255}, {69,255}, {75,255}, {80,255}, {84,255}, {88,255}, {91,255}, {95,255},
679 {53,255}, {48,255}, {44,255}, {40,255}, {35,255}, {255,255}, {255,255}, {255,255}, {255,255},
680 {48,138}, {40,154}, {33,175}, {28,200}, {24,227}, {21,255}, {255,255}, {255,255}, {255,255},
682 {192,255}, {184,131}, {174,141}, {166,159}, {160,181}, {155,207}, {174,244}, {171,255}, {166,255},
683 {128,9}, {128,43}, {128,77}, {128,111}, {128,145}, {128,179}, {255,255}, {150,252}, {162,255},
685 {0,26}, {0,60}, {0,94}, {0,128}, {0,162}, {0,218}, {227,193}, {234,245}, {255,255},
686 {195,128}, {205,135}, {214,149}, {221,169}, {255,255}, {210,244}, {213,255}, {218,255}, {222,255},
688 {255,255}, {255,255}, {255,255}, {255,255}, {255,255}, {255,255}, {255,255}, {255,255}, {255,255},
689 {70,255}, {66,255}, {62,255}, {59,255}, {56,255}, {73,255}, {76,255}, {79,255}, {84,255},
691 {52,255}, {49,255}, {47,255}, {44,255}, {41,255}, {38,255}, {37,255}, {25,255}, {14,255},
692 {27,255}, {15,255}, {29,255}, {17,255}, {255,255}, {241,255}, {227,255}, {229,255}, {231,255}
694 #elif defined(RGB_BACKLIGHT_HS60) && defined(HS60_ANSI)
695 const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
697 {0,0}, {4,16}, {6,32}, {10,48}, {16,0}, {24,16}, {28,32}, {36,48}, {32,0}, {40,16}, {44,32}, {52,48},
698 {48,0}, {56,16}, {60,32}, {68,48}, {64,0}, {72,16}, {76,32}, {84,48}, {80,0}, {88,16}, {92,32}, {100,48},
699 {96,0}, {104,16}, {108,32}, {116,48}, {112,0}, {120,16}, {124,32}, {132,48}, {128,0}, {136,16}, {140,32},
700 {148,48}, {144,0}, {152,16}, {156,32}, {164,48}, {160,0}, {168,16}, {172,32}, {180,48}, {176,0}, {184, 16}, {188,32},
701 {255,255},// LA48 does not exist, dummy
704 {255,255},// LA51 does not exit, dummy
706 {210,48}, {216,0}, {220,16}, {214,32}, {222,64}, {2,64}, {22,64}, {42,64}, {102,64},
707 {255,255},// LA61 does not exit, dummy
708 {162,64}, {182,64}, {202,64}
710 const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
712 {96,255}, {109,255}, {128,242}, {148,255}, {93,255}, {105,238}, {128,192}, {154,216}, {89,255}, {101,208}, {128,155}, {159,188},
713 {85,255}, {96,181}, {128,119}, {165,163}, {81,255}, {89,157}, {128,82}, {173,143}, {75,255}, {81,139}, {128,46}, {183,131},
714 {70,255}, {70,129}, {129,9}, {195,128}, {64,255}, {58,129}, {255,27}, {206,136}, {58,255}, {47,139}, {255,64}, {215,152},
715 {53,255}, {39,157}, {255,101}, {222,175}, {47,255}, {32,181}, {255,137}, {228,201}, {43,255}, {27,208}, {255, 174},
716 {255,255},// LA48 does not exist, dummy
719 {255,255},// LA51 does not exit, dummy
721 {235,255}, {33,255}, {19,255}, {255,233}, {224,255}, {160,255}, {164,255}, {169,255}, {188,255},
722 {255,255},// LA61 does not exit, dummy
723 {209,255}, {215,255}, {220,255}
725 #elif defined(RGB_BACKLIGHT_HS60) && defined(HS60_HHKB)
726 const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
728 {0,0}, {4,16}, {6,32}, {10,48}, {16,0}, {24,16}, {28,32}, {36,48}, {32,0}, {40,16}, {44,32}, {52,48},
729 {48,0}, {56,16}, {60,32}, {68,48}, {64,0}, {72,16}, {76,32}, {84,48}, {80,0}, {88,16}, {92,32}, {100,48},
730 {96,0}, {104,16}, {108,32}, {116,48}, {112,0}, {120,16}, {124,32}, {132,48}, {128,0}, {136,16}, {140,32},
731 {148,48}, {144,0}, {152,16}, {156,32}, {164,48}, {160,0}, {168,16}, {172,32}, {180,48}, {176,0}, {184, 16}, {188,32},
732 {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},
733 {255,255}, {255,255}, // LA61..LA62 does not exit, dummy
737 const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
739 {96,255}, {109,255}, {128,242}, {148,255}, {93,255}, {105,238}, {128,192}, {154,216}, {89,255}, {101,208}, {128,155}, {159,188},
740 {85,255}, {96,181}, {128,119}, {165,163}, {81,255}, {89,157}, {128,82}, {173,143}, {75,255}, {81,139}, {128,46}, {183,131},
741 {70,255}, {70,129}, {129,9}, {195,128}, {64,255}, {58,129}, {255,27}, {206,136}, {58,255}, {47,139}, {255,64}, {215,152},
742 {53,255}, {39,157}, {255,101}, {222,175}, {47,255}, {32,181}, {255,137}, {228,201}, {43,255}, {27,208}, {255, 174}, {32,255},
743 {39,255}, {23,238}, {233,242}, {237,255}, {35,255}, {19,255}, {255,233}, {223,255}, {161,255}, {165,255}, {170,255}, {192,255},
744 {255,255}, {255,255}, // LA61..LA62 does not exit, dummy
748 #elif defined(RGB_BACKLIGHT_HS60) //HS60_ISO
749 const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
751 {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},
752 {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},
753 {108,32}, {116,48}, {112,0}, {120,16}, {124,32}, {132,48}, {128,0}, {136,16}, {140,32}, {148,48}, {144,0}, {152,16},
754 {156,32}, {164,48}, {160,0}, {168,16}, {172,32}, {180,48}, {176,0}, {184, 16}, {188,32}, {20,48}, {192,0}, {200,16},
755 {255,255},// LA51 does not exit, dummy
757 {210,48}, {216,0}, {220,16}, {222,24}, {222,64}, {2,64}, {22,64}, {42,64}, {102,64},
758 {255,255},// LA61 does not exit, dummy
759 {162,64}, {182,64}, {202,64}
761 const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
763 {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},
764 {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},
765 {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},
766 {222,175}, {47,255}, {32,181}, {255,137}, {228,201}, {43,255}, {27,208}, {255, 174}, {150,246}, {39,255}, {23,238},
767 {255,255},// LA51 does not exit, dummy
769 {235,255}, {33,255}, {19,255}, {10,255}, {224,255}, {160,255}, {164,255}, {169,255}, {188,255},
770 {255,255},// LA61 does not exit, dummy
771 {209,255}, {215,255}, {220,255}
773 #elif defined(RGB_BACKLIGHT_NK65)
774 const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
776 {0,0}, {4,16}, {6,32}, {10,48}, {16,0}, {24,16}, {28,32}, {36,48}, {32,0}, {40,16}, {44,32}, {52,48},
777 {48,0}, {56,16}, {60,32}, {68,48}, {64,0}, {72,16}, {76,32}, {84,48}, {80,0}, {88,16}, {92,32}, {100,48},
778 {96,0}, {104,16}, {108,32}, {116,48}, {112,0}, {120,16}, {124,32}, {132,48}, {128,0}, {136,16}, {140,32},
779 {148,48}, {144,0}, {152,16}, {156,32}, {164,48}, {160,0}, {168,16}, {172,32}, {180,48}, {176,0}, {184, 16}, {188,32},
780 {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},
781 {255,255},// LA61 does not exit, dummy
783 {176,64}, {192,64}, {208,64}, {240,0}, {240,16}, {240,48}, {240,64}, {240,32}
785 const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
787 {96,255}, {109,255}, {128,242}, {148,255}, {93,255}, {105,238}, {128,192}, {154,216}, {89,255}, {101,208}, {128,155}, {159,188},
788 {85,255}, {96,181}, {128,119}, {165,163}, {81,255}, {89,157}, {128,82}, {173,143}, {75,255}, {81,139}, {128,46}, {183,131},
789 {70,255}, {70,129}, {129,9}, {195,128}, {64,255}, {58,129}, {255,27}, {206,136}, {58,255}, {47,139}, {255,64}, {215,152},
790 {53,255}, {39,157}, {255,101}, {222,175}, {47,255}, {32,181}, {255,137}, {228,201}, {43,255}, {27,208}, {255, 174},
791 {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},
792 {255,255},// LA61 does not exit, dummy
794 {221,255}, {225,255}, {229,255}, {22,255}, {12,255}, {244,255}, {234,255}, {255,255},
796 #elif defined(RGB_BACKLIGHT_M6_B)
797 // M6-B is really simple:
800 const Point g_map_led_to_point[BACKLIGHT_LED_COUNT] PROGMEM = {
801 {0,0}, {0,16}, {16,16}, {16,0}, {32,16}, {32,0}
803 const Point g_map_led_to_point_polar[BACKLIGHT_LED_COUNT] PROGMEM = {
804 {160,255}, {96,255}, {77,255}, {179,255}, {51,255}, {205,255}
808 // This may seem counter-intuitive, but it's quite flexible.
809 // For each LED, get it's position to decide what color to make it.
810 // This solves the issue of LEDs (and switches) not aligning to a grid,
811 // or having a large "bitmap" and sampling them.
812 void map_led_to_point( uint8_t index, Point *point )
814 // Slightly messy way to get Point structs out of progmem.
815 uint8_t *addr = (uint8_t*)&g_map_led_to_point[index];
816 point->x = pgm_read_byte(addr);
817 point->y = pgm_read_byte(addr+1);
819 #if defined(RGB_BACKLIGHT_M6_B) || defined(RGB_BACKLIGHT_HS60) || defined(RGB_BACKLIGHT_NK65)
826 if ( g_config.use_split_backspace )
829 #if defined(RGB_BACKLIGHT_ZEAL60)
831 if ( g_config.use_iso_enter )
832 point->y += 8; // extremely pedantic
835 if ( !g_config.use_iso_enter )
839 if ( !g_config.use_split_left_shift )
843 #if defined(RGB_BACKLIGHT_ZEAL60) || defined(RGB_BACKLIGHT_M60_A)
845 if ( g_config.use_7u_spacebar )
849 if ( g_config.use_7u_spacebar )
853 if ( !g_config.use_split_right_shift )
860 void map_led_to_point_polar( uint8_t index, Point *point )
862 // Slightly messy way to get Point structs out of progmem.
863 uint8_t *addr = (uint8_t*)&g_map_led_to_point_polar[index];
864 point->x = pgm_read_byte(addr);
865 point->y = pgm_read_byte(addr+1);
869 // Maps switch matrix coordinate (row,col) to LED index
873 #if defined(RGB_BACKLIGHT_ZEAL65)
874 // Note: Left spacebar stab is at 4,2 (LC7)
875 // Right spacebar stab is at 4,9 (D14)
877 // A17, A16, A15, A14, A13, A12, A11, A10, A9, B0, B1, B2, B3, B4, B6
878 // A7, A6, A5, A4, A3, A2, A1, A0, B9, B10, B11, B12, B13, B14, B7
879 // A8, C14, C13, C12, C11, C10, C9, D0, D1, D2, D3, D4, D5, B5, B8
880 // C16, C15, C5, C4, C3, C2, C1, D9, D10, D11, D12, D6, D7, D8, B15
881 // C17, C8, C7, ---, ---, ---, ---, C0, ---, D14, D15, D16, D17, B17, B16
882 const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
883 { 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 },
884 { 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 },
885 { 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 },
886 { 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 },
887 { 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 }
889 #elif defined(RGB_BACKLIGHT_KOYU)
890 // Note: Left spacebar stab is at 4,4 (LC6)
891 // Right spacebar stab is at 4,10 (D14)
893 // A17, A16, A15, A14, A13, A12, A11, A10, A9, B0, B1, B2, B3, B4, B6
894 // A7, A6, A5, A4, A3, A2, A1, A0, B9, B10, B11, B12, B13, B14, B7
895 // A8, C14, C13, C12, C11, C10, C9, D0, D1, D2, D3, D4, D5, B5, B8
896 // C16, C15, C5, C4, C3, C2, C1, D9, D10, D11, D12, D6, D7, D8, B15
897 // C17, C8, C7, C6, ---, ---, ---, C0, ---, ---, D14, D15, D16, B17, B16
898 const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
899 { 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 },
900 { 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 },
901 { 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 },
902 { 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 },
903 { 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 }
905 #elif defined(RGB_BACKLIGHT_ZEAL60) || defined(RGB_BACKLIGHT_M60_A)
906 // Note: Left spacebar stab is at 4,3 (LC6)
907 // Right spacebar stab is at 4,9 (LD13) or 4,10 (LD14)
909 // A17, A16, A15, A14, A13, A12, A11, A10, A9, B0, B1, B2, B3, B4,
910 // A7, A6, A5, A4, A3, A2, A1, A0, B9, B10, B11, B12, B13, B14,
911 // A8, C14, C13, C12, C11, C10, C9, D0, D1, D2, D3, D4, D5, B5,
912 // C16, C15, C5, C4, C3, C2, C1, D9, D10, D11, D12, D6, D7, D8,
913 // C17, C8, C7, C6, ---, ---, ---, C0, ---, D13, D14, D15, D16, D17,
914 const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
915 { 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 },
916 { 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 },
917 { 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 },
918 { 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 },
919 { 36+17, 36+8, 36+7, 36+6, 255, 255, 255, 36+0, 255, 54+13, 54+14, 54+15, 54+16, 54+17 }
921 #elif defined(RGB_BACKLIGHT_U80_A)
922 // Note: Left spacebar stab is at 5,3 (LC6)
923 // Right spacebar stab is at 5,10 (LD14)
924 const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
925 { 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 },
926 { 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 },
927 { 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 },
928 { 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 },
929 { 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 },
930 { 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 }
932 #elif defined(RGB_BACKLIGHT_HS60) && defined(HS60_ANSI)
934 // LA1, LA5, LA9, LA13, LA17, LA21, LA25, LA29, LA33, LA37, LA41, LA45, LA49, LA53,
935 // LA2, LA6, LA10, LA14, LA18, LA22, LA26, LA30, LA34, LA38, LA42, LA46, LA50, ---,
936 // LA3, LA7, LA11, LA15, LA19, LA23, LA27, LA31, LA35, LA39, LA43, LA47, LA54, LA55,
937 // LA4, ---, LA8, LA12, LA16, LA20, LA24, LA28, LA32, LA36, LA40, LA44, ---, LA52,
938 // LA57, LA58, LA59, ---, ---, ---, LA60, ---, ---, ---, LA62, LA63, LA64, LA56
939 const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
940 { 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 },
941 { 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 },
942 { 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 },
943 { 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 },
944 { 57-1, 58-1, 59-1, 255, 255, 255, 60-1, 255, 255, 255, 62-1, 63-1, 64-1, 56-1 }
946 #elif defined(RGB_BACKLIGHT_HS60) && defined(HS60_HHKB)
948 // LA1, LA5, LA9, LA13, LA17, LA21, LA25, LA29, LA33, LA37, LA41, LA45, LA49, LA53,
949 // LA2, LA6, LA10, LA14, LA18, LA22, LA26, LA30, LA34, LA38, LA42, LA46, LA50, LA48,
950 // LA3, LA7, LA11, LA15, LA19, LA23, LA27, LA31, LA35, LA39, LA43, LA47, LA54, LA55,
951 // LA4, ---, LA8, LA12, LA16, LA20, LA24, LA28, LA32, LA36, LA40, LA44, LA51, LA52,
952 // LA57, LA58, LA59, ---, ---, ---, LA60, ---, ---, ---, ---, LA63, LA64, LA56
953 const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
954 { 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 },
955 { 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 },
956 { 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 },
957 { 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 },
958 { 57-1, 58-1, 59-1, 255, 255, 255, 60-1, 255, 255, 255, 255, 63-1, 64-1, 56-1 }
960 #elif defined(RGB_BACKLIGHT_HS60) //HS60_ISO
962 // LA1, LA5, LA9, LA13, LA17, LA21, LA25, LA29, LA33, LA37, LA41, LA45, LA49, LA53,
963 // LA2, LA6, LA10, LA14, LA18, LA22, LA26, LA30, LA34, LA38, LA42, LA46, LA50, ---,
964 // LA3, LA7, LA11, LA15, LA19, LA23, LA27, LA31, LA35, LA39, LA43, LA47, LA54, LA55,
965 // LA4, LA48, LA8, LA12, LA16, LA20, LA24, LA28, LA32, LA36, LA40, LA44, ---, LA52,
966 // LA57, LA58, LA59, ---, ---, ---, LA60, ---, ---, ---, LA62, LA63, LA64, LA56
967 const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
968 { 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 },
969 { 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 },
970 { 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 },
971 { 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 },
972 { 57-1, 58-1, 59-1, 255, 255, 255, 60-1, 255, 255, 255, 62-1, 63-1, 64-1, 56-1 }
974 #elif defined(RGB_BACKLIGHT_NK65)
976 // LA1, LA5, LA9, LA13, LA17, LA21, LA25, LA29, LA33, LA37, LA41, LA45, LA49, LA53, LB1,
977 // LA2, LA6, LA10, LA14, LA18, LA22, LA26, LA30, LA34, LA38, LA42, LA46, LA50, ---, LB2,
978 // LA3, LA7, LA11, LA15, LA19, LA23, LA27, LA31, LA35, LA39, LA43, LA47, LA54, LA55, LB5,
979 // LA4, ---, LA8, LA12, LA16, LA20, LA24, LA28, LA32, LA36, LA40, LA44, LA51, LA52, LB3,
980 // LA57, LA58, LA59, ---, ---, ---, LA60, ---, ---, LA48, LA62, LA63, LA64, LA56, LB4
981 const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
982 { 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 },
983 { 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 },
984 { 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 },
985 { 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 },
986 { 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 }
988 #elif defined(RGB_BACKLIGHT_M6_B)
989 // M6-B is really simple:
992 const uint8_t g_map_row_column_to_led[MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
997 void map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led )
1000 if ( row < MATRIX_ROWS && column < MATRIX_COLS )
1002 *led = pgm_read_byte(&g_map_row_column_to_led[row][column]);
1006 void backlight_update_pwm_buffers(void)
1008 #if defined(RGB_BACKLIGHT_M6_B)
1009 IS31FL3218_update_pwm_buffers();
1010 #elif defined(RGB_BACKLIGHT_HS60)
1011 IS31FL3733_update_pwm_buffers( ISSI_ADDR_1, 0 );
1012 IS31FL3733_update_led_control_registers( ISSI_ADDR_1, 0 );
1013 #elif defined(RGB_BACKLIGHT_NK65)
1014 IS31FL3733_update_pwm_buffers( ISSI_ADDR_1, 0 );
1015 IS31FL3733_update_pwm_buffers( ISSI_ADDR_2, 1 );
1016 IS31FL3733_update_led_control_registers( ISSI_ADDR_1, 0 );
1017 IS31FL3733_update_led_control_registers( ISSI_ADDR_2, 1 );
1018 #elif defined(RGB_BACKLIGHT_U80_A)
1019 static uint8_t driver = 0;
1023 IS31FL3731_update_pwm_buffers( ISSI_ADDR_1, 0 );
1026 IS31FL3731_update_pwm_buffers( ISSI_ADDR_2, 1 );
1029 IS31FL3731_update_pwm_buffers( ISSI_ADDR_3, 2 );
1037 IS31FL3731_update_pwm_buffers( ISSI_ADDR_1, 0 );
1038 IS31FL3731_update_pwm_buffers( ISSI_ADDR_2, 1 );
1039 IS31FL3731_update_led_control_registers( ISSI_ADDR_1, 0 );
1040 IS31FL3731_update_led_control_registers( ISSI_ADDR_2, 1 );
1044 void backlight_set_color( int index, uint8_t red, uint8_t green, uint8_t blue )
1046 #if defined(RGB_BACKLIGHT_M6_B)
1047 IS31FL3218_set_color( index, red, green, blue );
1048 #elif defined(RGB_BACKLIGHT_HS60) || defined(RGB_BACKLIGHT_NK65)
1049 IS31FL3733_set_color( index, red, green, blue );
1051 IS31FL3731_set_color( index, red, green, blue );
1055 void backlight_set_color_all( uint8_t red, uint8_t green, uint8_t blue )
1057 #if defined(RGB_BACKLIGHT_M6_B)
1058 IS31FL3218_set_color_all( red, green, blue );
1059 #elif defined(RGB_BACKLIGHT_HS60) || defined(RGB_BACKLIGHT_NK65)
1060 IS31FL3733_set_color_all( red, green, blue );
1062 IS31FL3731_set_color_all( red, green, blue );
1066 void backlight_set_key_hit(uint8_t row, uint8_t column)
1069 map_row_column_to_led(row,column,&led);
1075 #if !defined(RGB_BACKLIGHT_HS60) && !defined(RGB_BACKLIGHT_NK65)
1076 // This is (F_CPU/1024) / 20 Hz
1077 // = 15625 Hz / 20 Hz
1079 #define TIMER3_TOP 781
1081 void backlight_timer_init(void)
1083 static uint8_t backlight_timer_is_init = 0;
1084 if ( backlight_timer_is_init )
1088 backlight_timer_is_init = 1;
1091 TCCR3B = _BV(WGM32) | // CTC mode OCR3A as TOP
1092 _BV(CS32) | _BV(CS30); // prescale by /1024
1094 uint8_t sreg = SREG;
1097 OCR3AH = (TIMER3_TOP >> 8) & 0xff;
1098 OCR3AL = TIMER3_TOP & 0xff;
1102 void backlight_timer_enable(void)
1104 TIMSK3 |= _BV(OCIE3A);
1107 void backlight_timer_disable(void)
1109 TIMSK3 &= ~_BV(OCIE3A);
1111 #else //STM32, use GPT with TIM4. Enable in halconf.h
1112 static void gpt_backlight_timer_task(GPTDriver *gptp);
1113 // Timer setup at 200Khz, callback at 10k ticks = 20Hz
1114 static GPTConfig gpt4cfg1 = {
1115 .frequency = 200000U,
1116 .callback = gpt_backlight_timer_task
1119 void backlight_timer_init(void)
1121 gptStart(&GPTD4, &gpt4cfg1);
1124 void backlight_timer_enable(void)
1126 gptStartContinuous(&GPTD4, 10000);
1129 void backlight_timer_disable(void)
1131 gptStopTimer(&GPTD4);
1133 #endif //!defined(RGB_BACKLIGHT_HS60) && !defined(RGB_BACKLIGHT_NK65)
1135 void backlight_set_suspend_state(bool state)
1137 g_suspend_state = state;
1140 void backlight_set_indicator_state(uint8_t state)
1142 g_indicator_state = state;
1145 void backlight_effect_rgb_test(void)
1147 // Mask out bits 4 and 5
1148 // This 2-bit value will stay the same for 16 ticks.
1149 switch ( (g_tick & 0x30) >> 4 )
1153 backlight_set_color_all( 255, 0, 0 );
1158 backlight_set_color_all( 0, 255, 0 );
1163 backlight_set_color_all( 0, 0, 255 );
1168 backlight_set_color_all( 255, 255, 255 );
1174 #if defined(RGB_DEBUGGING_ONLY)
1175 // This tests the LEDs
1176 // Note that it will change the LED control registers
1177 // in the LED drivers, and leave them in an invalid
1178 // state for other backlight effects.
1179 // ONLY USE THIS FOR TESTING LEDS!
1180 void backlight_effect_single_LED_test(void)
1182 static uint8_t color = 0; // 0,1,2 for R,G,B
1183 static uint8_t row = 0;
1184 static uint8_t column = 0;
1186 static uint8_t tick = 0;
1210 map_row_column_to_led( row, column, &led );
1211 backlight_set_color_all( 255, 255, 255 );
1212 backlight_test_led( led, color==0, color==1, color==2 );
1214 #endif // defined(RGB_DEBUGGING_ONLY)
1217 void backlight_effect_all_off(void)
1219 backlight_set_color_all( 0, 0, 0 );
1223 void backlight_effect_solid_color(void)
1225 HSV hsv = { .h = g_config.color_1.h, .s = g_config.color_1.s, .v = g_config.brightness };
1226 RGB rgb = hsv_to_rgb( hsv );
1227 backlight_set_color_all( rgb.r, rgb.g, rgb.b );
1230 // alphas = color1, mods = color2
1231 void backlight_effect_alphas_mods(void)
1233 RGB rgb1 = hsv_to_rgb( (HSV){ .h = g_config.color_1.h, .s = g_config.color_1.s, .v = g_config.brightness } );
1234 RGB rgb2 = hsv_to_rgb( (HSV){ .h = g_config.color_2.h, .s = g_config.color_2.s, .v = g_config.brightness } );
1235 bool is_alpha = false;
1236 for ( int row = 0; row < MATRIX_ROWS; row++ )
1238 for ( int column = 0; column < MATRIX_COLS; column++ )
1241 map_row_column_to_led( row, column, &index );
1242 if ( index < BACKLIGHT_LED_COUNT )
1244 #if defined(RGB_BACKLIGHT_U80_A)
1247 is_alpha = ( column < 16 ) && (( 0b1110000111100001 & (1<<column) ) == 0);
1251 is_alpha = ( column < 16 ) && (( g_config.alphas_mods[row-1] & (1<<column) ) == 0);
1254 is_alpha = ( g_config.alphas_mods[row] & (1<<column) ) == 0;
1258 backlight_set_color( index, rgb1.r, rgb1.g, rgb1.b );
1262 backlight_set_color( index, rgb2.r, rgb2.g, rgb2.b );
1269 void backlight_effect_gradient_up_down(void)
1271 int16_t h1 = g_config.color_1.h;
1272 int16_t h2 = g_config.color_2.h;
1273 int16_t deltaH = h2 - h1;
1275 // Take the shortest path between hues
1280 else if ( deltaH < -127 )
1284 // Divide delta by 4, this gives the delta per row
1287 int16_t s1 = g_config.color_1.s;
1288 int16_t s2 = g_config.color_2.s;
1289 int16_t deltaS = ( s2 - s1 ) / 4;
1291 HSV hsv = { .h = 0, .s = 255, .v = g_config.brightness };
1294 for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
1296 map_led_to_point( i, &point );
1297 // The y range will be 0..64, map this to 0..4
1298 uint8_t y = (point.y>>4);
1299 // Relies on hue being 8-bit and wrapping
1300 hsv.h = g_config.color_1.h + ( deltaH * y );
1301 hsv.s = g_config.color_1.s + ( deltaS * y );
1302 rgb = hsv_to_rgb( hsv );
1303 backlight_set_color( i, rgb.r, rgb.g, rgb.b );
1307 void backlight_effect_raindrops(bool initialize)
1309 int16_t h1 = g_config.color_1.h;
1310 int16_t h2 = g_config.color_2.h;
1311 int16_t deltaH = h2 - h1;
1314 // Take the shortest path between hues
1319 else if ( deltaH < -127 )
1324 int16_t s1 = g_config.color_1.s;
1325 int16_t s2 = g_config.color_2.s;
1326 int16_t deltaS = ( s2 - s1 ) / 4;
1331 // Change one LED every tick
1332 uint8_t led_to_change = ( g_tick & 0x000 ) == 0 ? rand() % BACKLIGHT_LED_COUNT : 255;
1334 for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
1336 // If initialize, all get set to random colors
1337 // If not, all but one will stay the same as before.
1338 if ( initialize || i == led_to_change )
1340 hsv.h = h1 + ( deltaH * ( rand() & 0x03 ) );
1341 hsv.s = s1 + ( deltaS * ( rand() & 0x03 ) );
1342 // Override brightness with global brightness control
1343 hsv.v = g_config.brightness;;
1345 rgb = hsv_to_rgb( hsv );
1346 backlight_set_color( i, rgb.r, rgb.g, rgb.b );
1351 void backlight_effect_cycle_all(void)
1353 uint8_t offset = ( g_tick << g_config.effect_speed ) & 0xFF;
1355 // Relies on hue being 8-bit and wrapping
1356 for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
1358 uint16_t offset2 = g_key_hit[i]<<2;
1359 #if !defined(RGB_BACKLIGHT_HS60) && !defined(RGB_BACKLIGHT_NK65)
1360 // stabilizer LEDs use spacebar hits
1361 if ( i == 36+6 || i == 54+13 || // LC6, LD13
1362 ( g_config.use_7u_spacebar && i == 54+14 ) ) // LD14
1364 offset2 = g_key_hit[36+0]<<2;
1367 offset2 = (offset2<=63) ? (63-offset2) : 0;
1369 HSV hsv = { .h = offset+offset2, .s = 255, .v = g_config.brightness };
1370 RGB rgb = hsv_to_rgb( hsv );
1371 backlight_set_color( i, rgb.r, rgb.g, rgb.b );
1375 void backlight_effect_cycle_left_right(void)
1377 uint8_t offset = ( g_tick << g_config.effect_speed ) & 0xFF;
1378 HSV hsv = { .h = 0, .s = 255, .v = g_config.brightness };
1381 for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
1383 uint16_t offset2 = g_key_hit[i]<<2;
1384 #if !defined(RGB_BACKLIGHT_HS60) && !defined(RGB_BACKLIGHT_NK65)
1385 // stabilizer LEDs use spacebar hits
1386 if ( i == 36+6 || i == 54+13 || // LC6, LD13
1387 ( g_config.use_7u_spacebar && i == 54+14 ) ) // LD14
1389 offset2 = g_key_hit[36+0]<<2;
1392 offset2 = (offset2<=63) ? (63-offset2) : 0;
1394 map_led_to_point( i, &point );
1395 // Relies on hue being 8-bit and wrapping
1396 hsv.h = point.x + offset + offset2;
1397 rgb = hsv_to_rgb( hsv );
1398 backlight_set_color( i, rgb.r, rgb.g, rgb.b );
1402 void backlight_effect_cycle_up_down(void)
1404 uint8_t offset = ( g_tick << g_config.effect_speed ) & 0xFF;
1405 HSV hsv = { .h = 0, .s = 255, .v = g_config.brightness };
1408 for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
1410 uint16_t offset2 = g_key_hit[i]<<2;
1411 #if !defined(RGB_BACKLIGHT_HS60) && !defined(RGB_BACKLIGHT_NK65)
1412 // stabilizer LEDs use spacebar hits
1413 if ( i == 36+6 || i == 54+13 || // LC6, LD13
1414 ( g_config.use_7u_spacebar && i == 54+14 ) ) // LD14
1416 offset2 = g_key_hit[36+0]<<2;
1419 offset2 = (offset2<=63) ? (63-offset2) : 0;
1421 map_led_to_point( i, &point );
1422 // Relies on hue being 8-bit and wrapping
1423 hsv.h = point.y + offset + offset2;
1424 rgb = hsv_to_rgb( hsv );
1425 backlight_set_color( i, rgb.r, rgb.g, rgb.b );
1429 void backlight_effect_jellybean_raindrops( bool initialize )
1434 // Change one LED every tick
1435 uint8_t led_to_change = ( g_tick & 0x000 ) == 0 ? rand() % BACKLIGHT_LED_COUNT : 255;
1437 for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
1439 // If initialize, all get set to random colors
1440 // If not, all but one will stay the same as before.
1441 if ( initialize || i == led_to_change )
1443 hsv.h = rand() & 0xFF;
1444 hsv.s = rand() & 0xFF;
1445 // Override brightness with global brightness control
1446 hsv.v = g_config.brightness;;
1448 rgb = hsv_to_rgb( hsv );
1449 backlight_set_color( i, rgb.r, rgb.g, rgb.b );
1454 void backlight_effect_cycle_radial1(void)
1456 uint8_t offset = ( g_tick << g_config.effect_speed ) & 0xFF;
1457 HSV hsv = { .h = 0, .s = 255, .v = g_config.brightness };
1460 for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
1462 map_led_to_point_polar( i, &point );
1463 // Relies on hue being 8-bit and wrapping
1464 hsv.h = point.x + offset;
1466 rgb = hsv_to_rgb( hsv );
1467 backlight_set_color( i, rgb.r, rgb.g, rgb.b );
1471 void backlight_effect_cycle_radial2(void)
1473 uint8_t offset = ( g_tick << g_config.effect_speed ) & 0xFF;
1475 HSV hsv = { .h = 0, .s = g_config.color_1.s, .v = g_config.brightness };
1478 for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
1480 map_led_to_point_polar( i, &point );
1481 uint8_t offset2 = offset + point.x;
1482 if ( offset2 & 0x80 )
1486 offset2 = offset2 >> 2;
1487 hsv.h = g_config.color_1.h + offset2;
1488 hsv.s = 127 + ( point.y >> 1 );
1489 rgb = hsv_to_rgb( hsv );
1490 backlight_set_color( i, rgb.r, rgb.g, rgb.b );
1494 #if defined(RGB_BACKLIGHT_M6_B)
1495 void backlight_effect_custom_colors(void)
1498 for ( uint8_t i = 0; i < 6; i++ )
1500 HSV hsv = { .h = g_config.custom_color[i].h, .s = g_config.custom_color[i].s, .v = g_config.brightness };
1501 rgb = hsv_to_rgb( hsv );
1503 map_row_column_to_led( 0, i, &led );
1504 backlight_set_color( led, rgb.r, rgb.g, rgb.b );
1509 void backlight_effect_indicators_set_colors( uint8_t index, HS color )
1511 HSV hsv = { .h = color.h, .s = color.s, .v = g_config.brightness };
1512 RGB rgb = hsv_to_rgb( hsv );
1515 backlight_set_color_all( rgb.r, rgb.g, rgb.b );
1519 backlight_set_color( index, rgb.r, rgb.g, rgb.b );
1521 // If the spacebar LED is the indicator,
1522 // do the same for the spacebar stabilizers
1523 if ( index == 36+0 ) // LC0
1525 #if defined(RGB_BACKLIGHT_ZEAL65)
1526 backlight_set_color( 36+7, rgb.r, rgb.g, rgb.b ); // LC7
1527 backlight_set_color( 54+14, rgb.r, rgb.g, rgb.b ); // LD14
1528 #elif defined(RGB_BACKLIGHT_KOYU)
1529 backlight_set_color( 36+6, rgb.r, rgb.g, rgb.b ); // LC6
1530 backlight_set_color( 54+14, rgb.r, rgb.g, rgb.b ); // LD14
1531 #elif defined(RGB_BACKLIGHT_ZEAL60) || defined(RGB_BACKLIGHT_M60_A)
1532 backlight_set_color( 36+6, rgb.r, rgb.g, rgb.b ); // LC6
1533 backlight_set_color( 54+13, rgb.r, rgb.g, rgb.b ); // LD13
1534 if ( g_config.use_7u_spacebar )
1536 backlight_set_color( 54+14, rgb.r, rgb.g, rgb.b ); // LD14
1543 // This runs after another backlight effect and replaces
1544 // colors already set
1545 void backlight_effect_indicators(void)
1547 if ( g_config.caps_lock_indicator.index != 255 &&
1548 ( g_indicator_state & (1<<USB_LED_CAPS_LOCK) ) )
1550 backlight_effect_indicators_set_colors( g_config.caps_lock_indicator.index, g_config.caps_lock_indicator.color );
1553 #if defined(RGB_BACKLIGHT_NK65)
1554 if ( g_indicator_state & (1<<USB_LED_CAPS_LOCK) )
1556 IS31FL3733_set_color( 7+64-1, 0, 255, 0 );
1558 IS31FL3733_set_color( 7+64-1, 0, 0, 0 );
1560 if ( g_indicator_state & (1<<USB_LED_SCROLL_LOCK) )
1562 IS31FL3733_set_color( 6+64-1, 255, 0, 255 );
1564 IS31FL3733_set_color( 6+64-1, 0, 0, 0 );
1566 if ( g_indicator_state & (1<<USB_LED_NUM_LOCK) )
1568 IS31FL3733_set_color( 6+64-1, 0, 255, 0 );
1570 IS31FL3733_set_color( 6+64-1, 0, 0, 0 );
1574 // This if/else if structure allows higher layers to
1575 // override lower ones. If we set layer 3's indicator
1576 // to none, then it will NOT show layer 2 or layer 1
1577 // indicators, even if those layers are on via the
1578 // MO13/MO23 Fn combo magic.
1580 // Basically we want to handle the case where layer 3 is
1581 // still the backlight configuration layer and we don't
1582 // want "all LEDs" indicators hiding the backlight effect,
1583 // but still allow end users to do whatever they want.
1584 if ( IS_LAYER_ON(3) )
1586 if ( g_config.layer_3_indicator.index != 255 )
1588 backlight_effect_indicators_set_colors( g_config.layer_3_indicator.index, g_config.layer_3_indicator.color );
1591 else if ( IS_LAYER_ON(2) )
1593 if ( g_config.layer_2_indicator.index != 255 )
1595 backlight_effect_indicators_set_colors( g_config.layer_2_indicator.index, g_config.layer_2_indicator.color );
1598 else if ( IS_LAYER_ON(1) )
1600 if ( g_config.layer_1_indicator.index != 255 )
1602 backlight_effect_indicators_set_colors( g_config.layer_1_indicator.index, g_config.layer_1_indicator.color );
1607 #if !defined(RGB_BACKLIGHT_HS60) && !defined(RGB_BACKLIGHT_NK65)
1608 ISR(TIMER3_COMPA_vect)
1609 #else //STM32 interrupt
1610 static void gpt_backlight_timer_task(GPTDriver *gptp)
1613 // delay 1 second before driving LEDs or doing anything else
1614 static uint8_t startup_tick = 0;
1615 if ( startup_tick < 20 )
1623 if ( g_any_key_hit < 0xFFFFFFFF )
1628 for ( int led = 0; led < BACKLIGHT_LED_COUNT; led++ )
1630 if ( g_key_hit[led] < 255 )
1636 // Factory default magic value
1637 if ( g_config.effect == 255 )
1639 backlight_effect_rgb_test();
1643 // Ideally we would also stop sending zeros to the LED driver PWM buffers
1644 // while suspended and just do a software shutdown. This is a cheap hack for now.
1645 bool suspend_backlight = ((g_suspend_state && g_config.disable_when_usb_suspended) ||
1646 (g_config.disable_after_timeout > 0 && g_any_key_hit > g_config.disable_after_timeout * 60 * 20));
1647 uint8_t effect = suspend_backlight ? 0 : g_config.effect;
1649 // Keep track of the effect used last time,
1650 // detect change in effect, so each effect can
1651 // have an optional initialization.
1652 static uint8_t effect_last = 255;
1653 bool initialize = effect != effect_last;
1654 effect_last = effect;
1656 // this gets ticked at 20 Hz.
1657 // each effect can opt to do calculations
1658 // and/or request PWM buffer updates.
1662 backlight_effect_all_off();
1665 backlight_effect_solid_color();
1668 #if defined(RGB_BACKLIGHT_M6_B)
1669 backlight_effect_custom_colors();
1671 backlight_effect_alphas_mods();
1675 backlight_effect_gradient_up_down();
1678 backlight_effect_raindrops( initialize );
1681 backlight_effect_cycle_all();
1684 backlight_effect_cycle_left_right();
1687 backlight_effect_cycle_up_down();
1690 backlight_effect_jellybean_raindrops( initialize );
1693 backlight_effect_cycle_radial1();
1696 backlight_effect_cycle_radial2();
1699 backlight_effect_all_off();
1703 if ( ! suspend_backlight )
1705 #if !defined(RGB_BACKLIGHT_M6_B)
1706 backlight_effect_indicators();
1711 void backlight_set_indicator_index( uint8_t *index, uint8_t row, uint8_t column )
1713 if ( row >= MATRIX_ROWS )
1715 // Special value, 255=none, 254=all
1720 map_row_column_to_led( row, column, index );
1724 void backlight_get_indicator_row_col( uint8_t index, uint8_t *row, uint8_t *column )
1726 if ( index == 255 || index == 254 )
1728 // Special value, 255=none, 254=all
1733 for ( uint8_t r = 0; r < MATRIX_ROWS; r++ )
1735 for ( uint8_t c = 0; c < MATRIX_COLS; c++ )
1738 map_row_column_to_led( r, c, &i );
1749 // Some helpers for setting/getting HSV
1750 void _set_color( HS *color, uint8_t *data )
1756 void _get_color( HS *color, uint8_t *data )
1762 void backlight_config_set_value( uint8_t *data )
1764 bool reinitialize = false;
1765 uint8_t *value_id = &(data[0]);
1766 uint8_t *value_data = &(data[1]);
1767 switch ( *value_id )
1769 #if defined (RGB_BACKLIGHT_ZEAL60) || defined(RGB_BACKLIGHT_ZEAL65)
1770 case id_use_split_backspace:
1772 g_config.use_split_backspace = (bool)*value_data;
1773 reinitialize = true;
1777 #if defined (RGB_BACKLIGHT_ZEAL60)
1778 case id_use_split_left_shift:
1780 g_config.use_split_left_shift = (bool)*value_data;
1781 reinitialize = true;
1784 case id_use_split_right_shift:
1786 g_config.use_split_right_shift = (bool)*value_data;
1787 reinitialize = true;
1790 case id_use_7u_spacebar:
1792 g_config.use_7u_spacebar = (bool)*value_data;
1793 reinitialize = true;
1796 case id_use_iso_enter:
1798 g_config.use_iso_enter = (bool)*value_data;
1799 reinitialize = true;
1802 case id_disable_hhkb_blocker_leds:
1804 g_config.disable_hhkb_blocker_leds = (bool)*value_data;
1805 reinitialize = true;
1809 case id_disable_when_usb_suspended:
1811 g_config.disable_when_usb_suspended = (bool)*value_data;
1814 case id_disable_after_timeout:
1816 g_config.disable_after_timeout = *value_data;
1821 g_config.brightness = *value_data;
1826 g_config.effect = *value_data;
1829 case id_effect_speed:
1831 g_config.effect_speed = *value_data;
1836 _set_color( &(g_config.color_1), value_data );
1841 _set_color( &(g_config.color_2), value_data );
1844 case id_caps_lock_indicator_color:
1846 _set_color( &(g_config.caps_lock_indicator.color), value_data );
1849 case id_caps_lock_indicator_row_col:
1851 backlight_set_indicator_index( &(g_config.caps_lock_indicator.index), value_data[0], value_data[1] );
1854 case id_layer_1_indicator_color:
1856 _set_color( &(g_config.layer_1_indicator.color), value_data );
1859 case id_layer_1_indicator_row_col:
1861 backlight_set_indicator_index( &(g_config.layer_1_indicator.index), value_data[0], value_data[1] );
1864 case id_layer_2_indicator_color:
1866 _set_color( &(g_config.layer_2_indicator.color), value_data );
1869 case id_layer_2_indicator_row_col:
1871 backlight_set_indicator_index( &(g_config.layer_2_indicator.index), value_data[0], value_data[1] );
1874 case id_layer_3_indicator_color:
1876 _set_color( &(g_config.layer_3_indicator.color), value_data );
1879 case id_layer_3_indicator_row_col:
1881 backlight_set_indicator_index( &(g_config.layer_3_indicator.index), value_data[0], value_data[1] );
1884 case id_alphas_mods:
1886 for ( int i=0; i<5; i++ )
1888 g_config.alphas_mods[i] = ( *(value_data+i*2) << 8 ) | ( *(value_data+i*2+1) );
1891 #if defined(RGB_BACKLIGHT_M6_B)
1892 case id_custom_color:
1894 uint8_t index = value_data[0];
1895 if ( index >= 0 && index <= 6 )
1897 _set_color( &(g_config.custom_color[index]), &(value_data[1]) );
1905 backlight_init_drivers();
1909 void backlight_config_get_value( uint8_t *data )
1911 uint8_t *value_id = &(data[0]);
1912 uint8_t *value_data = &(data[1]);
1913 switch ( *value_id )
1915 case id_use_split_backspace:
1917 *value_data = ( g_config.use_split_backspace ? 1 : 0 );
1920 case id_use_split_left_shift:
1922 *value_data = ( g_config.use_split_left_shift ? 1 : 0 );
1925 case id_use_split_right_shift:
1927 *value_data = ( g_config.use_split_right_shift ? 1 : 0 );
1930 case id_use_7u_spacebar:
1932 *value_data = ( g_config.use_7u_spacebar ? 1 : 0 );
1935 case id_use_iso_enter:
1937 *value_data = ( g_config.use_iso_enter ? 1 : 0 );
1940 case id_disable_when_usb_suspended:
1942 *value_data = ( g_config.disable_when_usb_suspended ? 1 : 0 );
1945 case id_disable_hhkb_blocker_leds:
1947 *value_data = ( g_config.disable_hhkb_blocker_leds ? 1 : 0 );
1950 case id_disable_after_timeout:
1952 *value_data = g_config.disable_after_timeout;
1957 *value_data = g_config.brightness;
1962 *value_data = g_config.effect;
1965 case id_effect_speed:
1967 *value_data = g_config.effect_speed;
1972 _get_color( &(g_config.color_1), value_data );
1977 _get_color( &(g_config.color_2), value_data );
1980 case id_caps_lock_indicator_color:
1982 _get_color( &(g_config.caps_lock_indicator.color), value_data );
1985 case id_caps_lock_indicator_row_col:
1987 backlight_get_indicator_row_col( g_config.caps_lock_indicator.index, &(value_data[0]), &(value_data[1]) );
1990 case id_layer_1_indicator_color:
1992 _get_color( &(g_config.layer_1_indicator.color), value_data );
1995 case id_layer_1_indicator_row_col:
1997 backlight_get_indicator_row_col( g_config.layer_1_indicator.index, &(value_data[0]), &(value_data[1]) );
2000 case id_layer_2_indicator_color:
2002 _get_color( &(g_config.layer_2_indicator.color), value_data );
2005 case id_layer_2_indicator_row_col:
2007 backlight_get_indicator_row_col( g_config.layer_2_indicator.index, &(value_data[0]), &(value_data[1]) );
2010 case id_layer_3_indicator_color:
2012 _get_color( &(g_config.layer_3_indicator.color), value_data );
2015 case id_layer_3_indicator_row_col:
2017 backlight_get_indicator_row_col( g_config.layer_3_indicator.index, &(value_data[0]), &(value_data[1]) );
2020 case id_alphas_mods:
2022 for ( int i=0; i<5; i++ )
2024 *(value_data+i*2) = g_config.alphas_mods[i] >> 8;
2025 *(value_data+i*2+1) = g_config.alphas_mods[i] & 0xFF;
2028 #if defined(RGB_BACKLIGHT_M6_B)
2029 case id_custom_color:
2031 uint8_t index = value_data[0];
2032 if ( index >= 0 && index <= 6 )
2034 _get_color( &(g_config.custom_color[index]), &(value_data[1]) );
2041 void backlight_config_set_alphas_mods( uint16_t *alphas_mods )
2043 for ( int i=0; i<5; i++ )
2045 g_config.alphas_mods[i] = alphas_mods[i];
2048 backlight_config_save();
2051 void backlight_config_load(void)
2053 eeprom_read_block( &g_config, ((void*)RGB_BACKLIGHT_CONFIG_EEPROM_ADDR), sizeof(backlight_config) );
2056 void backlight_config_save(void)
2058 eeprom_update_block( &g_config, ((void*)RGB_BACKLIGHT_CONFIG_EEPROM_ADDR), sizeof(backlight_config) );
2061 void backlight_init_drivers(void)
2066 #if defined(RGB_BACKLIGHT_M6_B)
2068 #elif defined(RGB_BACKLIGHT_HS60)
2069 IS31FL3733_init( ISSI_ADDR_1, 0 );
2071 for ( int index = 0; index < DRIVER_LED_TOTAL; index++ )
2073 #if defined(HS60_ANSI)
2074 bool enabled = !( ( index == 48-1 ) || //LA48
2075 ( index == 51-1 ) || //LA51
2076 ( index == 61-1 ) ); //LA61
2077 #elif defined(HS60_HHKB)
2078 bool enabled = !( ( index == 61-1 ) || //LA61
2079 ( index == 62-1 ) ); //LA62
2081 bool enabled = !( ( index == 51-1 ) || //LA51
2082 ( index == 61-1 ) ); //LA61
2084 // This only caches it for later
2085 IS31FL3733_set_led_control_register( index, enabled, enabled, enabled );
2087 // This actually updates the LED drivers
2088 IS31FL3733_update_led_control_registers( ISSI_ADDR_1, 0 );
2089 #elif defined(RGB_BACKLIGHT_NK65)
2090 IS31FL3733_init( ISSI_ADDR_1, 0 );
2091 IS31FL3733_init( ISSI_ADDR_2, 0 );
2093 for ( int index = 0; index < DRIVER_LED_TOTAL; index++ )
2095 bool enabled = !( ( index == 61-1 ) || //LA61
2096 ( index > 6+64-1 ) ); //LB7-LB64
2097 // This only caches it for later
2098 IS31FL3733_set_led_control_register( index, enabled, enabled, enabled );
2100 IS31FL3733_set_led_control_register( 7+64-1, 0, 1, 0 ); //Enable LB7 green enable for indicators
2101 // This actually updates the LED drivers
2102 IS31FL3733_update_led_control_registers( ISSI_ADDR_1, 0 );
2103 IS31FL3733_update_led_control_registers( ISSI_ADDR_2, 1 );
2105 IS31FL3731_init( ISSI_ADDR_1 );
2106 IS31FL3731_init( ISSI_ADDR_2 );
2108 #if defined(RGB_BACKLIGHT_U80_A)
2109 IS31FL3731_init( ISSI_ADDR_3 );
2112 // Experimental feature, not in configuration yet
2113 #if defined(RGB_BACKLIGHT_ZEAL60)
2114 bool disable_spacebar_stab_leds = false;
2117 for ( int index = 0; index < DRIVER_LED_TOTAL; index++ )
2119 // OR the possible "disabled" cases together, then NOT the result to get the enabled state
2120 // LC6 LD13 not present on Zeal65
2121 #if defined(RGB_BACKLIGHT_ZEAL65)
2122 bool enabled = !( ( index == 18+5 && !g_config.use_split_backspace ) || // LB5
2123 ( index == 36+6 ) || // LC6
2124 ( index == 54+13 ) ); // LD13
2125 #elif defined(RGB_BACKLIGHT_KOYU)
2126 bool enabled = !( ( index == 36+15 ) || // LC15
2127 ( index == 54+13 ) || // LD13
2128 ( index == 54+17 ) ); // LD17
2129 #elif defined(RGB_BACKLIGHT_M60_A)
2131 // LB6 LB7 LB8 LB15 LB16 LB17 not present on M60-A
2132 ( index == 18+6 ) || // LB6
2133 ( index == 18+7 ) || // LB7
2134 ( index == 18+8 ) || // LB8
2135 ( index == 18+15 ) || // LB15
2136 ( index == 18+16 ) || // LB16
2137 ( index == 18+17 ) || // LB17
2138 // HHKB blockers (LC17, LD17) and ISO extra keys (LC15,LD13) not present on M60-A
2139 ( index == 36+17 ) || // LC17
2140 ( index == 54+17 ) || // LD17
2141 ( index == 36+15 ) || // LC15
2142 ( index == 54+13 ) ); // LD13
2143 #elif defined(RGB_BACKLIGHT_ZEAL60)
2144 // LB6 LB7 LB8 LB15 LB16 LB17 not present on Zeal60
2145 bool enabled = !( ( index == 18+5 && !g_config.use_split_backspace ) || // LB5
2146 ( index == 36+15 && !g_config.use_split_left_shift ) || // LC15
2147 ( index == 54+8 && !g_config.use_split_right_shift ) || // LD8
2148 ( index == 54+13 && g_config.use_7u_spacebar ) || // LD13
2149 ( index == 36+17 && g_config.disable_hhkb_blocker_leds ) || // LC17
2150 ( index == 54+17 && g_config.disable_hhkb_blocker_leds ) || // LD17
2151 ( index == 18+6 ) || // LB6
2152 ( index == 18+7 ) || // LB7
2153 ( index == 18+8 ) || // LB8
2154 ( index == 18+15 ) || // LB15
2155 ( index == 18+16 ) || // LB16
2156 ( index == 18+17 ) || // LB17
2157 ( index == 36+6 && disable_spacebar_stab_leds ) || // LC6
2158 ( index == 54+13 && disable_spacebar_stab_leds ) || // LD13
2159 ( index == 54+14 && disable_spacebar_stab_leds && g_config.use_7u_spacebar ) ); // LD14
2160 #elif defined(RGB_BACKLIGHT_U80_A)
2161 // LB5, LB6, LB7, LB8, LB15, LB16, LB17, LC15, LD8, LD13, LE0-LE8, LF13
2163 ( index == 18+5 ) || // LB5
2164 ( index == 18+6 ) || // LB6
2165 ( index == 18+7 ) || // LB7
2166 ( index == 18+8 ) || // LB8
2167 ( index == 18+15 ) || // LB15
2168 ( index == 18+16 ) || // LB16
2169 ( index == 18+16 ) || // LB17
2170 ( index == 36+15 ) || // LC15
2171 ( index == 54+8 ) || // LD8
2172 ( index == 54+13 ) || // LD13
2173 ( index >= 72+0 && index <= 72+8 ) || // LE0-LE8
2174 ( index == 90+13 ) ); // LF13
2176 // This only caches it for later
2177 IS31FL3731_set_led_control_register( index, enabled, enabled, enabled );
2179 // This actually updates the LED drivers
2180 IS31FL3731_update_led_control_registers( ISSI_ADDR_1, 0 );
2181 IS31FL3731_update_led_control_registers( ISSI_ADDR_2, 1 );
2182 #if defined(RGB_BACKLIGHT_U80_A)
2183 IS31FL3731_update_led_control_registers( ISSI_ADDR_3, 2 );
2185 #endif // !defined(RGB_BACKLIGHT_M6_B)
2187 // TODO: put the 1 second startup delay here?
2189 // clear the key hits
2190 for ( int led=0; led<BACKLIGHT_LED_COUNT; led++ )
2192 g_key_hit[led] = 255;
2196 bool process_record_backlight(uint16_t keycode, keyrecord_t *record)
2198 // Record keypresses for backlight effects
2199 if ( record->event.pressed )
2201 backlight_set_key_hit( record->event.key.row, record->event.key.col );
2207 if (record->event.pressed)
2209 backlight_brightness_increase();
2214 if (record->event.pressed)
2216 backlight_brightness_decrease();
2221 if (record->event.pressed)
2223 backlight_effect_increase();
2228 if (record->event.pressed)
2230 backlight_effect_decrease();
2235 if (record->event.pressed)
2237 backlight_effect_speed_increase();
2242 if (record->event.pressed)
2244 backlight_effect_speed_decrease();
2249 if (record->event.pressed)
2251 backlight_color_1_hue_increase();
2256 if (record->event.pressed)
2258 backlight_color_1_hue_decrease();
2263 if (record->event.pressed)
2265 backlight_color_1_sat_increase();
2270 if (record->event.pressed)
2272 backlight_color_1_sat_decrease();
2278 if (record->event.pressed)
2280 backlight_color_2_hue_increase();
2285 if (record->event.pressed)
2287 backlight_color_2_hue_decrease();
2292 if (record->event.pressed)
2294 backlight_color_2_sat_increase();
2299 if (record->event.pressed)
2301 backlight_color_2_sat_decrease();
2311 // Deals with the messy details of incrementing an integer
2312 uint8_t increment( uint8_t value, uint8_t step, uint8_t min, uint8_t max )
2314 int16_t new_value = value;
2316 return MIN( MAX( new_value, min ), max );
2319 uint8_t decrement( uint8_t value, uint8_t step, uint8_t min, uint8_t max )
2321 int16_t new_value = value;
2323 return MIN( MAX( new_value, min ), max );
2326 void backlight_effect_increase(void)
2328 g_config.effect = increment( g_config.effect, 1, 0, BACKLIGHT_EFFECT_MAX );
2329 backlight_config_save();
2332 void backlight_effect_decrease(void)
2334 g_config.effect = decrement( g_config.effect, 1, 0, BACKLIGHT_EFFECT_MAX );
2335 backlight_config_save();
2338 void backlight_effect_speed_increase(void)
2340 g_config.effect_speed = increment( g_config.effect_speed, 1, 0, 3 );
2341 backlight_config_save();
2344 void backlight_effect_speed_decrease(void)
2346 g_config.effect_speed = decrement( g_config.effect_speed, 1, 0, 3 );
2347 backlight_config_save();
2350 void backlight_brightness_increase(void)
2352 g_config.brightness = increment( g_config.brightness, 8, 0, 255 );
2353 backlight_config_save();
2356 void backlight_brightness_decrease(void)
2358 g_config.brightness = decrement( g_config.brightness, 8, 0, 255 );
2359 backlight_config_save();
2362 void backlight_color_1_hue_increase(void)
2364 g_config.color_1.h = increment( g_config.color_1.h, 8, 0, 255 );
2365 backlight_config_save();
2368 void backlight_color_1_hue_decrease(void)
2370 g_config.color_1.h = decrement( g_config.color_1.h, 8, 0, 255 );
2371 backlight_config_save();
2374 void backlight_color_1_sat_increase(void)
2376 g_config.color_1.s = increment( g_config.color_1.s, 8, 0, 255 );
2377 backlight_config_save();
2380 void backlight_color_1_sat_decrease(void)
2382 g_config.color_1.s = decrement( g_config.color_1.s, 8, 0, 255 );
2383 backlight_config_save();
2386 void backlight_color_2_hue_increase(void)
2388 g_config.color_2.h = increment( g_config.color_2.h, 8, 0, 255 );
2389 backlight_config_save();
2392 void backlight_color_2_hue_decrease(void)
2394 g_config.color_2.h = decrement( g_config.color_2.h, 8, 0, 255 );
2395 backlight_config_save();
2398 void backlight_color_2_sat_increase(void)
2400 g_config.color_2.s = increment( g_config.color_2.s, 8, 0, 255 );
2401 backlight_config_save();
2404 void backlight_color_2_sat_decrease(void)
2406 g_config.color_2.s = decrement( g_config.color_2.s, 8, 0, 255 );
2407 backlight_config_save();
2410 #if defined(RGB_DEBUGGING_ONLY)
2411 void backlight_test_led( uint8_t index, bool red, bool green, bool blue )
2413 for ( int i=0; i<BACKLIGHT_LED_COUNT; i++ )
2417 IS31FL3731_set_led_control_register( i, red, green, blue );
2421 IS31FL3731_set_led_control_register( i, false, false, false );
2426 void backlight_debug_led( bool state )
2441 #endif // defined(RGB_DEBUGGING_ONLY)