2020-11-08 18:00:08 +00:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
|
|
|
#[path = "../example_common.rs"]
|
|
|
|
mod example_common;
|
|
|
|
use example_common::*;
|
|
|
|
|
2021-02-04 22:56:17 +00:00
|
|
|
use core::pin::Pin;
|
2020-11-08 18:00:08 +00:00
|
|
|
use cortex_m_rt::entry;
|
2020-12-29 00:53:17 +00:00
|
|
|
use defmt::panic;
|
2020-11-08 18:00:08 +00:00
|
|
|
use nrf52840_hal::gpio;
|
|
|
|
|
|
|
|
use embassy::executor::{task, Executor};
|
2021-02-04 22:56:17 +00:00
|
|
|
use embassy::gpio::{WaitForHigh, WaitForLow};
|
2020-11-08 18:00:08 +00:00
|
|
|
use embassy::util::Forever;
|
2021-02-04 22:56:17 +00:00
|
|
|
use embassy_nrf::gpiote::{Gpiote, GpiotePin};
|
2020-12-29 00:53:17 +00:00
|
|
|
use embassy_nrf::interrupt;
|
2020-11-08 18:00:08 +00:00
|
|
|
|
2021-02-04 22:56:17 +00:00
|
|
|
async fn button(n: usize, mut pin: GpiotePin<gpio::PullUp>) {
|
2020-11-08 18:00:08 +00:00
|
|
|
loop {
|
2021-02-04 22:56:17 +00:00
|
|
|
Pin::new(&mut pin).wait_for_low().await;
|
2020-11-08 18:00:08 +00:00
|
|
|
info!("Button {:?} pressed!", n);
|
2021-02-04 22:56:17 +00:00
|
|
|
Pin::new(&mut pin).wait_for_high().await;
|
2020-11-08 18:00:08 +00:00
|
|
|
info!("Button {:?} released!", n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[task]
|
|
|
|
async fn run() {
|
|
|
|
let p = unwrap!(embassy_nrf::pac::Peripherals::take());
|
|
|
|
let port0 = gpio::p0::Parts::new(p.P0);
|
|
|
|
|
2021-02-04 22:56:17 +00:00
|
|
|
let (g, _) = Gpiote::new(p.GPIOTE, interrupt::take!(GPIOTE));
|
2020-11-08 18:00:08 +00:00
|
|
|
|
2021-02-04 22:56:17 +00:00
|
|
|
let button1 = button(
|
|
|
|
1,
|
|
|
|
GpiotePin::new(g, port0.p0_11.into_pullup_input().degrade()),
|
|
|
|
);
|
|
|
|
let button2 = button(
|
|
|
|
2,
|
|
|
|
GpiotePin::new(g, port0.p0_12.into_pullup_input().degrade()),
|
|
|
|
);
|
|
|
|
let button3 = button(
|
|
|
|
3,
|
|
|
|
GpiotePin::new(g, port0.p0_24.into_pullup_input().degrade()),
|
|
|
|
);
|
|
|
|
let button4 = button(
|
|
|
|
4,
|
|
|
|
GpiotePin::new(g, port0.p0_25.into_pullup_input().degrade()),
|
|
|
|
);
|
2020-11-08 18:00:08 +00:00
|
|
|
futures::join!(button1, button2, button3, button4);
|
|
|
|
}
|
|
|
|
|
|
|
|
static EXECUTOR: Forever<Executor> = Forever::new();
|
|
|
|
|
|
|
|
#[entry]
|
|
|
|
fn main() -> ! {
|
|
|
|
info!("Hello World!");
|
|
|
|
|
2021-02-02 04:14:52 +00:00
|
|
|
let executor = EXECUTOR.put(Executor::new());
|
|
|
|
executor.run(|spawner| {
|
|
|
|
unwrap!(spawner.spawn(run()));
|
|
|
|
});
|
2020-11-08 18:00:08 +00:00
|
|
|
}
|