aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/nrf/src/bin/awaitable_timer.rs29
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"]
7mod example_common;
8use embassy_nrf::interrupt;
9use embassy_nrf::timer::Timer;
10use embassy_nrf::Peripherals;
11use example_common::info;
12
13use embassy::executor::Spawner;
14
15#[embassy::main]
16async 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}