Add rules.mk defaults for f103,f072,f042 (#7704)
[jackhill/qmk/firmware.git] / quantum / rgblight.c
1 /* Copyright 2016-2017 Yang Liu
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 */
16 #include <math.h>
17 #include <string.h>
18 #ifdef __AVR__
19 # include <avr/eeprom.h>
20 # include <avr/interrupt.h>
21 #endif
22 #ifdef STM32_EEPROM_ENABLE
23 # include "hal.h"
24 # include "eeprom.h"
25 # include "eeprom_stm32.h"
26 #endif
27 #include "wait.h"
28 #include "progmem.h"
29 #include "timer.h"
30 #include "rgblight.h"
31 #include "color.h"
32 #include "debug.h"
33 #include "led_tables.h"
34 #include "lib/lib8tion/lib8tion.h"
35 #ifdef VELOCIKEY_ENABLE
36 # include "velocikey.h"
37 #endif
38
39 #ifdef RGBLIGHT_SPLIT
40 /* for split keyboard */
41 # define RGBLIGHT_SPLIT_SET_CHANGE_MODE rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_MODE
42 # define RGBLIGHT_SPLIT_SET_CHANGE_HSVS rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_HSVS
43 # define RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS rgblight_status.change_flags |= (RGBLIGHT_STATUS_CHANGE_MODE | RGBLIGHT_STATUS_CHANGE_HSVS)
44 # define RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_TIMER
45 # define RGBLIGHT_SPLIT_ANIMATION_TICK rgblight_status.change_flags |= RGBLIGHT_STATUS_ANIMATION_TICK
46 #else
47 # define RGBLIGHT_SPLIT_SET_CHANGE_MODE
48 # define RGBLIGHT_SPLIT_SET_CHANGE_HSVS
49 # define RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS
50 # define RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE
51 # define RGBLIGHT_SPLIT_ANIMATION_TICK
52 #endif
53
54 #define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_##sym,
55 #define _RGBM_SINGLE_DYNAMIC(sym)
56 #define _RGBM_MULTI_STATIC(sym) RGBLIGHT_MODE_##sym,
57 #define _RGBM_MULTI_DYNAMIC(sym)
58 #define _RGBM_TMP_STATIC(sym, msym) RGBLIGHT_MODE_##sym,
59 #define _RGBM_TMP_DYNAMIC(sym, msym)
60 static uint8_t static_effect_table[] = {
61 #include "rgblight_modes.h"
62 };
63
64 #define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_##sym,
65 #define _RGBM_SINGLE_DYNAMIC(sym) RGBLIGHT_MODE_##sym,
66 #define _RGBM_MULTI_STATIC(sym) RGBLIGHT_MODE_##sym,
67 #define _RGBM_MULTI_DYNAMIC(sym) RGBLIGHT_MODE_##sym,
68 #define _RGBM_TMP_STATIC(sym, msym) RGBLIGHT_MODE_##msym,
69 #define _RGBM_TMP_DYNAMIC(sym, msym) RGBLIGHT_MODE_##msym,
70 static uint8_t mode_base_table[] = {
71 0, // RGBLIGHT_MODE_zero
72 #include "rgblight_modes.h"
73 };
74
75 static inline int is_static_effect(uint8_t mode) { return memchr(static_effect_table, mode, sizeof(static_effect_table)) != NULL; }
76
77 #ifdef RGBLIGHT_LED_MAP
78 const uint8_t led_map[] PROGMEM = RGBLIGHT_LED_MAP;
79 #endif
80
81 #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT
82 __attribute__((weak)) const uint8_t RGBLED_GRADIENT_RANGES[] PROGMEM = {255, 170, 127, 85, 64};
83 #endif
84
85 rgblight_config_t rgblight_config;
86 rgblight_status_t rgblight_status = {.timer_enabled = false};
87 bool is_rgblight_initialized = false;
88
89 #ifdef RGBLIGHT_USE_TIMER
90 animation_status_t animation_status = {};
91 #endif
92
93 #ifndef LED_ARRAY
94 LED_TYPE led[RGBLED_NUM];
95 # define LED_ARRAY led
96 #endif
97
98 static uint8_t clipping_start_pos = 0;
99 static uint8_t clipping_num_leds = RGBLED_NUM;
100 static uint8_t effect_start_pos = 0;
101 static uint8_t effect_end_pos = RGBLED_NUM;
102 static uint8_t effect_num_leds = RGBLED_NUM;
103
104 void rgblight_set_clipping_range(uint8_t start_pos, uint8_t num_leds) {
105 clipping_start_pos = start_pos;
106 clipping_num_leds = num_leds;
107 }
108
109 void rgblight_set_effect_range(uint8_t start_pos, uint8_t num_leds) {
110 if (start_pos >= RGBLED_NUM) return;
111 if (start_pos + num_leds > RGBLED_NUM) return;
112 effect_start_pos = start_pos;
113 effect_end_pos = start_pos + num_leds;
114 effect_num_leds = num_leds;
115 }
116
117 void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) {
118 HSV hsv = {hue, sat, val};
119 RGB rgb = hsv_to_rgb(hsv);
120 setrgb(rgb.r, rgb.g, rgb.b, led1);
121 }
122
123 void sethsv(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { sethsv_raw(hue, sat, val > RGBLIGHT_LIMIT_VAL ? RGBLIGHT_LIMIT_VAL : val, led1); }
124
125 void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1) {
126 (*led1).r = r;
127 (*led1).g = g;
128 (*led1).b = b;
129 #ifdef RGBW
130 (*led1).w = 0;
131 #endif
132 }
133
134 void rgblight_check_config(void) {
135 /* Add some out of bound checks for RGB light config */
136
137 if (rgblight_config.mode < RGBLIGHT_MODE_STATIC_LIGHT) {
138 rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT;
139 } else if (rgblight_config.mode > RGBLIGHT_MODES) {
140 rgblight_config.mode = RGBLIGHT_MODES;
141 }
142
143 if (rgblight_config.val > RGBLIGHT_LIMIT_VAL) {
144 rgblight_config.val = RGBLIGHT_LIMIT_VAL;
145 }
146 }
147
148 uint32_t eeconfig_read_rgblight(void) {
149 #if defined(__AVR__) || defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE)
150 return eeprom_read_dword(EECONFIG_RGBLIGHT);
151 #else
152 return 0;
153 #endif
154 }
155
156 void eeconfig_update_rgblight(uint32_t val) {
157 #if defined(__AVR__) || defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE)
158 rgblight_check_config();
159 eeprom_update_dword(EECONFIG_RGBLIGHT, val);
160 #endif
161 }
162
163 void eeconfig_update_rgblight_default(void) {
164 rgblight_config.enable = 1;
165 rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT;
166 rgblight_config.hue = 0;
167 rgblight_config.sat = UINT8_MAX;
168 rgblight_config.val = RGBLIGHT_LIMIT_VAL;
169 rgblight_config.speed = 0;
170 RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS;
171 eeconfig_update_rgblight(rgblight_config.raw);
172 }
173
174 void eeconfig_debug_rgblight(void) {
175 dprintf("rgblight_config EEPROM:\n");
176 dprintf("rgblight_config.enable = %d\n", rgblight_config.enable);
177 dprintf("rghlight_config.mode = %d\n", rgblight_config.mode);
178 dprintf("rgblight_config.hue = %d\n", rgblight_config.hue);
179 dprintf("rgblight_config.sat = %d\n", rgblight_config.sat);
180 dprintf("rgblight_config.val = %d\n", rgblight_config.val);
181 dprintf("rgblight_config.speed = %d\n", rgblight_config.speed);
182 }
183
184 void rgblight_init(void) {
185 /* if already initialized, don't do it again.
186 If you must do it again, extern this and set to false, first.
187 This is a dirty, dirty hack until proper hooks can be added for keyboard startup. */
188 if (is_rgblight_initialized) {
189 return;
190 }
191
192 dprintf("rgblight_init called.\n");
193 dprintf("rgblight_init start!\n");
194 if (!eeconfig_is_enabled()) {
195 dprintf("rgblight_init eeconfig is not enabled.\n");
196 eeconfig_init();
197 eeconfig_update_rgblight_default();
198 }
199 rgblight_config.raw = eeconfig_read_rgblight();
200 RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS;
201 if (!rgblight_config.mode) {
202 dprintf("rgblight_init rgblight_config.mode = 0. Write default values to EEPROM.\n");
203 eeconfig_update_rgblight_default();
204 rgblight_config.raw = eeconfig_read_rgblight();
205 }
206 rgblight_check_config();
207
208 eeconfig_debug_rgblight(); // display current eeprom values
209
210 #ifdef RGBLIGHT_USE_TIMER
211 rgblight_timer_init(); // setup the timer
212 #endif
213
214 if (rgblight_config.enable) {
215 rgblight_mode_noeeprom(rgblight_config.mode);
216 }
217
218 is_rgblight_initialized = true;
219 }
220
221 uint32_t rgblight_read_dword(void) { return rgblight_config.raw; }
222
223 void rgblight_update_dword(uint32_t dword) {
224 RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS;
225 rgblight_config.raw = dword;
226 if (rgblight_config.enable)
227 rgblight_mode_noeeprom(rgblight_config.mode);
228 else {
229 #ifdef RGBLIGHT_USE_TIMER
230 rgblight_timer_disable();
231 #endif
232 rgblight_set();
233 }
234 }
235
236 void rgblight_increase(void) {
237 uint8_t mode = 0;
238 if (rgblight_config.mode < RGBLIGHT_MODES) {
239 mode = rgblight_config.mode + 1;
240 }
241 rgblight_mode(mode);
242 }
243 void rgblight_decrease(void) {
244 uint8_t mode = 0;
245 // Mode will never be < 1. If it ever is, eeprom needs to be initialized.
246 if (rgblight_config.mode > RGBLIGHT_MODE_STATIC_LIGHT) {
247 mode = rgblight_config.mode - 1;
248 }
249 rgblight_mode(mode);
250 }
251 void rgblight_step_helper(bool write_to_eeprom) {
252 uint8_t mode = 0;
253 mode = rgblight_config.mode + 1;
254 if (mode > RGBLIGHT_MODES) {
255 mode = 1;
256 }
257 rgblight_mode_eeprom_helper(mode, write_to_eeprom);
258 }
259 void rgblight_step_noeeprom(void) { rgblight_step_helper(false); }
260 void rgblight_step(void) { rgblight_step_helper(true); }
261 void rgblight_step_reverse_helper(bool write_to_eeprom) {
262 uint8_t mode = 0;
263 mode = rgblight_config.mode - 1;
264 if (mode < 1) {
265 mode = RGBLIGHT_MODES;
266 }
267 rgblight_mode_eeprom_helper(mode, write_to_eeprom);
268 }
269 void rgblight_step_reverse_noeeprom(void) { rgblight_step_reverse_helper(false); }
270 void rgblight_step_reverse(void) { rgblight_step_reverse_helper(true); }
271
272 uint8_t rgblight_get_mode(void) {
273 if (!rgblight_config.enable) {
274 return false;
275 }
276
277 return rgblight_config.mode;
278 }
279
280 void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) {
281 if (!rgblight_config.enable) {
282 return;
283 }
284 if (mode < RGBLIGHT_MODE_STATIC_LIGHT) {
285 rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT;
286 } else if (mode > RGBLIGHT_MODES) {
287 rgblight_config.mode = RGBLIGHT_MODES;
288 } else {
289 rgblight_config.mode = mode;
290 }
291 RGBLIGHT_SPLIT_SET_CHANGE_MODE;
292 if (write_to_eeprom) {
293 eeconfig_update_rgblight(rgblight_config.raw);
294 dprintf("rgblight mode [EEPROM]: %u\n", rgblight_config.mode);
295 } else {
296 dprintf("rgblight mode [NOEEPROM]: %u\n", rgblight_config.mode);
297 }
298 if (is_static_effect(rgblight_config.mode)) {
299 #ifdef RGBLIGHT_USE_TIMER
300 rgblight_timer_disable();
301 #endif
302 } else {
303 #ifdef RGBLIGHT_USE_TIMER
304 rgblight_timer_enable();
305 #endif
306 }
307 #ifdef RGBLIGHT_USE_TIMER
308 animation_status.restart = true;
309 #endif
310 rgblight_sethsv_noeeprom(rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
311 }
312
313 void rgblight_mode(uint8_t mode) { rgblight_mode_eeprom_helper(mode, true); }
314
315 void rgblight_mode_noeeprom(uint8_t mode) { rgblight_mode_eeprom_helper(mode, false); }
316
317 void rgblight_toggle(void) {
318 dprintf("rgblight toggle [EEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable);
319 if (rgblight_config.enable) {
320 rgblight_disable();
321 } else {
322 rgblight_enable();
323 }
324 }
325
326 void rgblight_toggle_noeeprom(void) {
327 dprintf("rgblight toggle [NOEEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable);
328 if (rgblight_config.enable) {
329 rgblight_disable_noeeprom();
330 } else {
331 rgblight_enable_noeeprom();
332 }
333 }
334
335 void rgblight_enable(void) {
336 rgblight_config.enable = 1;
337 // No need to update EEPROM here. rgblight_mode() will do that, actually
338 // eeconfig_update_rgblight(rgblight_config.raw);
339 dprintf("rgblight enable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
340 rgblight_mode(rgblight_config.mode);
341 }
342
343 void rgblight_enable_noeeprom(void) {
344 rgblight_config.enable = 1;
345 dprintf("rgblight enable [NOEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
346 rgblight_mode_noeeprom(rgblight_config.mode);
347 }
348
349 void rgblight_disable(void) {
350 rgblight_config.enable = 0;
351 eeconfig_update_rgblight(rgblight_config.raw);
352 dprintf("rgblight disable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
353 #ifdef RGBLIGHT_USE_TIMER
354 rgblight_timer_disable();
355 #endif
356 RGBLIGHT_SPLIT_SET_CHANGE_MODE;
357 wait_ms(50);
358 rgblight_set();
359 }
360
361 void rgblight_disable_noeeprom(void) {
362 rgblight_config.enable = 0;
363 dprintf("rgblight disable [NOEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
364 #ifdef RGBLIGHT_USE_TIMER
365 rgblight_timer_disable();
366 #endif
367 RGBLIGHT_SPLIT_SET_CHANGE_MODE;
368 wait_ms(50);
369 rgblight_set();
370 }
371
372 void rgblight_increase_hue_helper(bool write_to_eeprom) {
373 uint8_t hue = rgblight_config.hue + RGBLIGHT_HUE_STEP;
374 rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom);
375 }
376 void rgblight_increase_hue_noeeprom(void) { rgblight_increase_hue_helper(false); }
377 void rgblight_increase_hue(void) { rgblight_increase_hue_helper(true); }
378 void rgblight_decrease_hue_helper(bool write_to_eeprom) {
379 uint8_t hue = rgblight_config.hue - RGBLIGHT_HUE_STEP;
380 rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom);
381 }
382 void rgblight_decrease_hue_noeeprom(void) { rgblight_decrease_hue_helper(false); }
383 void rgblight_decrease_hue(void) { rgblight_decrease_hue_helper(true); }
384 void rgblight_increase_sat_helper(bool write_to_eeprom) {
385 uint8_t sat = qadd8(rgblight_config.sat, RGBLIGHT_SAT_STEP);
386 rgblight_sethsv_eeprom_helper(rgblight_config.hue, sat, rgblight_config.val, write_to_eeprom);
387 }
388 void rgblight_increase_sat_noeeprom(void) { rgblight_increase_sat_helper(false); }
389 void rgblight_increase_sat(void) { rgblight_increase_sat_helper(true); }
390 void rgblight_decrease_sat_helper(bool write_to_eeprom) {
391 uint8_t sat = qsub8(rgblight_config.sat, RGBLIGHT_SAT_STEP);
392 rgblight_sethsv_eeprom_helper(rgblight_config.hue, sat, rgblight_config.val, write_to_eeprom);
393 }
394 void rgblight_decrease_sat_noeeprom(void) { rgblight_decrease_sat_helper(false); }
395 void rgblight_decrease_sat(void) { rgblight_decrease_sat_helper(true); }
396 void rgblight_increase_val_helper(bool write_to_eeprom) {
397 uint8_t val = qadd8(rgblight_config.val, RGBLIGHT_VAL_STEP);
398 rgblight_sethsv_eeprom_helper(rgblight_config.hue, rgblight_config.sat, val, write_to_eeprom);
399 }
400 void rgblight_increase_val_noeeprom(void) { rgblight_increase_val_helper(false); }
401 void rgblight_increase_val(void) { rgblight_increase_val_helper(true); }
402 void rgblight_decrease_val_helper(bool write_to_eeprom) {
403 uint8_t val = qsub8(rgblight_config.val, RGBLIGHT_VAL_STEP);
404 rgblight_sethsv_eeprom_helper(rgblight_config.hue, rgblight_config.sat, val, write_to_eeprom);
405 }
406 void rgblight_decrease_val_noeeprom(void) { rgblight_decrease_val_helper(false); }
407 void rgblight_decrease_val(void) { rgblight_decrease_val_helper(true); }
408 void rgblight_increase_speed(void) {
409 if (rgblight_config.speed < 3) rgblight_config.speed++;
410 // RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED?
411 eeconfig_update_rgblight(rgblight_config.raw); // EECONFIG needs to be increased to support this
412 }
413
414 void rgblight_decrease_speed(void) {
415 if (rgblight_config.speed > 0) rgblight_config.speed--;
416 // RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED??
417 eeconfig_update_rgblight(rgblight_config.raw); // EECONFIG needs to be increased to support this
418 }
419
420 void rgblight_sethsv_noeeprom_old(uint8_t hue, uint8_t sat, uint8_t val) {
421 if (rgblight_config.enable) {
422 LED_TYPE tmp_led;
423 sethsv(hue, sat, val, &tmp_led);
424 rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b);
425 }
426 }
427
428 void rgblight_sethsv_eeprom_helper(uint8_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom) {
429 if (rgblight_config.enable) {
430 rgblight_status.base_mode = mode_base_table[rgblight_config.mode];
431 if (rgblight_config.mode == RGBLIGHT_MODE_STATIC_LIGHT) {
432 // same static color
433 LED_TYPE tmp_led;
434 sethsv(hue, sat, val, &tmp_led);
435 rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b);
436 } else {
437 // all LEDs in same color
438 if (1 == 0) { // dummy
439 }
440 #ifdef RGBLIGHT_EFFECT_BREATHING
441 else if (rgblight_status.base_mode == RGBLIGHT_MODE_BREATHING) {
442 // breathing mode, ignore the change of val, use in memory value instead
443 val = rgblight_config.val;
444 }
445 #endif
446 #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD
447 else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_MOOD) {
448 // rainbow mood, ignore the change of hue
449 hue = rgblight_config.hue;
450 }
451 #endif
452 #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL
453 else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_SWIRL) {
454 // rainbow swirl, ignore the change of hue
455 hue = rgblight_config.hue;
456 }
457 #endif
458 #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT
459 else if (rgblight_status.base_mode == RGBLIGHT_MODE_STATIC_GRADIENT) {
460 // static gradient
461 uint8_t delta = rgblight_config.mode - rgblight_status.base_mode;
462 bool direction = (delta % 2) == 0;
463 # ifdef __AVR__
464 // probably due to how pgm_read_word is defined for ARM, but the ARM compiler really hates this line
465 uint8_t range = pgm_read_word(&RGBLED_GRADIENT_RANGES[delta / 2]);
466 # else
467 uint8_t range = RGBLED_GRADIENT_RANGES[delta / 2];
468 # endif
469 for (uint8_t i = 0; i < effect_num_leds; i++) {
470 uint8_t _hue = ((uint16_t)i * (uint16_t)range) / effect_num_leds;
471 if (direction) {
472 _hue = hue + _hue;
473 } else {
474 _hue = hue - _hue;
475 }
476 dprintf("rgblight rainbow set hsv: %d,%d,%d,%u\n", i, _hue, direction, range);
477 sethsv(_hue, sat, val, (LED_TYPE *)&led[i + effect_start_pos]);
478 }
479 rgblight_set();
480 }
481 #endif
482 }
483 #ifdef RGBLIGHT_SPLIT
484 if (rgblight_config.hue != hue || rgblight_config.sat != sat || rgblight_config.val != val) {
485 RGBLIGHT_SPLIT_SET_CHANGE_HSVS;
486 }
487 #endif
488 rgblight_config.hue = hue;
489 rgblight_config.sat = sat;
490 rgblight_config.val = val;
491 if (write_to_eeprom) {
492 eeconfig_update_rgblight(rgblight_config.raw);
493 dprintf("rgblight set hsv [EEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
494 } else {
495 dprintf("rgblight set hsv [NOEEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
496 }
497 }
498 }
499
500 void rgblight_sethsv(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_sethsv_eeprom_helper(hue, sat, val, true); }
501
502 void rgblight_sethsv_noeeprom(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_sethsv_eeprom_helper(hue, sat, val, false); }
503
504 uint8_t rgblight_get_hue(void) { return rgblight_config.hue; }
505
506 uint8_t rgblight_get_sat(void) { return rgblight_config.sat; }
507
508 uint8_t rgblight_get_val(void) { return rgblight_config.val; }
509
510 void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b) {
511 if (!rgblight_config.enable) {
512 return;
513 }
514
515 for (uint8_t i = effect_start_pos; i < effect_end_pos; i++) {
516 led[i].r = r;
517 led[i].g = g;
518 led[i].b = b;
519 #ifdef RGBW
520 led[i].w = 0;
521 #endif
522 }
523 rgblight_set();
524 }
525
526 void rgblight_setrgb_at(uint8_t r, uint8_t g, uint8_t b, uint8_t index) {
527 if (!rgblight_config.enable || index >= RGBLED_NUM) {
528 return;
529 }
530
531 led[index].r = r;
532 led[index].g = g;
533 led[index].b = b;
534 #ifdef RGBW
535 led[index].w = 0;
536 #endif
537 rgblight_set();
538 }
539
540 void rgblight_sethsv_at(uint8_t hue, uint8_t sat, uint8_t val, uint8_t index) {
541 if (!rgblight_config.enable) {
542 return;
543 }
544
545 LED_TYPE tmp_led;
546 sethsv(hue, sat, val, &tmp_led);
547 rgblight_setrgb_at(tmp_led.r, tmp_led.g, tmp_led.b, index);
548 }
549
550 #if defined(RGBLIGHT_EFFECT_BREATHING) || defined(RGBLIGHT_EFFECT_RAINBOW_MOOD) || defined(RGBLIGHT_EFFECT_RAINBOW_SWIRL) || defined(RGBLIGHT_EFFECT_SNAKE) || defined(RGBLIGHT_EFFECT_KNIGHT)
551
552 static uint8_t get_interval_time(const uint8_t *default_interval_address, uint8_t velocikey_min, uint8_t velocikey_max) {
553 return
554 # ifdef VELOCIKEY_ENABLE
555 velocikey_enabled() ? velocikey_match_speed(velocikey_min, velocikey_max) :
556 # endif
557 pgm_read_byte(default_interval_address);
558 }
559
560 #endif
561
562 void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8_t end) {
563 if (!rgblight_config.enable || start < 0 || start >= end || end > RGBLED_NUM) {
564 return;
565 }
566
567 for (uint8_t i = start; i < end; i++) {
568 led[i].r = r;
569 led[i].g = g;
570 led[i].b = b;
571 #ifdef RGBW
572 led[i].w = 0;
573 #endif
574 }
575 rgblight_set();
576 wait_ms(1);
577 }
578
579 void rgblight_sethsv_range(uint8_t hue, uint8_t sat, uint8_t val, uint8_t start, uint8_t end) {
580 if (!rgblight_config.enable) {
581 return;
582 }
583
584 LED_TYPE tmp_led;
585 sethsv(hue, sat, val, &tmp_led);
586 rgblight_setrgb_range(tmp_led.r, tmp_led.g, tmp_led.b, start, end);
587 }
588
589 #ifndef RGBLIGHT_SPLIT
590 void rgblight_setrgb_master(uint8_t r, uint8_t g, uint8_t b) { rgblight_setrgb_range(r, g, b, 0, (uint8_t)RGBLED_NUM / 2); }
591
592 void rgblight_setrgb_slave(uint8_t r, uint8_t g, uint8_t b) { rgblight_setrgb_range(r, g, b, (uint8_t)RGBLED_NUM / 2, (uint8_t)RGBLED_NUM); }
593
594 void rgblight_sethsv_master(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_sethsv_range(hue, sat, val, 0, (uint8_t)RGBLED_NUM / 2); }
595
596 void rgblight_sethsv_slave(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_sethsv_range(hue, sat, val, (uint8_t)RGBLED_NUM / 2, (uint8_t)RGBLED_NUM); }
597 #endif // ifndef RGBLIGHT_SPLIT
598
599 #ifndef RGBLIGHT_CUSTOM_DRIVER
600 void rgblight_set(void) {
601 LED_TYPE *start_led;
602 uint16_t num_leds = clipping_num_leds;
603
604 if (!rgblight_config.enable) {
605 for (uint8_t i = effect_start_pos; i < effect_end_pos; i++) {
606 led[i].r = 0;
607 led[i].g = 0;
608 led[i].b = 0;
609 # ifdef RGBW
610 led[i].w = 0;
611 # endif
612 }
613 }
614 # ifdef RGBLIGHT_LED_MAP
615 LED_TYPE led0[RGBLED_NUM];
616 for (uint8_t i = 0; i < RGBLED_NUM; i++) {
617 led0[i] = led[pgm_read_byte(&led_map[i])];
618 }
619 start_led = led0 + clipping_start_pos;
620 # else
621 start_led = led + clipping_start_pos;
622 # endif
623 ws2812_setleds(start_led, num_leds);
624 }
625 #endif
626
627 #ifdef RGBLIGHT_SPLIT
628 /* for split keyboard master side */
629 uint8_t rgblight_get_change_flags(void) { return rgblight_status.change_flags; }
630
631 void rgblight_clear_change_flags(void) { rgblight_status.change_flags = 0; }
632
633 void rgblight_get_syncinfo(rgblight_syncinfo_t *syncinfo) {
634 syncinfo->config = rgblight_config;
635 syncinfo->status = rgblight_status;
636 }
637
638 /* for split keyboard slave side */
639 void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom) {
640 if (syncinfo->status.change_flags & RGBLIGHT_STATUS_CHANGE_MODE) {
641 if (syncinfo->config.enable) {
642 rgblight_config.enable = 1; // == rgblight_enable_noeeprom();
643 rgblight_mode_eeprom_helper(syncinfo->config.mode, write_to_eeprom);
644 } else {
645 rgblight_disable_noeeprom();
646 }
647 }
648 if (syncinfo->status.change_flags & RGBLIGHT_STATUS_CHANGE_HSVS) {
649 rgblight_sethsv_eeprom_helper(syncinfo->config.hue, syncinfo->config.sat, syncinfo->config.val, write_to_eeprom);
650 // rgblight_config.speed = config->speed; // NEED???
651 }
652 # ifdef RGBLIGHT_USE_TIMER
653 if (syncinfo->status.change_flags & RGBLIGHT_STATUS_CHANGE_TIMER) {
654 if (syncinfo->status.timer_enabled) {
655 rgblight_timer_enable();
656 } else {
657 rgblight_timer_disable();
658 }
659 }
660 # ifndef RGBLIGHT_SPLIT_NO_ANIMATION_SYNC
661 if (syncinfo->status.change_flags & RGBLIGHT_STATUS_ANIMATION_TICK) {
662 animation_status.restart = true;
663 }
664 # endif /* RGBLIGHT_SPLIT_NO_ANIMATION_SYNC */
665 # endif /* RGBLIGHT_USE_TIMER */
666 }
667 #endif /* RGBLIGHT_SPLIT */
668
669 #ifdef RGBLIGHT_USE_TIMER
670
671 typedef void (*effect_func_t)(animation_status_t *anim);
672
673 // Animation timer -- use system timer (AVR Timer0)
674 void rgblight_timer_init(void) {
675 // OLD!!!! Animation timer -- AVR Timer3
676 // static uint8_t rgblight_timer_is_init = 0;
677 // if (rgblight_timer_is_init) {
678 // return;
679 // }
680 // rgblight_timer_is_init = 1;
681 // /* Timer 3 setup */
682 // TCCR3B = _BV(WGM32) // CTC mode OCR3A as TOP
683 // | _BV(CS30); // Clock selelct: clk/1
684 // /* Set TOP value */
685 // uint8_t sreg = SREG;
686 // cli();
687 // OCR3AH = (RGBLED_TIMER_TOP >> 8) & 0xff;
688 // OCR3AL = RGBLED_TIMER_TOP & 0xff;
689 // SREG = sreg;
690
691 rgblight_status.timer_enabled = false;
692 RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE;
693 }
694 void rgblight_timer_enable(void) {
695 if (!is_static_effect(rgblight_config.mode)) {
696 rgblight_status.timer_enabled = true;
697 }
698 animation_status.last_timer = timer_read();
699 RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE;
700 dprintf("rgblight timer enabled.\n");
701 }
702 void rgblight_timer_disable(void) {
703 rgblight_status.timer_enabled = false;
704 RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE;
705 dprintf("rgblight timer disable.\n");
706 }
707 void rgblight_timer_toggle(void) {
708 dprintf("rgblight timer toggle.\n");
709 if (rgblight_status.timer_enabled) {
710 rgblight_timer_disable();
711 } else {
712 rgblight_timer_enable();
713 }
714 }
715
716 void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b) {
717 rgblight_enable();
718 rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT);
719 rgblight_setrgb(r, g, b);
720 }
721
722 static void rgblight_effect_dummy(animation_status_t *anim) {
723 // do nothing
724 /********
725 dprintf("rgblight_task() what happened?\n");
726 dprintf("is_static_effect %d\n", is_static_effect(rgblight_config.mode));
727 dprintf("mode = %d, base_mode = %d, timer_enabled %d, ",
728 rgblight_config.mode, rgblight_status.base_mode,
729 rgblight_status.timer_enabled);
730 dprintf("last_timer = %d\n",anim->last_timer);
731 **/
732 }
733
734 void rgblight_task(void) {
735 if (rgblight_status.timer_enabled) {
736 effect_func_t effect_func = rgblight_effect_dummy;
737 uint16_t interval_time = 2000; // dummy interval
738 uint8_t delta = rgblight_config.mode - rgblight_status.base_mode;
739 animation_status.delta = delta;
740
741 // static light mode, do nothing here
742 if (1 == 0) { // dummy
743 }
744 # ifdef RGBLIGHT_EFFECT_BREATHING
745 else if (rgblight_status.base_mode == RGBLIGHT_MODE_BREATHING) {
746 // breathing mode
747 interval_time = get_interval_time(&RGBLED_BREATHING_INTERVALS[delta], 1, 100);
748 effect_func = rgblight_effect_breathing;
749 }
750 # endif
751 # ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD
752 else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_MOOD) {
753 // rainbow mood mode
754 interval_time = get_interval_time(&RGBLED_RAINBOW_MOOD_INTERVALS[delta], 5, 100);
755 effect_func = rgblight_effect_rainbow_mood;
756 }
757 # endif
758 # ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL
759 else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_SWIRL) {
760 // rainbow swirl mode
761 interval_time = get_interval_time(&RGBLED_RAINBOW_SWIRL_INTERVALS[delta / 2], 1, 100);
762 effect_func = rgblight_effect_rainbow_swirl;
763 }
764 # endif
765 # ifdef RGBLIGHT_EFFECT_SNAKE
766 else if (rgblight_status.base_mode == RGBLIGHT_MODE_SNAKE) {
767 // snake mode
768 interval_time = get_interval_time(&RGBLED_SNAKE_INTERVALS[delta / 2], 1, 200);
769 effect_func = rgblight_effect_snake;
770 }
771 # endif
772 # ifdef RGBLIGHT_EFFECT_KNIGHT
773 else if (rgblight_status.base_mode == RGBLIGHT_MODE_KNIGHT) {
774 // knight mode
775 interval_time = get_interval_time(&RGBLED_KNIGHT_INTERVALS[delta], 5, 100);
776 effect_func = rgblight_effect_knight;
777 }
778 # endif
779 # ifdef RGBLIGHT_EFFECT_CHRISTMAS
780 else if (rgblight_status.base_mode == RGBLIGHT_MODE_CHRISTMAS) {
781 // christmas mode
782 interval_time = RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL;
783 effect_func = (effect_func_t)rgblight_effect_christmas;
784 }
785 # endif
786 # ifdef RGBLIGHT_EFFECT_RGB_TEST
787 else if (rgblight_status.base_mode == RGBLIGHT_MODE_RGB_TEST) {
788 // RGB test mode
789 interval_time = pgm_read_word(&RGBLED_RGBTEST_INTERVALS[0]);
790 effect_func = (effect_func_t)rgblight_effect_rgbtest;
791 }
792 # endif
793 # ifdef RGBLIGHT_EFFECT_ALTERNATING
794 else if (rgblight_status.base_mode == RGBLIGHT_MODE_ALTERNATING) {
795 interval_time = 500;
796 effect_func = (effect_func_t)rgblight_effect_alternating;
797 }
798 # endif
799 if (animation_status.restart) {
800 animation_status.restart = false;
801 animation_status.last_timer = timer_read() - interval_time - 1;
802 animation_status.pos16 = 0; // restart signal to local each effect
803 }
804 if (timer_elapsed(animation_status.last_timer) >= interval_time) {
805 # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
806 static uint16_t report_last_timer = 0;
807 static bool tick_flag = false;
808 uint16_t oldpos16;
809 if (tick_flag) {
810 tick_flag = false;
811 if (timer_elapsed(report_last_timer) >= 30000) {
812 report_last_timer = timer_read();
813 dprintf("rgblight animation tick report to slave\n");
814 RGBLIGHT_SPLIT_ANIMATION_TICK;
815 }
816 }
817 oldpos16 = animation_status.pos16;
818 # endif
819 animation_status.last_timer += interval_time;
820 effect_func(&animation_status);
821 # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
822 if (animation_status.pos16 == 0 && oldpos16 != 0) {
823 tick_flag = true;
824 }
825 # endif
826 }
827 }
828 }
829
830 #endif /* RGBLIGHT_USE_TIMER */
831
832 // Effects
833 #ifdef RGBLIGHT_EFFECT_BREATHING
834
835 # ifndef RGBLIGHT_EFFECT_BREATHE_CENTER
836 # ifndef RGBLIGHT_BREATHE_TABLE_SIZE
837 # define RGBLIGHT_BREATHE_TABLE_SIZE 256 // 256 or 128 or 64
838 # endif
839 # include <rgblight_breathe_table.h>
840 # endif
841
842 __attribute__((weak)) const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5};
843
844 void rgblight_effect_breathing(animation_status_t *anim) {
845 float val;
846
847 // http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/
848 # ifdef RGBLIGHT_EFFECT_BREATHE_TABLE
849 val = pgm_read_byte(&rgblight_effect_breathe_table[anim->pos / table_scale]);
850 # else
851 val = (exp(sin((anim->pos / 255.0) * M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER / M_E) * (RGBLIGHT_EFFECT_BREATHE_MAX / (M_E - 1 / M_E));
852 # endif
853 rgblight_sethsv_noeeprom_old(rgblight_config.hue, rgblight_config.sat, val);
854 anim->pos = (anim->pos + 1);
855 }
856 #endif
857
858 #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD
859 __attribute__((weak)) const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[] PROGMEM = {120, 60, 30};
860
861 void rgblight_effect_rainbow_mood(animation_status_t *anim) {
862 rgblight_sethsv_noeeprom_old(anim->current_hue, rgblight_config.sat, rgblight_config.val);
863 anim->current_hue++;
864 }
865 #endif
866
867 #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL
868 # ifndef RGBLIGHT_RAINBOW_SWIRL_RANGE
869 # define RGBLIGHT_RAINBOW_SWIRL_RANGE 255
870 # endif
871
872 __attribute__((weak)) const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[] PROGMEM = {100, 50, 20};
873
874 void rgblight_effect_rainbow_swirl(animation_status_t *anim) {
875 uint8_t hue;
876 uint8_t i;
877
878 for (i = 0; i < effect_num_leds; i++) {
879 hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / effect_num_leds * i + anim->current_hue);
880 sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + effect_start_pos]);
881 }
882 rgblight_set();
883
884 if (anim->delta % 2) {
885 anim->current_hue++;
886 } else {
887 anim->current_hue--;
888 }
889 }
890 #endif
891
892 #ifdef RGBLIGHT_EFFECT_SNAKE
893 __attribute__((weak)) const uint8_t RGBLED_SNAKE_INTERVALS[] PROGMEM = {100, 50, 20};
894
895 void rgblight_effect_snake(animation_status_t *anim) {
896 static uint8_t pos = 0;
897 uint8_t i, j;
898 int8_t k;
899 int8_t increment = 1;
900
901 if (anim->delta % 2) {
902 increment = -1;
903 }
904
905 # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
906 if (anim->pos == 0) { // restart signal
907 if (increment == 1) {
908 pos = effect_num_leds - 1;
909 } else {
910 pos = 0;
911 }
912 anim->pos = 1;
913 }
914 # endif
915
916 for (i = 0; i < effect_num_leds; i++) {
917 LED_TYPE *ledp = led + i + effect_start_pos;
918 ledp->r = 0;
919 ledp->g = 0;
920 ledp->b = 0;
921 # ifdef RGBW
922 ledp->w = 0;
923 # endif
924 for (j = 0; j < RGBLIGHT_EFFECT_SNAKE_LENGTH; j++) {
925 k = pos + j * increment;
926 if (k > RGBLED_NUM) {
927 k = k % RGBLED_NUM;
928 }
929 if (k < 0) {
930 k = k + effect_num_leds;
931 }
932 if (i == k) {
933 sethsv(rgblight_config.hue, rgblight_config.sat, (uint8_t)(rgblight_config.val * (RGBLIGHT_EFFECT_SNAKE_LENGTH - j) / RGBLIGHT_EFFECT_SNAKE_LENGTH), ledp);
934 }
935 }
936 }
937 rgblight_set();
938 if (increment == 1) {
939 if (pos - 1 < 0) {
940 pos = effect_num_leds - 1;
941 # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
942 anim->pos = 0;
943 # endif
944 } else {
945 pos -= 1;
946 # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
947 anim->pos = 1;
948 # endif
949 }
950 } else {
951 pos = (pos + 1) % effect_num_leds;
952 # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
953 anim->pos = pos;
954 # endif
955 }
956 }
957 #endif
958
959 #ifdef RGBLIGHT_EFFECT_KNIGHT
960 __attribute__((weak)) const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {127, 63, 31};
961
962 void rgblight_effect_knight(animation_status_t *anim) {
963 static int8_t low_bound = 0;
964 static int8_t high_bound = RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1;
965 static int8_t increment = 1;
966 uint8_t i, cur;
967
968 # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
969 if (anim->pos == 0) { // restart signal
970 anim->pos = 1;
971 low_bound = 0;
972 high_bound = RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1;
973 increment = 1;
974 }
975 # endif
976 // Set all the LEDs to 0
977 for (i = effect_start_pos; i < effect_end_pos; i++) {
978 led[i].r = 0;
979 led[i].g = 0;
980 led[i].b = 0;
981 # ifdef RGBW
982 led[i].w = 0;
983 # endif
984 }
985 // Determine which LEDs should be lit up
986 for (i = 0; i < RGBLIGHT_EFFECT_KNIGHT_LED_NUM; i++) {
987 cur = (i + RGBLIGHT_EFFECT_KNIGHT_OFFSET) % effect_num_leds + effect_start_pos;
988
989 if (i >= low_bound && i <= high_bound) {
990 sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[cur]);
991 } else {
992 led[cur].r = 0;
993 led[cur].g = 0;
994 led[cur].b = 0;
995 # ifdef RGBW
996 led[cur].w = 0;
997 # endif
998 }
999 }
1000 rgblight_set();
1001
1002 // Move from low_bound to high_bound changing the direction we increment each
1003 // time a boundary is hit.
1004 low_bound += increment;
1005 high_bound += increment;
1006
1007 if (high_bound <= 0 || low_bound >= RGBLIGHT_EFFECT_KNIGHT_LED_NUM - 1) {
1008 increment = -increment;
1009 # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
1010 if (increment == 1) {
1011 anim->pos = 0;
1012 }
1013 # endif
1014 }
1015 }
1016 #endif
1017
1018 #ifdef RGBLIGHT_EFFECT_CHRISTMAS
1019 void rgblight_effect_christmas(animation_status_t *anim) {
1020 uint8_t hue;
1021 uint8_t i;
1022
1023 anim->current_offset = (anim->current_offset + 1) % 2;
1024 for (i = 0; i < effect_num_leds; i++) {
1025 hue = 0 + ((i / RGBLIGHT_EFFECT_CHRISTMAS_STEP + anim->current_offset) % 2) * 85;
1026 sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + effect_start_pos]);
1027 }
1028 rgblight_set();
1029 }
1030 #endif
1031
1032 #ifdef RGBLIGHT_EFFECT_RGB_TEST
1033 __attribute__((weak)) const uint16_t RGBLED_RGBTEST_INTERVALS[] PROGMEM = {1024};
1034
1035 void rgblight_effect_rgbtest(animation_status_t *anim) {
1036 static uint8_t maxval = 0;
1037 uint8_t g;
1038 uint8_t r;
1039 uint8_t b;
1040
1041 if (maxval == 0) {
1042 LED_TYPE tmp_led;
1043 sethsv(0, 255, RGBLIGHT_LIMIT_VAL, &tmp_led);
1044 maxval = tmp_led.r;
1045 }
1046 g = r = b = 0;
1047 switch (anim->pos) {
1048 case 0:
1049 r = maxval;
1050 break;
1051 case 1:
1052 g = maxval;
1053 break;
1054 case 2:
1055 b = maxval;
1056 break;
1057 }
1058 rgblight_setrgb(r, g, b);
1059 anim->pos = (anim->pos + 1) % 3;
1060 }
1061 #endif
1062
1063 #ifdef RGBLIGHT_EFFECT_ALTERNATING
1064 void rgblight_effect_alternating(animation_status_t *anim) {
1065 for (int i = 0; i < effect_num_leds; i++) {
1066 LED_TYPE *ledp = led + i + effect_start_pos;
1067 if (i < effect_num_leds / 2 && anim->pos) {
1068 sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp);
1069 } else if (i >= effect_num_leds / 2 && !anim->pos) {
1070 sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp);
1071 } else {
1072 sethsv(rgblight_config.hue, rgblight_config.sat, 0, ledp);
1073 }
1074 }
1075 rgblight_set();
1076 anim->pos = (anim->pos + 1) % 2;
1077 }
1078 #endif