summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <dirbaio@dirbaio.net>2022-01-14 22:02:00 +0100
committerDario Nieuwenhuis <dirbaio@dirbaio.net>2022-01-19 17:59:55 +0100
commit58fc64722c65bbdc209ae0fd1700f03702bbcd08 (patch)
tree77f9412b47259cd4cf4170b0a257b371398d4f2c
parent52e156b429417bde59d0ea67d11256866f1dcec9 (diff)
downloadembassy-58fc64722c65bbdc209ae0fd1700f03702bbcd08.zip
stm32/gpio: expose all functionality as inherent methods.
-rw-r--r--embassy-lora/src/stm32wl/mod.rs19
-rw-r--r--embassy-stm32/src/exti.rs12
-rw-r--r--embassy-stm32/src/gpio.rs230
-rw-r--r--examples/stm32f1/src/bin/blinky.rs5
-rw-r--r--examples/stm32f3/src/bin/blinky.rs5
-rw-r--r--examples/stm32f3/src/bin/button.rs11
-rw-r--r--examples/stm32f4/src/bin/blinky.rs5
-rw-r--r--examples/stm32f4/src/bin/button.rs11
-rw-r--r--examples/stm32f4/src/bin/spi.rs5
-rw-r--r--examples/stm32f7/src/bin/blinky.rs5
-rw-r--r--examples/stm32f7/src/bin/button.rs11
-rw-r--r--examples/stm32g0/src/bin/blinky.rs5
-rw-r--r--examples/stm32g0/src/bin/button.rs3
-rw-r--r--examples/stm32g4/src/bin/blinky.rs5
-rw-r--r--examples/stm32g4/src/bin/button.rs3
-rw-r--r--examples/stm32h7/src/bin/blinky.rs5
-rw-r--r--examples/stm32h7/src/bin/camera.rs5
-rw-r--r--examples/stm32h7/src/bin/mco.rs5
-rw-r--r--examples/stm32h7/src/bin/rng.rs5
-rw-r--r--examples/stm32l0/src/bin/blinky.rs5
-rw-r--r--examples/stm32l0/src/bin/button.rs11
-rw-r--r--examples/stm32l0/src/bin/spi.rs5
-rw-r--r--examples/stm32l1/src/bin/blinky.rs5
-rw-r--r--examples/stm32l1/src/bin/spi.rs5
-rw-r--r--examples/stm32l4/src/bin/blinky.rs5
-rw-r--r--examples/stm32l4/src/bin/button.rs3
-rw-r--r--examples/stm32l4/src/bin/spi.rs5
-rw-r--r--examples/stm32l4/src/bin/spi_blocking_async.rs9
-rw-r--r--examples/stm32l4/src/bin/spi_dma.rs9
-rw-r--r--examples/stm32wb55/src/bin/blinky.rs5
-rw-r--r--examples/stm32wl55/src/bin/blinky.rs5
-rw-r--r--examples/stm32wl55/src/bin/button.rs11
-rw-r--r--examples/stm32wl55/src/bin/subghz.rs11
-rw-r--r--tests/stm32/src/bin/gpio.rs27
34 files changed, 266 insertions, 210 deletions
diff --git a/embassy-lora/src/stm32wl/mod.rs b/embassy-lora/src/stm32wl/mod.rs
index 8cac46f7..783140cb 100644
--- a/embassy-lora/src/stm32wl/mod.rs
+++ b/embassy-lora/src/stm32wl/mod.rs
@@ -16,7 +16,6 @@ use embassy_stm32::{
TxParams,
},
};
-use embedded_hal::digital::v2::OutputPin;
use lorawan_device::async_device::{
radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig},
Timings,
@@ -329,22 +328,22 @@ impl<'a> RadioSwitch<'a> {
}
pub(crate) fn set_rx(&mut self) {
- self.ctrl1.set_high().unwrap();
- self.ctrl2.set_low().unwrap();
- self.ctrl3.set_high().unwrap();
+ self.ctrl1.set_high();
+ self.ctrl2.set_low();
+ self.ctrl3.set_high();
}
pub(crate) fn set_tx_lp(&mut self) {
- self.ctrl1.set_high().unwrap();
- self.ctrl2.set_high().unwrap();
- self.ctrl3.set_high().unwrap();
+ self.ctrl1.set_high();
+ self.ctrl2.set_high();
+ self.ctrl3.set_high();
}
#[allow(dead_code)]
pub(crate) fn set_tx_hp(&mut self) {
- self.ctrl2.set_high().unwrap();
- self.ctrl1.set_low().unwrap();
- self.ctrl3.set_high().unwrap();
+ self.ctrl2.set_high();
+ self.ctrl1.set_low();
+ self.ctrl3.set_high();
}
}
diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs
index 552433b8..eded6ba7 100644
--- a/embassy-stm32/src/exti.rs
+++ b/embassy-stm32/src/exti.rs
@@ -94,17 +94,25 @@ impl<'d, T: GpioPin> ExtiInput<'d, T> {
pub fn new(pin: Input<'d, T>, _ch: impl Unborrow<Target = T::ExtiChannel> + 'd) -> Self {
Self { pin }
}
+
+ pub fn is_high(&self) -> bool {
+ self.pin.is_high()
+ }
+
+ pub fn is_low(&self) -> bool {
+ self.pin.is_low()
+ }
}
impl<'d, T: GpioPin> InputPin for ExtiInput<'d, T> {
type Error = Infallible;
fn is_high(&self) -> Result<bool, Self::Error> {
- self.pin.is_high()
+ Ok(self.is_high())
}
fn is_low(&self) -> Result<bool, Self::Error> {
- self.pin.is_low()
+ Ok(self.is_low())
}
}
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs
index 6b4a9285..57b9ba6b 100644
--- a/embassy-stm32/src/gpio.rs
+++ b/embassy-stm32/src/gpio.rs
@@ -3,7 +3,7 @@ use core::convert::Infallible;
use core::marker::PhantomData;
use embassy::util::Unborrow;
use embassy_hal_common::{unborrow, unsafe_impl_unborrow};
-use embedded_hal::digital::v2::{toggleable, InputPin, OutputPin, StatefulOutputPin};
+use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin};
use crate::pac;
use crate::pac::gpio::{self, vals};
@@ -113,6 +113,15 @@ impl<'d, T: Pin> Input<'d, T> {
phantom: PhantomData,
}
}
+
+ pub fn is_high(&self) -> bool {
+ !self.is_low()
+ }
+
+ pub fn is_low(&self) -> bool {
+ let state = unsafe { self.pin.block().idr().read().idr(self.pin.pin() as _) };
+ state == vals::Idr::LOW
+ }
}
impl<'d, T: Pin> Drop for Input<'d, T> {
@@ -132,19 +141,6 @@ impl<'d, T: Pin> Drop for Input<'d, T> {
}
}
-impl<'d, T: Pin> InputPin for Input<'d, T> {
- type Error = Infallible;
-
- fn is_high(&self) -> Result<bool, Self::Error> {
- self.is_low().map(|v| !v)
- }
-
- fn is_low(&self) -> Result<bool, Self::Error> {
- let state = unsafe { self.pin.block().idr().read().idr(self.pin.pin() as _) };
- Ok(state == vals::Idr::LOW)
- }
-}
-
/// Digital input or output level.
#[derive(Debug, Eq, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@@ -191,6 +187,36 @@ impl<'d, T: Pin> Output<'d, T> {
phantom: PhantomData,
}
}
+
+ /// Set the output as high.
+ pub fn set_high(&mut self) {
+ self.pin.set_high();
+ }
+
+ /// Set the output as low.
+ pub fn set_low(&mut self) {
+ self.pin.set_low();
+ }
+
+ /// Is the output pin set as high?
+ pub fn is_set_high(&self) -> bool {
+ !self.is_set_low()
+ }
+
+ /// Is the output pin set as low?
+ pub fn is_set_low(&self) -> bool {
+ let state = unsafe { self.pin.block().odr().read().odr(self.pin.pin() as _) };
+ state == vals::Odr::LOW
+ }
+
+ /// Toggle pin output
+ pub fn toggle(&mut self) {
+ if self.is_set_low() {
+ self.set_high()
+ } else {
+ self.set_low()
+ }
+ }
}
impl<'d, T: Pin> Drop for Output<'d, T> {
@@ -214,37 +240,6 @@ impl<'d, T: Pin> Drop for Output<'d, T> {
}
}
-impl<'d, T: Pin> OutputPin for Output<'d, T> {
- type Error = Infallible;
-
- /// Set the output as high.
- fn set_high(&mut self) -> Result<(), Self::Error> {
- self.pin.set_high();
- Ok(())
- }
-
- /// Set the output as low.
- fn set_low(&mut self) -> Result<(), Self::Error> {
- self.pin.set_low();
- Ok(())
- }
-}
-
-impl<'d, T: Pin> StatefulOutputPin for Output<'d, T> {
- /// Is the output pin set as high?
- fn is_set_high(&self) -> Result<bool, Self::Error> {
- self.is_set_low().map(|v| !v)
- }
-
- /// Is the output pin set as low?
- fn is_set_low(&self) -> Result<bool, Self::Error> {
- let state = unsafe { self.pin.block().odr().read().odr(self.pin.pin() as _) };
- Ok(state == vals::Odr::LOW)
- }
-}
-
-impl<'d, T: Pin> toggleable::Default for Output<'d, T> {}
-
/// GPIO output open-drain driver.
pub struct OutputOpenDrain<'d, T: Pin> {
pub(crate) pin: T,
@@ -294,6 +289,45 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> {
phantom: PhantomData,
}
}
+
+ pub fn is_high(&self) -> bool {
+ !self.is_low()
+ }
+
+ pub fn is_low(&self) -> bool {
+ let state = unsafe { self.pin.block().idr().read().idr(self.pin.pin() as _) };
+ state == vals::Idr::LOW
+ }
+
+ /// Set the output as high.
+ pub fn set_high(&mut self) {
+ self.pin.set_high();
+ }
+
+ /// Set the output as low.
+ pub fn set_low(&mut self) {
+ self.pin.set_low();
+ }
+
+ /// Is the output pin set as high?
+ pub fn is_set_high(&self) -> bool {
+ !self.is_set_low()
+ }
+
+ /// Is the output pin set as low?
+ pub fn is_set_low(&self) -> bool {
+ let state = unsafe { self.pin.block().odr().read().odr(self.pin.pin() as _) };
+ state == vals::Odr::LOW
+ }
+
+ /// Toggle pin output
+ pub fn toggle(&mut self) {
+ if self.is_set_low() {
+ self.set_high()
+ } else {
+ self.set_low()
+ }
+ }
}
impl<'d, T: Pin> Drop for OutputOpenDrain<'d, T> {
@@ -317,36 +351,6 @@ impl<'d, T: Pin> Drop for OutputOpenDrain<'d, T> {
}
}
-impl<'d, T: Pin> OutputPin for OutputOpenDrain<'d, T> {
- type Error = Infallible;
-
- /// Set the output as high.
- fn set_high(&mut self) -> Result<(), Self::Error> {
- self.pin.set_high();
- Ok(())
- }
-
- /// Set the output as low.
- fn set_low(&mut self) -> Result<(), Self::Error> {
- self.pin.set_low();
- Ok(())
- }
-}
-
-impl<'d, T: Pin> InputPin for OutputOpenDrain<'d, T> {
- type Error = Infallible;
-
- fn is_high(&self) -> Result<bool, Self::Error> {
- self.is_low().map(|v| !v)
- }
-
- fn is_low(&self) -> Result<bool, Self::Error> {
- // NOTE(safety) Atomic read
- let state = unsafe { self.pin.block().idr().read().idr(self.pin.pin() as usize) };
- Ok(state == vals::Idr::LOW)
- }
-}
-
pub(crate) mod sealed {
use super::*;
@@ -612,3 +616,79 @@ pub(crate) unsafe fn init() {
};
}
}
+
+mod eh02 {
+ use super::*;
+
+ impl<'d, T: Pin> InputPin for Input<'d, T> {
+ type Error = Infallible;
+
+ fn is_high(&self) -> Result<bool, Self::Error> {
+ Ok(self.is_high())
+ }
+
+ fn is_low(&self) -> Result<bool, Self::Error> {
+ Ok(self.is_low())
+ }
+ }
+
+ impl<'d, T: Pin> OutputPin for Output<'d, T> {
+ type Error = Infallible;
+
+ fn set_high(&mut self) -> Result<(), Self::Error> {
+ Ok(self.set_high())
+ }
+
+ fn set_low(&mut self) -> Result<(), Self::Error> {
+ Ok(self.set_low())
+ }
+ }
+
+ impl<'d, T: Pin> StatefulOutputPin for Output<'d, T> {
+ fn is_set_high(&self) -> Result<bool, Self::Error> {
+ Ok(self.is_set_high())
+ }
+
+ /// Is the output pin set as low?
+ fn is_set_low(&self) -> Result<bool, Self::Error> {
+ Ok(self.is_set_low())
+ }
+ }
+
+ impl<'d, T: Pin> ToggleableOutputPin for Output<'d, T> {
+ type Error = Infallible;
+ fn toggle(&mut self) -> Result<(), Self::Error> {
+ Ok(self.toggle())
+ }
+ }
+
+ impl<'d, T: Pin> OutputPin for OutputOpenDrain<'d, T> {
+ type Error = Infallible;
+
+ fn set_high(&mut self) -> Result<(), Self::Error> {
+ Ok(self.set_high())
+ }
+
+ fn set_low(&mut self) -> Result<(), Self::Error> {
+ Ok(self.set_low())
+ }
+ }
+
+ impl<'d, T: Pin> StatefulOutputPin for OutputOpenDrain<'d, T> {
+ fn is_set_high(&self) -> Result<bool, Self::Error> {
+ Ok(self.is_set_high())
+ }
+
+ /// Is the output pin set as low?
+ fn is_set_low(&self) -> Result<bool, Self::Error> {
+ Ok(self.is_set_low())
+ }
+ }
+
+ impl<'d, T: Pin> ToggleableOutputPin for OutputOpenDrain<'d, T> {
+ type Error = Infallible;
+ fn toggle(&mut self) -> Result<(), Self::Error> {
+ Ok(self.toggle())
+ }
+ }
+}
diff --git a/examples/stm32f1/src/bin/blinky.rs b/examples/stm32f1/src/bin/blinky.rs
index 1e4f2dee..0d953745 100644
--- a/examples/stm32f1/src/bin/blinky.rs
+++ b/examples/stm32f1/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::Peripherals;
-use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
info!("high");
- unwrap!(led.set_high());
+ led.set_high();
Timer::after(Duration::from_millis(300)).await;
info!("low");
- unwrap!(led.set_low());
+ led.set_low();
Timer::after(Duration::from_millis(300)).await;
}
}
diff --git a/examples/stm32f3/src/bin/blinky.rs b/examples/stm32f3/src/bin/blinky.rs
index 32164355..e8b8dc23 100644
--- a/examples/stm32f3/src/bin/blinky.rs
+++ b/examples/stm32f3/src/bin/blinky.rs
@@ -9,7 +9,6 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::Peripherals;
-use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@@ -20,11 +19,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
info!("high");
- unwrap!(led.set_high());
+ led.set_high();
Timer::after(Duration::from_millis(1000)).await;
info!("low");
- unwrap!(led.set_low());
+ led.set_low();
Timer::after(Duration::from_millis(1000)).await;
}
}
diff --git a/examples/stm32f3/src/bin/button.rs b/examples/stm32f3/src/bin/button.rs
index c5fab138..131d4af4 100644
--- a/examples/stm32f3/src/bin/button.rs
+++ b/examples/stm32f3/src/bin/button.rs
@@ -6,7 +6,6 @@
mod example_common;
use cortex_m_rt::entry;
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
-use embedded_hal::digital::v2::{InputPin, OutputPin};
use example_common::*;
#[entry]
@@ -20,14 +19,14 @@ fn main() -> ! {
let mut led2 = Output::new(p.PE15, Level::High, Speed::Low);
loop {
- if unwrap!(button.is_high()) {
+ if button.is_high() {
info!("high");
- unwrap!(led1.set_high());
- unwrap!(led2.set_low());
+ led1.set_high();
+ led2.set_low();
} else {
info!("low");
- unwrap!(led1.set_low());
- unwrap!(led2.set_high());
+ led1.set_low();
+ led2.set_high();
}
}
}
diff --git a/examples/stm32f4/src/bin/blinky.rs b/examples/stm32f4/src/bin/blinky.rs
index c4857195..00d67dac 100644
--- a/examples/stm32f4/src/bin/blinky.rs
+++ b/examples/stm32f4/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::Peripherals;
-use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
info!("high");
- unwrap!(led.set_high());
+ led.set_high();
Timer::after(Duration::from_millis(300)).await;
info!("low");
- unwrap!(led.set_low());
+ led.set_low();
Timer::after(Duration::from_millis(300)).await;
}
}
diff --git a/examples/stm32f4/src/bin/button.rs b/examples/stm32f4/src/bin/button.rs
index 95dee7c7..24eef75b 100644
--- a/examples/stm32f4/src/bin/button.rs
+++ b/examples/stm32f4/src/bin/button.rs
@@ -6,7 +6,6 @@
mod example_common;
use cortex_m_rt::entry;
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
-use embedded_hal::digital::v2::{InputPin, OutputPin};
use example_common::*;
#[entry]
@@ -21,14 +20,14 @@ fn main() -> ! {
let mut led3 = Output::new(p.PB14, Level::High, Speed::Low);
loop {
- if unwrap!(button.is_high()) {
+ if button.is_high() {
info!("high");
- unwrap!(led1.set_high());
- unwrap!(led3.set_low());
+ led1.set_high();
+ led3.set_low();
} else {
info!("low");
- unwrap!(led1.set_low());
- unwrap!(led3.set_high());
+ led1.set_low();
+ led3.set_high();
}
}
}
diff --git a/examples/stm32f4/src/bin/spi.rs b/examples/stm32f4/src/bin/spi.rs
index 0192e186..b66eb958 100644
--- a/examples/stm32f4/src/bin/spi.rs
+++ b/examples/stm32f4/src/bin/spi.rs
@@ -11,7 +11,6 @@ use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::spi::{Config, Spi};
use embassy_stm32::time::Hertz;
use embedded_hal::blocking::spi::Transfer;
-use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[entry]
@@ -35,9 +34,9 @@ fn main() -> ! {
loop {
let mut buf = [0x0Au8; 4];
- unwrap!(cs.set_low());
+ cs.set_low();
unwrap!(spi.transfer(&mut buf));
- unwrap!(cs.set_high());
+ cs.set_high();
info!("xfer {=[u8]:x}", buf);
}
}
diff --git a/examples/stm32f7/src/bin/blinky.rs b/examples/stm32f7/src/bin/blinky.rs
index c4857195..00d67dac 100644
--- a/examples/stm32f7/src/bin/blinky.rs
+++ b/examples/stm32f7/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::Peripherals;
-use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
info!("high");
- unwrap!(led.set_high());
+ led.set_high();
Timer::after(Duration::from_millis(300)).await;
info!("low");
- unwrap!(led.set_low());
+ led.set_low();
Timer::after(Duration::from_millis(300)).await;
}
}
diff --git a/examples/stm32f7/src/bin/button.rs b/examples/stm32f7/src/bin/button.rs
index 95dee7c7..24eef75b 100644
--- a/examples/stm32f7/src/bin/button.rs
+++ b/examples/stm32f7/src/bin/button.rs
@@ -6,7 +6,6 @@
mod example_common;
use cortex_m_rt::entry;
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
-use embedded_hal::digital::v2::{InputPin, OutputPin};
use example_common::*;
#[entry]
@@ -21,14 +20,14 @@ fn main() -> ! {
let mut led3 = Output::new(p.PB14, Level::High, Speed::Low);
loop {
- if unwrap!(button.is_high()) {
+ if button.is_high() {
info!("high");
- unwrap!(led1.set_high());
- unwrap!(led3.set_low());
+ led1.set_high();
+ led3.set_low();
} else {
info!("low");
- unwrap!(led1.set_low());
- unwrap!(led3.set_high());
+ led1.set_low();
+ led3.set_high();
}
}
}
diff --git a/examples/stm32g0/src/bin/blinky.rs b/examples/stm32g0/src/bin/blinky.rs
index c4857195..00d67dac 100644
--- a/examples/stm32g0/src/bin/blinky.rs
+++ b/examples/stm32g0/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::Peripherals;
-use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
info!("high");
- unwrap!(led.set_high());
+ led.set_high();
Timer::after(Duration::from_millis(300)).await;
info!("low");
- unwrap!(led.set_low());
+ led.set_low();
Timer::after(Duration::from_millis(300)).await;
}
}
diff --git a/examples/stm32g0/src/bin/button.rs b/examples/stm32g0/src/bin/button.rs
index 4ca2a43b..e901c575 100644
--- a/examples/stm32g0/src/bin/button.rs
+++ b/examples/stm32g0/src/bin/button.rs
@@ -6,7 +6,6 @@
mod example_common;
use cortex_m_rt::entry;
use embassy_stm32::gpio::{Input, Pull};
-use embedded_hal::digital::v2::InputPin;
use example_common::*;
#[entry]
@@ -18,7 +17,7 @@ fn main() -> ! {
let button = Input::new(p.PC13, Pull::Up);
loop {
- if unwrap!(button.is_high()) {
+ if button.is_high() {
info!("high");
} else {
info!("low");
diff --git a/examples/stm32g4/src/bin/blinky.rs b/examples/stm32g4/src/bin/blinky.rs
index a43922a6..1dc67f99 100644
--- a/examples/stm32g4/src/bin/blinky.rs
+++ b/examples/stm32g4/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::Peripherals;
-use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
info!("high");
- unwrap!(led.set_high());
+ led.set_high();
Timer::after(Duration::from_millis(300)).await;
info!("low");
- unwrap!(led.set_low());
+ led.set_low();
Timer::after(Duration::from_millis(300)).await;
}
}
diff --git a/examples/stm32g4/src/bin/button.rs b/examples/stm32g4/src/bin/button.rs
index f0a4c874..8c0d7d4f 100644
--- a/examples/stm32g4/src/bin/button.rs
+++ b/examples/stm32g4/src/bin/button.rs
@@ -6,7 +6,6 @@
mod example_common;
use cortex_m_rt::entry;
use embassy_stm32::gpio::{Input, Pull};
-use embedded_hal::digital::v2::InputPin;
use example_common::*;
#[entry]
@@ -18,7 +17,7 @@ fn main() -> ! {
let button = Input::new(p.PC13, Pull::Down);
loop {
- if unwrap!(button.is_high()) {
+ if button.is_high() {
info!("high");
} else {
info!("low");
diff --git a/examples/stm32h7/src/bin/blinky.rs b/examples/stm32h7/src/bin/blinky.rs
index 78edb5e2..7e593423 100644
--- a/examples/stm32h7/src/bin/blinky.rs
+++ b/examples/stm32h7/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::Peripherals;
-use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
info!("high");
- unwrap!(led.set_high());
+ led.set_high();
Timer::after(Duration::from_millis(500)).await;
info!("low");
- unwrap!(led.set_low());
+ led.set_low();
Timer::after(Duration::from_millis(500)).await;
}
}
diff --git a/examples/stm32h7/src/bin/camera.rs b/examples/stm32h7/src/bin/camera.rs
index d9459207..9e8071bb 100644
--- a/examples/stm32h7/src/bin/camera.rs
+++ b/examples/stm32h7/src/bin/camera.rs
@@ -11,7 +11,6 @@ use embassy_stm32::interrupt;
use embassy_stm32::rcc::{Mco, Mco1Source, McoClock};
use embassy_stm32::time::U32Ext;
use embassy_stm32::Peripherals;
-use embedded_hal::digital::v2::OutputPin;
use defmt_rtt as _; // global logger
use panic_probe as _;
@@ -114,11 +113,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
defmt::info!("main loop running");
loop {
defmt::info!("high");
- defmt::unwrap!(led.set_high());
+ led.set_high();
Timer::after(Duration::from_millis(500)).await;
defmt::info!("low");
- defmt::unwrap!(led.set_low());
+ led.set_low();
Timer::after(Duration::from_millis(500)).await;
}
}
diff --git a/examples/stm32h7/src/bin/mco.rs b/examples/stm32h7/src/bin/mco.rs
index 4cecd9b0..f27bd8ef 100644
--- a/examples/stm32h7/src/bin/mco.rs
+++ b/examples/stm32h7/src/bin/mco.rs
@@ -9,7 +9,6 @@ use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::rcc::{Mco, Mco1Source, McoClock};
use embassy_stm32::Peripherals;
-use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@@ -22,11 +21,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
info!("high");
- unwrap!(led.set_high());
+ led.set_high();
Timer::after(Duration::from_millis(500)).await;
info!("low");
- unwrap!(led.set_low());
+ led.set_low();
Timer::after(Duration::from_millis(500)).await;
}
}
diff --git a/examples/stm32h7/src/bin/rng.rs b/examples/stm32h7/src/bin/rng.rs
index d64ad9bc..8e03861d 100644
--- a/examples/stm32h7/src/bin/rng.rs
+++ b/examples/stm32h7/src/bin/rng.rs
@@ -10,7 +10,6 @@ use embassy::traits::rng::Random;
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::rng::Rng;
use embassy_stm32::Peripherals;
-use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@@ -23,11 +22,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
info!("high {}", unwrap!(rng.next_u8(16).await));
- unwrap!(led.set_high());
+ led.set_high();
Timer::after(Duration::from_millis(500)).await;
info!("low {}", unwrap!(rng.next_u8(16).await));
- unwrap!(led.set_low());
+ led.set_low();
Timer::after(Duration::from_millis(500)).await;
}
}
diff --git a/examples/stm32l0/src/bin/blinky.rs b/examples/stm32l0/src/bin/blinky.rs
index 1198b29d..46e29a89 100644
--- a/examples/stm32l0/src/bin/blinky.rs
+++ b/examples/stm32l0/src/bin/blinky.rs
@@ -9,7 +9,6 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::Peripherals;
-use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@@ -20,11 +19,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
info!("high");
- unwrap!(led.set_high());
+ led.set_high();
Timer::after(Duration::from_millis(300)).await;
info!("low");
- unwrap!(led.set_low());
+ led.set_low();
Timer::after(Duration::from_millis(300)).await;
}
}
diff --git a/examples/stm32l0/src/bin/button.rs b/examples/stm32l0/src/bin/button.rs
index c2915530..046c43ca 100644
--- a/examples/stm32l0/src/bin/button.rs
+++ b/examples/stm32l0/src/bin/button.rs
@@ -7,7 +7,6 @@ mod example_common;
use embassy::executor::Spawner;
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embassy_stm32::Peripherals;
-use embedded_hal::digital::v2::{InputPin, OutputPin};
use example_common::*;
#[embassy::main]
@@ -19,14 +18,14 @@ async fn main(_spawner: Spawner, p: Peripherals) {
let mut led2 = Output::new(p.PB5, Level::High, Speed::Low);
loop {
- if unwrap!(button.is_high()) {
+ if button.is_high() {
info!("high");
- unwrap!(led1.set_high());
- unwrap!(led2.set_low());
+ led1.set_high();
+ led2.set_low();
} else {
info!("low");
- unwrap!(led1.set_low());
- unwrap!(led2.set_high());
+ led1.set_low();
+ led2.set_high();
}
}
}
diff --git a/examples/stm32l0/src/bin/spi.rs b/examples/stm32l0/src/bin/spi.rs
index f768a522..d30bb8d7 100644
--- a/examples/stm32l0/src/bin/spi.rs
+++ b/examples/stm32l0/src/bin/spi.rs
@@ -7,7 +7,6 @@ mod example_common;
use embassy::executor::Spawner;
use embassy_stm32::gpio::{Level, Output, Speed};
-use embedded_hal::digital::v2::OutputPin;
use example_common::*;
use embassy_stm32::dma::NoDma;
@@ -35,9 +34,9 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
let mut buf = [0x0Au8; 4];
- unwrap!(cs.set_low());
+ cs.set_low();
unwrap!(spi.transfer(&mut buf));
- unwrap!(cs.set_high());
+ cs.set_high();
info!("xfer {=[u8]:x}", buf);
}
}
diff --git a/examples/stm32l1/src/bin/blinky.rs b/examples/stm32l1/src/bin/blinky.rs
index deabdddb..07c804e9 100644
--- a/examples/stm32l1/src/bin/blinky.rs
+++ b/examples/stm32l1/src/bin/blinky.rs
@@ -9,7 +9,6 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::Peripherals;
-use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@@ -20,11 +19,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
info!("high");
- unwrap!(led.set_high());
+ led.set_high();
Timer::after(Duration::from_millis(1000)).await;
info!("low");
- unwrap!(led.set_low());
+ led.set_low();
Timer::after(Duration::from_millis(1000)).await;
}
}
diff --git a/examples/stm32l1/src/bin/spi.rs b/examples/stm32l1/src/bin/spi.rs
index 3cfbe3fc..9d1a2fc8 100644
--- a/examples/stm32l1/src/bin/spi.rs
+++ b/examples/stm32l1/src/bin/spi.rs
@@ -7,7 +7,6 @@ mod example_common;
use embassy::executor::Spawner;
use embassy_stm32::gpio::{Level, Output, Speed};
-use embedded_hal::digital::v2::OutputPin;
use example_common::*;
use embassy_stm32::dma::NoDma;
@@ -35,9 +34,9 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
let mut buf = [0x0Au8; 4];
- unwrap!(cs.set_low());
+ cs.set_low();
unwrap!(spi.transfer(&mut buf));
- unwrap!(cs.set_high());
+ cs.set_high();
info!("xfer {=[u8]:x}", buf);
}
}
diff --git a/examples/stm32l4/src/bin/blinky.rs b/examples/stm32l4/src/bin/blinky.rs
index 8a65858f..03028375 100644
--- a/examples/stm32l4/src/bin/blinky.rs
+++ b/examples/stm32l4/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::Peripherals;
-use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@@ -18,9 +17,9 @@ async fn main(_spawner: Spawner, p: Peripherals) {
let mut led = Output::new(p.PB14, Level::High, Speed::Low);
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/stm32l4/src/bin/button.rs b/examples/stm32l4/src/bin/button.rs
index fd867454..6073c137 100644
--- a/examples/stm32l4/src/bin/button.rs
+++ b/examples/stm32l4/src/bin/button.rs
@@ -5,7 +5,6 @@
#[path = "../example_common.rs"]
mod example_common;
use embassy_stm32::gpio::{Input, Pull};
-use embedded_hal::digital::v2::InputPin;
use example_common::*;
#[cortex_m_rt::entry]
@@ -17,7 +16,7 @@ fn main() -> ! {
let button = Input::new(p.PC13, Pull::Up);
loop {
- if unwrap!(button.is_high()) {
+ if button.is_high() {
info!("high");
} else {
info!("low");
diff --git a/examples/stm32l4/src/bin/spi.rs b/examples/stm32l4/src/bin/spi.rs
index 5b9ae1ce..1b6e3946 100644
--- a/examples/stm32l4/src/bin/spi.rs
+++ b/examples/stm32l4/src/bin/spi.rs
@@ -10,7 +10,6 @@ use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::spi::{Config, Spi};
use embassy_stm32::time::Hertz;
use embedded_hal::blocking::spi::Transfer;
-use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[cortex_m_rt::entry]
@@ -34,9 +33,9 @@ fn main() -> ! {
loop {
let mut buf = [0x0Au8; 4];
- unwrap!(cs.set_low());
+ cs.set_low();
unwrap!(spi.transfer(&mut buf));
- unwrap!(cs.set_high());
+ cs.set_high();
info!("xfer {=[u8]:x}", buf);
}
}
diff --git a/examples/stm32l4/src/bin/spi_blocking_async.rs b/examples/stm32l4/src/bin/spi_blocking_async.rs
index f092706d..3be3f21c 100644
--- a/examples/stm32l4/src/bin/spi_blocking_async.rs
+++ b/examples/stm32l4/src/bin/spi_blocking_async.rs
@@ -12,7 +12,6 @@ use embassy_stm32::spi::{Config, Spi};
use embassy_stm32::time::Hertz;
use embassy_stm32::Peripherals;
use embassy_traits::{adapter::BlockingAsync, spi::FullDuplex};
-use embedded_hal::digital::v2::{InputPin, OutputPin};
use example_common::*;
#[embassy::main]
@@ -41,17 +40,17 @@ async fn main(_spawner: Spawner, p: Peripherals) {
let ready = Input::new(p.PE1, Pull::Up);
cortex_m::asm::delay(100_000);
- unwrap!(reset.set_high());
+ reset.set_high();
cortex_m::asm::delay(100_000);
- while unwrap!(ready.is_low()) {
+ while ready.is_low() {
info!("waiting for ready");
}
let write = [0x0A; 10];
let mut read = [0; 10];
- unwrap!(cs.set_low());
+ cs.set_low();
spi.read_write(&mut read, &write).await.ok();
- unwrap!(cs.set_high());
+ cs.set_high();
info!("xfer {=[u8]:x}", read);
}
diff --git a/examples/stm32l4/src/bin/spi_dma.rs b/examples/stm32l4/src/bin/spi_dma.rs
index 4b74c7d7..d6464bbf 100644
--- a/examples/stm32l4/src/bin/spi_dma.rs
+++ b/examples/stm32l4/src/bin/spi_dma.rs
@@ -11,7 +11,6 @@ use embassy_stm32::spi::{Config, Spi};
use embassy_stm32::time::Hertz;
use embassy_stm32::Peripherals;
use embassy_traits::spi::FullDuplex;
-use embedded_hal::digital::v2::{InputPin, OutputPin};
use example_common::*;
#[embassy::main]
@@ -38,17 +37,17 @@ async fn main(_spawner: Spawner, p: Peripherals) {
let ready = Input::new(p.PE1, Pull::Up);
cortex_m::asm::delay(100_000);
- unwrap!(reset.set_high());
+ reset.set_high();
cortex_m::asm::delay(100_000);
- while unwrap!(ready.is_low()) {
+ while ready.is_low() {
info!("waiting for ready");
}
let write = [0x0A; 10];
let mut read = [0; 10];
- unwrap!(cs.set_low());
+ cs.set_low();
spi.read_write(&mut read, &write).await.ok();
- unwrap!(cs.set_high());
+ cs.set_high();
info!("xfer {=[u8]:x}", read);
}
diff --git a/examples/stm32wb55/src/bin/blinky.rs b/examples/stm32wb55/src/bin/blinky.rs
index 42522fe9..e1dbb30d 100644
--- a/examples/stm32wb55/src/bin/blinky.rs
+++ b/examples/stm32wb55/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::Peripherals;
-use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
info!("high");
- unwrap!(led.set_high());
+ led.set_high();
Timer::after(Duration::from_millis(500)).await;
info!("low");
- unwrap!(led.set_low());
+ led.set_low();
Timer::after(Duration::from_millis(500)).await;
}
}
diff --git a/examples/stm32wl55/src/bin/blinky.rs b/examples/stm32wl55/src/bin/blinky.rs
index 3c12a79d..9ec208c3 100644
--- a/examples/stm32wl55/src/bin/blinky.rs
+++ b/examples/stm32wl55/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_stm32::Peripherals;
-use embedded_hal::digital::v2::OutputPin;
use example_common::*;
#[embassy::main]
@@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
loop {
info!("high");
- unwrap!(led.set_high());
+ led.set_high();
Timer::after(Duration::from_millis(500)).await;
info!("low");
- unwrap!(led.set_low());
+ led.set_low();
Timer::after(Duration::from_millis(500)).await;
}
}
diff --git a/examples/stm32wl55/src/bin/button.rs b/examples/stm32wl55/src/bin/button.rs
index 55b68866..be8f60e2 100644
--- a/examples/stm32wl55/src/bin/button.rs
+++ b/examples/stm32wl55/src/bin/button.rs
@@ -5,7 +5,6 @@
#[path = "../example_common.rs"]
mod example_common;
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
-use embedded_hal::digital::v2::{InputPin, OutputPin};
use example_common::*;
use cortex_m_rt::entry;
@@ -21,12 +20,12 @@ fn main() -> ! {
let mut led2 = Output::new(p.PB9, Level::High, Speed::Low);
loop {
- if button.is_high().unwrap() {
- led1.set_high().unwrap();
- led2.set_low().unwrap();
+ if button.is_high() {
+ led1.set_high();
+ led2.set_low();
} else {
- led1.set_low().unwrap();
- led2.set_high().unwrap();
+ led1.set_low();
+ led2.set_high();
}
}
}
diff --git a/examples/stm32wl55/src/bin/subghz.rs b/examples/stm32wl55/src/bin/subghz.rs
index 52fe6e9f..570bd980 100644
--- a/examples/stm32wl55/src/bin/subghz.rs
+++ b/examples/stm32wl55/src/bin/subghz.rs
@@ -17,7 +17,6 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embassy_stm32::interrupt;
use embassy_stm32::subghz::*;
use embassy_stm32::Peripherals;
-use embedded_hal::digital::v2::OutputPin;
use example_common::unwrap;
const PING_DATA: &str = "PING";
@@ -89,9 +88,9 @@ async fn main(_spawner: embassy::executor::Spawner, p: Peripherals) {
defmt::info!("Radio ready for use");
- unwrap!(led1.set_low());
+ led1.set_low();
- unwrap!(led2.set_high());
+ led2.set_high();
unwrap!(radio.set_standby(StandbyClk::Rc));
unwrap!(radio.set_tcxo_mode(&TCXO_MODE));
@@ -110,11 +109,11 @@ async fn main(_spawner: embassy::executor::Spawner, p: Peripherals) {
defmt::info!("Status: {:?}", unwrap!(radio.status()));
- unwrap!(led2.set_low());
+ led2.set_low();
loop {
pin.wait_for_rising_edge().await;
- unwrap!(led3.set_high());
+ led3.set_high();
unwrap!(radio.set_irq_cfg(&CfgIrq::new().irq_enable_all(Irq::TxDone)));
unwrap!(radio.write_buffer(TX_BUF_OFFSET, PING_DATA_BYTES));
unwrap!(radio.set_tx(Timeout::DISABLED));
@@ -127,6 +126,6 @@ async fn main(_spawner: embassy::executor::Spawner, p: Peripherals) {
defmt::info!("TX done");
}
unwrap!(radio.clear_irq_status(irq_status));
- unwrap!(led3.set_low());
+ led3.set_low();
}
}
diff --git a/tests/stm32/src/bin/gpio.rs b/tests/stm32/src/bin/gpio.rs
index 51ede6ce..305da8d1 100644
--- a/tests/stm32/src/bin/gpio.rs
+++ b/tests/stm32/src/bin/gpio.rs
@@ -8,7 +8,6 @@ use defmt::assert;
use embassy::executor::Spawner;
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
use embassy_stm32::Peripherals;
-use embedded_hal::digital::v2::{InputPin, OutputPin};
use example_common::*;
#[embassy::main(config = "config()")]
@@ -35,12 +34,12 @@ async fn main(_spawner: Spawner, p: Peripherals) {
{
let _a = Output::new(&mut a, Level::Low, Speed::Low);
delay();
- assert!(b.is_low().unwrap());
+ assert!(b.is_low());
}
{
let _a = Output::new(&mut a, Level::High, Speed::Low);
delay();
- assert!(b.is_high().unwrap());
+ assert!(b.is_high());
}
}
@@ -51,38 +50,38 @@ async fn main(_spawner: Spawner, p: Peripherals) {
let mut a = Output::new(&mut a, Level::Low, Speed::Low);
delay();
- assert!(b.is_low().unwrap());
- a.set_high().unwrap();
+ assert!(b.is_low());
+ a.set_high();
delay();
- assert!(b.is_high().unwrap());
+ assert!(b.is_high());
}
// Test input pulldown
{
let b = Input::new(&mut b, Pull::Down);
delay();
- assert!(b.is_low().unwrap());
+ assert!(b.is_low());
let mut a = Output::new(&mut a, Level::Low, Speed::Low);
delay();
- assert!(b.is_low().unwrap());
- a.set_high().unwrap();
+ assert!(b.is_low());
+ a.set_high();
delay();
- assert!(b.is_high().unwrap());
+ assert!(b.is_high());
}
// Test input pullup
{
let b = Input::new(&mut b, Pull::Up);
delay();
- assert!(b.is_high().unwrap());
+ assert!(b.is_high());
let mut a = Output::new(&mut a, Level::Low, Speed::Low);
delay();
- assert!(b.is_low().unwrap());
- a.set_high().unwrap();
+ assert!(b.is_low());
+ a.set_high();
delay();
- assert!(b.is_high().unwrap());
+ assert!(b.is_high());
}
info!("Test OK");