diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-10-19 18:50:37 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-10-19 18:50:37 +0000 |
| commit | 675172f9816a41792d53ba9dcd33ad3592e94eb8 (patch) | |
| tree | 1b22cf95d15a280917f7bb999dabd15d138f8075 /examples | |
| parent | 729b17bc25fed42b4348cae0fb3d781590572c3f (diff) | |
| parent | 69953a78f10905330fb5d682dd5bda01f13a4e0c (diff) | |
Merge #436
436: Add support for temperature sensor peripheral r=lulf a=lulf
* Add TEMP peripheral to all nRF52 chips
* Add async HAL for reading temperature values
* Add example application reading temperature values
Co-authored-by: Ulf Lilleengen <[email protected]>
Co-authored-by: Ulf Lilleengen <[email protected]>
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/nrf/src/bin/temp.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/examples/nrf/src/bin/temp.rs b/examples/nrf/src/bin/temp.rs new file mode 100644 index 000000000..af9775f5a --- /dev/null +++ b/examples/nrf/src/bin/temp.rs | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | #[path = "../example_common.rs"] | ||
| 6 | mod example_common; | ||
| 7 | use example_common::*; | ||
| 8 | |||
| 9 | use defmt::panic; | ||
| 10 | use embassy::{ | ||
| 11 | executor::Spawner, | ||
| 12 | time::{Duration, Timer}, | ||
| 13 | }; | ||
| 14 | use embassy_nrf::{interrupt, temp::Temp, Peripherals}; | ||
| 15 | |||
| 16 | #[embassy::main] | ||
| 17 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 18 | let irq = interrupt::take!(TEMP); | ||
| 19 | let mut temp = Temp::new(p.TEMP, irq); | ||
| 20 | |||
| 21 | loop { | ||
| 22 | let value = temp.read().await; | ||
| 23 | info!("temperature: {}℃", value.to_num::<u16>()); | ||
| 24 | Timer::after(Duration::from_secs(1)).await; | ||
| 25 | } | ||
| 26 | } | ||
