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!");
44 memset(&config, 0,
sizeof(config));
46 config.rmt_mode = RMT_MODE_TX;
47 config.gpio_num = gpio_num_t(this->
pin_);
48 config.mem_block_num = 1;
49 config.clk_div = RMT_CLK_DIV;
50 config.tx_config.loop_en =
false;
51 config.tx_config.carrier_level = RMT_CARRIER_LEVEL_LOW;
52 config.tx_config.carrier_en =
false;
53 config.tx_config.idle_level = RMT_IDLE_LEVEL_LOW;
54 config.tx_config.idle_output_en =
true;
56 if (rmt_config(&config) != ESP_OK) {
57 ESP_LOGE(TAG,
"Cannot initialize RMT!");
61 if (rmt_driver_install(config.channel, 0, 0) != ESP_OK) {
62 ESP_LOGE(TAG,
"Cannot install RMT driver!");
70 float ratio = (float) RMT_CLK_FREQ / RMT_CLK_DIV / 1e09f;
73 this->
bit0_.duration0 = (uint32_t) (ratio * bit0_high);
74 this->
bit0_.level0 = 1;
75 this->
bit0_.duration1 = (uint32_t) (ratio * bit0_low);
76 this->
bit0_.level1 = 0;
78 this->
bit1_.duration0 = (uint32_t) (ratio * bit1_high);
79 this->
bit1_.level0 = 1;
80 this->
bit1_.duration1 = (uint32_t) (ratio * bit1_low);
81 this->
bit1_.level1 = 0;
95 ESP_LOGVV(TAG,
"Writing RGB values to bus...");
97 if (rmt_wait_tx_done(this->
channel_, pdMS_TO_TICKS(1000)) != ESP_OK) {
98 ESP_LOGE(TAG,
"RMT TX timeout");
108 uint8_t *psrc = this->
buf_;
109 rmt_item32_t *pdest = this->
rmt_buf_;
110 while (size < buffer_size) {
112 for (
int i = 0; i < 8; i++) {
113 pdest->val = b & (1 << (7 - i)) ? this->
bit1_.val : this->
bit0_.val;
121 if (rmt_write_items(this->
channel_, this->
rmt_buf_, len,
false) != ESP_OK) {
122 ESP_LOGE(TAG,
"RMT TX error");
130 int32_t r = 0, g = 0, b = 0;
164 uint8_t white = this->
is_wrgb_ ? 0 : 3;
166 return {this->
buf_ + (index * multiplier) + r + this->
is_wrgb_,
168 this->
buf_ + (index * multiplier) + b + this->is_wrgb_,
169 this->
is_rgbw_ || this->is_wrgb_ ? this->
buf_ + (index * multiplier) + white :
nullptr,
175 ESP_LOGCONFIG(TAG,
"ESP32 RMT LED Strip:");
176 ESP_LOGCONFIG(TAG,
" Pin: %u", this->
pin_);
177 ESP_LOGCONFIG(TAG,
" Channel: %u", this->
channel_);
178 const char *rgb_order;
199 rgb_order =
"UNKNOWN";
202 ESP_LOGCONFIG(TAG,
" RGB Order: %s", rgb_order);
204 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)
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_