diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-01-01 22:41:59 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-01-01 22:46:32 +0100 |
| commit | 20d3dc87f95f844e747a7e93036ce9ddac369081 (patch) | |
| tree | 3842a1f3a343de0af8195a1a2a2cf0da17cb7c37 /examples/src/bin/gpiote.rs | |
| parent | 4783222f675c1316d0e1a0fda92591f7aca63456 (diff) | |
Rename examples -> embassy-nrf-examples
Diffstat (limited to 'examples/src/bin/gpiote.rs')
| -rw-r--r-- | examples/src/bin/gpiote.rs | 83 |
1 files changed, 0 insertions, 83 deletions
diff --git a/examples/src/bin/gpiote.rs b/examples/src/bin/gpiote.rs deleted file mode 100644 index afa1b85d5..000000000 --- a/examples/src/bin/gpiote.rs +++ /dev/null | |||
| @@ -1,83 +0,0 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | #[path = "../example_common.rs"] | ||
| 6 | mod example_common; | ||
| 7 | use example_common::*; | ||
| 8 | |||
| 9 | use cortex_m_rt::entry; | ||
| 10 | use defmt::panic; | ||
| 11 | use nrf52840_hal::gpio; | ||
| 12 | |||
| 13 | use embassy::executor::{task, Executor}; | ||
| 14 | use embassy::util::Forever; | ||
| 15 | use embassy_nrf::gpiote; | ||
| 16 | use embassy_nrf::interrupt; | ||
| 17 | |||
| 18 | #[task] | ||
| 19 | async fn run() { | ||
| 20 | let p = unwrap!(embassy_nrf::pac::Peripherals::take()); | ||
| 21 | let port0 = gpio::p0::Parts::new(p.P0); | ||
| 22 | |||
| 23 | let g = gpiote::Gpiote::new(p.GPIOTE, interrupt::take!(GPIOTE)); | ||
| 24 | |||
| 25 | info!("Starting!"); | ||
| 26 | |||
| 27 | let pin1 = port0.p0_11.into_pullup_input().degrade(); | ||
| 28 | let button1 = async { | ||
| 29 | let ch = unwrap!(g.new_input_channel(pin1, gpiote::InputChannelPolarity::HiToLo)); | ||
| 30 | |||
| 31 | loop { | ||
| 32 | ch.wait().await; | ||
| 33 | info!("Button 1 pressed") | ||
| 34 | } | ||
| 35 | }; | ||
| 36 | |||
| 37 | let pin2 = port0.p0_12.into_pullup_input().degrade(); | ||
| 38 | let button2 = async { | ||
| 39 | let ch = unwrap!(g.new_input_channel(pin2, gpiote::InputChannelPolarity::LoToHi)); | ||
| 40 | |||
| 41 | loop { | ||
| 42 | ch.wait().await; | ||
| 43 | info!("Button 2 released") | ||
| 44 | } | ||
| 45 | }; | ||
| 46 | |||
| 47 | let pin3 = port0.p0_24.into_pullup_input().degrade(); | ||
| 48 | let button3 = async { | ||
| 49 | let ch = unwrap!(g.new_input_channel(pin3, gpiote::InputChannelPolarity::Toggle)); | ||
| 50 | |||
| 51 | loop { | ||
| 52 | ch.wait().await; | ||
| 53 | info!("Button 3 toggled") | ||
| 54 | } | ||
| 55 | }; | ||
| 56 | |||
| 57 | let pin4 = port0.p0_25.into_pullup_input().degrade(); | ||
| 58 | let button4 = async { | ||
| 59 | let ch = unwrap!(g.new_input_channel(pin4, gpiote::InputChannelPolarity::Toggle)); | ||
| 60 | |||
| 61 | loop { | ||
| 62 | ch.wait().await; | ||
| 63 | info!("Button 4 toggled") | ||
| 64 | } | ||
| 65 | }; | ||
| 66 | |||
| 67 | futures::join!(button1, button2, button3, button4); | ||
| 68 | } | ||
| 69 | |||
| 70 | static EXECUTOR: Forever<Executor> = Forever::new(); | ||
| 71 | |||
| 72 | #[entry] | ||
| 73 | fn main() -> ! { | ||
| 74 | info!("Hello World!"); | ||
| 75 | |||
| 76 | let executor = EXECUTOR.put(Executor::new(cortex_m::asm::sev)); | ||
| 77 | unwrap!(executor.spawn(run())); | ||
| 78 | |||
| 79 | loop { | ||
| 80 | executor.run(); | ||
| 81 | cortex_m::asm::wfe(); | ||
| 82 | } | ||
| 83 | } | ||
