Skip to content

Commit

Permalink
Fix oneshot adc read waiting indefinitely
Browse files Browse the repository at this point in the history
  • Loading branch information
mjptree committed May 2, 2024
1 parent 840e90b commit a6f43a4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions rp2040-hal/src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a6f43a4

Please sign in to comment.