From d0e88c9dae9e6382d15714a5e7c93d5a44a7f62f Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 24 May 2023 17:24:48 +0200 Subject: [PATCH] Fix BusyDelay WS2812 --- tasmota/tasmota_support/support.ino | 5 ++--- tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_leds.ino | 4 +++- tasmota/tasmota_xlgt_light/xlgt_01_ws2812.ino | 7 ++++++- tasmota/tasmota_xsns_sensor/xsns_02_analog.ino | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/tasmota/tasmota_support/support.ino b/tasmota/tasmota_support/support.ino index e7bad295e..a6f426be8 100755 --- a/tasmota/tasmota_support/support.ino +++ b/tasmota/tasmota_support/support.ino @@ -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; } } diff --git a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_leds.ino b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_leds.ino index f8327c68b..c3af02426 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_leds.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_leds.ino @@ -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()); diff --git a/tasmota/tasmota_xlgt_light/xlgt_01_ws2812.ino b/tasmota/tasmota_xlgt_light/xlgt_01_ws2812.ino index 8dd87f738..13032fdf8 100644 --- a/tasmota/tasmota_xlgt_light/xlgt_01_ws2812.ino +++ b/tasmota/tasmota_xlgt_light/xlgt_01_ws2812.ino @@ -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) diff --git a/tasmota/tasmota_xsns_sensor/xsns_02_analog.ino b/tasmota/tasmota_xsns_sensor/xsns_02_analog.ino index 4351b12aa..59c469d12 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_02_analog.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_02_analog.ino @@ -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;