diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-05-12 01:01:08 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-05-17 00:57:20 +0200 |
| commit | 97b01f1c4799a66bc2af596bfc5138ccf919a6de (patch) | |
| tree | a2d705f32bf9e5abea5cdb0239ec2b2b31092c4d /embassy-nrf-examples/src | |
| parent | 92be72e0e3917782aade44e5b4cdbebb2dbab46e (diff) | |
nrf/gpiote: initialize automatically
Diffstat (limited to 'embassy-nrf-examples/src')
| -rw-r--r-- | embassy-nrf-examples/src/bin/gpiote_channel.rs | 5 | ||||
| -rw-r--r-- | embassy-nrf-examples/src/bin/gpiote_port.rs | 13 | ||||
| -rw-r--r-- | embassy-nrf-examples/src/bin/ppi.rs | 7 |
3 files changed, 6 insertions, 19 deletions
diff --git a/embassy-nrf-examples/src/bin/gpiote_channel.rs b/embassy-nrf-examples/src/bin/gpiote_channel.rs index 9e653192b..ee670acd5 100644 --- a/embassy-nrf-examples/src/bin/gpiote_channel.rs +++ b/embassy-nrf-examples/src/bin/gpiote_channel.rs | |||
| @@ -18,30 +18,25 @@ use embassy_nrf::{interrupt, Peripherals}; | |||
| 18 | #[embassy::main] | 18 | #[embassy::main] |
| 19 | async fn main(spawner: Spawner) { | 19 | async fn main(spawner: Spawner) { |
| 20 | let p = Peripherals::take().unwrap(); | 20 | let p = Peripherals::take().unwrap(); |
| 21 | let g = gpiote::initialize(p.GPIOTE, interrupt::take!(GPIOTE)); | ||
| 22 | 21 | ||
| 23 | info!("Starting!"); | 22 | info!("Starting!"); |
| 24 | 23 | ||
| 25 | let ch1 = InputChannel::new( | 24 | let ch1 = InputChannel::new( |
| 26 | g, | ||
| 27 | p.GPIOTE_CH0, | 25 | p.GPIOTE_CH0, |
| 28 | Input::new(p.P0_11, Pull::Up), | 26 | Input::new(p.P0_11, Pull::Up), |
| 29 | InputChannelPolarity::HiToLo, | 27 | InputChannelPolarity::HiToLo, |
| 30 | ); | 28 | ); |
| 31 | let ch2 = InputChannel::new( | 29 | let ch2 = InputChannel::new( |
| 32 | g, | ||
| 33 | p.GPIOTE_CH1, | 30 | p.GPIOTE_CH1, |
| 34 | Input::new(p.P0_12, Pull::Up), | 31 | Input::new(p.P0_12, Pull::Up), |
| 35 | InputChannelPolarity::LoToHi, | 32 | InputChannelPolarity::LoToHi, |
| 36 | ); | 33 | ); |
| 37 | let ch3 = InputChannel::new( | 34 | let ch3 = InputChannel::new( |
| 38 | g, | ||
| 39 | p.GPIOTE_CH2, | 35 | p.GPIOTE_CH2, |
| 40 | Input::new(p.P0_24, Pull::Up), | 36 | Input::new(p.P0_24, Pull::Up), |
| 41 | InputChannelPolarity::Toggle, | 37 | InputChannelPolarity::Toggle, |
| 42 | ); | 38 | ); |
| 43 | let ch4 = InputChannel::new( | 39 | let ch4 = InputChannel::new( |
| 44 | g, | ||
| 45 | p.GPIOTE_CH3, | 40 | p.GPIOTE_CH3, |
| 46 | Input::new(p.P0_25, Pull::Up), | 41 | Input::new(p.P0_25, Pull::Up), |
| 47 | InputChannelPolarity::Toggle, | 42 | InputChannelPolarity::Toggle, |
diff --git a/embassy-nrf-examples/src/bin/gpiote_port.rs b/embassy-nrf-examples/src/bin/gpiote_port.rs index 386806dfc..717d3398b 100644 --- a/embassy-nrf-examples/src/bin/gpiote_port.rs +++ b/embassy-nrf-examples/src/bin/gpiote_port.rs | |||
| @@ -8,12 +8,11 @@ | |||
| 8 | #[path = "../example_common.rs"] | 8 | #[path = "../example_common.rs"] |
| 9 | mod example_common; | 9 | mod example_common; |
| 10 | 10 | ||
| 11 | use core::pin::Pin; | ||
| 12 | use defmt::panic; | 11 | use defmt::panic; |
| 13 | use embassy::executor::Spawner; | 12 | use embassy::executor::Spawner; |
| 14 | use embassy::traits::gpio::{WaitForHigh, WaitForLow}; | 13 | use embassy::traits::gpio::{WaitForHigh, WaitForLow}; |
| 15 | use embassy_nrf::gpio::{AnyPin, Input, Pin as _, Pull}; | 14 | use embassy_nrf::gpio::{AnyPin, Input, Pin as _, Pull}; |
| 16 | use embassy_nrf::gpiote::{self, PortInput}; | 15 | use embassy_nrf::gpiote::PortInput; |
| 17 | use embassy_nrf::interrupt; | 16 | use embassy_nrf::interrupt; |
| 18 | use embassy_nrf::Peripherals; | 17 | use embassy_nrf::Peripherals; |
| 19 | use example_common::*; | 18 | use example_common::*; |
| @@ -32,12 +31,12 @@ async fn button_task(n: usize, mut pin: PortInput<'static, AnyPin>) { | |||
| 32 | async fn main(spawner: Spawner) { | 31 | async fn main(spawner: Spawner) { |
| 33 | let p = Peripherals::take().unwrap(); | 32 | let p = Peripherals::take().unwrap(); |
| 34 | 33 | ||
| 35 | let g = gpiote::initialize(p.GPIOTE, interrupt::take!(GPIOTE)); | 34 | info!("Starting!"); |
| 36 | 35 | ||
| 37 | let btn1 = PortInput::new(g, Input::new(p.P0_11.degrade(), Pull::Up)); | 36 | let btn1 = PortInput::new(Input::new(p.P0_11.degrade(), Pull::Up)); |
| 38 | let btn2 = PortInput::new(g, Input::new(p.P0_12.degrade(), Pull::Up)); | 37 | let btn2 = PortInput::new(Input::new(p.P0_12.degrade(), Pull::Up)); |
| 39 | let btn3 = PortInput::new(g, Input::new(p.P0_24.degrade(), Pull::Up)); | 38 | let btn3 = PortInput::new(Input::new(p.P0_24.degrade(), Pull::Up)); |
| 40 | let btn4 = PortInput::new(g, Input::new(p.P0_25.degrade(), Pull::Up)); | 39 | let btn4 = PortInput::new(Input::new(p.P0_25.degrade(), Pull::Up)); |
| 41 | 40 | ||
| 42 | spawner.spawn(button_task(1, btn1)).unwrap(); | 41 | spawner.spawn(button_task(1, btn1)).unwrap(); |
| 43 | spawner.spawn(button_task(2, btn2)).unwrap(); | 42 | spawner.spawn(button_task(2, btn2)).unwrap(); |
diff --git a/embassy-nrf-examples/src/bin/ppi.rs b/embassy-nrf-examples/src/bin/ppi.rs index aeda76f21..3c39e032e 100644 --- a/embassy-nrf-examples/src/bin/ppi.rs +++ b/embassy-nrf-examples/src/bin/ppi.rs | |||
| @@ -21,44 +21,37 @@ use gpiote::{OutputChannel, OutputChannelPolarity}; | |||
| 21 | #[embassy::main] | 21 | #[embassy::main] |
| 22 | async fn main(spawner: Spawner) { | 22 | async fn main(spawner: Spawner) { |
| 23 | let p = Peripherals::take().unwrap(); | 23 | let p = Peripherals::take().unwrap(); |
| 24 | let g = gpiote::initialize(p.GPIOTE, interrupt::take!(GPIOTE)); | ||
| 25 | 24 | ||
| 26 | info!("Starting!"); | 25 | info!("Starting!"); |
| 27 | 26 | ||
| 28 | let button1 = InputChannel::new( | 27 | let button1 = InputChannel::new( |
| 29 | g, | ||
| 30 | p.GPIOTE_CH0, | 28 | p.GPIOTE_CH0, |
| 31 | Input::new(p.P0_11, Pull::Up), | 29 | Input::new(p.P0_11, Pull::Up), |
| 32 | InputChannelPolarity::HiToLo, | 30 | InputChannelPolarity::HiToLo, |
| 33 | ); | 31 | ); |
| 34 | let button2 = InputChannel::new( | 32 | let button2 = InputChannel::new( |
| 35 | g, | ||
| 36 | p.GPIOTE_CH1, | 33 | p.GPIOTE_CH1, |
| 37 | Input::new(p.P0_12, Pull::Up), | 34 | Input::new(p.P0_12, Pull::Up), |
| 38 | InputChannelPolarity::HiToLo, | 35 | InputChannelPolarity::HiToLo, |
| 39 | ); | 36 | ); |
| 40 | let button3 = InputChannel::new( | 37 | let button3 = InputChannel::new( |
| 41 | g, | ||
| 42 | p.GPIOTE_CH2, | 38 | p.GPIOTE_CH2, |
| 43 | Input::new(p.P0_24, Pull::Up), | 39 | Input::new(p.P0_24, Pull::Up), |
| 44 | InputChannelPolarity::HiToLo, | 40 | InputChannelPolarity::HiToLo, |
| 45 | ); | 41 | ); |
| 46 | let button4 = InputChannel::new( | 42 | let button4 = InputChannel::new( |
| 47 | g, | ||
| 48 | p.GPIOTE_CH3, | 43 | p.GPIOTE_CH3, |
| 49 | Input::new(p.P0_25, Pull::Up), | 44 | Input::new(p.P0_25, Pull::Up), |
| 50 | InputChannelPolarity::HiToLo, | 45 | InputChannelPolarity::HiToLo, |
| 51 | ); | 46 | ); |
| 52 | 47 | ||
| 53 | let led1 = OutputChannel::new( | 48 | let led1 = OutputChannel::new( |
| 54 | g, | ||
| 55 | p.GPIOTE_CH4, | 49 | p.GPIOTE_CH4, |
| 56 | Output::new(p.P0_13, Level::Low, OutputDrive::Standard), | 50 | Output::new(p.P0_13, Level::Low, OutputDrive::Standard), |
| 57 | OutputChannelPolarity::Toggle, | 51 | OutputChannelPolarity::Toggle, |
| 58 | ); | 52 | ); |
| 59 | 53 | ||
| 60 | let led2 = OutputChannel::new( | 54 | let led2 = OutputChannel::new( |
| 61 | g, | ||
| 62 | p.GPIOTE_CH5, | 55 | p.GPIOTE_CH5, |
| 63 | Output::new(p.P0_14, Level::Low, OutputDrive::Standard), | 56 | Output::new(p.P0_14, Level::Low, OutputDrive::Standard), |
| 64 | OutputChannelPolarity::Toggle, | 57 | OutputChannelPolarity::Toggle, |
