diff --git a/lib/led_ws2812b.c b/lib/led_ws2812b.c
index c43ecb1..4e25e64 100644
--- a/lib/led_ws2812b.c
+++ b/lib/led_ws2812b.c
@@ -12,10 +12,10 @@
* along with this program. If not, see .
*
*/
-/** library to drive a WS2812B LED chain (code)
- * @file led_ws2812b.c
+/** library to drive a WS2812B LED chain
+ * @file
* @author King Kévin
- * @date 2016-2017
+ * @date 2016-2020
* @note peripherals used: SPI @ref led_ws2812b_spi, timer @ref led_ws2812b_timer, DMA (for SPI MISO)
*/
@@ -59,13 +59,13 @@
*/
#define LED_WS2812B_SPI_TEMPLATE 0x924924
-uint8_t led_ws2812b_data[LED_WS2812B_LEDS*3*3+40*3/8+1] = {0}; /**< data encoded to be shifted out by SPI for the WS2812B, plus the 50us reset (~40 data bits) */
+uint8_t led_ws2812b_data[LED_WS2812B_LEDS * 3 * 3 + 40 * 3 / 8 + 1] = {0}; /**< data encoded to be shifted out by SPI for the WS2812B, plus the 50us reset (~40 data bits) */
static volatile bool transmit_flag = false; /**< flag set in software when transmission started, clear by interrupt when transmission completed */
void led_ws2812b_set_rgb(uint16_t led, uint8_t red, uint8_t green, uint8_t blue)
{
// verify the led exists
- if (led>=LED_WS2812B_LEDS) {
+ if (led >= LED_WS2812B_LEDS) {
return;
}
// wait for transmission to complete before changing the color
@@ -75,14 +75,14 @@ void led_ws2812b_set_rgb(uint16_t led, uint8_t red, uint8_t green, uint8_t blue)
const uint8_t colors[] = {green, red, blue}; // color order for the WS2812B
const uint8_t pattern_bit[] = {0x02, 0x10, 0x80, 0x04, 0x20, 0x01, 0x08, 0x40}; // which bit to change in the pattern
- const uint8_t pattern_byte[] = {2,2,2,1,1,0,0,0}; // in which byte in the pattern to write the pattern bit
- for (uint8_t color=0; color>16);
- led_ws2812b_data[i*3+1] = (uint8_t)(LED_WS2812B_SPI_TEMPLATE>>8);
- led_ws2812b_data[i*3+2] = (uint8_t)(LED_WS2812B_SPI_TEMPLATE>>0);
+ for (uint16_t i = 0; i < LED_WS2812B_LEDS * 3; i++) {
+ led_ws2812b_data[i * 3 + 0] = (uint8_t)(LED_WS2812B_SPI_TEMPLATE >> 16);
+ led_ws2812b_data[i * 3 + 1] = (uint8_t)(LED_WS2812B_SPI_TEMPLATE >> 8);
+ led_ws2812b_data[i * 3 + 2] = (uint8_t)(LED_WS2812B_SPI_TEMPLATE >> 0);
}
// fill remaining with with 0 to encode the reset code
- for (uint16_t i=LED_WS2812B_LEDS*3*3; i.
*
*/
-/** library to drive a WS2812B LED chain (API)
- * @file led_ws2812b.h
+/** library to drive a WS2812B LED chain
+ * @file
* @author King Kévin
- * @date 2016-2017
+ * @date 2016-2020
* @note peripherals used: SPI @ref led_ws2812b_spi, timer @ref led_ws2812b_timer, DMA (for SPI MISO)
*/
#pragma once