68 if (this->
buf_ ==
nullptr) {
69 ESP_LOGE(TAG,
"Cannot allocate LED buffer!");
73 memset(this->
buf_, 0, buffer_size);
77 ESP_LOGE(TAG,
"Cannot allocate effect data!");
82#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
92 rmt_tx_channel_config_t channel;
93 memset(&channel, 0,
sizeof(channel));
94 channel.clk_src = RMT_CLK_SRC_DEFAULT;
95 channel.resolution_hz = RMT_CLK_FREQ / RMT_CLK_DIV;
96 channel.gpio_num = gpio_num_t(this->
pin_);
98 channel.trans_queue_depth = 1;
99 channel.flags.io_loop_back = 0;
100 channel.flags.io_od_mode = 0;
101 channel.flags.invert_out = 0;
102 channel.flags.with_dma = this->
use_dma_;
103 channel.intr_priority = 0;
104 if (rmt_new_tx_channel(&channel, &this->
channel_) != ESP_OK) {
105 ESP_LOGE(TAG,
"Channel creation failed");
110#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
111 rmt_simple_encoder_config_t encoder;
112 memset(&encoder, 0,
sizeof(encoder));
113 encoder.callback = encoder_callback;
115 encoder.min_chunk_size = RMT_SYMBOLS_PER_BYTE;
116 if (rmt_new_simple_encoder(&encoder, &this->
encoder_) != ESP_OK) {
117 ESP_LOGE(TAG,
"Encoder creation failed");
122 rmt_copy_encoder_config_t encoder;
123 memset(&encoder, 0,
sizeof(encoder));
124 if (rmt_new_copy_encoder(&encoder, &this->
encoder_) != ESP_OK) {
125 ESP_LOGE(TAG,
"Encoder creation failed");
131 if (rmt_enable(this->
channel_) != ESP_OK) {
132 ESP_LOGE(TAG,
"Enabling channel failed");
139 uint32_t bit1_low, uint32_t reset_time_high, uint32_t reset_time_low) {
140 float ratio = (float) RMT_CLK_FREQ / RMT_CLK_DIV / 1e09f;
143 this->
params_.
bit0.duration0 = (uint32_t) (ratio * bit0_high);
145 this->
params_.
bit0.duration1 = (uint32_t) (ratio * bit0_low);
148 this->
params_.
bit1.duration0 = (uint32_t) (ratio * bit1_high);
150 this->
params_.
bit1.duration1 = (uint32_t) (ratio * bit1_low);
153 this->
params_.
reset.duration0 = (uint32_t) (ratio * reset_time_high);
155 this->
params_.
reset.duration1 = (uint32_t) (ratio * reset_time_low);
170 ESP_LOGVV(TAG,
"Writing RGB values to bus");
172 esp_err_t error = rmt_tx_wait_all_done(this->
channel_, 1000);
173 if (error != ESP_OK) {
174 ESP_LOGE(TAG,
"RMT TX timeout");
180#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
187 uint8_t *psrc = this->
buf_;
188 rmt_symbol_word_t *pdest = this->
rmt_buf_;
189 while (size < buffer_size) {
191 for (
int i = 0; i < 8; i++) {
200 if (this->
params_.
reset.duration0 > 0 || this->params_.reset.duration1 > 0) {
207 rmt_transmit_config_t config;
208 memset(&config, 0,
sizeof(config));
209#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
214 if (error != ESP_OK) {
215 ESP_LOGE(TAG,
"RMT TX error");
223 int32_t r = 0, g = 0, b = 0;
257 uint8_t white = this->
is_wrgb_ ? 0 : 3;
259 return {this->
buf_ + (index * multiplier) + r + this->
is_wrgb_,
261 this->
buf_ + (index * multiplier) + b + this->is_wrgb_,
262 this->
is_rgbw_ || this->is_wrgb_ ? this->
buf_ + (index * multiplier) + white :
nullptr,