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)]
|
|
|
|
|
|
|
|
#[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 embassy::executor::{task, Executor};
|
2021-03-01 23:32:23 +00:00
|
|
|
use embassy::traits::gpio::{WaitForHigh, WaitForLow};
|
2020-11-08 18:00:08 +00:00
|
|
|
use embassy::util::Forever;
|
2021-03-21 20:03:02 +00:00
|
|
|
use embassy_nrf::gpio::{AnyPin, Input, Pin as _, Pull};
|
|
|
|
use embassy_nrf::gpiote::{self, PortInput};
|
2020-12-29 00:53:17 +00:00
|
|
|
use embassy_nrf::interrupt;
|
2020-11-08 18:00:08 +00:00
|
|
|
|
2021-03-21 20:01:06 +00:00
|
|
|
async fn button(n: usize, mut pin: PortInput<AnyPin>) {
|
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() {
|
2021-03-20 02:09:42 +00:00
|
|
|
let p = unsafe { embassy_nrf::peripherals::Peripherals::steal() };
|
2020-11-08 18:00:08 +00:00
|
|
|
|
2021-03-20 02:09:42 +00:00
|
|
|
let g = gpiote::initialize(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,
|
2021-03-21 20:01:06 +00:00
|
|
|
PortInput::new(g, Input::new(p.p0_11.degrade(), Pull::Up)),
|
2021-02-04 22:56:17 +00:00
|
|
|
);
|
|
|
|
let button2 = button(
|
|
|
|
2,
|
2021-03-21 20:01:06 +00:00
|
|
|
PortInput::new(g, Input::new(p.p0_12.degrade(), Pull::Up)),
|
2021-02-04 22:56:17 +00:00
|
|
|
);
|
|
|
|
let button3 = button(
|
|
|
|
3,
|
2021-03-21 20:01:06 +00:00
|
|
|
PortInput::new(g, Input::new(p.p0_24.degrade(), Pull::Up)),
|
2021-02-04 22:56:17 +00:00
|
|
|
);
|
|
|
|
let button4 = button(
|
|
|
|
4,
|
2021-03-21 20:01:06 +00:00
|
|
|
PortInput::new(g, Input::new(p.p0_25.degrade(), Pull::Up)),
|
2021-02-04 22:56:17 +00:00
|
|
|
);
|
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
|
|
|
}
|