diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-02-04 21:36:19 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2024-02-04 21:36:19 +0100 |
| commit | d5d86b866fd5ceb8081cbfcce832be4c68b82691 (patch) | |
| tree | 8884048c369632e1d96370010ec96b4caf1eab90 /tests | |
| parent | 711dd120d1802dd43b003b2536a290a1c53cfeba (diff) | |
nrf/gpiote: add support for nrf51.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/nrf51422/Cargo.toml | 3 | ||||
| -rw-r--r-- | tests/nrf51422/src/bin/gpiote.rs | 47 |
2 files changed, 49 insertions, 1 deletions
diff --git a/tests/nrf51422/Cargo.toml b/tests/nrf51422/Cargo.toml index 2cab20ac0..07236987b 100644 --- a/tests/nrf51422/Cargo.toml +++ b/tests/nrf51422/Cargo.toml | |||
| @@ -7,10 +7,11 @@ license = "MIT OR Apache-2.0" | |||
| 7 | [dependencies] | 7 | [dependencies] |
| 8 | teleprobe-meta = "1" | 8 | teleprobe-meta = "1" |
| 9 | 9 | ||
| 10 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } | ||
| 10 | embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt", ] } | 11 | embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt", ] } |
| 11 | embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "task-arena-size-128", "integrated-timers"] } | 12 | embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "task-arena-size-128", "integrated-timers"] } |
| 12 | embassy-time = { version = "0.3.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } | 13 | embassy-time = { version = "0.3.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } |
| 13 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf51", "time-driver-rtc1", "unstable-pac", "time"] } | 14 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf51", "time-driver-rtc1", "unstable-pac", "time", "gpiote"] } |
| 14 | embedded-io-async = { version = "0.6.1", features = ["defmt-03"] } | 15 | embedded-io-async = { version = "0.6.1", features = ["defmt-03"] } |
| 15 | embedded-hal-async = { version = "1.0" } | 16 | embedded-hal-async = { version = "1.0" } |
| 16 | 17 | ||
diff --git a/tests/nrf51422/src/bin/gpiote.rs b/tests/nrf51422/src/bin/gpiote.rs new file mode 100644 index 000000000..330fe993e --- /dev/null +++ b/tests/nrf51422/src/bin/gpiote.rs | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | teleprobe_meta::target!(b"nrf51-dk"); | ||
| 4 | |||
| 5 | use defmt::{assert, info}; | ||
| 6 | use embassy_executor::Spawner; | ||
| 7 | use embassy_futures::join::join; | ||
| 8 | use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; | ||
| 9 | use embassy_time::{Duration, Instant, Timer}; | ||
| 10 | use {defmt_rtt as _, panic_probe as _}; | ||
| 11 | |||
| 12 | #[embassy_executor::main] | ||
| 13 | async fn main(_spawner: Spawner) { | ||
| 14 | let p = embassy_nrf::init(Default::default()); | ||
| 15 | |||
| 16 | let mut input = Input::new(p.P0_13, Pull::Up); | ||
| 17 | let mut output = Output::new(p.P0_14, Level::Low, OutputDrive::Standard); | ||
| 18 | |||
| 19 | let fut1 = async { | ||
| 20 | Timer::after_millis(100).await; | ||
| 21 | output.set_high(); | ||
| 22 | }; | ||
| 23 | let fut2 = async { | ||
| 24 | let start = Instant::now(); | ||
| 25 | input.wait_for_high().await; | ||
| 26 | let dur = Instant::now() - start; | ||
| 27 | assert!((Duration::from_millis(90)..Duration::from_millis(110)).contains(&dur)); | ||
| 28 | }; | ||
| 29 | |||
| 30 | join(fut1, fut2).await; | ||
| 31 | |||
| 32 | let fut1 = async { | ||
| 33 | Timer::after_millis(100).await; | ||
| 34 | output.set_low(); | ||
| 35 | }; | ||
| 36 | let fut2 = async { | ||
| 37 | let start = Instant::now(); | ||
| 38 | input.wait_for_low().await; | ||
| 39 | let dur = Instant::now() - start; | ||
| 40 | assert!((Duration::from_millis(90)..Duration::from_millis(110)).contains(&dur)); | ||
| 41 | }; | ||
| 42 | |||
| 43 | join(fut1, fut2).await; | ||
| 44 | |||
| 45 | info!("Test OK"); | ||
| 46 | cortex_m::asm::bkpt(); | ||
| 47 | } | ||
