diff options
| author | Dario Nieuwenhuis <[email protected]> | 2020-11-09 01:04:34 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2020-11-09 01:04:34 +0100 |
| commit | 2e062f562773f4f4ff978e7976c2d4b08b968a6c (patch) | |
| tree | 7a671295164f2c2dfd3b2432a12d7038bec6676a /examples | |
| parent | 61b1d4e18889fa0c6238fe2d5758e2276a62c590 (diff) | |
gpiote: change port api to directly return futures.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/src/bin/gpiote_port.rs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/examples/src/bin/gpiote_port.rs b/examples/src/bin/gpiote_port.rs index bc0cb4367..585317642 100644 --- a/examples/src/bin/gpiote_port.rs +++ b/examples/src/bin/gpiote_port.rs | |||
| @@ -12,15 +12,13 @@ use nrf52840_hal::gpio; | |||
| 12 | 12 | ||
| 13 | use embassy::executor::{task, Executor}; | 13 | use embassy::executor::{task, Executor}; |
| 14 | use embassy::util::Forever; | 14 | use embassy::util::Forever; |
| 15 | use embassy_nrf::gpiote; | 15 | use embassy_nrf::gpiote::{Gpiote, PortInputPolarity}; |
| 16 | |||
| 17 | async fn button(g: &gpiote::Gpiote, n: usize, pin: gpio::Pin<gpio::Input<gpio::PullUp>>) { | ||
| 18 | let ch = g.new_port_input(pin); | ||
| 19 | 16 | ||
| 17 | async fn button(g: &Gpiote, n: usize, pin: gpio::Pin<gpio::Input<gpio::PullUp>>) { | ||
| 20 | loop { | 18 | loop { |
| 21 | ch.wait(gpiote::PortInputPolarity::Low).await; | 19 | g.wait_port_input(&pin, PortInputPolarity::Low).await; |
| 22 | info!("Button {:?} pressed!", n); | 20 | info!("Button {:?} pressed!", n); |
| 23 | ch.wait(gpiote::PortInputPolarity::High).await; | 21 | g.wait_port_input(&pin, PortInputPolarity::High).await; |
| 24 | info!("Button {:?} released!", n); | 22 | info!("Button {:?} released!", n); |
| 25 | } | 23 | } |
| 26 | } | 24 | } |
| @@ -30,12 +28,12 @@ async fn run() { | |||
| 30 | let p = unwrap!(embassy_nrf::pac::Peripherals::take()); | 28 | let p = unwrap!(embassy_nrf::pac::Peripherals::take()); |
| 31 | let port0 = gpio::p0::Parts::new(p.P0); | 29 | let port0 = gpio::p0::Parts::new(p.P0); |
| 32 | 30 | ||
| 33 | let g = gpiote::Gpiote::new(p.GPIOTE); | 31 | let g = Gpiote::new(p.GPIOTE); |
| 34 | info!( | 32 | info!( |
| 35 | "sizeof Signal<()> = {:usize}", | 33 | "sizeof Signal<()> = {:usize}", |
| 36 | mem::size_of::<embassy::util::Signal<()>>() | 34 | mem::size_of::<embassy::util::Signal<()>>() |
| 37 | ); | 35 | ); |
| 38 | info!("sizeof gpiote = {:usize}", mem::size_of::<gpiote::Gpiote>()); | 36 | info!("sizeof gpiote = {:usize}", mem::size_of::<Gpiote>()); |
| 39 | 37 | ||
| 40 | info!("Starting!"); | 38 | info!("Starting!"); |
| 41 | 39 | ||
