12 namespace esp32_rmt_led_strip {
14 static const char *
const TAG =
"esp32_rmt_led_strip";
16 static const uint32_t RMT_CLK_FREQ = 80000000;
18 static const uint8_t RMT_CLK_DIV = 2;
21 ESP_LOGCONFIG(TAG,
"Setting up ESP32 LED Strip...");
27 if (this->
buf_ ==
nullptr) {
28 ESP_LOGE(TAG,
"Cannot allocate LED buffer!");
35 ESP_LOGE(TAG,
"Cannot allocate effect data!");
45 memset(&config, 0,
sizeof(config));
47 config.rmt_mode = RMT_MODE_TX;
48 config.gpio_num = gpio_num_t(this->
pin_);
49 config.mem_block_num = 1;
50 config.clk_div = RMT_CLK_DIV;
51 config.tx_config.loop_en =
false;
52 config.tx_config.carrier_level = RMT_CARRIER_LEVEL_LOW;
53 config.tx_config.carrier_en =
false;
54 config.tx_config.idle_level = RMT_IDLE_LEVEL_LOW;
55 config.tx_config.idle_output_en =
true;
57 if (rmt_config(&config) != ESP_OK) {
58 ESP_LOGE(TAG,
"Cannot initialize RMT!");
62 if (rmt_driver_install(config.channel, 0, 0) != ESP_OK) {
63 ESP_LOGE(TAG,
"Cannot install RMT driver!");
70 uint32_t bit1_low, uint32_t reset_time_high, uint32_t reset_time_low) {
71 float ratio = (float) RMT_CLK_FREQ / RMT_CLK_DIV / 1e09f;
74 this->
bit0_.duration0 = (uint32_t) (ratio * bit0_high);
75 this->
bit0_.level0 = 1;
76 this->
bit0_.duration1 = (uint32_t) (ratio * bit0_low);
77 this->
bit0_.level1 = 0;
79 this->
bit1_.duration0 = (uint32_t) (ratio * bit1_high);
80 this->
bit1_.level0 = 1;
81 this->
bit1_.duration1 = (uint32_t) (ratio * bit1_low);
82 this->
bit1_.level1 = 0;
84 this->
reset_.duration0 = (uint32_t) (ratio * reset_time_high);
86 this->
reset_.duration1 = (uint32_t) (ratio * reset_time_low);
101 ESP_LOGVV(TAG,
"Writing RGB values to bus...");
103 if (rmt_wait_tx_done(this->
channel_, pdMS_TO_TICKS(1000)) != ESP_OK) {
104 ESP_LOGE(TAG,
"RMT TX timeout");
114 uint8_t *psrc = this->
buf_;
115 rmt_item32_t *pdest = this->
rmt_buf_;
116 while (size < buffer_size) {
118 for (
int i = 0; i < 8; i++) {
119 pdest->val = b & (1 << (7 - i)) ? this->
bit1_.val : this->
bit0_.val;
127 if (this->
reset_.duration0 > 0 || this->reset_.duration1 > 0) {
128 pdest->val = this->
reset_.val;
133 if (rmt_write_items(this->
channel_, this->
rmt_buf_, len,
false) != ESP_OK) {
134 ESP_LOGE(TAG,
"RMT TX error");
142 int32_t r = 0, g = 0, b = 0;
176 uint8_t white = this->
is_wrgb_ ? 0 : 3;
178 return {this->
buf_ + (index * multiplier) + r + this->
is_wrgb_,
180 this->
buf_ + (index * multiplier) + b + this->is_wrgb_,
181 this->
is_rgbw_ || this->is_wrgb_ ? this->
buf_ + (index * multiplier) + white :
nullptr,
187 ESP_LOGCONFIG(TAG,
"ESP32 RMT LED Strip:");
188 ESP_LOGCONFIG(TAG,
" Pin: %u", this->
pin_);
189 ESP_LOGCONFIG(TAG,
" Channel: %u", this->
channel_);
190 const char *rgb_order;
211 rgb_order =
"UNKNOWN";
214 ESP_LOGCONFIG(TAG,
" RGB Order: %s", rgb_order);
216 ESP_LOGCONFIG(TAG,
" Number of LEDs: %u", this->
num_leds_);
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
light::ESPColorView get_view_internal(int32_t index) const override
void status_set_warning(const char *message="unspecified")
uint32_t IRAM_ATTR HOT micros()
void set_led_params(uint32_t bit0_high, uint32_t bit0_low, uint32_t bit1_high, uint32_t bit1_low, uint32_t reset_time_high, uint32_t reset_time_low)
float get_setup_priority() const override
void status_clear_warning()
void write_state(light::LightState *state) override
void dump_config() override
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
ESPColorCorrection correction_
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
int32_t size() const override
size_t get_buffer_size_() const
optional< uint32_t > max_refresh_rate_