Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport pull request #799 #801

Merged
merged 3 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading