63 if (this->
buf_ ==
nullptr) {
64 ESP_LOGE(TAG,
"Cannot allocate LED buffer!");
68 memset(this->
buf_, 0, buffer_size);
72 ESP_LOGE(TAG,
"Cannot allocate effect data!");
77#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
87 rmt_tx_channel_config_t channel;
88 memset(&channel, 0,
sizeof(channel));
89 channel.clk_src = RMT_CLK_SRC_DEFAULT;
90 channel.resolution_hz = RMT_CLK_FREQ / RMT_CLK_DIV;
91 channel.gpio_num = gpio_num_t(this->
pin_);
93 channel.trans_queue_depth = 1;
94 channel.flags.io_loop_back = 0;
95 channel.flags.io_od_mode = 0;
96 channel.flags.invert_out = 0;
97 channel.flags.with_dma = this->
use_dma_;
98 channel.intr_priority = 0;
99 if (rmt_new_tx_channel(&channel, &this->
channel_) != ESP_OK) {
100 ESP_LOGE(TAG,
"Channel creation failed");
105#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
106 rmt_simple_encoder_config_t encoder;
107 memset(&encoder, 0,
sizeof(encoder));
108 encoder.callback = encoder_callback;
110 encoder.min_chunk_size = RMT_SYMBOLS_PER_BYTE;
111 if (rmt_new_simple_encoder(&encoder, &this->
encoder_) != ESP_OK) {
112 ESP_LOGE(TAG,
"Encoder creation failed");
117 rmt_copy_encoder_config_t encoder;
118 memset(&encoder, 0,
sizeof(encoder));
119 if (rmt_new_copy_encoder(&encoder, &this->
encoder_) != ESP_OK) {
120 ESP_LOGE(TAG,
"Encoder creation failed");
126 if (rmt_enable(this->
channel_) != ESP_OK) {
127 ESP_LOGE(TAG,
"Enabling channel failed");
134 uint32_t bit1_low, uint32_t reset_time_high, uint32_t reset_time_low) {
135 float ratio = (float) RMT_CLK_FREQ / RMT_CLK_DIV / 1e09f;
138 this->
params_.
bit0.duration0 = (uint32_t) (ratio * bit0_high);
140 this->
params_.
bit0.duration1 = (uint32_t) (ratio * bit0_low);
143 this->
params_.
bit1.duration0 = (uint32_t) (ratio * bit1_high);
145 this->
params_.
bit1.duration1 = (uint32_t) (ratio * bit1_low);
148 this->
params_.
reset.duration0 = (uint32_t) (ratio * reset_time_high);
150 this->
params_.
reset.duration1 = (uint32_t) (ratio * reset_time_low);
165 ESP_LOGVV(TAG,
"Writing RGB values to bus");
167 esp_err_t error = rmt_tx_wait_all_done(this->
channel_, 1000);
168 if (error != ESP_OK) {
169 ESP_LOGE(TAG,
"RMT TX timeout");
175#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
182 uint8_t *psrc = this->
buf_;
183 rmt_symbol_word_t *pdest = this->
rmt_buf_;
184 while (size < buffer_size) {
186 for (
int i = 0; i < 8; i++) {
195 if (this->
params_.
reset.duration0 > 0 || this->params_.reset.duration1 > 0) {
202 rmt_transmit_config_t config;
203 memset(&config, 0,
sizeof(config));
204#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
209 if (error != ESP_OK) {
210 ESP_LOGE(TAG,
"RMT TX error");
218 int32_t r = 0, g = 0, b = 0;
252 uint8_t white = this->
is_wrgb_ ? 0 : 3;
254 return {this->
buf_ + (index * multiplier) + r + this->
is_wrgb_,
256 this->
buf_ + (index * multiplier) + b + this->is_wrgb_,
257 this->
is_rgbw_ || this->is_wrgb_ ? this->
buf_ + (index * multiplier) + white :
nullptr,