2020-09-23 00:32:49 +02:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
2022-04-02 04:35:06 +02:00
|
|
|
use defmt::info;
|
2021-03-29 02:47:10 +02:00
|
|
|
use embassy::executor::Spawner;
|
2021-03-27 03:50:18 +01:00
|
|
|
use embassy_nrf::gpio::{Input, Pull};
|
2021-05-12 01:57:01 +02:00
|
|
|
use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity};
|
2021-08-03 22:08:13 +02:00
|
|
|
use embassy_nrf::Peripherals;
|
2020-09-24 22:04:45 +02:00
|
|
|
|
2022-04-02 04:35:06 +02:00
|
|
|
use defmt_rtt as _; // global logger
|
|
|
|
use panic_probe as _;
|
|
|
|
|
2021-03-29 02:47:10 +02:00
|
|
|
#[embassy::main]
|
2021-05-17 11:48:58 +02:00
|
|
|
async fn main(_spawner: Spawner, p: Peripherals) {
|
2020-09-23 00:32:49 +02:00
|
|
|
info!("Starting!");
|
|
|
|
|
2021-03-27 03:50:18 +01:00
|
|
|
let ch1 = InputChannel::new(
|
|
|
|
p.GPIOTE_CH0,
|
|
|
|
Input::new(p.P0_11, Pull::Up),
|
|
|
|
InputChannelPolarity::HiToLo,
|
|
|
|
);
|
|
|
|
let ch2 = InputChannel::new(
|
|
|
|
p.GPIOTE_CH1,
|
|
|
|
Input::new(p.P0_12, Pull::Up),
|
|
|
|
InputChannelPolarity::LoToHi,
|
|
|
|
);
|
|
|
|
let ch3 = InputChannel::new(
|
|
|
|
p.GPIOTE_CH2,
|
|
|
|
Input::new(p.P0_24, Pull::Up),
|
|
|
|
InputChannelPolarity::Toggle,
|
|
|
|
);
|
|
|
|
let ch4 = InputChannel::new(
|
|
|
|
p.GPIOTE_CH3,
|
|
|
|
Input::new(p.P0_25, Pull::Up),
|
|
|
|
InputChannelPolarity::Toggle,
|
|
|
|
);
|
2020-09-23 00:32:49 +02:00
|
|
|
|
2021-02-04 23:56:17 +01:00
|
|
|
let button1 = async {
|
2020-09-23 00:32:49 +02:00
|
|
|
loop {
|
2021-02-04 23:56:17 +01:00
|
|
|
ch1.wait().await;
|
2020-09-23 00:32:49 +02:00
|
|
|
info!("Button 1 pressed")
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let button2 = async {
|
|
|
|
loop {
|
2021-02-04 23:56:17 +01:00
|
|
|
ch2.wait().await;
|
2020-09-23 00:32:49 +02:00
|
|
|
info!("Button 2 released")
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let button3 = async {
|
|
|
|
loop {
|
2021-02-04 23:56:17 +01:00
|
|
|
ch3.wait().await;
|
2020-09-23 00:32:49 +02:00
|
|
|
info!("Button 3 toggled")
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let button4 = async {
|
|
|
|
loop {
|
2021-02-04 23:56:17 +01:00
|
|
|
ch4.wait().await;
|
2020-09-23 00:32:49 +02:00
|
|
|
info!("Button 4 toggled")
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
futures::join!(button1, button2, button3, button4);
|
|
|
|
}
|