embassy/embassy-nrf-examples/src/bin/gpiote_port.rs

54 lines
1.4 KiB
Rust
Raw Normal View History

2020-11-08 19:00:08 +01:00
#![no_std]
#![no_main]
2021-03-17 02:48:16 +01:00
#![feature(min_type_alias_impl_trait)]
#![feature(impl_trait_in_bindings)]
2020-11-08 19:00:08 +01:00
#![feature(type_alias_impl_trait)]
2021-03-27 03:12:58 +01:00
#![allow(incomplete_features)]
2020-11-08 19:00:08 +01:00
#[path = "../example_common.rs"]
mod example_common;
use core::pin::Pin;
2020-12-29 01:53:17 +01:00
use defmt::panic;
2021-03-29 02:47:10 +02:00
use embassy::executor::Spawner;
2021-03-02 00:32:23 +01:00
use embassy::traits::gpio::{WaitForHigh, WaitForLow};
2021-03-21 21:03:02 +01:00
use embassy_nrf::gpio::{AnyPin, Input, Pin as _, Pull};
use embassy_nrf::gpiote::{self, PortInput};
2020-12-29 01:53:17 +01:00
use embassy_nrf::interrupt;
2021-03-21 21:58:59 +01:00
use embassy_nrf::Peripherals;
use example_common::*;
2020-11-08 19:00:08 +01:00
2021-03-24 18:31:11 +01:00
async fn button(n: usize, mut pin: PortInput<'static, AnyPin>) {
2020-11-08 19:00:08 +01:00
loop {
Pin::new(&mut pin).wait_for_low().await;
2020-11-08 19:00:08 +01:00
info!("Button {:?} pressed!", n);
Pin::new(&mut pin).wait_for_high().await;
2020-11-08 19:00:08 +01:00
info!("Button {:?} released!", n);
}
}
2021-03-29 02:47:10 +02:00
#[embassy::main]
async fn main(spawner: Spawner) {
2021-03-21 21:58:59 +01:00
let p = Peripherals::take().unwrap();
2020-11-08 19:00:08 +01:00
2021-03-27 03:12:58 +01:00
let g = gpiote::initialize(p.GPIOTE, interrupt::take!(GPIOTE));
2020-11-08 19:00:08 +01:00
let button1 = button(
1,
2021-03-27 03:12:58 +01:00
PortInput::new(g, Input::new(p.P0_11.degrade(), Pull::Up)),
);
let button2 = button(
2,
2021-03-27 03:12:58 +01:00
PortInput::new(g, Input::new(p.P0_12.degrade(), Pull::Up)),
);
let button3 = button(
3,
2021-03-27 03:12:58 +01:00
PortInput::new(g, Input::new(p.P0_24.degrade(), Pull::Up)),
);
let button4 = button(
4,
2021-03-27 03:12:58 +01:00
PortInput::new(g, Input::new(p.P0_25.degrade(), Pull::Up)),
);
2020-11-08 19:00:08 +01:00
futures::join!(button1, button2, button3, button4);
}