diff options
Diffstat (limited to 'src/drv/ws2812B/ws2812b.c')
-rw-r--r-- | src/drv/ws2812B/ws2812b.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/drv/ws2812B/ws2812b.c b/src/drv/ws2812B/ws2812b.c new file mode 100644 index 0000000..e1e9309 --- /dev/null +++ b/src/drv/ws2812B/ws2812b.c @@ -0,0 +1,55 @@ +#include "drv/ws2812B/ws2812b.h" + +#include "kern/mem.h" +#include "kern/panic.h" +#include "kern/dma/dma_manager.h" +#include "arch/stm32l4xxx/peripherals/spi.h" + +uint8_t* ws2812b_compile_rgb(rgb_t* out_, size_t arr_len) +{ + uint8_t* out = (uint8_t*) out_; + uint8_t* spi_out = kalloc(arr_len * 9); + + if (!spi_out) { + panic("Unable to allocate spi_out\n"); + } + + size_t i; + size_t j; + + for (i = 0, j = 0; i < arr_len * 3; ++i, j += 3) { + // stuff + uint8_t c = out[i]; + spi_out[j] = 0 + | (1 << 7) + | ((c & (1 << 7)) << 6) + | (0 << 5) + | (1 << 4) + | ((c & (1 << 6)) << 3) + | (0 << 2) + | (1 << 1) + | ((c & (1 << 5)) << 0); + + spi_out[j + 1] = 0 + | (0 << 7) + | (1 << 6) + | ((c & (1 << 4)) << 5) + | (0 << 4) + | (1 << 3) + | ((c & (1 << 3)) << 2) + | (0 << 1) + | (1 << 0); + + spi_out[j + 2] = 0 + | ((c & (1 << 2)) << 7) + | (0 << 6) + | (1 << 5) + | ((c & (1 << 1)) << 4) + | (0 << 3) + | (1 << 2) + | ((c & (1 << 0)) << 1) + | (0 << 0); + } + + return spi_out; +} |