diff options
Diffstat (limited to 'drivers/chibios')
-rw-r--r-- | drivers/chibios/ws2812.c | 7 | ||||
-rw-r--r-- | drivers/chibios/ws2812_pwm.c | 45 | ||||
-rw-r--r-- | drivers/chibios/ws2812_spi.c | 6 |
3 files changed, 55 insertions, 3 deletions
diff --git a/drivers/chibios/ws2812.c b/drivers/chibios/ws2812.c index 0440cac75..504fb4f07 100644 --- a/drivers/chibios/ws2812.c +++ b/drivers/chibios/ws2812.c | |||
@@ -89,9 +89,16 @@ void ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) { | |||
89 | 89 | ||
90 | for (uint8_t i = 0; i < leds; i++) { | 90 | for (uint8_t i = 0; i < leds; i++) { |
91 | // WS2812 protocol dictates grb order | 91 | // WS2812 protocol dictates grb order |
92 | #if (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_GRB) | ||
92 | sendByte(ledarray[i].g); | 93 | sendByte(ledarray[i].g); |
93 | sendByte(ledarray[i].r); | 94 | sendByte(ledarray[i].r); |
94 | sendByte(ledarray[i].b); | 95 | sendByte(ledarray[i].b); |
96 | #elif (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_RGB) | ||
97 | sendByte(ledarray[i].r); | ||
98 | sendByte(ledarray[i].g); | ||
99 | sendByte(ledarray[i].b); | ||
100 | #endif | ||
101 | |||
95 | #ifdef RGBW | 102 | #ifdef RGBW |
96 | sendByte(ledarray[i].w); | 103 | sendByte(ledarray[i].w); |
97 | #endif | 104 | #endif |
diff --git a/drivers/chibios/ws2812_pwm.c b/drivers/chibios/ws2812_pwm.c index bfb44ce4a..14be0a9ed 100644 --- a/drivers/chibios/ws2812_pwm.c +++ b/drivers/chibios/ws2812_pwm.c | |||
@@ -107,6 +107,7 @@ | |||
107 | */ | 107 | */ |
108 | #define WS2812_BIT(led, byte, bit) (24 * (led) + 8 * (byte) + (7 - (bit))) | 108 | #define WS2812_BIT(led, byte, bit) (24 * (led) + 8 * (byte) + (7 - (bit))) |
109 | 109 | ||
110 | #if (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_GRB) | ||
110 | /** | 111 | /** |
111 | * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given red bit | 112 | * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given red bit |
112 | * | 113 | * |
@@ -117,7 +118,7 @@ | |||
117 | * | 118 | * |
118 | * @return The bit index | 119 | * @return The bit index |
119 | */ | 120 | */ |
120 | #define WS2812_RED_BIT(led, bit) WS2812_BIT((led), 1, (bit)) | 121 | # define WS2812_RED_BIT(led, bit) WS2812_BIT((led), 1, (bit)) |
121 | 122 | ||
122 | /** | 123 | /** |
123 | * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given green bit | 124 | * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given green bit |
@@ -129,7 +130,7 @@ | |||
129 | * | 130 | * |
130 | * @return The bit index | 131 | * @return The bit index |
131 | */ | 132 | */ |
132 | #define WS2812_GREEN_BIT(led, bit) WS2812_BIT((led), 0, (bit)) | 133 | # define WS2812_GREEN_BIT(led, bit) WS2812_BIT((led), 0, (bit)) |
133 | 134 | ||
134 | /** | 135 | /** |
135 | * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given blue bit | 136 | * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given blue bit |
@@ -141,7 +142,45 @@ | |||
141 | * | 142 | * |
142 | * @return The bit index | 143 | * @return The bit index |
143 | */ | 144 | */ |
144 | #define WS2812_BLUE_BIT(led, bit) WS2812_BIT((led), 2, (bit)) | 145 | # define WS2812_BLUE_BIT(led, bit) WS2812_BIT((led), 2, (bit)) |
146 | |||
147 | #elif (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_RGB) | ||
148 | /** | ||
149 | * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given red bit | ||
150 | * | ||
151 | * @note The red byte is the middle byte in the color packet | ||
152 | * | ||
153 | * @param[in] led: The led index [0, @ref RGBLED_NUM) | ||
154 | * @param[in] bit: The bit number [0, 7] | ||
155 | * | ||
156 | * @return The bit index | ||
157 | */ | ||
158 | # define WS2812_RED_BIT(led, bit) WS2812_BIT((led), 0, (bit)) | ||
159 | |||
160 | /** | ||
161 | * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given green bit | ||
162 | * | ||
163 | * @note The red byte is the first byte in the color packet | ||
164 | * | ||
165 | * @param[in] led: The led index [0, @ref RGBLED_NUM) | ||
166 | * @param[in] bit: The bit number [0, 7] | ||
167 | * | ||
168 | * @return The bit index | ||
169 | */ | ||
170 | # define WS2812_GREEN_BIT(led, bit) WS2812_BIT((led), 1, (bit)) | ||
171 | |||
172 | /** | ||
173 | * @brief Determine the index in @ref ws2812_frame_buffer "the frame buffer" of a given blue bit | ||
174 | * | ||
175 | * @note The red byte is the last byte in the color packet | ||
176 | * | ||
177 | * @param[in] led: The led index [0, @ref RGBLED_NUM) | ||
178 | * @param[in] bit: The bit index [0, 7] | ||
179 | * | ||
180 | * @return The bit index | ||
181 | */ | ||
182 | # define WS2812_BLUE_BIT(led, bit) WS2812_BIT((led), 2, (bit)) | ||
183 | #endif | ||
145 | 184 | ||
146 | /* --- PRIVATE VARIABLES ---------------------------------------------------- */ | 185 | /* --- PRIVATE VARIABLES ---------------------------------------------------- */ |
147 | 186 | ||
diff --git a/drivers/chibios/ws2812_spi.c b/drivers/chibios/ws2812_spi.c index 7a1d2f05d..1dec1f516 100644 --- a/drivers/chibios/ws2812_spi.c +++ b/drivers/chibios/ws2812_spi.c | |||
@@ -62,9 +62,15 @@ static uint8_t get_protocol_eq(uint8_t data, int pos) { | |||
62 | static void set_led_color_rgb(LED_TYPE color, int pos) { | 62 | static void set_led_color_rgb(LED_TYPE color, int pos) { |
63 | uint8_t* tx_start = &txbuf[PREAMBLE_SIZE]; | 63 | uint8_t* tx_start = &txbuf[PREAMBLE_SIZE]; |
64 | 64 | ||
65 | #if (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_GRB) | ||
65 | for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + j] = get_protocol_eq(color.g, j); | 66 | for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + j] = get_protocol_eq(color.g, j); |
66 | for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + BYTES_FOR_LED_BYTE + j] = get_protocol_eq(color.r, j); | 67 | for (int j = 0; j < 4; j++) tx_start[BYTES_FOR_LED * pos + BYTES_FOR_LED_BYTE + j] = get_protocol_eq(color.r, j); |
67 | 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); | 68 | 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); |
69 | #elif (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_RGB) | ||
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); | ||
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 | #endif | ||
68 | } | 74 | } |
69 | 75 | ||
70 | void ws2812_init(void) { | 76 | void ws2812_init(void) { |