ESPHome  2024.10.2
led_strip.h
Go to the documentation of this file.
1 #pragma once
2 
3 #ifdef USE_BK72XX
4 
7 #include "esphome/core/color.h"
9 #include "esphome/core/helpers.h"
10 
11 namespace esphome {
12 namespace beken_spi_led_strip {
13 
14 enum RGBOrder : uint8_t {
21 };
22 
24  public:
25  void setup() override;
26  void write_state(light::LightState *state) override;
27  float get_setup_priority() const override;
28 
29  int32_t size() const override { return this->num_leds_; }
31  auto traits = light::LightTraits();
32  if (this->is_rgbw_ || this->is_wrgb_) {
33  traits.set_supported_color_modes({light::ColorMode::RGB_WHITE, light::ColorMode::WHITE});
34  } else {
35  traits.set_supported_color_modes({light::ColorMode::RGB});
36  }
37  return traits;
38  }
39 
40  void set_pin(uint8_t pin) { this->pin_ = pin; }
41  void set_num_leds(uint16_t num_leds) { this->num_leds_ = num_leds; }
42  void set_is_rgbw(bool is_rgbw) { this->is_rgbw_ = is_rgbw; }
43  void set_is_wrgb(bool is_wrgb) { this->is_wrgb_ = is_wrgb; }
44 
46  void set_max_refresh_rate(uint32_t interval_us) { this->max_refresh_rate_ = interval_us; }
47 
48  void set_led_params(uint8_t bit0, uint8_t bit1, uint32_t spi_frequency);
49 
50  void set_rgb_order(RGBOrder rgb_order) { this->rgb_order_ = rgb_order; }
51 
52  void clear_effect_data() override {
53  for (int i = 0; i < this->size(); i++)
54  this->effect_data_[i] = 0;
55  }
56 
57  void dump_config() override;
58 
59  protected:
60  light::ESPColorView get_view_internal(int32_t index) const override;
61 
62  size_t get_buffer_size_() const { return this->num_leds_ * (this->is_rgbw_ || this->is_wrgb_ ? 4 : 3); }
63 
64  uint8_t *buf_{nullptr};
65  uint8_t *effect_data_{nullptr};
66  uint8_t *dma_buf_{nullptr};
67 
68  uint8_t pin_;
69  uint16_t num_leds_;
70  bool is_rgbw_;
71  bool is_wrgb_;
72 
73  uint32_t spi_frequency_{6666666};
74  uint8_t bit0_{0xE0};
75  uint8_t bit1_{0xFC};
77 
78  uint32_t last_refresh_{0};
80 };
81 
82 } // namespace beken_spi_led_strip
83 } // namespace esphome
84 
85 #endif // USE_BK72XX
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition: light_state.h:34
RGB color output and a separate white output.
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:46
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).
void set_led_params(uint8_t bit0, uint8_t bit1, uint32_t spi_frequency)
Definition: led_strip.cpp:242
light::ESPColorView get_view_internal(int32_t index) const override
Definition: led_strip.cpp:302
void write_state(light::LightState *state) override
Definition: led_strip.cpp:248
bool state
Definition: fan.h:34