ESPHome 2025.7.2
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_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
89 uint32_t rmt_symbols_{48};
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
98
99 uint32_t last_refresh_{0};
101};
102
103} // namespace esp32_rmt_led_strip
104} // namespace esphome
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:66
This class is used to represent the capabilities of a light.
bool state
Definition fan.h:0
@ 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