9 namespace spi_led_strip {
11 static const char *
const TAG =
"spi_led_strip";
13 public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_HIGH, spi::CLOCK_PHASE_TRAILING,
14 spi::DATA_RATE_1MHZ> {
30 if (this->
buf_ ==
nullptr) {
31 esph_log_e(TAG,
"Failed to allocate buffer of size %u", this->
buffer_size_);
38 esph_log_e(TAG,
"Failed to allocate effect data of size %u", num_leds);
43 memset(this->
buf_, 0, 4);
47 esph_log_config(TAG,
"SPI LED Strip:");
48 esph_log_config(TAG,
" LEDs: %d", this->
num_leds_);
50 esph_log_config(TAG,
" Data rate: %uMHz", (
unsigned) (this->
data_rate_ / 1000000));
52 esph_log_config(TAG,
" Data rate: %ukHz", (
unsigned) (this->
data_rate_ / 1000));
59 if (ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE) {
61 size_t len = std::min(this->
buffer_size_, (
size_t) (
sizeof(strbuf) - 1) / 3);
62 memset(strbuf, 0,
sizeof(strbuf));
63 for (
size_t i = 0; i !=
len; i++) {
64 sprintf(strbuf + i * 3,
"%02X ", this->
buf_[i]);
66 esph_log_v(TAG,
"write_state: buf = %s", strbuf);
74 for (
int i = 0; i < this->
size(); i++)
80 size_t pos = index * 4 + 5;
81 return {this->
buf_ + pos + 2, this->
buf_ + pos + 1, this->
buf_ + pos + 0,
nullptr,
void write_state(light::LightState *state) override
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
void set_num_leds(uint16_t num_leds)
void spi_setup() override
light::LightTraits get_traits() override
The SPIDevice is what components using the SPI will create.
int32_t size() const override
This class is used to represent the capabilities of a light.
light::ESPColorView get_view_internal(int32_t index) const override
ESPColorCorrection correction_
virtual void mark_failed()
Mark this component as failed.
void write_array(const uint8_t *data, size_t length)
Implementation of SPI Controller mode.
void dump_config() override
Color can be controlled using RGB format (includes a brightness control for the color).
void clear_effect_data() override
An STL allocator that uses SPI or internal RAM.