ESPHome  2024.9.0
led_strip.h
Go to the documentation of this file.
1 #pragma once
2 
3 #ifdef USE_ESP32
4 
7 #include "esphome/core/color.h"
9 #include "esphome/core/helpers.h"
10 
11 #include <driver/gpio.h>
12 #include <driver/rmt.h>
13 #include <esp_err.h>
14 
15 namespace esphome {
16 namespace esp32_rmt_led_strip {
17 
18 enum RGBOrder : uint8_t {
25 };
26 
28  public:
29  void setup() override;
30  void write_state(light::LightState *state) override;
31  float get_setup_priority() const override;
32 
33  int32_t size() const override { return this->num_leds_; }
35  auto traits = light::LightTraits();
36  if (this->is_rgbw_ || this->is_wrgb_) {
37  traits.set_supported_color_modes({light::ColorMode::RGB_WHITE, light::ColorMode::WHITE});
38  } else {
39  traits.set_supported_color_modes({light::ColorMode::RGB});
40  }
41  return traits;
42  }
43 
44  void set_pin(uint8_t pin) { this->pin_ = pin; }
45  void set_num_leds(uint16_t num_leds) { this->num_leds_ = num_leds; }
46  void set_is_rgbw(bool is_rgbw) { this->is_rgbw_ = is_rgbw; }
47  void set_is_wrgb(bool is_wrgb) { this->is_wrgb_ = is_wrgb; }
48 
50  void set_max_refresh_rate(uint32_t interval_us) { this->max_refresh_rate_ = interval_us; }
51 
52  void set_led_params(uint32_t bit0_high, uint32_t bit0_low, uint32_t bit1_high, uint32_t bit1_low,
53  uint32_t reset_time_high, uint32_t reset_time_low);
54 
55  void set_rgb_order(RGBOrder rgb_order) { this->rgb_order_ = rgb_order; }
56  void set_rmt_channel(rmt_channel_t channel) { this->channel_ = channel; }
57 
58  void clear_effect_data() override {
59  for (int i = 0; i < this->size(); i++)
60  this->effect_data_[i] = 0;
61  }
62 
63  void dump_config() override;
64 
65  protected:
66  light::ESPColorView get_view_internal(int32_t index) const override;
67 
68  size_t get_buffer_size_() const { return this->num_leds_ * (this->is_rgbw_ || this->is_wrgb_ ? 4 : 3); }
69 
70  uint8_t *buf_{nullptr};
71  uint8_t *effect_data_{nullptr};
72  rmt_item32_t *rmt_buf_{nullptr};
73 
74  uint8_t pin_;
75  uint16_t num_leds_;
76  bool is_rgbw_;
77  bool is_wrgb_;
78 
79  rmt_item32_t bit0_, bit1_, reset_;
81  rmt_channel_t channel_;
82 
83  uint32_t last_refresh_{0};
85 };
86 
87 } // namespace esp32_rmt_led_strip
88 } // namespace esphome
89 
90 #endif // USE_ESP32
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition: light_state.h:34
light::ESPColorView get_view_internal(int32_t index) const override
Definition: led_strip.cpp:141
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:50
RGB color output and a separate white output.
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)
Definition: led_strip.cpp:69
void write_state(light::LightState *state) override
Definition: led_strip.cpp:90
White output only (use only if the light also has another color mode such as RGB).
This class is used to represent the capabilities of a light.
Definition: light_traits.h:11
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
Color can be controlled using RGB format (includes a brightness control for the color).
bool state
Definition: fan.h:34