2020-09-22 22:32:49 +00:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
|
|
|
#[path = "../example_common.rs"]
|
|
|
|
mod example_common;
|
|
|
|
use example_common::*;
|
|
|
|
|
|
|
|
use cortex_m_rt::entry;
|
2020-12-29 00:53:17 +00:00
|
|
|
use defmt::panic;
|
2020-09-22 22:32:49 +00:00
|
|
|
use nrf52840_hal::gpio;
|
|
|
|
|
2020-10-19 19:15:24 +00:00
|
|
|
use embassy::executor::{task, Executor};
|
2020-10-31 21:37:24 +00:00
|
|
|
use embassy::util::Forever;
|
|
|
|
use embassy_nrf::gpiote;
|
2020-12-29 00:53:17 +00:00
|
|
|
use embassy_nrf::interrupt;
|
2020-09-24 20:04:45 +00:00
|
|
|
|
|
|
|
#[task]
|
2020-09-22 22:32:49 +00:00
|
|
|
async fn run() {
|
2020-11-01 16:17:24 +00:00
|
|
|
let p = unwrap!(embassy_nrf::pac::Peripherals::take());
|
2020-09-22 22:32:49 +00:00
|
|
|
let port0 = gpio::p0::Parts::new(p.P0);
|
|
|
|
|
2020-12-29 00:53:17 +00:00
|
|
|
let g = gpiote::Gpiote::new(p.GPIOTE, interrupt::take!(GPIOTE));
|
2020-09-22 22:32:49 +00:00
|
|
|
|
|
|
|
info!("Starting!");
|
|
|
|
|
|
|
|
let pin1 = port0.p0_11.into_pullup_input().degrade();
|
|
|
|
let button1 = async {
|
2020-11-08 16:38:45 +00:00
|
|
|
let ch = unwrap!(g.new_input_channel(pin1, gpiote::InputChannelPolarity::HiToLo));
|
2020-09-22 22:32:49 +00:00
|
|
|
|
|
|
|
loop {
|
|
|
|
ch.wait().await;
|
|
|
|
info!("Button 1 pressed")
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let pin2 = port0.p0_12.into_pullup_input().degrade();
|
|
|
|
let button2 = async {
|
2020-11-08 16:38:45 +00:00
|
|
|
let ch = unwrap!(g.new_input_channel(pin2, gpiote::InputChannelPolarity::LoToHi));
|
2020-09-22 22:32:49 +00:00
|
|
|
|
|
|
|
loop {
|
|
|
|
ch.wait().await;
|
|
|
|
info!("Button 2 released")
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let pin3 = port0.p0_24.into_pullup_input().degrade();
|
|
|
|
let button3 = async {
|
2020-11-08 16:38:45 +00:00
|
|
|
let ch = unwrap!(g.new_input_channel(pin3, gpiote::InputChannelPolarity::Toggle));
|
2020-09-22 22:32:49 +00:00
|
|
|
|
|
|
|
loop {
|
|
|
|
ch.wait().await;
|
|
|
|
info!("Button 3 toggled")
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let pin4 = port0.p0_25.into_pullup_input().degrade();
|
|
|
|
let button4 = async {
|
2020-11-08 16:38:45 +00:00
|
|
|
let ch = unwrap!(g.new_input_channel(pin4, gpiote::InputChannelPolarity::Toggle));
|
2020-09-22 22:32:49 +00:00
|
|
|
|
|
|
|
loop {
|
|
|
|
ch.wait().await;
|
|
|
|
info!("Button 4 toggled")
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
futures::join!(button1, button2, button3, button4);
|
|
|
|
}
|
|
|
|
|
2020-10-31 21:37:24 +00:00
|
|
|
static EXECUTOR: Forever<Executor> = Forever::new();
|
|
|
|
|
2020-09-22 22:32:49 +00:00
|
|
|
#[entry]
|
|
|
|
fn main() -> ! {
|
|
|
|
info!("Hello World!");
|
|
|
|
|
2020-11-01 16:17:24 +00:00
|
|
|
let executor = EXECUTOR.put(Executor::new(cortex_m::asm::sev));
|
|
|
|
unwrap!(executor.spawn(run()));
|
2020-09-24 20:04:45 +00:00
|
|
|
|
2020-10-31 21:37:24 +00:00
|
|
|
loop {
|
|
|
|
executor.run();
|
|
|
|
cortex_m::asm::wfe();
|
2020-09-22 22:32:49 +00:00
|
|
|
}
|
|
|
|
}
|