From 1679790481a80270e6d79bb7fe069cd71fe46488 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Sat, 11 Feb 2023 20:21:25 -0500 Subject: [PATCH] Tweaked to run without delays on zero w --- ports/broadcom/common-hal/neopixel_write/__init__.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ports/broadcom/common-hal/neopixel_write/__init__.c b/ports/broadcom/common-hal/neopixel_write/__init__.c index 5629c97425..d685ac53ce 100644 --- a/ports/broadcom/common-hal/neopixel_write/__init__.c +++ b/ports/broadcom/common-hal/neopixel_write/__init__.c @@ -97,6 +97,7 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t *digitalinout, COMPLETE_MEMORY_READS; icnt = 0; while ((CM_PWM->CS_b.BUSY == 0) & (icnt++ < 1000)) { + COMPLETE_MEMORY_READS; } } @@ -142,6 +143,7 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t *digitalinout, icnt = 0; while ((pwm->STA_b.FULL1 == 1) & (icnt++ < 150)) { RUN_BACKGROUND_TASKS; + COMPLETE_MEMORY_READS; } // Dummy value for the first channel. pwm->FIF1 = 0x000000; @@ -149,12 +151,14 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t *digitalinout, icnt = 0; while ((pwm->STA_b.FULL1 == 1) & (icnt++ < 150)) { RUN_BACKGROUND_TASKS; + COMPLETE_MEMORY_READS; } pwm->FIF1 = expanded; if (channel == 0) { icnt = 0; while ((pwm->STA_b.FULL1 == 1) & (icnt++ < 150)) { RUN_BACKGROUND_TASKS; + COMPLETE_MEMORY_READS; } // Dummy value for the second channel. pwm->FIF1 = 0x000000; @@ -164,17 +168,23 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t *digitalinout, icnt = 0; while ((pwm->STA_b.EMPT1 == 0) & (icnt++ < 2500)) { RUN_BACKGROUND_TASKS; + COMPLETE_MEMORY_READS; } // Wait for transmission to start. icnt = 0; while (((pwm->STA_b.STA1 == 0) & (pwm->STA_b.STA2 == 0)) & (icnt++ < 150)) { RUN_BACKGROUND_TASKS; + COMPLETE_MEMORY_READS; } // Wait for transmission to complete. icnt = 0; while (((pwm->STA_b.STA1 == 1) | (pwm->STA_b.STA2 == 1)) & (icnt++ < 150)) { RUN_BACKGROUND_TASKS; + COMPLETE_MEMORY_READS; } + // Shouldn't be anything left in queue but clear it so the clock doesn't crash if there is + pwm->CTL = PWM0_CTL_CLRF1_Msk; + COMPLETE_MEMORY_READS; gpio_set_function(digitalinout->pin->number, GPIO_FUNCTION_OUTPUT);