ESPHome 2026.2.3
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
16namespace esphome {
17namespace esp32_rmt_led_strip {
18
27
28struct LedParams {
29 rmt_symbol_word_t bit0;
30 rmt_symbol_word_t bit1;
31 rmt_symbol_word_t reset;
32};
33
35 public:
36 void setup() override;
37 void write_state(light::LightState *state) override;
38 float get_setup_priority() const override;
39
40 int32_t size() const override { return this->num_leds_; }
42 auto traits = light::LightTraits();
43 if (this->is_rgbw_ || this->is_wrgb_) {
44 traits.set_supported_color_modes({light::ColorMode::RGB_WHITE, light::ColorMode::WHITE});
45 } else {
46 traits.set_supported_color_modes({light::ColorMode::RGB});
47 }
48 return traits;
49 }
50
51 void set_pin(uint8_t pin) { this->pin_ = pin; }
52 void set_inverted(bool inverted) { this->invert_out_ = inverted; }
53 void set_num_leds(uint16_t num_leds) { this->num_leds_ = num_leds; }
54 void set_is_rgbw(bool is_rgbw) { this->is_rgbw_ = is_rgbw; }
55 void set_is_wrgb(bool is_wrgb) { this->is_wrgb_ = is_wrgb; }
56 void set_use_dma(bool use_dma) { this->use_dma_ = use_dma; }
57 void set_use_psram(bool use_psram) { this->use_psram_ = use_psram; }
58
60 void set_max_refresh_rate(uint32_t interval_us) { this->max_refresh_rate_ = interval_us; }
61
62 void set_led_params(uint32_t bit0_high, uint32_t bit0_low, uint32_t bit1_high, uint32_t bit1_low,
63 uint32_t reset_time_high, uint32_t reset_time_low);
64
65 void set_rgb_order(RGBOrder rgb_order) { this->rgb_order_ = rgb_order; }
66 void set_rmt_symbols(uint32_t rmt_symbols) { this->rmt_symbols_ = rmt_symbols; }
67
68 void clear_effect_data() override {
69 for (int i = 0; i < this->size(); i++)
70 this->effect_data_[i] = 0;
71 }
72
73 void dump_config() override;
74
75 protected:
76 light::ESPColorView get_view_internal(int32_t index) const override;
77
78 size_t get_buffer_size_() const { return this->num_leds_ * (this->is_rgbw_ || this->is_wrgb_ ? 4 : 3); }
79
80 uint8_t *buf_{nullptr};
81 uint8_t *effect_data_{nullptr};
83 rmt_channel_handle_t channel_{nullptr};
84 rmt_encoder_handle_t encoder_{nullptr};
85#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
86 uint8_t *rmt_buf_{nullptr};
87#else
88 rmt_symbol_word_t *rmt_buf_{nullptr};
89#endif
90 uint32_t rmt_symbols_{48};
91 uint8_t pin_;
92 uint16_t num_leds_;
93 bool is_rgbw_{false};
94 bool is_wrgb_{false};
95 bool use_dma_{false};
96 bool use_psram_{false};
97 bool invert_out_{false};
98
100
101 uint32_t last_refresh_{0};
103};
104
105} // namespace esp32_rmt_led_strip
106} // namespace esphome
107
108#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:60
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:91
This class is used to represent the capabilities of a light.
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).
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7