added modified spi_led_strip with support for WS2801 LED strips

This commit is contained in:
2026-10-30 09:10:13 +01:00
commit b4d00f8ff8
5 changed files with 264 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/core/log.h"
#include "esphome/components/light/addressable_light.h"
#include "esphome/components/spi/spi.h"
namespace esphome::spi_led_strip {
ESPHOME_LOG_TAG(TAG, "spi_led_strip");
enum class SpiLedChipset : uint8_t {
// 4-byte start frame, then 0xFF + B, G, R per LED, then a 4-byte end frame
SPI_LED_CHIPSET_APA102,
// R, G, B per LED, no framing; the data is latched when the clock stays low for 500 us
SPI_LED_CHIPSET_WS2801,
};
class SpiLedStrip final : public light::AddressableLight,
public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_HIGH,
spi::CLOCK_PHASE_TRAILING, spi::DATA_RATE_1MHZ> {
public:
SpiLedStrip(uint16_t num_leds, SpiLedChipset chipset);
void setup() override;
float get_setup_priority() const override { return setup_priority::IO; }
int32_t size() const override { return this->num_leds_; }
light::LightTraits get_traits() override;
void dump_config() override;
void write_state(light::LightState *state) override;
void clear_effect_data() override { memset(this->effect_data_, 0, this->num_leds_ * sizeof(this->effect_data_[0])); }
protected:
light::ESPColorView get_view_internal(int32_t index) const override;
size_t buffer_size_{};
uint8_t *effect_data_{nullptr};
uint8_t *buf_{nullptr};
uint16_t num_leds_;
SpiLedChipset chipset_;
};
} // namespace esphome::spi_led_strip