From 3daebb36c3bccff2e490b37519ee12eddeeca759 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 2f822b4184..2945ac7022 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 c00a630f50dd105b43ff40073fcd788f71901fdf 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 2945ac7022..c2d59ffdba 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++; }