From 5fcd744ddba591829a129560992b2e43fb615d4d Mon Sep 17 00:00:00 2001 From: XScorpion2 Date: Sun, 14 Apr 2019 20:50:35 -0400 Subject: Features/ws2812 matrix driver (#5418) * WS2812 driver implementation for RGB Matrix * Added driver configuration docs --- quantum/rgblight.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 08515564bc..e2410424e4 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -63,7 +63,11 @@ const uint16_t RGBLED_GRADIENT_RANGES[] PROGMEM = {360, 240, 180, 120, 90}; rgblight_config_t rgblight_config; bool is_rgblight_initialized = false; +#ifndef LED_ARRAY LED_TYPE led[RGBLED_NUM]; + #define LED_ARRAY led +#endif + bool rgblight_timer_enabled = false; static uint8_t clipping_start_pos = 0; -- cgit v1.2.3 From dfab177f889fd6701e5f898c869be1bf3a2d0ef9 Mon Sep 17 00:00:00 2001 From: Takeshi ISHII <2170248+mtei@users.noreply.github.com> Date: Sat, 20 Apr 2019 07:05:51 +0900 Subject: 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. --- quantum/rgblight.c | 390 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 260 insertions(+), 130 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index e2410424e4..5ec11bc077 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -34,14 +34,38 @@ #include "velocikey.h" #endif +#ifdef RGBLIGHT_SPLIT + /* for split keyboard */ + #define RGBLIGHT_SPLIT_SET_CHANGE_MODE rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_MODE + #define RGBLIGHT_SPLIT_SET_CHANGE_HSVS rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_HSVS + #define RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_TIMER + #define RGBLIGHT_SPLIT_ANIMATION_TICK rgblight_status.change_flags |= RGBLIGHT_STATUS_ANIMATION_TICK +#else + #define RGBLIGHT_SPLIT_SET_CHANGE_MODE + #define RGBLIGHT_SPLIT_SET_CHANGE_HSVS + #define RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE + #define RGBLIGHT_SPLIT_ANIMATION_TICK +#endif + #define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_ ## sym, #define _RGBM_SINGLE_DYNAMIC(sym) #define _RGBM_MULTI_STATIC(sym) RGBLIGHT_MODE_ ## sym, #define _RGBM_MULTI_DYNAMIC(sym) -#define _RGBM_TMP_STATIC(sym) RGBLIGHT_MODE_ ## sym, -#define _RGBM_TMP_DYNAMIC(sym) +#define _RGBM_TMP_STATIC(sym, msym) RGBLIGHT_MODE_ ## sym, +#define _RGBM_TMP_DYNAMIC(sym, msym) static uint8_t static_effect_table [] = { -#include "rgblight.h" +#include "rgblight_modes.h" +}; + +#define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_ ## sym, +#define _RGBM_SINGLE_DYNAMIC(sym) RGBLIGHT_MODE_ ## sym, +#define _RGBM_MULTI_STATIC(sym) RGBLIGHT_MODE_ ## sym, +#define _RGBM_MULTI_DYNAMIC(sym) RGBLIGHT_MODE_ ## sym, +#define _RGBM_TMP_STATIC(sym, msym) RGBLIGHT_MODE_ ## msym, +#define _RGBM_TMP_DYNAMIC(sym, msym) RGBLIGHT_MODE_ ## msym, +static uint8_t mode_base_table [] = { + 0, // RGBLIGHT_MODE_zero +#include "rgblight_modes.h" }; static inline int is_static_effect(uint8_t mode) { @@ -61,14 +85,18 @@ const uint16_t RGBLED_GRADIENT_RANGES[] PROGMEM = {360, 240, 180, 120, 90}; #endif rgblight_config_t rgblight_config; +rgblight_status_t rgblight_status = { .timer_enabled = false }; bool is_rgblight_initialized = false; +#ifdef RGBLIGHT_USE_TIMER +animation_status_t animation_status = {}; +#endif + #ifndef LED_ARRAY LED_TYPE led[RGBLED_NUM]; #define LED_ARRAY led #endif -bool rgblight_timer_enabled = false; static uint8_t clipping_start_pos = 0; static uint8_t clipping_num_leds = RGBLED_NUM; @@ -221,6 +249,7 @@ void rgblight_init(void) { eeconfig_update_rgblight_default(); } rgblight_config.raw = eeconfig_read_rgblight(); + RGBLIGHT_SPLIT_SET_CHANGE_HSVS; if (!rgblight_config.mode) { dprintf("rgblight_init rgblight_config.mode = 0. Write default values to EEPROM.\n"); eeconfig_update_rgblight_default(); @@ -321,6 +350,7 @@ void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { } else { rgblight_config.mode = mode; } + RGBLIGHT_SPLIT_SET_CHANGE_MODE; if (write_to_eeprom) { eeconfig_update_rgblight(rgblight_config.raw); 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) { rgblight_timer_enable(); #endif } +#ifdef RGBLIGHT_USE_TIMER + animation_status.restart = true; +#endif rgblight_sethsv_noeeprom(rgblight_config.hue, rgblight_config.sat, rgblight_config.val); } @@ -389,6 +422,7 @@ void rgblight_disable(void) { #ifdef RGBLIGHT_USE_TIMER rgblight_timer_disable(); #endif + RGBLIGHT_SPLIT_SET_CHANGE_MODE; wait_ms(50); rgblight_set(); } @@ -399,6 +433,7 @@ void rgblight_disable_noeeprom(void) { #ifdef RGBLIGHT_USE_TIMER rgblight_timer_disable(); #endif + RGBLIGHT_SPLIT_SET_CHANGE_MODE; wait_ms(50); rgblight_set(); } @@ -505,11 +540,13 @@ void rgblight_decrease_val(void) { } void rgblight_increase_speed(void) { rgblight_config.speed = increment( rgblight_config.speed, 1, 0, 3 ); + //RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED? eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this } void rgblight_decrease_speed(void) { rgblight_config.speed = decrement( rgblight_config.speed, 1, 0, 3 ); + //RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED?? eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this } @@ -524,6 +561,7 @@ void rgblight_sethsv_noeeprom_old(uint16_t hue, uint8_t sat, uint8_t val) { void rgblight_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom) { if (rgblight_config.enable) { + rgblight_status.base_mode = mode_base_table[rgblight_config.mode]; if (rgblight_config.mode == RGBLIGHT_MODE_STATIC_LIGHT) { // same static color LED_TYPE tmp_led; @@ -534,33 +572,30 @@ void rgblight_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool if ( 1 == 0 ) { //dummy } #ifdef RGBLIGHT_EFFECT_BREATHING - else if (rgblight_config.mode >= RGBLIGHT_MODE_BREATHING && - rgblight_config.mode <= RGBLIGHT_MODE_BREATHING_end) { + else if (rgblight_status.base_mode == RGBLIGHT_MODE_BREATHING ) { // breathing mode, ignore the change of val, use in memory value instead val = rgblight_config.val; } #endif #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD - else if (rgblight_config.mode >= RGBLIGHT_MODE_RAINBOW_MOOD && - rgblight_config.mode <= RGBLIGHT_MODE_RAINBOW_MOOD_end) { + else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_MOOD) { // rainbow mood, ignore the change of hue hue = rgblight_config.hue; } #endif #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL - else if (rgblight_config.mode >= RGBLIGHT_MODE_RAINBOW_SWIRL && - rgblight_config.mode <= RGBLIGHT_MODE_RAINBOW_SWIRL_end) { + else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_SWIRL) { // rainbow swirl, ignore the change of hue hue = rgblight_config.hue; } #endif #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT - else if (rgblight_config.mode >= RGBLIGHT_MODE_STATIC_GRADIENT && - rgblight_config.mode <= RGBLIGHT_MODE_STATIC_GRADIENT_end) { + else if (rgblight_status.base_mode == RGBLIGHT_MODE_STATIC_GRADIENT) { // static gradient uint16_t _hue; - int8_t direction = ((rgblight_config.mode - RGBLIGHT_MODE_STATIC_GRADIENT) % 2) ? -1 : 1; - uint16_t range = pgm_read_word(&RGBLED_GRADIENT_RANGES[(rgblight_config.mode - RGBLIGHT_MODE_STATIC_GRADIENT) / 2]); + uint8_t delta = rgblight_config.mode - rgblight_status.base_mode; + int8_t direction = (delta % 2) ? -1 : 1; + uint16_t range = pgm_read_word(&RGBLED_GRADIENT_RANGES[delta / 2]); for (uint8_t i = 0; i < RGBLED_NUM; i++) { _hue = (range / RGBLED_NUM * i * direction + hue + 360) % 360; 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 } #endif } +#ifdef RGBLIGHT_SPLIT + if( rgblight_config.hue != hue || + rgblight_config.sat != sat || + rgblight_config.val != val ) { + RGBLIGHT_SPLIT_SET_CHANGE_HSVS; + } +#endif rgblight_config.hue = hue; rgblight_config.sat = sat; rgblight_config.val = val; @@ -711,10 +753,59 @@ void rgblight_set(void) { } #endif +#ifdef RGBLIGHT_SPLIT +/* for split keyboard master side */ +uint8_t rgblight_get_change_flags(void) { + return rgblight_status.change_flags; +} + +void rgblight_clear_change_flags(void) { + rgblight_status.change_flags = 0; +} + +void rgblight_get_syncinfo(rgblight_syncinfo_t *syncinfo) { + syncinfo->config = rgblight_config; + syncinfo->status = rgblight_status; +} + +/* for split keyboard slave side */ +void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom) { + if (syncinfo->status.change_flags & RGBLIGHT_STATUS_CHANGE_MODE) { + if (syncinfo->config.enable) { + rgblight_config.enable = 1; // == rgblight_enable_noeeprom(); + rgblight_mode_eeprom_helper(syncinfo->config.mode, write_to_eeprom); + } else { + rgblight_disable_noeeprom(); + } + } + if (syncinfo->status.change_flags & RGBLIGHT_STATUS_CHANGE_HSVS) { + rgblight_sethsv_eeprom_helper(syncinfo->config.hue, syncinfo->config.sat, syncinfo->config.val, write_to_eeprom); + // rgblight_config.speed = config->speed; // NEED??? + } + #ifdef RGBLIGHT_USE_TIMER + if (syncinfo->status.change_flags & RGBLIGHT_STATUS_CHANGE_TIMER) { + if (syncinfo->status.timer_enabled) { + rgblight_timer_enable(); + } else { + rgblight_timer_disable(); + } + } + #ifndef RGBLIGHT_SPLIT_NO_ANIMATION_SYNC + if (syncinfo->status.change_flags & RGBLIGHT_STATUS_ANIMATION_TICK) { + animation_status.restart = true; + } + #endif /* RGBLIGHT_SPLIT_NO_ANIMATION_SYNC */ + #endif /* RGBLIGHT_USE_TIMER */ +} +#endif /* RGBLIGHT_SPLIT */ + #ifdef RGBLIGHT_USE_TIMER -// Animation timer -- AVR Timer3 +typedef void (*effect_func_t)(animation_status_t *anim); + +// Animation timer -- use system timer (AVR Timer0) void rgblight_timer_init(void) { + // OLD!!!! Animation timer -- AVR Timer3 // static uint8_t rgblight_timer_is_init = 0; // if (rgblight_timer_is_init) { // return; @@ -730,19 +821,29 @@ void rgblight_timer_init(void) { // OCR3AL = RGBLED_TIMER_TOP & 0xff; // SREG = sreg; - rgblight_timer_enabled = true; + rgblight_status.timer_enabled = false; + RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE; } void rgblight_timer_enable(void) { - rgblight_timer_enabled = true; - dprintf("TIMER3 enabled.\n"); + if( !is_static_effect(rgblight_config.mode) ) { + rgblight_status.timer_enabled = true; + } + animation_status.last_timer = timer_read(); + RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE; + dprintf("rgblight timer enabled.\n"); } void rgblight_timer_disable(void) { - rgblight_timer_enabled = false; - dprintf("TIMER3 disabled.\n"); + rgblight_status.timer_enabled = false; + RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE; + dprintf("rgblight timer disable.\n"); } void rgblight_timer_toggle(void) { - rgblight_timer_enabled ^= rgblight_timer_enabled; - dprintf("TIMER3 toggled.\n"); + dprintf("rgblight timer toggle.\n"); + if(rgblight_status.timer_enabled) { + rgblight_timer_disable(); + } else { + rgblight_timer_enable(); + } } void 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) { rgblight_setrgb(r, g, b); } +static void rgblight_effect_dummy(animation_status_t *anim) { + // do nothing + /******** + dprintf("rgblight_task() what happened?\n"); + dprintf("is_static_effect %d\n", is_static_effect(rgblight_config.mode)); + dprintf("mode = %d, base_mode = %d, timer_enabled %d, ", + rgblight_config.mode, rgblight_status.base_mode, + rgblight_status.timer_enabled); + dprintf("last_timer = %d\n",anim->last_timer); + **/ +} + void rgblight_task(void) { + if (rgblight_status.timer_enabled) { + effect_func_t effect_func = rgblight_effect_dummy; + uint16_t interval_time = 2000; // dummy interval + uint8_t delta = rgblight_config.mode - rgblight_status.base_mode; + animation_status.delta = delta; - if (rgblight_timer_enabled) { // static light mode, do nothing here if ( 1 == 0 ) { //dummy } #ifdef RGBLIGHT_EFFECT_BREATHING - else if (rgblight_config.mode >= RGBLIGHT_MODE_BREATHING && - rgblight_config.mode <= RGBLIGHT_MODE_BREATHING_end) { + else if (rgblight_status.base_mode == RGBLIGHT_MODE_BREATHING) { // breathing mode - rgblight_effect_breathing(rgblight_config.mode - RGBLIGHT_MODE_BREATHING ); + interval_time = get_interval_time(&RGBLED_BREATHING_INTERVALS[delta], 1, 100); + effect_func = rgblight_effect_breathing; } #endif #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD - else if (rgblight_config.mode >= RGBLIGHT_MODE_RAINBOW_MOOD && - rgblight_config.mode <= RGBLIGHT_MODE_RAINBOW_MOOD_end) { + else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_MOOD) { // rainbow mood mode - rgblight_effect_rainbow_mood(rgblight_config.mode - RGBLIGHT_MODE_RAINBOW_MOOD); + interval_time = get_interval_time(&RGBLED_RAINBOW_MOOD_INTERVALS[delta], 5, 100); + effect_func = rgblight_effect_rainbow_mood; } #endif #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL - else if (rgblight_config.mode >= RGBLIGHT_MODE_RAINBOW_SWIRL && - rgblight_config.mode <= RGBLIGHT_MODE_RAINBOW_SWIRL_end) { + else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_SWIRL) { // rainbow swirl mode - rgblight_effect_rainbow_swirl(rgblight_config.mode - RGBLIGHT_MODE_RAINBOW_SWIRL); + interval_time = get_interval_time(&RGBLED_RAINBOW_SWIRL_INTERVALS[delta / 2], 1, 100); + effect_func = rgblight_effect_rainbow_swirl; } #endif #ifdef RGBLIGHT_EFFECT_SNAKE - else if (rgblight_config.mode >= RGBLIGHT_MODE_SNAKE && - rgblight_config.mode <= RGBLIGHT_MODE_SNAKE_end) { + else if (rgblight_status.base_mode == RGBLIGHT_MODE_SNAKE) { // snake mode - rgblight_effect_snake(rgblight_config.mode - RGBLIGHT_MODE_SNAKE); + interval_time = get_interval_time(&RGBLED_SNAKE_INTERVALS[delta / 2], 1, 200); + effect_func = rgblight_effect_snake; } #endif #ifdef RGBLIGHT_EFFECT_KNIGHT - else if (rgblight_config.mode >= RGBLIGHT_MODE_KNIGHT && - rgblight_config.mode <= RGBLIGHT_MODE_KNIGHT_end) { + else if (rgblight_status.base_mode == RGBLIGHT_MODE_KNIGHT) { // knight mode - rgblight_effect_knight(rgblight_config.mode - RGBLIGHT_MODE_KNIGHT); + interval_time = get_interval_time(&RGBLED_KNIGHT_INTERVALS[delta], 5, 100); + effect_func = rgblight_effect_knight; } #endif #ifdef RGBLIGHT_EFFECT_CHRISTMAS - else if (rgblight_config.mode == RGBLIGHT_MODE_CHRISTMAS) { + else if (rgblight_status.base_mode == RGBLIGHT_MODE_CHRISTMAS) { // christmas mode - rgblight_effect_christmas(); + interval_time = RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL; + effect_func = (effect_func_t)rgblight_effect_christmas; } #endif #ifdef RGBLIGHT_EFFECT_RGB_TEST - else if (rgblight_config.mode == RGBLIGHT_MODE_RGB_TEST) { + else if (rgblight_status.base_mode == RGBLIGHT_MODE_RGB_TEST) { // RGB test mode - rgblight_effect_rgbtest(); + interval_time = pgm_read_word(&RGBLED_RGBTEST_INTERVALS[0]); + effect_func = (effect_func_t)rgblight_effect_rgbtest; } #endif #ifdef RGBLIGHT_EFFECT_ALTERNATING - else if (rgblight_config.mode == RGBLIGHT_MODE_ALTERNATING){ - rgblight_effect_alternating(); + else if (rgblight_status.base_mode == RGBLIGHT_MODE_ALTERNATING){ + interval_time = 500; + effect_func = (effect_func_t)rgblight_effect_alternating; + } +#endif + if (animation_status.restart) { + animation_status.restart = false; + animation_status.last_timer = timer_read() - interval_time - 1; + animation_status.pos16 = 0; // restart signal to local each effect } + if (timer_elapsed(animation_status.last_timer) >= interval_time) { +#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) + static uint16_t report_last_timer = 0; + static bool tick_flag = false; + uint16_t oldpos16; + if (tick_flag) { + tick_flag = false; + //dprintf("rgblight animation tick\n"); + if (timer_elapsed(report_last_timer) >= 30000) { + report_last_timer = timer_read(); + dprintf("rgblight animation tick report to slave\n"); + RGBLIGHT_SPLIT_ANIMATION_TICK; + } + } + oldpos16 = animation_status.pos16; + //dprintf("call effect function\n"); +#endif + animation_status.last_timer += interval_time; + effect_func(&animation_status); +#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) + //dprintf("pos16, oldpos16 = %d %d\n", + // animation_status.pos16,oldpos16); + if (animation_status.pos16 == 0 && oldpos16 != 0) { + //dprintf("flag on\n"); + tick_flag = true; + } #endif + } } } @@ -819,22 +972,13 @@ void rgblight_task(void) { __attribute__ ((weak)) const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5}; -void rgblight_effect_breathing(uint8_t interval) { - static uint8_t pos = 0; - static uint16_t last_timer = 0; +void rgblight_effect_breathing(animation_status_t *anim) { float val; - uint8_t interval_time = get_interval_time(&RGBLED_BREATHING_INTERVALS[interval], 1, 100); - - if (timer_elapsed(last_timer) < interval_time) { - return; - } - last_timer = timer_read(); - // http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ - val = (exp(sin((pos/255.0)*M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)*(RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E)); + val = (exp(sin((anim->pos/255.0)*M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)*(RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E)); rgblight_sethsv_noeeprom_old(rgblight_config.hue, rgblight_config.sat, val); - pos = (pos + 1) % 256; + anim->pos = (anim->pos + 1) % 256; } #endif @@ -842,18 +986,9 @@ void rgblight_effect_breathing(uint8_t interval) { __attribute__ ((weak)) const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[] PROGMEM = {120, 60, 30}; -void rgblight_effect_rainbow_mood(uint8_t interval) { - static uint16_t current_hue = 0; - static uint16_t last_timer = 0; - - uint8_t interval_time = get_interval_time(&RGBLED_RAINBOW_MOOD_INTERVALS[interval], 5, 100); - - if (timer_elapsed(last_timer) < interval_time) { - return; - } - last_timer = timer_read(); - rgblight_sethsv_noeeprom_old(current_hue, rgblight_config.sat, rgblight_config.val); - current_hue = (current_hue + 1) % 360; +void rgblight_effect_rainbow_mood(animation_status_t *anim) { + rgblight_sethsv_noeeprom_old(anim->current_hue, rgblight_config.sat, rgblight_config.val); + anim->current_hue = (anim->current_hue + 1) % 360; } #endif @@ -865,31 +1000,23 @@ void rgblight_effect_rainbow_mood(uint8_t interval) { __attribute__ ((weak)) const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[] PROGMEM = {100, 50, 20}; -void rgblight_effect_rainbow_swirl(uint8_t interval) { - static uint16_t current_hue = 0; - static uint16_t last_timer = 0; +void rgblight_effect_rainbow_swirl(animation_status_t *anim) { uint16_t hue; uint8_t i; - uint8_t interval_time = get_interval_time(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2], 1, 100); - - if (timer_elapsed(last_timer) < interval_time) { - return; - } - last_timer = timer_read(); for (i = 0; i < RGBLED_NUM; i++) { - hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / RGBLED_NUM * i + current_hue) % 360; + hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / RGBLED_NUM * i + anim->current_hue) % 360; sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]); } rgblight_set(); - if (interval % 2) { - current_hue = (current_hue + 1) % 360; + if (anim->delta % 2) { + anim->current_hue = (anim->current_hue + 1) % 360; } else { - if (current_hue - 1 < 0) { - current_hue = 359; + if (anim->current_hue - 1 < 0) { + anim->current_hue = 359; } else { - current_hue = current_hue - 1; + anim->current_hue = anim->current_hue - 1; } } } @@ -899,22 +1026,27 @@ void rgblight_effect_rainbow_swirl(uint8_t interval) { __attribute__ ((weak)) const uint8_t RGBLED_SNAKE_INTERVALS[] PROGMEM = {100, 50, 20}; -void rgblight_effect_snake(uint8_t interval) { +void rgblight_effect_snake(animation_status_t *anim) { static uint8_t pos = 0; - static uint16_t last_timer = 0; uint8_t i, j; int8_t k; int8_t increment = 1; - if (interval % 2) { + + if (anim->delta % 2) { increment = -1; } - uint8_t interval_time = get_interval_time(&RGBLED_SNAKE_INTERVALS[interval / 2], 1, 200); - - if (timer_elapsed(last_timer) < interval_time) { - return; +#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) + if (anim->pos == 0) { // restart signal + if (increment == 1) { + pos = RGBLED_NUM - 1; + } else { + pos = 0; + } + anim->pos = 1; } - last_timer = timer_read(); +#endif + for (i = 0; i < RGBLED_NUM; i++) { led[i].r = 0; led[i].g = 0; @@ -925,7 +1057,9 @@ void rgblight_effect_snake(uint8_t interval) { k = k + RGBLED_NUM; } if (i == k) { - 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]); + 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]); } } } @@ -933,11 +1067,20 @@ void rgblight_effect_snake(uint8_t interval) { if (increment == 1) { if (pos - 1 < 0) { pos = RGBLED_NUM - 1; +#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) + anim->pos = 0; +#endif } else { pos -= 1; +#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) + anim->pos = 1; +#endif } } else { pos = (pos + 1) % RGBLED_NUM; +#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) + anim->pos = pos; +#endif } } #endif @@ -946,21 +1089,21 @@ void rgblight_effect_snake(uint8_t interval) { __attribute__ ((weak)) const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {127, 63, 31}; -void rgblight_effect_knight(uint8_t interval) { - static uint16_t last_timer = 0; - - uint8_t interval_time = get_interval_time(&RGBLED_KNIGHT_INTERVALS[interval], 5, 100); - - if (timer_elapsed(last_timer) < interval_time) { - return; - } - last_timer = timer_read(); +void rgblight_effect_knight(animation_status_t *anim) { static int8_t low_bound = 0; static int8_t high_bound = RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1; static int8_t increment = 1; uint8_t i, cur; +#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) + if (anim->pos == 0) { // restart signal + anim->pos = 1; + low_bound = 0; + high_bound = RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1; + increment = 1; + } +#endif // Set all the LEDs to 0 for (i = 0; i < RGBLED_NUM; i++) { led[i].r = 0; @@ -988,23 +1131,23 @@ void rgblight_effect_knight(uint8_t interval) { if (high_bound <= 0 || low_bound >= RGBLIGHT_EFFECT_KNIGHT_LED_NUM - 1) { increment = -increment; +#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) + if (increment == 1) { + anim->pos = 0; + } +#endif } } #endif #ifdef RGBLIGHT_EFFECT_CHRISTMAS -void rgblight_effect_christmas(void) { - static uint16_t current_offset = 0; - static uint16_t last_timer = 0; +void rgblight_effect_christmas(animation_status_t *anim) { uint16_t hue; uint8_t i; - if (timer_elapsed(last_timer) < RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL) { - return; - } - last_timer = timer_read(); - current_offset = (current_offset + 1) % 2; + + anim->current_offset = (anim->current_offset + 1) % 2; for (i = 0; i < RGBLED_NUM; i++) { - hue = 0 + ((i/RGBLIGHT_EFFECT_CHRISTMAS_STEP + current_offset) % 2) * 120; + hue = 0 + ((i/RGBLIGHT_EFFECT_CHRISTMAS_STEP + anim->current_offset) % 2) * 120; sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]); } rgblight_set(); @@ -1015,52 +1158,39 @@ void rgblight_effect_christmas(void) { __attribute__ ((weak)) const uint16_t RGBLED_RGBTEST_INTERVALS[] PROGMEM = {1024}; -void rgblight_effect_rgbtest(void) { - static uint8_t pos = 0; - static uint16_t last_timer = 0; +void rgblight_effect_rgbtest(animation_status_t *anim) { static uint8_t maxval = 0; uint8_t g; uint8_t r; uint8_t b; - if (timer_elapsed(last_timer) < pgm_read_word(&RGBLED_RGBTEST_INTERVALS[0])) { - return; - } - if( maxval == 0 ) { LED_TYPE tmp_led; sethsv(0, 255, RGBLIGHT_LIMIT_VAL, &tmp_led); maxval = tmp_led.r; } - last_timer = timer_read(); g = r = b = 0; - switch( pos ) { + switch( anim->pos ) { case 0: r = maxval; break; case 1: g = maxval; break; case 2: b = maxval; break; } rgblight_setrgb(r, g, b); - pos = (pos + 1) % 3; + anim->pos = (anim->pos + 1) % 3; } #endif #ifdef RGBLIGHT_EFFECT_ALTERNATING -void rgblight_effect_alternating(void){ - static uint16_t last_timer = 0; - static uint16_t pos = 0; - if (timer_elapsed(last_timer) < 500) { - return; - } - last_timer = timer_read(); +void rgblight_effect_alternating(animation_status_t *anim) { for(int i = 0; ipos){ sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]); - }else if (i>=RGBLED_NUM/2 && !pos){ + }else if (i>=RGBLED_NUM/2 && !anim->pos){ sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]); }else{ sethsv(rgblight_config.hue, rgblight_config.sat, 0, (LED_TYPE *)&led[i]); } } rgblight_set(); - pos = (pos + 1) % 2; + anim->pos = (anim->pos + 1) % 2; } #endif -- cgit v1.2.3 From 5312131d35ee389231bfc596625ac5915264cc16 Mon Sep 17 00:00:00 2001 From: mtei <2170248+mtei@users.noreply.github.com> Date: Wed, 24 Apr 2019 02:38:54 +0900 Subject: add RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; to eeconfig_update_rgblight_default() --- quantum/rgblight.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 5ec11bc077..0b90b79eaf 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -38,11 +38,13 @@ /* for split keyboard */ #define RGBLIGHT_SPLIT_SET_CHANGE_MODE rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_MODE #define RGBLIGHT_SPLIT_SET_CHANGE_HSVS rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_HSVS + #define RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS rgblight_status.change_flags |= (RGBLIGHT_STATUS_CHANGE_MODE|RGBLIGHT_STATUS_CHANGE_HSVS) #define RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_TIMER #define RGBLIGHT_SPLIT_ANIMATION_TICK rgblight_status.change_flags |= RGBLIGHT_STATUS_ANIMATION_TICK #else #define RGBLIGHT_SPLIT_SET_CHANGE_MODE #define RGBLIGHT_SPLIT_SET_CHANGE_HSVS + #define RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS #define RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE #define RGBLIGHT_SPLIT_ANIMATION_TICK #endif @@ -221,6 +223,7 @@ void eeconfig_update_rgblight_default(void) { rgblight_config.sat = 255; rgblight_config.val = RGBLIGHT_LIMIT_VAL; rgblight_config.speed = 0; + RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; eeconfig_update_rgblight(rgblight_config.raw); } @@ -249,7 +252,7 @@ void rgblight_init(void) { eeconfig_update_rgblight_default(); } rgblight_config.raw = eeconfig_read_rgblight(); - RGBLIGHT_SPLIT_SET_CHANGE_HSVS; + RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; if (!rgblight_config.mode) { dprintf("rgblight_init rgblight_config.mode = 0. Write default values to EEPROM.\n"); eeconfig_update_rgblight_default(); -- cgit v1.2.3 From 9f8c8c53a51ec6bb8acd55683b1d024558b071ab Mon Sep 17 00:00:00 2001 From: mtei <2170248+mtei@users.noreply.github.com> Date: Wed, 24 Apr 2019 02:43:44 +0900 Subject: add RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; to rgblight_update_dword() --- quantum/rgblight.c | 1 + 1 file changed, 1 insertion(+) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 0b90b79eaf..2f23768ed7 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -279,6 +279,7 @@ uint32_t rgblight_read_dword(void) { } void rgblight_update_dword(uint32_t dword) { + RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; rgblight_config.raw = dword; if (rgblight_config.enable) rgblight_mode_noeeprom(rgblight_config.mode); -- cgit v1.2.3 From 22ba36a4d86c06ce1b6049555525646eb16bb57a Mon Sep 17 00:00:00 2001 From: XScorpion2 Date: Wed, 1 May 2019 10:02:02 -0500 Subject: rgblight 255 hue (#5547) --- quantum/rgblight.c | 200 ++++++++++++++--------------------------------------- 1 file changed, 51 insertions(+), 149 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 2f23768ed7..98755ff08b 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -28,8 +28,10 @@ #include "progmem.h" #include "timer.h" #include "rgblight.h" +#include "color.h" #include "debug.h" #include "led_tables.h" +#include "lib/lib8tion/lib8tion.h" #ifdef VELOCIKEY_ENABLE #include "velocikey.h" #endif @@ -74,16 +76,13 @@ static inline int is_static_effect(uint8_t mode) { return memchr(static_effect_table, mode, sizeof(static_effect_table)) != NULL; } -#define MIN(a,b) (((a)<(b))?(a):(b)) -#define MAX(a,b) (((a)>(b))?(a):(b)) - #ifdef RGBLIGHT_LED_MAP const uint8_t led_map[] PROGMEM = RGBLIGHT_LED_MAP; #endif #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT __attribute__ ((weak)) -const uint16_t RGBLED_GRADIENT_RANGES[] PROGMEM = {360, 240, 180, 120, 90}; +const uint8_t RGBLED_GRADIENT_RANGES[] PROGMEM = {255, 170, 127, 85, 64}; #endif rgblight_config_t rgblight_config; @@ -109,59 +108,10 @@ void rgblight_set_clipping_range(uint8_t start_pos, uint8_t num_leds) { } -void sethsv(uint16_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { - uint8_t r = 0, g = 0, b = 0, base, color; - - if (val > RGBLIGHT_LIMIT_VAL) { - val=RGBLIGHT_LIMIT_VAL; // limit the val - } - - if (sat == 0) { // Acromatic color (gray). Hue doesn't mind. - r = val; - g = val; - b = val; - } else { - base = ((255 - sat) * val) >> 8; - color = (val - base) * (hue % 60) / 60; - - switch (hue / 60) { - case 0: - r = val; - g = base + color; - b = base; - break; - case 1: - r = val - color; - g = val; - b = base; - break; - case 2: - r = base; - g = val; - b = base + color; - break; - case 3: - r = base; - g = val - color; - b = val; - break; - case 4: - r = base + color; - g = base; - b = val; - break; - case 5: - r = val; - g = base; - b = val - color; - break; - } - } - r = pgm_read_byte(&CIE1931_CURVE[r]); - g = pgm_read_byte(&CIE1931_CURVE[g]); - b = pgm_read_byte(&CIE1931_CURVE[b]); - - setrgb(r, g, b, led1); +void sethsv(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { + HSV hsv = { hue, sat, val > RGBLIGHT_LIMIT_VAL ? RGBLIGHT_LIMIT_VAL : val }; + RGB rgb = hsv_to_rgb(hsv); + setrgb(rgb.r, rgb.g, rgb.b, led1); } void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1) { @@ -180,24 +130,9 @@ void rgblight_check_config(void) { rgblight_config.mode = RGBLIGHT_MODES; } - if (rgblight_config.hue < 0) { - rgblight_config.hue = 0; - } else if (rgblight_config.hue > 360) { - rgblight_config.hue %= 360; - } - - if (rgblight_config.sat < 0) { - rgblight_config.sat = 0; - } else if (rgblight_config.sat > 255) { - rgblight_config.sat = 255; - } - - if (rgblight_config.val < 0) { - rgblight_config.val = 0; - } else if (rgblight_config.val > RGBLIGHT_LIMIT_VAL) { + if (rgblight_config.val > RGBLIGHT_LIMIT_VAL) { rgblight_config.val = RGBLIGHT_LIMIT_VAL; } - } uint32_t eeconfig_read_rgblight(void) { @@ -220,7 +155,7 @@ void eeconfig_update_rgblight_default(void) { rgblight_config.enable = 1; rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT; rgblight_config.hue = 0; - rgblight_config.sat = 255; + rgblight_config.sat = UINT8_MAX; rgblight_config.val = RGBLIGHT_LIMIT_VAL; rgblight_config.speed = 0; RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; @@ -442,23 +377,8 @@ void rgblight_disable_noeeprom(void) { rgblight_set(); } - -// Deals with the messy details of incrementing an integer -static uint8_t increment( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) { - int16_t new_value = value; - new_value += step; - return MIN( MAX( new_value, min ), max ); -} - -static uint8_t decrement( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) { - int16_t new_value = value; - new_value -= step; - return MIN( MAX( new_value, min ), max ); -} - void rgblight_increase_hue_helper(bool write_to_eeprom) { - uint16_t hue; - hue = (rgblight_config.hue+RGBLIGHT_HUE_STEP) % 360; + uint8_t hue = rgblight_config.hue + RGBLIGHT_HUE_STEP; rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom); } void rgblight_increase_hue_noeeprom(void) { @@ -468,12 +388,7 @@ void rgblight_increase_hue(void) { rgblight_increase_hue_helper(true); } void rgblight_decrease_hue_helper(bool write_to_eeprom) { - uint16_t hue; - if (rgblight_config.hue-RGBLIGHT_HUE_STEP < 0) { - hue = (rgblight_config.hue + 360 - RGBLIGHT_HUE_STEP) % 360; - } else { - hue = (rgblight_config.hue - RGBLIGHT_HUE_STEP) % 360; - } + uint8_t hue = rgblight_config.hue - RGBLIGHT_HUE_STEP; rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom); } void rgblight_decrease_hue_noeeprom(void) { @@ -483,12 +398,7 @@ void rgblight_decrease_hue(void) { rgblight_decrease_hue_helper(true); } void rgblight_increase_sat_helper(bool write_to_eeprom) { - uint8_t sat; - if (rgblight_config.sat + RGBLIGHT_SAT_STEP > 255) { - sat = 255; - } else { - sat = rgblight_config.sat + RGBLIGHT_SAT_STEP; - } + uint8_t sat = qadd8(rgblight_config.sat, RGBLIGHT_SAT_STEP); rgblight_sethsv_eeprom_helper(rgblight_config.hue, sat, rgblight_config.val, write_to_eeprom); } void rgblight_increase_sat_noeeprom(void) { @@ -498,12 +408,7 @@ void rgblight_increase_sat(void) { rgblight_increase_sat_helper(true); } void rgblight_decrease_sat_helper(bool write_to_eeprom) { - uint8_t sat; - if (rgblight_config.sat - RGBLIGHT_SAT_STEP < 0) { - sat = 0; - } else { - sat = rgblight_config.sat - RGBLIGHT_SAT_STEP; - } + uint8_t sat = qsub8(rgblight_config.sat, RGBLIGHT_SAT_STEP); rgblight_sethsv_eeprom_helper(rgblight_config.hue, sat, rgblight_config.val, write_to_eeprom); } void rgblight_decrease_sat_noeeprom(void) { @@ -513,12 +418,7 @@ void rgblight_decrease_sat(void) { rgblight_decrease_sat_helper(true); } void rgblight_increase_val_helper(bool write_to_eeprom) { - uint8_t val; - if (rgblight_config.val + RGBLIGHT_VAL_STEP > RGBLIGHT_LIMIT_VAL) { - val = RGBLIGHT_LIMIT_VAL; - } else { - val = rgblight_config.val + RGBLIGHT_VAL_STEP; - } + uint8_t val = qadd8(rgblight_config.val, RGBLIGHT_VAL_STEP); rgblight_sethsv_eeprom_helper(rgblight_config.hue, rgblight_config.sat, val, write_to_eeprom); } void rgblight_increase_val_noeeprom(void) { @@ -528,12 +428,7 @@ void rgblight_increase_val(void) { rgblight_increase_val_helper(true); } void rgblight_decrease_val_helper(bool write_to_eeprom) { - uint8_t val; - if (rgblight_config.val - RGBLIGHT_VAL_STEP < 0) { - val = 0; - } else { - val = rgblight_config.val - RGBLIGHT_VAL_STEP; - } + uint8_t val = qsub8(rgblight_config.val, RGBLIGHT_VAL_STEP); rgblight_sethsv_eeprom_helper(rgblight_config.hue, rgblight_config.sat, val, write_to_eeprom); } void rgblight_decrease_val_noeeprom(void) { @@ -543,18 +438,20 @@ void rgblight_decrease_val(void) { rgblight_decrease_val_helper(true); } void rgblight_increase_speed(void) { - rgblight_config.speed = increment( rgblight_config.speed, 1, 0, 3 ); + if (rgblight_config.speed < 3) + rgblight_config.speed++; //RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED? eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this } void rgblight_decrease_speed(void) { - rgblight_config.speed = decrement( rgblight_config.speed, 1, 0, 3 ); + if (rgblight_config.speed > 0) + rgblight_config.speed--; //RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED?? eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this } -void rgblight_sethsv_noeeprom_old(uint16_t hue, uint8_t sat, uint8_t val) { +void rgblight_sethsv_noeeprom_old(uint8_t hue, uint8_t sat, uint8_t val) { if (rgblight_config.enable) { LED_TYPE tmp_led; sethsv(hue, sat, val, &tmp_led); @@ -563,7 +460,7 @@ void rgblight_sethsv_noeeprom_old(uint16_t hue, uint8_t sat, uint8_t val) { } } -void rgblight_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom) { +void rgblight_sethsv_eeprom_helper(uint8_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom) { if (rgblight_config.enable) { rgblight_status.base_mode = mode_base_table[rgblight_config.mode]; if (rgblight_config.mode == RGBLIGHT_MODE_STATIC_LIGHT) { @@ -596,13 +493,22 @@ void rgblight_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT else if (rgblight_status.base_mode == RGBLIGHT_MODE_STATIC_GRADIENT) { // static gradient - uint16_t _hue; uint8_t delta = rgblight_config.mode - rgblight_status.base_mode; - int8_t direction = (delta % 2) ? -1 : 1; - uint16_t range = pgm_read_word(&RGBLED_GRADIENT_RANGES[delta / 2]); + bool direction = (delta % 2) == 0; +#ifdef __AVR__ + // probably due to how pgm_read_word is defined for ARM, but the ARM compiler really hates this line + uint8_t range = pgm_read_word(&RGBLED_GRADIENT_RANGES[delta / 2]); +#else + uint8_t range = RGBLED_GRADIENT_RANGES[delta / 2]; +#endif for (uint8_t i = 0; i < RGBLED_NUM; i++) { - _hue = (range / RGBLED_NUM * i * direction + hue + 360) % 360; - dprintf("rgblight rainbow set hsv: %u,%u,%d,%u\n", i, _hue, direction, range); + uint8_t _hue = ((uint16_t)i * (uint16_t)range) / RGBLED_NUM; + if (direction) { + _hue = hue + _hue; + } else { + _hue = hue - _hue; + } + dprintf("rgblight rainbow set hsv: %d,%d,%d,%u\n", i, _hue, direction, range); sethsv(_hue, sat, val, (LED_TYPE *)&led[i]); } rgblight_set(); @@ -628,15 +534,15 @@ void rgblight_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool } } -void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val) { +void rgblight_sethsv(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_sethsv_eeprom_helper(hue, sat, val, true); } -void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { +void rgblight_sethsv_noeeprom(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_sethsv_eeprom_helper(hue, sat, val, false); } -uint16_t rgblight_get_hue(void) { +uint8_t rgblight_get_hue(void) { return rgblight_config.hue; } @@ -668,7 +574,7 @@ void rgblight_setrgb_at(uint8_t r, uint8_t g, uint8_t b, uint8_t index) { rgblight_set(); } -void rgblight_sethsv_at(uint16_t hue, uint8_t sat, uint8_t val, uint8_t index) { +void rgblight_sethsv_at(uint8_t hue, uint8_t sat, uint8_t val, uint8_t index) { if (!rgblight_config.enable) { return; } LED_TYPE tmp_led; @@ -701,7 +607,7 @@ void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8 wait_ms(1); } -void rgblight_sethsv_range(uint16_t hue, uint8_t sat, uint8_t val, uint8_t start, uint8_t end) { +void rgblight_sethsv_range(uint8_t hue, uint8_t sat, uint8_t val, uint8_t start, uint8_t end) { if (!rgblight_config.enable) { return; } LED_TYPE tmp_led; @@ -717,11 +623,11 @@ 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); } -void rgblight_sethsv_master(uint16_t hue, uint8_t sat, uint8_t val) { +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); } -void rgblight_sethsv_slave(uint16_t hue, uint8_t sat, uint8_t val) { +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); } @@ -982,7 +888,7 @@ void rgblight_effect_breathing(animation_status_t *anim) { // http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ val = (exp(sin((anim->pos/255.0)*M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)*(RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E)); rgblight_sethsv_noeeprom_old(rgblight_config.hue, rgblight_config.sat, val); - anim->pos = (anim->pos + 1) % 256; + anim->pos = (anim->pos + 1); } #endif @@ -992,36 +898,32 @@ const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[] PROGMEM = {120, 60, 30}; void rgblight_effect_rainbow_mood(animation_status_t *anim) { rgblight_sethsv_noeeprom_old(anim->current_hue, rgblight_config.sat, rgblight_config.val); - anim->current_hue = (anim->current_hue + 1) % 360; + anim->current_hue++; } #endif #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL #ifndef RGBLIGHT_RAINBOW_SWIRL_RANGE - #define RGBLIGHT_RAINBOW_SWIRL_RANGE 360 + #define RGBLIGHT_RAINBOW_SWIRL_RANGE 255 #endif __attribute__ ((weak)) const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[] PROGMEM = {100, 50, 20}; void rgblight_effect_rainbow_swirl(animation_status_t *anim) { - uint16_t hue; + uint8_t hue; uint8_t i; for (i = 0; i < RGBLED_NUM; i++) { - hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / RGBLED_NUM * i + anim->current_hue) % 360; + hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / RGBLED_NUM * i + anim->current_hue); sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]); } rgblight_set(); if (anim->delta % 2) { - anim->current_hue = (anim->current_hue + 1) % 360; + anim->current_hue++; } else { - if (anim->current_hue - 1 < 0) { - anim->current_hue = 359; - } else { - anim->current_hue = anim->current_hue - 1; - } + anim->current_hue--; } } #endif @@ -1146,12 +1048,12 @@ void rgblight_effect_knight(animation_status_t *anim) { #ifdef RGBLIGHT_EFFECT_CHRISTMAS void rgblight_effect_christmas(animation_status_t *anim) { - uint16_t hue; + uint8_t hue; uint8_t i; anim->current_offset = (anim->current_offset + 1) % 2; for (i = 0; i < RGBLED_NUM; i++) { - hue = 0 + ((i/RGBLIGHT_EFFECT_CHRISTMAS_STEP + anim->current_offset) % 2) * 120; + hue = 0 + ((i/RGBLIGHT_EFFECT_CHRISTMAS_STEP + anim->current_offset) % 2) * 85; sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]); } rgblight_set(); -- cgit v1.2.3 From 3da8d46a07167fc862e90b6bb232812d5cb64651 Mon Sep 17 00:00:00 2001 From: Takeshi ISHII <2170248+mtei@users.noreply.github.com> Date: Thu, 2 May 2019 23:59:29 +0900 Subject: If RGBLIGHT_EFFECT_BREATHE_CENTER is undefined, use fixed breathe table instead of exp() and sin() (#5484) * If RGBLIGHT_EFFECT_BREATHE_CENTER is undefined, use fixed breathe table instead of exp() and sin() * Change rgblight breathing table size to be easily selectable. add RGBLIGHT_BREATHE_TABLE_SIZE macro for customize breathing effect. --- quantum/rgblight.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 98755ff08b..77772e2925 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -879,6 +879,14 @@ void rgblight_task(void) { // Effects #ifdef RGBLIGHT_EFFECT_BREATHING + +#ifndef RGBLIGHT_EFFECT_BREATHE_CENTER + #ifndef RGBLIGHT_BREATHE_TABLE_SIZE + #define RGBLIGHT_BREATHE_TABLE_SIZE 256 // 256 or 128 or 64 + #endif + #include +#endif + __attribute__ ((weak)) const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5}; @@ -886,7 +894,11 @@ void rgblight_effect_breathing(animation_status_t *anim) { float val; // http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ +#ifdef RGBLIGHT_EFFECT_BREATHE_TABLE + val = pgm_read_byte(&rgblight_effect_breathe_table[anim->pos / table_scale]); +#else val = (exp(sin((anim->pos/255.0)*M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)*(RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E)); +#endif rgblight_sethsv_noeeprom_old(rgblight_config.hue, rgblight_config.sat, val); anim->pos = (anim->pos + 1); } -- cgit v1.2.3 From 670a9b7f83dacf2b0e9fb42756935a77598c6677 Mon Sep 17 00:00:00 2001 From: Takeshi ISHII <2170248+mtei@users.noreply.github.com> Date: Thu, 16 May 2019 13:11:28 +0900 Subject: Add effect range to rgblight.c (#5856) * add rgblight_set_effect_range() * implement effect range * Arrange the order of function list in rgblight.h . * update docs/feature_rgblight.md * fix RGBLIGHT_RAINBOW_SWIRL_RANGE default value * add example code about Utility Functions * add example code about direct operation functions * When RGBLIGHT_SPLIT is defined, the following function has no meaning and is invalidated. * rgblight_setrgb_master(r, g, b) * rgblight_setrgb_slave(r, g, b) * rgblight_sethsv_master(h, s, v) * rgblight_sethsv_slave(h, s, v) * add temporary test code for rgblight_set_effect_range * fix rgblight_effect_knight() bug * Test End. Revert "add temporary test code for rgblight_set_effect_range" This reverts commit 5680cddd012d68b2db75a532862a7fef250f8973. --- quantum/rgblight.c | 117 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 67 insertions(+), 50 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 77772e2925..75e4ef0d86 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -101,19 +101,35 @@ LED_TYPE led[RGBLED_NUM]; static uint8_t clipping_start_pos = 0; static uint8_t clipping_num_leds = RGBLED_NUM; +static uint8_t effect_start_pos = 0; +static uint8_t effect_end_pos = RGBLED_NUM; +static uint8_t effect_num_leds = RGBLED_NUM; void rgblight_set_clipping_range(uint8_t start_pos, uint8_t num_leds) { clipping_start_pos = start_pos; clipping_num_leds = num_leds; } +void rgblight_set_effect_range(uint8_t start_pos, uint8_t num_leds) { + if (start_pos >= RGBLED_NUM) return; + if (start_pos + num_leds > RGBLED_NUM) return; + effect_start_pos = start_pos; + effect_end_pos = start_pos + num_leds; + effect_num_leds = num_leds; +} -void sethsv(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { - HSV hsv = { hue, sat, val > RGBLIGHT_LIMIT_VAL ? RGBLIGHT_LIMIT_VAL : val }; +void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { + HSV hsv = { hue, sat, val }; RGB rgb = hsv_to_rgb(hsv); setrgb(rgb.r, rgb.g, rgb.b, led1); } +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); +} + void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1) { (*led1).r = r; (*led1).g = g; @@ -501,15 +517,15 @@ void rgblight_sethsv_eeprom_helper(uint8_t hue, uint8_t sat, uint8_t val, bool w #else uint8_t range = RGBLED_GRADIENT_RANGES[delta / 2]; #endif - for (uint8_t i = 0; i < RGBLED_NUM; i++) { - uint8_t _hue = ((uint16_t)i * (uint16_t)range) / RGBLED_NUM; + for (uint8_t i = 0; i < effect_num_leds; i++) { + uint8_t _hue = ((uint16_t)i * (uint16_t)range) / effect_num_leds; if (direction) { _hue = hue + _hue; } else { _hue = hue - _hue; } dprintf("rgblight rainbow set hsv: %d,%d,%d,%u\n", i, _hue, direction, range); - sethsv(_hue, sat, val, (LED_TYPE *)&led[i]); + sethsv(_hue, sat, val, (LED_TYPE *)&led[i + effect_start_pos]); } rgblight_set(); } @@ -557,7 +573,7 @@ uint8_t rgblight_get_val(void) { void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b) { if (!rgblight_config.enable) { return; } - for (uint8_t i = 0; i < RGBLED_NUM; i++) { + for (uint8_t i = effect_start_pos; i < effect_end_pos; i++) { led[i].r = r; led[i].g = g; led[i].b = b; @@ -615,6 +631,7 @@ void rgblight_sethsv_range(uint8_t hue, uint8_t sat, uint8_t val, uint8_t start, rgblight_setrgb_range(tmp_led.r, tmp_led.g, tmp_led.b, start, end); } +#ifndef RGBLIGHT_SPLIT 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); } @@ -630,36 +647,34 @@ void rgblight_sethsv_master(uint8_t hue, uint8_t sat, uint8_t val) { 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); } +#endif // ifndef RGBLIGHT_SPLIT #ifndef RGBLIGHT_CUSTOM_DRIVER void rgblight_set(void) { - LED_TYPE *start_led = led + clipping_start_pos; + LED_TYPE *start_led; uint16_t num_leds = clipping_num_leds; - if (rgblight_config.enable) { - #ifdef RGBLIGHT_LED_MAP - LED_TYPE led0[RGBLED_NUM]; - for(uint8_t i = 0; i < RGBLED_NUM; i++) { - led0[i] = led[pgm_read_byte(&led_map[i])]; - } - start_led = led0 + clipping_start_pos; - #endif - #ifdef RGBW - ws2812_setleds_rgbw(start_led, num_leds); - #else - ws2812_setleds(start_led, num_leds); - #endif - } else { - for (uint8_t i = 0; i < RGBLED_NUM; i++) { + + if (!rgblight_config.enable) { + for (uint8_t i = effect_start_pos; i < effect_end_pos; i++) { led[i].r = 0; led[i].g = 0; led[i].b = 0; } - #ifdef RGBW - ws2812_setleds_rgbw(start_led, num_leds); - #else - ws2812_setleds(start_led, num_leds); - #endif } +#ifdef RGBLIGHT_LED_MAP + LED_TYPE led0[RGBLED_NUM]; + for(uint8_t i = 0; i < RGBLED_NUM; i++) { + led0[i] = led[pgm_read_byte(&led_map[i])]; + } + start_led = led0 + clipping_start_pos; +#else + start_led = led + clipping_start_pos; +#endif +#ifdef RGBW + ws2812_setleds_rgbw(start_led, num_leds); +#else + ws2812_setleds(start_led, num_leds); +#endif } #endif @@ -926,9 +941,9 @@ void rgblight_effect_rainbow_swirl(animation_status_t *anim) { uint8_t hue; uint8_t i; - for (i = 0; i < RGBLED_NUM; i++) { - hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / RGBLED_NUM * i + anim->current_hue); - sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]); + for (i = 0; i < effect_num_leds; i++) { + hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / effect_num_leds * i + anim->current_hue); + sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + effect_start_pos]); } rgblight_set(); @@ -957,7 +972,7 @@ void rgblight_effect_snake(animation_status_t *anim) { #if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) if (anim->pos == 0) { // restart signal if (increment == 1) { - pos = RGBLED_NUM - 1; + pos = effect_num_leds - 1; } else { pos = 0; } @@ -965,26 +980,27 @@ void rgblight_effect_snake(animation_status_t *anim) { } #endif - for (i = 0; i < RGBLED_NUM; i++) { - led[i].r = 0; - led[i].g = 0; - led[i].b = 0; + for (i = 0; i < effect_num_leds; i++) { + LED_TYPE *ledp = led + i + effect_start_pos; + ledp->r = 0; + ledp->g = 0; + ledp->b = 0; for (j = 0; j < RGBLIGHT_EFFECT_SNAKE_LENGTH; j++) { k = pos + j * increment; if (k < 0) { - k = k + RGBLED_NUM; + k = k + effect_num_leds; } if (i == k) { 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]); + ledp); } } } rgblight_set(); if (increment == 1) { if (pos - 1 < 0) { - pos = RGBLED_NUM - 1; + pos = effect_num_leds - 1; #if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) anim->pos = 0; #endif @@ -995,7 +1011,7 @@ void rgblight_effect_snake(animation_status_t *anim) { #endif } } else { - pos = (pos + 1) % RGBLED_NUM; + pos = (pos + 1) % effect_num_leds; #if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) anim->pos = pos; #endif @@ -1023,14 +1039,14 @@ void rgblight_effect_knight(animation_status_t *anim) { } #endif // Set all the LEDs to 0 - for (i = 0; i < RGBLED_NUM; i++) { + for (i = effect_start_pos; i < effect_end_pos; i++) { led[i].r = 0; led[i].g = 0; led[i].b = 0; } // Determine which LEDs should be lit up for (i = 0; i < RGBLIGHT_EFFECT_KNIGHT_LED_NUM; i++) { - cur = (i + RGBLIGHT_EFFECT_KNIGHT_OFFSET) % RGBLED_NUM; + cur = (i + RGBLIGHT_EFFECT_KNIGHT_OFFSET) % effect_num_leds + effect_start_pos; if (i >= low_bound && i <= high_bound) { sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[cur]); @@ -1064,9 +1080,9 @@ void rgblight_effect_christmas(animation_status_t *anim) { uint8_t i; anim->current_offset = (anim->current_offset + 1) % 2; - for (i = 0; i < RGBLED_NUM; i++) { + for (i = 0; i < effect_num_leds; i++) { hue = 0 + ((i/RGBLIGHT_EFFECT_CHRISTMAS_STEP + anim->current_offset) % 2) * 85; - sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]); + sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + effect_start_pos]); } rgblight_set(); } @@ -1099,13 +1115,14 @@ void rgblight_effect_rgbtest(animation_status_t *anim) { #ifdef RGBLIGHT_EFFECT_ALTERNATING void rgblight_effect_alternating(animation_status_t *anim) { - for(int i = 0; ipos){ - sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]); - }else if (i>=RGBLED_NUM/2 && !anim->pos){ - sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]); - }else{ - sethsv(rgblight_config.hue, rgblight_config.sat, 0, (LED_TYPE *)&led[i]); + for (int i = 0; i < effect_num_leds; i++) { + LED_TYPE *ledp = led + i + effect_start_pos; + if (ipos) { + sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp); + } else if (i>=effect_num_leds/2 && !anim->pos) { + sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp); + } else { + sethsv(rgblight_config.hue, rgblight_config.sat, 0, ledp); } } rgblight_set(); -- cgit v1.2.3 From e040028f1bf0d3c213667148455e9894cdf2c5ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20=C4=90or=C4=91evi=C4=87?= Date: Fri, 19 Jul 2019 17:47:04 +0200 Subject: Change xprintf() calls in rgblight.c to dprintf() (#6363) --- quantum/rgblight.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 75e4ef0d86..f569d6b9e3 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -167,7 +167,6 @@ void eeconfig_update_rgblight(uint32_t val) { } void eeconfig_update_rgblight_default(void) { - //dprintf("eeconfig_update_rgblight_default\n"); rgblight_config.enable = 1; rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT; rgblight_config.hue = 0; @@ -179,7 +178,7 @@ void eeconfig_update_rgblight_default(void) { } void eeconfig_debug_rgblight(void) { - dprintf("rgblight_config eprom\n"); + dprintf("rgblight_config EEPROM:\n"); dprintf("rgblight_config.enable = %d\n", rgblight_config.enable); dprintf("rghlight_config.mode = %d\n", rgblight_config.mode); dprintf("rgblight_config.hue = %d\n", rgblight_config.hue); @@ -308,9 +307,9 @@ void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { RGBLIGHT_SPLIT_SET_CHANGE_MODE; if (write_to_eeprom) { eeconfig_update_rgblight(rgblight_config.raw); - xprintf("rgblight mode [EEPROM]: %u\n", rgblight_config.mode); + dprintf("rgblight mode [EEPROM]: %u\n", rgblight_config.mode); } else { - xprintf("rgblight mode [NOEEPROM]: %u\n", rgblight_config.mode); + dprintf("rgblight mode [NOEEPROM]: %u\n", rgblight_config.mode); } if( is_static_effect(rgblight_config.mode) ) { #ifdef RGBLIGHT_USE_TIMER @@ -337,7 +336,7 @@ void rgblight_mode_noeeprom(uint8_t mode) { void rgblight_toggle(void) { - xprintf("rgblight toggle [EEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable); + dprintf("rgblight toggle [EEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable); if (rgblight_config.enable) { rgblight_disable(); } @@ -347,7 +346,7 @@ void rgblight_toggle(void) { } void rgblight_toggle_noeeprom(void) { - xprintf("rgblight toggle [NOEEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable); + dprintf("rgblight toggle [NOEEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable); if (rgblight_config.enable) { rgblight_disable_noeeprom(); } @@ -360,20 +359,20 @@ void rgblight_enable(void) { rgblight_config.enable = 1; // No need to update EEPROM here. rgblight_mode() will do that, actually //eeconfig_update_rgblight(rgblight_config.raw); - xprintf("rgblight enable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); + dprintf("rgblight enable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); rgblight_mode(rgblight_config.mode); } void rgblight_enable_noeeprom(void) { rgblight_config.enable = 1; - xprintf("rgblight enable [NOEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); + dprintf("rgblight enable [NOEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); rgblight_mode_noeeprom(rgblight_config.mode); } void rgblight_disable(void) { rgblight_config.enable = 0; eeconfig_update_rgblight(rgblight_config.raw); - xprintf("rgblight disable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); + dprintf("rgblight disable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); #ifdef RGBLIGHT_USE_TIMER rgblight_timer_disable(); #endif @@ -384,7 +383,7 @@ void rgblight_disable(void) { void rgblight_disable_noeeprom(void) { rgblight_config.enable = 0; - xprintf("rgblight disable [noEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); + dprintf("rgblight disable [NOEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); #ifdef RGBLIGHT_USE_TIMER rgblight_timer_disable(); #endif @@ -471,7 +470,6 @@ void rgblight_sethsv_noeeprom_old(uint8_t hue, uint8_t sat, uint8_t val) { if (rgblight_config.enable) { LED_TYPE tmp_led; sethsv(hue, sat, val, &tmp_led); - // dprintf("rgblight set hue [MEMORY]: %u,%u,%u\n", inmem_config.hue, inmem_config.sat, inmem_config.val); rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b); } } @@ -543,9 +541,9 @@ void rgblight_sethsv_eeprom_helper(uint8_t hue, uint8_t sat, uint8_t val, bool w rgblight_config.val = val; if (write_to_eeprom) { eeconfig_update_rgblight(rgblight_config.raw); - xprintf("rgblight set hsv [EEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val); + dprintf("rgblight set hsv [EEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val); } else { - xprintf("rgblight set hsv [NOEEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val); + dprintf("rgblight set hsv [NOEEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val); } } } @@ -866,7 +864,6 @@ void rgblight_task(void) { uint16_t oldpos16; if (tick_flag) { tick_flag = false; - //dprintf("rgblight animation tick\n"); if (timer_elapsed(report_last_timer) >= 30000) { report_last_timer = timer_read(); dprintf("rgblight animation tick report to slave\n"); @@ -874,15 +871,11 @@ void rgblight_task(void) { } } oldpos16 = animation_status.pos16; - //dprintf("call effect function\n"); #endif animation_status.last_timer += interval_time; effect_func(&animation_status); #if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) - //dprintf("pos16, oldpos16 = %d %d\n", - // animation_status.pos16,oldpos16); if (animation_status.pos16 == 0 && oldpos16 != 0) { - //dprintf("flag on\n"); tick_flag = true; } #endif -- cgit v1.2.3 From b624f32f944acdc59dcb130674c09090c5c404cb Mon Sep 17 00:00:00 2001 From: skullY Date: Fri, 30 Aug 2019 11:19:03 -0700 Subject: clang-format changes --- quantum/rgblight.c | 1444 +++++++++++++++++++++++++--------------------------- 1 file changed, 688 insertions(+), 756 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index f569d6b9e3..a094863fe9 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -16,13 +16,13 @@ #include #include #ifdef __AVR__ - #include - #include +# include +# include #endif #ifdef STM32_EEPROM_ENABLE - #include "hal.h" - #include "eeprom.h" - #include "eeprom_stm32.h" +# include "hal.h" +# include "eeprom.h" +# include "eeprom_stm32.h" #endif #include "wait.h" #include "progmem.h" @@ -33,61 +33,58 @@ #include "led_tables.h" #include "lib/lib8tion/lib8tion.h" #ifdef VELOCIKEY_ENABLE - #include "velocikey.h" +# include "velocikey.h" #endif #ifdef RGBLIGHT_SPLIT - /* for split keyboard */ - #define RGBLIGHT_SPLIT_SET_CHANGE_MODE rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_MODE - #define RGBLIGHT_SPLIT_SET_CHANGE_HSVS rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_HSVS - #define RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS rgblight_status.change_flags |= (RGBLIGHT_STATUS_CHANGE_MODE|RGBLIGHT_STATUS_CHANGE_HSVS) - #define RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_TIMER - #define RGBLIGHT_SPLIT_ANIMATION_TICK rgblight_status.change_flags |= RGBLIGHT_STATUS_ANIMATION_TICK +/* for split keyboard */ +# define RGBLIGHT_SPLIT_SET_CHANGE_MODE rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_MODE +# define RGBLIGHT_SPLIT_SET_CHANGE_HSVS rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_HSVS +# define RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS rgblight_status.change_flags |= (RGBLIGHT_STATUS_CHANGE_MODE | RGBLIGHT_STATUS_CHANGE_HSVS) +# define RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_TIMER +# define RGBLIGHT_SPLIT_ANIMATION_TICK rgblight_status.change_flags |= RGBLIGHT_STATUS_ANIMATION_TICK #else - #define RGBLIGHT_SPLIT_SET_CHANGE_MODE - #define RGBLIGHT_SPLIT_SET_CHANGE_HSVS - #define RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS - #define RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE - #define RGBLIGHT_SPLIT_ANIMATION_TICK +# define RGBLIGHT_SPLIT_SET_CHANGE_MODE +# define RGBLIGHT_SPLIT_SET_CHANGE_HSVS +# define RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS +# define RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE +# define RGBLIGHT_SPLIT_ANIMATION_TICK #endif -#define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_ ## sym, +#define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_##sym, #define _RGBM_SINGLE_DYNAMIC(sym) -#define _RGBM_MULTI_STATIC(sym) RGBLIGHT_MODE_ ## sym, +#define _RGBM_MULTI_STATIC(sym) RGBLIGHT_MODE_##sym, #define _RGBM_MULTI_DYNAMIC(sym) -#define _RGBM_TMP_STATIC(sym, msym) RGBLIGHT_MODE_ ## sym, +#define _RGBM_TMP_STATIC(sym, msym) RGBLIGHT_MODE_##sym, #define _RGBM_TMP_DYNAMIC(sym, msym) -static uint8_t static_effect_table [] = { +static uint8_t static_effect_table[] = { #include "rgblight_modes.h" }; -#define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_ ## sym, -#define _RGBM_SINGLE_DYNAMIC(sym) RGBLIGHT_MODE_ ## sym, -#define _RGBM_MULTI_STATIC(sym) RGBLIGHT_MODE_ ## sym, -#define _RGBM_MULTI_DYNAMIC(sym) RGBLIGHT_MODE_ ## sym, -#define _RGBM_TMP_STATIC(sym, msym) RGBLIGHT_MODE_ ## msym, -#define _RGBM_TMP_DYNAMIC(sym, msym) RGBLIGHT_MODE_ ## msym, -static uint8_t mode_base_table [] = { - 0, // RGBLIGHT_MODE_zero +#define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_##sym, +#define _RGBM_SINGLE_DYNAMIC(sym) RGBLIGHT_MODE_##sym, +#define _RGBM_MULTI_STATIC(sym) RGBLIGHT_MODE_##sym, +#define _RGBM_MULTI_DYNAMIC(sym) RGBLIGHT_MODE_##sym, +#define _RGBM_TMP_STATIC(sym, msym) RGBLIGHT_MODE_##msym, +#define _RGBM_TMP_DYNAMIC(sym, msym) RGBLIGHT_MODE_##msym, +static uint8_t mode_base_table[] = { + 0, // RGBLIGHT_MODE_zero #include "rgblight_modes.h" }; -static inline int is_static_effect(uint8_t mode) { - return memchr(static_effect_table, mode, sizeof(static_effect_table)) != NULL; -} +static inline int is_static_effect(uint8_t mode) { return memchr(static_effect_table, mode, sizeof(static_effect_table)) != NULL; } #ifdef RGBLIGHT_LED_MAP const uint8_t led_map[] PROGMEM = RGBLIGHT_LED_MAP; #endif #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT -__attribute__ ((weak)) -const uint8_t RGBLED_GRADIENT_RANGES[] PROGMEM = {255, 170, 127, 85, 64}; +__attribute__((weak)) const uint8_t RGBLED_GRADIENT_RANGES[] PROGMEM = {255, 170, 127, 85, 64}; #endif rgblight_config_t rgblight_config; -rgblight_status_t rgblight_status = { .timer_enabled = false }; -bool is_rgblight_initialized = false; +rgblight_status_t rgblight_status = {.timer_enabled = false}; +bool is_rgblight_initialized = false; #ifdef RGBLIGHT_USE_TIMER animation_status_t animation_status = {}; @@ -95,596 +92,533 @@ animation_status_t animation_status = {}; #ifndef LED_ARRAY LED_TYPE led[RGBLED_NUM]; - #define LED_ARRAY led +# define LED_ARRAY led #endif - static uint8_t clipping_start_pos = 0; -static uint8_t clipping_num_leds = RGBLED_NUM; -static uint8_t effect_start_pos = 0; -static uint8_t effect_end_pos = RGBLED_NUM; -static uint8_t effect_num_leds = RGBLED_NUM; +static uint8_t clipping_num_leds = RGBLED_NUM; +static uint8_t effect_start_pos = 0; +static uint8_t effect_end_pos = RGBLED_NUM; +static uint8_t effect_num_leds = RGBLED_NUM; void rgblight_set_clipping_range(uint8_t start_pos, uint8_t num_leds) { - clipping_start_pos = start_pos; - clipping_num_leds = num_leds; + clipping_start_pos = start_pos; + clipping_num_leds = num_leds; } void rgblight_set_effect_range(uint8_t start_pos, uint8_t num_leds) { - if (start_pos >= RGBLED_NUM) return; - if (start_pos + num_leds > RGBLED_NUM) return; - effect_start_pos = start_pos; - effect_end_pos = start_pos + num_leds; - effect_num_leds = num_leds; + if (start_pos >= RGBLED_NUM) return; + if (start_pos + num_leds > RGBLED_NUM) return; + effect_start_pos = start_pos; + effect_end_pos = start_pos + num_leds; + effect_num_leds = num_leds; } void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { - HSV hsv = { hue, sat, val }; - RGB rgb = hsv_to_rgb(hsv); - setrgb(rgb.r, rgb.g, rgb.b, led1); + HSV hsv = {hue, sat, val}; + RGB rgb = hsv_to_rgb(hsv); + setrgb(rgb.r, rgb.g, rgb.b, led1); } -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); -} +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); } void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1) { - (*led1).r = r; - (*led1).g = g; - (*led1).b = b; + (*led1).r = r; + (*led1).g = g; + (*led1).b = b; } void rgblight_check_config(void) { - /* Add some out of bound checks for RGB light config */ - - if (rgblight_config.mode < RGBLIGHT_MODE_STATIC_LIGHT) { - rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT; - } - else if (rgblight_config.mode > RGBLIGHT_MODES) { - rgblight_config.mode = RGBLIGHT_MODES; - } - - if (rgblight_config.val > RGBLIGHT_LIMIT_VAL) { - rgblight_config.val = RGBLIGHT_LIMIT_VAL; - } + /* Add some out of bound checks for RGB light config */ + + if (rgblight_config.mode < RGBLIGHT_MODE_STATIC_LIGHT) { + rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT; + } else if (rgblight_config.mode > RGBLIGHT_MODES) { + rgblight_config.mode = RGBLIGHT_MODES; + } + + if (rgblight_config.val > RGBLIGHT_LIMIT_VAL) { + rgblight_config.val = RGBLIGHT_LIMIT_VAL; + } } uint32_t eeconfig_read_rgblight(void) { - #if defined(__AVR__) || defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE) +#if defined(__AVR__) || defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE) return eeprom_read_dword(EECONFIG_RGBLIGHT); - #else +#else return 0; - #endif +#endif } void eeconfig_update_rgblight(uint32_t val) { - #if defined(__AVR__) || defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE) +#if defined(__AVR__) || defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE) rgblight_check_config(); eeprom_update_dword(EECONFIG_RGBLIGHT, val); - #endif +#endif } void eeconfig_update_rgblight_default(void) { - rgblight_config.enable = 1; - rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT; - rgblight_config.hue = 0; - rgblight_config.sat = UINT8_MAX; - rgblight_config.val = RGBLIGHT_LIMIT_VAL; - rgblight_config.speed = 0; - RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; - eeconfig_update_rgblight(rgblight_config.raw); + rgblight_config.enable = 1; + rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT; + rgblight_config.hue = 0; + rgblight_config.sat = UINT8_MAX; + rgblight_config.val = RGBLIGHT_LIMIT_VAL; + rgblight_config.speed = 0; + RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; + eeconfig_update_rgblight(rgblight_config.raw); } void eeconfig_debug_rgblight(void) { - dprintf("rgblight_config EEPROM:\n"); - dprintf("rgblight_config.enable = %d\n", rgblight_config.enable); - dprintf("rghlight_config.mode = %d\n", rgblight_config.mode); - dprintf("rgblight_config.hue = %d\n", rgblight_config.hue); - dprintf("rgblight_config.sat = %d\n", rgblight_config.sat); - dprintf("rgblight_config.val = %d\n", rgblight_config.val); - dprintf("rgblight_config.speed = %d\n", rgblight_config.speed); + dprintf("rgblight_config EEPROM:\n"); + dprintf("rgblight_config.enable = %d\n", rgblight_config.enable); + dprintf("rghlight_config.mode = %d\n", rgblight_config.mode); + dprintf("rgblight_config.hue = %d\n", rgblight_config.hue); + dprintf("rgblight_config.sat = %d\n", rgblight_config.sat); + dprintf("rgblight_config.val = %d\n", rgblight_config.val); + dprintf("rgblight_config.speed = %d\n", rgblight_config.speed); } void rgblight_init(void) { - /* if already initialized, don't do it again. - If you must do it again, extern this and set to false, first. - This is a dirty, dirty hack until proper hooks can be added for keyboard startup. */ - if (is_rgblight_initialized) { return; } - - debug_enable = 1; // Debug ON! - dprintf("rgblight_init called.\n"); - dprintf("rgblight_init start!\n"); - if (!eeconfig_is_enabled()) { - dprintf("rgblight_init eeconfig is not enabled.\n"); - eeconfig_init(); - eeconfig_update_rgblight_default(); - } - rgblight_config.raw = eeconfig_read_rgblight(); - RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; - if (!rgblight_config.mode) { - dprintf("rgblight_init rgblight_config.mode = 0. Write default values to EEPROM.\n"); - eeconfig_update_rgblight_default(); + /* if already initialized, don't do it again. + If you must do it again, extern this and set to false, first. + This is a dirty, dirty hack until proper hooks can be added for keyboard startup. */ + if (is_rgblight_initialized) { + return; + } + + debug_enable = 1; // Debug ON! + dprintf("rgblight_init called.\n"); + dprintf("rgblight_init start!\n"); + if (!eeconfig_is_enabled()) { + dprintf("rgblight_init eeconfig is not enabled.\n"); + eeconfig_init(); + eeconfig_update_rgblight_default(); + } rgblight_config.raw = eeconfig_read_rgblight(); - } - rgblight_check_config(); + RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; + if (!rgblight_config.mode) { + dprintf("rgblight_init rgblight_config.mode = 0. Write default values to EEPROM.\n"); + eeconfig_update_rgblight_default(); + rgblight_config.raw = eeconfig_read_rgblight(); + } + rgblight_check_config(); - eeconfig_debug_rgblight(); // display current eeprom values + eeconfig_debug_rgblight(); // display current eeprom values #ifdef RGBLIGHT_USE_TIMER - rgblight_timer_init(); // setup the timer + rgblight_timer_init(); // setup the timer #endif - if (rgblight_config.enable) { - rgblight_mode_noeeprom(rgblight_config.mode); - } - - is_rgblight_initialized = true; + if (rgblight_config.enable) { + rgblight_mode_noeeprom(rgblight_config.mode); + } + is_rgblight_initialized = true; } -uint32_t rgblight_read_dword(void) { - return rgblight_config.raw; -} +uint32_t rgblight_read_dword(void) { return rgblight_config.raw; } void rgblight_update_dword(uint32_t dword) { - RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; - rgblight_config.raw = dword; - if (rgblight_config.enable) - rgblight_mode_noeeprom(rgblight_config.mode); - else { + RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; + rgblight_config.raw = dword; + if (rgblight_config.enable) + rgblight_mode_noeeprom(rgblight_config.mode); + else { #ifdef RGBLIGHT_USE_TIMER - rgblight_timer_disable(); + rgblight_timer_disable(); #endif - rgblight_set(); - } + rgblight_set(); + } } void rgblight_increase(void) { - uint8_t mode = 0; - if (rgblight_config.mode < RGBLIGHT_MODES) { - mode = rgblight_config.mode + 1; - } - rgblight_mode(mode); + uint8_t mode = 0; + if (rgblight_config.mode < RGBLIGHT_MODES) { + mode = rgblight_config.mode + 1; + } + rgblight_mode(mode); } void rgblight_decrease(void) { - uint8_t mode = 0; - // Mode will never be < 1. If it ever is, eeprom needs to be initialized. - if (rgblight_config.mode > RGBLIGHT_MODE_STATIC_LIGHT) { - mode = rgblight_config.mode - 1; - } - rgblight_mode(mode); + uint8_t mode = 0; + // Mode will never be < 1. If it ever is, eeprom needs to be initialized. + if (rgblight_config.mode > RGBLIGHT_MODE_STATIC_LIGHT) { + mode = rgblight_config.mode - 1; + } + rgblight_mode(mode); } void rgblight_step_helper(bool write_to_eeprom) { - uint8_t mode = 0; - mode = rgblight_config.mode + 1; - if (mode > RGBLIGHT_MODES) { - mode = 1; - } - rgblight_mode_eeprom_helper(mode, write_to_eeprom); -} -void rgblight_step_noeeprom(void) { - rgblight_step_helper(false); -} -void rgblight_step(void) { - rgblight_step_helper(true); + uint8_t mode = 0; + mode = rgblight_config.mode + 1; + if (mode > RGBLIGHT_MODES) { + mode = 1; + } + rgblight_mode_eeprom_helper(mode, write_to_eeprom); } +void rgblight_step_noeeprom(void) { rgblight_step_helper(false); } +void rgblight_step(void) { rgblight_step_helper(true); } void rgblight_step_reverse_helper(bool write_to_eeprom) { - uint8_t mode = 0; - mode = rgblight_config.mode - 1; - if (mode < 1) { - mode = RGBLIGHT_MODES; - } - rgblight_mode_eeprom_helper(mode, write_to_eeprom); -} -void rgblight_step_reverse_noeeprom(void) { - rgblight_step_reverse_helper(false); -} -void rgblight_step_reverse(void) { - rgblight_step_reverse_helper(true); + uint8_t mode = 0; + mode = rgblight_config.mode - 1; + if (mode < 1) { + mode = RGBLIGHT_MODES; + } + rgblight_mode_eeprom_helper(mode, write_to_eeprom); } +void rgblight_step_reverse_noeeprom(void) { rgblight_step_reverse_helper(false); } +void rgblight_step_reverse(void) { rgblight_step_reverse_helper(true); } uint8_t rgblight_get_mode(void) { - if (!rgblight_config.enable) { - return false; - } + if (!rgblight_config.enable) { + return false; + } - return rgblight_config.mode; + return rgblight_config.mode; } void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { - if (!rgblight_config.enable) { - return; - } - if (mode < RGBLIGHT_MODE_STATIC_LIGHT) { - rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT; - } else if (mode > RGBLIGHT_MODES) { - rgblight_config.mode = RGBLIGHT_MODES; - } else { - rgblight_config.mode = mode; - } - RGBLIGHT_SPLIT_SET_CHANGE_MODE; - if (write_to_eeprom) { - eeconfig_update_rgblight(rgblight_config.raw); - dprintf("rgblight mode [EEPROM]: %u\n", rgblight_config.mode); - } else { - dprintf("rgblight mode [NOEEPROM]: %u\n", rgblight_config.mode); - } - if( is_static_effect(rgblight_config.mode) ) { + if (!rgblight_config.enable) { + return; + } + if (mode < RGBLIGHT_MODE_STATIC_LIGHT) { + rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT; + } else if (mode > RGBLIGHT_MODES) { + rgblight_config.mode = RGBLIGHT_MODES; + } else { + rgblight_config.mode = mode; + } + RGBLIGHT_SPLIT_SET_CHANGE_MODE; + if (write_to_eeprom) { + eeconfig_update_rgblight(rgblight_config.raw); + dprintf("rgblight mode [EEPROM]: %u\n", rgblight_config.mode); + } else { + dprintf("rgblight mode [NOEEPROM]: %u\n", rgblight_config.mode); + } + if (is_static_effect(rgblight_config.mode)) { #ifdef RGBLIGHT_USE_TIMER - rgblight_timer_disable(); + rgblight_timer_disable(); #endif - } else { + } else { #ifdef RGBLIGHT_USE_TIMER - rgblight_timer_enable(); + rgblight_timer_enable(); #endif - } + } #ifdef RGBLIGHT_USE_TIMER animation_status.restart = true; #endif - rgblight_sethsv_noeeprom(rgblight_config.hue, rgblight_config.sat, rgblight_config.val); + rgblight_sethsv_noeeprom(rgblight_config.hue, rgblight_config.sat, rgblight_config.val); } -void rgblight_mode(uint8_t mode) { - rgblight_mode_eeprom_helper(mode, true); -} - -void rgblight_mode_noeeprom(uint8_t mode) { - rgblight_mode_eeprom_helper(mode, false); -} +void rgblight_mode(uint8_t mode) { rgblight_mode_eeprom_helper(mode, true); } +void rgblight_mode_noeeprom(uint8_t mode) { rgblight_mode_eeprom_helper(mode, false); } void rgblight_toggle(void) { - dprintf("rgblight toggle [EEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable); - if (rgblight_config.enable) { - rgblight_disable(); - } - else { - rgblight_enable(); - } + dprintf("rgblight toggle [EEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable); + if (rgblight_config.enable) { + rgblight_disable(); + } else { + rgblight_enable(); + } } void rgblight_toggle_noeeprom(void) { - dprintf("rgblight toggle [NOEEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable); - if (rgblight_config.enable) { - rgblight_disable_noeeprom(); - } - else { - rgblight_enable_noeeprom(); - } + dprintf("rgblight toggle [NOEEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable); + if (rgblight_config.enable) { + rgblight_disable_noeeprom(); + } else { + rgblight_enable_noeeprom(); + } } void rgblight_enable(void) { - rgblight_config.enable = 1; - // No need to update EEPROM here. rgblight_mode() will do that, actually - //eeconfig_update_rgblight(rgblight_config.raw); - dprintf("rgblight enable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); - rgblight_mode(rgblight_config.mode); + rgblight_config.enable = 1; + // No need to update EEPROM here. rgblight_mode() will do that, actually + // eeconfig_update_rgblight(rgblight_config.raw); + dprintf("rgblight enable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); + rgblight_mode(rgblight_config.mode); } void rgblight_enable_noeeprom(void) { - rgblight_config.enable = 1; - dprintf("rgblight enable [NOEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); - rgblight_mode_noeeprom(rgblight_config.mode); + rgblight_config.enable = 1; + dprintf("rgblight enable [NOEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); + rgblight_mode_noeeprom(rgblight_config.mode); } void rgblight_disable(void) { - rgblight_config.enable = 0; - eeconfig_update_rgblight(rgblight_config.raw); - dprintf("rgblight disable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); + rgblight_config.enable = 0; + eeconfig_update_rgblight(rgblight_config.raw); + dprintf("rgblight disable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); #ifdef RGBLIGHT_USE_TIMER - rgblight_timer_disable(); + rgblight_timer_disable(); #endif - RGBLIGHT_SPLIT_SET_CHANGE_MODE; - wait_ms(50); - rgblight_set(); + RGBLIGHT_SPLIT_SET_CHANGE_MODE; + wait_ms(50); + rgblight_set(); } void rgblight_disable_noeeprom(void) { - rgblight_config.enable = 0; - dprintf("rgblight disable [NOEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); + rgblight_config.enable = 0; + dprintf("rgblight disable [NOEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); #ifdef RGBLIGHT_USE_TIMER rgblight_timer_disable(); #endif - RGBLIGHT_SPLIT_SET_CHANGE_MODE; - wait_ms(50); - rgblight_set(); + RGBLIGHT_SPLIT_SET_CHANGE_MODE; + wait_ms(50); + rgblight_set(); } void rgblight_increase_hue_helper(bool write_to_eeprom) { - uint8_t hue = rgblight_config.hue + RGBLIGHT_HUE_STEP; - rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom); -} -void rgblight_increase_hue_noeeprom(void) { - rgblight_increase_hue_helper(false); -} -void rgblight_increase_hue(void) { - rgblight_increase_hue_helper(true); + uint8_t hue = rgblight_config.hue + RGBLIGHT_HUE_STEP; + rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom); } +void rgblight_increase_hue_noeeprom(void) { rgblight_increase_hue_helper(false); } +void rgblight_increase_hue(void) { rgblight_increase_hue_helper(true); } void rgblight_decrease_hue_helper(bool write_to_eeprom) { - uint8_t hue = rgblight_config.hue - RGBLIGHT_HUE_STEP; - rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom); -} -void rgblight_decrease_hue_noeeprom(void) { - rgblight_decrease_hue_helper(false); -} -void rgblight_decrease_hue(void) { - rgblight_decrease_hue_helper(true); + uint8_t hue = rgblight_config.hue - RGBLIGHT_HUE_STEP; + rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom); } +void rgblight_decrease_hue_noeeprom(void) { rgblight_decrease_hue_helper(false); } +void rgblight_decrease_hue(void) { rgblight_decrease_hue_helper(true); } void rgblight_increase_sat_helper(bool write_to_eeprom) { - uint8_t sat = qadd8(rgblight_config.sat, RGBLIGHT_SAT_STEP); - rgblight_sethsv_eeprom_helper(rgblight_config.hue, sat, rgblight_config.val, write_to_eeprom); -} -void rgblight_increase_sat_noeeprom(void) { - rgblight_increase_sat_helper(false); -} -void rgblight_increase_sat(void) { - rgblight_increase_sat_helper(true); + uint8_t sat = qadd8(rgblight_config.sat, RGBLIGHT_SAT_STEP); + rgblight_sethsv_eeprom_helper(rgblight_config.hue, sat, rgblight_config.val, write_to_eeprom); } +void rgblight_increase_sat_noeeprom(void) { rgblight_increase_sat_helper(false); } +void rgblight_increase_sat(void) { rgblight_increase_sat_helper(true); } void rgblight_decrease_sat_helper(bool write_to_eeprom) { - uint8_t sat = qsub8(rgblight_config.sat, RGBLIGHT_SAT_STEP); - rgblight_sethsv_eeprom_helper(rgblight_config.hue, sat, rgblight_config.val, write_to_eeprom); -} -void rgblight_decrease_sat_noeeprom(void) { - rgblight_decrease_sat_helper(false); -} -void rgblight_decrease_sat(void) { - rgblight_decrease_sat_helper(true); + uint8_t sat = qsub8(rgblight_config.sat, RGBLIGHT_SAT_STEP); + rgblight_sethsv_eeprom_helper(rgblight_config.hue, sat, rgblight_config.val, write_to_eeprom); } +void rgblight_decrease_sat_noeeprom(void) { rgblight_decrease_sat_helper(false); } +void rgblight_decrease_sat(void) { rgblight_decrease_sat_helper(true); } void rgblight_increase_val_helper(bool write_to_eeprom) { - uint8_t val = qadd8(rgblight_config.val, RGBLIGHT_VAL_STEP); - rgblight_sethsv_eeprom_helper(rgblight_config.hue, rgblight_config.sat, val, write_to_eeprom); -} -void rgblight_increase_val_noeeprom(void) { - rgblight_increase_val_helper(false); -} -void rgblight_increase_val(void) { - rgblight_increase_val_helper(true); + uint8_t val = qadd8(rgblight_config.val, RGBLIGHT_VAL_STEP); + rgblight_sethsv_eeprom_helper(rgblight_config.hue, rgblight_config.sat, val, write_to_eeprom); } +void rgblight_increase_val_noeeprom(void) { rgblight_increase_val_helper(false); } +void rgblight_increase_val(void) { rgblight_increase_val_helper(true); } void rgblight_decrease_val_helper(bool write_to_eeprom) { - uint8_t val = qsub8(rgblight_config.val, RGBLIGHT_VAL_STEP); - rgblight_sethsv_eeprom_helper(rgblight_config.hue, rgblight_config.sat, val, write_to_eeprom); -} -void rgblight_decrease_val_noeeprom(void) { - rgblight_decrease_val_helper(false); -} -void rgblight_decrease_val(void) { - rgblight_decrease_val_helper(true); + uint8_t val = qsub8(rgblight_config.val, RGBLIGHT_VAL_STEP); + rgblight_sethsv_eeprom_helper(rgblight_config.hue, rgblight_config.sat, val, write_to_eeprom); } +void rgblight_decrease_val_noeeprom(void) { rgblight_decrease_val_helper(false); } +void rgblight_decrease_val(void) { rgblight_decrease_val_helper(true); } void rgblight_increase_speed(void) { - if (rgblight_config.speed < 3) - rgblight_config.speed++; - //RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED? - eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this + if (rgblight_config.speed < 3) rgblight_config.speed++; + // RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED? + eeconfig_update_rgblight(rgblight_config.raw); // EECONFIG needs to be increased to support this } void rgblight_decrease_speed(void) { - if (rgblight_config.speed > 0) - rgblight_config.speed--; - //RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED?? - eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this + if (rgblight_config.speed > 0) rgblight_config.speed--; + // RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED?? + eeconfig_update_rgblight(rgblight_config.raw); // EECONFIG needs to be increased to support this } void rgblight_sethsv_noeeprom_old(uint8_t hue, uint8_t sat, uint8_t val) { - if (rgblight_config.enable) { - LED_TYPE tmp_led; - sethsv(hue, sat, val, &tmp_led); - rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b); - } + if (rgblight_config.enable) { + LED_TYPE tmp_led; + sethsv(hue, sat, val, &tmp_led); + rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b); + } } void rgblight_sethsv_eeprom_helper(uint8_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom) { - if (rgblight_config.enable) { - rgblight_status.base_mode = mode_base_table[rgblight_config.mode]; - if (rgblight_config.mode == RGBLIGHT_MODE_STATIC_LIGHT) { - // same static color - LED_TYPE tmp_led; - sethsv(hue, sat, val, &tmp_led); - rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b); - } else { - // all LEDs in same color - if ( 1 == 0 ) { //dummy - } + if (rgblight_config.enable) { + rgblight_status.base_mode = mode_base_table[rgblight_config.mode]; + if (rgblight_config.mode == RGBLIGHT_MODE_STATIC_LIGHT) { + // same static color + LED_TYPE tmp_led; + sethsv(hue, sat, val, &tmp_led); + rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b); + } else { + // all LEDs in same color + if (1 == 0) { // dummy + } #ifdef RGBLIGHT_EFFECT_BREATHING - else if (rgblight_status.base_mode == RGBLIGHT_MODE_BREATHING ) { - // breathing mode, ignore the change of val, use in memory value instead - val = rgblight_config.val; - } + else if (rgblight_status.base_mode == RGBLIGHT_MODE_BREATHING) { + // breathing mode, ignore the change of val, use in memory value instead + val = rgblight_config.val; + } #endif #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD - else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_MOOD) { - // rainbow mood, ignore the change of hue - hue = rgblight_config.hue; - } + else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_MOOD) { + // rainbow mood, ignore the change of hue + hue = rgblight_config.hue; + } #endif #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL - else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_SWIRL) { - // rainbow swirl, ignore the change of hue - hue = rgblight_config.hue; - } + else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_SWIRL) { + // rainbow swirl, ignore the change of hue + hue = rgblight_config.hue; + } #endif #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT - else if (rgblight_status.base_mode == RGBLIGHT_MODE_STATIC_GRADIENT) { - // static gradient - uint8_t delta = rgblight_config.mode - rgblight_status.base_mode; - bool direction = (delta % 2) == 0; -#ifdef __AVR__ - // probably due to how pgm_read_word is defined for ARM, but the ARM compiler really hates this line - uint8_t range = pgm_read_word(&RGBLED_GRADIENT_RANGES[delta / 2]); -#else - uint8_t range = RGBLED_GRADIENT_RANGES[delta / 2]; + else if (rgblight_status.base_mode == RGBLIGHT_MODE_STATIC_GRADIENT) { + // static gradient + uint8_t delta = rgblight_config.mode - rgblight_status.base_mode; + bool direction = (delta % 2) == 0; +# ifdef __AVR__ + // probably due to how pgm_read_word is defined for ARM, but the ARM compiler really hates this line + uint8_t range = pgm_read_word(&RGBLED_GRADIENT_RANGES[delta / 2]); +# else + uint8_t range = RGBLED_GRADIENT_RANGES[delta / 2]; +# endif + for (uint8_t i = 0; i < effect_num_leds; i++) { + uint8_t _hue = ((uint16_t)i * (uint16_t)range) / effect_num_leds; + if (direction) { + _hue = hue + _hue; + } else { + _hue = hue - _hue; + } + dprintf("rgblight rainbow set hsv: %d,%d,%d,%u\n", i, _hue, direction, range); + sethsv(_hue, sat, val, (LED_TYPE *)&led[i + effect_start_pos]); + } + rgblight_set(); + } #endif - for (uint8_t i = 0; i < effect_num_leds; i++) { - uint8_t _hue = ((uint16_t)i * (uint16_t)range) / effect_num_leds; - if (direction) { - _hue = hue + _hue; - } else { - _hue = hue - _hue; - } - dprintf("rgblight rainbow set hsv: %d,%d,%d,%u\n", i, _hue, direction, range); - sethsv(_hue, sat, val, (LED_TYPE *)&led[i + effect_start_pos]); } - rgblight_set(); - } -#endif - } #ifdef RGBLIGHT_SPLIT - if( rgblight_config.hue != hue || - rgblight_config.sat != sat || - rgblight_config.val != val ) { - RGBLIGHT_SPLIT_SET_CHANGE_HSVS; - } + if (rgblight_config.hue != hue || rgblight_config.sat != sat || rgblight_config.val != val) { + RGBLIGHT_SPLIT_SET_CHANGE_HSVS; + } #endif - rgblight_config.hue = hue; - rgblight_config.sat = sat; - rgblight_config.val = val; - if (write_to_eeprom) { - eeconfig_update_rgblight(rgblight_config.raw); - dprintf("rgblight set hsv [EEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val); - } else { - dprintf("rgblight set hsv [NOEEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val); + rgblight_config.hue = hue; + rgblight_config.sat = sat; + rgblight_config.val = val; + if (write_to_eeprom) { + eeconfig_update_rgblight(rgblight_config.raw); + dprintf("rgblight set hsv [EEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val); + } else { + dprintf("rgblight set hsv [NOEEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val); + } } - } } -void rgblight_sethsv(uint8_t hue, uint8_t sat, uint8_t val) { - rgblight_sethsv_eeprom_helper(hue, sat, val, true); -} +void rgblight_sethsv(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_sethsv_eeprom_helper(hue, sat, val, true); } -void rgblight_sethsv_noeeprom(uint8_t hue, uint8_t sat, uint8_t val) { - rgblight_sethsv_eeprom_helper(hue, sat, val, false); -} +void rgblight_sethsv_noeeprom(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_sethsv_eeprom_helper(hue, sat, val, false); } -uint8_t rgblight_get_hue(void) { - return rgblight_config.hue; -} +uint8_t rgblight_get_hue(void) { return rgblight_config.hue; } -uint8_t rgblight_get_sat(void) { - return rgblight_config.sat; -} +uint8_t rgblight_get_sat(void) { return rgblight_config.sat; } -uint8_t rgblight_get_val(void) { - return rgblight_config.val; -} +uint8_t rgblight_get_val(void) { return rgblight_config.val; } void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b) { - if (!rgblight_config.enable) { return; } - - for (uint8_t i = effect_start_pos; i < effect_end_pos; i++) { - led[i].r = r; - led[i].g = g; - led[i].b = b; - } - rgblight_set(); + if (!rgblight_config.enable) { + return; + } + + for (uint8_t i = effect_start_pos; i < effect_end_pos; i++) { + led[i].r = r; + led[i].g = g; + led[i].b = b; + } + rgblight_set(); } void rgblight_setrgb_at(uint8_t r, uint8_t g, uint8_t b, uint8_t index) { - if (!rgblight_config.enable || index >= RGBLED_NUM) { return; } + if (!rgblight_config.enable || index >= RGBLED_NUM) { + return; + } - led[index].r = r; - led[index].g = g; - led[index].b = b; - rgblight_set(); + led[index].r = r; + led[index].g = g; + led[index].b = b; + rgblight_set(); } void rgblight_sethsv_at(uint8_t hue, uint8_t sat, uint8_t val, uint8_t index) { - if (!rgblight_config.enable) { return; } + if (!rgblight_config.enable) { + return; + } - LED_TYPE tmp_led; - sethsv(hue, sat, val, &tmp_led); - rgblight_setrgb_at(tmp_led.r, tmp_led.g, tmp_led.b, index); + LED_TYPE tmp_led; + sethsv(hue, sat, val, &tmp_led); + rgblight_setrgb_at(tmp_led.r, tmp_led.g, tmp_led.b, index); } -#if defined(RGBLIGHT_EFFECT_BREATHING) || defined(RGBLIGHT_EFFECT_RAINBOW_MOOD) || defined(RGBLIGHT_EFFECT_RAINBOW_SWIRL) \ - || defined(RGBLIGHT_EFFECT_SNAKE) || defined(RGBLIGHT_EFFECT_KNIGHT) +#if defined(RGBLIGHT_EFFECT_BREATHING) || defined(RGBLIGHT_EFFECT_RAINBOW_MOOD) || defined(RGBLIGHT_EFFECT_RAINBOW_SWIRL) || defined(RGBLIGHT_EFFECT_SNAKE) || defined(RGBLIGHT_EFFECT_KNIGHT) -static uint8_t get_interval_time(const uint8_t* default_interval_address, uint8_t velocikey_min, uint8_t velocikey_max) { - return -#ifdef VELOCIKEY_ENABLE - velocikey_enabled() ? velocikey_match_speed(velocikey_min, velocikey_max) : -#endif - pgm_read_byte(default_interval_address); +static uint8_t get_interval_time(const uint8_t *default_interval_address, uint8_t velocikey_min, uint8_t velocikey_max) { + return +# ifdef VELOCIKEY_ENABLE + velocikey_enabled() ? velocikey_match_speed(velocikey_min, velocikey_max) : +# endif + pgm_read_byte(default_interval_address); } #endif void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8_t end) { - if (!rgblight_config.enable || start < 0 || start >= end || end > RGBLED_NUM) { return; } - - for (uint8_t i = start; i < end; i++) { - led[i].r = r; - led[i].g = g; - led[i].b = b; - } - rgblight_set(); - wait_ms(1); + if (!rgblight_config.enable || start < 0 || start >= end || end > RGBLED_NUM) { + return; + } + + for (uint8_t i = start; i < end; i++) { + led[i].r = r; + led[i].g = g; + led[i].b = b; + } + rgblight_set(); + wait_ms(1); } void rgblight_sethsv_range(uint8_t hue, uint8_t sat, uint8_t val, uint8_t start, uint8_t end) { - if (!rgblight_config.enable) { return; } + if (!rgblight_config.enable) { + return; + } - LED_TYPE tmp_led; - sethsv(hue, sat, val, &tmp_led); - rgblight_setrgb_range(tmp_led.r, tmp_led.g, tmp_led.b, start, end); + LED_TYPE tmp_led; + sethsv(hue, sat, val, &tmp_led); + rgblight_setrgb_range(tmp_led.r, tmp_led.g, tmp_led.b, start, end); } #ifndef RGBLIGHT_SPLIT -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); -} +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); } -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); -} +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); } -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); -} +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); } -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); -} -#endif // ifndef RGBLIGHT_SPLIT +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); } +#endif // ifndef RGBLIGHT_SPLIT #ifndef RGBLIGHT_CUSTOM_DRIVER void rgblight_set(void) { - LED_TYPE *start_led; - uint16_t num_leds = clipping_num_leds; - - if (!rgblight_config.enable) { - for (uint8_t i = effect_start_pos; i < effect_end_pos; i++) { - led[i].r = 0; - led[i].g = 0; - led[i].b = 0; + LED_TYPE *start_led; + uint16_t num_leds = clipping_num_leds; + + if (!rgblight_config.enable) { + for (uint8_t i = effect_start_pos; i < effect_end_pos; i++) { + led[i].r = 0; + led[i].g = 0; + led[i].b = 0; + } } - } -#ifdef RGBLIGHT_LED_MAP - LED_TYPE led0[RGBLED_NUM]; - for(uint8_t i = 0; i < RGBLED_NUM; i++) { - led0[i] = led[pgm_read_byte(&led_map[i])]; - } - start_led = led0 + clipping_start_pos; -#else - start_led = led + clipping_start_pos; -#endif -#ifdef RGBW - ws2812_setleds_rgbw(start_led, num_leds); -#else - ws2812_setleds(start_led, num_leds); -#endif +# ifdef RGBLIGHT_LED_MAP + LED_TYPE led0[RGBLED_NUM]; + for (uint8_t i = 0; i < RGBLED_NUM; i++) { + led0[i] = led[pgm_read_byte(&led_map[i])]; + } + start_led = led0 + clipping_start_pos; +# else + start_led = led + clipping_start_pos; +# endif +# ifdef RGBW + ws2812_setleds_rgbw(start_led, num_leds); +# else + ws2812_setleds(start_led, num_leds); +# endif } #endif #ifdef RGBLIGHT_SPLIT /* for split keyboard master side */ -uint8_t rgblight_get_change_flags(void) { - return rgblight_status.change_flags; -} +uint8_t rgblight_get_change_flags(void) { return rgblight_status.change_flags; } -void rgblight_clear_change_flags(void) { - rgblight_status.change_flags = 0; -} +void rgblight_clear_change_flags(void) { rgblight_status.change_flags = 0; } void rgblight_get_syncinfo(rgblight_syncinfo_t *syncinfo) { syncinfo->config = rgblight_config; @@ -695,7 +629,7 @@ void rgblight_get_syncinfo(rgblight_syncinfo_t *syncinfo) { void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom) { if (syncinfo->status.change_flags & RGBLIGHT_STATUS_CHANGE_MODE) { if (syncinfo->config.enable) { - rgblight_config.enable = 1; // == rgblight_enable_noeeprom(); + rgblight_config.enable = 1; // == rgblight_enable_noeeprom(); rgblight_mode_eeprom_helper(syncinfo->config.mode, write_to_eeprom); } else { rgblight_disable_noeeprom(); @@ -705,7 +639,7 @@ void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom) { rgblight_sethsv_eeprom_helper(syncinfo->config.hue, syncinfo->config.sat, syncinfo->config.val, write_to_eeprom); // rgblight_config.speed = config->speed; // NEED??? } - #ifdef RGBLIGHT_USE_TIMER +# ifdef RGBLIGHT_USE_TIMER if (syncinfo->status.change_flags & RGBLIGHT_STATUS_CHANGE_TIMER) { if (syncinfo->status.timer_enabled) { rgblight_timer_enable(); @@ -713,12 +647,12 @@ void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom) { rgblight_timer_disable(); } } - #ifndef RGBLIGHT_SPLIT_NO_ANIMATION_SYNC +# ifndef RGBLIGHT_SPLIT_NO_ANIMATION_SYNC if (syncinfo->status.change_flags & RGBLIGHT_STATUS_ANIMATION_TICK) { animation_status.restart = true; } - #endif /* RGBLIGHT_SPLIT_NO_ANIMATION_SYNC */ - #endif /* RGBLIGHT_USE_TIMER */ +# endif /* RGBLIGHT_SPLIT_NO_ANIMATION_SYNC */ +# endif /* RGBLIGHT_USE_TIMER */ } #endif /* RGBLIGHT_SPLIT */ @@ -728,51 +662,51 @@ typedef void (*effect_func_t)(animation_status_t *anim); // Animation timer -- use system timer (AVR Timer0) void rgblight_timer_init(void) { - // OLD!!!! Animation timer -- AVR Timer3 - // static uint8_t rgblight_timer_is_init = 0; - // if (rgblight_timer_is_init) { - // return; - // } - // rgblight_timer_is_init = 1; - // /* Timer 3 setup */ - // TCCR3B = _BV(WGM32) // CTC mode OCR3A as TOP - // | _BV(CS30); // Clock selelct: clk/1 - // /* Set TOP value */ - // uint8_t sreg = SREG; - // cli(); - // OCR3AH = (RGBLED_TIMER_TOP >> 8) & 0xff; - // OCR3AL = RGBLED_TIMER_TOP & 0xff; - // SREG = sreg; - - rgblight_status.timer_enabled = false; - RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE; + // OLD!!!! Animation timer -- AVR Timer3 + // static uint8_t rgblight_timer_is_init = 0; + // if (rgblight_timer_is_init) { + // return; + // } + // rgblight_timer_is_init = 1; + // /* Timer 3 setup */ + // TCCR3B = _BV(WGM32) // CTC mode OCR3A as TOP + // | _BV(CS30); // Clock selelct: clk/1 + // /* Set TOP value */ + // uint8_t sreg = SREG; + // cli(); + // OCR3AH = (RGBLED_TIMER_TOP >> 8) & 0xff; + // OCR3AL = RGBLED_TIMER_TOP & 0xff; + // SREG = sreg; + + rgblight_status.timer_enabled = false; + RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE; } void rgblight_timer_enable(void) { - if( !is_static_effect(rgblight_config.mode) ) { - rgblight_status.timer_enabled = true; - } - animation_status.last_timer = timer_read(); - RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE; - dprintf("rgblight timer enabled.\n"); + if (!is_static_effect(rgblight_config.mode)) { + rgblight_status.timer_enabled = true; + } + animation_status.last_timer = timer_read(); + RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE; + dprintf("rgblight timer enabled.\n"); } void rgblight_timer_disable(void) { - rgblight_status.timer_enabled = false; - RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE; - dprintf("rgblight timer disable.\n"); + rgblight_status.timer_enabled = false; + RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE; + dprintf("rgblight timer disable.\n"); } void rgblight_timer_toggle(void) { - dprintf("rgblight timer toggle.\n"); - if(rgblight_status.timer_enabled) { - rgblight_timer_disable(); - } else { - rgblight_timer_enable(); - } + dprintf("rgblight timer toggle.\n"); + if (rgblight_status.timer_enabled) { + rgblight_timer_disable(); + } else { + rgblight_timer_enable(); + } } void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b) { - rgblight_enable(); - rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT); - rgblight_setrgb(r, g, b); + rgblight_enable(); + rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT); + rgblight_setrgb(r, g, b); } static void rgblight_effect_dummy(animation_status_t *anim) { @@ -788,99 +722,99 @@ static void rgblight_effect_dummy(animation_status_t *anim) { } void rgblight_task(void) { - if (rgblight_status.timer_enabled) { - effect_func_t effect_func = rgblight_effect_dummy; - uint16_t interval_time = 2000; // dummy interval - uint8_t delta = rgblight_config.mode - rgblight_status.base_mode; - animation_status.delta = delta; - - // static light mode, do nothing here - if ( 1 == 0 ) { //dummy - } -#ifdef RGBLIGHT_EFFECT_BREATHING - else if (rgblight_status.base_mode == RGBLIGHT_MODE_BREATHING) { - // breathing mode - interval_time = get_interval_time(&RGBLED_BREATHING_INTERVALS[delta], 1, 100); - effect_func = rgblight_effect_breathing; - } -#endif -#ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD - else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_MOOD) { - // rainbow mood mode - interval_time = get_interval_time(&RGBLED_RAINBOW_MOOD_INTERVALS[delta], 5, 100); - effect_func = rgblight_effect_rainbow_mood; - } -#endif -#ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL - else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_SWIRL) { - // rainbow swirl mode - interval_time = get_interval_time(&RGBLED_RAINBOW_SWIRL_INTERVALS[delta / 2], 1, 100); - effect_func = rgblight_effect_rainbow_swirl; - } -#endif -#ifdef RGBLIGHT_EFFECT_SNAKE - else if (rgblight_status.base_mode == RGBLIGHT_MODE_SNAKE) { - // snake mode - interval_time = get_interval_time(&RGBLED_SNAKE_INTERVALS[delta / 2], 1, 200); - effect_func = rgblight_effect_snake; - } -#endif -#ifdef RGBLIGHT_EFFECT_KNIGHT - else if (rgblight_status.base_mode == RGBLIGHT_MODE_KNIGHT) { - // knight mode - interval_time = get_interval_time(&RGBLED_KNIGHT_INTERVALS[delta], 5, 100); - effect_func = rgblight_effect_knight; - } -#endif -#ifdef RGBLIGHT_EFFECT_CHRISTMAS - else if (rgblight_status.base_mode == RGBLIGHT_MODE_CHRISTMAS) { - // christmas mode - interval_time = RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL; - effect_func = (effect_func_t)rgblight_effect_christmas; - } -#endif -#ifdef RGBLIGHT_EFFECT_RGB_TEST - else if (rgblight_status.base_mode == RGBLIGHT_MODE_RGB_TEST) { - // RGB test mode - interval_time = pgm_read_word(&RGBLED_RGBTEST_INTERVALS[0]); - effect_func = (effect_func_t)rgblight_effect_rgbtest; - } -#endif -#ifdef RGBLIGHT_EFFECT_ALTERNATING - else if (rgblight_status.base_mode == RGBLIGHT_MODE_ALTERNATING){ - interval_time = 500; - effect_func = (effect_func_t)rgblight_effect_alternating; - } -#endif - if (animation_status.restart) { - animation_status.restart = false; - animation_status.last_timer = timer_read() - interval_time - 1; - animation_status.pos16 = 0; // restart signal to local each effect - } - if (timer_elapsed(animation_status.last_timer) >= interval_time) { -#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) - static uint16_t report_last_timer = 0; - static bool tick_flag = false; - uint16_t oldpos16; - if (tick_flag) { - tick_flag = false; - if (timer_elapsed(report_last_timer) >= 30000) { - report_last_timer = timer_read(); - dprintf("rgblight animation tick report to slave\n"); - RGBLIGHT_SPLIT_ANIMATION_TICK; + if (rgblight_status.timer_enabled) { + effect_func_t effect_func = rgblight_effect_dummy; + uint16_t interval_time = 2000; // dummy interval + uint8_t delta = rgblight_config.mode - rgblight_status.base_mode; + animation_status.delta = delta; + + // static light mode, do nothing here + if (1 == 0) { // dummy + } +# ifdef RGBLIGHT_EFFECT_BREATHING + else if (rgblight_status.base_mode == RGBLIGHT_MODE_BREATHING) { + // breathing mode + interval_time = get_interval_time(&RGBLED_BREATHING_INTERVALS[delta], 1, 100); + effect_func = rgblight_effect_breathing; + } +# endif +# ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD + else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_MOOD) { + // rainbow mood mode + interval_time = get_interval_time(&RGBLED_RAINBOW_MOOD_INTERVALS[delta], 5, 100); + effect_func = rgblight_effect_rainbow_mood; + } +# endif +# ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL + else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_SWIRL) { + // rainbow swirl mode + interval_time = get_interval_time(&RGBLED_RAINBOW_SWIRL_INTERVALS[delta / 2], 1, 100); + effect_func = rgblight_effect_rainbow_swirl; + } +# endif +# ifdef RGBLIGHT_EFFECT_SNAKE + else if (rgblight_status.base_mode == RGBLIGHT_MODE_SNAKE) { + // snake mode + interval_time = get_interval_time(&RGBLED_SNAKE_INTERVALS[delta / 2], 1, 200); + effect_func = rgblight_effect_snake; + } +# endif +# ifdef RGBLIGHT_EFFECT_KNIGHT + else if (rgblight_status.base_mode == RGBLIGHT_MODE_KNIGHT) { + // knight mode + interval_time = get_interval_time(&RGBLED_KNIGHT_INTERVALS[delta], 5, 100); + effect_func = rgblight_effect_knight; + } +# endif +# ifdef RGBLIGHT_EFFECT_CHRISTMAS + else if (rgblight_status.base_mode == RGBLIGHT_MODE_CHRISTMAS) { + // christmas mode + interval_time = RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL; + effect_func = (effect_func_t)rgblight_effect_christmas; + } +# endif +# ifdef RGBLIGHT_EFFECT_RGB_TEST + else if (rgblight_status.base_mode == RGBLIGHT_MODE_RGB_TEST) { + // RGB test mode + interval_time = pgm_read_word(&RGBLED_RGBTEST_INTERVALS[0]); + effect_func = (effect_func_t)rgblight_effect_rgbtest; + } +# endif +# ifdef RGBLIGHT_EFFECT_ALTERNATING + else if (rgblight_status.base_mode == RGBLIGHT_MODE_ALTERNATING) { + interval_time = 500; + effect_func = (effect_func_t)rgblight_effect_alternating; + } +# endif + if (animation_status.restart) { + animation_status.restart = false; + animation_status.last_timer = timer_read() - interval_time - 1; + animation_status.pos16 = 0; // restart signal to local each effect + } + if (timer_elapsed(animation_status.last_timer) >= interval_time) { +# if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) + static uint16_t report_last_timer = 0; + static bool tick_flag = false; + uint16_t oldpos16; + if (tick_flag) { + tick_flag = false; + if (timer_elapsed(report_last_timer) >= 30000) { + report_last_timer = timer_read(); + dprintf("rgblight animation tick report to slave\n"); + RGBLIGHT_SPLIT_ANIMATION_TICK; + } + } + oldpos16 = animation_status.pos16; +# endif + animation_status.last_timer += interval_time; + effect_func(&animation_status); +# if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) + if (animation_status.pos16 == 0 && oldpos16 != 0) { + tick_flag = true; + } +# endif } - } - oldpos16 = animation_status.pos16; -#endif - animation_status.last_timer += interval_time; - effect_func(&animation_status); -#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) - if (animation_status.pos16 == 0 && oldpos16 != 0) { - tick_flag = true; - } -#endif } - } } #endif /* RGBLIGHT_USE_TIMER */ @@ -888,237 +822,235 @@ void rgblight_task(void) { // Effects #ifdef RGBLIGHT_EFFECT_BREATHING -#ifndef RGBLIGHT_EFFECT_BREATHE_CENTER - #ifndef RGBLIGHT_BREATHE_TABLE_SIZE - #define RGBLIGHT_BREATHE_TABLE_SIZE 256 // 256 or 128 or 64 - #endif - #include -#endif +# ifndef RGBLIGHT_EFFECT_BREATHE_CENTER +# ifndef RGBLIGHT_BREATHE_TABLE_SIZE +# define RGBLIGHT_BREATHE_TABLE_SIZE 256 // 256 or 128 or 64 +# endif +# include +# endif -__attribute__ ((weak)) -const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5}; +__attribute__((weak)) const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5}; void rgblight_effect_breathing(animation_status_t *anim) { - float val; + float val; - // http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ -#ifdef RGBLIGHT_EFFECT_BREATHE_TABLE - val = pgm_read_byte(&rgblight_effect_breathe_table[anim->pos / table_scale]); -#else - val = (exp(sin((anim->pos/255.0)*M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)*(RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E)); -#endif - rgblight_sethsv_noeeprom_old(rgblight_config.hue, rgblight_config.sat, val); - anim->pos = (anim->pos + 1); + // http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ +# ifdef RGBLIGHT_EFFECT_BREATHE_TABLE + val = pgm_read_byte(&rgblight_effect_breathe_table[anim->pos / table_scale]); +# else + val = (exp(sin((anim->pos / 255.0) * M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER / M_E) * (RGBLIGHT_EFFECT_BREATHE_MAX / (M_E - 1 / M_E)); +# endif + rgblight_sethsv_noeeprom_old(rgblight_config.hue, rgblight_config.sat, val); + anim->pos = (anim->pos + 1); } #endif #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD -__attribute__ ((weak)) -const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[] PROGMEM = {120, 60, 30}; +__attribute__((weak)) const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[] PROGMEM = {120, 60, 30}; void rgblight_effect_rainbow_mood(animation_status_t *anim) { - rgblight_sethsv_noeeprom_old(anim->current_hue, rgblight_config.sat, rgblight_config.val); - anim->current_hue++; + rgblight_sethsv_noeeprom_old(anim->current_hue, rgblight_config.sat, rgblight_config.val); + anim->current_hue++; } #endif #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL -#ifndef RGBLIGHT_RAINBOW_SWIRL_RANGE - #define RGBLIGHT_RAINBOW_SWIRL_RANGE 255 -#endif +# ifndef RGBLIGHT_RAINBOW_SWIRL_RANGE +# define RGBLIGHT_RAINBOW_SWIRL_RANGE 255 +# endif -__attribute__ ((weak)) -const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[] PROGMEM = {100, 50, 20}; +__attribute__((weak)) const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[] PROGMEM = {100, 50, 20}; void rgblight_effect_rainbow_swirl(animation_status_t *anim) { - uint8_t hue; - uint8_t i; + uint8_t hue; + uint8_t i; - for (i = 0; i < effect_num_leds; i++) { - hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / effect_num_leds * i + anim->current_hue); - sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + effect_start_pos]); - } - rgblight_set(); + for (i = 0; i < effect_num_leds; i++) { + hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / effect_num_leds * i + anim->current_hue); + sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + effect_start_pos]); + } + rgblight_set(); - if (anim->delta % 2) { - anim->current_hue++; - } else { - anim->current_hue--; - } + if (anim->delta % 2) { + anim->current_hue++; + } else { + anim->current_hue--; + } } #endif #ifdef RGBLIGHT_EFFECT_SNAKE -__attribute__ ((weak)) -const uint8_t RGBLED_SNAKE_INTERVALS[] PROGMEM = {100, 50, 20}; +__attribute__((weak)) const uint8_t RGBLED_SNAKE_INTERVALS[] PROGMEM = {100, 50, 20}; void rgblight_effect_snake(animation_status_t *anim) { - static uint8_t pos = 0; - uint8_t i, j; - int8_t k; - int8_t increment = 1; - - if (anim->delta % 2) { - increment = -1; - } + static uint8_t pos = 0; + uint8_t i, j; + int8_t k; + int8_t increment = 1; -#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) - if (anim->pos == 0) { // restart signal - if (increment == 1) { - pos = effect_num_leds - 1; - } else { - pos = 0; + if (anim->delta % 2) { + increment = -1; } - anim->pos = 1; - } -#endif - for (i = 0; i < effect_num_leds; i++) { - LED_TYPE *ledp = led + i + effect_start_pos; - ledp->r = 0; - ledp->g = 0; - ledp->b = 0; - for (j = 0; j < RGBLIGHT_EFFECT_SNAKE_LENGTH; j++) { - k = pos + j * increment; - if (k < 0) { - k = k + effect_num_leds; - } - if (i == k) { - sethsv(rgblight_config.hue, rgblight_config.sat, - (uint8_t)(rgblight_config.val*(RGBLIGHT_EFFECT_SNAKE_LENGTH-j)/RGBLIGHT_EFFECT_SNAKE_LENGTH), - ledp); - } +# if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) + if (anim->pos == 0) { // restart signal + if (increment == 1) { + pos = effect_num_leds - 1; + } else { + pos = 0; + } + anim->pos = 1; } - } - rgblight_set(); - if (increment == 1) { - if (pos - 1 < 0) { - pos = effect_num_leds - 1; -#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) - anim->pos = 0; -#endif +# endif + + for (i = 0; i < effect_num_leds; i++) { + LED_TYPE *ledp = led + i + effect_start_pos; + ledp->r = 0; + ledp->g = 0; + ledp->b = 0; + for (j = 0; j < RGBLIGHT_EFFECT_SNAKE_LENGTH; j++) { + k = pos + j * increment; + if (k < 0) { + k = k + effect_num_leds; + } + if (i == k) { + sethsv(rgblight_config.hue, rgblight_config.sat, (uint8_t)(rgblight_config.val * (RGBLIGHT_EFFECT_SNAKE_LENGTH - j) / RGBLIGHT_EFFECT_SNAKE_LENGTH), ledp); + } + } + } + rgblight_set(); + if (increment == 1) { + if (pos - 1 < 0) { + pos = effect_num_leds - 1; +# if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) + anim->pos = 0; +# endif + } else { + pos -= 1; +# if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) + anim->pos = 1; +# endif + } } else { - pos -= 1; -#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) - anim->pos = 1; -#endif + pos = (pos + 1) % effect_num_leds; +# if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) + anim->pos = pos; +# endif } - } else { - pos = (pos + 1) % effect_num_leds; -#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) - anim->pos = pos; -#endif - } } #endif #ifdef RGBLIGHT_EFFECT_KNIGHT -__attribute__ ((weak)) -const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {127, 63, 31}; +__attribute__((weak)) const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {127, 63, 31}; void rgblight_effect_knight(animation_status_t *anim) { - - static int8_t low_bound = 0; - static int8_t high_bound = RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1; - static int8_t increment = 1; - uint8_t i, cur; - -#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) - if (anim->pos == 0) { // restart signal - anim->pos = 1; - low_bound = 0; - high_bound = RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1; - increment = 1; - } -#endif - // Set all the LEDs to 0 - for (i = effect_start_pos; i < effect_end_pos; i++) { - led[i].r = 0; - led[i].g = 0; - led[i].b = 0; - } - // Determine which LEDs should be lit up - for (i = 0; i < RGBLIGHT_EFFECT_KNIGHT_LED_NUM; i++) { - cur = (i + RGBLIGHT_EFFECT_KNIGHT_OFFSET) % effect_num_leds + effect_start_pos; - - if (i >= low_bound && i <= high_bound) { - sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[cur]); - } else { - led[cur].r = 0; - led[cur].g = 0; - led[cur].b = 0; + static int8_t low_bound = 0; + static int8_t high_bound = RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1; + static int8_t increment = 1; + uint8_t i, cur; + +# if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) + if (anim->pos == 0) { // restart signal + anim->pos = 1; + low_bound = 0; + high_bound = RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1; + increment = 1; } - } - rgblight_set(); - - // Move from low_bound to high_bound changing the direction we increment each - // time a boundary is hit. - low_bound += increment; - high_bound += increment; +# endif + // Set all the LEDs to 0 + for (i = effect_start_pos; i < effect_end_pos; i++) { + led[i].r = 0; + led[i].g = 0; + led[i].b = 0; + } + // Determine which LEDs should be lit up + for (i = 0; i < RGBLIGHT_EFFECT_KNIGHT_LED_NUM; i++) { + cur = (i + RGBLIGHT_EFFECT_KNIGHT_OFFSET) % effect_num_leds + effect_start_pos; - if (high_bound <= 0 || low_bound >= RGBLIGHT_EFFECT_KNIGHT_LED_NUM - 1) { - increment = -increment; -#if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) - if (increment == 1) { - anim->pos = 0; + if (i >= low_bound && i <= high_bound) { + sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[cur]); + } else { + led[cur].r = 0; + led[cur].g = 0; + led[cur].b = 0; + } + } + rgblight_set(); + + // Move from low_bound to high_bound changing the direction we increment each + // time a boundary is hit. + low_bound += increment; + high_bound += increment; + + if (high_bound <= 0 || low_bound >= RGBLIGHT_EFFECT_KNIGHT_LED_NUM - 1) { + increment = -increment; +# if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) + if (increment == 1) { + anim->pos = 0; + } +# endif } -#endif - } } #endif #ifdef RGBLIGHT_EFFECT_CHRISTMAS void rgblight_effect_christmas(animation_status_t *anim) { - uint8_t hue; - uint8_t i; - - anim->current_offset = (anim->current_offset + 1) % 2; - for (i = 0; i < effect_num_leds; i++) { - hue = 0 + ((i/RGBLIGHT_EFFECT_CHRISTMAS_STEP + anim->current_offset) % 2) * 85; - sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + effect_start_pos]); - } - rgblight_set(); + uint8_t hue; + uint8_t i; + + anim->current_offset = (anim->current_offset + 1) % 2; + for (i = 0; i < effect_num_leds; i++) { + hue = 0 + ((i / RGBLIGHT_EFFECT_CHRISTMAS_STEP + anim->current_offset) % 2) * 85; + sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + effect_start_pos]); + } + rgblight_set(); } #endif #ifdef RGBLIGHT_EFFECT_RGB_TEST -__attribute__ ((weak)) -const uint16_t RGBLED_RGBTEST_INTERVALS[] PROGMEM = {1024}; +__attribute__((weak)) const uint16_t RGBLED_RGBTEST_INTERVALS[] PROGMEM = {1024}; void rgblight_effect_rgbtest(animation_status_t *anim) { - static uint8_t maxval = 0; - uint8_t g; uint8_t r; uint8_t b; - - if( maxval == 0 ) { - LED_TYPE tmp_led; - sethsv(0, 255, RGBLIGHT_LIMIT_VAL, &tmp_led); - maxval = tmp_led.r; - } - g = r = b = 0; - switch( anim->pos ) { - case 0: r = maxval; break; - case 1: g = maxval; break; - case 2: b = maxval; break; - } - rgblight_setrgb(r, g, b); - anim->pos = (anim->pos + 1) % 3; + static uint8_t maxval = 0; + uint8_t g; + uint8_t r; + uint8_t b; + + if (maxval == 0) { + LED_TYPE tmp_led; + sethsv(0, 255, RGBLIGHT_LIMIT_VAL, &tmp_led); + maxval = tmp_led.r; + } + g = r = b = 0; + switch (anim->pos) { + case 0: + r = maxval; + break; + case 1: + g = maxval; + break; + case 2: + b = maxval; + break; + } + rgblight_setrgb(r, g, b); + anim->pos = (anim->pos + 1) % 3; } #endif #ifdef RGBLIGHT_EFFECT_ALTERNATING void rgblight_effect_alternating(animation_status_t *anim) { - - for (int i = 0; i < effect_num_leds; i++) { - LED_TYPE *ledp = led + i + effect_start_pos; - if (ipos) { - sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp); - } else if (i>=effect_num_leds/2 && !anim->pos) { - sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp); - } else { - sethsv(rgblight_config.hue, rgblight_config.sat, 0, ledp); - } - } - rgblight_set(); - anim->pos = (anim->pos + 1) % 2; + for (int i = 0; i < effect_num_leds; i++) { + LED_TYPE *ledp = led + i + effect_start_pos; + if (i < effect_num_leds / 2 && anim->pos) { + sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp); + } else if (i >= effect_num_leds / 2 && !anim->pos) { + sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp); + } else { + sethsv(rgblight_config.hue, rgblight_config.sat, 0, ledp); + } + } + rgblight_set(); + anim->pos = (anim->pos + 1) % 2; } #endif -- cgit v1.2.3 From 5a3aefed8d7fa2d86ff3d292915b42a3444048d0 Mon Sep 17 00:00:00 2001 From: theVDude Date: Tue, 15 Oct 2019 18:13:13 -0400 Subject: Fix small hiccup in snake animation (#6858) --- quantum/rgblight.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index a094863fe9..1c197827f2 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -910,6 +910,9 @@ void rgblight_effect_snake(animation_status_t *anim) { ledp->b = 0; for (j = 0; j < RGBLIGHT_EFFECT_SNAKE_LENGTH; j++) { k = pos + j * increment; + if (k > RGBLED_NUM) { + k = k % RGBLED_NUM; + } if (k < 0) { k = k + effect_num_leds; } -- cgit v1.2.3 From 60e4921378d879eed110f801328e9642f35fa1e9 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Sat, 9 Nov 2019 07:51:39 -0800 Subject: Unify RGB and RGBW commands (#7297) * Fix unicode in comments Co-Authored-By: fauxpark * Remove separate RGBW implementation for a unified function * Set White to 0 in RGBW LEDs This is just to get this working, later, proper brightness can be handled elsewhere. * Use us instead of nanoseconds(?) since it renders correctly on web * Remove RGBW function from arm/ws2812.h * Remove RGBW function from arm/ws2812.c * Formatting changes * Add doc info --- quantum/rgblight.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 1c197827f2..a4cbe513e1 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -126,6 +126,9 @@ void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1) { (*led1).r = r; (*led1).g = g; (*led1).b = b; +#ifdef RGBW + (*led1).w = 0; +#endif } void rgblight_check_config(void) { @@ -514,6 +517,9 @@ void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b) { led[i].r = r; led[i].g = g; led[i].b = b; +#ifdef RGBW + led[i].w = 0; +#endif } rgblight_set(); } @@ -526,6 +532,9 @@ void rgblight_setrgb_at(uint8_t r, uint8_t g, uint8_t b, uint8_t index) { led[index].r = r; led[index].g = g; led[index].b = b; +#ifdef RGBW + led[index].w = 0; +#endif rgblight_set(); } @@ -560,6 +569,9 @@ void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8 led[i].r = r; led[i].g = g; led[i].b = b; +#ifdef RGBW + led[i].w = 0; +#endif } rgblight_set(); wait_ms(1); @@ -595,6 +607,9 @@ void rgblight_set(void) { led[i].r = 0; led[i].g = 0; led[i].b = 0; +# ifdef RGBW + led[i].w = 0; +# endif } } # ifdef RGBLIGHT_LED_MAP @@ -606,11 +621,7 @@ void rgblight_set(void) { # else start_led = led + clipping_start_pos; # endif -# ifdef RGBW - ws2812_setleds_rgbw(start_led, num_leds); -# else ws2812_setleds(start_led, num_leds); -# endif } #endif @@ -908,6 +919,9 @@ void rgblight_effect_snake(animation_status_t *anim) { ledp->r = 0; ledp->g = 0; ledp->b = 0; +# ifdef RGBW + ledp->w = 0; +# endif for (j = 0; j < RGBLIGHT_EFFECT_SNAKE_LENGTH; j++) { k = pos + j * increment; if (k > RGBLED_NUM) { @@ -965,6 +979,9 @@ void rgblight_effect_knight(animation_status_t *anim) { led[i].r = 0; led[i].g = 0; led[i].b = 0; +# ifdef RGBW + led[i].w = 0; +# endif } // Determine which LEDs should be lit up for (i = 0; i < RGBLIGHT_EFFECT_KNIGHT_LED_NUM; i++) { @@ -976,6 +993,9 @@ void rgblight_effect_knight(animation_status_t *anim) { led[cur].r = 0; led[cur].g = 0; led[cur].b = 0; +# ifdef RGBW + led[cur].w = 0; +# endif } } rgblight_set(); -- cgit v1.2.3 From f48986dda29f9ca4a88d4b4da9ba00dd7864914e Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Mon, 11 Nov 2019 21:06:14 +0000 Subject: Remove force of debug on within rgblight - causes lockups waiting for hid_listen (#7330) --- quantum/rgblight.c | 1 - 1 file changed, 1 deletion(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index a4cbe513e1..80f276139c 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -189,7 +189,6 @@ void rgblight_init(void) { return; } - debug_enable = 1; // Debug ON! dprintf("rgblight_init called.\n"); dprintf("rgblight_init start!\n"); if (!eeconfig_is_enabled()) { -- cgit v1.2.3 From a91c0c476507cb8c12840abb59bff34ab0de3c03 Mon Sep 17 00:00:00 2001 From: zvecr Date: Sun, 17 Nov 2019 14:02:26 +0000 Subject: Run clang-format manually to fix recently changed files --- quantum/rgblight.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 80f276139c..7949bb688e 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -919,7 +919,7 @@ void rgblight_effect_snake(animation_status_t *anim) { ledp->g = 0; ledp->b = 0; # ifdef RGBW - ledp->w = 0; + ledp->w = 0; # endif for (j = 0; j < RGBLIGHT_EFFECT_SNAKE_LENGTH; j++) { k = pos + j * increment; -- cgit v1.2.3 From 7ba6456c0b2e041bb9f97dbed265c5b8b4b12192 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Tue, 31 Dec 2019 08:33:49 -0800 Subject: Use White channel on RGBW LEDs (#7678) * Use White channel on RGBW LEDs Co-authored-by: kwerdenker * Manually apply white channel to array * Move where convert_rgb_to_rgbw is called * Fix type for rgbw led struct * Add changes to Ergodox EZ can revert if deemed necessary * Revert "Add changes to Ergodox EZ" This reverts commit aa44db198d40d758ca10470eb94615513592d1dd. * Revert "Fix type for rgbw led struct" This reverts commit c5c744cba040201cc0d124400773cf13f8a2cf22. * Revert "Move where convert_rgb_to_rgbw is called" This reverts commit cd7f17caf6dd30731c54b3be54490fe4519444f9. * Revert changes and fix up functions * Enable white channel for Ergodox EZ as well * Only run conversion of rgblight is enabled Co-authored-by: kwerdenker --- quantum/rgblight.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 7949bb688e..141dc2e7bc 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -611,6 +611,7 @@ void rgblight_set(void) { # endif } } + # ifdef RGBLIGHT_LED_MAP LED_TYPE led0[RGBLED_NUM]; for (uint8_t i = 0; i < RGBLED_NUM; i++) { @@ -620,7 +621,13 @@ void rgblight_set(void) { # else start_led = led + clipping_start_pos; # endif - ws2812_setleds(start_led, num_leds); + +#ifdef RGBW + for (uint8_t i = 0; i < num_leds; i++) { + convert_rgb_to_rgbw(&start_led[i]); + } +#endif + ws2812_setleds(start_led, num_leds); } #endif -- cgit v1.2.3 From 667045b4928badaedb38f535d885a46ff8a454fb Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Sun, 19 Jan 2020 16:30:34 +0000 Subject: Run clang-format manually to fix recently changed files (#7934) * Run clang-format manually to fix recently changed files * Run clang-format manually to fix recently changed files - revert template files * Run clang-format manually to fix recently changed files - format off for ascii_to_keycode_lut --- quantum/rgblight.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 141dc2e7bc..26887f057e 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -622,12 +622,12 @@ void rgblight_set(void) { start_led = led + clipping_start_pos; # endif -#ifdef RGBW +# ifdef RGBW for (uint8_t i = 0; i < num_leds; i++) { convert_rgb_to_rgbw(&start_led[i]); } -#endif - ws2812_setleds(start_led, num_leds); +# endif + ws2812_setleds(start_led, num_leds); } #endif -- cgit v1.2.3 From 484a9b12bc3961fc0dd9481d3cb734959db42191 Mon Sep 17 00:00:00 2001 From: Wilba Date: Tue, 21 Jan 2020 05:18:25 +1100 Subject: Add VIA support for QMK backlight, QMK RGBLight (#7911) * Add VIA support for QMK backlight, QMK RGBLight * clang-format changes --- quantum/rgblight.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 26887f057e..85b3191105 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -160,6 +160,10 @@ void eeconfig_update_rgblight(uint32_t val) { #endif } +void eeconfig_update_rgblight_current(void) { + eeconfig_update_rgblight(rgblight_config.raw); +} + void eeconfig_update_rgblight_default(void) { rgblight_config.enable = 1; rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT; @@ -501,6 +505,22 @@ void rgblight_sethsv(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_sethsv_ee void rgblight_sethsv_noeeprom(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_sethsv_eeprom_helper(hue, sat, val, false); } +uint8_t rgblight_get_speed(void) { return rgblight_config.speed; } + +void rgblight_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { + rgblight_config.speed = speed; + if (write_to_eeprom) { + eeconfig_update_rgblight(rgblight_config.raw); // EECONFIG needs to be increased to support this + dprintf("rgblight set speed [EEPROM]: %u\n", rgblight_config.speed); + } else { + dprintf("rgblight set speed [NOEEPROM]: %u\n", rgblight_config.speed); + } +} + +void rgblight_set_speed(uint8_t speed) { rgblight_set_speed_eeprom_helper(speed, true); } + +void rgblight_set_speed_noeeprom(uint8_t speed) { rgblight_set_speed_eeprom_helper(speed, false); } + uint8_t rgblight_get_hue(void) { return rgblight_config.hue; } uint8_t rgblight_get_sat(void) { return rgblight_config.sat; } -- cgit v1.2.3 From e3d59a72f9c5a462066439bb5396484bd39ab739 Mon Sep 17 00:00:00 2001 From: QMK Bot Date: Mon, 20 Jan 2020 18:48:28 +0000 Subject: format code according to conventions [skip ci] --- quantum/rgblight.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 85b3191105..40de19eac3 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -160,9 +160,7 @@ void eeconfig_update_rgblight(uint32_t val) { #endif } -void eeconfig_update_rgblight_current(void) { - eeconfig_update_rgblight(rgblight_config.raw); -} +void eeconfig_update_rgblight_current(void) { eeconfig_update_rgblight(rgblight_config.raw); } void eeconfig_update_rgblight_default(void) { rgblight_config.enable = 1; @@ -510,7 +508,7 @@ uint8_t rgblight_get_speed(void) { return rgblight_config.speed; } void rgblight_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { rgblight_config.speed = speed; if (write_to_eeprom) { - eeconfig_update_rgblight(rgblight_config.raw); // EECONFIG needs to be increased to support this + eeconfig_update_rgblight(rgblight_config.raw); // EECONFIG needs to be increased to support this dprintf("rgblight set speed [EEPROM]: %u\n", rgblight_config.speed); } else { dprintf("rgblight set speed [NOEEPROM]: %u\n", rgblight_config.speed); -- cgit v1.2.3 From d13ada11622977bcc0b530212b4405229805016d Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Wed, 6 Nov 2019 08:04:50 +1100 Subject: Add customisable EEPROM driver selection (#7274) - uprintf -> dprintf - Fix atsam "vendor" eeprom. - Bump Kinetis K20x to 64 bytes, too. - Rollback Kinetis to 32 bytes as partitioning can only be done once. Add warning about changing the value. - Change RAM-backed "fake" EEPROM implementations to match eeconfig's current usage. - Add 24LC128 by request. --- quantum/rgblight.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 40de19eac3..67d601af7f 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -19,9 +19,11 @@ # include # include #endif +#ifdef EEPROM_ENABLE +# include "eeprom.h" +#endif #ifdef STM32_EEPROM_ENABLE # include "hal.h" -# include "eeprom.h" # include "eeprom_stm32.h" #endif #include "wait.h" @@ -146,7 +148,7 @@ void rgblight_check_config(void) { } uint32_t eeconfig_read_rgblight(void) { -#if defined(__AVR__) || defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE) +#ifdef EEPROM_ENABLE return eeprom_read_dword(EECONFIG_RGBLIGHT); #else return 0; @@ -154,7 +156,7 @@ uint32_t eeconfig_read_rgblight(void) { } void eeconfig_update_rgblight(uint32_t val) { -#if defined(__AVR__) || defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE) +#ifdef EEPROM_ENABLE rgblight_check_config(); eeprom_update_dword(EECONFIG_RGBLIGHT, val); #endif -- cgit v1.2.3 From dbbab409812ea7c579760e2973399245c21ff843 Mon Sep 17 00:00:00 2001 From: Takeshi ISHII <2170248+mtei@users.noreply.github.com> Date: Tue, 10 Mar 2020 17:46:03 +0900 Subject: Refactor rgblight_reconfig.h (#7773) * Moved contents of rgblight_reconfig.h to rgblight_post_config.h. In #3582, rgblight_reconfig.h had to be newly created. Now, the build system of qmk_firmware has a post_cofig feature, so that what was done in rgblight_reconfig.h can now be realized in rgblight_post_config.h. **This commit does not change the build result.** Testing script ```shell # build on master git checkout master echo master > /tmp/master_md5.txt # RGBLIGHT_ENABLE = no make HELIX=verbose helix/rev2:default:clean make HELIX=verbose helix/rev2:default md5 helix_rev2_default.hex >> /tmp/master_md5.txt # RGBLIGHT_ENABLE = yes, with animations make HELIX=verbose helix/rev2/back:default:clean make HELIX=verbose helix/rev2/back:default md5 helix_rev2_back_default.hex >> /tmp/master_md5.txt # RGBLIGHT_ENABLE = yes, without animations make HELIX=verbose,no_ani helix/rev2/back:default:clean make HELIX=verbose,no_ani helix/rev2/back:default md5 helix_rev2_back_default.hex >> /tmp/master_md5.txt # build on refactor_rgblight_reconfig.h git checkout refactor_rgblight_reconfig.h echo refactor_rgblight_reconfig.h > /tmp/branch_md5.txt # RGBLIGHT_ENABLE = no make HELIX=verbose helix/rev2:default:clean make HELIX=verbose helix/rev2:default md5 helix_rev2_default.hex >> /tmp/branch_md5.txt # RGBLIGHT_ENABLE = yes, with animations make HELIX=verbose helix/rev2/back:default:clean make HELIX=verbose helix/rev2/back:default md5 helix_rev2_back_default.hex >> /tmp/branch_md5.txt # RGBLIGHT_ENABLE = yes, without animations make HELIX=verbose,no_ani helix/rev2/back:default:clean make HELIX=verbose,no_ani helix/rev2/back:default md5 helix_rev2_back_default.hex >> /tmp/branch_md5.txt diff -u /tmp/master_md5.txt /tmp/branch_md5.txt ``` Test result: ``` --- /tmp/master_md5.txt 2020-01-03 15:42:22.000000000 +0900 +++ /tmp/branch_md5.txt 2020-01-03 15:42:42.000000000 +0900 @@ -1,4 +1,4 @@ -master +refactor_rgblight_reconfig.h MD5 (helix_rev2_default.hex) = f360032edd522448366d471d8f4f8181 MD5 (helix_rev2_back_default.hex) = 0c663acc6cccc44476b3b969ad22a48f MD5 (helix_rev2_back_default.hex) = e66b1195ff6d38e6e22c975b8ae42fd3 ``` * Expressions that are too long are difficult to read, so wrap them. * Edit the expression again * remove `defined(RGBLIGHT_ANIMATIONS)` in `tmk_core/common/*/suspend.c`, `tmk_core/protocol/*/main.c` move contents of rgblight_reconfig.h to rgblight.h. The following changes were made to rgblight.h. ```diff +#ifdef RGBLIGHT_USE_TIMER void rgblight_task(void); void rgblight_timer_init(void); void rgblight_timer_enable(void); void rgblight_timer_disable(void); void rgblight_timer_toggle(void); +#else +#define rgblight_task() +#define rgblight_timer_init() +#define rgblight_timer_enable() +#define rgblight_timer_disable() +#define rgblight_timer_toggle() +#endif ``` The following changes were made to tmk_core/common/avr/suspend.c, tmk_core/common/chibios/suspend.c, tmk_core/protocol/chibios/main.c, tmk_core/protocol/lufa/lufa.c, tmk_core/protocol/vusb/main.c. ```diff -# ifdef RGBLIGHT_ANIMATIONS rgblight_timer_enable(); -# endif ``` ```diff -#if defined(RGBLIGHT_ANIMATIONS) && defined(RGBLIGHT_ENABLE) +#if defined(RGBLIGHT_ENABLE) rgblight_task(); #endif ``` * remove 'defined(RGBLIGHT_ANIMATIONS)' in tmk_core/common/keyboard.c Co-authored-by: Joel Challis --- quantum/rgblight.c | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 67d601af7f..f072ae8ca9 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -211,9 +211,7 @@ void rgblight_init(void) { eeconfig_debug_rgblight(); // display current eeprom values -#ifdef RGBLIGHT_USE_TIMER rgblight_timer_init(); // setup the timer -#endif if (rgblight_config.enable) { rgblight_mode_noeeprom(rgblight_config.mode); @@ -230,9 +228,7 @@ void rgblight_update_dword(uint32_t dword) { if (rgblight_config.enable) rgblight_mode_noeeprom(rgblight_config.mode); else { -#ifdef RGBLIGHT_USE_TIMER rgblight_timer_disable(); -#endif rgblight_set(); } } @@ -300,13 +296,9 @@ void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { dprintf("rgblight mode [NOEEPROM]: %u\n", rgblight_config.mode); } if (is_static_effect(rgblight_config.mode)) { -#ifdef RGBLIGHT_USE_TIMER rgblight_timer_disable(); -#endif } else { -#ifdef RGBLIGHT_USE_TIMER rgblight_timer_enable(); -#endif } #ifdef RGBLIGHT_USE_TIMER animation_status.restart = true; @@ -354,9 +346,7 @@ void rgblight_disable(void) { rgblight_config.enable = 0; eeconfig_update_rgblight(rgblight_config.raw); dprintf("rgblight disable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); -#ifdef RGBLIGHT_USE_TIMER rgblight_timer_disable(); -#endif RGBLIGHT_SPLIT_SET_CHANGE_MODE; wait_ms(50); rgblight_set(); @@ -365,9 +355,7 @@ void rgblight_disable(void) { void rgblight_disable_noeeprom(void) { rgblight_config.enable = 0; dprintf("rgblight disable [NOEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); -#ifdef RGBLIGHT_USE_TIMER rgblight_timer_disable(); -#endif RGBLIGHT_SPLIT_SET_CHANGE_MODE; wait_ms(50); rgblight_set(); -- cgit v1.2.3 From 2ffb08843ba59f0af0870335934bdb277fc85620 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Tue, 10 Mar 2020 12:50:01 -0700 Subject: Feature: RGBLight layers (#7768) * New feature: RGBLIGHT_LAYERS This feature allows users to define multiple independent layers of lighting that can be toggled on and off individually, making it easy to use your RGB lighting to indicate things like active keyboard layer & modifier state. * Demonstrate built in functions for layer state checking Also link the video in the docs. * Follow existing pattern for setting rgblight_status flags * Eliminate rgblight_is_static_mode since it's not needed Just check to see if the timer is enabled directly. --- quantum/rgblight.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index f072ae8ca9..b3f0f18d42 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -38,17 +38,23 @@ # include "velocikey.h" #endif +#ifndef MIN +# define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#endif + #ifdef RGBLIGHT_SPLIT /* for split keyboard */ # define RGBLIGHT_SPLIT_SET_CHANGE_MODE rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_MODE # define RGBLIGHT_SPLIT_SET_CHANGE_HSVS rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_HSVS # define RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS rgblight_status.change_flags |= (RGBLIGHT_STATUS_CHANGE_MODE | RGBLIGHT_STATUS_CHANGE_HSVS) +# define RGBLIGHT_SPLIT_SET_CHANGE_LAYERS rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_LAYERS # define RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_TIMER # define RGBLIGHT_SPLIT_ANIMATION_TICK rgblight_status.change_flags |= RGBLIGHT_STATUS_ANIMATION_TICK #else # define RGBLIGHT_SPLIT_SET_CHANGE_MODE # define RGBLIGHT_SPLIT_SET_CHANGE_HSVS # define RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS +# define RGBLIGHT_SPLIT_SET_CHANGE_LAYERS # define RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE # define RGBLIGHT_SPLIT_ANIMATION_TICK #endif @@ -97,6 +103,10 @@ LED_TYPE led[RGBLED_NUM]; # define LED_ARRAY led #endif +#ifdef RGBLIGHT_LAYERS +rgblight_segment_t const * const *rgblight_layers = NULL; +#endif + static uint8_t clipping_start_pos = 0; static uint8_t clipping_num_leds = RGBLED_NUM; static uint8_t effect_start_pos = 0; @@ -604,11 +614,67 @@ void rgblight_sethsv_master(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_se 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); } #endif // ifndef RGBLIGHT_SPLIT +#ifdef RGBLIGHT_LAYERS +void rgblight_set_layer_state(uint8_t layer, bool enabled) { + uint8_t mask = 1 << layer; + if (enabled) { + rgblight_status.enabled_layer_mask |= mask; + } else { + rgblight_status.enabled_layer_mask &= ~mask; + } + RGBLIGHT_SPLIT_SET_CHANGE_LAYERS; + // Static modes don't have a ticker running to update the LEDs + if (rgblight_status.timer_enabled == false) { + rgblight_mode_noeeprom(rgblight_config.mode); + } +} + +bool rgblight_get_layer_state(uint8_t layer) { + uint8_t mask = 1 << layer; + return (rgblight_status.enabled_layer_mask & mask) != 0; +} + +// Write any enabled LED layers into the buffer +static void rgblight_layers_write(void) { + uint8_t i = 0; + // For each layer + for (const rgblight_segment_t * const *layer_ptr = rgblight_layers; i < RGBLIGHT_MAX_LAYERS; layer_ptr++, i++) { + if (!rgblight_get_layer_state(i)) { + continue; // Layer is disabled + } + const rgblight_segment_t * segment_ptr = pgm_read_ptr(layer_ptr); + if (segment_ptr == NULL) { + break; // No more layers + } + // For each segment + while (1) { + rgblight_segment_t segment; + memcpy_P(&segment, segment_ptr, sizeof(rgblight_segment_t)); + if (segment.index == RGBLIGHT_END_SEGMENT_INDEX) { + break; // No more segments + } + // Write segment.count LEDs + LED_TYPE * const limit = &led[MIN(segment.index + segment.count, RGBLED_NUM)]; + for (LED_TYPE *led_ptr = &led[segment.index]; led_ptr < limit; led_ptr++) { + sethsv(segment.hue, segment.sat, segment.val, led_ptr); + } + segment_ptr++; + } + } +} +#endif + #ifndef RGBLIGHT_CUSTOM_DRIVER void rgblight_set(void) { LED_TYPE *start_led; uint16_t num_leds = clipping_num_leds; +# ifdef RGBLIGHT_LAYERS + if (rgblight_layers != NULL) { + rgblight_layers_write(); + } +# endif + if (!rgblight_config.enable) { for (uint8_t i = effect_start_pos; i < effect_end_pos; i++) { led[i].r = 0; @@ -652,6 +718,11 @@ void rgblight_get_syncinfo(rgblight_syncinfo_t *syncinfo) { /* for split keyboard slave side */ void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom) { +# ifdef RGBLIGHT_LAYERS + if (syncinfo->status.change_flags & RGBLIGHT_STATUS_CHANGE_LAYERS) { + rgblight_status.enabled_layer_mask = syncinfo->status.enabled_layer_mask; + } +# endif if (syncinfo->status.change_flags & RGBLIGHT_STATUS_CHANGE_MODE) { if (syncinfo->config.enable) { rgblight_config.enable = 1; // == rgblight_enable_noeeprom(); -- cgit v1.2.3 From 1aa40dde46ae38e2768fd23e4d7a3bdd8838f724 Mon Sep 17 00:00:00 2001 From: QMK Bot Date: Tue, 10 Mar 2020 20:24:13 +0000 Subject: format code according to conventions [skip ci] --- quantum/rgblight.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index b3f0f18d42..cc35b01ed4 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -104,7 +104,7 @@ LED_TYPE led[RGBLED_NUM]; #endif #ifdef RGBLIGHT_LAYERS -rgblight_segment_t const * const *rgblight_layers = NULL; +rgblight_segment_t const *const *rgblight_layers = NULL; #endif static uint8_t clipping_start_pos = 0; @@ -638,11 +638,11 @@ bool rgblight_get_layer_state(uint8_t layer) { static void rgblight_layers_write(void) { uint8_t i = 0; // For each layer - for (const rgblight_segment_t * const *layer_ptr = rgblight_layers; i < RGBLIGHT_MAX_LAYERS; layer_ptr++, i++) { + for (const rgblight_segment_t *const *layer_ptr = rgblight_layers; i < RGBLIGHT_MAX_LAYERS; layer_ptr++, i++) { if (!rgblight_get_layer_state(i)) { - continue; // Layer is disabled + continue; // Layer is disabled } - const rgblight_segment_t * segment_ptr = pgm_read_ptr(layer_ptr); + const rgblight_segment_t *segment_ptr = pgm_read_ptr(layer_ptr); if (segment_ptr == NULL) { break; // No more layers } @@ -654,7 +654,7 @@ static void rgblight_layers_write(void) { break; // No more segments } // Write segment.count LEDs - LED_TYPE * const limit = &led[MIN(segment.index + segment.count, RGBLED_NUM)]; + LED_TYPE *const limit = &led[MIN(segment.index + segment.count, RGBLED_NUM)]; for (LED_TYPE *led_ptr = &led[segment.index]; led_ptr < limit; led_ptr++) { sethsv(segment.hue, segment.sat, segment.val, led_ptr); } -- cgit v1.2.3 From 86c4c4e91de20b3f928300cfab617963c31699f9 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Wed, 29 Apr 2020 01:22:28 -0700 Subject: Convert clipping variables in rgblight.c to a structure (#7720) --- quantum/rgblight.c | 73 +++++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 36 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index cc35b01ed4..ef46f231fc 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -107,23 +107,19 @@ LED_TYPE led[RGBLED_NUM]; rgblight_segment_t const *const *rgblight_layers = NULL; #endif -static uint8_t clipping_start_pos = 0; -static uint8_t clipping_num_leds = RGBLED_NUM; -static uint8_t effect_start_pos = 0; -static uint8_t effect_end_pos = RGBLED_NUM; -static uint8_t effect_num_leds = RGBLED_NUM; +rgblight_ranges_t rgblight_ranges = { 0, RGBLED_NUM, 0, RGBLED_NUM, RGBLED_NUM }; void rgblight_set_clipping_range(uint8_t start_pos, uint8_t num_leds) { - clipping_start_pos = start_pos; - clipping_num_leds = num_leds; + rgblight_ranges.clipping_start_pos = start_pos; + rgblight_ranges.clipping_num_leds = num_leds; } void rgblight_set_effect_range(uint8_t start_pos, uint8_t num_leds) { if (start_pos >= RGBLED_NUM) return; if (start_pos + num_leds > RGBLED_NUM) return; - effect_start_pos = start_pos; - effect_end_pos = start_pos + num_leds; - effect_num_leds = num_leds; + rgblight_ranges.effect_start_pos = start_pos; + rgblight_ranges.effect_end_pos = start_pos + num_leds; + rgblight_ranges.effect_num_leds = num_leds; } void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { @@ -468,15 +464,15 @@ void rgblight_sethsv_eeprom_helper(uint8_t hue, uint8_t sat, uint8_t val, bool w # else uint8_t range = RGBLED_GRADIENT_RANGES[delta / 2]; # endif - for (uint8_t i = 0; i < effect_num_leds; i++) { - uint8_t _hue = ((uint16_t)i * (uint16_t)range) / effect_num_leds; + for (uint8_t i = 0; i < rgblight_ranges.effect_num_leds; i++) { + uint8_t _hue = ((uint16_t)i * (uint16_t)range) / rgblight_ranges.effect_num_leds; if (direction) { _hue = hue + _hue; } else { _hue = hue - _hue; } dprintf("rgblight rainbow set hsv: %d,%d,%d,%u\n", i, _hue, direction, range); - sethsv(_hue, sat, val, (LED_TYPE *)&led[i + effect_start_pos]); + sethsv(_hue, sat, val, (LED_TYPE *)&led[i + rgblight_ranges.effect_start_pos]); } rgblight_set(); } @@ -530,7 +526,7 @@ void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b) { return; } - for (uint8_t i = effect_start_pos; i < effect_end_pos; i++) { + for (uint8_t i = rgblight_ranges.effect_start_pos; i < rgblight_ranges.effect_end_pos; i++) { led[i].r = r; led[i].g = g; led[i].b = b; @@ -664,10 +660,15 @@ static void rgblight_layers_write(void) { } #endif +__attribute__((weak)) +void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds) { + ws2812_setleds(start_led, num_leds); +} + #ifndef RGBLIGHT_CUSTOM_DRIVER void rgblight_set(void) { LED_TYPE *start_led; - uint16_t num_leds = clipping_num_leds; + uint8_t num_leds = rgblight_ranges.clipping_num_leds; # ifdef RGBLIGHT_LAYERS if (rgblight_layers != NULL) { @@ -676,7 +677,7 @@ void rgblight_set(void) { # endif if (!rgblight_config.enable) { - for (uint8_t i = effect_start_pos; i < effect_end_pos; i++) { + for (uint8_t i = rgblight_ranges.effect_start_pos; i < rgblight_ranges.effect_end_pos; i++) { led[i].r = 0; led[i].g = 0; led[i].b = 0; @@ -691,9 +692,9 @@ void rgblight_set(void) { for (uint8_t i = 0; i < RGBLED_NUM; i++) { led0[i] = led[pgm_read_byte(&led_map[i])]; } - start_led = led0 + clipping_start_pos; + start_led = led0 + rgblight_ranges.clipping_start_pos; # else - start_led = led + clipping_start_pos; + start_led = led + rgblight_ranges.clipping_start_pos; # endif # ifdef RGBW @@ -701,7 +702,7 @@ void rgblight_set(void) { convert_rgb_to_rgbw(&start_led[i]); } # endif - ws2812_setleds(start_led, num_leds); + rgblight_call_driver(start_led, num_leds); } #endif @@ -961,9 +962,9 @@ void rgblight_effect_rainbow_swirl(animation_status_t *anim) { uint8_t hue; uint8_t i; - for (i = 0; i < effect_num_leds; i++) { - hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / effect_num_leds * i + anim->current_hue); - sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + effect_start_pos]); + for (i = 0; i < rgblight_ranges.effect_num_leds; i++) { + hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / rgblight_ranges.effect_num_leds * i + anim->current_hue); + sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + rgblight_ranges.effect_start_pos]); } rgblight_set(); @@ -991,7 +992,7 @@ void rgblight_effect_snake(animation_status_t *anim) { # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) if (anim->pos == 0) { // restart signal if (increment == 1) { - pos = effect_num_leds - 1; + pos = rgblight_ranges.effect_num_leds - 1; } else { pos = 0; } @@ -999,8 +1000,8 @@ void rgblight_effect_snake(animation_status_t *anim) { } # endif - for (i = 0; i < effect_num_leds; i++) { - LED_TYPE *ledp = led + i + effect_start_pos; + for (i = 0; i < rgblight_ranges.effect_num_leds; i++) { + LED_TYPE *ledp = led + i + rgblight_ranges.effect_start_pos; ledp->r = 0; ledp->g = 0; ledp->b = 0; @@ -1013,7 +1014,7 @@ void rgblight_effect_snake(animation_status_t *anim) { k = k % RGBLED_NUM; } if (k < 0) { - k = k + effect_num_leds; + k = k + rgblight_ranges.effect_num_leds; } if (i == k) { sethsv(rgblight_config.hue, rgblight_config.sat, (uint8_t)(rgblight_config.val * (RGBLIGHT_EFFECT_SNAKE_LENGTH - j) / RGBLIGHT_EFFECT_SNAKE_LENGTH), ledp); @@ -1023,7 +1024,7 @@ void rgblight_effect_snake(animation_status_t *anim) { rgblight_set(); if (increment == 1) { if (pos - 1 < 0) { - pos = effect_num_leds - 1; + pos = rgblight_ranges.effect_num_leds - 1; # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) anim->pos = 0; # endif @@ -1034,7 +1035,7 @@ void rgblight_effect_snake(animation_status_t *anim) { # endif } } else { - pos = (pos + 1) % effect_num_leds; + pos = (pos + 1) % rgblight_ranges.effect_num_leds; # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) anim->pos = pos; # endif @@ -1060,7 +1061,7 @@ void rgblight_effect_knight(animation_status_t *anim) { } # endif // Set all the LEDs to 0 - for (i = effect_start_pos; i < effect_end_pos; i++) { + for (i = rgblight_ranges.effect_start_pos; i < rgblight_ranges.effect_end_pos; i++) { led[i].r = 0; led[i].g = 0; led[i].b = 0; @@ -1070,7 +1071,7 @@ void rgblight_effect_knight(animation_status_t *anim) { } // Determine which LEDs should be lit up for (i = 0; i < RGBLIGHT_EFFECT_KNIGHT_LED_NUM; i++) { - cur = (i + RGBLIGHT_EFFECT_KNIGHT_OFFSET) % effect_num_leds + effect_start_pos; + cur = (i + RGBLIGHT_EFFECT_KNIGHT_OFFSET) % rgblight_ranges.effect_num_leds + rgblight_ranges.effect_start_pos; if (i >= low_bound && i <= high_bound) { sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[cur]); @@ -1107,9 +1108,9 @@ void rgblight_effect_christmas(animation_status_t *anim) { uint8_t i; anim->current_offset = (anim->current_offset + 1) % 2; - for (i = 0; i < effect_num_leds; i++) { + for (i = 0; i < rgblight_ranges.effect_num_leds; i++) { hue = 0 + ((i / RGBLIGHT_EFFECT_CHRISTMAS_STEP + anim->current_offset) % 2) * 85; - sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + effect_start_pos]); + sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + rgblight_ranges.effect_start_pos]); } rgblight_set(); } @@ -1148,11 +1149,11 @@ void rgblight_effect_rgbtest(animation_status_t *anim) { #ifdef RGBLIGHT_EFFECT_ALTERNATING void rgblight_effect_alternating(animation_status_t *anim) { - for (int i = 0; i < effect_num_leds; i++) { - LED_TYPE *ledp = led + i + effect_start_pos; - if (i < effect_num_leds / 2 && anim->pos) { + for (int i = 0; i < rgblight_ranges.effect_num_leds; i++) { + LED_TYPE *ledp = led + i + rgblight_ranges.effect_start_pos; + if (i < rgblight_ranges.effect_num_leds / 2 && anim->pos) { sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp); - } else if (i >= effect_num_leds / 2 && !anim->pos) { + } else if (i >= rgblight_ranges.effect_num_leds / 2 && !anim->pos) { sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp); } else { sethsv(rgblight_config.hue, rgblight_config.sat, 0, ledp); -- cgit v1.2.3 From 812d80efbdc31b874930b635df48c8f365f5398b Mon Sep 17 00:00:00 2001 From: QMK Bot Date: Wed, 29 Apr 2020 08:57:41 +0000 Subject: format code according to conventions [skip ci] --- quantum/rgblight.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index ef46f231fc..26cb41a96f 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -107,7 +107,7 @@ LED_TYPE led[RGBLED_NUM]; rgblight_segment_t const *const *rgblight_layers = NULL; #endif -rgblight_ranges_t rgblight_ranges = { 0, RGBLED_NUM, 0, RGBLED_NUM, RGBLED_NUM }; +rgblight_ranges_t rgblight_ranges = {0, RGBLED_NUM, 0, RGBLED_NUM, RGBLED_NUM}; void rgblight_set_clipping_range(uint8_t start_pos, uint8_t num_leds) { rgblight_ranges.clipping_start_pos = start_pos; @@ -660,15 +660,12 @@ static void rgblight_layers_write(void) { } #endif -__attribute__((weak)) -void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds) { - ws2812_setleds(start_led, num_leds); -} +__attribute__((weak)) void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds) { ws2812_setleds(start_led, num_leds); } #ifndef RGBLIGHT_CUSTOM_DRIVER void rgblight_set(void) { LED_TYPE *start_led; - uint8_t num_leds = rgblight_ranges.clipping_num_leds; + uint8_t num_leds = rgblight_ranges.clipping_num_leds; # ifdef RGBLIGHT_LAYERS if (rgblight_layers != NULL) { -- cgit v1.2.3 From e0f548085cc9c29e85122d393e74143eb5de1d4d Mon Sep 17 00:00:00 2001 From: Joshua Diamond Date: Sat, 9 May 2020 04:38:33 -0400 Subject: Add ability to blink lighting layer for a specified duration (#8760) * Implement momentarily blink of lighting layers * Refactor spidey3 userspace to use rgb layer blink * Remove un-necessary line from example in documentation * Revert "Refactor spidey3 userspace to use rgb layer blink" This reverts commit 831649bb680c41c6d663ae6fa86d13f4f8bebdd8. * Adds a missing bit of documentation about lighting layer blink * Update docs/feature_rgblight.md per suggestions Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> * Update docs/feature_rgblight.md per suggestions Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> * Update docs/feature_rgblight.md per suggestions Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> * cformat, as suggested Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> --- quantum/rgblight.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 26cb41a96f..33326fa868 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -658,6 +658,31 @@ static void rgblight_layers_write(void) { } } } + +# ifdef RGBLIGHT_LAYER_BLINK +uint8_t _blinked_layer_mask = 0; +uint16_t _blink_duration = 0; +static uint16_t _blink_timer; + +void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms) { + rgblight_set_layer_state(layer, true); + _blinked_layer_mask |= 1 << layer; + _blink_timer = timer_read(); + _blink_duration = duration_ms; +} + +void rgblight_unblink_layers(void) { + if (_blinked_layer_mask != 0 && timer_elapsed(_blink_timer) > _blink_duration) { + for (uint8_t layer = 0; layer < RGBLIGHT_MAX_LAYERS; layer++) { + if ((_blinked_layer_mask & 1 << layer) != 0) { + rgblight_set_layer_state(layer, false); + } + } + _blinked_layer_mask = 0; + } +} +# endif + #endif __attribute__((weak)) void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds) { ws2812_setleds(start_led, num_leds); } @@ -909,6 +934,10 @@ void rgblight_task(void) { # endif } } + +# ifdef RGBLIGHT_LAYER_BLINK + rgblight_unblink_layers(); +# endif } #endif /* RGBLIGHT_USE_TIMER */ -- cgit v1.2.3 From 2fe7e221ec9e412cc008aa5c03eaf27e35ff62c6 Mon Sep 17 00:00:00 2001 From: Joshua Diamond Date: Sat, 9 May 2020 04:56:16 -0400 Subject: New RGB Lighting effect: Twinkle (#8887) * Add twinkle RGB Lighting effect * 2nd twinkle algo - double-buffering * Further refinement: Per-LED twinkle * Add documentation for Twinkle RBG Lighting mode * Bias twinkle saturation closer to the set value * Fix whitespace --- quantum/rgblight.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 33326fa868..8d01bcf0e6 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -15,6 +15,7 @@ */ #include #include +#include #ifdef __AVR__ # include # include @@ -561,7 +562,7 @@ void rgblight_sethsv_at(uint8_t hue, uint8_t sat, uint8_t val, uint8_t index) { rgblight_setrgb_at(tmp_led.r, tmp_led.g, tmp_led.b, index); } -#if defined(RGBLIGHT_EFFECT_BREATHING) || defined(RGBLIGHT_EFFECT_RAINBOW_MOOD) || defined(RGBLIGHT_EFFECT_RAINBOW_SWIRL) || defined(RGBLIGHT_EFFECT_SNAKE) || defined(RGBLIGHT_EFFECT_KNIGHT) +#if defined(RGBLIGHT_EFFECT_BREATHING) || defined(RGBLIGHT_EFFECT_RAINBOW_MOOD) || defined(RGBLIGHT_EFFECT_RAINBOW_SWIRL) || defined(RGBLIGHT_EFFECT_SNAKE) || defined(RGBLIGHT_EFFECT_KNIGHT) || defined(RGBLIGHT_EFFECT_TWINKLE) static uint8_t get_interval_time(const uint8_t *default_interval_address, uint8_t velocikey_min, uint8_t velocikey_max) { return @@ -904,6 +905,12 @@ void rgblight_task(void) { interval_time = 500; effect_func = (effect_func_t)rgblight_effect_alternating; } +# endif +# ifdef RGBLIGHT_EFFECT_TWINKLE + else if (rgblight_status.base_mode == RGBLIGHT_MODE_TWINKLE) { + interval_time = get_interval_time(&RGBLED_TWINKLE_INTERVALS[delta % 3], 5, 50); + effect_func = (effect_func_t)rgblight_effect_twinkle; + } # endif if (animation_status.restart) { animation_status.restart = false; @@ -1189,3 +1196,59 @@ void rgblight_effect_alternating(animation_status_t *anim) { anim->pos = (anim->pos + 1) % 2; } #endif + +#ifdef RGBLIGHT_EFFECT_TWINKLE +__attribute__((weak)) const uint8_t RGBLED_TWINKLE_INTERVALS[] PROGMEM = {50, 25, 10}; + +typedef struct PACKED { + HSV hsv; + uint8_t life; + bool up; +} TwinkleState; + +static TwinkleState led_twinkle_state[RGBLED_NUM]; + +void rgblight_effect_twinkle(animation_status_t *anim) { + + bool random_color = anim->delta / 3; + bool restart = anim->pos == 0; + anim->pos = 1; + + for (uint8_t i = 0; i < rgblight_ranges.effect_num_leds; i++) { + TwinkleState *t = &(led_twinkle_state[i]); + HSV *c = &(t->hsv); + if (restart) { + // Restart + t->life = 0; + t->hsv.v = 0; + } else if (t->life) { + // This LED is already on, either brightening or dimming + t->life--; + uint8_t on = t->up ? RGBLIGHT_EFFECT_TWINKLE_LIFE - t->life : t->life; + c->v = (uint16_t) rgblight_config.val * on / RGBLIGHT_EFFECT_TWINKLE_LIFE; + if (t->life == 0 && t->up) { + t->up = false; + t->life = RGBLIGHT_EFFECT_TWINKLE_LIFE; + } + if (!random_color) { + c->h = rgblight_config.hue; + c->s = rgblight_config.sat; + } + } else if (rand() < RAND_MAX * RGBLIGHT_EFFECT_TWINKLE_PROBABILITY) { + // This LED is off, but was randomly selected to start brightening + c->h = random_color ? rand() % 0xFF : rgblight_config.hue; + c->s = random_color ? (rand() % (rgblight_config.sat / 2)) + (rgblight_config.sat / 2) : rgblight_config.sat; + c->v = 0; + t->life = RGBLIGHT_EFFECT_TWINKLE_LIFE; + t->up = true; + } else { + // This LED is off, and was NOT selected to start brightening + } + + LED_TYPE *ledp = led + i + rgblight_ranges.effect_start_pos; + sethsv(c->h, c->s, c->v, ledp); + } + + rgblight_set(); +} +#endif -- cgit v1.2.3 From e7860d673b0e671988711a487931f61926dbbd56 Mon Sep 17 00:00:00 2001 From: QMK Bot Date: Sat, 9 May 2020 09:31:49 +0000 Subject: format code according to conventions [skip ci] --- quantum/rgblight.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 8d01bcf0e6..4f227794fe 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -1201,33 +1201,32 @@ void rgblight_effect_alternating(animation_status_t *anim) { __attribute__((weak)) const uint8_t RGBLED_TWINKLE_INTERVALS[] PROGMEM = {50, 25, 10}; typedef struct PACKED { - HSV hsv; - uint8_t life; - bool up; + HSV hsv; + uint8_t life; + bool up; } TwinkleState; static TwinkleState led_twinkle_state[RGBLED_NUM]; void rgblight_effect_twinkle(animation_status_t *anim) { - bool random_color = anim->delta / 3; - bool restart = anim->pos == 0; - anim->pos = 1; + bool restart = anim->pos == 0; + anim->pos = 1; for (uint8_t i = 0; i < rgblight_ranges.effect_num_leds; i++) { TwinkleState *t = &(led_twinkle_state[i]); - HSV *c = &(t->hsv); + HSV * c = &(t->hsv); if (restart) { // Restart - t->life = 0; + t->life = 0; t->hsv.v = 0; } else if (t->life) { // This LED is already on, either brightening or dimming t->life--; uint8_t on = t->up ? RGBLIGHT_EFFECT_TWINKLE_LIFE - t->life : t->life; - c->v = (uint16_t) rgblight_config.val * on / RGBLIGHT_EFFECT_TWINKLE_LIFE; + c->v = (uint16_t)rgblight_config.val * on / RGBLIGHT_EFFECT_TWINKLE_LIFE; if (t->life == 0 && t->up) { - t->up = false; + t->up = false; t->life = RGBLIGHT_EFFECT_TWINKLE_LIFE; } if (!random_color) { @@ -1236,11 +1235,11 @@ void rgblight_effect_twinkle(animation_status_t *anim) { } } else if (rand() < RAND_MAX * RGBLIGHT_EFFECT_TWINKLE_PROBABILITY) { // This LED is off, but was randomly selected to start brightening - c->h = random_color ? rand() % 0xFF : rgblight_config.hue; - c->s = random_color ? (rand() % (rgblight_config.sat / 2)) + (rgblight_config.sat / 2) : rgblight_config.sat; - c->v = 0; + c->h = random_color ? rand() % 0xFF : rgblight_config.hue; + c->s = random_color ? (rand() % (rgblight_config.sat / 2)) + (rgblight_config.sat / 2) : rgblight_config.sat; + c->v = 0; t->life = RGBLIGHT_EFFECT_TWINKLE_LIFE; - t->up = true; + t->up = true; } else { // This LED is off, and was NOT selected to start brightening } -- cgit v1.2.3 From a8a8bf0ff3d6e1c9637079b925b30cf7eb8913fd Mon Sep 17 00:00:00 2001 From: Joshua Diamond Date: Wed, 13 May 2020 16:39:05 -0400 Subject: Allow expanding from 8 to 32 RGB Lighting Layers (#8941) * Allow 16 lighting layers * Require #define RGBLIGHT_LAYERS_16 to enable 16 layers * Override RGBLIGHT_MAX_LAYERS to set maximum number of lighting layers * Enforce lower bound on RGBLIGHT_MAX_LAYERS Co-Authored-By: Takeshi ISHII <2170248+mtei@users.noreply.github.com> * Fix an error in the check for valid RGBLIGHT_MAX_LAYERS * Don't use bitfield / PACKED, as it causes bloat * Update documentation re: up to 32 lighting layers * Run cformat * Add note about increasing FW size in docs/config_options.md Co-authored-by: Drashna Jaelre * Remove no-longer-valid comment * Add doc note that split sync will be slower Co-authored-by: Takeshi ISHII <2170248+mtei@users.noreply.github.com> Co-authored-by: Drashna Jaelre --- quantum/rgblight.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 4f227794fe..64123774c7 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -613,7 +613,7 @@ void rgblight_sethsv_slave(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_set #ifdef RGBLIGHT_LAYERS void rgblight_set_layer_state(uint8_t layer, bool enabled) { - uint8_t mask = 1 << layer; + rgblight_layer_mask_t mask = 1 << layer; if (enabled) { rgblight_status.enabled_layer_mask |= mask; } else { @@ -627,7 +627,7 @@ void rgblight_set_layer_state(uint8_t layer, bool enabled) { } bool rgblight_get_layer_state(uint8_t layer) { - uint8_t mask = 1 << layer; + rgblight_layer_mask_t mask = 1 << layer; return (rgblight_status.enabled_layer_mask & mask) != 0; } -- cgit v1.2.3 From d0e0202b272a28d6a1e7f0d059396067bb861272 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Mon, 18 May 2020 06:05:35 -0700 Subject: Add query functions for RGB Light and RGB Matrix (#8960) * Add additional query functions for RGBLIGHT * Add additional query functions for RGB Matrix * Change names of enable check functions * Fix macro for rgb matrix takeover of rgblight functions * Add documentation for rgb_matrix_get_hsv() * Add *_get_hsv function to rgblight --- quantum/rgblight.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 64123774c7..b50be200ee 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -368,6 +368,8 @@ void rgblight_disable_noeeprom(void) { rgblight_set(); } +bool rgblight_is_enabled(void) { return rgblight_config.enable; } + void rgblight_increase_hue_helper(bool write_to_eeprom) { uint8_t hue = rgblight_config.hue + RGBLIGHT_HUE_STEP; rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom); @@ -522,6 +524,10 @@ uint8_t rgblight_get_sat(void) { return rgblight_config.sat; } uint8_t rgblight_get_val(void) { return rgblight_config.val; } +HSV rgblight_get_hsv(void) { + return (HSV){ rgblight_config.hue, rgblight_config.sat, rgblight_config.val }; +} + void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b) { if (!rgblight_config.enable) { return; -- cgit v1.2.3 From 010c5b12bd0bc4a53abda6d8f9d77de8a7ef1e8f Mon Sep 17 00:00:00 2001 From: QMK Bot Date: Mon, 18 May 2020 13:42:23 +0000 Subject: format code according to conventions [skip ci] --- quantum/rgblight.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index b50be200ee..73a7afd7b3 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -524,9 +524,7 @@ uint8_t rgblight_get_sat(void) { return rgblight_config.sat; } uint8_t rgblight_get_val(void) { return rgblight_config.val; } -HSV rgblight_get_hsv(void) { - return (HSV){ rgblight_config.hue, rgblight_config.sat, rgblight_config.val }; -} +HSV rgblight_get_hsv(void) { return (HSV){rgblight_config.hue, rgblight_config.sat, rgblight_config.val}; } void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b) { if (!rgblight_config.enable) { -- cgit v1.2.3 From e2e287ec5f720839efd8f7cecf447763433cda27 Mon Sep 17 00:00:00 2001 From: Joshua Diamond Date: Mon, 1 Jun 2020 05:02:28 -0400 Subject: Option to allow lighting layers when RGB Lighting is off (#9051) --- quantum/rgblight.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 73a7afd7b3..949dd79fe7 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -628,6 +628,13 @@ void rgblight_set_layer_state(uint8_t layer, bool enabled) { if (rgblight_status.timer_enabled == false) { rgblight_mode_noeeprom(rgblight_config.mode); } + +# ifdef RGBLIGHT_LAYERS_OVERRIDE_RGB_OFF + // If not enabled, then nothing else will actually set the LEDs... + if (!rgblight_config.enable) { + rgblight_set(); + } +# endif } bool rgblight_get_layer_state(uint8_t layer) { @@ -693,16 +700,11 @@ void rgblight_unblink_layers(void) { __attribute__((weak)) void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds) { ws2812_setleds(start_led, num_leds); } #ifndef RGBLIGHT_CUSTOM_DRIVER + void rgblight_set(void) { LED_TYPE *start_led; uint8_t num_leds = rgblight_ranges.clipping_num_leds; -# ifdef RGBLIGHT_LAYERS - if (rgblight_layers != NULL) { - rgblight_layers_write(); - } -# endif - if (!rgblight_config.enable) { for (uint8_t i = rgblight_ranges.effect_start_pos; i < rgblight_ranges.effect_end_pos; i++) { led[i].r = 0; @@ -714,6 +716,16 @@ void rgblight_set(void) { } } +# ifdef RGBLIGHT_LAYERS + if (rgblight_layers != NULL +# ifndef RGBLIGHT_LAYERS_OVERRIDE_RGB_OFF + && rgblight_config.enable +# endif + ) { + rgblight_layers_write(); + } +# endif + # ifdef RGBLIGHT_LED_MAP LED_TYPE led0[RGBLED_NUM]; for (uint8_t i = 0; i < RGBLED_NUM; i++) { -- cgit v1.2.3 From 563d5919b32c99b10e63754c4e5dab0c69a7c5e1 Mon Sep 17 00:00:00 2001 From: Joshua Diamond Date: Mon, 1 Jun 2020 20:12:08 -0400 Subject: Fix layer mask size for RGBLIGHT_LAYER_BLINK (#9260) --- quantum/rgblight.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 949dd79fe7..d33484ccfd 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -672,9 +672,9 @@ static void rgblight_layers_write(void) { } # ifdef RGBLIGHT_LAYER_BLINK -uint8_t _blinked_layer_mask = 0; -uint16_t _blink_duration = 0; -static uint16_t _blink_timer; +rgblight_layer_mask_t _blinked_layer_mask = 0; +uint16_t _blink_duration = 0; +static uint16_t _blink_timer; void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms) { rgblight_set_layer_state(layer, true); -- cgit v1.2.3 From b338a4d8867f69bd6a92ec92e306715a4ae41740 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Tue, 25 Aug 2020 02:08:09 -0700 Subject: Add noeeprom speed function for RGBLIGHT (#9706) * [Docs] Add Speed functions to RGB Light docs * Add noeeprom functions for speed * Fix wording in doc Co-authored-by: Ryan Co-authored-by: Ryan --- quantum/rgblight.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index d33484ccfd..f9e9da1679 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -406,17 +406,28 @@ void rgblight_decrease_val_helper(bool write_to_eeprom) { } void rgblight_decrease_val_noeeprom(void) { rgblight_decrease_val_helper(false); } void rgblight_decrease_val(void) { rgblight_decrease_val_helper(true); } -void rgblight_increase_speed(void) { + + +void rgblight_increase_speed_helper(bool write_to_eeprom) { if (rgblight_config.speed < 3) rgblight_config.speed++; // RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED? - eeconfig_update_rgblight(rgblight_config.raw); // EECONFIG needs to be increased to support this + if (write_to_eeprom) { + eeconfig_update_rgblight(rgblight_config.raw); // EECONFIG needs to be increased to support this + } } +void rgblight_increase_speed(void) { rgblight_increase_speed_helper(true); } +void rgblight_increase_speed_noeeprom(void) { rgblight_increase_speed_helper(false); } -void rgblight_decrease_speed(void) { +void rgblight_decrease_speed_helper(bool write_to_eeprom) { if (rgblight_config.speed > 0) rgblight_config.speed--; // RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED?? - eeconfig_update_rgblight(rgblight_config.raw); // EECONFIG needs to be increased to support this + if (write_to_eeprom) { + eeconfig_update_rgblight(rgblight_config.raw); // EECONFIG needs to be increased to support this + } } +void rgblight_decrease_speed(void) { rgblight_decrease_speed_helper(true); } +void rgblight_decrease_speed_noeeprom(void) { rgblight_decrease_speed_helper(false); } + void rgblight_sethsv_noeeprom_old(uint8_t hue, uint8_t sat, uint8_t val) { if (rgblight_config.enable) { -- cgit v1.2.3 From 4b74f985ec7b14f5517df4e591f0c36b24f85f5c Mon Sep 17 00:00:00 2001 From: Max Rumpf Date: Sun, 26 Jul 2020 01:00:33 +0200 Subject: Tweak the Christmas animation effect to be less harsh on the eyes (#7648) * Tweak the Christmas animation effect to be less harsh on the eyes * Further improve the tweaked Christmas animation code - Use constants where it makes sense - Instead of complicated math, use a static variable to keep track if it's animating from or to red - Don't use pow (but a simple macro instead) - Using floating point math is necessary for the fraction in the cubic bezier function to work * Update docs for the tweaked Christmas animation effect * Further improve memory usage - Don't use floats, but 32 bit ints instead (where needed) - Replace limits.h with constant * Fix typo --- quantum/rgblight.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index f9e9da1679..52d8da1813 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -1163,16 +1163,39 @@ void rgblight_effect_knight(animation_status_t *anim) { #endif #ifdef RGBLIGHT_EFFECT_CHRISTMAS +# define CUBED(x) ((x) * (x) * (x)) + +/** + * Christmas lights effect, with a smooth animation between red & green. + */ void rgblight_effect_christmas(animation_status_t *anim) { - uint8_t hue; + static int8_t increment = 1; + const uint8_t max_pos = 32; + const uint8_t hue_green = 85; + + uint32_t xa; + uint8_t hue, val; uint8_t i; - anim->current_offset = (anim->current_offset + 1) % 2; + // The effect works by animating anim->pos from 0 to 32 and back to 0. + // The pos is used in a cubic bezier formula to ease-in-out between red and green, leaving the interpolated colors visible as short as possible. + xa = CUBED((uint32_t) anim->pos); + hue = ((uint32_t) hue_green) * xa / (xa + CUBED((uint32_t) (max_pos - anim->pos))); + // Additionally, these interpolated colors get shown with a slightly darker value, to make them less prominent than the main colors. + val = 255 - (3 * (hue < hue_green / 2 ? hue : hue_green - hue) / 2); + for (i = 0; i < rgblight_ranges.effect_num_leds; i++) { - hue = 0 + ((i / RGBLIGHT_EFFECT_CHRISTMAS_STEP + anim->current_offset) % 2) * 85; - sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + rgblight_ranges.effect_start_pos]); + uint8_t local_hue = (i / RGBLIGHT_EFFECT_CHRISTMAS_STEP) % 2 ? hue : hue_green - hue; + sethsv(local_hue, rgblight_config.sat, val, (LED_TYPE *)&led[i + rgblight_ranges.effect_start_pos]); } rgblight_set(); + + if (anim->pos == 0) { + increment = 1; + } else if (anim->pos == max_pos) { + increment = -1; + } + anim->pos += increment; } #endif -- cgit v1.2.3 From a3db72df7299140e52f57d082a3742a8b480a226 Mon Sep 17 00:00:00 2001 From: QMK Bot Date: Sat, 29 Aug 2020 22:57:48 +0000 Subject: format code according to conventions [skip ci] --- quantum/rgblight.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 52d8da1813..211ec975a6 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -407,7 +407,6 @@ void rgblight_decrease_val_helper(bool write_to_eeprom) { void rgblight_decrease_val_noeeprom(void) { rgblight_decrease_val_helper(false); } void rgblight_decrease_val(void) { rgblight_decrease_val_helper(true); } - void rgblight_increase_speed_helper(bool write_to_eeprom) { if (rgblight_config.speed < 3) rgblight_config.speed++; // RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED? @@ -428,7 +427,6 @@ void rgblight_decrease_speed_helper(bool write_to_eeprom) { void rgblight_decrease_speed(void) { rgblight_decrease_speed_helper(true); } void rgblight_decrease_speed_noeeprom(void) { rgblight_decrease_speed_helper(false); } - void rgblight_sethsv_noeeprom_old(uint8_t hue, uint8_t sat, uint8_t val) { if (rgblight_config.enable) { LED_TYPE tmp_led; @@ -1170,17 +1168,17 @@ void rgblight_effect_knight(animation_status_t *anim) { */ void rgblight_effect_christmas(animation_status_t *anim) { static int8_t increment = 1; - const uint8_t max_pos = 32; + const uint8_t max_pos = 32; const uint8_t hue_green = 85; uint32_t xa; - uint8_t hue, val; - uint8_t i; + uint8_t hue, val; + uint8_t i; // The effect works by animating anim->pos from 0 to 32 and back to 0. // The pos is used in a cubic bezier formula to ease-in-out between red and green, leaving the interpolated colors visible as short as possible. - xa = CUBED((uint32_t) anim->pos); - hue = ((uint32_t) hue_green) * xa / (xa + CUBED((uint32_t) (max_pos - anim->pos))); + xa = CUBED((uint32_t)anim->pos); + hue = ((uint32_t)hue_green) * xa / (xa + CUBED((uint32_t)(max_pos - anim->pos))); // Additionally, these interpolated colors get shown with a slightly darker value, to make them less prominent than the main colors. val = 255 - (3 * (hue < hue_green / 2 ? hue : hue_green - hue) / 2); -- cgit v1.2.3 From c16ee227843dbdb23907fec50fdcad327aa359d7 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sun, 27 Sep 2020 04:42:40 +1000 Subject: `setrgb()`: Use arrow operator (#10451) --- quantum/rgblight.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 211ec975a6..76bb6eb8cb 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -132,11 +132,11 @@ void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { 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); } void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1) { - (*led1).r = r; - (*led1).g = g; - (*led1).b = b; + led1->r = r; + led1->g = g; + led1->b = b; #ifdef RGBW - (*led1).w = 0; + led1->w = 0; #endif } -- cgit v1.2.3 From c66df1664497546f32662409778731143e45a552 Mon Sep 17 00:00:00 2001 From: James Young <18669334+noroadsleft@users.noreply.github.com> Date: Sat, 28 Nov 2020 12:02:18 -0800 Subject: 2020 November 28 Breaking Changes Update (#11053) * Branch point for 2020 November 28 Breaking Change * Remove matrix_col_t to allow MATRIX_ROWS > 32 (#10183) * Add support for soft serial to ATmega32U2 (#10204) * Change MIDI velocity implementation to allow direct control of velocity value (#9940) * Add ability to build a subset of all keyboards based on platform. * Actually use eeprom_driver_init(). * Make bootloader_jump weak for ChibiOS. (#10417) * Joystick 16-bit support (#10439) * Per-encoder resolutions (#10259) * Share button state from mousekey to pointing_device (#10179) * Add hotfix for chibios keyboards not wake (#10088) * Add advanced/efficient RGB Matrix Indicators (#8564) * Naming change. * Support for STM32 GPIOF,G,H,I,J,K (#10206) * Add milc as a dependency and remove the installed milc (#10563) * ChibiOS upgrade: early init conversions (#10214) * ChibiOS upgrade: configuration file migrator (#9952) * Haptic and solenoid cleanup (#9700) * XD75 cleanup (#10524) * OLED display update interval support (#10388) * Add definition based on currently-selected serial driver. (#10716) * New feature: Retro Tapping per key (#10622) * Allow for modification of output RGB values when using rgblight/rgb_matrix. (#10638) * Add housekeeping task callbacks so that keyboards/keymaps are capable of executing code for each main loop iteration. (#10530) * Rescale both ChibiOS and AVR backlighting. * Reduce Helix keyboard build variation (#8669) * Minor change to behavior allowing display updates to continue between task ticks (#10750) * Some GPIO manipulations in matrix.c change to atomic. (#10491) * qmk cformat (#10767) * [Keyboard] Update the Speedo firmware for v3.0 (#10657) * Maartenwut/Maarten namechange to evyd13/Evy (#10274) * [quantum] combine repeated lines of code (#10837) * Add step sequencer feature (#9703) * aeboards/ext65 refactor (#10820) * Refactor xelus/dawn60 for Rev2 later (#10584) * add DEBUG_MATRIX_SCAN_RATE_ENABLE to common_features.mk (#10824) * [Core] Added `add_oneshot_mods` & `del_oneshot_mods` (#10549) * update chibios os usb for the otg driver (#8893) * Remove HD44780 References, Part 4 (#10735) * [Keyboard] Add Valor FRL TKL (+refactor) (#10512) * Fix cursor position bug in oled_write_raw functions (#10800) * Fixup version.h writing when using SKIP_VERSION=yes (#10972) * Allow for certain code in the codebase assuming length of string. (#10974) * Add AT90USB support for serial.c (#10706) * Auto shift: support repeats and early registration (#9826) * Rename ledmatrix.h to match .c file (#7949) * Split RGB_MATRIX_ENABLE into _ENABLE and _DRIVER (#10231) * Split LED_MATRIX_ENABLE into _ENABLE and _DRIVER (#10840) * Merge point for 2020 Nov 28 Breaking Change --- quantum/rgblight.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 76bb6eb8cb..7f9e330d37 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -123,9 +123,11 @@ void rgblight_set_effect_range(uint8_t start_pos, uint8_t num_leds) { rgblight_ranges.effect_num_leds = num_leds; } +__attribute__((weak)) RGB rgblight_hsv_to_rgb(HSV hsv) { return hsv_to_rgb(hsv); } + void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { HSV hsv = {hue, sat, val}; - RGB rgb = hsv_to_rgb(hsv); + RGB rgb = rgblight_hsv_to_rgb(hsv); setrgb(rgb.r, rgb.g, rgb.b, led1); } -- cgit v1.2.3 From a8d0ec0749046b0ab89c18b1b7083b1e8674de2a Mon Sep 17 00:00:00 2001 From: XScorpion2 Date: Tue, 1 Dec 2020 12:04:42 -0600 Subject: [Split] Sync Timer feature (#10997) A timer that is kept in sync between the halves of a split keyboard --- quantum/rgblight.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 7f9e330d37..65308572db 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -29,7 +29,7 @@ #endif #include "wait.h" #include "progmem.h" -#include "timer.h" +#include "sync_timer.h" #include "rgblight.h" #include "color.h" #include "debug.h" @@ -684,18 +684,16 @@ static void rgblight_layers_write(void) { # ifdef RGBLIGHT_LAYER_BLINK rgblight_layer_mask_t _blinked_layer_mask = 0; -uint16_t _blink_duration = 0; static uint16_t _blink_timer; void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms) { rgblight_set_layer_state(layer, true); _blinked_layer_mask |= 1 << layer; - _blink_timer = timer_read(); - _blink_duration = duration_ms; + _blink_timer = sync_timer_read() + duration_ms; } void rgblight_unblink_layers(void) { - if (_blinked_layer_mask != 0 && timer_elapsed(_blink_timer) > _blink_duration) { + if (_blinked_layer_mask != 0 && timer_expired(sync_timer_read(), _blink_timer)) { for (uint8_t layer = 0; layer < RGBLIGHT_MAX_LAYERS; layer++) { if ((_blinked_layer_mask & 1 << layer) != 0) { rgblight_set_layer_state(layer, false); @@ -799,7 +797,7 @@ void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom) { animation_status.restart = true; } # endif /* RGBLIGHT_SPLIT_NO_ANIMATION_SYNC */ -# endif /* RGBLIGHT_USE_TIMER */ +# endif /* RGBLIGHT_USE_TIMER */ } #endif /* RGBLIGHT_SPLIT */ @@ -832,7 +830,7 @@ void rgblight_timer_enable(void) { if (!is_static_effect(rgblight_config.mode)) { rgblight_status.timer_enabled = true; } - animation_status.last_timer = timer_read(); + animation_status.last_timer = sync_timer_read(); RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE; dprintf("rgblight timer enabled.\n"); } @@ -941,18 +939,19 @@ void rgblight_task(void) { # endif if (animation_status.restart) { animation_status.restart = false; - animation_status.last_timer = timer_read() - interval_time - 1; + animation_status.last_timer = sync_timer_read(); animation_status.pos16 = 0; // restart signal to local each effect } - if (timer_elapsed(animation_status.last_timer) >= interval_time) { + uint16_t now = sync_timer_read(); + if (timer_expired(now, animation_status.last_timer)) { # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) static uint16_t report_last_timer = 0; static bool tick_flag = false; uint16_t oldpos16; if (tick_flag) { tick_flag = false; - if (timer_elapsed(report_last_timer) >= 30000) { - report_last_timer = timer_read(); + if (timer_expired(now, report_last_timer)) { + report_last_timer += 30000; dprintf("rgblight animation tick report to slave\n"); RGBLIGHT_SPLIT_ANIMATION_TICK; } -- cgit v1.2.3 From 501f2fdef115314713e94428d409e5c3b5bfc1c2 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 11 Dec 2020 13:45:24 +1100 Subject: Normalise include statements in core code (#11153) * Normalise include statements in core code * Missed one --- quantum/rgblight.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 7f9e330d37..e6f14487c1 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -24,7 +24,7 @@ # include "eeprom.h" #endif #ifdef STM32_EEPROM_ENABLE -# include "hal.h" +# include # include "eeprom_stm32.h" #endif #include "wait.h" @@ -34,7 +34,7 @@ #include "color.h" #include "debug.h" #include "led_tables.h" -#include "lib/lib8tion/lib8tion.h" +#include #ifdef VELOCIKEY_ENABLE # include "velocikey.h" #endif @@ -983,7 +983,7 @@ void rgblight_task(void) { # ifndef RGBLIGHT_BREATHE_TABLE_SIZE # define RGBLIGHT_BREATHE_TABLE_SIZE 256 // 256 or 128 or 64 # endif -# include +# include "rgblight_breathe_table.h" # endif __attribute__((weak)) const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5}; -- cgit v1.2.3 From 10e4487ba368a9e220c96e12a0d17ae729d5c1e1 Mon Sep 17 00:00:00 2001 From: Takeshi ISHII <2170248+mtei@users.noreply.github.com> Date: Sun, 13 Dec 2020 03:19:15 +0900 Subject: Fix incorrect search order for `rgblight_breathe_table.h` that `rgblight.c` includes. (#11192) When `rgblight.c` includes `rgblight_breathe_table.h`, the search order should be as follows. * `keyboards/KEYBOARD/keymaps/USER/rgblight_breathe_table.h` * `users/USER/rgblight_breathe_table.h` * `quantum/rgblight_breathe_table.h` However, the current implementation was wrong, so I fixed it. --- quantum/rgblight.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index e6f14487c1..db725301cb 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -983,7 +983,7 @@ void rgblight_task(void) { # ifndef RGBLIGHT_BREATHE_TABLE_SIZE # define RGBLIGHT_BREATHE_TABLE_SIZE 256 // 256 or 128 or 64 # endif -# include "rgblight_breathe_table.h" +# include # endif __attribute__((weak)) const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5}; -- cgit v1.2.3 From b3de903a3dfe5f75312b6b8a7555ccabe01a5e6e Mon Sep 17 00:00:00 2001 From: Joshua Diamond Date: Sat, 2 Jan 2021 16:42:48 -0500 Subject: Fix broken Lighting Layers when RGBLIGHT_MAX_LAYERS > 16 (#11406) * fix incorrect bit math when RGBLIGHT_MAX_LAYERS > 16 * with 1UL cast is not needed * ...but just casting works and is even more efficient * cformat --- quantum/rgblight.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index db725301cb..beeef65689 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -628,7 +628,7 @@ void rgblight_sethsv_slave(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_set #ifdef RGBLIGHT_LAYERS void rgblight_set_layer_state(uint8_t layer, bool enabled) { - rgblight_layer_mask_t mask = 1 << layer; + rgblight_layer_mask_t mask = (rgblight_layer_mask_t)1 << layer; if (enabled) { rgblight_status.enabled_layer_mask |= mask; } else { @@ -649,7 +649,7 @@ void rgblight_set_layer_state(uint8_t layer, bool enabled) { } bool rgblight_get_layer_state(uint8_t layer) { - rgblight_layer_mask_t mask = 1 << layer; + rgblight_layer_mask_t mask = (rgblight_layer_mask_t)1 << layer; return (rgblight_status.enabled_layer_mask & mask) != 0; } @@ -689,7 +689,7 @@ static uint16_t _blink_timer; void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms) { rgblight_set_layer_state(layer, true); - _blinked_layer_mask |= 1 << layer; + _blinked_layer_mask |= (rgblight_layer_mask_t)1 << layer; _blink_timer = timer_read(); _blink_duration = duration_ms; } @@ -697,7 +697,7 @@ void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms) { void rgblight_unblink_layers(void) { if (_blinked_layer_mask != 0 && timer_elapsed(_blink_timer) > _blink_duration) { for (uint8_t layer = 0; layer < RGBLIGHT_MAX_LAYERS; layer++) { - if ((_blinked_layer_mask & 1 << layer) != 0) { + if ((_blinked_layer_mask & (rgblight_layer_mask_t)1 << layer) != 0) { rgblight_set_layer_state(layer, false); } } -- cgit v1.2.3 From 6e8adeeaacd8cdc83422494e3d525caeded6fe9e Mon Sep 17 00:00:00 2001 From: Joshua Diamond Date: Mon, 11 Jan 2021 02:04:42 -0500 Subject: Refine twinkle to be smoother (use breathing curve) (#11350) * Refine twinkle to be smoother (use breathing curve) * tune more for firmware size * fix bug when v=255 ~ drashna approved ~ --- quantum/rgblight.c | 81 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 33 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index d277029e4b..59b3f40264 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -42,6 +42,9 @@ #ifndef MIN # define MIN(a, b) (((a) < (b)) ? (a) : (b)) #endif +#ifndef MAX +# define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#endif #ifdef RGBLIGHT_SPLIT /* for split keyboard */ @@ -933,7 +936,7 @@ void rgblight_task(void) { # endif # ifdef RGBLIGHT_EFFECT_TWINKLE else if (rgblight_status.base_mode == RGBLIGHT_MODE_TWINKLE) { - interval_time = get_interval_time(&RGBLED_TWINKLE_INTERVALS[delta % 3], 5, 50); + interval_time = get_interval_time(&RGBLED_TWINKLE_INTERVALS[delta % 3], 5, 30); effect_func = (effect_func_t)rgblight_effect_twinkle; } # endif @@ -975,8 +978,7 @@ void rgblight_task(void) { #endif /* RGBLIGHT_USE_TIMER */ -// Effects -#ifdef RGBLIGHT_EFFECT_BREATHING +#if defined(RGBLIGHT_EFFECT_BREATHING) || defined(RGBLIGHT_EFFECT_TWINKLE) # ifndef RGBLIGHT_EFFECT_BREATHE_CENTER # ifndef RGBLIGHT_BREATHE_TABLE_SIZE @@ -985,17 +987,24 @@ void rgblight_task(void) { # include # endif -__attribute__((weak)) const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5}; - -void rgblight_effect_breathing(animation_status_t *anim) { - float val; - +static uint8_t breathe_calc(uint8_t pos) { // http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ # ifdef RGBLIGHT_EFFECT_BREATHE_TABLE - val = pgm_read_byte(&rgblight_effect_breathe_table[anim->pos / table_scale]); + return pgm_read_byte(&rgblight_effect_breathe_table[pos / table_scale]); # else - val = (exp(sin((anim->pos / 255.0) * M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER / M_E) * (RGBLIGHT_EFFECT_BREATHE_MAX / (M_E - 1 / M_E)); + return (exp(sin((pos / 255.0) * M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER / M_E) * (RGBLIGHT_EFFECT_BREATHE_MAX / (M_E - 1 / M_E)); # endif +} + +#endif + +// Effects +#ifdef RGBLIGHT_EFFECT_BREATHING + +__attribute__((weak)) const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5}; + +void rgblight_effect_breathing(animation_status_t *anim) { + uint8_t val = breathe_calc(anim->pos); rgblight_sethsv_noeeprom_old(rgblight_config.hue, rgblight_config.sat, val); anim->pos = (anim->pos + 1); } @@ -1247,48 +1256,54 @@ void rgblight_effect_alternating(animation_status_t *anim) { #endif #ifdef RGBLIGHT_EFFECT_TWINKLE -__attribute__((weak)) const uint8_t RGBLED_TWINKLE_INTERVALS[] PROGMEM = {50, 25, 10}; +__attribute__((weak)) const uint8_t RGBLED_TWINKLE_INTERVALS[] PROGMEM = {30, 15, 5}; typedef struct PACKED { HSV hsv; uint8_t life; - bool up; + uint8_t max_life; } TwinkleState; static TwinkleState led_twinkle_state[RGBLED_NUM]; void rgblight_effect_twinkle(animation_status_t *anim) { - bool random_color = anim->delta / 3; - bool restart = anim->pos == 0; - anim->pos = 1; + const bool random_color = anim->delta / 3; + const bool restart = anim->pos == 0; + anim->pos = 1; + + const uint8_t bottom = breathe_calc(0); + const uint8_t top = breathe_calc(127); + + uint8_t frac(uint8_t n, uint8_t d) { return (uint16_t)255 * n / d; } + uint8_t scale(uint16_t v, uint8_t scale) { return (v * scale) >> 8; } for (uint8_t i = 0; i < rgblight_ranges.effect_num_leds; i++) { TwinkleState *t = &(led_twinkle_state[i]); HSV * c = &(t->hsv); + + if (!random_color) { + c->h = rgblight_config.hue; + c->s = rgblight_config.sat; + } + if (restart) { // Restart - t->life = 0; - t->hsv.v = 0; + t->life = 0; + c->v = 0; } else if (t->life) { // This LED is already on, either brightening or dimming t->life--; - uint8_t on = t->up ? RGBLIGHT_EFFECT_TWINKLE_LIFE - t->life : t->life; - c->v = (uint16_t)rgblight_config.val * on / RGBLIGHT_EFFECT_TWINKLE_LIFE; - if (t->life == 0 && t->up) { - t->up = false; - t->life = RGBLIGHT_EFFECT_TWINKLE_LIFE; - } - if (!random_color) { - c->h = rgblight_config.hue; - c->s = rgblight_config.sat; - } - } else if (rand() < RAND_MAX * RGBLIGHT_EFFECT_TWINKLE_PROBABILITY) { + uint8_t unscaled = frac(breathe_calc(frac(t->life, t->max_life)) - bottom, top - bottom); + c->v = scale(rgblight_config.val, unscaled); + } else if (rand() < scale((uint16_t)RAND_MAX * RGBLIGHT_EFFECT_TWINKLE_PROBABILITY, 127 + rgblight_config.val / 2)) { // This LED is off, but was randomly selected to start brightening - c->h = random_color ? rand() % 0xFF : rgblight_config.hue; - c->s = random_color ? (rand() % (rgblight_config.sat / 2)) + (rgblight_config.sat / 2) : rgblight_config.sat; - c->v = 0; - t->life = RGBLIGHT_EFFECT_TWINKLE_LIFE; - t->up = true; + if (random_color) { + c->h = rand() % 0xFF; + c->s = (rand() % (rgblight_config.sat / 2)) + (rgblight_config.sat / 2); + } + c->v = 0; + t->max_life = MAX(20, MIN(RGBLIGHT_EFFECT_TWINKLE_LIFE, rgblight_config.val)); + t->life = t->max_life; } else { // This LED is off, and was NOT selected to start brightening } -- cgit v1.2.3 From 4d96b85b6f39e89bdcc74853958f91153f27bfc1 Mon Sep 17 00:00:00 2001 From: Joshua Diamond Date: Mon, 11 Jan 2021 03:07:09 -0500 Subject: Lighting Layers should be disabled when suspended (#11442) * Lighting Layers should be disabled when suspended * bugfixes --- quantum/rgblight.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index beeef65689..d856f6d6c8 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -95,6 +95,11 @@ rgblight_config_t rgblight_config; rgblight_status_t rgblight_status = {.timer_enabled = false}; bool is_rgblight_initialized = false; +#ifdef RGBLIGHT_SLEEP +static bool is_suspended; +static bool pre_suspend_enabled; +#endif + #ifdef RGBLIGHT_USE_TIMER animation_status_t animation_status = {}; #endif @@ -708,6 +713,42 @@ void rgblight_unblink_layers(void) { #endif +#ifdef RGBLIGHT_SLEEP + +void rgblight_suspend(void) { + rgblight_timer_disable(); + if (!is_suspended) { + is_suspended = true; + pre_suspend_enabled = rgblight_config.enable; + +# ifdef RGBLIGHT_LAYER_BLINK + // make sure any layer blinks don't come back after suspend + rgblight_status.enabled_layer_mask &= ~_blinked_layer_mask; + _blinked_layer_mask = 0; +# endif + + rgblight_disable_noeeprom(); + } +} + +void rgblight_wakeup(void) { + is_suspended = false; + + if (pre_suspend_enabled) { + rgblight_enable_noeeprom(); + } +# ifdef RGBLIGHT_LAYERS_OVERRIDE_RGB_OFF + // Need this or else the LEDs won't be set + else if (rgblight_status.enabled_layer_mask != 0) { + rgblight_set(); + } +# endif + + rgblight_timer_enable(); +} + +#endif + __attribute__((weak)) void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds) { ws2812_setleds(start_led, num_leds); } #ifndef RGBLIGHT_CUSTOM_DRIVER @@ -729,8 +770,10 @@ void rgblight_set(void) { # ifdef RGBLIGHT_LAYERS if (rgblight_layers != NULL -# ifndef RGBLIGHT_LAYERS_OVERRIDE_RGB_OFF +# if !defined(RGBLIGHT_LAYERS_OVERRIDE_RGB_OFF) && rgblight_config.enable +# elif defined(RGBLIGHT_SLEEP) + && !is_suspended # endif ) { rgblight_layers_write(); -- cgit v1.2.3 From 31c57aab35e6fd49c4c8336f449419afe7630e93 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Mon, 18 Jan 2021 05:12:15 +1100 Subject: `qmk cformat` --- quantum/rgblight.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index b16c3e7c26..44e9eade53 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -843,7 +843,7 @@ void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom) { animation_status.restart = true; } # endif /* RGBLIGHT_SPLIT_NO_ANIMATION_SYNC */ -# endif /* RGBLIGHT_USE_TIMER */ +# endif /* RGBLIGHT_USE_TIMER */ } #endif /* RGBLIGHT_SPLIT */ -- cgit v1.2.3 From bad9592a18494e3f678c2a117a526ca5f2f2280d Mon Sep 17 00:00:00 2001 From: Joshua Diamond Date: Wed, 27 Jan 2021 12:42:03 -0500 Subject: Add rgblight_reload_from_eeprom() (#11411) * Add rgblight_reset_from_eeprom() * reset->reload --- quantum/rgblight.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index d856f6d6c8..ac4ff9bfda 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -234,6 +234,17 @@ void rgblight_init(void) { is_rgblight_initialized = true; } +void rgblight_reload_from_eeprom(void) { + /* Reset back to what we have in eeprom */ + rgblight_config.raw = eeconfig_read_rgblight(); + RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; + rgblight_check_config(); + eeconfig_debug_rgblight(); // display current eeprom values + if (rgblight_config.enable) { + rgblight_mode_noeeprom(rgblight_config.mode); + } +} + uint32_t rgblight_read_dword(void) { return rgblight_config.raw; } void rgblight_update_dword(uint32_t dword) { -- cgit v1.2.3 From 53b96f685d3399e1281747b11a1194178089706c Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 17 Feb 2021 02:51:28 +1100 Subject: RGBLight: Allow configurable default settings (#11912) * RGBLight: Allow configurable default settings * Docs --- quantum/rgblight.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 7d7d015ba0..904c02d6cd 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -84,6 +84,26 @@ static uint8_t mode_base_table[] = { #include "rgblight_modes.h" }; +#if !defined(RGBLIGHT_DEFAULT_MODE) +# define RGBLIGHT_DEFAULT_MODE RGBLIGHT_MODE_STATIC_LIGHT +#endif + +#if !defined(RGBLIGHT_DEFAULT_HUE) +# define RGBLIGHT_DEFAULT_HUE 0 +#endif + +#if !defined(RGBLIGHT_DEFAULT_SAT) +# define RGBLIGHT_DEFAULT_SAT UINT8_MAX +#endif + +#if !defined(RGBLIGHT_DEFAULT_VAL) +# define RGBLIGHT_DEFAULT_VAL RGBLIGHT_LIMIT_VAL +#endif + +#if !defined(RGBLIGHT_DEFAULT_SPD) +# define RGBLIGHT_DEFAULT_SPD 0 +#endif + static inline int is_static_effect(uint8_t mode) { return memchr(static_effect_table, mode, sizeof(static_effect_table)) != NULL; } #ifdef RGBLIGHT_LED_MAP @@ -183,11 +203,11 @@ void eeconfig_update_rgblight_current(void) { eeconfig_update_rgblight(rgblight_ void eeconfig_update_rgblight_default(void) { rgblight_config.enable = 1; - rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT; - rgblight_config.hue = 0; - rgblight_config.sat = UINT8_MAX; - rgblight_config.val = RGBLIGHT_LIMIT_VAL; - rgblight_config.speed = 0; + rgblight_config.mode = RGBLIGHT_DEFAULT_MODE; + rgblight_config.hue = RGBLIGHT_DEFAULT_HUE; + rgblight_config.sat = RGBLIGHT_DEFAULT_SAT; + rgblight_config.val = RGBLIGHT_DEFAULT_VAL; + rgblight_config.speed = RGBLIGHT_DEFAULT_SPD; RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; eeconfig_update_rgblight(rgblight_config.raw); } -- cgit v1.2.3 From b664db3cf32f9e286dbbeb9a44761fcf707caf4d Mon Sep 17 00:00:00 2001 From: Takeshi ISHII <2170248+mtei@users.noreply.github.com> Date: Thu, 25 Mar 2021 21:05:38 +0900 Subject: Removed unused RGBLED_TIMER_TOP and F_CPU macros from quantum/rgblight.[ch] (#12233) --- quantum/rgblight.c | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 904c02d6cd..119d3eab21 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -884,22 +884,6 @@ typedef void (*effect_func_t)(animation_status_t *anim); // Animation timer -- use system timer (AVR Timer0) void rgblight_timer_init(void) { - // OLD!!!! Animation timer -- AVR Timer3 - // static uint8_t rgblight_timer_is_init = 0; - // if (rgblight_timer_is_init) { - // return; - // } - // rgblight_timer_is_init = 1; - // /* Timer 3 setup */ - // TCCR3B = _BV(WGM32) // CTC mode OCR3A as TOP - // | _BV(CS30); // Clock selelct: clk/1 - // /* Set TOP value */ - // uint8_t sreg = SREG; - // cli(); - // OCR3AH = (RGBLED_TIMER_TOP >> 8) & 0xff; - // OCR3AL = RGBLED_TIMER_TOP & 0xff; - // SREG = sreg; - rgblight_status.timer_enabled = false; RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE; } -- cgit v1.2.3