ESPHome 2026.11.0b6
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
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; }
38 this->internal_accessor_.channel_colors = channel_colors;
39 }
40 void set_use_dma(bool use_dma) { this->use_dma_ = use_dma; }
41 void set_use_psram(bool use_psram) { this->use_psram_ = use_psram; }
42
44 void set_max_refresh_rate(uint32_t interval_us) { this->max_refresh_rate_ = interval_us; }
45
46 void set_led_params(uint32_t bit0_high, uint32_t bit0_low, uint32_t bit1_high, uint32_t bit1_low,
47 uint32_t reset_time_high, uint32_t reset_time_low);
48
49 void set_rmt_symbols(uint32_t rmt_symbols) { this->rmt_symbols_ = rmt_symbols; }
50
52
53 void dump_config() override;
54
55 protected:
57
58 // Small members first so they fill the tail padding of AddressableLight
59 uint16_t num_leds_;
60 uint8_t pin_;
61 bool use_dma_{false};
62 bool use_psram_{false};
63 bool invert_out_{false};
65 rmt_channel_handle_t channel_{nullptr};
66 rmt_encoder_handle_t encoder_{nullptr};
67#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
68 uint8_t *rmt_buf_{nullptr};
69#else
70 rmt_symbol_word_t *rmt_buf_{nullptr};
71#endif
76 // Worst-case wire time of one frame plus the reset gap, computed in setup()
78};
79
80} // namespace esphome::esp32_rmt_led_strip
81
82#endif // USE_ESP32
void write_state(light::LightState *state) 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:44
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
light::CorrectedBufferColorAccessor internal_accessor_
Definition led_strip.h:64
void clear_effect_data(size_t num_leds)
Zero the effect data of the first num_leds LEDs; does nothing before the effect data is allocated.
Color accessor backed by a buffer whose contents have color correction applied.
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.
LightTraits traits() const
Colour modes of a strip with this channel order.