stash
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
j3d1 2021-11-18 03:31:26 +01:00
parent 4b23e5bc09
commit 22b240a472

View file

@ -14,7 +14,6 @@
extern "C" { extern "C" {
#include <sysparam.h> #include <sysparam.h>
} }
const int cs0 = 15;
struct apa10xx_pixel_t { struct apa10xx_pixel_t {
struct { struct {
@ -70,6 +69,7 @@ namespace fiatlux {
hal_module_t gpio2 = hal_module_t::NONE; hal_module_t gpio2 = hal_module_t::NONE;
hal_module_t gpio4 = hal_module_t::NONE; hal_module_t gpio4 = hal_module_t::NONE;
hal_module_t gpio5 = hal_module_t::NONE; hal_module_t gpio5 = hal_module_t::NONE;
hal_module_t gpio15 = hal_module_t::NONE;
} }
namespace signal { namespace signal {
@ -99,41 +99,43 @@ namespace fiatlux {
} }
namespace spi_dimmer { namespace spi_dimmer {
constexpr int cs0 = 15;
void write_data(uint16_t data[6]) { void write_data(uint16_t data[6]) {
for (int i = 0; i < 6; ++i) { for (int i = 0; i < 6; ++i) {
int dac_val = (data[i] << 2) & 0x3FFC; int dac_val = (data[i] << 2) & 0x3FFC;
spi_transfer_8(1, ~(0x00)); spi_transfer_8(1, ~(0x00));
gpio_write(cs0, 1); gpio_write(cs0, true);
gpio_write(cs0, 0); gpio_write(cs0, false);
spi_transfer_8(1, ~(0x01 << i)); spi_transfer_8(1, ~(0x01 << i));
gpio_write(cs0, 1); gpio_write(cs0, true);
gpio_write(cs0, 0); gpio_write(cs0, false);
spi_transfer_16(1, dac_val); spi_transfer_16(1, dac_val);
spi_transfer_8(1, ~(0x00)); spi_transfer_8(1, ~(0x00));
gpio_write(cs0, 1); gpio_write(cs0, true);
gpio_write(cs0, 0); gpio_write(cs0, false);
spi_transfer_8(1, ~(0x01 << i)); spi_transfer_8(1, ~(0x01 << i));
gpio_write(cs0, 1); gpio_write(cs0, true);
gpio_write(cs0, 0); gpio_write(cs0, false);
} }
} }
void setup() { void setup() {
gpio_enable(cs0, GPIO_OUTPUT);
spi_init(1, SPI_MODE0, SPI_FREQ_DIV_1M, 1, SPI_BIG_ENDIAN, 1); spi_init(1, SPI_MODE0, SPI_FREQ_DIV_1M, 1, SPI_BIG_ENDIAN, 1);
} }
} }
namespace ws28x { namespace ws28x {
void write_data(ws2812_pixel_t *data, size_t len) { void write_data(ws2812_pixel_t *data) {
ws2812_i2s_init(len, PIXEL_RGBW);
ws2812_i2s_update(data, PIXEL_RGBW); ws2812_i2s_update(data, PIXEL_RGBW);
} }
void setup() { void setup(size_t len) {
ws2812_i2s_init(len, PIXEL_RGBW);
} }
} }
@ -142,6 +144,8 @@ namespace fiatlux {
spi_transfer_32(1, 0x00000000); spi_transfer_32(1, 0x00000000);
for (size_t i = 0; i < len; i++) for (size_t i = 0; i < len; i++)
spi_transfer_32(1, *(uint32_t *) &data[i]); spi_transfer_32(1, *(uint32_t *) &data[i]);
//spi_transfer_32(1, *(uint32_t *) &data[len - 1]); // dunno maybe this helps
//spi_transfer_32(1, *(uint32_t *) &data[len - 1]); // dunno maybe this helps
spi_transfer_32(1, 0xFFFFFFFF); spi_transfer_32(1, 0xFFFFFFFF);
spi_transfer_32(1, 0xFFFFFFFF); spi_transfer_32(1, 0xFFFFFFFF);
} }
@ -173,7 +177,7 @@ namespace fiatlux {
} else if(mod == hal_module_t::WS28X) { } else if(mod == hal_module_t::WS28X) {
if(stride != 4) if(stride != 4)
return "unsupported value for stride"; return "unsupported value for stride";
ws28x::write_data((ws2812_pixel_t *) data, count); ws28x::write_data((ws2812_pixel_t *) data);
} else if(mod == hal_module_t::APA10X) { } else if(mod == hal_module_t::APA10X) {
if(stride != 4) if(stride != 4)
return "unsupported value for stride"; return "unsupported value for stride";
@ -236,10 +240,10 @@ extern "C" [[noreturn]] void lux_task(void *pvParameters) {
if(ret != SYSPARAM_OK) if(ret != SYSPARAM_OK)
lux_ws2812_number = 8; lux_ws2812_number = 8;
int32_t lux_apa10xx_number = 8; int32_t lux_apa10xx_number = 40;
ret = sysparam_get_int32("lux_apa10xx_number", &lux_apa10xx_number); ret = sysparam_get_int32("lux_apa10xx_number", &lux_apa10xx_number);
if(ret != SYSPARAM_OK) if(ret != SYSPARAM_OK)
lux_apa10xx_number = 8; lux_apa10xx_number = 40;
ws2812_pixel_t pixels[lux_ws2812_number]; ws2812_pixel_t pixels[lux_ws2812_number];
ws2812_i2s_init(lux_ws2812_number, PIXEL_RGBW); ws2812_i2s_init(lux_ws2812_number, PIXEL_RGBW);
@ -252,7 +256,6 @@ extern "C" [[noreturn]] void lux_task(void *pvParameters) {
//gpio_enable(9, GPIO_INPUT); //gpio_enable(9, GPIO_INPUT);
//gpio_enable(10, GPIO_INPUT); //gpio_enable(10, GPIO_INPUT);
//gpio_enable(cs0, GPIO_OUTPUT);
//fiatlux::spi_dimmer::setup(); //fiatlux::spi_dimmer::setup();
fiatlux::signal::setup(); fiatlux::signal::setup();