diff --git a/extras/ws2812_i2s/ws2812_i2s.c b/extras/ws2812_i2s/ws2812_i2s.c index 62dc496..c0ac747 100644 --- a/extras/ws2812_i2s/ws2812_i2s.c +++ b/extras/ws2812_i2s/ws2812_i2s.c @@ -24,6 +24,7 @@ #include "ws2812_i2s.h" #include "i2s_dma/i2s_dma.h" +#include #include #include @@ -156,10 +157,25 @@ const IRAM_DATA int16_t bitpatterns[16] = 0b1110111010001000, 0b1110111010001110, 0b1110111011101000, 0b1110111011101110, }; -void ws2812_i2s_update(ws2812_pixel_t *pixels, pixeltype_t type) +#define WAIT_SAMPLE (280UL + 3UL * dma_buffer_size) + +int ws2812_i2s_update(ws2812_pixel_t *pixels, pixeltype_t type) { while (i2s_dma_processing) {}; + if (i2s_dma_processing) + { + return -1; //Busy + } + //TODO: Found a better way to prevent this. i2s_dma_processing work like intended ?? + //This is to set minimum time between two i2s_update when executed following + static uint32_t time = 0; + if (sdk_system_get_time() < (time + WAIT_SAMPLE)) + { + return -1; //Busy + } + time = sdk_system_get_time(); + uint16_t *p_dma_buf = dma_buffer; for (uint32_t i = 0; i < (dma_buffer_size / type); i++) { @@ -184,4 +200,5 @@ void ws2812_i2s_update(ws2812_pixel_t *pixels, pixeltype_t type) i2s_dma_processing = true; i2s_dma_start(dma_block_list); + return 0; } diff --git a/extras/ws2812_i2s/ws2812_i2s.h b/extras/ws2812_i2s/ws2812_i2s.h index ffb2701..18a5a7f 100644 --- a/extras/ws2812_i2s/ws2812_i2s.h +++ b/extras/ws2812_i2s/ws2812_i2s.h @@ -60,8 +60,9 @@ void ws2812_i2s_init(uint32_t pixels_number, pixeltype_t type); * * @param pixels Array of 'pixels_number' pixels. The array must contain all * the pixels. + * @return Non-zero if busy */ -void ws2812_i2s_update(ws2812_pixel_t *pixels, pixeltype_t type); +int ws2812_i2s_update(ws2812_pixel_t *pixels, pixeltype_t type); #ifdef __cplusplus }