aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi ISHII <2170248+mtei@users.noreply.github.com>2019-04-20 07:05:51 +0900
committerDrashna Jaelre <drashna@live.com>2019-04-19 15:05:51 -0700
commitdfab177f889fd6701e5f898c869be1bf3a2d0ef9 (patch)
tree5dd9582cf5271389e931530bf2c8689299b8512d
parentdd64a4e73868027b44a018278039cc42a01e730b (diff)
downloadqmk_firmware-dfab177f889fd6701e5f898c869be1bf3a2d0ef9.tar.gz
qmk_firmware-dfab177f889fd6701e5f898c869be1bf3a2d0ef9.zip
Add function to support split-keyboard in rgblight.[ch]. (#5020)
* add temporary file that is rgblight.c call graph * add rgblight_update_hook() * update rgblight-call-graph.dot (temporary file) * add more hook point * add TODO comment * temporary Revert "add TODO comment" This reverts commit df6165aac9b3a31d1d3e31ce52aadc134b84eac2. * temporary Revert "add more hook point" This reverts commit 64592b06f3bcdaac47c59f922018a273bef76776. * temporary Revert "add rgblight_update_hook()" This reverts commit 432b74c912ed4333e6633e20a1bcda10c6a10eaf. * add rgblight_update_hook() * add more hook point * add TODO comment * implement rgblight_update_hook() * remove rgblight_update_hook(), add RGBLIGHT_SPLIT_SET_CHANGE_XXXX rgblight_update_hook() is too large. change to simple flag setting. * shrink rgblight_config_t * implement rgblight_update_sync() Note: The animation synchronization process has not been implemented yet. * update quantum/rgblight-call-graph.dot (temporary file) * rmove quantum/rgblight-call-graph.dot (temporary file) * update rgblight.c * Add temporary code to Helix keyboard 'five_rows' keymap to test rgblight.c . * fix build break rgblight_update_sync() when all animation off * fix quantum/rgblight.c:rgblight_disable_XX() add RGBLIGHT_SPLIT_SET_CHANGE_MODE * quantum/rgblight.c change code order: move rgblight_update_sync() * add mode_base_table[] to quantum/rgblight.c * quantum/rgblight.c use mode_base_table[] and rgblight_status.base_mode * quantum/rgblkght.c animation timer integration * quantum/rgblkght.c add animation sync for split keyboard * fix mode_base_table[] and snake effect * fix build break keyboards/mxss. keyboards/mxss's local rgblight.c need old version rgblight.h * rgblight.c: fix animation sync * quantum/rgblight.c: fix snake effect sync * quantum/rgblight.c: animation sync interverl 30 sec * quantum/rgblight.c: fix rgblight_effect_rainbow_swirl() and rgblight_effect_knight() * quantum/rgblight.c: add macro RGBLIGHT_SPLIT_ANIMATION * cherry-pick from 'rgblight_modes.h sample implementation' * fix RGBLIGHT_SPLIT_ANIMATION check position * Update temporary code in Helix keyboard 'five_rows' keymap to test rgblight.c * Reduce the firmware size by 1500 bytes when rgblight_effect_breathing() is enabled. * Changed to rgblight_sethsv_eeprom_helper() for easier reading. * add fail-safe code to quantum/rgblight.c:rgblight_task(),rgblight_timer_enable() * remove temporary code in Helix keyboard 'five_rows' keymap * quantum/rgblight.c: add split-keyboard master side sync functions add functions: uint8_t rgblight_get_change_flags(void); void rgblight_clear_change_flags(void); void rgblight_get_syncinfo(rgblight_syncinfo_t *syncinfo); change function: void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom); * Change rgblight_update_sync() to use write_to_eeprom. * remove TODO comment from quantum/rgblight.h * Revert "fix build break keyboards/mxss." This reverts commit 90b9a1aa7d8af226751500e49e3ea0214cc4e024. (Separated this change into the newly opened PR #5461.) * Revert "Reduce the firmware size by 1500 bytes when rgblight_effect_breathing() is enabled." This reverts commit b61004e63e82cf5334cee4def4ba10cffa88885f. * update quantum/rgblight.c: Code size reduction when not using RGBLIGHT_SPLIT. * Add temporary code to Helix keyboard 'five_rows' keymap to test rgblight.c . * add temporary pdhelix(Patched Helix) code * Add temporary code to split_common/transport.c to test rgblight.c. * Finish testing rgblight.c with helix keyboard. Revert "Add temporary code to Helix keyboard 'five_rows' keymap to test rgblight.c ." This reverts commit 0bf81a4723a977adc0cb09b4272ee5c9b4f2bbbb. * Finish testing rgblight.c with quantum/split_common code. Revert "Add temporary code to split_common/transport.c to test rgblight.c." This reverts commit 71db3e24eef40d4c455fb9fd1664e4487c9d927a. * remove temporary pdhelix(Patched Helix) code This reverts commit 5287e51a394741bcb6028c7cfc0dd0c984645f76. * Added description of RGBLIGHT_SPLIT macro to docs/feature_rgblight.md. * add RGBLIGHT_SPLIT_SET_CHANGE_HSVS to rgblight_init() * Changed to restart animation only when changing mode. When changing hue, sat and val, the animation is not restarted and continues.
-rw-r--r--docs/feature_rgblight.md1
-rw-r--r--quantum/rgblight.c390
-rw-r--r--quantum/rgblight.h134
-rw-r--r--quantum/rgblight_modes.h67
4 files changed, 384 insertions, 208 deletions
diff --git a/docs/feature_rgblight.md b/docs/feature_rgblight.md
index cba97cb41..97a995994 100644
--- a/docs/feature_rgblight.md
+++ b/docs/feature_rgblight.md
@@ -75,6 +75,7 @@ Your RGB lighting can be configured by placing these `#define`s in your `config.
75|`RGBLIGHT_VAL_STEP` |`17` |The number of steps to increment the brightness by | 75|`RGBLIGHT_VAL_STEP` |`17` |The number of steps to increment the brightness by |
76|`RGBLIGHT_LIMIT_VAL` |`255` |The maximum brightness level | 76|`RGBLIGHT_LIMIT_VAL` |`255` |The maximum brightness level |
77|`RGBLIGHT_SLEEP` |*Not defined*|If defined, the RGB lighting will be switched off when the host goes to sleep| 77|`RGBLIGHT_SLEEP` |*Not defined*|If defined, the RGB lighting will be switched off when the host goes to sleep|
78|`RGBLIGHT_SPLIT` |*Not defined*|If defined, synchronization functionality for split keyboards is added|
78 79
79## Animations 80## Animations
80 81
diff --git a/quantum/rgblight.c b/quantum/rgblight.c
index e2410424e..5ec11bc07 100644
--- a/quantum/rgblight.c
+++ b/quantum/rgblight.c
@@ -34,14 +34,38 @@
34 #include "velocikey.h" 34 #include "velocikey.h"
35#endif 35#endif
36 36
37#ifdef RGBLIGHT_SPLIT
38 /* for split keyboard */
39 #define RGBLIGHT_SPLIT_SET_CHANGE_MODE rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_MODE
40 #define RGBLIGHT_SPLIT_SET_CHANGE_HSVS rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_HSVS
41 #define RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_TIMER
42 #define RGBLIGHT_SPLIT_ANIMATION_TICK rgblight_status.change_flags |= RGBLIGHT_STATUS_ANIMATION_TICK
43#else
44 #define RGBLIGHT_SPLIT_SET_CHANGE_MODE
45 #define RGBLIGHT_SPLIT_SET_CHANGE_HSVS
46 #define RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE
47 #define RGBLIGHT_SPLIT_ANIMATION_TICK
48#endif
49
37#define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_ ## sym, 50#define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_ ## sym,
38#define _RGBM_SINGLE_DYNAMIC(sym) 51#define _RGBM_SINGLE_DYNAMIC(sym)
39#define _RGBM_MULTI_STATIC(sym) RGBLIGHT_MODE_ ## sym, 52#define _RGBM_MULTI_STATIC(sym) RGBLIGHT_MODE_ ## sym,
40#define _RGBM_MULTI_DYNAMIC(sym) 53#define _RGBM_MULTI_DYNAMIC(sym)
41#define _RGBM_TMP_STATIC(sym) RGBLIGHT_MODE_ ## sym, 54#define _RGBM_TMP_STATIC(sym, msym) RGBLIGHT_MODE_ ## sym,
42#define _RGBM_TMP_DYNAMIC(sym) 55#define _RGBM_TMP_DYNAMIC(sym, msym)
43static uint8_t static_effect_table [] = { 56static uint8_t static_effect_table [] = {
44#include "rgblight.h" 57#include "rgblight_modes.h"
58};
59
60#define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_ ## sym,
61#define _RGBM_SINGLE_DYNAMIC(sym) RGBLIGHT_MODE_ ## sym,
62#define _RGBM_MULTI_STATIC(sym) RGBLIGHT_MODE_ ## sym,
63#define _RGBM_MULTI_DYNAMIC(sym) RGBLIGHT_MODE_ ## sym,
64#define _RGBM_TMP_STATIC(sym, msym) RGBLIGHT_MODE_ ## msym,
65#define _RGBM_TMP_DYNAMIC(sym, msym) RGBLIGHT_MODE_ ## msym,
66static uint8_t mode_base_table [] = {
67 0, // RGBLIGHT_MODE_zero
68#include "rgblight_modes.h"
45}; 69};
46 70
47static inline int is_static_effect(uint8_t mode) { 71static inline int is_static_effect(uint8_t mode) {
@@ -61,14 +85,18 @@ const uint16_t RGBLED_GRADIENT_RANGES[] PROGMEM = {360, 240, 180, 120, 90};
61#endif 85#endif
62 86
63rgblight_config_t rgblight_config; 87rgblight_config_t rgblight_config;
88rgblight_status_t rgblight_status = { .timer_enabled = false };
64bool is_rgblight_initialized = false; 89bool is_rgblight_initialized = false;
65 90
91#ifdef RGBLIGHT_USE_TIMER
92animation_status_t animation_status = {};
93#endif
94
66#ifndef LED_ARRAY 95#ifndef LED_ARRAY
67LED_TYPE led[RGBLED_NUM]; 96LED_TYPE led[RGBLED_NUM];
68 #define LED_ARRAY led 97 #define LED_ARRAY led
69#endif 98#endif
70 99
71bool rgblight_timer_enabled = false;
72 100
73static uint8_t clipping_start_pos = 0; 101static uint8_t clipping_start_pos = 0;
74static uint8_t clipping_num_leds = RGBLED_NUM; 102static uint8_t clipping_num_leds = RGBLED_NUM;
@@ -221,6 +249,7 @@ void rgblight_init(void) {
221 eeconfig_update_rgblight_default(); 249 eeconfig_update_rgblight_default();
222 } 250 }
223 rgblight_config.raw = eeconfig_read_rgblight(); 251 rgblight_config.raw = eeconfig_read_rgblight();
252 RGBLIGHT_SPLIT_SET_CHANGE_HSVS;
224 if (!rgblight_config.mode) { 253 if (!rgblight_config.mode) {
225 dprintf("rgblight_init rgblight_config.mode = 0. Write default values to EEPROM.\n"); 254 dprintf("rgblight_init rgblight_config.mode = 0. Write default values to EEPROM.\n");
226 eeconfig_update_rgblight_default(); 255 eeconfig_update_rgblight_default();
@@ -321,6 +350,7 @@ void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) {
321 } else { 350 } else {
322 rgblight_config.mode = mode; 351 rgblight_config.mode = mode;
323 } 352 }
353 RGBLIGHT_SPLIT_SET_CHANGE_MODE;
324 if (write_to_eeprom) { 354 if (write_to_eeprom) {
325 eeconfig_update_rgblight(rgblight_config.raw); 355 eeconfig_update_rgblight(rgblight_config.raw);
326 xprintf("rgblight mode [EEPROM]: %u\n", rgblight_config.mode); 356 xprintf("rgblight mode [EEPROM]: %u\n", rgblight_config.mode);
@@ -336,6 +366,9 @@ void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) {
336 rgblight_timer_enable(); 366 rgblight_timer_enable();
337#endif 367#endif
338 } 368 }
369#ifdef RGBLIGHT_USE_TIMER
370 animation_status.restart = true;
371#endif
339 rgblight_sethsv_noeeprom(rgblight_config.hue, rgblight_config.sat, rgblight_config.val); 372 rgblight_sethsv_noeeprom(rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
340} 373}
341 374
@@ -389,6 +422,7 @@ void rgblight_disable(void) {
389#ifdef RGBLIGHT_USE_TIMER 422#ifdef RGBLIGHT_USE_TIMER
390 rgblight_timer_disable(); 423 rgblight_timer_disable();
391#endif 424#endif
425 RGBLIGHT_SPLIT_SET_CHANGE_MODE;
392 wait_ms(50); 426 wait_ms(50);
393 rgblight_set(); 427 rgblight_set();
394} 428}
@@ -399,6 +433,7 @@ void rgblight_disable_noeeprom(void) {
399#ifdef RGBLIGHT_USE_TIMER 433#ifdef RGBLIGHT_USE_TIMER
400 rgblight_timer_disable(); 434 rgblight_timer_disable();
401#endif 435#endif
436 RGBLIGHT_SPLIT_SET_CHANGE_MODE;
402 wait_ms(50); 437 wait_ms(50);
403 rgblight_set(); 438 rgblight_set();
404} 439}
@@ -505,11 +540,13 @@ void rgblight_decrease_val(void) {
505} 540}
506void rgblight_increase_speed(void) { 541void rgblight_increase_speed(void) {
507 rgblight_config.speed = increment( rgblight_config.speed, 1, 0, 3 ); 542 rgblight_config.speed = increment( rgblight_config.speed, 1, 0, 3 );
543 //RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED?
508 eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this 544 eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this
509} 545}
510 546
511void rgblight_decrease_speed(void) { 547void rgblight_decrease_speed(void) {
512 rgblight_config.speed = decrement( rgblight_config.speed, 1, 0, 3 ); 548 rgblight_config.speed = decrement( rgblight_config.speed, 1, 0, 3 );
549 //RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED??
513 eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this 550 eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this
514} 551}
515 552
@@ -524,6 +561,7 @@ void rgblight_sethsv_noeeprom_old(uint16_t hue, uint8_t sat, uint8_t val) {
524 561
525void rgblight_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom) { 562void rgblight_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom) {
526 if (rgblight_config.enable) { 563 if (rgblight_config.enable) {
564 rgblight_status.base_mode = mode_base_table[rgblight_config.mode];
527 if (rgblight_config.mode == RGBLIGHT_MODE_STATIC_LIGHT) { 565 if (rgblight_config.mode == RGBLIGHT_MODE_STATIC_LIGHT) {
528 // same static color 566 // same static color
529 LED_TYPE tmp_led; 567 LED_TYPE tmp_led;
@@ -534,33 +572,30 @@ void rgblight_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool
534 if ( 1 == 0 ) { //dummy 572 if ( 1 == 0 ) { //dummy
535 } 573 }
536#ifdef RGBLIGHT_EFFECT_BREATHING 574#ifdef RGBLIGHT_EFFECT_BREATHING
537 else if (rgblight_config.mode >= RGBLIGHT_MODE_BREATHING && 575 else if (rgblight_status.base_mode == RGBLIGHT_MODE_BREATHING ) {
538 rgblight_config.mode <= RGBLIGHT_MODE_BREATHING_end) {
539 // breathing mode, ignore the change of val, use in memory value instead 576 // breathing mode, ignore the change of val, use in memory value instead
540 val = rgblight_config.val; 577 val = rgblight_config.val;
541 } 578 }
542#endif 579#endif
543#ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD 580#ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD
544 else if (rgblight_config.mode >= RGBLIGHT_MODE_RAINBOW_MOOD && 581 else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_MOOD) {
545 rgblight_config.mode <= RGBLIGHT_MODE_RAINBOW_MOOD_end) {
546 // rainbow mood, ignore the change of hue 582 // rainbow mood, ignore the change of hue
547 hue = rgblight_config.hue; 583 hue = rgblight_config.hue;
548 } 584 }
549#endif 585#endif
550#ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL 586#ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL
551 else if (rgblight_config.mode >= RGBLIGHT_MODE_RAINBOW_SWIRL && 587 else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_SWIRL) {
552 rgblight_config.mode <= RGBLIGHT_MODE_RAINBOW_SWIRL_end) {
553 // rainbow swirl, ignore the change of hue 588 // rainbow swirl, ignore the change of hue
554 hue = rgblight_config.hue; 589 hue = rgblight_config.hue;
555 } 590 }
556#endif 591#endif
557#ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT 592#ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT
558 else if (rgblight_config.mode >= RGBLIGHT_MODE_STATIC_GRADIENT && 593 else if (rgblight_status.base_mode == RGBLIGHT_MODE_STATIC_GRADIENT) {
559 rgblight_config.mode <= RGBLIGHT_MODE_STATIC_GRADIENT_end) {
560 // static gradient 594 // static gradient
561 uint16_t _hue; 595 uint16_t _hue;
562 int8_t direction = ((rgblight_config.mode - RGBLIGHT_MODE_STATIC_GRADIENT) % 2) ? -1 : 1; 596 uint8_t delta = rgblight_config.mode - rgblight_status.base_mode;
563 uint16_t range = pgm_read_word(&RGBLED_GRADIENT_RANGES[(rgblight_config.mode - RGBLIGHT_MODE_STATIC_GRADIENT) / 2]); 597 int8_t direction = (delta % 2) ? -1 : 1;
598 uint16_t range = pgm_read_word(&RGBLED_GRADIENT_RANGES[delta / 2]);
564 for (uint8_t i = 0; i < RGBLED_NUM; i++) { 599 for (uint8_t i = 0; i < RGBLED_NUM; i++) {
565 _hue = (range / RGBLED_NUM * i * direction + hue + 360) % 360; 600 _hue = (range / RGBLED_NUM * i * direction + hue + 360) % 360;
566 dprintf("rgblight rainbow set hsv: %u,%u,%d,%u\n", i, _hue, direction, range); 601 dprintf("rgblight rainbow set hsv: %u,%u,%d,%u\n", i, _hue, direction, range);
@@ -570,6 +605,13 @@ void rgblight_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool
570 } 605 }
571#endif 606#endif
572 } 607 }
608#ifdef RGBLIGHT_SPLIT
609 if( rgblight_config.hue != hue ||
610 rgblight_config.sat != sat ||
611 rgblight_config.val != val ) {
612 RGBLIGHT_SPLIT_SET_CHANGE_HSVS;
613 }
614#endif
573 rgblight_config.hue = hue; 615 rgblight_config.hue = hue;
574 rgblight_config.sat = sat; 616 rgblight_config.sat = sat;
575 rgblight_config.val = val; 617 rgblight_config.val = val;
@@ -711,10 +753,59 @@ void rgblight_set(void) {
711} 753}
712#endif 754#endif
713 755
756#ifdef RGBLIGHT_SPLIT
757/* for split keyboard master side */
758uint8_t rgblight_get_change_flags(void) {
759 return rgblight_status.change_flags;
760}
761
762void rgblight_clear_change_flags(void) {
763 rgblight_status.change_flags = 0;
764}
765
766void rgblight_get_syncinfo(rgblight_syncinfo_t *syncinfo) {
767 syncinfo->config = rgblight_config;
768 syncinfo->status = rgblight_status;
769}
770
771/* for split keyboard slave side */
772void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom) {
773 if (syncinfo->status.change_flags & RGBLIGHT_STATUS_CHANGE_MODE) {
774 if (syncinfo->config.enable) {
775 rgblight_config.enable = 1; // == rgblight_enable_noeeprom();
776 rgblight_mode_eeprom_helper(syncinfo->config.mode, write_to_eeprom);
777 } else {
778 rgblight_disable_noeeprom();
779 }
780 }
781 if (syncinfo->status.change_flags & RGBLIGHT_STATUS_CHANGE_HSVS) {
782 rgblight_sethsv_eeprom_helper(syncinfo->config.hue, syncinfo->config.sat, syncinfo->config.val, write_to_eeprom);
783 // rgblight_config.speed = config->speed; // NEED???
784 }
785 #ifdef RGBLIGHT_USE_TIMER
786 if (syncinfo->status.change_flags & RGBLIGHT_STATUS_CHANGE_TIMER) {
787 if (syncinfo->status.timer_enabled) {
788 rgblight_timer_enable();
789 } else {
790 rgblight_timer_disable();
791 }
792 }
793 #ifndef RGBLIGHT_SPLIT_NO_ANIMATION_SYNC
794 if (syncinfo->status.change_flags & RGBLIGHT_STATUS_ANIMATION_TICK) {
795 animation_status.restart = true;
796 }
797 #endif /* RGBLIGHT_SPLIT_NO_ANIMATION_SYNC */
798 #endif /* RGBLIGHT_USE_TIMER */
799}
800#endif /* RGBLIGHT_SPLIT */
801
714#ifdef RGBLIGHT_USE_TIMER 802#ifdef RGBLIGHT_USE_TIMER
715 803
716// Animation timer -- AVR Timer3 804typedef void (*effect_func_t)(animation_status_t *anim);
805
806// Animation timer -- use system timer (AVR Timer0)
717void rgblight_timer_init(void) { 807void rgblight_timer_init(void) {
808 // OLD!!!! Animation timer -- AVR Timer3
718 // static uint8_t rgblight_timer_is_init = 0; 809 // static uint8_t rgblight_timer_is_init = 0;
719 // if (rgblight_timer_is_init) { 810 // if (rgblight_timer_is_init) {
720 // return; 811 // return;
@@ -730,19 +821,29 @@ void rgblight_timer_init(void) {
730 // OCR3AL = RGBLED_TIMER_TOP & 0xff; 821 // OCR3AL = RGBLED_TIMER_TOP & 0xff;
731 // SREG = sreg; 822 // SREG = sreg;
732 823
733 rgblight_timer_enabled = true; 824 rgblight_status.timer_enabled = false;
825 RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE;
734} 826}
735void rgblight_timer_enable(void) { 827void rgblight_timer_enable(void) {
736 rgblight_timer_enabled = true; 828 if( !is_static_effect(rgblight_config.mode) ) {
737 dprintf("TIMER3 enabled.\n"); 829 rgblight_status.timer_enabled = true;
830 }
831 animation_status.last_timer = timer_read();
832 RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE;
833 dprintf("rgblight timer enabled.\n");
738} 834}
739void rgblight_timer_disable(void) { 835void rgblight_timer_disable(void) {
740 rgblight_timer_enabled = false; 836 rgblight_status.timer_enabled = false;
741 dprintf("TIMER3 disabled.\n"); 837 RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE;
838 dprintf("rgblight timer disable.\n");
742} 839}
743void rgblight_timer_toggle(void) { 840void rgblight_timer_toggle(void) {
744 rgblight_timer_enabled ^= rgblight_timer_enabled; 841 dprintf("rgblight timer toggle.\n");
745 dprintf("TIMER3 toggled.\n"); 842 if(rgblight_status.timer_enabled) {
843 rgblight_timer_disable();
844 } else {
845 rgblight_timer_enable();
846 }
746} 847}
747 848
748void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b) { 849void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b) {
@@ -751,64 +852,116 @@ void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b) {
751 rgblight_setrgb(r, g, b); 852 rgblight_setrgb(r, g, b);
752} 853}
753 854
855static void rgblight_effect_dummy(animation_status_t *anim) {
856 // do nothing
857 /********
858 dprintf("rgblight_task() what happened?\n");
859 dprintf("is_static_effect %d\n", is_static_effect(rgblight_config.mode));
860 dprintf("mode = %d, base_mode = %d, timer_enabled %d, ",
861 rgblight_config.mode, rgblight_status.base_mode,
862 rgblight_status.timer_enabled);
863 dprintf("last_timer = %d\n",anim->last_timer);
864 **/
865}
866
754void rgblight_task(void) { 867void rgblight_task(void) {
868 if (rgblight_status.timer_enabled) {
869 effect_func_t effect_func = rgblight_effect_dummy;
870 uint16_t interval_time = 2000; // dummy interval
871 uint8_t delta = rgblight_config.mode - rgblight_status.base_mode;
872 animation_status.delta = delta;
755 873
756 if (rgblight_timer_enabled) {
757 // static light mode, do nothing here 874 // static light mode, do nothing here
758 if ( 1 == 0 ) { //dummy 875 if ( 1 == 0 ) { //dummy
759 } 876 }
760#ifdef RGBLIGHT_EFFECT_BREATHING 877#ifdef RGBLIGHT_EFFECT_BREATHING
761 else if (rgblight_config.mode >= RGBLIGHT_MODE_BREATHING && 878 else if (rgblight_status.base_mode == RGBLIGHT_MODE_BREATHING) {
762 rgblight_config.mode <= RGBLIGHT_MODE_BREATHING_end) {
763 // breathing mode 879 // breathing mode
764 rgblight_effect_breathing(rgblight_config.mode - RGBLIGHT_MODE_BREATHING ); 880 interval_time = get_interval_time(&RGBLED_BREATHING_INTERVALS[delta], 1, 100);
881 effect_func = rgblight_effect_breathing;
765 } 882 }
766#endif 883#endif
767#ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD 884#ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD
768 else if (rgblight_config.mode >= RGBLIGHT_MODE_RAINBOW_MOOD && 885 else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_MOOD) {
769 rgblight_config.mode <= RGBLIGHT_MODE_RAINBOW_MOOD_end) {
770 // rainbow mood mode 886 // rainbow mood mode
771 rgblight_effect_rainbow_mood(rgblight_config.mode - RGBLIGHT_MODE_RAINBOW_MOOD); 887 interval_time = get_interval_time(&RGBLED_RAINBOW_MOOD_INTERVALS[delta], 5, 100);
888 effect_func = rgblight_effect_rainbow_mood;
772 } 889 }
773#endif 890#endif
774#ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL 891#ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL
775 else if (rgblight_config.mode >= RGBLIGHT_MODE_RAINBOW_SWIRL && 892 else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_SWIRL) {
776 rgblight_config.mode <= RGBLIGHT_MODE_RAINBOW_SWIRL_end) {
777 // rainbow swirl mode 893 // rainbow swirl mode
778 rgblight_effect_rainbow_swirl(rgblight_config.mode - RGBLIGHT_MODE_RAINBOW_SWIRL); 894 interval_time = get_interval_time(&RGBLED_RAINBOW_SWIRL_INTERVALS[delta / 2], 1, 100);
895 effect_func = rgblight_effect_rainbow_swirl;
779 } 896 }
780#endif 897#endif
781#ifdef RGBLIGHT_EFFECT_SNAKE 898#ifdef RGBLIGHT_EFFECT_SNAKE
782 else if (rgblight_config.mode >= RGBLIGHT_MODE_SNAKE && 899 else if (rgblight_status.base_mode == RGBLIGHT_MODE_SNAKE) {
783 rgblight_config.mode <= RGBLIGHT_MODE_SNAKE_end) {
784 // snake mode 900 // snake mode
785 rgblight_effect_snake(rgblight_config.mode - RGBLIGHT_MODE_SNAKE); 901 interval_time = get_interval_time(&RGBLED_SNAKE_INTERVALS[delta / 2], 1, 200);
902 effect_func = rgblight_effect_snake;
786 } 903 }
787#endif 904#endif
788#ifdef RGBLIGHT_EFFECT_KNIGHT 905#ifdef RGBLIGHT_EFFECT_KNIGHT
789 else if (rgblight_config.mode >= RGBLIGHT_MODE_KNIGHT && 906 else if (rgblight_status.base_mode == RGBLIGHT_MODE_KNIGHT) {
790 rgblight_config.mode <= RGBLIGHT_MODE_KNIGHT_end) {
791 // knight mode 907 // knight mode
792 rgblight_effect_knight(rgblight_config.mode - RGBLIGHT_MODE_KNIGHT); 908 interval_time = get_interval_time(&RGBLED_KNIGHT_INTERVALS[delta], 5, 100);
909 effect_func = rgblight_effect_knight;
793 } 910 }
794#endif 911#endif
795#ifdef RGBLIGHT_EFFECT_CHRISTMAS 912#ifdef RGBLIGHT_EFFECT_CHRISTMAS
796 else if (rgblight_config.mode == RGBLIGHT_MODE_CHRISTMAS) { 913 else if (rgblight_status.base_mode == RGBLIGHT_MODE_CHRISTMAS) {
797 // christmas mode 914 // christmas mode
798 rgblight_effect_christmas(); 915 interval_time = RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL;
916 effect_func = (effect_func_t)rgblight_effect_christmas;
799 } 917 }
800#endif 918#endif
801#ifdef RGBLIGHT_EFFECT_RGB_TEST 919#ifdef RGBLIGHT_EFFECT_RGB_TEST
802 else if (rgblight_config.mode == RGBLIGHT_MODE_RGB_TEST) { 920 else if (rgblight_status.base_mode == RGBLIGHT_MODE_RGB_TEST) {
803 // RGB test mode 921 // RGB test mode
804 rgblight_effect_rgbtest(); 922 interval_time = pgm_read_word(&RGBLED_RGBTEST_INTERVALS[0]);
923 effect_func = (effect_func_t)rgblight_effect_rgbtest;
805 } 924 }
806#endif 925#endif
807#ifdef RGBLIGHT_EFFECT_ALTERNATING 926#ifdef RGBLIGHT_EFFECT_ALTERNATING
808 else if (rgblight_config.mode == RGBLIGHT_MODE_ALTERNATING){ 927 else if (rgblight_status.base_mode == RGBLIGHT_MODE_ALTERNATING){
809 rgblight_effect_alternating(); 928 interval_time = 500;
929 effect_func = (effect_func_t)rgblight_effect_alternating;
930 }
931#endif
932 if (animation_status.restart) {
933 animation_status.restart = false;
934 animation_status.last_timer = timer_read() - interval_time - 1;
935 animation_status.pos16 = 0; // restart signal to local each effect
810 } 936 }
937 if (timer_elapsed(animation_status.last_timer) >= interval_time) {
938#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
939 static uint16_t report_last_timer = 0;
940 static bool tick_flag = false;
941 uint16_t oldpos16;
942 if (tick_flag) {
943 tick_flag = false;
944 //dprintf("rgblight animation tick\n");
945 if (timer_elapsed(report_last_timer) >= 30000) {
946 report_last_timer = timer_read();
947 dprintf("rgblight animation tick report to slave\n");
948 RGBLIGHT_SPLIT_ANIMATION_TICK;
949 }
950 }
951 oldpos16 = animation_status.pos16;
952 //dprintf("call effect function\n");
953#endif
954 animation_status.last_timer += interval_time;
955 effect_func(&animation_status);
956#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
957 //dprintf("pos16, oldpos16 = %d %d\n",
958 // animation_status.pos16,oldpos16);
959 if (animation_status.pos16 == 0 && oldpos16 != 0) {
960 //dprintf("flag on\n");
961 tick_flag = true;
962 }
811#endif 963#endif
964 }
812 } 965 }
813} 966}
814 967
@@ -819,22 +972,13 @@ void rgblight_task(void) {
819__attribute__ ((weak)) 972__attribute__ ((weak))
820const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5}; 973const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5};
821 974
822void rgblight_effect_breathing(uint8_t interval) { 975void rgblight_effect_breathing(animation_status_t *anim) {
823 static uint8_t pos = 0;
824 static uint16_t last_timer = 0;
825 float val; 976 float val;
826 977
827 uint8_t interval_time = get_interval_time(&RGBLED_BREATHING_INTERVALS[interval], 1, 100);
828
829 if (timer_elapsed(last_timer) < interval_time) {
830 return;
831 }
832 last_timer = timer_read();
833
834 // http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ 978 // http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/
835 val = (exp(sin((pos/255.0)*M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)*(RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E)); 979 val = (exp(sin((anim->pos/255.0)*M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)*(RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E));
836 rgblight_sethsv_noeeprom_old(rgblight_config.hue, rgblight_config.sat, val); 980 rgblight_sethsv_noeeprom_old(rgblight_config.hue, rgblight_config.sat, val);
837 pos = (pos + 1) % 256; 981 anim->pos = (anim->pos + 1) % 256;
838} 982}
839#endif 983#endif
840 984
@@ -842,18 +986,9 @@ void rgblight_effect_breathing(uint8_t interval) {
842__attribute__ ((weak)) 986__attribute__ ((weak))
843const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[] PROGMEM = {120, 60, 30}; 987const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[] PROGMEM = {120, 60, 30};
844 988
845void rgblight_effect_rainbow_mood(uint8_t interval) { 989void rgblight_effect_rainbow_mood(animation_status_t *anim) {
846 static uint16_t current_hue = 0; 990 rgblight_sethsv_noeeprom_old(anim->current_hue, rgblight_config.sat, rgblight_config.val);
847 static uint16_t last_timer = 0; 991 anim->current_hue = (anim->current_hue + 1) % 360;
848
849 uint8_t interval_time = get_interval_time(&RGBLED_RAINBOW_MOOD_INTERVALS[interval], 5, 100);
850
851 if (timer_elapsed(last_timer) < interval_time) {
852 return;
853 }
854 last_timer = timer_read();
855 rgblight_sethsv_noeeprom_old(current_hue, rgblight_config.sat, rgblight_config.val);
856 current_hue = (current_hue + 1) % 360;
857} 992}
858#endif 993#endif
859 994
@@ -865,31 +1000,23 @@ void rgblight_effect_rainbow_mood(uint8_t interval) {
865__attribute__ ((weak)) 1000__attribute__ ((weak))
866const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[] PROGMEM = {100, 50, 20}; 1001const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[] PROGMEM = {100, 50, 20};
867 1002
868void rgblight_effect_rainbow_swirl(uint8_t interval) { 1003void rgblight_effect_rainbow_swirl(animation_status_t *anim) {
869 static uint16_t current_hue = 0;
870 static uint16_t last_timer = 0;
871 uint16_t hue; 1004 uint16_t hue;
872 uint8_t i; 1005 uint8_t i;
873 1006
874 uint8_t interval_time = get_interval_time(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2], 1, 100);
875
876 if (timer_elapsed(last_timer) < interval_time) {
877 return;
878 }
879 last_timer = timer_read();
880 for (i = 0; i < RGBLED_NUM; i++) { 1007 for (i = 0; i < RGBLED_NUM; i++) {
881 hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / RGBLED_NUM * i + current_hue) % 360; 1008 hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / RGBLED_NUM * i + anim->current_hue) % 360;
882 sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]); 1009 sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]);
883 } 1010 }
884 rgblight_set(); 1011 rgblight_set();
885 1012
886 if (interval % 2) { 1013 if (anim->delta % 2) {
887 current_hue = (current_hue + 1) % 360; 1014 anim->current_hue = (anim->current_hue + 1) % 360;
888 } else { 1015 } else {
889 if (current_hue - 1 < 0) { 1016 if (anim->current_hue - 1 < 0) {
890 current_hue = 359; 1017 anim->current_hue = 359;
891 } else { 1018 } else {
892 current_hue = current_hue - 1; 1019 anim->current_hue = anim->current_hue - 1;
893 } 1020 }
894 } 1021 }
895} 1022}
@@ -899,22 +1026,27 @@ void rgblight_effect_rainbow_swirl(uint8_t interval) {
899__attribute__ ((weak)) 1026__attribute__ ((weak))
900const uint8_t RGBLED_SNAKE_INTERVALS[] PROGMEM = {100, 50, 20}; 1027const uint8_t RGBLED_SNAKE_INTERVALS[] PROGMEM = {100, 50, 20};
901 1028
902void rgblight_effect_snake(uint8_t interval) { 1029void rgblight_effect_snake(animation_status_t *anim) {
903 static uint8_t pos = 0; 1030 static uint8_t pos = 0;
904 static uint16_t last_timer = 0;
905 uint8_t i, j; 1031 uint8_t i, j;
906 int8_t k; 1032 int8_t k;
907 int8_t increment = 1; 1033 int8_t increment = 1;
908 if (interval % 2) { 1034
1035 if (anim->delta % 2) {
909 increment = -1; 1036 increment = -1;
910 } 1037 }
911 1038
912 uint8_t interval_time = get_interval_time(&RGBLED_SNAKE_INTERVALS[interval / 2], 1, 200); 1039#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
913 1040 if (anim->pos == 0) { // restart signal
914 if (timer_elapsed(last_timer) < interval_time) { 1041 if (increment == 1) {
915 return; 1042 pos = RGBLED_NUM - 1;
1043 } else {
1044 pos = 0;
1045 }
1046 anim->pos = 1;
916 } 1047 }
917 last_timer = timer_read(); 1048#endif
1049
918 for (i = 0; i < RGBLED_NUM; i++) { 1050 for (i = 0; i < RGBLED_NUM; i++) {
919 led[i].r = 0; 1051 led[i].r = 0;
920 led[i].g = 0; 1052 led[i].g = 0;
@@ -925,7 +1057,9 @@ void rgblight_effect_snake(uint8_t interval) {
925 k = k + RGBLED_NUM; 1057 k = k + RGBLED_NUM;
926 } 1058 }
927 if (i == k) { 1059 if (i == k) {
928 sethsv(rgblight_config.hue, rgblight_config.sat, (uint8_t)(rgblight_config.val*(RGBLIGHT_EFFECT_SNAKE_LENGTH-j)/RGBLIGHT_EFFECT_SNAKE_LENGTH), (LED_TYPE *)&led[i]); 1060 sethsv(rgblight_config.hue, rgblight_config.sat,
1061 (uint8_t)(rgblight_config.val*(RGBLIGHT_EFFECT_SNAKE_LENGTH-j)/RGBLIGHT_EFFECT_SNAKE_LENGTH),
1062 (LED_TYPE *)&led[i]);
929 } 1063 }
930 } 1064 }
931 } 1065 }
@@ -933,11 +1067,20 @@ void rgblight_effect_snake(uint8_t interval) {
933 if (increment == 1) { 1067 if (increment == 1) {
934 if (pos - 1 < 0) { 1068 if (pos - 1 < 0) {
935 pos = RGBLED_NUM - 1; 1069 pos = RGBLED_NUM - 1;
1070#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
1071 anim->pos = 0;
1072#endif
936 } else { 1073 } else {
937 pos -= 1; 1074 pos -= 1;
1075#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
1076 anim->pos = 1;
1077#endif
938 } 1078 }
939 } else { 1079 } else {
940 pos = (pos + 1) % RGBLED_NUM; 1080 pos = (pos + 1) % RGBLED_NUM;
1081#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
1082 anim->pos = pos;
1083#endif
941 } 1084 }
942} 1085}
943#endif 1086#endif
@@ -946,21 +1089,21 @@ void rgblight_effect_snake(uint8_t interval) {
946__attribute__ ((weak)) 1089__attribute__ ((weak))
947const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {127, 63, 31}; 1090const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {127, 63, 31};
948 1091
949void rgblight_effect_knight(uint8_t interval) { 1092void rgblight_effect_knight(animation_status_t *anim) {
950 static uint16_t last_timer = 0;
951
952 uint8_t interval_time = get_interval_time(&RGBLED_KNIGHT_INTERVALS[interval], 5, 100);
953
954 if (timer_elapsed(last_timer) < interval_time) {
955 return;
956 }
957 last_timer = timer_read();
958 1093
959 static int8_t low_bound = 0; 1094 static int8_t low_bound = 0;
960 static int8_t high_bound = RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1; 1095 static int8_t high_bound = RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1;
961 static int8_t increment = 1; 1096 static int8_t increment = 1;
962 uint8_t i, cur; 1097 uint8_t i, cur;
963 1098
1099#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
1100 if (anim->pos == 0) { // restart signal
1101 anim->pos = 1;
1102 low_bound = 0;
1103 high_bound = RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1;
1104 increment = 1;
1105 }
1106#endif
964 // Set all the LEDs to 0 1107 // Set all the LEDs to 0
965 for (i = 0; i < RGBLED_NUM; i++) { 1108 for (i = 0; i < RGBLED_NUM; i++) {
966 led[i].r = 0; 1109 led[i].r = 0;
@@ -988,23 +1131,23 @@ void rgblight_effect_knight(uint8_t interval) {
988 1131
989 if (high_bound <= 0 || low_bound >= RGBLIGHT_EFFECT_KNIGHT_LED_NUM - 1) { 1132 if (high_bound <= 0 || low_bound >= RGBLIGHT_EFFECT_KNIGHT_LED_NUM - 1) {
990 increment = -increment; 1133 increment = -increment;
1134#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
1135 if (increment == 1) {
1136 anim->pos = 0;
1137 }
1138#endif
991 } 1139 }
992} 1140}
993#endif 1141#endif
994 1142
995#ifdef RGBLIGHT_EFFECT_CHRISTMAS 1143#ifdef RGBLIGHT_EFFECT_CHRISTMAS
996void rgblight_effect_christmas(void) { 1144void rgblight_effect_christmas(animation_status_t *anim) {
997 static uint16_t current_offset = 0;
998 static uint16_t last_timer = 0;
999 uint16_t hue; 1145 uint16_t hue;
1000 uint8_t i; 1146 uint8_t i;
1001 if (timer_elapsed(last_timer) < RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL) { 1147
1002 return; 1148 anim->current_offset = (anim->current_offset + 1) % 2;
1003 }
1004 last_timer = timer_read();
1005 current_offset = (current_offset + 1) % 2;
1006 for (i = 0; i < RGBLED_NUM; i++) { 1149 for (i = 0; i < RGBLED_NUM; i++) {
1007 hue = 0 + ((i/RGBLIGHT_EFFECT_CHRISTMAS_STEP + current_offset) % 2) * 120; 1150 hue = 0 + ((i/RGBLIGHT_EFFECT_CHRISTMAS_STEP + anim->current_offset) % 2) * 120;
1008 sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]); 1151 sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]);
1009 } 1152 }
1010 rgblight_set(); 1153 rgblight_set();
@@ -1015,52 +1158,39 @@ void rgblight_effect_christmas(void) {
1015__attribute__ ((weak)) 1158__attribute__ ((weak))
1016const uint16_t RGBLED_RGBTEST_INTERVALS[] PROGMEM = {1024}; 1159const uint16_t RGBLED_RGBTEST_INTERVALS[] PROGMEM = {1024};
1017 1160
1018void rgblight_effect_rgbtest(void) { 1161void rgblight_effect_rgbtest(animation_status_t *anim) {
1019 static uint8_t pos = 0;
1020 static uint16_t last_timer = 0;
1021 static uint8_t maxval = 0; 1162 static uint8_t maxval = 0;
1022 uint8_t g; uint8_t r; uint8_t b; 1163 uint8_t g; uint8_t r; uint8_t b;
1023 1164
1024 if (timer_elapsed(last_timer) < pgm_read_word(&RGBLED_RGBTEST_INTERVALS[0])) {
1025 return;
1026 }
1027
1028 if( maxval == 0 ) { 1165 if( maxval == 0 ) {
1029 LED_TYPE tmp_led; 1166 LED_TYPE tmp_led;
1030 sethsv(0, 255, RGBLIGHT_LIMIT_VAL, &tmp_led); 1167 sethsv(0, 255, RGBLIGHT_LIMIT_VAL, &tmp_led);
1031 maxval = tmp_led.r; 1168 maxval = tmp_led.r;
1032 } 1169 }
1033 last_timer = timer_read();
1034 g = r = b = 0; 1170 g = r = b = 0;
1035 switch( pos ) { 1171 switch( anim->pos ) {
1036 case 0: r = maxval; break; 1172 case 0: r = maxval; break;
1037 case 1: g = maxval; break; 1173 case 1: g = maxval; break;
1038 case 2: b = maxval; break; 1174 case 2: b = maxval; break;
1039 } 1175 }
1040 rgblight_setrgb(r, g, b); 1176 rgblight_setrgb(r, g, b);
1041 pos = (pos + 1) % 3; 1177 anim->pos = (anim->pos + 1) % 3;
1042} 1178}
1043#endif 1179#endif
1044 1180
1045#ifdef RGBLIGHT_EFFECT_ALTERNATING 1181#ifdef RGBLIGHT_EFFECT_ALTERNATING
1046void rgblight_effect_alternating(void){ 1182void rgblight_effect_alternating(animation_status_t *anim) {
1047 static uint16_t last_timer = 0;
1048 static uint16_t pos = 0;
1049 if (timer_elapsed(last_timer) < 500) {
1050 return;
1051 }
1052 last_timer = timer_read();
1053 1183
1054 for(int i = 0; i<RGBLED_NUM; i++){ 1184 for(int i = 0; i<RGBLED_NUM; i++){
1055 if(i<RGBLED_NUM/2 && pos){ 1185 if(i<RGBLED_NUM/2 && anim->pos){
1056 sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]); 1186 sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]);
1057 }else if (i>=RGBLED_NUM/2 && !pos){ 1187 }else if (i>=RGBLED_NUM/2 && !anim->pos){
1058 sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]); 1188 sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]);
1059 }else{ 1189 }else{
1060 sethsv(rgblight_config.hue, rgblight_config.sat, 0, (LED_TYPE *)&led[i]); 1190 sethsv(rgblight_config.hue, rgblight_config.sat, 0, (LED_TYPE *)&led[i]);
1061 } 1191 }
1062 } 1192 }
1063 rgblight_set(); 1193 rgblight_set();
1064 pos = (pos + 1) % 2; 1194 anim->pos = (anim->pos + 1) % 2;
1065} 1195}
1066#endif 1196#endif
diff --git a/quantum/rgblight.h b/quantum/rgblight.h
index 1769f719d..748d009dc 100644
--- a/quantum/rgblight.h
+++ b/quantum/rgblight.h
@@ -68,11 +68,11 @@
68#define _RGBM_SINGLE_DYNAMIC(sym) RGBLIGHT_MODE_ ## sym, 68#define _RGBM_SINGLE_DYNAMIC(sym) RGBLIGHT_MODE_ ## sym,
69#define _RGBM_MULTI_STATIC(sym) RGBLIGHT_MODE_ ## sym, 69#define _RGBM_MULTI_STATIC(sym) RGBLIGHT_MODE_ ## sym,
70#define _RGBM_MULTI_DYNAMIC(sym) RGBLIGHT_MODE_ ## sym, 70#define _RGBM_MULTI_DYNAMIC(sym) RGBLIGHT_MODE_ ## sym,
71#define _RGBM_TMP_STATIC(sym) RGBLIGHT_MODE_ ## sym, 71#define _RGBM_TMP_STATIC(sym, msym) RGBLIGHT_MODE_ ## sym,
72#define _RGBM_TMP_DYNAMIC(sym) RGBLIGHT_MODE_ ## sym, 72#define _RGBM_TMP_DYNAMIC(sym, msym) RGBLIGHT_MODE_ ## sym,
73enum RGBLIGHT_EFFECT_MODE { 73enum RGBLIGHT_EFFECT_MODE {
74 RGBLIGHT_MODE_zero = 0, 74 RGBLIGHT_MODE_zero = 0,
75#include "rgblight.h" 75#include "rgblight_modes.h"
76 RGBLIGHT_MODE_last 76 RGBLIGHT_MODE_last
77}; 77};
78 78
@@ -163,6 +163,33 @@ typedef union {
163 }; 163 };
164} rgblight_config_t; 164} rgblight_config_t;
165 165
166typedef struct _rgblight_status_t {
167 uint8_t base_mode;
168 bool timer_enabled;
169#ifdef RGBLIGHT_SPLIT
170 uint8_t change_flags;
171#endif
172} rgblight_status_t;
173
174#ifdef RGBLIGHT_SPLIT
175 #define RGBLIGHT_STATUS_CHANGE_MODE (1<<0)
176 #define RGBLIGHT_STATUS_CHANGE_HSVS (1<<1)
177 #define RGBLIGHT_STATUS_CHANGE_TIMER (1<<2)
178 #define RGBLIGHT_STATUS_ANIMATION_TICK (1<<3)
179
180 typedef struct _rgblight_syncinfo_t {
181 rgblight_config_t config;
182 rgblight_status_t status;
183 } rgblight_syncinfo_t;
184
185 /* for split keyboard master side */
186 uint8_t rgblight_get_change_flags(void);
187 void rgblight_clear_change_flags(void);
188 void rgblight_get_syncinfo(rgblight_syncinfo_t *syncinfo);
189 /* for split keyboard slave side */
190 void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom);
191#endif
192
166void rgblight_init(void); 193void rgblight_init(void);
167void rgblight_increase(void); 194void rgblight_increase(void);
168void rgblight_decrease(void); 195void rgblight_decrease(void);
@@ -237,82 +264,33 @@ void rgblight_timer_init(void);
237void rgblight_timer_enable(void); 264void rgblight_timer_enable(void);
238void rgblight_timer_disable(void); 265void rgblight_timer_disable(void);
239void rgblight_timer_toggle(void); 266void rgblight_timer_toggle(void);
240void rgblight_effect_breathing(uint8_t interval);
241void rgblight_effect_rainbow_mood(uint8_t interval);
242void rgblight_effect_rainbow_swirl(uint8_t interval);
243void rgblight_effect_snake(uint8_t interval);
244void rgblight_effect_knight(uint8_t interval);
245void rgblight_effect_christmas(void);
246void rgblight_effect_rgbtest(void);
247void rgblight_effect_alternating(void);
248 267
249#endif // #ifndef RGBLIGHT_H_DUMMY_DEFINE 268#ifdef RGBLIGHT_USE_TIMER
250#endif // RGBLIGHT_H 269
270typedef struct _animation_status_t {
271 uint16_t last_timer;
272 uint8_t delta; /* mode - base_mode */
273 bool restart;
274 union {
275 uint16_t pos16;
276 uint8_t pos;
277 int16_t current_hue;
278 uint16_t current_offset;
279 };
280} animation_status_t;
281
282extern animation_status_t animation_status;
283
284void rgblight_effect_breathing(animation_status_t *anim);
285void rgblight_effect_rainbow_mood(animation_status_t *anim);
286void rgblight_effect_rainbow_swirl(animation_status_t *anim);
287void rgblight_effect_snake(animation_status_t *anim);
288void rgblight_effect_knight(animation_status_t *anim);
289void rgblight_effect_christmas(animation_status_t *anim);
290void rgblight_effect_rgbtest(animation_status_t *anim);
291void rgblight_effect_alternating(animation_status_t *anim);
251 292
252#ifdef _RGBM_SINGLE_STATIC
253 _RGBM_SINGLE_STATIC( STATIC_LIGHT )
254 #ifdef RGBLIGHT_EFFECT_BREATHING
255 _RGBM_MULTI_DYNAMIC( BREATHING )
256 _RGBM_TMP_DYNAMIC( breathing_3 )
257 _RGBM_TMP_DYNAMIC( breathing_4 )
258 _RGBM_TMP_DYNAMIC( BREATHING_end )
259 #endif
260 #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD
261 _RGBM_MULTI_DYNAMIC( RAINBOW_MOOD )
262 _RGBM_TMP_DYNAMIC( rainbow_mood_7 )
263 _RGBM_TMP_DYNAMIC( RAINBOW_MOOD_end )
264 #endif
265 #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL
266 _RGBM_MULTI_DYNAMIC( RAINBOW_SWIRL )
267 _RGBM_TMP_DYNAMIC( rainbow_swirl_10 )
268 _RGBM_TMP_DYNAMIC( rainbow_swirl_11 )
269 _RGBM_TMP_DYNAMIC( rainbow_swirl_12 )
270 _RGBM_TMP_DYNAMIC( rainbow_swirl_13 )
271 _RGBM_TMP_DYNAMIC( RAINBOW_SWIRL_end )
272 #endif
273 #ifdef RGBLIGHT_EFFECT_SNAKE
274 _RGBM_MULTI_DYNAMIC( SNAKE )
275 _RGBM_TMP_DYNAMIC( snake_16 )
276 _RGBM_TMP_DYNAMIC( snake_17 )
277 _RGBM_TMP_DYNAMIC( snake_18 )
278 _RGBM_TMP_DYNAMIC( snake_19 )
279 _RGBM_TMP_DYNAMIC( SNAKE_end )
280 #endif
281 #ifdef RGBLIGHT_EFFECT_KNIGHT
282 _RGBM_MULTI_DYNAMIC( KNIGHT )
283 _RGBM_TMP_DYNAMIC( knight_22 )
284 _RGBM_TMP_DYNAMIC( KNIGHT_end )
285 #endif
286 #ifdef RGBLIGHT_EFFECT_CHRISTMAS
287 _RGBM_SINGLE_DYNAMIC( CHRISTMAS )
288 #endif
289 #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT
290 _RGBM_MULTI_STATIC( STATIC_GRADIENT )
291 _RGBM_TMP_STATIC( static_gradient_26 )
292 _RGBM_TMP_STATIC( static_gradient_27 )
293 _RGBM_TMP_STATIC( static_gradient_28 )
294 _RGBM_TMP_STATIC( static_gradient_29 )
295 _RGBM_TMP_STATIC( static_gradient_30 )
296 _RGBM_TMP_STATIC( static_gradient_31 )
297 _RGBM_TMP_STATIC( static_gradient_32 )
298 _RGBM_TMP_STATIC( static_gradient_33 )
299 _RGBM_TMP_STATIC( STATIC_GRADIENT_end )
300 #endif
301 #ifdef RGBLIGHT_EFFECT_RGB_TEST
302 _RGBM_SINGLE_DYNAMIC( RGB_TEST )
303 #endif
304 #ifdef RGBLIGHT_EFFECT_ALTERNATING
305 _RGBM_SINGLE_DYNAMIC( ALTERNATING )
306 #endif
307 //// Add a new mode here.
308 // #ifdef RGBLIGHT_EFFECT_<name>
309 // _RGBM_<SINGLE|MULTI>_<STATIC|DYNAMIC>( <name> )
310 // #endif
311#endif 293#endif
312 294
313#undef _RGBM_SINGLE_STATIC 295#endif // #ifndef RGBLIGHT_H_DUMMY_DEFINE
314#undef _RGBM_SINGLE_DYNAMIC 296#endif // RGBLIGHT_H
315#undef _RGBM_MULTI_STATIC
316#undef _RGBM_MULTI_DYNAMIC
317#undef _RGBM_TMP_STATIC
318#undef _RGBM_TMP_DYNAMIC
diff --git a/quantum/rgblight_modes.h b/quantum/rgblight_modes.h
new file mode 100644
index 000000000..8a8f9bdda
--- /dev/null
+++ b/quantum/rgblight_modes.h
@@ -0,0 +1,67 @@
1#ifdef _RGBM_SINGLE_STATIC
2 _RGBM_SINGLE_STATIC( STATIC_LIGHT )
3 #ifdef RGBLIGHT_EFFECT_BREATHING
4 _RGBM_MULTI_DYNAMIC( BREATHING )
5 _RGBM_TMP_DYNAMIC( breathing_3, BREATHING )
6 _RGBM_TMP_DYNAMIC( breathing_4, BREATHING )
7 _RGBM_TMP_DYNAMIC( BREATHING_end, BREATHING )
8 #endif
9 #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD
10 _RGBM_MULTI_DYNAMIC( RAINBOW_MOOD )
11 _RGBM_TMP_DYNAMIC( rainbow_mood_7, RAINBOW_MOOD )
12 _RGBM_TMP_DYNAMIC( RAINBOW_MOOD_end, RAINBOW_MOOD )
13 #endif
14 #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL
15 _RGBM_MULTI_DYNAMIC( RAINBOW_SWIRL )
16 _RGBM_TMP_DYNAMIC( rainbow_swirl_10, RAINBOW_SWIRL )
17 _RGBM_TMP_DYNAMIC( rainbow_swirl_11, RAINBOW_SWIRL )
18 _RGBM_TMP_DYNAMIC( rainbow_swirl_12, RAINBOW_SWIRL )
19 _RGBM_TMP_DYNAMIC( rainbow_swirl_13, RAINBOW_SWIRL )
20 _RGBM_TMP_DYNAMIC( RAINBOW_SWIRL_end, RAINBOW_SWIRL )
21 #endif
22 #ifdef RGBLIGHT_EFFECT_SNAKE
23 _RGBM_MULTI_DYNAMIC( SNAKE )
24 _RGBM_TMP_DYNAMIC( snake_16, SNAKE )
25 _RGBM_TMP_DYNAMIC( snake_17, SNAKE )
26 _RGBM_TMP_DYNAMIC( snake_18, SNAKE )
27 _RGBM_TMP_DYNAMIC( snake_19, SNAKE )
28 _RGBM_TMP_DYNAMIC( SNAKE_end, SNAKE )
29 #endif
30 #ifdef RGBLIGHT_EFFECT_KNIGHT
31 _RGBM_MULTI_DYNAMIC( KNIGHT )
32 _RGBM_TMP_DYNAMIC( knight_22, KNIGHT )
33 _RGBM_TMP_DYNAMIC( KNIGHT_end, KNIGHT )
34 #endif
35 #ifdef RGBLIGHT_EFFECT_CHRISTMAS
36 _RGBM_SINGLE_DYNAMIC( CHRISTMAS )
37 #endif
38 #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT
39 _RGBM_MULTI_STATIC( STATIC_GRADIENT )
40 _RGBM_TMP_STATIC( static_gradient_26, STATIC_GRADIENT )
41 _RGBM_TMP_STATIC( static_gradient_27, STATIC_GRADIENT )
42 _RGBM_TMP_STATIC( static_gradient_28, STATIC_GRADIENT )
43 _RGBM_TMP_STATIC( static_gradient_29, STATIC_GRADIENT )
44 _RGBM_TMP_STATIC( static_gradient_30, STATIC_GRADIENT )
45 _RGBM_TMP_STATIC( static_gradient_31, STATIC_GRADIENT )
46 _RGBM_TMP_STATIC( static_gradient_32, STATIC_GRADIENT )
47 _RGBM_TMP_STATIC( static_gradient_33, STATIC_GRADIENT )
48 _RGBM_TMP_STATIC( STATIC_GRADIENT_end, STATIC_GRADIENT )
49 #endif
50 #ifdef RGBLIGHT_EFFECT_RGB_TEST
51 _RGBM_SINGLE_DYNAMIC( RGB_TEST )
52 #endif
53 #ifdef RGBLIGHT_EFFECT_ALTERNATING
54 _RGBM_SINGLE_DYNAMIC( ALTERNATING )
55 #endif
56 //// Add a new mode here.
57 // #ifdef RGBLIGHT_EFFECT_<name>
58 // _RGBM_<SINGLE|MULTI>_<STATIC|DYNAMIC>( <name> )
59 // #endif
60#endif
61
62#undef _RGBM_SINGLE_STATIC
63#undef _RGBM_SINGLE_DYNAMIC
64#undef _RGBM_MULTI_STATIC
65#undef _RGBM_MULTI_DYNAMIC
66#undef _RGBM_TMP_STATIC
67#undef _RGBM_TMP_DYNAMIC