Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions extras/ws2812_i2s/ws2812_i2s.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
#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

// red
*p_dma_buf++ = bitpatterns[pixels[i].red & 0x0F];
*p_dma_buf++ = bitpatterns[pixels[i].red >> 4];
// 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];

// blue
*p_dma_buf++ = bitpatterns[pixels[i].blue & 0x0F];
*p_dma_buf++ = bitpatterns[pixels[i].blue >> 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;
Expand Down
51 changes: 51 additions & 0 deletions extras/ws2812_i2s/ws2812_i2s.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down