diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-12-14 14:09:59 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-12-14 14:09:59 +0000 |
| commit | 1a7b9e3279b4920392cfb1a6614968d8be4eee2a (patch) | |
| tree | f4e0387818d6a12fc47349e9376ea12355e8b95f /examples | |
| parent | 3f3b7d066ebfeee76dc9467ee3c4c05468730e40 (diff) | |
| parent | 153b1bbdbfc38b7973b27c05589514bee993e690 (diff) | |
Merge #542
542: nrf/gpiote: remove PortInput, move impls to Input/FlexPin. r=Dirbaio a=Dirbaio
`PortInput` is just a dumb wrapper around `Input`, it has no reason whatsoever to exist. This PR moves the `wait_for_x` functionality to `Input` directly.
It also adds it to `FlexPin` for completeness and consistency with `Input`.
(The reason `PortInput` exists is a while ago `GPIOTE` was an owned singleton that you had to initialize, so `PortInput::new()` would require it to enforce it's been initialized. This doesn't apply anymore now that GPIOTE is "global")
Co-authored-by: Dario Nieuwenhuis <[email protected]>
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/nrf/src/bin/gpiote_port.rs | 11 | ||||
| -rw-r--r-- | examples/nrf/src/bin/wdt.rs | 3 |
2 files changed, 6 insertions, 8 deletions
diff --git a/examples/nrf/src/bin/gpiote_port.rs b/examples/nrf/src/bin/gpiote_port.rs index ba9436aca..76c861d95 100644 --- a/examples/nrf/src/bin/gpiote_port.rs +++ b/examples/nrf/src/bin/gpiote_port.rs | |||
| @@ -8,12 +8,11 @@ mod example_common; | |||
| 8 | use embassy::executor::Spawner; | 8 | use embassy::executor::Spawner; |
| 9 | use embassy::traits::gpio::{WaitForHigh, WaitForLow}; | 9 | use embassy::traits::gpio::{WaitForHigh, WaitForLow}; |
| 10 | use embassy_nrf::gpio::{AnyPin, Input, Pin as _, Pull}; | 10 | use embassy_nrf::gpio::{AnyPin, Input, Pin as _, Pull}; |
| 11 | use embassy_nrf::gpiote::PortInput; | ||
| 12 | use embassy_nrf::Peripherals; | 11 | use embassy_nrf::Peripherals; |
| 13 | use example_common::*; | 12 | use example_common::*; |
| 14 | 13 | ||
| 15 | #[embassy::task(pool_size = 4)] | 14 | #[embassy::task(pool_size = 4)] |
| 16 | async fn button_task(n: usize, mut pin: PortInput<'static, AnyPin>) { | 15 | async fn button_task(n: usize, mut pin: Input<'static, AnyPin>) { |
| 17 | loop { | 16 | loop { |
| 18 | pin.wait_for_low().await; | 17 | pin.wait_for_low().await; |
| 19 | info!("Button {:?} pressed!", n); | 18 | info!("Button {:?} pressed!", n); |
| @@ -26,10 +25,10 @@ async fn button_task(n: usize, mut pin: PortInput<'static, AnyPin>) { | |||
| 26 | async fn main(spawner: Spawner, p: Peripherals) { | 25 | async fn main(spawner: Spawner, p: Peripherals) { |
| 27 | info!("Starting!"); | 26 | info!("Starting!"); |
| 28 | 27 | ||
| 29 | let btn1 = PortInput::new(Input::new(p.P0_11.degrade(), Pull::Up)); | 28 | let btn1 = Input::new(p.P0_11.degrade(), Pull::Up); |
| 30 | let btn2 = PortInput::new(Input::new(p.P0_12.degrade(), Pull::Up)); | 29 | let btn2 = Input::new(p.P0_12.degrade(), Pull::Up); |
| 31 | let btn3 = PortInput::new(Input::new(p.P0_24.degrade(), Pull::Up)); | 30 | let btn3 = Input::new(p.P0_24.degrade(), Pull::Up); |
| 32 | let btn4 = PortInput::new(Input::new(p.P0_25.degrade(), Pull::Up)); | 31 | let btn4 = Input::new(p.P0_25.degrade(), Pull::Up); |
| 33 | 32 | ||
| 34 | unwrap!(spawner.spawn(button_task(1, btn1))); | 33 | unwrap!(spawner.spawn(button_task(1, btn1))); |
| 35 | unwrap!(spawner.spawn(button_task(2, btn2))); | 34 | unwrap!(spawner.spawn(button_task(2, btn2))); |
diff --git a/examples/nrf/src/bin/wdt.rs b/examples/nrf/src/bin/wdt.rs index 76f171cd3..78c2205d9 100644 --- a/examples/nrf/src/bin/wdt.rs +++ b/examples/nrf/src/bin/wdt.rs | |||
| @@ -8,7 +8,6 @@ mod example_common; | |||
| 8 | use defmt::*; | 8 | use defmt::*; |
| 9 | use embassy::executor::Spawner; | 9 | use embassy::executor::Spawner; |
| 10 | use embassy_nrf::gpio::{Input, Pull}; | 10 | use embassy_nrf::gpio::{Input, Pull}; |
| 11 | use embassy_nrf::gpiote::PortInput; | ||
| 12 | use embassy_nrf::wdt::{Config, Watchdog}; | 11 | use embassy_nrf::wdt::{Config, Watchdog}; |
| 13 | use embassy_nrf::Peripherals; | 12 | use embassy_nrf::Peripherals; |
| 14 | use embassy_traits::gpio::{WaitForHigh, WaitForLow}; | 13 | use embassy_traits::gpio::{WaitForHigh, WaitForLow}; |
| @@ -32,7 +31,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 32 | } | 31 | } |
| 33 | }; | 32 | }; |
| 34 | 33 | ||
| 35 | let mut button = PortInput::new(Input::new(p.P0_11, Pull::Up)); | 34 | let mut button = Input::new(p.P0_11, Pull::Up); |
| 36 | 35 | ||
| 37 | info!("Watchdog started, press button 1 to pet it or I'll reset in 3 seconds!"); | 36 | info!("Watchdog started, press button 1 to pet it or I'll reset in 3 seconds!"); |
| 38 | 37 | ||
