aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-09-02 13:39:55 +0200
committerGitHub <[email protected]>2021-09-02 13:39:55 +0200
commitd0c87493996cd5a80ad02533a888eef47fb94ba3 (patch)
treed7d1fd8c291862c567a1536435483e93934e45b7 /examples
parentdb3cb02032fd6b861b2c39a0a354767cc72af1df (diff)
parent34c66fa78d700fa5ca324dd043dc0861694ea693 (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.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}