ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
led_strip.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef USE_RP2
4
8
12
13#include <hardware/dma.h>
14#include <hardware/pio.h>
15#include <hardware/structs/pio.h>
16#include <pico/stdio.h>
17#include <pico/sem.h>
18#include <map>
19
21
30
31using init_fn = void (*)(PIO pio, uint sm, uint offset, uint pin, float freq);
32
34 public:
35 void setup() override;
36 void write_state(light::LightState *state) override;
37 float get_setup_priority() const override;
38
39 int32_t size() const override { return this->num_leds_; }
40 light::LightTraits get_traits() override { return this->channel_colors_.traits(); }
41 void set_pin(uint8_t pin) { this->pin_ = pin; }
42 void set_num_leds(uint32_t num_leds) { this->num_leds_ = num_leds; }
43 void set_channel_colors(light::ChannelColors channel_colors) { this->channel_colors_ = channel_colors; }
44
45 void set_max_refresh_rate(float interval_us) { this->max_refresh_rate_ = interval_us; }
46
47 void set_pio(int pio_num) { pio_num ? this->pio_ = pio1 : this->pio_ = pio0; }
48 void set_program(const pio_program_t *program) { this->program_ = program; }
49 void set_init_function(init_fn init) { this->init_ = init; }
50
51 void set_chipset(Chipset chipset) { this->chipset_ = chipset; };
52 void clear_effect_data() override {
53 if (this->effect_data_ != nullptr)
54 memset(this->effect_data_, 0, this->num_leds_);
55 }
56
57 void dump_config() override;
58
59 protected:
60 light::ESPColorView get_view_internal(int32_t index) const override {
61 return this->channel_colors_.view(this->buf_, this->effect_data_, index, &this->correction_);
62 }
63
64 size_t get_buffer_size_() const { return this->num_leds_ * this->channel_colors_.bytes_per_led(); }
65
66 static void dma_write_complete_handler();
67
68 uint8_t *buf_{nullptr};
69 uint8_t *effect_data_{nullptr};
70
71 uint8_t pin_;
73
74 pio_hw_t *pio_;
75 uint sm_;
77 dma_channel_config dma_config_;
78
81
83
84 const pio_program_t *program_;
86
87 private:
88 inline static int num_instance[2];
89 inline static std::map<Chipset, bool> conf_count;
90 inline static std::map<Chipset, int> chipset_offsets;
91 inline static bool dma_chan_active[12];
92 inline static struct semaphore dma_write_complete_sem[12];
93};
94
95} // namespace esphome::rp2040_pio_led_strip
96
97#endif // USE_RP2
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition light_state.h:68
This class is used to represent the capabilities of a light.
Definition light_traits.h:9
light::ESPColorView get_view_internal(int32_t index) const override
Definition led_strip.h:60
void set_channel_colors(light::ChannelColors channel_colors)
Definition led_strip.h:43
void write_state(light::LightState *state) override
bool state
Definition fan.h:2
void(*)(PIO pio, uint sm, uint offset, uint pin, float freq) init_fn
Definition led_strip.h:31
static void uint32_t
Which byte of an addressable LED's data carries each colour.
ESPColorView view(uint8_t *buf, uint8_t *effect_data, int32_t index, const ESPColorCorrection *correction) const
View of LED index in buf; a scratch pixel while buf or effect_data is unallocated (failed setup()).
static constexpr uint8_t NO_WHITE
Value of w for a strip that only has red, green and blue channels.
LightTraits traits() const
Colour modes of a strip with this channel order.