2020-11-08 18:00:08 +00:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
2021-03-17 01:48:16 +00:00
|
|
|
#![feature(min_type_alias_impl_trait)]
|
|
|
|
#![feature(impl_trait_in_bindings)]
|
2020-11-08 18:00:08 +00:00
|
|
|
#![feature(type_alias_impl_trait)]
|
2021-03-27 02:12:58 +00:00
|
|
|
#![allow(incomplete_features)]
|
2020-11-08 18:00:08 +00:00
|
|
|
|
|
|
|
#[path = "../example_common.rs"]
|
|
|
|
mod example_common;
|
|
|
|
|
2020-12-29 00:53:17 +00:00
|
|
|
use defmt::panic;
|
2021-03-29 00:47:10 +00:00
|
|
|
use embassy::executor::Spawner;
|
2021-03-01 23:32:23 +00:00
|
|
|
use embassy::traits::gpio::{WaitForHigh, WaitForLow};
|
2021-03-21 20:03:02 +00:00
|
|
|
use embassy_nrf::gpio::{AnyPin, Input, Pin as _, Pull};
|
2021-05-11 23:01:08 +00:00
|
|
|
use embassy_nrf::gpiote::PortInput;
|
2020-12-29 00:53:17 +00:00
|
|
|
use embassy_nrf::interrupt;
|
2021-03-21 20:58:59 +00:00
|
|
|
use embassy_nrf::Peripherals;
|
|
|
|
use example_common::*;
|
2020-11-08 18:00:08 +00:00
|
|
|
|
2021-03-29 01:09:51 +00:00
|
|
|
#[embassy::task(pool_size = 4)]
|
|
|
|
async fn button_task(n: usize, mut pin: PortInput<'static, AnyPin>) {
|
2020-11-08 18:00:08 +00:00
|
|
|
loop {
|
2021-04-14 14:25:54 +00:00
|
|
|
pin.wait_for_low().await;
|
2020-11-08 18:00:08 +00:00
|
|
|
info!("Button {:?} pressed!", n);
|
2021-04-14 14:25:54 +00:00
|
|
|
pin.wait_for_high().await;
|
2020-11-08 18:00:08 +00:00
|
|
|
info!("Button {:?} released!", n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-29 00:47:10 +00:00
|
|
|
#[embassy::main]
|
|
|
|
async fn main(spawner: Spawner) {
|
2021-03-21 20:58:59 +00:00
|
|
|
let p = Peripherals::take().unwrap();
|
2020-11-08 18:00:08 +00:00
|
|
|
|
2021-05-11 23:01:08 +00:00
|
|
|
info!("Starting!");
|
2020-11-08 18:00:08 +00:00
|
|
|
|
2021-05-11 23:01:08 +00:00
|
|
|
let btn1 = PortInput::new(Input::new(p.P0_11.degrade(), Pull::Up));
|
|
|
|
let btn2 = PortInput::new(Input::new(p.P0_12.degrade(), Pull::Up));
|
|
|
|
let btn3 = PortInput::new(Input::new(p.P0_24.degrade(), Pull::Up));
|
|
|
|
let btn4 = PortInput::new(Input::new(p.P0_25.degrade(), Pull::Up));
|
2021-03-29 01:09:51 +00:00
|
|
|
|
|
|
|
spawner.spawn(button_task(1, btn1)).unwrap();
|
|
|
|
spawner.spawn(button_task(2, btn2)).unwrap();
|
|
|
|
spawner.spawn(button_task(3, btn3)).unwrap();
|
|
|
|
spawner.spawn(button_task(4, btn4)).unwrap();
|
2020-11-08 18:00:08 +00:00
|
|
|
}
|