aboutsummaryrefslogtreecommitdiff
path: root/tests/nrf/src/bin/gpiote.rs
blob: 0700016d19249402ec1b071b338f596bec850962 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#![no_std]
#![no_main]

#[path = "../common.rs"]
mod common;

use defmt::{assert, info};
use embassy_executor::Spawner;
use embassy_futures::join::join;
use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull};
use embassy_time::{Duration, Instant, Timer};

#[embassy_executor::main]
async fn main(_spawner: Spawner) {
    let p = embassy_nrf::init(Default::default());

    let mut input = Input::new(peri!(p, PIN_A), Pull::Up);
    let mut output = Output::new(peri!(p, PIN_B), Level::Low, OutputDrive::Standard);

    let fut1 = async {
        Timer::after_millis(100).await;
        output.set_high();
    };
    let fut2 = async {
        let start = Instant::now();
        input.wait_for_high().await;
        let dur = Instant::now() - start;
        info!("took {} ms", dur.as_millis());
        assert!((Duration::from_millis(90)..Duration::from_millis(110)).contains(&dur));
    };

    join(fut1, fut2).await;

    let fut1 = async {
        Timer::after_millis(100).await;
        output.set_low();
    };
    let fut2 = async {
        let start = Instant::now();
        input.wait_for_low().await;
        let dur = Instant::now() - start;
        info!("took {} ms", dur.as_millis());
        assert!((Duration::from_millis(90)..Duration::from_millis(110)).contains(&dur));
    };

    join(fut1, fut2).await;

    info!("Test OK");
    cortex_m::asm::bkpt();
}