aboutsummaryrefslogtreecommitdiff
path: root/examples/nrf/src/bin/awaitable_timer.rs
blob: 34a657cb91353cdafcd53085cd65ab9197314097 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]

use defmt::info;
use embassy::executor::Spawner;
use embassy_nrf::timer::Timer;
use embassy_nrf::{interrupt, Peripherals};
use {defmt_rtt as _, panic_probe as _};

#[embassy::main]
async fn main(_spawner: Spawner, p: Peripherals) {
    let mut t = Timer::new_awaitable(p.TIMER0, interrupt::take!(TIMER0));
    // default frequency is 1MHz, so this triggers every second
    t.cc(0).write(1_000_000);
    // clear the timer value on cc[0] compare match
    t.cc(0).short_compare_clear();
    t.start();

    loop {
        // wait for compare match
        t.cc(0).wait().await;
        info!("hardware timer tick");
    }
}