ESPHome 2026.10.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_; }
33 auto traits = light::LightTraits();
34 if (this->channel_colors_.has_white()) {
35 traits.set_supported_color_modes({light::ColorMode::RGB_WHITE, light::ColorMode::WHITE});
36 } else {
37 traits.set_supported_color_modes({light::ColorMode::RGB});
38 }
39 return traits;
40 }
41
42 void set_pin(uint8_t pin) { this->pin_ = pin; }
43 void set_inverted(bool inverted) { this->invert_out_ = inverted; }
44 void set_num_leds(uint16_t num_leds) { this->num_leds_ = num_leds; }
45 void set_channel_colors(light::ChannelColors channel_colors) { this->channel_colors_ = channel_colors; }
46 void set_use_dma(bool use_dma) { this->use_dma_ = use_dma; }
47 void set_use_psram(bool use_psram) { this->use_psram_ = use_psram; }
48
50 void set_max_refresh_rate(uint32_t interval_us) { this->max_refresh_rate_ = interval_us; }
51
52 void set_led_params(uint32_t bit0_high, uint32_t bit0_low, uint32_t bit1_high, uint32_t bit1_low,
53 uint32_t reset_time_high, uint32_t reset_time_low);
54
55 void set_rmt_symbols(uint32_t rmt_symbols) { this->rmt_symbols_ = rmt_symbols; }
56
57 void clear_effect_data() override {
58 for (int i = 0; i < this->size(); i++)
59 this->effect_data_[i] = 0;
60 }
61
62 void dump_config() override;
63
64 protected:
65 light::ESPColorView get_view_internal(int32_t index) const override;
66
67 size_t get_buffer_size_() const { return this->num_leds_ * this->channel_colors_.bytes_per_led(); }
68
69 uint8_t *buf_{nullptr};
70 uint8_t *effect_data_{nullptr};
72 rmt_channel_handle_t channel_{nullptr};
73 rmt_encoder_handle_t encoder_{nullptr};
74#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
75 uint8_t *rmt_buf_{nullptr};
76#else
77 rmt_symbol_word_t *rmt_buf_{nullptr};
78#endif
80 uint8_t pin_;
81 uint16_t num_leds_;
82 bool use_dma_{false};
83 bool use_psram_{false};
84 bool invert_out_{false};
85
87
89 optional<uint32_t> max_refresh_rate_{};
90};
91
92} // namespace esphome::esp32_rmt_led_strip
93
94#endif // USE_ESP32
void write_state(light::LightState *state) override
light::ESPColorView get_view_internal(int32_t index) const override
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:50
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:45
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition light_state.h:93
This class is used to represent the capabilities of a light.
Definition light_traits.h:9
bool state
Definition fan.h:2
@ RGB_WHITE
RGB color output and a separate white output.
@ RGB
RGB color output.
@ WHITE
White output only (use only if the light also has another color mode such as RGB).
static void uint32_t
Which byte of an addressable LED's data carries each colour.
static constexpr uint8_t NO_WHITE
Value of w for a strip that only has red, green and blue channels.