25 esp_clk_tree_src_get_freq_hz((soc_module_clk_t) RMT_CLK_SRC_DEFAULT, ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED, &freq);
71 if (this->
buf_ ==
nullptr) {
72 ESP_LOGE(TAG,
"Cannot allocate LED buffer!");
76 memset(this->
buf_, 0, buffer_size);
80 ESP_LOGE(TAG,
"Cannot allocate effect data!");
85#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
95 rmt_tx_channel_config_t channel;
96 memset(&channel, 0,
sizeof(channel));
97 channel.clk_src = RMT_CLK_SRC_DEFAULT;
98 channel.resolution_hz = rmt_resolution_hz();
99 channel.gpio_num = gpio_num_t(this->
pin_);
101 channel.trans_queue_depth = 1;
102 channel.flags.io_loop_back = 0;
103 channel.flags.io_od_mode = 0;
105 channel.flags.with_dma = this->
use_dma_;
106 channel.intr_priority = 0;
107 if (rmt_new_tx_channel(&channel, &this->
channel_) != ESP_OK) {
108 ESP_LOGE(TAG,
"Channel creation failed");
113#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
114 rmt_simple_encoder_config_t encoder;
115 memset(&encoder, 0,
sizeof(encoder));
116 encoder.callback = encoder_callback;
118 encoder.min_chunk_size = RMT_SYMBOLS_PER_BYTE;
119 if (rmt_new_simple_encoder(&encoder, &this->
encoder_) != ESP_OK) {
120 ESP_LOGE(TAG,
"Encoder creation failed");
125 rmt_copy_encoder_config_t encoder;
126 memset(&encoder, 0,
sizeof(encoder));
127 if (rmt_new_copy_encoder(&encoder, &this->
encoder_) != ESP_OK) {
128 ESP_LOGE(TAG,
"Encoder creation failed");
134 if (rmt_enable(this->
channel_) != ESP_OK) {
135 ESP_LOGE(TAG,
"Enabling channel failed");
142 uint32_t bit1_low, uint32_t reset_time_high, uint32_t reset_time_low) {
143 float ratio = (float) rmt_resolution_hz() / 1e09f;
146 this->
params_.
bit0.duration0 = (uint32_t) (ratio * bit0_high);
148 this->
params_.
bit0.duration1 = (uint32_t) (ratio * bit0_low);
151 this->
params_.
bit1.duration0 = (uint32_t) (ratio * bit1_high);
153 this->
params_.
bit1.duration1 = (uint32_t) (ratio * bit1_low);
156 this->
params_.
reset.duration0 = (uint32_t) (ratio * reset_time_high);
158 this->
params_.
reset.duration1 = (uint32_t) (ratio * reset_time_low);
173 ESP_LOGVV(TAG,
"Writing RGB values to bus");
175 esp_err_t error = rmt_tx_wait_all_done(this->
channel_, 1000);
176 if (error != ESP_OK) {
177 ESP_LOGE(TAG,
"RMT TX timeout");
183#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
190 uint8_t *psrc = this->
buf_;
191 rmt_symbol_word_t *pdest = this->
rmt_buf_;
192 while (size < buffer_size) {
194 for (
int i = 0; i < 8; i++) {
203 if (this->
params_.
reset.duration0 > 0 || this->params_.reset.duration1 > 0) {
210 rmt_transmit_config_t config;
211 memset(&config, 0,
sizeof(config));
212#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
217 if (error != ESP_OK) {
218 ESP_LOGE(TAG,
"RMT TX error");
226 int32_t r = 0, g = 0, b = 0;
260 uint8_t white = this->
is_wrgb_ ? 0 : 3;
262 return {this->
buf_ + (index * multiplier) + r + this->
is_wrgb_,
264 this->
buf_ + (index * multiplier) + b + this->is_wrgb_,
265 this->
is_rgbw_ || this->is_wrgb_ ? this->
buf_ + (index * multiplier) + white :
nullptr,