quick fix to prevent two ws2812_update that follow each other
This commit is contained in:
parent
f67495f4f0
commit
9317995eb1
2 changed files with 20 additions and 2 deletions
|
@ -24,6 +24,7 @@
|
|||
#include "ws2812_i2s.h"
|
||||
#include "i2s_dma/i2s_dma.h"
|
||||
|
||||
#include <espressif/esp_common.h>
|
||||
#include <string.h>
|
||||
#include <malloc.h>
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue