Skip to content

File WS2812B.h

FileList > driver > Inc > WS2812B.h

Go to the source code of this file

  • #include "stm32xx_hal.h"
  • #include "FreeRTOS.h"
  • #include "semphr.h"

Classes

Type Name
struct ws2812b_color_t
struct ws2812b_handle_t

Public Types

Type Name
enum ws2812b_status_t

Public Functions

Type Name
void ws2812b_TIM_PWM_PulseFinishedCallback (TIM_HandleTypeDef * htim, ws2812b_handle_t * ledHandler, BaseType_t * xHigherPriorityTaskWoken)
Callback function that gets called in the TIM_PWM_PulseFinishedCallback function.
ws2812b_status_t ws2812b_init (ws2812b_handle_t * ledHandler, uint8_t ledData, uint16_t * pwmData, TIM_HandleTypeDef * timerHandle, uint32_t channel, uint8_t numberLeds)
Initializes a strip of ws2812b LEDs.
ws2812b_status_t ws2812b_load_colors (ws2812b_handle_t * ledHandler, const ws2812b_color_t colors, uint8_t start, uint8_t numColors, TickType_t delay_ticks)
Loads an array of colors into the led strip.
ws2812b_status_t ws2812b_set_all_leds (ws2812b_handle_t * ledHandler, ws2812b_color_t color, TickType_t delay_ticks)
Sets the color of all LEDs in a ws2812b strip.
ws2812b_status_t ws2812b_set_color (ws2812b_handle_t * ledHandler, uint8_t led_num, ws2812b_color_t color, TickType_t delay_ticks)
Sets the color for a specific led in the ws2812b strip.
ws2812b_status_t ws2812b_set_led_range (ws2812b_handle_t * ledHandler, uint8_t start, uint8_t end, ws2812b_color_t color, TickType_t delay_ticks)
Sets the color of a specified range of LEDs in a ws2812b strip.

Macros

Type Name
define MAX_RGB_VAL 255
define NUMBER_PWM_DATA_ELEMENTS 4
define WS2812B_SOLID_BLUE (([**ws2812b\_color\_t**](structws2812b__color__t.md)){ .red = 0, .green = 0, .blue = 255 })
define WS2812B_SOLID_BURNT_ORANGE (([**ws2812b\_color\_t**](structws2812b__color__t.md)){ .red = 204, .green = 85, .blue = 0 })
define WS2812B_SOLID_GREEN (([**ws2812b\_color\_t**](structws2812b__color__t.md)){ .red = 0, .green = 255, .blue = 0 })
define WS2812B_SOLID_OFF (([**ws2812b\_color\_t**](structws2812b__color__t.md)){ .red = 0, .green = 0, .blue = 0 })
define WS2812B_SOLID_PURPLE (([**ws2812b\_color\_t**](structws2812b__color__t.md)){ .red = 128, .green = 0, .blue = 128 })
define WS2812B_SOLID_RED (([**ws2812b\_color\_t**](structws2812b__color__t.md)){ .red = 255, .green = 0, .blue = 0 })
define WS2812B_SOLID_YELLOW (([**ws2812b\_color\_t**](structws2812b__color__t.md)){ .red = 255, .green = 255, .blue = 0 })
define WS2812B_TIMER_PERIOD_TICKS 90
define WS2812_HIGH (2\*[**WS2812B\_TIMER\_PERIOD\_TICKS**](WS2812B_8h.md#define-ws2812b_timer_period_ticks))/3
define WS2812_LOW [**WS2812B\_TIMER\_PERIOD\_TICKS**](WS2812B_8h.md#define-ws2812b_timer_period_ticks)/3
define WS2812_RESET_TIME 50

Public Types Documentation

enum ws2812b_status_t

enum ws2812b_status_t {
    WS2812B_OK,
    WS2812B_NULL_ERROR,
    WS2812B_ERROR,
    WS2812B_BUSY
};

Public Functions Documentation

function ws2812b_TIM_PWM_PulseFinishedCallback

Callback function that gets called in the TIM_PWM_PulseFinishedCallback function.

void ws2812b_TIM_PWM_PulseFinishedCallback (
    TIM_HandleTypeDef * htim,
    ws2812b_handle_t * ledHandler,
    BaseType_t * xHigherPriorityTaskWoken
) 

Parameters:

  • ledHandler Pointer to the ws2812b handle.
  • timerHandle Pointer to the timer handle.
  • xHigherPriorityTaskWoken Pointer to the highest priority task to be called next

Returns:

none


function ws2812b_init

Initializes a strip of ws2812b LEDs.

ws2812b_status_t ws2812b_init (
    ws2812b_handle_t * ledHandler,
    uint8_t ledData,
    uint16_t * pwmData,
    TIM_HandleTypeDef * timerHandle,
    uint32_t channel,
    uint8_t numberLeds
) 

Parameters:

  • ledHandler Pointer to the ws2812b handle.
  • ledData 2D array storing per-LED color data
  • pwmData Buffer used for encoded PWM waveform data.
  • timerHandle Pointer to the timer handle.
  • channel Timer channel used for PWM output.
  • numberLeds Number of LEDs in a strip

Returns:

ws2812b_status_t Returns WS2812B_OK on success, and returns any other value on failure


function ws2812b_load_colors

Loads an array of colors into the led strip.

ws2812b_status_t ws2812b_load_colors (
    ws2812b_handle_t * ledHandler,
    const ws2812b_color_t colors,
    uint8_t start,
    uint8_t numColors,
    TickType_t delay_ticks
) 

Parameters:

  • ledHandler Pointer to the ws2812b handle.
  • color An array of color structs that the led strip will be set too.
  • start Starting index of the led range to set (0 indexed).
  • numColors Number of elements in the colors array
  • delay_ticks Ticks to wait for data (0 = non-blocking, portMAX_DELAY = block until available).

Returns:

ws2812b_status_t Returns WS2812B_OK on success, and returns any other value on failure


function ws2812b_set_all_leds

Sets the color of all LEDs in a ws2812b strip.

ws2812b_status_t ws2812b_set_all_leds (
    ws2812b_handle_t * ledHandler,
    ws2812b_color_t color,
    TickType_t delay_ticks
) 

Parameters:

  • ledHandler Pointer to the ws2812b handle.
  • color Struct containing RGB value to set the led too.
  • delay_ticks Ticks to wait for data (0 = non-blocking, portMAX_DELAY = block until available).

Returns:

ws2812b_status_t Returns WS2812B_OK on success, and returns any other value on failure


function ws2812b_set_color

Sets the color for a specific led in the ws2812b strip.

ws2812b_status_t ws2812b_set_color (
    ws2812b_handle_t * ledHandler,
    uint8_t led_num,
    ws2812b_color_t color,
    TickType_t delay_ticks
) 

Parameters:

  • ledHandler Pointer to the ws2812b handle.
  • led_num The led number being set (0 indexed).
  • color Struct containing RGB value to set the led too.
  • delay_ticks Ticks to wait for data (0 = non-blocking, portMAX_DELAY = block until available).

Returns:

ws2812b_status_t Returns WS2812B_OK on success, and returns any other value on failure


function ws2812b_set_led_range

Sets the color of a specified range of LEDs in a ws2812b strip.

ws2812b_status_t ws2812b_set_led_range (
    ws2812b_handle_t * ledHandler,
    uint8_t start,
    uint8_t end,
    ws2812b_color_t color,
    TickType_t delay_ticks
) 

Parameters:

  • ledHandler Pointer to the ws2812b handle.
  • start Starting index of the led range to set (0 indexed).
  • end Ending index of the led range to set (0 indexed).
  • color Struct containing RGB value to set the led too.
  • delay_ticks Ticks to wait for data (0 = non-blocking, portMAX_DELAY = block until available).

Returns:

ws2812b_status_t Returns WS2812B_OK on success, and returns any other value on failure


Macro Definition Documentation

define MAX_RGB_VAL

#define MAX_RGB_VAL `255`

define NUMBER_PWM_DATA_ELEMENTS

#define NUMBER_PWM_DATA_ELEMENTS `4`

define WS2812B_SOLID_BLUE

#define WS2812B_SOLID_BLUE `(( ws2812b_color_t ){ .red = 0,   .green = 0,     .blue = 255 })`

define WS2812B_SOLID_BURNT_ORANGE

#define WS2812B_SOLID_BURNT_ORANGE `(( ws2812b_color_t ){ .red = 204, .green = 85,    .blue = 0 })`

define WS2812B_SOLID_GREEN

#define WS2812B_SOLID_GREEN `(( ws2812b_color_t ){ .red = 0,   .green = 255,   .blue = 0 })`

define WS2812B_SOLID_OFF

#define WS2812B_SOLID_OFF `(( ws2812b_color_t ){ .red = 0,   .green = 0,     .blue = 0 })`

define WS2812B_SOLID_PURPLE

#define WS2812B_SOLID_PURPLE `(( ws2812b_color_t ){ .red = 128, .green = 0,     .blue = 128 })`

define WS2812B_SOLID_RED

#define WS2812B_SOLID_RED `(( ws2812b_color_t ){ .red = 255, .green = 0,     .blue = 0 })`

define WS2812B_SOLID_YELLOW

#define WS2812B_SOLID_YELLOW `(( ws2812b_color_t ){ .red = 255, .green = 255,   .blue = 0 })`

define WS2812B_TIMER_PERIOD_TICKS

#define WS2812B_TIMER_PERIOD_TICKS `90`

define WS2812_HIGH

#define WS2812_HIGH `(2* WS2812B_TIMER_PERIOD_TICKS )/3`

define WS2812_LOW

#define WS2812_LOW `WS2812B_TIMER_PERIOD_TICKS /3`

define WS2812_RESET_TIME

#define WS2812_RESET_TIME `50`


The documentation for this class was generated from the following file driver/Inc/WS2812B.h