diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-09-02 13:39:55 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-09-02 13:39:55 +0200 |
| commit | d0c87493996cd5a80ad02533a888eef47fb94ba3 (patch) | |
| tree | d7d1fd8c291862c567a1536435483e93934e45b7 /examples | |
| parent | db3cb02032fd6b861b2c39a0a354767cc72af1df (diff) | |
| parent | 34c66fa78d700fa5ca324dd043dc0861694ea693 (diff) | |
Merge pull request #382 from fnafnio/typestate_nrf_timer
Typestate nrf timer
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/nrf/src/bin/awaitable_timer.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/examples/nrf/src/bin/awaitable_timer.rs b/examples/nrf/src/bin/awaitable_timer.rs new file mode 100644 index 000000000..289a33c71 --- /dev/null +++ b/examples/nrf/src/bin/awaitable_timer.rs | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | #![allow(incomplete_features)] | ||
| 5 | |||
| 6 | #[path = "../example_common.rs"] | ||
| 7 | mod example_common; | ||
| 8 | use embassy_nrf::interrupt; | ||
| 9 | use embassy_nrf::timer::Timer; | ||
| 10 | use embassy_nrf::Peripherals; | ||
| 11 | use example_common::info; | ||
| 12 | |||
| 13 | use embassy::executor::Spawner; | ||
| 14 | |||
| 15 | #[embassy::main] | ||
| 16 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 17 | let mut t = Timer::new_awaitable(p.TIMER0, interrupt::take!(TIMER0)); | ||
| 18 | // default frequency is 1MHz, so this triggers every second | ||
| 19 | t.cc(0).write(1_000_000); | ||
| 20 | // clear the timer value on cc[0] compare match | ||
| 21 | t.cc(0).short_compare_clear(); | ||
| 22 | t.start(); | ||
| 23 | |||
| 24 | loop { | ||
| 25 | // wait for compare match | ||
| 26 | t.cc(0).wait().await; | ||
| 27 | info!("hardware timer tick"); | ||
| 28 | } | ||
| 29 | } | ||
