From a6f43a49928f6a0a5f7d94f3ac881a671a68f85d Mon Sep 17 00:00:00 2001 From: Michael Prantl Date: Fri, 3 May 2024 00:23:53 +0100 Subject: [PATCH] Fix oneshot adc read waiting indefinitely --- rp2040-hal/src/adc.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rp2040-hal/src/adc.rs b/rp2040-hal/src/adc.rs index 846677db7..1a5ba5457 100644 --- a/rp2040-hal/src/adc.rs +++ b/rp2040-hal/src/adc.rs @@ -404,12 +404,16 @@ impl Adc { /// /// Also returns immediately if start_many is set, to avoid indefinite blocking. pub fn wait_ready(&self) { - let cs = self.device.cs().read(); - while !cs.ready().bit_is_set() && !cs.start_many().bit_is_set() { + while !self.is_ready_or_free_running() { cortex_m::asm::nop(); } } + fn is_ready_or_free_running(&self) -> bool { + let cs = self.device.cs().read(); + cs.ready().bit_is_set() || cs.start_many().bit_is_set() + } + /// Returns true if the ADC is ready for the next conversion. /// /// This implies that any previous conversion has finished.