HF-WS2812 Driver 0.1.0-dev
HF-WS2812 ESP32 RMT Driver
Loading...
Searching...
No Matches
ws2812_control.h File Reference

ESP-IDF RMT based driver for WS2812 / NeoPixel LED chains. More...

#include "driver/gpio.h"
#include "driver/rmt_tx.h"
#include "driver/rmt_types.h"
#include "esp_err.h"
#include "led_strip_encoder.h"
#include "sdkconfig.h"
#include <stdint.h>
Include dependency graph for ws2812_control.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  led_state
 Desired colors for a chain of LEDs. More...
 

Macros

Driver constants
#define NUM_LEDS   CONFIG_WS2812_NUM_LEDS
 
#define WS2812_LED_BUFFER_ITEMS   (NUM_LEDS * WS2812_BITS_PER_LED)
 
#define WS2812_T0H   CONFIG_WS2812_T0H
 
#define WS2812_T1H   CONFIG_WS2812_T1H
 
#define WS2812_T0L   CONFIG_WS2812_T0L
 
#define WS2812_T1L   CONFIG_WS2812_T1L
 
#define WS2812_DEFAULT_BRIGHTNESS   CONFIG_WS2812_DEFAULT_BRIGHTNESS
 

Functions

esp_err_t ws2812_control_init (gpio_num_t gpio_num, int channel)
 Initialise the RMT peripheral for WS2812 output.
 
esp_err_t ws2812_write_leds (struct led_state new_state)
 Send LED colour data.
 
void ws2812_set_brightness (uint8_t brightness)
 Set global brightness for subsequent transmissions.
 

Detailed Description

ESP-IDF RMT based driver for WS2812 / NeoPixel LED chains.

Macro Definition Documentation

◆ NUM_LEDS

#define NUM_LEDS   CONFIG_WS2812_NUM_LEDS

Number of LEDs that will be driven by the component.

◆ WS2812_DEFAULT_BRIGHTNESS

#define WS2812_DEFAULT_BRIGHTNESS   CONFIG_WS2812_DEFAULT_BRIGHTNESS

Default global brightness scaling

◆ WS2812_LED_BUFFER_ITEMS

#define WS2812_LED_BUFFER_ITEMS   (NUM_LEDS * WS2812_BITS_PER_LED)

Number of RMT items required to represent the LED chain.

◆ WS2812_T0H

#define WS2812_T0H   CONFIG_WS2812_T0H

Timing for a '0' bit high pulse in RMT ticks

◆ WS2812_T0L

#define WS2812_T0L   CONFIG_WS2812_T0L

Low time for any bit in RMT ticks

◆ WS2812_T1H

#define WS2812_T1H   CONFIG_WS2812_T1H

Timing for a '1' bit high pulse in RMT ticks

◆ WS2812_T1L

#define WS2812_T1L   CONFIG_WS2812_T1L

Function Documentation

◆ ws2812_control_init()

esp_err_t ws2812_control_init ( gpio_num_t gpio_num,
int channel )

Initialise the RMT peripheral for WS2812 output.

This function must be called once before any LED data is transmitted. The GPIO and channel can be specified at runtime.

Parameters
gpio_numGPIO connected to the LED strip.
channelRMT channel to use.
Returns
ESP_OK on success or an error code from the ESP-IDF drivers.

Initialise the RMT peripheral for WS2812 output.

Must be called once before any LED data is transmitted. The pin and channel can be chosen at runtime.

Parameters
gpio_numGPIO connected to the LED strip.
channelRMT channel used for transmission.
Returns
ESP_OK on success or an ESP-IDF error code.

◆ ws2812_set_brightness()

void ws2812_set_brightness ( uint8_t brightness)

Set global brightness for subsequent transmissions.

All LED values are scaled by this factor before being sent. 255 means full brightness.

Parameters
brightnessBrightness level 0-255.

◆ ws2812_write_leds()

esp_err_t ws2812_write_leds ( struct led_state new_state)

Send LED colour data.

The function blocks the calling task until the complete buffer has been transmitted by the RMT peripheral.

Parameters
new_stateDesired LED colours.
Returns
ESP_OK on success or an ESP-IDF error code.

Send LED colour data.

The function blocks until the RMT peripheral finishes sending all LED data.

Parameters
new_stateDesired LED colours.
Returns
ESP_OK on success or an ESP-IDF error code.