aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/ws2812_driver.md9
-rw-r--r--drivers/chibios/ws2812.c4
-rw-r--r--drivers/chibios/ws2812_pwm.c37
-rw-r--r--drivers/chibios/ws2812_spi.c4
-rw-r--r--quantum/color.h9
5 files changed, 59 insertions, 4 deletions
diff --git a/docs/ws2812_driver.md b/docs/ws2812_driver.md
index da5db01db..cca6827ec 100644
--- a/docs/ws2812_driver.md
+++ b/docs/ws2812_driver.md
@@ -33,10 +33,11 @@ The default setting is 280 µs, which should work for most cases, but this can b
33Some variants of the WS2812 may have their color components in a different physical or logical order. For example, the WS2812B-2020 has physically swapped red and green LEDs, which causes the wrong color to be displayed, because the default order of the bytes sent over the wire is defined as GRB. 33Some variants of the WS2812 may have their color components in a different physical or logical order. For example, the WS2812B-2020 has physically swapped red and green LEDs, which causes the wrong color to be displayed, because the default order of the bytes sent over the wire is defined as GRB.
34In this case, you can change the byte order by defining `WS2812_BYTE_ORDER` as one of the following values: 34In this case, you can change the byte order by defining `WS2812_BYTE_ORDER` as one of the following values:
35 35
36| Byte order | Known devices | 36|Byte order |Known devices |
37|-----------------------------------|-------------------------------| 37|---------------------------------|-----------------------------|
38| `WS2812_BYTE_ORDER_GRB` (default) | Most WS2812's, SK6812, SK6805 | 38|`WS2812_BYTE_ORDER_GRB` (default)|Most WS2812's, SK6812, SK6805|
39| `WS2812_BYTE_ORDER_RGB` | WS2812B-2020 | 39|`WS2812_BYTE_ORDER_RGB` |WS2812B-2020 |
40|`WS2812_BYTE_ORDER_BGR` |TM1812 |
40 41
41 42
42### Bitbang 43### Bitbang
diff --git a/drivers/chibios/ws2812.c b/drivers/chibios/ws2812.c
index 59ed90374..0d12e2fb7 100644
--- a/drivers/chibios/ws2812.c
+++ b/drivers/chibios/ws2812.c
@@ -97,6 +97,10 @@ void ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) {
97 sendByte(ledarray[i].r); 97 sendByte(ledarray[i].r);
98 sendByte(ledarray[i].g); 98 sendByte(ledarray[i].g);
99 sendByte(ledarray[i].b); 99 sendByte(ledarray[i].b);
100#elif (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_BGR)
101 sendByte(ledarray[i].b);
102 sendByte(ledarray[i].g);
103 sendByte(ledarray[i].r);
100#endif 104#endif
101 105
102#ifdef RGBW 106#ifdef RGBW
diff --git a/drivers/chibios/ws2812_pwm.c b/drivers/chibios/ws2812_pwm.c
index 3af922c06..140120d48 100644
--- a/drivers/chibios/ws2812_pwm.c
+++ b/drivers/chibios/ws2812_pwm.c
@@ -180,6 +180,43 @@
180 * @return The bit index 180 * @return The bit index
181 */ 181 */
182# define WS2812_BLUE_BIT(led, bit) WS2812_BIT((led), 2, (bit)) 182# define WS2812_BLUE_BIT(led, bit) WS2812_BIT((led), 2, (bit))
183
184#elif (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_BGR)
185/**
186 * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given red bit
187 *
188 * @note The red byte is the middle byte in the color packet
189 *
190 * @param[in] led: The led index [0, @ref RGBLED_NUM)
191 * @param[in] bit: The bit number [0, 7]
192 *
193 * @return The bit index
194 */
195# define WS2812_RED_BIT(led, bit) WS2812_BIT((led), 2, (bit))
196
197/**
198 * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given green bit
199 *
200 * @note The red byte is the first byte in the color packet
201 *
202 * @param[in] led: The led index [0, @ref RGBLED_NUM)
203 * @param[in] bit: The bit number [0, 7]
204 *
205 * @return The bit index
206 */
207# define WS2812_GREEN_BIT(led, bit) WS2812_BIT((led), 1, (bit))
208
209/**
210 * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given blue bit
211 *
212 * @note The red byte is the last byte in the color packet
213 *
214 * @param[in] led: The led index [0, @ref RGBLED_NUM)
215 * @param[in] bit: The bit index [0, 7]
216 *
217 * @return The bit index
218 */
219# define WS2812_BLUE_BIT(led, bit) WS2812_BIT((led), 0, (bit))
183#endif 220#endif
184 221
185/* --- PRIVATE VARIABLES ---------------------------------------------------- */ 222/* --- PRIVATE VARIABLES ---------------------------------------------------- */
diff --git a/drivers/chibios/ws2812_spi.c b/drivers/chibios/ws2812_spi.c
index a93342436..89df2987b 100644
--- a/drivers/chibios/ws2812_spi.c
+++ b/drivers/chibios/ws2812_spi.c
@@ -70,6 +70,10 @@ static void set_led_color_rgb(LED_TYPE color, int pos) {
70 for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + j] = get_protocol_eq(color.r, j); 70 for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + j] = get_protocol_eq(color.r, j);
71 for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + BYTES_FOR_LED_BYTE + j] = get_protocol_eq(color.g, j); 71 for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + BYTES_FOR_LED_BYTE + j] = get_protocol_eq(color.g, j);
72 for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + BYTES_FOR_LED_BYTE * 2 + j] = get_protocol_eq(color.b, j); 72 for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + BYTES_FOR_LED_BYTE * 2 + j] = get_protocol_eq(color.b, j);
73#elif (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_BGR)
74 for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + j] = get_protocol_eq(color.b, j);
75 for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + BYTES_FOR_LED_BYTE + j] = get_protocol_eq(color.g, j);
76 for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + BYTES_FOR_LED_BYTE * 2 + j] = get_protocol_eq(color.r, j);
73#endif 77#endif
74} 78}
75 79
diff --git a/quantum/color.h b/quantum/color.h
index 7448168b3..4783f6839 100644
--- a/quantum/color.h
+++ b/quantum/color.h
@@ -37,6 +37,7 @@
37 37
38#define WS2812_BYTE_ORDER_RGB 0 38#define WS2812_BYTE_ORDER_RGB 0
39#define WS2812_BYTE_ORDER_GRB 1 39#define WS2812_BYTE_ORDER_GRB 1
40#define WS2812_BYTE_ORDER_BGR 2
40 41
41#ifndef WS2812_BYTE_ORDER 42#ifndef WS2812_BYTE_ORDER
42# define WS2812_BYTE_ORDER WS2812_BYTE_ORDER_GRB 43# define WS2812_BYTE_ORDER WS2812_BYTE_ORDER_GRB
@@ -51,6 +52,10 @@ typedef struct PACKED {
51 uint8_t r; 52 uint8_t r;
52 uint8_t g; 53 uint8_t g;
53 uint8_t b; 54 uint8_t b;
55#elif (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_BGR)
56 uint8_t b;
57 uint8_t g;
58 uint8_t r;
54#endif 59#endif
55} cRGB; 60} cRGB;
56 61
@@ -66,6 +71,10 @@ typedef struct PACKED {
66 uint8_t r; 71 uint8_t r;
67 uint8_t g; 72 uint8_t g;
68 uint8_t b; 73 uint8_t b;
74#elif (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_BGR)
75 uint8_t b;
76 uint8_t g;
77 uint8_t r;
69#endif 78#endif
70 uint8_t w; 79 uint8_t w;
71} cRGBW; 80} cRGBW;