working wsled driver checkpoint
This commit is contained in:
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
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "SsdInterface.hpp"
|
#include "SsdInterface.hpp"
|
||||||
#include "pins.hpp"
|
#include "pins.hpp"
|
||||||
|
#include "drivers/wsled.h"
|
||||||
|
|
||||||
DemoTask::DemoTask() {
|
DemoTask::DemoTask() {
|
||||||
|
|
||||||
@@ -17,8 +18,16 @@ void DemoTask::run() {
|
|||||||
|
|
||||||
ESP_LOGI(__FILE__, "Demo Task: run()");
|
ESP_LOGI(__FILE__, "Demo Task: run()");
|
||||||
|
|
||||||
ssd_595_t dev = { gpio_ssd_data, gpio_ssd_clk, gpio_ssd_latch, true };
|
// ssd device
|
||||||
SsdInterface ssd(&dev, ssdDigits);
|
ssd_595_t ssdDev = { gpio_ssd_data, gpio_ssd_clk, gpio_ssd_latch, true };
|
||||||
|
SsdInterface ssd(&ssdDev, ssdDigits);
|
||||||
|
|
||||||
|
// wsled device
|
||||||
|
size_t ledCount = 4;
|
||||||
|
wsled_t wsledDev = { gpio_ws2812b, WS2812B, ledCount};
|
||||||
|
// 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;
|
||||||
@@ -28,6 +37,16 @@ void DemoTask::run() {
|
|||||||
digit++;
|
digit++;
|
||||||
if(digit >= 16) digit = 0;
|
if(digit >= 16) digit = 0;
|
||||||
|
|
||||||
|
//ledBuffer[0] = CRGB{100, 0, 80};
|
||||||
|
wsledFill(CRGB{100, 20, 20});
|
||||||
|
wsledUpdate();
|
||||||
|
|
||||||
|
vTaskDelay(delay / portTICK_PERIOD_MS);
|
||||||
|
|
||||||
|
//ledBuffer[0] = CRGB{0, 0, 10};
|
||||||
|
wsledFill(CRGB{20, 20, 100});
|
||||||
|
wsledUpdate();
|
||||||
|
|
||||||
vTaskDelay(delay / portTICK_PERIOD_MS);
|
vTaskDelay(delay / portTICK_PERIOD_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,17 @@
|
|||||||
#include "wsled.h"
|
#include "wsled.h"
|
||||||
|
|
||||||
#include "esp_heap_caps.h"
|
#include "esp_heap_caps.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
uint16_t* dmaBuffer;
|
uint16_t* dmaBuffer;
|
||||||
CRGB* wsledPixels;
|
CRGB* wsledPixels;
|
||||||
static int ledCount, resetDelay, dmaBufferSize;
|
static uint32_t ledCount;
|
||||||
|
static uint32_t resetDelay;
|
||||||
|
static size_t dmaBufferSize;
|
||||||
WsledType type;
|
WsledType type;
|
||||||
|
|
||||||
static spi_settings_t spiSettings = {
|
static spi_settings_t spiSettings = {
|
||||||
@@ -26,7 +33,7 @@ static spi_settings_t spiSettings = {
|
|||||||
.queue_size = 1,
|
.queue_size = 1,
|
||||||
.command_bits = 0,
|
.command_bits = 0,
|
||||||
.address_bits = 0,
|
.address_bits = 0,
|
||||||
.flags = SPI_DEVICE_TXBIT_LSBFIRST,
|
//.flags = SPI_DEVICE_TXBIT_LSBFIRST,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -36,41 +43,54 @@ static const uint16_t timingBits[16] = {
|
|||||||
|
|
||||||
esp_err_t wsledInit(wsled_t* dev, CRGB** buffer) {
|
esp_err_t wsledInit(wsled_t* dev, CRGB** buffer) {
|
||||||
|
|
||||||
|
ESP_LOGI(__FILE__, "Initializing wsled device...");
|
||||||
|
|
||||||
type = dev->type;
|
type = dev->type;
|
||||||
ledCount = dev->numLeds;
|
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);
|
||||||
|
|
||||||
// 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 = ledCount * 12 + (resetDelay + 1) * 2;
|
||||||
wsledPixels = malloc(sizeof(CRGB) * ledCount);
|
wsledPixels = malloc(sizeof(CRGB) * ledCount);
|
||||||
if (wsledPixels == NULL) {
|
if (wsledPixels == NULL) {
|
||||||
|
ESP_LOGI(__FILE__, "Allocating memory failed");
|
||||||
return ESP_ERR_NO_MEM;
|
return ESP_ERR_NO_MEM;
|
||||||
}
|
}
|
||||||
*buffer = wsledPixels;
|
*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;
|
||||||
|
|
||||||
|
ESP_LOGI(__FILE__, "Initializing spi interface...");
|
||||||
if (ESP_OK != spi_bus_initialize(spiSettings.host, &spiSettings.buscfg, spiSettings.dma_chan)) {
|
if (ESP_OK != spi_bus_initialize(spiSettings.host, &spiSettings.buscfg, spiSettings.dma_chan)) {
|
||||||
free(wsledPixels);
|
free(wsledPixels);
|
||||||
|
ESP_LOGI(__FILE__, "SPI initialization failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ESP_LOGI(__FILE__, "Adding spi bus device...");
|
||||||
if (ESP_OK != spi_bus_add_device(spiSettings.host, &spiSettings.devcfg, &spiSettings.spi)) {
|
if (ESP_OK != spi_bus_add_device(spiSettings.host, &spiSettings.devcfg, &spiSettings.spi)) {
|
||||||
free(wsledPixels);
|
free(wsledPixels);
|
||||||
|
ESP_LOGI(__FILE__, "Failed to add spi bus device");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL == heap_caps_malloc(dmaBufferSize, MALLOC_CAP_DMA)) {
|
ESP_LOGI(__FILE__, "heap_caps_malloc() with dmaBufferSize=%u...", dmaBufferSize);
|
||||||
|
dmaBuffer = heap_caps_malloc(dmaBufferSize, MALLOC_CAP_DMA);
|
||||||
|
if (NULL == dmaBuffer) {
|
||||||
free(wsledPixels);
|
free(wsledPixels);
|
||||||
|
ESP_LOGI(__FILE__, "Failed to heap_caps_malloc");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wsledFill(CRGB color) {
|
esp_err_t wsledFill(CRGB color) {
|
||||||
for (int i = 0; i < ledCount; i++) {
|
for (int i = 0; i < ledCount; i++) {
|
||||||
wsledPixels[i] = color;
|
wsledPixels[i] = color;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t wsledUpdate() {
|
esp_err_t wsledUpdate() {
|
||||||
@@ -82,28 +102,23 @@ esp_err_t wsledUpdate() {
|
|||||||
|
|
||||||
for (int i = 0; i < ledCount; i++) {
|
for (int i = 0; i < ledCount; i++) {
|
||||||
|
|
||||||
// Data you want to write to each LEDs
|
|
||||||
|
|
||||||
CRGB currentPixel = wsledPixels[i];
|
CRGB currentPixel = wsledPixels[i];
|
||||||
|
|
||||||
uint32_t packedData;
|
uint8_t b0 = (type == WS2812B) ? currentPixel.g : currentPixel.r;
|
||||||
if(type == WS2812B) { // different models have different color orders
|
uint8_t b1 = (type == WS2812B) ? currentPixel.r : currentPixel.g;
|
||||||
packedData = currentPixel.g | ((uint32_t)currentPixel.r << 8) | ((uint32_t)currentPixel.b << 16) | ((uint32_t)(0x00) << 24);
|
uint8_t b2 = currentPixel.b;
|
||||||
} else {
|
|
||||||
packedData = currentPixel.r | ((uint32_t)currentPixel.g << 8) | ((uint32_t)currentPixel.b << 16) | ((uint32_t)(0x00) << 24);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Red
|
|
||||||
dmaBuffer[n++] = timingBits[0x0f & (packedData >> 4)];
|
|
||||||
dmaBuffer[n++] = timingBits[0x0f & (packedData)];
|
|
||||||
|
|
||||||
// Green
|
// Green
|
||||||
dmaBuffer[n++] = timingBits[0x0f & (packedData >> 12)];
|
dmaBuffer[n++] = timingBits[(b0 >> 4) & 0x0F];
|
||||||
dmaBuffer[n++] = timingBits[0x0f & (packedData) >> 8];
|
dmaBuffer[n++] = timingBits[b0 & 0x0F];
|
||||||
|
|
||||||
|
// Red
|
||||||
|
dmaBuffer[n++] = timingBits[(b1 >> 4) & 0x0F];
|
||||||
|
dmaBuffer[n++] = timingBits[b1 & 0x0F];
|
||||||
|
|
||||||
// Blue
|
// Blue
|
||||||
dmaBuffer[n++] = timingBits[0x0f & (packedData >> 20)];
|
dmaBuffer[n++] = timingBits[(b2 >> 4) & 0x0F];
|
||||||
dmaBuffer[n++] = timingBits[0x0f & (packedData) >> 16];
|
dmaBuffer[n++] = timingBits[b2 & 0x0F];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,4 +132,8 @@ esp_err_t wsledUpdate() {
|
|||||||
.tx_buffer = dmaBuffer,
|
.tx_buffer = dmaBuffer,
|
||||||
});
|
});
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -6,9 +6,13 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define WSLED_12_RESET_TIME 3
|
#define WSLED_12_RESET_TIME 30
|
||||||
#define WSLED_15_RESET_TIME 30
|
#define WSLED_15_RESET_TIME 30
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t r;
|
uint8_t r;
|
||||||
uint8_t g;
|
uint8_t g;
|
||||||
@@ -37,6 +41,10 @@ typedef struct {
|
|||||||
esp_err_t wsledInit(wsled_t* dev, CRGB** buffer);
|
esp_err_t wsledInit(wsled_t* dev, CRGB** buffer);
|
||||||
|
|
||||||
// test function
|
// test function
|
||||||
esp_err_t wsledFillAll(CRGB color);
|
esp_err_t wsledFill(CRGB color);
|
||||||
|
|
||||||
esp_err_t wsledUpdate();
|
esp_err_t wsledUpdate();
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user