ESP-IDF Firmware
Firmware architecture and call graph
Loading...
Searching...
No Matches
led_strip_rmt.h File Reference
#include <stdint.h>
#include "esp_err.h"
#include "led_strip_types.h"
#include "esp_idf_version.h"
#include "driver/rmt_types.h"
Include dependency graph for led_strip_rmt.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  led_strip_rmt_config_t
 LED Strip RMT specific configuration. More...

Functions

esp_err_t led_strip_new_rmt_device (const led_strip_config_t *led_config, const led_strip_rmt_config_t *rmt_config, led_strip_handle_t *ret_strip)
 Create LED strip based on RMT TX channel.

Function Documentation

◆ led_strip_new_rmt_device()

esp_err_t led_strip_new_rmt_device ( const led_strip_config_t * led_config,
const led_strip_rmt_config_t * rmt_config,
led_strip_handle_t * ret_strip )

Create LED strip based on RMT TX channel.

Parameters
led_configLED strip configuration
rmt_configRMT specific configuration
ret_stripReturned LED strip handle
Returns
  • ESP_OK: create LED strip handle successfully
  • ESP_ERR_INVALID_ARG: create LED strip handle failed because of invalid argument
  • ESP_ERR_NO_MEM: create LED strip handle failed because of out of memory
  • ESP_FAIL: create LED strip handle failed because some other error

Definition at line 97 of file led_strip_rmt_dev.c.

98{
99 led_strip_rmt_obj *rmt_strip = NULL;
100 esp_err_t ret = ESP_OK;
101 ESP_GOTO_ON_FALSE(led_config && rmt_config && ret_strip, ESP_ERR_INVALID_ARG, err, TAG, "invalid argument");
102 ESP_GOTO_ON_FALSE(led_config->led_pixel_format < LED_PIXEL_FORMAT_INVALID, ESP_ERR_INVALID_ARG, err, TAG, "invalid led_pixel_format");
103 uint8_t bytes_per_pixel = 3;
104 if (led_config->led_pixel_format == LED_PIXEL_FORMAT_GRBW) {
105 bytes_per_pixel = 4;
106 } else if (led_config->led_pixel_format == LED_PIXEL_FORMAT_GRB) {
107 bytes_per_pixel = 3;
108 } else {
109 assert(false);
110 }
111 rmt_strip = calloc(1, sizeof(led_strip_rmt_obj) + led_config->max_leds * bytes_per_pixel);
112 ESP_GOTO_ON_FALSE(rmt_strip, ESP_ERR_NO_MEM, err, TAG, "no mem for rmt strip");
113 uint32_t resolution = rmt_config->resolution_hz ? rmt_config->resolution_hz : LED_STRIP_RMT_DEFAULT_RESOLUTION;
114
115 // for backward compatibility, if the user does not set the clk_src, use the default value
116 rmt_clock_source_t clk_src = RMT_CLK_SRC_DEFAULT;
117 if (rmt_config->clk_src) {
118 clk_src = rmt_config->clk_src;
119 }
120 size_t mem_block_symbols = LED_STRIP_RMT_DEFAULT_MEM_BLOCK_SYMBOLS;
121 // override the default value if the user sets it
122 if (rmt_config->mem_block_symbols) {
123 mem_block_symbols = rmt_config->mem_block_symbols;
124 }
125 rmt_tx_channel_config_t rmt_chan_config = {
126 .clk_src = clk_src,
127 .gpio_num = led_config->strip_gpio_num,
128 .mem_block_symbols = mem_block_symbols,
129 .resolution_hz = resolution,
130 .trans_queue_depth = LED_STRIP_RMT_DEFAULT_TRANS_QUEUE_SIZE,
131 .flags.with_dma = rmt_config->flags.with_dma,
132 .flags.invert_out = led_config->flags.invert_out,
133 };
134 ESP_GOTO_ON_ERROR(rmt_new_tx_channel(&rmt_chan_config, &rmt_strip->rmt_chan), err, TAG, "create RMT TX channel failed");
135
136 led_strip_encoder_config_t strip_encoder_conf = {
137 .resolution = resolution,
138 .led_model = led_config->led_model
139 };
140 ESP_GOTO_ON_ERROR(rmt_new_led_strip_encoder(&strip_encoder_conf, &rmt_strip->strip_encoder), err, TAG, "create LED strip encoder failed");
141
142
143 rmt_strip->bytes_per_pixel = bytes_per_pixel;
144 rmt_strip->strip_len = led_config->max_leds;
148 rmt_strip->base.clear = led_strip_rmt_clear;
149 rmt_strip->base.del = led_strip_rmt_del;
150
151 *ret_strip = &rmt_strip->base;
152 return ESP_OK;
153err:
154 if (rmt_strip) {
155 if (rmt_strip->rmt_chan) {
156 rmt_del_channel(rmt_strip->rmt_chan);
157 }
158 if (rmt_strip->strip_encoder) {
159 rmt_del_encoder(rmt_strip->strip_encoder);
160 }
161 free(rmt_strip);
162 }
163 return ret;
164}
#define ESP_GOTO_ON_ERROR(x, goto_tag, log_tag, format,...)
int esp_err_t
Definition esp_err.h:21
#define ESP_OK
Definition esp_err.h:23
static esp_err_t led_strip_rmt_refresh(led_strip_t *strip)
static esp_err_t led_strip_rmt_set_pixel_rgbw(led_strip_t *strip, uint32_t index, uint32_t red, uint32_t green, uint32_t blue, uint32_t white)
#define LED_STRIP_RMT_DEFAULT_TRANS_QUEUE_SIZE
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)
#define LED_STRIP_RMT_DEFAULT_RESOLUTION
esp_err_t rmt_new_led_strip_encoder(const led_strip_encoder_config_t *config, rmt_encoder_handle_t *ret_encoder)
Create RMT encoder for encoding LED strip pixels into RMT symbols.
@ LED_PIXEL_FORMAT_GRB
@ LED_PIXEL_FORMAT_INVALID
@ LED_PIXEL_FORMAT_GRBW
static const char * TAG
Definition main/main.c:31
led_pixel_format_t led_pixel_format
struct led_strip_config_t::@145177150267040163336221331365072267202117177200 flags
Type of led strip encoder configuration.
rmt_clock_source_t clk_src
struct led_strip_rmt_config_t::@177205126266303010206200207206146127175132325264 flags
rmt_channel_handle_t rmt_chan
rmt_encoder_handle_t strip_encoder
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(* set_pixel_rgbw)(led_strip_t *strip, uint32_t index, uint32_t red, uint32_t green, uint32_t blue, uint32_t white)
Set RGBW for a specific pixel. Similar to set_pixel but also set the white component.
esp_err_t(* clear)(led_strip_t *strip)
Clear LED strip (turn off all LEDs).

References led_strip_rmt_obj::base, led_strip_rmt_obj::bytes_per_pixel, led_strip_t::clear, led_strip_rmt_config_t::clk_src, led_strip_t::del, ESP_GOTO_ON_ERROR, ESP_OK, led_strip_config_t::flags, led_strip_rmt_config_t::flags, led_strip_config_t::invert_out, led_strip_config_t::led_model, LED_MODEL_SK6812, LED_MODEL_WS2812, led_strip_config_t::led_pixel_format, LED_PIXEL_FORMAT_GRB, LED_PIXEL_FORMAT_GRBW, LED_PIXEL_FORMAT_INVALID, led_strip_rmt_clear(), LED_STRIP_RMT_DEFAULT_MEM_BLOCK_SYMBOLS, LED_STRIP_RMT_DEFAULT_RESOLUTION, LED_STRIP_RMT_DEFAULT_TRANS_QUEUE_SIZE, led_strip_rmt_del(), led_strip_rmt_refresh(), led_strip_rmt_set_pixel(), led_strip_rmt_set_pixel_rgbw(), led_t0h_ticks, led_t0l_ticks, led_t1h_ticks, led_t1l_ticks, led_strip_config_t::max_leds, led_strip_rmt_config_t::mem_block_symbols, led_strip_t::refresh, led_strip_rmt_config_t::resolution_hz, led_strip_rmt_obj::rmt_chan, led_strip_rmt_obj::rmt_channel, rmt_new_led_strip_encoder(), led_strip_t::set_pixel, led_strip_t::set_pixel_rgbw, SK6812_T0H_NS, SK6812_T0L_NS, SK6812_T1H_NS, SK6812_T1L_NS, led_strip_rmt_obj::strip_encoder, led_strip_config_t::strip_gpio_num, led_strip_rmt_obj::strip_len, TAG, led_strip_rmt_config_t::with_dma, ws2812_rmt_adapter(), WS2812_T0H_NS, WS2812_T0L_NS, WS2812_T1H_NS, and WS2812_T1L_NS.

Here is the call graph for this function: