From f9e1fc119dfd08a6c383bc6572e1acd933578c98 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 23 Aug 2022 15:17:54 -0500 Subject: [PATCH 1/2] Fix handling of zero-length pulseout pulse --- ports/nrf/common-hal/pulseio/PulseOut.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ports/nrf/common-hal/pulseio/PulseOut.c b/ports/nrf/common-hal/pulseio/PulseOut.c index 1c3c317a05..d282043be7 100644 --- a/ports/nrf/common-hal/pulseio/PulseOut.c +++ b/ports/nrf/common-hal/pulseio/PulseOut.c @@ -74,6 +74,11 @@ static void pulseout_event_handler(nrf_timer_event_t event_type, void *p_context nrfx_timer_pause(timer); pulse_array_index++; + // Ignore a zero-length pulse + while (pulse_array[pulse_array_index] == 0 && + pulse_array_index < pulse_array_length) { + pulse_array_index++; + } // No more pulses. Turn off output and don't restart. if (pulse_array_index >= pulse_array_length) { From e700481aed3056e9f01886e1db19f66fc515a45d Mon Sep 17 00:00:00 2001 From: DavePutz Date: Tue, 23 Aug 2022 15:58:27 -0500 Subject: [PATCH 2/2] Update PulseOut.c reorder the tests for zero-length --- ports/nrf/common-hal/pulseio/PulseOut.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/nrf/common-hal/pulseio/PulseOut.c b/ports/nrf/common-hal/pulseio/PulseOut.c index d282043be7..557610bbdf 100644 --- a/ports/nrf/common-hal/pulseio/PulseOut.c +++ b/ports/nrf/common-hal/pulseio/PulseOut.c @@ -75,8 +75,8 @@ static void pulseout_event_handler(nrf_timer_event_t event_type, void *p_context pulse_array_index++; // Ignore a zero-length pulse - while (pulse_array[pulse_array_index] == 0 && - pulse_array_index < pulse_array_length) { + while (pulse_array_index < pulse_array_length && + pulse_array[pulse_array_index] == 0) { pulse_array_index++; }