diff options
| author | Ulf Lilleengen <[email protected]> | 2021-10-18 15:24:31 +0200 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2021-10-19 07:18:56 +0200 |
| commit | 2ef4a45fa0e153cb6435c4dc52f19108ca808cc7 (patch) | |
| tree | 8681889a127109a49d592b2857232c18e64645a6 /examples/nrf/src/bin | |
| parent | 729b17bc25fed42b4348cae0fb3d781590572c3f (diff) | |
Add support for temperature sensor peripheral
* Add TEMP peripheral to all nRF52 chips
* Add async HAL for reading temperature values
* Add example application reading temperature values
Diffstat (limited to 'examples/nrf/src/bin')
| -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..04d1d58fe --- /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 | } | ||
