CuVoodoo STM32F1 firmware template
Macros | Functions | Variables
led_ws2812b.c File Reference

library to drive a WS2812B LED chain (code) More...

Go to the source code of this file.

Macros

#define LED_WS2812B_SPI   1
 SPI peripheral.
 
#define LED_WS2812B_TIMER   3
 timer peripheral
 
#define LED_WS2812B_CLK_CH   3
 timer channel to output PWM (PB0), connect to SPI clock input
 
#define LED_WS2812B_TIMER_OC   TIM_OC3
 timer output compare used to set PWM frequency
 
#define LED_WS2812B_SPI_TEMPLATE   0x924924
 bit template to encode one byte to be shifted out by SPI to the WS2812B LEDs More...
 

Functions

void led_ws2812b_set_rgb (uint16_t led, uint8_t red, uint8_t green, uint8_t blue)
 set color of a single LED More...
 
bool led_ws2812b_transmit (void)
 transmit color values to WS2812B LEDs More...
 
void led_ws2812b_setup (void)
 setup WS2812B LED driver
 
void DMA_ISR_SPI_TX() LED_WS2812B_SPI (void)
 DMA interrupt service routine to stop transmission after it finished.
 

Variables

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
 

Detailed Description

library to drive a WS2812B LED chain (code)

Author
King Kévin kingk.nosp@m.evin.nosp@m.@cuvo.nosp@m.odoo.nosp@m..info
Date
2016-2017
Note
peripherals used: SPI SPI peripheral used to control the WS2812B LEDs, timer timer peripheral used to generate SPI clock, DMA (for SPI MISO)

Definition in file led_ws2812b.c.

Macro Definition Documentation

◆ LED_WS2812B_SPI_TEMPLATE

#define LED_WS2812B_SPI_TEMPLATE   0x924924

bit template to encode one byte to be shifted out by SPI to the WS2812B LEDs

For each WS2812B bit which needs to be transfered we require to transfer 3 SPI bits. The first SPI bit is the high start of the WS2812B bit frame. The second SPI bit determines if the WS2812B bit is a 0 or 1. The third SPI bit is the last part of the WS2812B bit frame, which is always low. The binary pattern is 0b100100100100100100100100

Definition at line 60 of file led_ws2812b.c.

Function Documentation

◆ led_ws2812b_set_rgb()

void led_ws2812b_set_rgb ( uint16_t  led,
uint8_t  red,
uint8_t  green,
uint8_t  blue 
)

set color of a single LED

Parameters
[in]ledthe LED number to set the color
[in]redthe red color value to set on the LED
[in]greenthe green color value to set on the LED
[in]bluethe blue color value to set on the LED
Note
transmission needs to be done separately

Definition at line 65 of file led_ws2812b.c.

◆ led_ws2812b_transmit()

bool led_ws2812b_transmit ( void  )

transmit color values to WS2812B LEDs

Returns
true if transmission started, false if another transmission is already ongoing

Definition at line 91 of file led_ws2812b.c.