diff options
Diffstat (limited to 'examples/nrf/src/bin/ppi.rs')
| -rw-r--r-- | examples/nrf/src/bin/ppi.rs | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/examples/nrf/src/bin/ppi.rs b/examples/nrf/src/bin/ppi.rs new file mode 100644 index 000000000..717604b9e --- /dev/null +++ b/examples/nrf/src/bin/ppi.rs | |||
| @@ -0,0 +1,87 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(min_type_alias_impl_trait)] | ||
| 4 | #![feature(impl_trait_in_bindings)] | ||
| 5 | #![feature(type_alias_impl_trait)] | ||
| 6 | #![allow(incomplete_features)] | ||
| 7 | |||
| 8 | #[path = "../example_common.rs"] | ||
| 9 | mod example_common; | ||
| 10 | use example_common::*; | ||
| 11 | |||
| 12 | use core::future::pending; | ||
| 13 | use defmt::panic; | ||
| 14 | use embassy::executor::Spawner; | ||
| 15 | use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; | ||
| 16 | use embassy_nrf::gpiote::{self, InputChannel, InputChannelPolarity}; | ||
| 17 | use embassy_nrf::ppi::Ppi; | ||
| 18 | use embassy_nrf::{interrupt, Peripherals}; | ||
| 19 | use gpiote::{OutputChannel, OutputChannelPolarity}; | ||
| 20 | |||
| 21 | #[embassy::main] | ||
| 22 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 23 | info!("Starting!"); | ||
| 24 | |||
| 25 | let button1 = InputChannel::new( | ||
| 26 | p.GPIOTE_CH0, | ||
| 27 | Input::new(p.P0_11, Pull::Up), | ||
| 28 | InputChannelPolarity::HiToLo, | ||
| 29 | ); | ||
| 30 | let button2 = InputChannel::new( | ||
| 31 | p.GPIOTE_CH1, | ||
| 32 | Input::new(p.P0_12, Pull::Up), | ||
| 33 | InputChannelPolarity::HiToLo, | ||
| 34 | ); | ||
| 35 | let button3 = InputChannel::new( | ||
| 36 | p.GPIOTE_CH2, | ||
| 37 | Input::new(p.P0_24, Pull::Up), | ||
| 38 | InputChannelPolarity::HiToLo, | ||
| 39 | ); | ||
| 40 | let button4 = InputChannel::new( | ||
| 41 | p.GPIOTE_CH3, | ||
| 42 | Input::new(p.P0_25, Pull::Up), | ||
| 43 | InputChannelPolarity::HiToLo, | ||
| 44 | ); | ||
| 45 | |||
| 46 | let led1 = OutputChannel::new( | ||
| 47 | p.GPIOTE_CH4, | ||
| 48 | Output::new(p.P0_13, Level::Low, OutputDrive::Standard), | ||
| 49 | OutputChannelPolarity::Toggle, | ||
| 50 | ); | ||
| 51 | |||
| 52 | let led2 = OutputChannel::new( | ||
| 53 | p.GPIOTE_CH5, | ||
| 54 | Output::new(p.P0_14, Level::Low, OutputDrive::Standard), | ||
| 55 | OutputChannelPolarity::Toggle, | ||
| 56 | ); | ||
| 57 | |||
| 58 | let mut ppi = Ppi::new(p.PPI_CH0); | ||
| 59 | ppi.set_event(button1.event_in()); | ||
| 60 | ppi.set_task(led1.task_out()); | ||
| 61 | ppi.enable(); | ||
| 62 | |||
| 63 | let mut ppi = Ppi::new(p.PPI_CH1); | ||
| 64 | ppi.set_event(button2.event_in()); | ||
| 65 | ppi.set_task(led1.task_clr()); | ||
| 66 | ppi.enable(); | ||
| 67 | |||
| 68 | let mut ppi = Ppi::new(p.PPI_CH2); | ||
| 69 | ppi.set_event(button3.event_in()); | ||
| 70 | ppi.set_task(led1.task_set()); | ||
| 71 | ppi.enable(); | ||
| 72 | |||
| 73 | let mut ppi = Ppi::new(p.PPI_CH3); | ||
| 74 | ppi.set_event(button4.event_in()); | ||
| 75 | ppi.set_task(led1.task_out()); | ||
| 76 | ppi.set_fork_task(led2.task_out()); | ||
| 77 | ppi.enable(); | ||
| 78 | |||
| 79 | info!("PPI setup!"); | ||
| 80 | info!("Press button 1 to toggle LED 1"); | ||
| 81 | info!("Press button 2 to turn on LED 1"); | ||
| 82 | info!("Press button 3 to turn off LED 1"); | ||
| 83 | info!("Press button 4 to toggle LEDs 1 and 2"); | ||
| 84 | |||
| 85 | // Block forever so the above drivers don't get dropped | ||
| 86 | pending::<()>().await; | ||
| 87 | } | ||
