ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
i2s_clockless_led_strip.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef USE_ESP32
4#include <soc/soc_caps.h>
5#endif
6
7#if defined(USE_ESP32) && SOC_I2S_SUPPORTS_TDM
8
9#include <atomic>
10#include <cstdint>
11#include <cstring>
12
14#include "esphome/core/log.h"
17
18#include <driver/i2s_types.h>
19
21
22// Each byte of LED strip data becomes one 24-bit I2S sample
23static constexpr size_t I2S_BYTES_PER_SAMPLE = 3;
25static constexpr size_t i2s_data_offset(uint16_t num_leds, uint8_t bytes_per_led) {
26 return (light::BufferColorAccessor::buffer_bytes(num_leds, bytes_per_led) + 3) / 4 * 4;
27}
29static constexpr size_t buffer_bytes(uint16_t num_leds, uint8_t bytes_per_led) {
30 return i2s_data_offset(num_leds, bytes_per_led) + num_leds * bytes_per_led * I2S_BYTES_PER_SAMPLE;
31}
32
34 public:
36 I2SClocklessLedStrip(uint8_t *buffer, uint8_t pin, uint16_t num_leds, light::ChannelColors channel_colors);
37
38 void dump_config() override;
39
40 float get_setup_priority() const override;
41 void setup() override;
42
44
45 int32_t size() const override { return this->num_leds_; }
47 void write_state(light::LightState *state) override;
48
49 protected:
50 static bool i2s_on_sent_callback(i2s_chan_handle_t handle, i2s_event_data_t *event, void *user_ctx);
51
53 const size_t color_data_bytes_;
54 uint8_t *i2s_data_{nullptr};
55 size_t i2s_data_sent_{0};
56 i2s_chan_handle_t tx_handle_{};
57 const uint16_t num_leds_;
58 const uint8_t pin_;
59 std::atomic<bool> i2s_data_ready_{false};
60};
61
62} // namespace esphome::i2s_clockless_led_strip
63
64#endif
I2SClocklessLedStrip(uint8_t *buffer, uint8_t pin, uint16_t num_leds, light::ChannelColors channel_colors)
buffer is a word aligned block of buffer_bytes().
static bool i2s_on_sent_callback(i2s_chan_handle_t handle, i2s_event_data_t *event, void *user_ctx)
static constexpr size_t buffer_bytes(size_t num_leds, uint8_t bytes_per_led)
The color data of num_leds LEDs followed by one effect byte per LED.
void clear_effect_data(size_t num_leds)
Zero the effect data of the first num_leds LEDs; does nothing before the effect data is allocated.
Color accessor backed by a buffer whose contents have color correction applied.
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition light_state.h:74
This class is used to represent the capabilities of a light.
Definition light_traits.h:9
bool state
Definition fan.h:2
uint32_t buffer
Definition gif.cpp:50
Which byte of an addressable LED's data carries each colour.
LightTraits traits() const
Colour modes of a strip with this channel order.
spi_device_handle_t handle