Skip to content

Commit

Permalink
Unify RGB and RGBW commands (qmk#7297)
Browse files Browse the repository at this point in the history
* Fix unicode in comments

Co-Authored-By: fauxpark <[email protected]>

* 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
  • Loading branch information
drashna authored and zvecr committed Nov 9, 2019
1 parent 78205e6 commit 60e4921
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 41 deletions.
4 changes: 2 additions & 2 deletions docs/config_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 3 additions & 8 deletions drivers/arm/ws2812.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 1 addition & 2 deletions drivers/arm/ws2812.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
22 changes: 7 additions & 15 deletions drivers/avr/ws2812.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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
}

Expand Down
3 changes: 1 addition & 2 deletions drivers/avr/ws2812.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
12 changes: 4 additions & 8 deletions drivers/avr/ws2812_i2c.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
3 changes: 3 additions & 0 deletions quantum/rgb_matrix_drivers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
28 changes: 24 additions & 4 deletions quantum/rgblight.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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++) {
Expand All @@ -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();
Expand Down

0 comments on commit 60e4921

Please sign in to comment.