fix wsled build
This commit is contained in:
@@ -9,5 +9,6 @@ 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
|
||||||
|
REQUIRES esp_driver_spi
|
||||||
INCLUDE_DIRS "."
|
INCLUDE_DIRS "."
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
|
||||||
#include "esp_ws28xx.h"
|
#include "wsled.h"
|
||||||
|
|
||||||
|
#include "esp_heap_caps.h"
|
||||||
|
|
||||||
uint16_t* dmaBuffer;
|
uint16_t* dmaBuffer;
|
||||||
CRGB* wsledPixels;
|
CRGB* wsledPixels;
|
||||||
@@ -28,7 +30,7 @@ static spi_settings_t spiSettings = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint16_t timing_bits[16] = {
|
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};
|
||||||
|
|
||||||
@@ -36,24 +38,24 @@ esp_err_t wsledInit(wsled_t* dev, CRGB** buffer) {
|
|||||||
|
|
||||||
type = dev->type;
|
type = dev->type;
|
||||||
ledCount = dev->numLeds;
|
ledCount = dev->numLeds;
|
||||||
resetDelay = (dev.wsledType == WS2812B) ? WSLED_12_RESET_TIME : WSLED_15_RESET_TIME;
|
resetDelay = (dev->type == WS2812B) ? WSLED_12_RESET_TIME : WSLED_15_RESET_TIME;
|
||||||
|
|
||||||
// 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 = dev->numLeds * 12 + (resetDelay + 1) * 2;
|
dmaBufferSize = ledCount * 12 + (resetDelay + 1) * 2;
|
||||||
wsledPixels = malloc(sizeof(CRGB) * dev->numLeds);
|
wsledPixels = malloc(sizeof(CRGB) * ledCount);
|
||||||
if (wsledPixels == NULL) {
|
if (wsledPixels == NULL) {
|
||||||
return ESP_ERR_NO_MEM;
|
return ESP_ERR_NO_MEM;
|
||||||
}
|
}
|
||||||
*buffer = wsledPixels;
|
*buffer = wsledPixels;
|
||||||
spi_settings.buscfg.mosi_io_num = pin;
|
spiSettings.buscfg.mosi_io_num = dev->pin;
|
||||||
spi_settings.buscfg.max_transfer_sz = dmaBufferSize;
|
spiSettings.buscfg.max_transfer_sz = dmaBufferSize;
|
||||||
|
|
||||||
if (ESP_OK != spi_bus_initialize(spi_settings.host, &spi_settings.buscfg, spi_settings.dma_chan)) {
|
if (ESP_OK != spi_bus_initialize(spiSettings.host, &spiSettings.buscfg, spiSettings.dma_chan)) {
|
||||||
free(wsledPixels);
|
free(wsledPixels);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ESP_OK != spi_bus_add_device(spi_settings.host, &spi_settings.devcfg, &spi_settings.spi)) {
|
if (ESP_OK != spi_bus_add_device(spiSettings.host, &spiSettings.devcfg, &spiSettings.spi)) {
|
||||||
free(wsledPixels);
|
free(wsledPixels);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -66,8 +68,8 @@ esp_err_t wsledInit(wsled_t* dev, CRGB** buffer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void wsledFill(CRGB color) {
|
void wsledFill(CRGB color) {
|
||||||
for (int i = 0; i < n_of_leds; i++) {
|
for (int i = 0; i < ledCount; i++) {
|
||||||
ws28xx_pixels[i] = color;
|
wsledPixels[i] = color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,16 +94,16 @@ esp_err_t wsledUpdate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Red
|
// Red
|
||||||
dmaBuffer[n++] = timing_bits[0x0f & (packedData >> 4)];
|
dmaBuffer[n++] = timingBits[0x0f & (packedData >> 4)];
|
||||||
dmaBuffer[n++] = timing_bits[0x0f & (packedData)];
|
dmaBuffer[n++] = timingBits[0x0f & (packedData)];
|
||||||
|
|
||||||
// Green
|
// Green
|
||||||
dmaBuffer[n++] = timing_bits[0x0f & (packedData >> 12)];
|
dmaBuffer[n++] = timingBits[0x0f & (packedData >> 12)];
|
||||||
dmaBuffer[n++] = timing_bits[0x0f & (packedData) >> 8];
|
dmaBuffer[n++] = timingBits[0x0f & (packedData) >> 8];
|
||||||
|
|
||||||
// Blue
|
// Blue
|
||||||
dma_buffer[n++] = timing_bits[0x0f & (packedData >> 20)];
|
dmaBuffer[n++] = timingBits[0x0f & (packedData >> 20)];
|
||||||
dma_buffer[n++] = timing_bits[0x0f & (packedData) >> 16];
|
dmaBuffer[n++] = timingBits[0x0f & (packedData) >> 16];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +112,7 @@ esp_err_t wsledUpdate() {
|
|||||||
dmaBuffer[n++] = 0;
|
dmaBuffer[n++] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t error = spi_device_transmit(spi_settings.spi, &(spi_transaction_t) {
|
esp_err_t error = spi_device_transmit(spiSettings.spi, &(spi_transaction_t) {
|
||||||
.length = dmaBufferSize * 8,
|
.length = dmaBufferSize * 8,
|
||||||
.tx_buffer = dmaBuffer,
|
.tx_buffer = dmaBuffer,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -28,11 +28,6 @@ typedef struct {
|
|||||||
spi_bus_config_t buscfg;
|
spi_bus_config_t buscfg;
|
||||||
} spi_settings_t;
|
} spi_settings_t;
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
WS2812B = 0,
|
|
||||||
WS2815,
|
|
||||||
} led_strip_model_t;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
gpio_num_t pin;
|
gpio_num_t pin;
|
||||||
WsledType type;
|
WsledType type;
|
||||||
|
|||||||
Reference in New Issue
Block a user