From 22bc1e4ae17fbc76442d4ee1375cf3a86e0b4757 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sun, 19 Dec 2021 23:25:02 +0100 Subject: nrf/gpio: add infallible inherent methods, remove some duplication. This implements Input and Output using FlexPin, to avoid some code duplication. --- examples/nrf/src/bin/blinky.rs | 6 ++---- examples/nrf/src/bin/mpsc.rs | 5 ++--- examples/nrf/src/bin/spim.rs | 17 ++++++++--------- 3 files changed, 12 insertions(+), 16 deletions(-) (limited to 'examples/nrf/src') diff --git a/examples/nrf/src/bin/blinky.rs b/examples/nrf/src/bin/blinky.rs index a12fe58ff..0fc004ed8 100644 --- a/examples/nrf/src/bin/blinky.rs +++ b/examples/nrf/src/bin/blinky.rs @@ -5,21 +5,19 @@ #[path = "../example_common.rs"] mod example_common; -use defmt::unwrap; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_nrf::gpio::{Level, Output, OutputDrive}; use embassy_nrf::Peripherals; -use embedded_hal::digital::v2::OutputPin; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); loop { - unwrap!(led.set_high()); + led.set_high(); Timer::after(Duration::from_millis(300)).await; - unwrap!(led.set_low()); + led.set_low(); Timer::after(Duration::from_millis(300)).await; } } diff --git a/examples/nrf/src/bin/mpsc.rs b/examples/nrf/src/bin/mpsc.rs index c85b7c282..454fb9541 100644 --- a/examples/nrf/src/bin/mpsc.rs +++ b/examples/nrf/src/bin/mpsc.rs @@ -13,7 +13,6 @@ use embassy::time::{Duration, Timer}; use embassy::util::Forever; use embassy_nrf::gpio::{Level, Output, OutputDrive}; use embassy_nrf::Peripherals; -use embedded_hal::digital::v2::OutputPin; enum LedState { On, @@ -53,8 +52,8 @@ async fn main(spawner: Spawner, p: Peripherals) { Err(TryRecvError::Closed) => break, }; match maybe_message { - Some(LedState::On) => unwrap!(led.set_high()), - Some(LedState::Off) => unwrap!(led.set_low()), + Some(LedState::On) => led.set_high(), + Some(LedState::Off) => led.set_low(), _ => (), } } diff --git a/examples/nrf/src/bin/spim.rs b/examples/nrf/src/bin/spim.rs index d34ca0b85..fc31d140a 100644 --- a/examples/nrf/src/bin/spim.rs +++ b/examples/nrf/src/bin/spim.rs @@ -10,7 +10,6 @@ use embassy_nrf::gpio::{Level, Output, OutputDrive}; use embassy_nrf::Peripherals; use embassy_nrf::{interrupt, spim}; use embassy_traits::spi::FullDuplex; -use embedded_hal::digital::v2::*; use example_common::*; #[embassy::main] @@ -29,12 +28,12 @@ async fn main(_spawner: Spawner, p: Peripherals) { // softreset cortex_m::asm::delay(10); - unwrap!(ncs.set_low()); + ncs.set_low(); cortex_m::asm::delay(5); let tx = [0xFF]; unwrap!(spim.read_write(&mut [], &tx).await); cortex_m::asm::delay(10); - unwrap!(ncs.set_high()); + ncs.set_high(); cortex_m::asm::delay(100000); @@ -42,31 +41,31 @@ async fn main(_spawner: Spawner, p: Peripherals) { // read ESTAT cortex_m::asm::delay(5000); - unwrap!(ncs.set_low()); + ncs.set_low(); cortex_m::asm::delay(5000); let tx = [0b000_11101, 0]; unwrap!(spim.read_write(&mut rx, &tx).await); cortex_m::asm::delay(5000); - unwrap!(ncs.set_high()); + ncs.set_high(); info!("estat: {=[?]}", rx); // Switch to bank 3 cortex_m::asm::delay(10); - unwrap!(ncs.set_low()); + ncs.set_low(); cortex_m::asm::delay(5); let tx = [0b100_11111, 0b11]; unwrap!(spim.read_write(&mut rx, &tx).await); cortex_m::asm::delay(10); - unwrap!(ncs.set_high()); + ncs.set_high(); // read EREVID cortex_m::asm::delay(10); - unwrap!(ncs.set_low()); + ncs.set_low(); cortex_m::asm::delay(5); let tx = [0b000_10010, 0]; unwrap!(spim.read_write(&mut rx, &tx).await); cortex_m::asm::delay(10); - unwrap!(ncs.set_high()); + ncs.set_high(); info!("erevid: {=[?]}", rx); } -- cgit