HF-WS2812 Driver 0.1.0-dev
HF-WS2812 ESP32 RMT Driver
Loading...
Searching...
No Matches
ws2812_control.c File Reference
#include "ws2812_control.h"
#include "driver/rmt_tx.h"
#include "driver/rmt_types.h"
#include "esp_check.h"
#include "esp_err.h"
#include "freertos/FreeRTOS.h"
#include "led_strip_encoder.h"
Include dependency graph for ws2812_control.c:

Macros

#define LED_RMT_TX_CHANNEL   CONFIG_WS2812_LED_RMT_TX_CHANNEL
 
#define LED_RMT_TX_GPIO   CONFIG_WS2812_LED_RMT_TX_GPIO
 
#define LED_BUFFER_ITEMS   (NUM_LEDS * BITS_PER_LED_CMD)
 
#define T0H   CONFIG_WS2812_T0H
 
#define T1H   CONFIG_WS2812_T1H
 
#define T0L   CONFIG_WS2812_T0L
 
#define T1L   CONFIG_WS2812_T1L
 

Functions

esp_err_t ws2812_control_init (gpio_num_t gpio_num, int channel)
 Initialise the RMT driver for WS2812 output.
 
esp_err_t ws2812_write_leds (struct led_state new_state)
 Transmit colour values to the LED chain.
 
void ws2812_set_brightness (uint8_t brightness)
 Set global brightness for subsequent transmissions.
 

Macro Definition Documentation

◆ LED_BUFFER_ITEMS

#define LED_BUFFER_ITEMS   (NUM_LEDS * BITS_PER_LED_CMD)

◆ LED_RMT_TX_CHANNEL

#define LED_RMT_TX_CHANNEL   CONFIG_WS2812_LED_RMT_TX_CHANNEL

◆ LED_RMT_TX_GPIO

#define LED_RMT_TX_GPIO   CONFIG_WS2812_LED_RMT_TX_GPIO

◆ T0H

#define T0H   CONFIG_WS2812_T0H

◆ T0L

#define T0L   CONFIG_WS2812_T0L

◆ T1H

#define T1H   CONFIG_WS2812_T1H

◆ T1L

#define 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 driver for WS2812 output.

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)

Transmit colour values to the LED chain.

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.