LED clock
 All Files Functions Variables Macros Groups Pages
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 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...
 
void ws2812b_transmit (void)
 transmit color values to WS2812b LEDs
 
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
 

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
Note
peripherals used: SPI SPI peripheral used to control the WS2812b LEDs, timer timer peripheral used to generate SPI clock, DMA DMA peripheral used to send the data

Definition in file led_ws2812b.c.

Macro Definition Documentation

#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.

Function Documentation

void 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 81 of file led_ws2812b.c.

Variable Documentation

volatile bool transmit_flag = false
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.