diff --git a/extras/ws2812_i2s/ws2812_i2s.c b/extras/ws2812_i2s/ws2812_i2s.c index 88caf27..9ad06ff 100644 --- a/extras/ws2812_i2s/ws2812_i2s.c +++ b/extras/ws2812_i2s/ws2812_i2s.c @@ -177,23 +177,33 @@ void ws2812_i2s_update(ws2812_pixel_t *pixels, pixeltype_t type) uint16_t *p_dma_buf = dma_buffer; for (uint32_t i = 0; i < (dma_buffer_size / type); i++) { - // green - *p_dma_buf++ = bitpatterns[pixels[i].green & 0x0F]; - *p_dma_buf++ = bitpatterns[pixels[i].green >> 4]; - - // red - *p_dma_buf++ = bitpatterns[pixels[i].red & 0x0F]; - *p_dma_buf++ = bitpatterns[pixels[i].red >> 4]; - - // blue - *p_dma_buf++ = bitpatterns[pixels[i].blue & 0x0F]; - *p_dma_buf++ = bitpatterns[pixels[i].blue >> 4]; - +#ifdef I2S_COLOR_WHITE_FIRST if(type == PIXEL_RGBW) { // white *p_dma_buf++ = bitpatterns[pixels[i].white & 0x0F]; *p_dma_buf++ = bitpatterns[pixels[i].white >> 4]; } +#endif + + // I2S_COLOR_FIRST, normally green + *p_dma_buf++ = bitpatterns[pixels[i].I2S_COLOR_FIRST & 0x0F]; + *p_dma_buf++ = bitpatterns[pixels[i].I2S_COLOR_FIRST >> 4]; + + // I2S_COLOR_SECOND, normally red + *p_dma_buf++ = bitpatterns[pixels[i].I2S_COLOR_SECOND & 0x0F]; + *p_dma_buf++ = bitpatterns[pixels[i].I2S_COLOR_SECOND >> 4]; + + // I2S_COLOR_THIRD, normally blue + *p_dma_buf++ = bitpatterns[pixels[i].I2S_COLOR_THIRD & 0x0F]; + *p_dma_buf++ = bitpatterns[pixels[i].I2S_COLOR_THIRD >> 4]; + +#ifndef I2S_COLOR_WHITE_FIRST + if(type == PIXEL_RGBW) { + // white + *p_dma_buf++ = bitpatterns[pixels[i].white & 0x0F]; + *p_dma_buf++ = bitpatterns[pixels[i].white >> 4]; + } +#endif } i2s_dma_processing = true; diff --git a/extras/ws2812_i2s/ws2812_i2s.h b/extras/ws2812_i2s/ws2812_i2s.h index c6c8df5..7ebf473 100644 --- a/extras/ws2812_i2s/ws2812_i2s.h +++ b/extras/ws2812_i2s/ws2812_i2s.h @@ -46,6 +46,57 @@ typedef enum { PIXEL_RGBW = 16 } pixeltype_t; +#define I2S_COLOR_PROFILE_N_RGB 1 +#define I2S_COLOR_PROFILE_N_RBG 2 +#define I2S_COLOR_PROFILE_N_GBR 3 +#define I2S_COLOR_PROFILE_N_GRB 4 +#define I2S_COLOR_PROFILE_N_BGR 5 +#define I2S_COLOR_PROFILE_N_BRG 6 + +#ifndef I2S_COLOR_PROFILE + +#if defined(I2S_COLOR_PROFILE_BRG) +#define I2S_COLOR_PROFILE I2S_COLOR_PROFILE_N_BRG +#elif defined(I2S_COLOR_PROFILE_RBG) +#define I2S_COLOR_PROFILE I2S_COLOR_PROFILE_N_RBG +#elif defined(I2S_COLOR_PROFILE_GBR) +#define I2S_COLOR_PROFILE I2S_COLOR_PROFILE_N_GBR +#elif defined(I2S_COLOR_PROFILE_RGB) +#define I2S_COLOR_PROFILE I2S_COLOR_PROFILE_N_RGB +#elif defined(I2S_COLOR_PROFILE_BGR) +#define I2S_COLOR_PROFILE I2S_COLOR_PROFILE_N_BGR +#else +#define I2S_COLOR_PROFILE I2S_COLOR_PROFILE_N_GRB +#endif + +#endif + +#if I2S_COLOR_PROFILE == I2S_COLOR_PROFILE_N_RGB +#define I2S_COLOR_FIRST red +#define I2S_COLOR_SECOND green +#define I2S_COLOR_THIRD blue +#elif I2S_COLOR_PROFILE == I2S_COLOR_PROFILE_N_RBG +#define I2S_COLOR_FIRST red +#define I2S_COLOR_SECOND blue +#define I2S_COLOR_THIRD green +#elif I2S_COLOR_PROFILE == I2S_COLOR_PROFILE_N_GBR +#define I2S_COLOR_FIRST green +#define I2S_COLOR_SECOND blue +#define I2S_COLOR_THIRD red +#elif I2S_COLOR_PROFILE == I2S_COLOR_PROFILE_N_GRB +#define I2S_COLOR_FIRST green +#define I2S_COLOR_SECOND red +#define I2S_COLOR_THIRD blue +#elif I2S_COLOR_PROFILE == I2S_COLOR_PROFILE_N_BGR +#define I2S_COLOR_FIRST blue +#define I2S_COLOR_SECOND green +#define I2S_COLOR_THIRD red +#else +#define I2S_COLOR_FIRST blue +#define I2S_COLOR_SECOND red +#define I2S_COLOR_THIRD green +#endif + /** * Initialize i2s and dma subsystems to work with ws2812 led strip. *