Fix BusyDelay WS2812

This commit is contained in:
Theo Arends 2023-05-24 17:24:48 +02:00
parent fc67cca8b4
commit d0e88c9dae
4 changed files with 12 additions and 6 deletions

View File

@ -2210,7 +2210,7 @@ bool TimeReachedUsec(uint32_t timer)
return (passed >= 0);
}
void SystemSetBusy(uint32_t busy) {
void SystemBusyDelay(uint32_t busy) {
/*
TasmotaGlobal.busy_time = millis();
SetNextTimeInterval(TasmotaGlobal.busy_time, busy +1);
@ -2221,7 +2221,7 @@ void SystemSetBusy(uint32_t busy) {
TasmotaGlobal.busy_time = busy;
}
void SystemWaitIfBusy(void) {
void SystemBusyDelayExecute(void) {
if (TasmotaGlobal.busy_time) {
/*
// Calls to millis() interrupt RMT and defeats our goal
@ -2230,7 +2230,6 @@ void SystemWaitIfBusy(void) {
}
*/
delay(TasmotaGlobal.busy_time);
TasmotaGlobal.busy_time = 0;
}
}

View File

@ -136,7 +136,9 @@ extern "C" {
case 2: // # 02 : show void -> void
if (s_ws2812_grb) s_ws2812_grb->Show();
if (s_sk6812_grbw) s_sk6812_grbw->Show();
SystemSetBusy(4);
// Wait for RMT/I2S to complete fixes distortion due to analogRead
// delay(5);
SystemBusyDelay(5); // Max 256 leds
break;
case 3: // # 03 : CanShow void -> bool
if (s_ws2812_grb) be_pushbool(vm, s_ws2812_grb->CanShow());

View File

@ -214,7 +214,12 @@ long wsmap(long x, long in_min, long in_max, long out_min, long out_max) {
void Ws2812LibStripShow(void) {
strip->Show();
SystemSetBusy(Settings->light_pixels >> 2); // 256 / 64 = 4
#if defined(USE_WS2812_DMA) || defined(USE_WS2812_RMT) || defined(USE_WS2812_I2S)
// Wait for DMA/RMT/I2S to complete fixes distortion due to analogRead
// delay((Settings->light_pixels >> 6) +1); // 256 / 64 = 4 +1 = 5
SystemBusyDelay((Settings->light_pixels >> 6) +1); // 256 / 64 = 4 +1 = 5
#endif
}
void Ws2812StripShow(void)

View File

@ -317,7 +317,7 @@ uint16_t AdcRead(uint32_t pin, uint32_t factor) {
// factor 3 = 8 samples
// factor 4 = 16 samples
// factor 5 = 32 samples
SystemWaitIfBusy();
SystemBusyDelayExecute();
uint32_t samples = 1 << factor;
uint32_t analog = 0;