11#include "driver/rmt.h"
15static const char *
TAG =
"led_strip_rmt";
17#define WS2812_T0H_NS (300)
18#define WS2812_T0L_NS (900)
19#define WS2812_T1H_NS (900)
20#define WS2812_T1L_NS (300)
22#define SK6812_T0H_NS (300)
23#define SK6812_T0L_NS (900)
24#define SK6812_T1H_NS (600)
25#define SK6812_T1L_NS (600)
27#define LED_STRIP_RESET_MS (10)
30#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
31#define LED_STRIP_RMT_DEFAULT_MEM_BLOCK_SYMBOLS 64
33#define LED_STRIP_RMT_DEFAULT_MEM_BLOCK_SYMBOLS 48
50 size_t wanted_num,
size_t *translated_size,
size_t *item_num)
52 if (src == NULL || dest == NULL) {
61 uint8_t *psrc = (uint8_t *)src;
62 rmt_item32_t *pdest = dest;
63 while (size < src_size && num < wanted_num) {
64 for (
int i = 0; i < 8; i++) {
66 if (*psrc & (1 << (7 - i))) {
67 pdest->val = bit1.val;
69 pdest->val = bit0.val;
77 *translated_size = size;
84 ESP_RETURN_ON_FALSE(index < rmt_strip->strip_len, ESP_ERR_INVALID_ARG,
TAG,
"index out of the maximum number of leds");
87 rmt_strip->
buffer[start + 0] = green & 0xFF;
88 rmt_strip->
buffer[start + 1] = red & 0xFF;
89 rmt_strip->
buffer[start + 2] = blue & 0xFF;
91 rmt_strip->
buffer[start + 3] = 0;
100 "transmit RMT samples failed");
125 ESP_RETURN_ON_FALSE(led_config && dev_config && ret_strip, ESP_ERR_INVALID_ARG,
TAG,
"invalid argument");
127 ESP_RETURN_ON_FALSE(dev_config->
flags.
with_dma == 0, ESP_ERR_NOT_SUPPORTED,
TAG,
"DMA is not supported");
129 uint8_t bytes_per_pixel = 3;
140 ESP_RETURN_ON_FALSE(rmt_strip, ESP_ERR_NO_MEM,
TAG,
"request memory for les_strip failed");
143 rmt_config_t config = RMT_DEFAULT_CONFIG_TX(led_config->
strip_gpio_num, dev_config->rmt_channel);
147 uint8_t mem_block_num = 2;
152 config.mem_block_num = mem_block_num;
157 uint32_t counter_clk_hz = 0;
158 rmt_get_counter_clock((rmt_channel_t)dev_config->rmt_channel, &counter_clk_hz);
160 float ratio = (float)counter_clk_hz / 1e9;
179 rmt_strip->
rmt_channel = (rmt_channel_t)dev_config->rmt_channel;
186 *ret_strip = &rmt_strip->
base;
#define ESP_RETURN_ON_ERROR(x, log_tag, format,...)
#define ESP_GOTO_ON_ERROR(x, goto_tag, log_tag, format,...)
static esp_err_t led_strip_rmt_refresh(led_strip_t *strip)
static esp_err_t led_strip_rmt_set_pixel(led_strip_t *strip, uint32_t index, uint32_t red, uint32_t green, uint32_t blue)
static esp_err_t led_strip_rmt_clear(led_strip_t *strip)
#define LED_STRIP_RMT_DEFAULT_MEM_BLOCK_SYMBOLS
static esp_err_t led_strip_rmt_del(led_strip_t *strip)
static esp_err_t led_strip_rmt_refresh(led_strip_t *strip)
static uint32_t led_t1l_ticks
#define LED_STRIP_RESET_MS
static void ws2812_rmt_adapter(const void *src, rmt_item32_t *dest, size_t src_size, size_t wanted_num, size_t *translated_size, size_t *item_num)
static esp_err_t led_strip_rmt_set_pixel(led_strip_t *strip, uint32_t index, uint32_t red, uint32_t green, uint32_t blue)
static esp_err_t led_strip_rmt_clear(led_strip_t *strip)
static uint32_t led_t0h_ticks
static esp_err_t led_strip_rmt_del(led_strip_t *strip)
static uint32_t led_t0l_ticks
esp_err_t led_strip_new_rmt_device(const led_strip_config_t *led_config, const led_strip_rmt_config_t *dev_config, led_strip_handle_t *ret_strip)
Create LED strip based on RMT TX channel.
static uint32_t led_t1h_ticks
@ LED_PIXEL_FORMAT_INVALID
struct led_strip_t * led_strip_handle_t
LED strip handle.
led_pixel_format_t led_pixel_format
LED Strip RMT specific configuration.
struct led_strip_rmt_config_t::@177205126266303010206200207206146127175132325264 flags
rmt_channel_t rmt_channel
LED strip interface definition.
esp_err_t(* refresh)(led_strip_t *strip)
Refresh memory colors to LEDs.
esp_err_t(* set_pixel)(led_strip_t *strip, uint32_t index, uint32_t red, uint32_t green, uint32_t blue)
Set RGB for a specific pixel.
esp_err_t(* del)(led_strip_t *strip)
Free LED strip resources.
esp_err_t(* clear)(led_strip_t *strip)
Clear LED strip (turn off all LEDs).