Skip to content

Commit

Permalink
Merge pull request #799 from mjptree/fix-oneshot-adc
Browse files Browse the repository at this point in the history
Fix oneshot adc read waiting indefinitely
  • Loading branch information
jannic authored May 3, 2024
2 parents 840e90b + a6f43a4 commit dfbdb9a
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 dfbdb9a

Please sign in to comment.