8 #include <hardware/clocks.h> 9 #include <hardware/pio.h> 10 #include <pico/stdlib.h> 13 namespace rp2040_pio_led_strip {
15 static const char *TAG =
"rp2040_pio_led_strip";
18 ESP_LOGCONFIG(TAG,
"Setting up RP2040 LED Strip...");
24 if (this->
buf_ ==
nullptr) {
25 ESP_LOGE(TAG,
"Failed to allocate buffer of size %u", buffer_size);
32 ESP_LOGE(TAG,
"Failed to allocate effect data of size %u", this->
num_leds_);
39 if (this->
pio_ ==
nullptr) {
40 ESP_LOGE(TAG,
"Failed to claim PIO instance");
46 uint offset = pio_add_program(this->
pio_, this->
program_);
49 this->
sm_ = pio_claim_unused_sm(this->
pio_,
true);
51 ESP_LOGE(TAG,
"Failed to claim PIO state machine");
59 ESP_LOGVV(TAG,
"Writing state...");
62 ESP_LOGW(TAG,
"Light is in failed state, not writing state.");
66 if (this->
buf_ ==
nullptr) {
67 ESP_LOGW(TAG,
"Buffer is null, not writing state.");
72 for (
int i = 0; i < this->
num_leds_; i++) {
73 uint8_t multiplier = this->
is_rgbw_ ? 4 : 3;
74 uint8_t c1 = this->
buf_[(i * multiplier) + 0];
75 uint8_t c2 = this->
buf_[(i * multiplier) + 1];
76 uint8_t c3 = this->
buf_[(i * multiplier) + 2];
77 uint8_t w = this->
is_rgbw_ ? this->
buf_[(i * 4) + 3] : 0;
79 pio_sm_put_blocking(this->
pio_, this->
sm_, color);
84 int32_t r = 0, g = 0, b = 0, w = 0;
117 uint8_t multiplier = this->
is_rgbw_ ? 4 : 3;
118 return {this->
buf_ + (index * multiplier) + r,
119 this->
buf_ + (index * multiplier) + g,
120 this->
buf_ + (index * multiplier) + b,
121 this->
is_rgbw_ ? this->
buf_ + (index * multiplier) + 3 :
nullptr,
127 ESP_LOGCONFIG(TAG,
"RP2040 PIO LED Strip Light Output:");
128 ESP_LOGCONFIG(TAG,
" Pin: GPIO%d", this->
pin_);
129 ESP_LOGCONFIG(TAG,
" Number of LEDs: %d", this->
num_leds_);
130 ESP_LOGCONFIG(TAG,
" RGBW: %s", YESNO(this->
is_rgbw_));
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
void write_state(light::LightState *state) override
An STL allocator that uses SPI RAM.
constexpr uint32_t encode_uint32(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4)
Encode a 32-bit value given four bytes in most to least significant byte order.
void dump_config() override
const char * rgb_order_to_string(RGBOrder order)
const pio_program_t * program_
light::ESPColorView get_view_internal(int32_t index) const override
float get_setup_priority() const override
size_t get_buffer_size_() const
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
ESPColorCorrection correction_
virtual void mark_failed()
Mark this component as failed.
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...