ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
led_strip.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef USE_ESP32
4
11
12#include <driver/gpio.h>
13#include <esp_err.h>
14#include <esp_idf_version.h>
15#include <driver/rmt_tx.h>
16
18
19struct LedParams {
20 rmt_symbol_word_t bit0;
21 rmt_symbol_word_t bit1;
22 rmt_symbol_word_t reset;
23};
24
26 public:
27 void setup() override;
28 void write_state(light::LightState *state) override;
29 float get_setup_priority() const override;
30
31 int32_t size() const override { return this->num_leds_; }
32 light::LightTraits get_traits() override { return this->channel_colors_.traits(); }
33
34 void set_pin(uint8_t pin) { this->pin_ = pin; }
35 void set_inverted(bool inverted) { this->invert_out_ = inverted; }
36 void set_num_leds(uint16_t num_leds) { this->num_leds_ = num_leds; }
37 void set_channel_colors(light::ChannelColors channel_colors) { this->channel_colors_ = channel_colors; }
38 void set_use_dma(bool use_dma) { this->use_dma_ = use_dma; }
39 void set_use_psram(bool use_psram) { this->use_psram_ = use_psram; }
40
42 void set_max_refresh_rate(uint32_t interval_us) { this->max_refresh_rate_ = interval_us; }
43
44 void set_led_params(uint32_t bit0_high, uint32_t bit0_low, uint32_t bit1_high, uint32_t bit1_low,
45 uint32_t reset_time_high, uint32_t reset_time_low);
46
47 void set_rmt_symbols(uint32_t rmt_symbols) { this->rmt_symbols_ = rmt_symbols; }
48
49 void clear_effect_data() override {
50 if (this->effect_data_ != nullptr)
51 memset(this->effect_data_, 0, this->num_leds_);
52 }
53
54 void dump_config() override;
55
56 protected:
57 light::ESPColorView get_view_internal(int32_t index) const override {
58 return this->channel_colors_.view(this->buf_, this->effect_data_, index, &this->correction_);
59 }
60
61 size_t get_buffer_size_() const { return this->num_leds_ * this->channel_colors_.bytes_per_led(); }
62
63 uint8_t *buf_{nullptr};
64 uint8_t *effect_data_{nullptr};
66 rmt_channel_handle_t channel_{nullptr};
67 rmt_encoder_handle_t encoder_{nullptr};
68#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
69 uint8_t *rmt_buf_{nullptr};
70#else
71 rmt_symbol_word_t *rmt_buf_{nullptr};
72#endif
74 uint8_t pin_;
75 uint16_t num_leds_;
76 bool use_dma_{false};
77 bool use_psram_{false};
78 bool invert_out_{false};
79
81
84};
85
86} // namespace esphome::esp32_rmt_led_strip
87
88#endif // USE_ESP32
void write_state(light::LightState *state) override
light::ESPColorView get_view_internal(int32_t index) const override
Definition led_strip.h:57
void set_max_refresh_rate(uint32_t interval_us)
Set a maximum refresh rate in µs as some lights do not like being updated too often.
Definition led_strip.h:42
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)
void set_channel_colors(light::ChannelColors channel_colors)
Definition led_strip.h:37
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition light_state.h:68
This class is used to represent the capabilities of a light.
Definition light_traits.h:9
bool state
Definition fan.h:2
static void uint32_t
Which byte of an addressable LED's data carries each colour.
ESPColorView view(uint8_t *buf, uint8_t *effect_data, int32_t index, const ESPColorCorrection *correction) const
View of LED index in buf; a scratch pixel while buf or effect_data is unallocated (failed setup()).
static constexpr uint8_t NO_WHITE
Value of w for a strip that only has red, green and blue channels.
LightTraits traits() const
Colour modes of a strip with this channel order.