17 spi_bus_config_t bus = {};
18 bus.mosi_io_num = this->
pin_;
19 bus.miso_io_num = bus.sclk_io_num = bus.quadwp_io_num = bus.quadhd_io_num = -1;
20 if (!this->
setup_check(spi_bus_initialize(SPI2_HOST, &bus, SPI_DMA_DISABLED) == ESP_OK,
21 LOG_STR(
"SPI bus init failed")))
23 spi_device_interface_config_t dev = {};
24 dev.clock_speed_hz = 100000;
25 dev.spics_io_num = -1;
26 dev.queue_size = NUM_ZONES;
27 if (!this->
setup_check(spi_bus_add_device(SPI2_HOST, &dev, &this->
dev_) == ESP_OK, LOG_STR(
"SPI device init failed")))
34 "BrizLabs two-wire LED string:\n"
35 " Data (SPI MOSI): GPIO%d\n"
37 this->
pin_, NUM_ZONES);
47 t.length = (
encode(frame, 0, zone, 0xFF, r, g, b) + 7) & ~7u;
49 esp_err_t err = spi_device_queue_trans(this->
dev_, &t, 0);
53 ESP_LOGW(TAG,
"queue frame: %s", esp_err_to_name(err));
64 for (
int z = 0;
z < NUM_ZONES;
z++) {
65 const uint8_t *p = this->
buf_ +
z * 3;
66 uniform &= memcmp(p, this->
buf_, 3) == 0;
70 for (
int z = 0;
z < NUM_ZONES;
z++) {
71 const uint8_t *p = this->
buf_ +
z * 3;
84 spi_transaction_t *
done;
85 while (this->
in_flight_ > 0 && spi_device_get_trans_result(this->
dev_, &done, 0) == ESP_OK)
bool status_comm_result(bool ok)
Clears the warning when ok, else sets it with message (default "Communication failed"); returns ok.
bool ESPHOME_ALWAYS_INLINE setup_check(bool ok)
Marks the component failed with message (default "Communication failed") unless ok; returns ok.
bool status_has_warning() const
void dump_config() override
uint8_t frames_[NUM_ZONES][FRAME_BYTES]
bool queue_frame_(uint8_t zone, uint8_t r, uint8_t g, uint8_t b)
light::CorrectedBufferColorAccessor internal_accessor_
spi_transaction_t trans_[NUM_ZONES]
void write_state(light::LightState *state) override
uint8_t buf_[NUM_ZONES *3]
ESPColorAccessor * accessor_
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
ESPHOME_LOG_TAG(TAG, "brizlabs_led_string")
size_t encode(uint8_t *out, uint8_t id, uint8_t zone, uint8_t hdr, uint8_t r, uint8_t g, uint8_t b)