Tweaked to run without delays on zero w

This commit is contained in:
RetiredWizard 2023-02-11 20:21:25 -05:00
parent 359a27e166
commit 1679790481

View File

@ -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);