ESPHome  2023.11.6
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_) {
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 
49  void set_max_refresh_rate(uint32_t interval_us) { this->max_refresh_rate_ = interval_us; }
50 
51  void set_led_params(uint32_t bit0_high, uint32_t bit0_low, uint32_t bit1_high, uint32_t bit1_low);
52 
53  void set_rgb_order(RGBOrder rgb_order) { this->rgb_order_ = rgb_order; }
54  void set_rmt_channel(rmt_channel_t channel) { this->channel_ = channel; }
55 
56  void clear_effect_data() override {
57  for (int i = 0; i < this->size(); i++)
58  this->effect_data_[i] = 0;
59  }
60 
61  void dump_config() override;
62 
63  protected:
64  light::ESPColorView get_view_internal(int32_t index) const override;
65 
66  size_t get_buffer_size_() const { return this->num_leds_ * (3 + this->is_rgbw_); }
67 
68  uint8_t *buf_{nullptr};
69  uint8_t *effect_data_{nullptr};
70  rmt_item32_t *rmt_buf_{nullptr};
71 
72  uint8_t pin_;
73  uint16_t num_leds_;
74  bool is_rgbw_;
75 
76  rmt_item32_t bit0_, bit1_;
78  rmt_channel_t channel_;
79 
80  uint32_t last_refresh_{0};
82 };
83 
84 } // namespace esp32_rmt_led_strip
85 } // namespace esphome
86 
87 #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:127
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:49
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:66
void write_state(light::LightState *state) override
Definition: led_strip.cpp:82
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