12 namespace esp32_rmt_led_strip {
14 static const char *
const TAG =
"esp32_rmt_led_strip";
16 static const uint8_t RMT_CLK_DIV = 2;
19 ESP_LOGCONFIG(TAG,
"Setting up ESP32 LED Strip...");
25 if (this->
buf_ ==
nullptr) {
26 ESP_LOGE(TAG,
"Cannot allocate LED buffer!");
33 ESP_LOGE(TAG,
"Cannot allocate effect data!");
42 memset(&config, 0,
sizeof(config));
44 config.rmt_mode = RMT_MODE_TX;
45 config.gpio_num = gpio_num_t(this->
pin_);
46 config.mem_block_num = 1;
47 config.clk_div = RMT_CLK_DIV;
48 config.tx_config.loop_en =
false;
49 config.tx_config.carrier_level = RMT_CARRIER_LEVEL_LOW;
50 config.tx_config.carrier_en =
false;
51 config.tx_config.idle_level = RMT_IDLE_LEVEL_LOW;
52 config.tx_config.idle_output_en =
true;
54 if (rmt_config(&config) != ESP_OK) {
55 ESP_LOGE(TAG,
"Cannot initialize RMT!");
59 if (rmt_driver_install(config.channel, 0, 0) != ESP_OK) {
60 ESP_LOGE(TAG,
"Cannot install RMT driver!");
68 float ratio = (float) APB_CLK_FREQ / RMT_CLK_DIV / 1e09f;
71 this->
bit0_.duration0 = (uint32_t) (ratio * bit0_high);
72 this->
bit0_.level0 = 1;
73 this->
bit0_.duration1 = (uint32_t) (ratio * bit0_low);
74 this->
bit0_.level1 = 0;
76 this->
bit1_.duration0 = (uint32_t) (ratio * bit1_high);
77 this->
bit1_.level0 = 1;
78 this->
bit1_.duration1 = (uint32_t) (ratio * bit1_low);
79 this->
bit1_.level1 = 0;
93 ESP_LOGVV(TAG,
"Writing RGB values to bus...");
95 if (rmt_wait_tx_done(this->
channel_, pdMS_TO_TICKS(1000)) != ESP_OK) {
96 ESP_LOGE(TAG,
"RMT TX timeout");
106 uint8_t *psrc = this->
buf_;
107 rmt_item32_t *pdest = this->
rmt_buf_;
108 while (size < buffer_size) {
110 for (
int i = 0; i < 8; i++) {
111 pdest->val = b & (1 << (7 - i)) ? this->
bit1_.val : this->
bit0_.val;
119 if (rmt_write_items(this->
channel_, this->
rmt_buf_, len,
false) != ESP_OK) {
120 ESP_LOGE(TAG,
"RMT TX error");
128 int32_t r = 0, g = 0, b = 0;
161 uint8_t multiplier = this->
is_rgbw_ ? 4 : 3;
162 return {this->
buf_ + (index * multiplier) + r,
163 this->
buf_ + (index * multiplier) + g,
164 this->
buf_ + (index * multiplier) + b,
165 this->
is_rgbw_ ? this->
buf_ + (index * multiplier) + 3 :
nullptr,
171 ESP_LOGCONFIG(TAG,
"ESP32 RMT LED Strip:");
172 ESP_LOGCONFIG(TAG,
" Pin: %u", this->
pin_);
173 ESP_LOGCONFIG(TAG,
" Channel: %u", this->
channel_);
174 const char *rgb_order;
195 rgb_order =
"UNKNOWN";
198 ESP_LOGCONFIG(TAG,
" RGB Order: %s", rgb_order);
200 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
An STL allocator that uses SPI RAM.
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 status_set_warning()
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_