Compare commits
9 Commits
1248a0ac39
...
36788ac5a6
| Author | SHA1 | Date | |
|---|---|---|---|
| 36788ac5a6 | |||
| 335452cc6d | |||
| 532d93d5d7 | |||
| e3090bf1f5 | |||
| 99e73d5d6b | |||
| 4f333435ea | |||
| 9f884b41e7 | |||
| bb8dcd76b2 | |||
| 7a2f701653 |
@@ -5,7 +5,11 @@ set(PROJECT_MAIN_COMPONENT ${CMAKE_CURRENT_LIST_DIR}/src)
|
|||||||
|
|
||||||
set(EXTRA_COMPONENT_DIRS
|
set(EXTRA_COMPONENT_DIRS
|
||||||
${CMAKE_CURRENT_LIST_DIR}/config
|
${CMAKE_CURRENT_LIST_DIR}/config
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src
|
${CMAKE_CURRENT_LIST_DIR}/src/drivers
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/src/main
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/src/tasks
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/src/ssd
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/src/wsled
|
||||||
)
|
)
|
||||||
|
|
||||||
# For the esp-idf configuration
|
# For the esp-idf configuration
|
||||||
|
|||||||
12
README.md
12
README.md
@@ -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)
|
||||||
@@ -35,3 +35,11 @@ After cloning: $ ./scripts/repo-setup # installs esp-idf, sets up target configu
|
|||||||
To build: $ ./scripts/build.sh\
|
To build: $ ./scripts/build.sh\
|
||||||
To flash: $ ./scripts/flash.sh # note: flash.sh automatically builds\
|
To flash: $ ./scripts/flash.sh # note: flash.sh automatically builds\
|
||||||
To monitor: $ ./scripts/monitor.sh\
|
To monitor: $ ./scripts/monitor.sh\
|
||||||
|
|
||||||
|
## TODOs for developers
|
||||||
|
- [ ] Move all hardware specifications to config/Kconfig.projbuild file. (things like NUM_LEDS, pins.h, ssd_digits, etc.)
|
||||||
|
- [ ] Create an effect base class for effects to inherit from
|
||||||
|
- [ ] Attach interrupts for hardware inputs
|
||||||
|
- [ ] Human I/O (like from buttons, knobs) needs to be in its own io task. Other tasks will be injected with a general I/O interface
|
||||||
|
- [ ] Investigate putting the wsled task on a separate core from io and such
|
||||||
|
- [ ] Wsled interface needs a platform for matrix creation
|
||||||
|
|||||||
1
scripts/build.sh
Normal file → Executable file
1
scripts/build.sh
Normal file → Executable file
@@ -8,6 +8,7 @@ export IDF_PATH=${PWD}/lib/esp-idf
|
|||||||
export SDKCONFIG=${PWD}/config/sdkconfig
|
export SDKCONFIG=${PWD}/config/sdkconfig
|
||||||
export SDKCONFIG_DEFAULTS=${PWD}/config/sdkconfig.defaults
|
export SDKCONFIG_DEFAULTS=${PWD}/config/sdkconfig.defaults
|
||||||
|
|
||||||
|
export IDF_PATH_FORCE=1
|
||||||
. ${IDF_PATH}/export.sh
|
. ${IDF_PATH}/export.sh
|
||||||
|
|
||||||
idf.py set-target esp32s3
|
idf.py set-target esp32s3
|
||||||
|
|||||||
1
scripts/flash.sh
Normal file → Executable file
1
scripts/flash.sh
Normal file → Executable file
@@ -8,6 +8,7 @@ export IDF_PATH=${PWD}/lib/esp-idf
|
|||||||
export SDKCONFIG=${PWD}/config/sdkconfig
|
export SDKCONFIG=${PWD}/config/sdkconfig
|
||||||
export SDKCONFIG_DEFAULTS=${PWD}/config/sdkconfig.defaults
|
export SDKCONFIG_DEFAULTS=${PWD}/config/sdkconfig.defaults
|
||||||
|
|
||||||
|
export IDF_PATH_FORCE=1
|
||||||
. ${IDF_PATH}/export.sh
|
. ${IDF_PATH}/export.sh
|
||||||
|
|
||||||
idf.py fullclean
|
idf.py fullclean
|
||||||
|
|||||||
1
scripts/monitor.sh
Normal file → Executable file
1
scripts/monitor.sh
Normal file → Executable file
@@ -5,6 +5,7 @@ set -e
|
|||||||
export IDF_TOOLS_PATH=${PWD}/lib/idf-tools
|
export IDF_TOOLS_PATH=${PWD}/lib/idf-tools
|
||||||
export IDF_PATH=${PWD}/lib/esp-idf
|
export IDF_PATH=${PWD}/lib/esp-idf
|
||||||
|
|
||||||
|
export IDF_PATH_FORCE=1
|
||||||
. ${IDF_PATH}/export.sh
|
. ${IDF_PATH}/export.sh
|
||||||
|
|
||||||
idf.py -b 115200 monitor
|
idf.py -b 115200 monitor
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
|
|
||||||
#include "DemoTask.hpp"
|
|
||||||
|
|
||||||
#include "driver/gpio.h"
|
|
||||||
#include "freertos/FreeRTOS.h"
|
|
||||||
#include "freertos/task.h"
|
|
||||||
#include "esp_log.h"
|
|
||||||
|
|
||||||
#include "SsdInterface.hpp"
|
|
||||||
#include "pins.hpp"
|
|
||||||
|
|
||||||
DemoTask::DemoTask() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void DemoTask::run() {
|
|
||||||
|
|
||||||
ESP_LOGI(__FILE__, "Demo Task: run()");
|
|
||||||
|
|
||||||
ssd_595_t dev = { gpio_ssd_data, gpio_ssd_clk, gpio_ssd_latch, true };
|
|
||||||
SsdInterface ssd(&dev, ssdDigits);
|
|
||||||
|
|
||||||
uint32_t delay = 500; // ms
|
|
||||||
uint8_t digit = 0;
|
|
||||||
|
|
||||||
while(1) {
|
|
||||||
ssd.writeRaw(&digitMap[digit], 1);
|
|
||||||
digit++;
|
|
||||||
if(digit >= 16) digit = 0;
|
|
||||||
|
|
||||||
vTaskDelay(delay / portTICK_PERIOD_MS);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -2,12 +2,11 @@
|
|||||||
file(GLOB SRC_FILES
|
file(GLOB SRC_FILES
|
||||||
"*.c"
|
"*.c"
|
||||||
"*.cpp"
|
"*.cpp"
|
||||||
"drivers/*.c"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
idf_component_register(
|
idf_component_register(
|
||||||
SRCS ${SRC_FILES}
|
SRCS ${SRC_FILES}
|
||||||
PRIV_REQUIRES spi_flash
|
PRIV_REQUIRES spi_flash
|
||||||
REQUIRES esp_driver_gpio
|
REQUIRES esp_driver_gpio esp_driver_spi
|
||||||
INCLUDE_DIRS "."
|
INCLUDE_DIRS "."
|
||||||
)
|
)
|
||||||
116
src/drivers/wsled.c
Normal file
116
src/drivers/wsled.c
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
|
||||||
|
#include "wsled.h"
|
||||||
|
|
||||||
|
#include "esp_heap_caps.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static uint16_t* dmaBuffer;
|
||||||
|
static size_t dmaBufferSize;
|
||||||
|
|
||||||
|
static spi_settings_t spiSettings = {
|
||||||
|
.host = SPI2_HOST,
|
||||||
|
.dma_chan = SPI_DMA_CH_AUTO,
|
||||||
|
.buscfg =
|
||||||
|
{
|
||||||
|
.miso_io_num = -1,
|
||||||
|
.sclk_io_num = -1,
|
||||||
|
.quadwp_io_num = -1,
|
||||||
|
.quadhd_io_num = -1,
|
||||||
|
},
|
||||||
|
.devcfg =
|
||||||
|
{
|
||||||
|
.clock_speed_hz = 3.2 * 1000 * 1000, // Clock out at 3.2 MHz
|
||||||
|
.mode = 0, // SPI mode 0
|
||||||
|
.spics_io_num = -1, // CS pin
|
||||||
|
.queue_size = 1,
|
||||||
|
.command_bits = 0,
|
||||||
|
.address_bits = 0,
|
||||||
|
//.flags = SPI_DEVICE_TXBIT_LSBFIRST,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// translations from SPI -> ws2812b protocol
|
||||||
|
// [spi] 0b1110 = [ws2812b]0b1 and [spi] 0b1000 = [ws2812b]0b0
|
||||||
|
static const uint16_t timingBits[16] = {
|
||||||
|
0x1111, 0x7111, 0x1711, 0x7711, 0x1171, 0x7171, 0x1771, 0x7771,
|
||||||
|
0x1117, 0x7117, 0x1717, 0x7717, 0x1177, 0x7177, 0x1777, 0x7777};
|
||||||
|
|
||||||
|
// WS2812b can handle shorter reset delays than the WS2815
|
||||||
|
static inline uint32_t resetDelay(const wsled_t* dev) {
|
||||||
|
return (dev->type == WS2812B) ? WSLED_12_RESET_TIME : WSLED_15_RESET_TIME;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t wsledInit(const wsled_t* dev) {
|
||||||
|
|
||||||
|
// 12 bytes for each led + bytes for initial zero and reset state
|
||||||
|
dmaBufferSize = dev->numLeds * 12 + (resetDelay(dev) + 1) * 2;
|
||||||
|
|
||||||
|
spiSettings.buscfg.mosi_io_num = dev->pin;
|
||||||
|
spiSettings.buscfg.max_transfer_sz = dmaBufferSize;
|
||||||
|
|
||||||
|
if (ESP_OK != spi_bus_initialize(spiSettings.host, &spiSettings.buscfg, spiSettings.dma_chan)) {
|
||||||
|
ESP_LOGI(__FILE__, "SPI initialization failed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ESP_OK != spi_bus_add_device(spiSettings.host, &spiSettings.devcfg, &spiSettings.spi)) {
|
||||||
|
ESP_LOGI(__FILE__, "Failed to add spi bus device");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dmaBuffer = heap_caps_malloc(dmaBufferSize, MALLOC_CAP_DMA);
|
||||||
|
if (NULL == dmaBuffer) {
|
||||||
|
ESP_LOGI(__FILE__, "Failed to heap_caps_malloc");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t wsledUpdate(const wsled_t* dev, const CRGB* pixels, size_t ledCount) {
|
||||||
|
|
||||||
|
uint32_t n = 0;
|
||||||
|
|
||||||
|
memset(dmaBuffer, 0, dmaBufferSize);
|
||||||
|
dmaBuffer[n++] = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < ledCount; i++) {
|
||||||
|
|
||||||
|
CRGB currentPixel = pixels[i];
|
||||||
|
|
||||||
|
uint8_t b0 = (dev->type == WS2812B) ? currentPixel.g : currentPixel.r;
|
||||||
|
uint8_t b1 = (dev->type == WS2812B) ? currentPixel.r : currentPixel.g;
|
||||||
|
uint8_t b2 = currentPixel.b;
|
||||||
|
|
||||||
|
// Green
|
||||||
|
dmaBuffer[n++] = timingBits[(b0 >> 4) & 0x0F];
|
||||||
|
dmaBuffer[n++] = timingBits[b0 & 0x0F];
|
||||||
|
|
||||||
|
// Red
|
||||||
|
dmaBuffer[n++] = timingBits[(b1 >> 4) & 0x0F];
|
||||||
|
dmaBuffer[n++] = timingBits[b1 & 0x0F];
|
||||||
|
|
||||||
|
// Blue
|
||||||
|
dmaBuffer[n++] = timingBits[(b2 >> 4) & 0x0F];
|
||||||
|
dmaBuffer[n++] = timingBits[b2 & 0x0F];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset pulse
|
||||||
|
for (int i = 0; i < resetDelay(dev); i++) {
|
||||||
|
dmaBuffer[n++] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t error = spi_device_transmit(spiSettings.spi, &(spi_transaction_t) {
|
||||||
|
.length = dmaBufferSize * 8,
|
||||||
|
.tx_buffer = dmaBuffer,
|
||||||
|
});
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
49
src/drivers/wsled.h
Normal file
49
src/drivers/wsled.h
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "driver/gpio.h"
|
||||||
|
#include "driver/spi_master.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define WSLED_12_RESET_TIME 5
|
||||||
|
#define WSLED_15_RESET_TIME 30
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t r;
|
||||||
|
uint8_t g;
|
||||||
|
uint8_t b;
|
||||||
|
} CRGB;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
WS2812B = 0,
|
||||||
|
WS2815
|
||||||
|
} WsledType;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
spi_host_device_t host;
|
||||||
|
spi_device_handle_t spi;
|
||||||
|
int dma_chan;
|
||||||
|
spi_device_interface_config_t devcfg;
|
||||||
|
spi_bus_config_t buscfg;
|
||||||
|
} spi_settings_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
gpio_num_t pin;
|
||||||
|
WsledType type;
|
||||||
|
uint32_t numLeds;
|
||||||
|
} wsled_t;
|
||||||
|
|
||||||
|
// initializes the wsled device provided the device settings
|
||||||
|
esp_err_t wsledInit(const wsled_t* dev);
|
||||||
|
|
||||||
|
// outputs the pixel data in pixels to the device
|
||||||
|
esp_err_t wsledUpdate(const wsled_t* dev, const CRGB* pixels, size_t ledCount);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
#include "pins.hpp"
|
#include "shared/pins.h"
|
||||||
|
|
||||||
#include "DemoTask.hpp"
|
#include "DemoTask.hpp"
|
||||||
|
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include<stdint.h>
|
#include<stdint.h>
|
||||||
|
|
||||||
|
// This class is for managing tasks
|
||||||
class App {
|
class App {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -14,8 +15,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
uint32_t ledState = 0;
|
|
||||||
uint32_t blinkTime = 250;
|
|
||||||
const char *TAG = "app"; // TODO: instead of this for logging you can use __FILE__ or __func__
|
const char *TAG = "app"; // TODO: instead of this for logging you can use __FILE__ or __func__
|
||||||
|
|
||||||
};
|
};
|
||||||
10
src/main/CMakeLists.txt
Normal file
10
src/main/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
file(GLOB SRC_FILES
|
||||||
|
"*.c"
|
||||||
|
"*.cpp"
|
||||||
|
)
|
||||||
|
|
||||||
|
idf_component_register(
|
||||||
|
SRCS ${SRC_FILES}
|
||||||
|
INCLUDE_DIRS "." ".."
|
||||||
|
)
|
||||||
12
src/ssd/CMakeLists.txt
Normal file
12
src/ssd/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
file(GLOB SRC_FILES
|
||||||
|
"*.c"
|
||||||
|
"*.cpp"
|
||||||
|
)
|
||||||
|
|
||||||
|
idf_component_register(
|
||||||
|
SRCS ${SRC_FILES}
|
||||||
|
PRIV_REQUIRES spi_flash
|
||||||
|
REQUIRES esp_driver_gpio esp_driver_spi
|
||||||
|
INCLUDE_DIRS "." ".."
|
||||||
|
)
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
|
|
||||||
#include "drivers/ssd.h"
|
#include "drivers/ssd.h"
|
||||||
#include "common.h"
|
#include "shared/common.h"
|
||||||
|
|
||||||
class SsdInterface {
|
class SsdInterface {
|
||||||
|
|
||||||
12
src/tasks/CMakeLists.txt
Normal file
12
src/tasks/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
file(GLOB SRC_FILES
|
||||||
|
"*.c"
|
||||||
|
"*.cpp"
|
||||||
|
)
|
||||||
|
|
||||||
|
idf_component_register(
|
||||||
|
SRCS ${SRC_FILES}
|
||||||
|
PRIV_REQUIRES spi_flash
|
||||||
|
REQUIRES esp_driver_gpio esp_driver_spi
|
||||||
|
INCLUDE_DIRS "." ".."
|
||||||
|
)
|
||||||
46
src/tasks/DemoTask.cpp
Normal file
46
src/tasks/DemoTask.cpp
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
#include "DemoTask.hpp"
|
||||||
|
|
||||||
|
#include "esp_log.h"
|
||||||
|
|
||||||
|
#include "ssd/SsdInterface.hpp"
|
||||||
|
#include "wsled/WsledInterface.hpp"
|
||||||
|
#include "shared/pins.h"
|
||||||
|
|
||||||
|
#define NUM_LEDS 4
|
||||||
|
|
||||||
|
DemoTask::DemoTask() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DemoTask::run() {
|
||||||
|
|
||||||
|
ESP_LOGI(__FILE__, "Demo Task: run()");
|
||||||
|
|
||||||
|
// ssd device
|
||||||
|
ssd_595_t ssdDev = { gpio_ssd_data, gpio_ssd_clk, gpio_ssd_latch, true };
|
||||||
|
SsdInterface ssd(&ssdDev, ssdDigits);
|
||||||
|
|
||||||
|
// wsled device
|
||||||
|
wsled_t wsledDev = { gpio_ws2812b, WS2812B, NUM_LEDS};
|
||||||
|
WsledInterface wsled(&wsledDev);
|
||||||
|
|
||||||
|
uint32_t delay = 500; // ms
|
||||||
|
uint8_t digit = 0;
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
|
||||||
|
// the SSD demo shifts a single hex digit over
|
||||||
|
ssd.writeRaw(&digitMap[digit], 1);
|
||||||
|
digit++;
|
||||||
|
if(digit >= 16) digit = 0;
|
||||||
|
|
||||||
|
// the wsled demo toggles the entire array between red and blue
|
||||||
|
CRGB color = (digit % 2) ? CRGB{100, 20, 20} : CRGB{20, 20, 100};
|
||||||
|
wsled.fill(color);
|
||||||
|
wsled.flush();
|
||||||
|
|
||||||
|
vTaskDelay(delay / portTICK_PERIOD_MS);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
12
src/wsled/CMakeLists.txt
Normal file
12
src/wsled/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
file(GLOB SRC_FILES
|
||||||
|
"*.c"
|
||||||
|
"*.cpp"
|
||||||
|
)
|
||||||
|
|
||||||
|
idf_component_register(
|
||||||
|
SRCS ${SRC_FILES}
|
||||||
|
PRIV_REQUIRES spi_flash
|
||||||
|
REQUIRES esp_driver_gpio esp_driver_spi
|
||||||
|
INCLUDE_DIRS "." ".."
|
||||||
|
)
|
||||||
50
src/wsled/WsledInterface.cpp
Normal file
50
src/wsled/WsledInterface.cpp
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
|
||||||
|
#include "WsledInterface.hpp"
|
||||||
|
|
||||||
|
WsledInterface::WsledInterface(const wsled_t* device) : device_(device), numLeds_(device->numLeds) {
|
||||||
|
|
||||||
|
(void)wsledInit(device);
|
||||||
|
|
||||||
|
// who cares if its dynamically allocated we have like 4 Mb of ram
|
||||||
|
// an led strip 1024 long will use 3kb here and 12kb in the driver for dma
|
||||||
|
leds_.resize(numLeds_);
|
||||||
|
|
||||||
|
// turn all leds off
|
||||||
|
(void)fill(CRGB(0, 0, 0));
|
||||||
|
(void)flush();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
STATUS WsledInterface::writePixel(CRGB pixel, size_t index) {
|
||||||
|
|
||||||
|
// is it really that easy
|
||||||
|
leds_[index] = pixel;
|
||||||
|
|
||||||
|
return OKAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
STATUS WsledInterface::get(CRGB* pixel, size_t index) {
|
||||||
|
|
||||||
|
// I could just return the pixel but im so cool and C coded
|
||||||
|
*pixel = leds_[index];
|
||||||
|
|
||||||
|
return OKAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
STATUS WsledInterface::flush() {
|
||||||
|
|
||||||
|
// man I wrote my driver so well that it really is that easy
|
||||||
|
wsledUpdate(device_, leds_.data(), numLeds_);
|
||||||
|
|
||||||
|
return OKAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
STATUS WsledInterface::fill(CRGB color) {
|
||||||
|
|
||||||
|
// I HATE ITERATORS YOU CAN NEVER MAKE ME USE THEM !!!!
|
||||||
|
for (size_t i = 0; i < numLeds_; i++) {
|
||||||
|
leds_[i] = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OKAY;
|
||||||
|
}
|
||||||
47
src/wsled/WsledInterface.hpp
Normal file
47
src/wsled/WsledInterface.hpp
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "stdint.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "drivers/wsled.h"
|
||||||
|
#include "shared/common.h"
|
||||||
|
|
||||||
|
class WsledInterface {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
WsledInterface(const wsled_t* device);
|
||||||
|
~WsledInterface() = default;
|
||||||
|
|
||||||
|
// Sets a pixel in the leds buffer to a particular color
|
||||||
|
// index: the order in the strip of the pixel
|
||||||
|
// Returns: execution status
|
||||||
|
STATUS writePixel(CRGB pixel, size_t index);
|
||||||
|
|
||||||
|
// Copies the color currently in a pixel to the pointer
|
||||||
|
// index: the order in the strip of the pixel
|
||||||
|
// Returns: execution status
|
||||||
|
STATUS get(CRGB* pixel, size_t index);
|
||||||
|
|
||||||
|
// Writes all the data in the leds buffer to hardware
|
||||||
|
// Returns: execution status
|
||||||
|
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:
|
||||||
|
|
||||||
|
const wsled_t* device_;
|
||||||
|
size_t numLeds_;
|
||||||
|
|
||||||
|
std::vector<CRGB> leds_;
|
||||||
|
|
||||||
|
};
|
||||||
0
src/wsled/effects/.gitkeep
Normal file
0
src/wsled/effects/.gitkeep
Normal file
Reference in New Issue
Block a user