library to drive a WS2812b LED chain (code) More...
Go to the source code of this file.
Macros | |
#define | WS2812B_SPI SPI1 |
#define | WS2812B_SPI_DR SPI1_DR |
#define | WS2812B_SPI_RCC RCC_SPI1 |
#define | WS2812B_SPI_PORT GPIOA |
#define | WS2812B_SPI_CLK GPIO_SPI1_SCK |
#define | WS2812B_SPI_DOUT GPIO_SPI1_MISO |
#define | WS2812B_TIMER TIM3 |
#define | WS2812B_TIMER_RCC RCC_TIM3 |
#define | WS2812B_TIMER_OC TIM_OC3 |
#define | WS2812B_CLK_RCC RCC_GPIOB |
#define | WS2812B_CLK_PORT GPIOB |
#define | WS2812B_CLK_PIN GPIO_TIM3_CH3 |
#define | WS2812B_DMA DMA1 |
#define | WS2812B_DMA_RCC RCC_DMA1 |
#define | WS2812B_DMA_CH DMA_CHANNEL3 |
#define | WS2812B_DMA_IRQ NVIC_DMA1_CHANNEL3_IRQ |
#define | WS2812B_DMA_ISR dma1_channel3_isr |
#define | WS2812B_SPI_TEMPLATE 0x924924 |
bit template to encode one byte to be shifted out by SPI to the WS2812b LEDs More... | |
Functions | |
void | ws2812b_set_rgb (uint16_t led, uint8_t red, uint8_t green, uint8_t blue) |
set color of a single LED More... | |
bool | ws2812b_transmit (void) |
transmit color values to WS2812b LEDs More... | |
void | ws2812b_setup (void) |
setup WS2812b LED driver | |
void | WS2812B_DMA_ISR (void) |
DMA interrupt service routine to stop transmission after it finished. | |
Variables | |
uint8_t | ws2812b_data [WS2812B_LEDS *3 *3+40 *3/8+1] = {0} |
static volatile bool | transmit_flag = false |
library to drive a WS2812b LED chain (code)
Definition in file led_ws2812b.c.
#define 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 76 of file led_ws2812b.c.
void ws2812b_set_rgb | ( | uint16_t | led, |
uint8_t | red, | ||
uint8_t | green, | ||
uint8_t | blue | ||
) |
set color of a single LED
[in] | led | the LED number to set the color |
[in] | red | the red color value to set on the LED |
[in] | green | the green color value to set on the LED |
[in] | blue | the blue color value to set on the LED |
Definition at line 81 of file led_ws2812b.c.
bool ws2812b_transmit | ( | void | ) |
transmit color values to WS2812b LEDs
Definition at line 107 of file led_ws2812b.c.
|
static |
flag set in software when transmission started, clear by interrupt when transmission completed
Definition at line 79 of file led_ws2812b.c.
uint8_t ws2812b_data[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)
Definition at line 78 of file led_ws2812b.c.