ESPHome 2025.5.0
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
15#if ESP_IDF_VERSION_MAJOR >= 5
16#include <driver/rmt_tx.h>
17#else
18#include <driver/rmt.h>
19#endif
20
21namespace esphome {
22namespace esp32_rmt_led_strip {
23
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_num_leds(uint16_t num_leds) { this->num_leds_ = num_leds; }
52 void set_is_rgbw(bool is_rgbw) { this->is_rgbw_ = is_rgbw; }
53 void set_is_wrgb(bool is_wrgb) { this->is_wrgb_ = is_wrgb; }
54 void set_use_dma(bool use_dma) { this->use_dma_ = use_dma; }
55 void set_use_psram(bool use_psram) { this->use_psram_ = use_psram; }
56
58 void set_max_refresh_rate(uint32_t interval_us) { this->max_refresh_rate_ = interval_us; }
59
60 void set_led_params(uint32_t bit0_high, uint32_t bit0_low, uint32_t bit1_high, uint32_t bit1_low,
61 uint32_t reset_time_high, uint32_t reset_time_low);
62
63 void set_rgb_order(RGBOrder rgb_order) { this->rgb_order_ = rgb_order; }
64#if ESP_IDF_VERSION_MAJOR >= 5
65 void set_rmt_symbols(uint32_t rmt_symbols) { this->rmt_symbols_ = rmt_symbols; }
66#else
67 void set_rmt_channel(rmt_channel_t channel) { this->channel_ = channel; }
68#endif
69
70 void clear_effect_data() override {
71 for (int i = 0; i < this->size(); i++)
72 this->effect_data_[i] = 0;
73 }
74
75 void dump_config() override;
76
77 protected:
78 light::ESPColorView get_view_internal(int32_t index) const override;
79
80 size_t get_buffer_size_() const { return this->num_leds_ * (this->is_rgbw_ || this->is_wrgb_ ? 4 : 3); }
81
82 uint8_t *buf_{nullptr};
83 uint8_t *effect_data_{nullptr};
84#if ESP_IDF_VERSION_MAJOR >= 5
85 rmt_channel_handle_t channel_{nullptr};
86 rmt_encoder_handle_t encoder_{nullptr};
87 rmt_symbol_word_t *rmt_buf_{nullptr};
88 rmt_symbol_word_t bit0_, bit1_, reset_;
89 uint32_t rmt_symbols_{48};
90#else
91 rmt_item32_t *rmt_buf_{nullptr};
92 rmt_item32_t bit0_, bit1_, reset_;
93 rmt_channel_t channel_{RMT_CHANNEL_0};
94#endif
95
96 uint8_t pin_;
97 uint16_t num_leds_;
98 bool is_rgbw_{false};
99 bool is_wrgb_{false};
100 bool use_dma_{false};
101 bool use_psram_{false};
102
104
105 uint32_t last_refresh_{0};
107};
108
109} // namespace esp32_rmt_led_strip
110} // namespace esphome
111
112#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:58
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:63
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