From 60e4921378d879eed110f801328e9642f35fa1e9 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Sat, 9 Nov 2019 07:51:39 -0800 Subject: [PATCH] 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 --- docs/config_options.md | 4 ++-- drivers/arm/ws2812.c | 11 +++-------- drivers/arm/ws2812.h | 3 +-- drivers/avr/ws2812.c | 22 +++++++--------------- drivers/avr/ws2812.h | 3 +-- drivers/avr/ws2812_i2c.c | 12 ++++-------- quantum/rgb_matrix_drivers.c | 3 +++ quantum/rgblight.c | 28 ++++++++++++++++++++++++---- 8 files changed, 45 insertions(+), 41 deletions(-) diff --git a/docs/config_options.md b/docs/config_options.md index c44a47178..0cf3fb78a 100644 --- a/docs/config_options.md +++ b/docs/config_options.md @@ -196,8 +196,8 @@ If you define these options you will enable the associated feature, which may in * units to step when in/decreasing saturation * `#define RGBLIGHT_VAL_STEP 12` * units to step when in/decreasing value (brightness) -* `#define RGBW_BB_TWI` - * bit-bangs TWI to EZ RGBW LEDs (only required for Ergodox EZ) +* `#define RGBW` + * Enables RGBW LED support ## Mouse Key Options diff --git a/drivers/arm/ws2812.c b/drivers/arm/ws2812.c index b076eff33..fa702fca9 100644 --- a/drivers/arm/ws2812.c +++ b/drivers/arm/ws2812.c @@ -84,17 +84,12 @@ void ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) { sendByte(ledarray[i].g); sendByte(ledarray[i].r); sendByte(ledarray[i].b); +#ifdef RGBW + sendByte(ledarray[i].w); +#endif } wait_ns(RES); chSysUnlock(); } - -// Setleds for SK6812RGBW -void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t leds) { -// not supported - for now error out if its enabled -#ifdef RGBW -# error "RGBW not supported" -#endif -} diff --git a/drivers/arm/ws2812.h b/drivers/arm/ws2812.h index bf5c9fd0f..41c22a00b 100644 --- a/drivers/arm/ws2812.h +++ b/drivers/arm/ws2812.h @@ -11,7 +11,6 @@ * The functions will perform the following actions: * - Set the data-out pin as output * - Send out the LED data - * - Wait 50�s to reset the LEDs + * - Wait 50us to reset the LEDs */ void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds); -void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t number_of_leds); diff --git a/drivers/avr/ws2812.c b/drivers/avr/ws2812.c index 5c733c4ab..dc7e8d48a 100644 --- a/drivers/avr/ws2812.c +++ b/drivers/avr/ws2812.c @@ -36,7 +36,6 @@ void ws2812_sendarray(uint8_t *array, uint16_t length); void ws2812_sendarray_mask(uint8_t *array, uint16_t length, uint8_t pinmask); - #ifdef RGBW_BB_TWI // Port for the I2C @@ -146,16 +145,6 @@ void inline ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) { } void inline ws2812_setleds_pin(LED_TYPE *ledarray, uint16_t leds, uint8_t pinmask) { - // ws2812_DDRREG |= pinmask; // Enable DDR - // new universal format (DDR) - _SFR_IO8((RGB_DI_PIN >> 4) + 1) |= pinmask; - - ws2812_sendarray_mask((uint8_t *)ledarray, leds + leds + leds, pinmask); - _delay_us(50); -} - -// Setleds for SK6812RGBW -void inline ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t leds) { #ifdef RGBW_BB_TWI uint8_t sreg_prev, twcr_prev; sreg_prev = SREG; @@ -176,15 +165,18 @@ void inline ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t leds) { SREG = sreg_prev; TWCR = twcr_prev; #endif - - // ws2812_DDRREG |= _BV(ws2812_pin); // Enable DDR + // ws2812_DDRREG |= pinmask; // Enable DDR // new universal format (DDR) - _SFR_IO8((RGB_DI_PIN >> 4) + 1) |= _BV(RGB_DI_PIN & 0xF); + _SFR_IO8((RGB_DI_PIN >> 4) + 1) |= pinmask; - ws2812_sendarray_mask((uint8_t *)ledarray, leds << 2, _BV(RGB_DI_PIN & 0xF)); + ws2812_sendarray_mask((uint8_t *)ledarray, leds * sizeof(LED_TYPE), pinmask); #ifndef RGBW_BB_TWI +# ifdef RGBW _delay_us(80); +# else + _delay_us(50); +# endif #endif } diff --git a/drivers/avr/ws2812.h b/drivers/avr/ws2812.h index 9652b94bb..b869fb28c 100644 --- a/drivers/avr/ws2812.h +++ b/drivers/avr/ws2812.h @@ -34,8 +34,7 @@ * The functions will perform the following actions: * - Set the data-out pin as output * - Send out the LED data - * - Wait 50�s to reset the LEDs + * - Wait 50us to reset the LEDs */ void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds); void ws2812_setleds_pin(LED_TYPE *ledarray, uint16_t number_of_leds, uint8_t pinmask); -void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t number_of_leds); diff --git a/drivers/avr/ws2812_i2c.c b/drivers/avr/ws2812_i2c.c index 8525a026c..1c332e24b 100644 --- a/drivers/avr/ws2812_i2c.c +++ b/drivers/avr/ws2812_i2c.c @@ -1,6 +1,10 @@ #include "ws2812.h" #include "i2c_master.h" +#ifdef RGBW +# error "RGBW not supported" +#endif + #ifndef WS2812_ADDRESS # define WS2812_ADDRESS 0xb0 #endif @@ -21,11 +25,3 @@ void ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) { i2c_transmit(WS2812_ADDRESS, (uint8_t *)ledarray, sizeof(LED_TYPE) * leds, WS2812_TIMEOUT); } - -// Setleds for SK6812RGBW -void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t leds) { -// not supported - for now error out if its enabled -#ifdef RGBW -# error "RGBW not supported" -#endif -} diff --git a/quantum/rgb_matrix_drivers.c b/quantum/rgb_matrix_drivers.c index 503f97014..9729a3064 100644 --- a/quantum/rgb_matrix_drivers.c +++ b/quantum/rgb_matrix_drivers.c @@ -112,6 +112,9 @@ static inline void setled(int i, 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 } static void setled_all(uint8_t r, uint8_t g, uint8_t b) { diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 1c197827f..a4cbe513e 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();