16#include "led_strip_rmt.h"
17#include "led_strip_types.h"
19#include "freertos/FreeRTOS.h"
20#include "freertos/semphr.h"
28constexpr uint16_t MAX_PIXELS = 1024;
30led_strip_handle_t s_handle =
nullptr;
33uint8_t s_format = 0xFF;
35SemaphoreHandle_t
mutex()
37 static SemaphoreHandle_t m = xSemaphoreCreateMutex();
48led_pixel_format_t map_format(uint8_t fmt,
bool& has_white)
56 default:
return LED_PIXEL_FORMAT_INVALID;
60int create_strip(uint8_t gpio, uint16_t count, uint8_t format)
62 bool has_white =
false;
63 led_pixel_format_t pf = map_format(format, has_white);
66 led_strip_config_t cfg{};
67 cfg.strip_gpio_num = gpio;
69 cfg.led_pixel_format = pf;
70 cfg.led_model = LED_MODEL_WS2812;
72 led_strip_rmt_config_t rmt{};
73 rmt.clk_src = RMT_CLK_SRC_DEFAULT;
74 rmt.resolution_hz = 10 * 1000 * 1000;
75 rmt.mem_block_symbols = 64;
76 rmt.flags.with_dma = 0;
78 led_strip_handle_t h =
nullptr;
79 if (led_strip_new_rmt_device(&cfg, &rmt, &h) != ESP_OK)
return HOST_ERR_GENERIC;
90 led_strip_clear(s_handle);
91 led_strip_del(s_handle);
102 explicit Lock(SemaphoreHandle_t s) : m(s), ok(xSemaphoreTake(s, pdMS_TO_TICKS(100)) == pdTRUE) {}
103 ~Lock() {
if (ok) xSemaphoreGive(m); }
121 if (s_handle && s_gpio == gpio_pin && s_count == num_pixels && s_format == format) {
125 return create_strip(gpio_pin, num_pixels, format);
153 for (uint16_t i = 0; i < s_count; ++i) {
154 if (led_strip_set_pixel(s_handle, i, r, g, b) != ESP_OK)
return HOST_ERR_GENERIC;
187 if (!l.ok)
return false;
188 return s_handle !=
nullptr;
Single source of truth for plugin-accessible GPIO pins.
Owned WAMR module instance + per-plugin state.
const PluginManifest & manifest() const noexcept
#define PIXEL_FORMAT_GRBW
int host_pixel_strip_refresh(void)
Push the strip buffer out over the RMT bus.
int host_pixel_strip_clear(void)
Clear every pixel to off (0, 0, 0).
uint16_t host_pixel_strip_length(void)
Number of pixels the strip was initialised with.
#define PIXEL_FORMAT_RGBW
int host_pixel_strip_fill(uint8_t r, uint8_t g, uint8_t b)
Fill every pixel with the same RGB colour.
int host_pixel_strip_set(uint16_t index, uint8_t r, uint8_t g, uint8_t b)
Set one pixel's RGB colour in the strip buffer.
int host_pixel_strip_init(uint8_t gpio_pin, uint16_t num_pixels, uint8_t format)
Initialise or reconfigure the global pixel strip.
int host_pixel_strip_deinit(void)
Tear down the global pixel strip.
bool host_pixel_strip_ready(void)
True when the strip has been successfully initialised.
CDC Badge OS plugin host API - canonical C ABI contract.
#define HOST_ERR_NO_CAPABILITY
#define HOST_ERR_INVALID_ARG
void * plg_get_active_plugin(void)
bool isAllowed(uint8_t pin)
PluginCapabilities capabilities