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::*;
|
|
|
|
|
|
|
|
use core::mem;
|
|
|
|
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};
|
|
|
|
use embassy::util::Forever;
|
2020-11-09 00:04:34 +00:00
|
|
|
use embassy_nrf::gpiote::{Gpiote, PortInputPolarity};
|
2020-12-29 00:53:17 +00:00
|
|
|
use embassy_nrf::interrupt;
|
2020-11-08 18:00:08 +00:00
|
|
|
|
2020-11-09 00:04:34 +00:00
|
|
|
async fn button(g: &Gpiote, n: usize, pin: gpio::Pin<gpio::Input<gpio::PullUp>>) {
|
2020-11-08 18:00:08 +00:00
|
|
|
loop {
|
2020-11-09 00:04:34 +00:00
|
|
|
g.wait_port_input(&pin, PortInputPolarity::Low).await;
|
2020-11-08 18:00:08 +00:00
|
|
|
info!("Button {:?} pressed!", n);
|
2020-11-09 00:04:34 +00:00
|
|
|
g.wait_port_input(&pin, PortInputPolarity::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);
|
|
|
|
|
2020-12-29 00:53:17 +00:00
|
|
|
let g = Gpiote::new(p.GPIOTE, interrupt::take!(GPIOTE));
|
2020-11-08 18:00:08 +00:00
|
|
|
info!(
|
|
|
|
"sizeof Signal<()> = {:usize}",
|
|
|
|
mem::size_of::<embassy::util::Signal<()>>()
|
|
|
|
);
|
2020-11-09 00:04:34 +00:00
|
|
|
info!("sizeof gpiote = {:usize}", mem::size_of::<Gpiote>());
|
2020-11-08 18:00:08 +00:00
|
|
|
|
|
|
|
info!("Starting!");
|
|
|
|
|
|
|
|
let button1 = button(&g, 1, port0.p0_11.into_pullup_input().degrade());
|
|
|
|
let button2 = button(&g, 2, port0.p0_12.into_pullup_input().degrade());
|
|
|
|
let button3 = button(&g, 3, port0.p0_24.into_pullup_input().degrade());
|
|
|
|
let button4 = button(&g, 4, port0.p0_25.into_pullup_input().degrade());
|
|
|
|
futures::join!(button1, button2, button3, button4);
|
|
|
|
}
|
|
|
|
|
|
|
|
static EXECUTOR: Forever<Executor> = Forever::new();
|
|
|
|
|
|
|
|
#[entry]
|
|
|
|
fn main() -> ! {
|
|
|
|
info!("Hello World!");
|
|
|
|
|
|
|
|
let executor = EXECUTOR.put(Executor::new(cortex_m::asm::sev));
|
|
|
|
unwrap!(executor.spawn(run()));
|
|
|
|
|
|
|
|
loop {
|
|
|
|
executor.run();
|
|
|
|
cortex_m::asm::wfe();
|
|
|
|
}
|
|
|
|
}
|