ESPHome 2026.6.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
10
11#include <driver/gpio.h>
12#include <esp_err.h>
13#include <esp_idf_version.h>
14#include <driver/rmt_tx.h>
15
17
26
27struct LedParams {
28 rmt_symbol_word_t bit0;
29 rmt_symbol_word_t bit1;
30 rmt_symbol_word_t reset;
31};
32
34 public:
35 void setup() override;
36 void write_state(light::LightState *state) override;
37 float get_setup_priority() const override;
38
39 int32_t size() const override { return this->num_leds_; }
41 auto traits = light::LightTraits();
42 if (this->is_rgbw_ || this->is_wrgb_) {
43 traits.set_supported_color_modes({light::ColorMode::RGB_WHITE, light::ColorMode::WHITE});
44 } else {
45 traits.set_supported_color_modes({light::ColorMode::RGB});
46 }
47 return traits;
48 }
49
50 void set_pin(uint8_t pin) { this->pin_ = pin; }
51 void set_inverted(bool inverted) { this->invert_out_ = inverted; }
52 void set_num_leds(uint16_t num_leds) { this->num_leds_ = num_leds; }
53 void set_is_rgbw(bool is_rgbw) { this->is_rgbw_ = is_rgbw; }
54 void set_is_wrgb(bool is_wrgb) { this->is_wrgb_ = is_wrgb; }
55 void set_use_dma(bool use_dma) { this->use_dma_ = use_dma; }
56 void set_use_psram(bool use_psram) { this->use_psram_ = use_psram; }
57
59 void set_max_refresh_rate(uint32_t interval_us) { this->max_refresh_rate_ = interval_us; }
60
61 void set_led_params(uint32_t bit0_high, uint32_t bit0_low, uint32_t bit1_high, uint32_t bit1_low,
62 uint32_t reset_time_high, uint32_t reset_time_low);
63
64 void set_rgb_order(RGBOrder rgb_order) { this->rgb_order_ = rgb_order; }
65 void set_rmt_symbols(uint32_t rmt_symbols) { this->rmt_symbols_ = rmt_symbols; }
66
67 void clear_effect_data() override {
68 for (int i = 0; i < this->size(); i++)
69 this->effect_data_[i] = 0;
70 }
71
72 void dump_config() override;
73
74 protected:
75 light::ESPColorView get_view_internal(int32_t index) const override;
76
77 size_t get_buffer_size_() const { return this->num_leds_ * (this->is_rgbw_ || this->is_wrgb_ ? 4 : 3); }
78
79 uint8_t *buf_{nullptr};
80 uint8_t *effect_data_{nullptr};
82 rmt_channel_handle_t channel_{nullptr};
83 rmt_encoder_handle_t encoder_{nullptr};
84#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
85 uint8_t *rmt_buf_{nullptr};
86#else
87 rmt_symbol_word_t *rmt_buf_{nullptr};
88#endif
90 uint8_t pin_;
91 uint16_t num_leds_;
92 bool is_rgbw_{false};
93 bool is_wrgb_{false};
94 bool use_dma_{false};
95 bool use_psram_{false};
96 bool invert_out_{false};
97
99
101 optional<uint32_t> max_refresh_rate_{};
102};
103
104} // namespace esphome::esp32_rmt_led_strip
105
106#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:59
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)
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