Skip to content

Commit

Permalink
Merge pull request #801 from jannic/backport-pr-799
Browse files Browse the repository at this point in the history
Backport pull request #799
  • Loading branch information
ithinuel authored May 4, 2024
2 parents 8b0ad9f + c9145ba commit f7f9313
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
11 changes: 11 additions & 0 deletions on-target-tests/tests/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,15 @@ mod tests {
assert!(pac.PADS_BANK0.gpio(id).read().ie().bit_is_clear());
}
}

#[test]
fn read_adc() {
use embedded_hal_0_2::adc::OneShot;

// Safety: Test cases do not run in parallel
let mut pac = unsafe { pac::Peripherals::steal() };
let mut adc = hal::Adc::new(pac.ADC, &mut pac.RESETS);
let mut temp_sensor = hal::adc::Adc::take_temp_sensor(&mut adc).unwrap();
let _temperature: u16 = adc.read(&mut temp_sensor).unwrap();
}
}
2 changes: 2 additions & 0 deletions rp2040-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Fix oneshot adc read waiting indefinitely - #799 @mjptree

## [0.10.1] - 2024-04-28

### Added
Expand Down
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 f7f9313

Please sign in to comment.