aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2019-11-09 07:51:39 -0800
committerJoel Challis <git@zvecr.com>2019-11-09 15:51:39 +0000
commit60e4921378d879eed110f801328e9642f35fa1e9 (patch)
tree9bb36017ba58e7aedbcfee9db0bba1a3bc466359
parent78205e64a7053746b1491c0d39dbb300a55f3248 (diff)
downloadqmk_firmware-60e4921378d879eed110f801328e9642f35fa1e9.tar.gz
qmk_firmware-60e4921378d879eed110f801328e9642f35fa1e9.zip
Unify RGB and RGBW commands (#7297)
* Fix unicode in comments Co-Authored-By: fauxpark <fauxpark@gmail.com> * 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
-rw-r--r--docs/config_options.md4
-rw-r--r--drivers/arm/ws2812.c11
-rw-r--r--drivers/arm/ws2812.h3
-rw-r--r--drivers/avr/ws2812.c22
-rw-r--r--drivers/avr/ws2812.h3
-rw-r--r--drivers/avr/ws2812_i2c.c12
-rw-r--r--quantum/rgb_matrix_drivers.c3
-rw-r--r--quantum/rgblight.c28
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
196 * units to step when in/decreasing saturation 196 * units to step when in/decreasing saturation
197* `#define RGBLIGHT_VAL_STEP 12` 197* `#define RGBLIGHT_VAL_STEP 12`
198 * units to step when in/decreasing value (brightness) 198 * units to step when in/decreasing value (brightness)
199* `#define RGBW_BB_TWI` 199* `#define RGBW`
200 * bit-bangs TWI to EZ RGBW LEDs (only required for Ergodox EZ) 200 * Enables RGBW LED support
201 201
202## Mouse Key Options 202## Mouse Key Options
203 203
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) {
84 sendByte(ledarray[i].g); 84 sendByte(ledarray[i].g);
85 sendByte(ledarray[i].r); 85 sendByte(ledarray[i].r);
86 sendByte(ledarray[i].b); 86 sendByte(ledarray[i].b);
87#ifdef RGBW
88 sendByte(ledarray[i].w);
89#endif
87 } 90 }
88 91
89 wait_ns(RES); 92 wait_ns(RES);
90 93
91 chSysUnlock(); 94 chSysUnlock();
92} 95}
93
94// Setleds for SK6812RGBW
95void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t leds) {
96// not supported - for now error out if its enabled
97#ifdef RGBW
98# error "RGBW not supported"
99#endif
100}
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 @@
11 * The functions will perform the following actions: 11 * The functions will perform the following actions:
12 * - Set the data-out pin as output 12 * - Set the data-out pin as output
13 * - Send out the LED data 13 * - Send out the LED data
14 * - Wait 50s to reset the LEDs 14 * - Wait 50us to reset the LEDs
15 */ 15 */
16void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds); 16void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds);
17void 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 @@
36void ws2812_sendarray(uint8_t *array, uint16_t length); 36void ws2812_sendarray(uint8_t *array, uint16_t length);
37void ws2812_sendarray_mask(uint8_t *array, uint16_t length, uint8_t pinmask); 37void ws2812_sendarray_mask(uint8_t *array, uint16_t length, uint8_t pinmask);
38 38
39
40#ifdef RGBW_BB_TWI 39#ifdef RGBW_BB_TWI
41 40
42// Port for the I2C 41// Port for the I2C
@@ -146,16 +145,6 @@ void inline ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) {
146} 145}
147 146
148void inline ws2812_setleds_pin(LED_TYPE *ledarray, uint16_t leds, uint8_t pinmask) { 147void inline ws2812_setleds_pin(LED_TYPE *ledarray, uint16_t leds, uint8_t pinmask) {
149 // ws2812_DDRREG |= pinmask; // Enable DDR
150 // new universal format (DDR)
151 _SFR_IO8((RGB_DI_PIN >> 4) + 1) |= pinmask;
152
153 ws2812_sendarray_mask((uint8_t *)ledarray, leds + leds + leds, pinmask);
154 _delay_us(50);
155}
156
157// Setleds for SK6812RGBW
158void inline ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t leds) {
159#ifdef RGBW_BB_TWI 148#ifdef RGBW_BB_TWI
160 uint8_t sreg_prev, twcr_prev; 149 uint8_t sreg_prev, twcr_prev;
161 sreg_prev = SREG; 150 sreg_prev = SREG;
@@ -176,15 +165,18 @@ void inline ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t leds) {
176 SREG = sreg_prev; 165 SREG = sreg_prev;
177 TWCR = twcr_prev; 166 TWCR = twcr_prev;
178#endif 167#endif
179 168 // ws2812_DDRREG |= pinmask; // Enable DDR
180 // ws2812_DDRREG |= _BV(ws2812_pin); // Enable DDR
181 // new universal format (DDR) 169 // new universal format (DDR)
182 _SFR_IO8((RGB_DI_PIN >> 4) + 1) |= _BV(RGB_DI_PIN & 0xF); 170 _SFR_IO8((RGB_DI_PIN >> 4) + 1) |= pinmask;
183 171
184 ws2812_sendarray_mask((uint8_t *)ledarray, leds << 2, _BV(RGB_DI_PIN & 0xF)); 172 ws2812_sendarray_mask((uint8_t *)ledarray, leds * sizeof(LED_TYPE), pinmask);
185 173
186#ifndef RGBW_BB_TWI 174#ifndef RGBW_BB_TWI
175# ifdef RGBW
187 _delay_us(80); 176 _delay_us(80);
177# else
178 _delay_us(50);
179# endif
188#endif 180#endif
189} 181}
190 182
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 @@
34 * The functions will perform the following actions: 34 * The functions will perform the following actions:
35 * - Set the data-out pin as output 35 * - Set the data-out pin as output
36 * - Send out the LED data 36 * - Send out the LED data
37 * - Wait 50s to reset the LEDs 37 * - Wait 50us to reset the LEDs
38 */ 38 */
39void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds); 39void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds);
40void ws2812_setleds_pin(LED_TYPE *ledarray, uint16_t number_of_leds, uint8_t pinmask); 40void ws2812_setleds_pin(LED_TYPE *ledarray, uint16_t number_of_leds, uint8_t pinmask);
41void 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 @@
1#include "ws2812.h" 1#include "ws2812.h"
2#include "i2c_master.h" 2#include "i2c_master.h"
3 3
4#ifdef RGBW
5# error "RGBW not supported"
6#endif
7
4#ifndef WS2812_ADDRESS 8#ifndef WS2812_ADDRESS
5# define WS2812_ADDRESS 0xb0 9# define WS2812_ADDRESS 0xb0
6#endif 10#endif
@@ -21,11 +25,3 @@ void ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) {
21 25
22 i2c_transmit(WS2812_ADDRESS, (uint8_t *)ledarray, sizeof(LED_TYPE) * leds, WS2812_TIMEOUT); 26 i2c_transmit(WS2812_ADDRESS, (uint8_t *)ledarray, sizeof(LED_TYPE) * leds, WS2812_TIMEOUT);
23} 27}
24
25// Setleds for SK6812RGBW
26void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t leds) {
27// not supported - for now error out if its enabled
28#ifdef RGBW
29# error "RGBW not supported"
30#endif
31}
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) {
112 led[i].r = r; 112 led[i].r = r;
113 led[i].g = g; 113 led[i].g = g;
114 led[i].b = b; 114 led[i].b = b;
115# ifdef RGBW
116 led[i].w = 0;
117# endif
115} 118}
116 119
117static void setled_all(uint8_t r, uint8_t g, uint8_t b) { 120static 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) {
126 (*led1).r = r; 126 (*led1).r = r;
127 (*led1).g = g; 127 (*led1).g = g;
128 (*led1).b = b; 128 (*led1).b = b;
129#ifdef RGBW
130 (*led1).w = 0;
131#endif
129} 132}
130 133
131void rgblight_check_config(void) { 134void rgblight_check_config(void) {
@@ -514,6 +517,9 @@ void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b) {
514 led[i].r = r; 517 led[i].r = r;
515 led[i].g = g; 518 led[i].g = g;
516 led[i].b = b; 519 led[i].b = b;
520#ifdef RGBW
521 led[i].w = 0;
522#endif
517 } 523 }
518 rgblight_set(); 524 rgblight_set();
519} 525}
@@ -526,6 +532,9 @@ void rgblight_setrgb_at(uint8_t r, uint8_t g, uint8_t b, uint8_t index) {
526 led[index].r = r; 532 led[index].r = r;
527 led[index].g = g; 533 led[index].g = g;
528 led[index].b = b; 534 led[index].b = b;
535#ifdef RGBW
536 led[index].w = 0;
537#endif
529 rgblight_set(); 538 rgblight_set();
530} 539}
531 540
@@ -560,6 +569,9 @@ void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8
560 led[i].r = r; 569 led[i].r = r;
561 led[i].g = g; 570 led[i].g = g;
562 led[i].b = b; 571 led[i].b = b;
572#ifdef RGBW
573 led[i].w = 0;
574#endif
563 } 575 }
564 rgblight_set(); 576 rgblight_set();
565 wait_ms(1); 577 wait_ms(1);
@@ -595,6 +607,9 @@ void rgblight_set(void) {
595 led[i].r = 0; 607 led[i].r = 0;
596 led[i].g = 0; 608 led[i].g = 0;
597 led[i].b = 0; 609 led[i].b = 0;
610# ifdef RGBW
611 led[i].w = 0;
612# endif
598 } 613 }
599 } 614 }
600# ifdef RGBLIGHT_LED_MAP 615# ifdef RGBLIGHT_LED_MAP
@@ -606,11 +621,7 @@ void rgblight_set(void) {
606# else 621# else
607 start_led = led + clipping_start_pos; 622 start_led = led + clipping_start_pos;
608# endif 623# endif
609# ifdef RGBW
610 ws2812_setleds_rgbw(start_led, num_leds);
611# else
612 ws2812_setleds(start_led, num_leds); 624 ws2812_setleds(start_led, num_leds);
613# endif
614} 625}
615#endif 626#endif
616 627
@@ -908,6 +919,9 @@ void rgblight_effect_snake(animation_status_t *anim) {
908 ledp->r = 0; 919 ledp->r = 0;
909 ledp->g = 0; 920 ledp->g = 0;
910 ledp->b = 0; 921 ledp->b = 0;
922# ifdef RGBW
923 ledp->w = 0;
924# endif
911 for (j = 0; j < RGBLIGHT_EFFECT_SNAKE_LENGTH; j++) { 925 for (j = 0; j < RGBLIGHT_EFFECT_SNAKE_LENGTH; j++) {
912 k = pos + j * increment; 926 k = pos + j * increment;
913 if (k > RGBLED_NUM) { 927 if (k > RGBLED_NUM) {
@@ -965,6 +979,9 @@ void rgblight_effect_knight(animation_status_t *anim) {
965 led[i].r = 0; 979 led[i].r = 0;
966 led[i].g = 0; 980 led[i].g = 0;
967 led[i].b = 0; 981 led[i].b = 0;
982# ifdef RGBW
983 led[i].w = 0;
984# endif
968 } 985 }
969 // Determine which LEDs should be lit up 986 // Determine which LEDs should be lit up
970 for (i = 0; i < RGBLIGHT_EFFECT_KNIGHT_LED_NUM; i++) { 987 for (i = 0; i < RGBLIGHT_EFFECT_KNIGHT_LED_NUM; i++) {
@@ -976,6 +993,9 @@ void rgblight_effect_knight(animation_status_t *anim) {
976 led[cur].r = 0; 993 led[cur].r = 0;
977 led[cur].g = 0; 994 led[cur].g = 0;
978 led[cur].b = 0; 995 led[cur].b = 0;
996# ifdef RGBW
997 led[cur].w = 0;
998# endif
979 } 999 }
980 } 1000 }
981 rgblight_set(); 1001 rgblight_set();