diff --git a/firmware/lux.cpp b/firmware/lux.cpp index dfa771f..d5d8e3c 100644 --- a/firmware/lux.cpp +++ b/firmware/lux.cpp @@ -14,7 +14,6 @@ extern "C" { #include } -const int cs0 = 15; struct apa10xx_pixel_t { struct { @@ -70,6 +69,7 @@ namespace fiatlux { hal_module_t gpio2 = hal_module_t::NONE; hal_module_t gpio4 = hal_module_t::NONE; hal_module_t gpio5 = hal_module_t::NONE; + hal_module_t gpio15 = hal_module_t::NONE; } namespace signal { @@ -99,41 +99,43 @@ namespace fiatlux { } namespace spi_dimmer { + constexpr int cs0 = 15; + void write_data(uint16_t data[6]) { for (int i = 0; i < 6; ++i) { int dac_val = (data[i] << 2) & 0x3FFC; spi_transfer_8(1, ~(0x00)); - gpio_write(cs0, 1); - gpio_write(cs0, 0); + gpio_write(cs0, true); + gpio_write(cs0, false); spi_transfer_8(1, ~(0x01 << i)); - gpio_write(cs0, 1); - gpio_write(cs0, 0); + gpio_write(cs0, true); + gpio_write(cs0, false); spi_transfer_16(1, dac_val); spi_transfer_8(1, ~(0x00)); - gpio_write(cs0, 1); - gpio_write(cs0, 0); + gpio_write(cs0, true); + gpio_write(cs0, false); spi_transfer_8(1, ~(0x01 << i)); - gpio_write(cs0, 1); - gpio_write(cs0, 0); + gpio_write(cs0, true); + gpio_write(cs0, false); } } void setup() { + gpio_enable(cs0, GPIO_OUTPUT); spi_init(1, SPI_MODE0, SPI_FREQ_DIV_1M, 1, SPI_BIG_ENDIAN, 1); } } namespace ws28x { - void write_data(ws2812_pixel_t *data, size_t len) { - ws2812_i2s_init(len, PIXEL_RGBW); + void write_data(ws2812_pixel_t *data) { 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); for (size_t i = 0; i < len; 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); } @@ -173,7 +177,7 @@ namespace fiatlux { } else if(mod == hal_module_t::WS28X) { if(stride != 4) 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) { if(stride != 4) return "unsupported value for stride"; @@ -236,10 +240,10 @@ extern "C" [[noreturn]] void lux_task(void *pvParameters) { if(ret != SYSPARAM_OK) 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); if(ret != SYSPARAM_OK) - lux_apa10xx_number = 8; + lux_apa10xx_number = 40; ws2812_pixel_t pixels[lux_ws2812_number]; 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(10, GPIO_INPUT); - //gpio_enable(cs0, GPIO_OUTPUT); //fiatlux::spi_dimmer::setup(); fiatlux::signal::setup();