flesh out wsled interface

This commit is contained in:
2026-02-14 13:19:41 -06:00
parent 99e73d5d6b
commit e3090bf1f5
6 changed files with 49 additions and 44 deletions

View File

@@ -13,8 +13,8 @@ Scripts are in scripts directory, named appropriately.
- [x] Build setup, get working hello-world program. - [x] Build setup, get working hello-world program.
- [x] Develop 7-segment display driver for the soburg-v2 board, which uses 32-bit shift registers. - [x] Develop 7-segment display driver for the soburg-v2 board, which uses 32-bit shift registers.
Ensures functional hardware interaction and interface design. Ensures functional hardware interaction and interface design.
- [ ] Develop WS2812b driver, would be nice to have some kind of testing for this. - [x] Develop WS2812b driver, would be nice to have some kind of testing for this.
- [ ] Develop WS2812b interface. I like the FastLed library for Arduino so might have a lot of similar functionality. - [x] Develop WS2812b interface. I like the FastLed library for Arduino so might have a lot of similar functionality.
- [ ] Implement proper app structure, with error checking and performance profiling - [ ] Implement proper app structure, with error checking and performance profiling
- [ ] Add a couple LED effects- the random blink and rainbow sweep are easy ones. - [ ] Add a couple LED effects- the random blink and rainbow sweep are easy ones.
- [ ] Create a mock LED panel that executes natively to test LED effects outside of hardware. (SDL2 or something) - [ ] Create a mock LED panel that executes natively to test LED effects outside of hardware. (SDL2 or something)

View File

@@ -7,8 +7,8 @@
#include "esp_log.h" #include "esp_log.h"
#include "SsdInterface.hpp" #include "SsdInterface.hpp"
#include "WsledInterface.hpp"
#include "pins.hpp" #include "pins.hpp"
#include "drivers/wsled.h"
DemoTask::DemoTask() { DemoTask::DemoTask() {
@@ -23,11 +23,8 @@ void DemoTask::run() {
SsdInterface ssd(&ssdDev, ssdDigits); SsdInterface ssd(&ssdDev, ssdDigits);
// wsled device // wsled device
size_t ledCount = 4; wsled_t wsledDev = { gpio_ws2812b, WS2812B, 0 /* fixed */};
wsled_t wsledDev = { gpio_ws2812b, WS2812B, ledCount}; WsledInterface wsled(&wsledDev);
// TODO: wsled interface
CRGB ledBuffer[4];
wsledInit(&wsledDev, (CRGB**)&ledBuffer);
uint32_t delay = 500; // ms uint32_t delay = 500; // ms
uint8_t digit = 0; uint8_t digit = 0;
@@ -37,15 +34,13 @@ void DemoTask::run() {
digit++; digit++;
if(digit >= 16) digit = 0; if(digit >= 16) digit = 0;
//ledBuffer[0] = CRGB{100, 0, 80}; wsled.fill(CRGB{100, 20, 20});
wsledFill(CRGB{100, 20, 20}); wsled.flush();
wsledUpdate();
vTaskDelay(delay / portTICK_PERIOD_MS); vTaskDelay(delay / portTICK_PERIOD_MS);
//ledBuffer[0] = CRGB{0, 0, 10}; wsled.fill(CRGB{20, 20, 100});
wsledFill(CRGB{20, 20, 100}); wsled.flush();
wsledUpdate();
vTaskDelay(delay / portTICK_PERIOD_MS); vTaskDelay(delay / portTICK_PERIOD_MS);
} }

View File

@@ -3,19 +3,36 @@
WsledInterface::WsledInterface(const wsled_t* device) { WsledInterface::WsledInterface(const wsled_t* device) {
(void)wsledInit(device);
} }
STATUS WsledInterface::writePixel(CRGB pixel, size_t index) { STATUS WsledInterface::writePixel(CRGB pixel, size_t index) {
leds_[index] = pixel;
return OKAY; return OKAY;
} }
STATUS WsledInterface::get(CRGB* pixel, size_t index) { STATUS WsledInterface::get(CRGB* pixel, size_t index) {
*pixel = leds_[index];
return OKAY; return OKAY;
} }
STATUS WsledInterface::flush() { STATUS WsledInterface::flush() {
wsledUpdate(leds_, numLeds_);
return OKAY;
}
STATUS WsledInterface::fill(CRGB color) {
for (size_t i = 0; i < numLeds_; i++) {
leds_[i] = color;
}
return OKAY; return OKAY;
} }

View File

@@ -27,6 +27,15 @@ public:
// Returns: execution status // Returns: execution status
STATUS flush(); STATUS flush();
// Below are the helper functions for manipulating the led buffer
// Fills the buffer with a single color
// Returns: execution status
STATUS fill(CRGB color);
// getter for numLeds_
size_t ledCount() { return numLeds_; }
private: private:
const wsled_t* device_; const wsled_t* device_;

View File

@@ -8,12 +8,11 @@
extern "C" { extern "C" {
#endif #endif
uint16_t* dmaBuffer; static uint16_t* dmaBuffer;
CRGB* wsledPixels; static CRGB* wsledPixels; // delete
static uint32_t ledCount; static uint32_t resetDelay; // delete
static uint32_t resetDelay; static size_t dmaBufferSize; // delete
static size_t dmaBufferSize; static WsledType type; // delete
WsledType type;
static spi_settings_t spiSettings = { static spi_settings_t spiSettings = {
.host = SPI2_HOST, .host = SPI2_HOST,
@@ -41,24 +40,18 @@ static const uint16_t timingBits[16] = {
0x1111, 0x7111, 0x1711, 0x7711, 0x1171, 0x7171, 0x1771, 0x7771, 0x1111, 0x7111, 0x1711, 0x7711, 0x1171, 0x7171, 0x1771, 0x7771,
0x1117, 0x7117, 0x1717, 0x7717, 0x1177, 0x7177, 0x1777, 0x7777}; 0x1117, 0x7117, 0x1717, 0x7717, 0x1177, 0x7177, 0x1777, 0x7777};
esp_err_t wsledInit(wsled_t* dev, CRGB** buffer) { esp_err_t wsledInit(const wsled_t* dev) {
ESP_LOGI(__FILE__, "Initializing wsled device..."); ESP_LOGI(__FILE__, "Initializing wsled device...");
type = dev->type; type = dev->type;
ledCount = dev->numLeds;
resetDelay = (dev->type == WS2812B) ? WSLED_12_RESET_TIME : WSLED_15_RESET_TIME; resetDelay = (dev->type == WS2812B) ? WSLED_12_RESET_TIME : WSLED_15_RESET_TIME;
ESP_LOGI(__FILE__, "mallocing the wsledPixel buffer with size %u bytes", sizeof(CRGB) * ledCount); ESP_LOGI(__FILE__, "mallocing the wsledPixel buffer with size %u bytes", sizeof(CRGB) * dev->numLeds);
// 12 bytes for each led + bytes for initial zero and reset state // 12 bytes for each led + bytes for initial zero and reset state
dmaBufferSize = ledCount * 12 + (resetDelay + 1) * 2; dmaBufferSize = dev->numLeds * 12 + (resetDelay + 1) * 2;
wsledPixels = malloc(sizeof(CRGB) * ledCount);
if (wsledPixels == NULL) {
ESP_LOGI(__FILE__, "Allocating memory failed");
return ESP_ERR_NO_MEM;
}
*buffer = wsledPixels;
spiSettings.buscfg.mosi_io_num = dev->pin; spiSettings.buscfg.mosi_io_num = dev->pin;
spiSettings.buscfg.max_transfer_sz = dmaBufferSize; spiSettings.buscfg.max_transfer_sz = dmaBufferSize;
@@ -86,14 +79,7 @@ esp_err_t wsledInit(wsled_t* dev, CRGB** buffer) {
return ESP_OK; return ESP_OK;
} }
esp_err_t wsledFill(CRGB color) { esp_err_t wsledUpdate(const CRGB* pixels, size_t ledCount) {
for (int i = 0; i < ledCount; i++) {
wsledPixels[i] = color;
}
return 0;
}
esp_err_t wsledUpdate() {
uint32_t n = 0; uint32_t n = 0;
@@ -102,7 +88,7 @@ esp_err_t wsledUpdate() {
for (int i = 0; i < ledCount; i++) { for (int i = 0; i < ledCount; i++) {
CRGB currentPixel = wsledPixels[i]; CRGB currentPixel = pixels[i];
uint8_t b0 = (type == WS2812B) ? currentPixel.g : currentPixel.r; uint8_t b0 = (type == WS2812B) ? currentPixel.g : currentPixel.r;
uint8_t b1 = (type == WS2812B) ? currentPixel.r : currentPixel.g; uint8_t b1 = (type == WS2812B) ? currentPixel.r : currentPixel.g;

View File

@@ -38,12 +38,10 @@ typedef struct {
uint32_t numLeds; uint32_t numLeds;
} wsled_t; } wsled_t;
esp_err_t wsledInit(wsled_t* dev, CRGB** buffer); // initializes the wsled device provided the device settings
esp_err_t wsledInit(const wsled_t* dev);
// test function esp_err_t wsledUpdate(const CRGB* pixels, size_t ledCount);
esp_err_t wsledFill(CRGB color);
esp_err_t wsledUpdate();
#ifdef __cplusplus #ifdef __cplusplus
} }