ESPHome 2026.10.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_; }
41 auto traits = light::LightTraits();
43 ? traits.set_supported_color_modes({light::ColorMode::RGB_WHITE, light::ColorMode::WHITE})
44 : traits.set_supported_color_modes({light::ColorMode::RGB});
45 return traits;
46 }
47 void set_pin(uint8_t pin) { this->pin_ = pin; }
48 void set_num_leds(uint32_t num_leds) { this->num_leds_ = num_leds; }
49 void set_channel_colors(light::ChannelColors channel_colors) { this->channel_colors_ = channel_colors; }
50
51 void set_max_refresh_rate(float interval_us) { this->max_refresh_rate_ = interval_us; }
52
53 void set_pio(int pio_num) { pio_num ? this->pio_ = pio1 : this->pio_ = pio0; }
54 void set_program(const pio_program_t *program) { this->program_ = program; }
55 void set_init_function(init_fn init) { this->init_ = init; }
56
57 void set_chipset(Chipset chipset) { this->chipset_ = chipset; };
58 void clear_effect_data() override {
59 for (int i = 0; i < this->size(); i++) {
60 this->effect_data_[i] = 0;
61 }
62 }
63
64 void dump_config() override;
65
66 protected:
67 light::ESPColorView get_view_internal(int32_t index) const override;
68
69 size_t get_buffer_size_() const { return this->num_leds_ * this->channel_colors_.bytes_per_led(); }
70
71 static void dma_write_complete_handler();
72
73 uint8_t *buf_{nullptr};
74 uint8_t *effect_data_{nullptr};
75
76 uint8_t pin_;
78
79 pio_hw_t *pio_;
80 uint sm_;
82 dma_channel_config dma_config_;
83
86
89
90 const pio_program_t *program_;
92
93 private:
94 inline static int num_instance[2];
95 inline static std::map<Chipset, bool> conf_count;
96 inline static std::map<Chipset, int> chipset_offsets;
97 inline static bool dma_chan_active[12];
98 inline static struct semaphore dma_write_complete_sem[12];
99};
100
101} // namespace esphome::rp2040_pio_led_strip
102
103#endif // USE_RP2
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition light_state.h:93
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
void set_channel_colors(light::ChannelColors channel_colors)
Definition led_strip.h:49
void write_state(light::LightState *state) override
bool state
Definition fan.h:2
@ RGB_WHITE
RGB color output and a separate white output.
@ RGB
RGB color output.
@ WHITE
White output only (use only if the light also has another color mode such as RGB).
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.
static constexpr uint8_t NO_WHITE
Value of w for a strip that only has red, green and blue channels.