ESPHome  2024.7.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 
54  void set_rgb_order(RGBOrder rgb_order) { this->rgb_order_ = rgb_order; }
55  void set_rmt_channel(rmt_channel_t channel) { this->channel_ = channel; }
56 
57  void clear_effect_data() override {
58  for (int i = 0; i < this->size(); i++)
59  this->effect_data_[i] = 0;
60  }
61 
62  void dump_config() override;
63 
64  protected:
65  light::ESPColorView get_view_internal(int32_t index) const override;
66 
67  size_t get_buffer_size_() const { return this->num_leds_ * (this->is_rgbw_ || this->is_wrgb_ ? 4 : 3); }
68 
69  uint8_t *buf_{nullptr};
70  uint8_t *effect_data_{nullptr};
71  rmt_item32_t *rmt_buf_{nullptr};
72 
73  uint8_t pin_;
74  uint16_t num_leds_;
75  bool is_rgbw_;
76  bool is_wrgb_;
77 
78  rmt_item32_t bit0_, bit1_;
80  rmt_channel_t channel_;
81 
82  uint32_t last_refresh_{0};
84 };
85 
86 } // namespace esp32_rmt_led_strip
87 } // namespace esphome
88 
89 #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:129
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)
Definition: led_strip.cpp:68
void write_state(light::LightState *state) override
Definition: led_strip.cpp:84
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