aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-01-14 22:02:00 +0100
committerDario Nieuwenhuis <[email protected]>2022-01-19 17:59:55 +0100
commit58fc64722c65bbdc209ae0fd1700f03702bbcd08 (patch)
tree77f9412b47259cd4cf4170b0a257b371398d4f2c
parent52e156b429417bde59d0ea67d11256866f1dcec9 (diff)
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 8cac46f7a..783140cb3 100644
--- a/embassy-lora/src/stm32wl/mod.rs
+++ b/embassy-lora/src/stm32wl/mod.rs
@@ -16,7 +16,6 @@ use embassy_stm32::{
16 TxParams, 16 TxParams,
17 }, 17 },
18}; 18};
19use embedded_hal::digital::v2::OutputPin;
20use lorawan_device::async_device::{ 19use lorawan_device::async_device::{
21 radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig}, 20 radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig},
22 Timings, 21 Timings,
@@ -329,22 +328,22 @@ impl<'a> RadioSwitch<'a> {
329 } 328 }
330 329
331 pub(crate) fn set_rx(&mut self) { 330 pub(crate) fn set_rx(&mut self) {
332 self.ctrl1.set_high().unwrap(); 331 self.ctrl1.set_high();
333 self.ctrl2.set_low().unwrap(); 332 self.ctrl2.set_low();
334 self.ctrl3.set_high().unwrap(); 333 self.ctrl3.set_high();
335 } 334 }
336 335
337 pub(crate) fn set_tx_lp(&mut self) { 336 pub(crate) fn set_tx_lp(&mut self) {
338 self.ctrl1.set_high().unwrap(); 337 self.ctrl1.set_high();
339 self.ctrl2.set_high().unwrap(); 338 self.ctrl2.set_high();
340 self.ctrl3.set_high().unwrap(); 339 self.ctrl3.set_high();
341 } 340 }
342 341
343 #[allow(dead_code)] 342 #[allow(dead_code)]
344 pub(crate) fn set_tx_hp(&mut self) { 343 pub(crate) fn set_tx_hp(&mut self) {
345 self.ctrl2.set_high().unwrap(); 344 self.ctrl2.set_high();
346 self.ctrl1.set_low().unwrap(); 345 self.ctrl1.set_low();
347 self.ctrl3.set_high().unwrap(); 346 self.ctrl3.set_high();
348 } 347 }
349} 348}
350 349
diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs
index 552433b87..eded6ba71 100644
--- a/embassy-stm32/src/exti.rs
+++ b/embassy-stm32/src/exti.rs
@@ -94,17 +94,25 @@ impl<'d, T: GpioPin> ExtiInput<'d, T> {
94 pub fn new(pin: Input<'d, T>, _ch: impl Unborrow<Target = T::ExtiChannel> + 'd) -> Self { 94 pub fn new(pin: Input<'d, T>, _ch: impl Unborrow<Target = T::ExtiChannel> + 'd) -> Self {
95 Self { pin } 95 Self { pin }
96 } 96 }
97
98 pub fn is_high(&self) -> bool {
99 self.pin.is_high()
100 }
101
102 pub fn is_low(&self) -> bool {
103 self.pin.is_low()
104 }
97} 105}
98 106
99impl<'d, T: GpioPin> InputPin for ExtiInput<'d, T> { 107impl<'d, T: GpioPin> InputPin for ExtiInput<'d, T> {
100 type Error = Infallible; 108 type Error = Infallible;
101 109
102 fn is_high(&self) -> Result<bool, Self::Error> { 110 fn is_high(&self) -> Result<bool, Self::Error> {
103 self.pin.is_high() 111 Ok(self.is_high())
104 } 112 }
105 113
106 fn is_low(&self) -> Result<bool, Self::Error> { 114 fn is_low(&self) -> Result<bool, Self::Error> {
107 self.pin.is_low() 115 Ok(self.is_low())
108 } 116 }
109} 117}
110 118
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs
index 6b4a9285f..57b9ba6b7 100644
--- a/embassy-stm32/src/gpio.rs
+++ b/embassy-stm32/src/gpio.rs
@@ -3,7 +3,7 @@ use core::convert::Infallible;
3use core::marker::PhantomData; 3use core::marker::PhantomData;
4use embassy::util::Unborrow; 4use embassy::util::Unborrow;
5use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; 5use embassy_hal_common::{unborrow, unsafe_impl_unborrow};
6use embedded_hal::digital::v2::{toggleable, InputPin, OutputPin, StatefulOutputPin}; 6use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin};
7 7
8use crate::pac; 8use crate::pac;
9use crate::pac::gpio::{self, vals}; 9use crate::pac::gpio::{self, vals};
@@ -113,6 +113,15 @@ impl<'d, T: Pin> Input<'d, T> {
113 phantom: PhantomData, 113 phantom: PhantomData,
114 } 114 }
115 } 115 }
116
117 pub fn is_high(&self) -> bool {
118 !self.is_low()
119 }
120
121 pub fn is_low(&self) -> bool {
122 let state = unsafe { self.pin.block().idr().read().idr(self.pin.pin() as _) };
123 state == vals::Idr::LOW
124 }
116} 125}
117 126
118impl<'d, T: Pin> Drop for Input<'d, T> { 127impl<'d, T: Pin> Drop for Input<'d, T> {
@@ -132,19 +141,6 @@ impl<'d, T: Pin> Drop for Input<'d, T> {
132 } 141 }
133} 142}
134 143
135impl<'d, T: Pin> InputPin for Input<'d, T> {
136 type Error = Infallible;
137
138 fn is_high(&self) -> Result<bool, Self::Error> {
139 self.is_low().map(|v| !v)
140 }
141
142 fn is_low(&self) -> Result<bool, Self::Error> {
143 let state = unsafe { self.pin.block().idr().read().idr(self.pin.pin() as _) };
144 Ok(state == vals::Idr::LOW)
145 }
146}
147
148/// Digital input or output level. 144/// Digital input or output level.
149#[derive(Debug, Eq, PartialEq)] 145#[derive(Debug, Eq, PartialEq)]
150#[cfg_attr(feature = "defmt", derive(defmt::Format))] 146#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@@ -191,6 +187,36 @@ impl<'d, T: Pin> Output<'d, T> {
191 phantom: PhantomData, 187 phantom: PhantomData,
192 } 188 }
193 } 189 }
190
191 /// Set the output as high.
192 pub fn set_high(&mut self) {
193 self.pin.set_high();
194 }
195
196 /// Set the output as low.
197 pub fn set_low(&mut self) {
198 self.pin.set_low();
199 }
200
201 /// Is the output pin set as high?
202 pub fn is_set_high(&self) -> bool {
203 !self.is_set_low()
204 }
205
206 /// Is the output pin set as low?
207 pub fn is_set_low(&self) -> bool {
208 let state = unsafe { self.pin.block().odr().read().odr(self.pin.pin() as _) };
209 state == vals::Odr::LOW
210 }
211
212 /// Toggle pin output
213 pub fn toggle(&mut self) {
214 if self.is_set_low() {
215 self.set_high()
216 } else {
217 self.set_low()
218 }
219 }
194} 220}
195 221
196impl<'d, T: Pin> Drop for Output<'d, T> { 222impl<'d, T: Pin> Drop for Output<'d, T> {
@@ -214,37 +240,6 @@ impl<'d, T: Pin> Drop for Output<'d, T> {
214 } 240 }
215} 241}
216 242
217impl<'d, T: Pin> OutputPin for Output<'d, T> {
218 type Error = Infallible;
219
220 /// Set the output as high.
221 fn set_high(&mut self) -> Result<(), Self::Error> {
222 self.pin.set_high();
223 Ok(())
224 }
225
226 /// Set the output as low.
227 fn set_low(&mut self) -> Result<(), Self::Error> {
228 self.pin.set_low();
229 Ok(())
230 }
231}
232
233impl<'d, T: Pin> StatefulOutputPin for Output<'d, T> {
234 /// Is the output pin set as high?
235 fn is_set_high(&self) -> Result<bool, Self::Error> {
236 self.is_set_low().map(|v| !v)
237 }
238
239 /// Is the output pin set as low?
240 fn is_set_low(&self) -> Result<bool, Self::Error> {
241 let state = unsafe { self.pin.block().odr().read().odr(self.pin.pin() as _) };
242 Ok(state == vals::Odr::LOW)
243 }
244}
245
246impl<'d, T: Pin> toggleable::Default for Output<'d, T> {}
247
248/// GPIO output open-drain driver. 243/// GPIO output open-drain driver.
249pub struct OutputOpenDrain<'d, T: Pin> { 244pub struct OutputOpenDrain<'d, T: Pin> {
250 pub(crate) pin: T, 245 pub(crate) pin: T,
@@ -294,6 +289,45 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> {
294 phantom: PhantomData, 289 phantom: PhantomData,
295 } 290 }
296 } 291 }
292
293 pub fn is_high(&self) -> bool {
294 !self.is_low()
295 }
296
297 pub fn is_low(&self) -> bool {
298 let state = unsafe { self.pin.block().idr().read().idr(self.pin.pin() as _) };
299 state == vals::Idr::LOW
300 }
301
302 /// Set the output as high.
303 pub fn set_high(&mut self) {
304 self.pin.set_high();
305 }
306
307 /// Set the output as low.
308 pub fn set_low(&mut self) {
309 self.pin.set_low();
310 }
311
312 /// Is the output pin set as high?
313 pub fn is_set_high(&self) -> bool {
314 !self.is_set_low()
315 }
316
317 /// Is the output pin set as low?
318 pub fn is_set_low(&self) -> bool {
319 let state = unsafe { self.pin.block().odr().read().odr(self.pin.pin() as _) };
320 state == vals::Odr::LOW
321 }
322
323 /// Toggle pin output
324 pub fn toggle(&mut self) {
325 if self.is_set_low() {
326 self.set_high()
327 } else {
328 self.set_low()
329 }
330 }
297} 331}
298 332
299impl<'d, T: Pin> Drop for OutputOpenDrain<'d, T> { 333impl<'d, T: Pin> Drop for OutputOpenDrain<'d, T> {
@@ -317,36 +351,6 @@ impl<'d, T: Pin> Drop for OutputOpenDrain<'d, T> {
317 } 351 }
318} 352}
319 353
320impl<'d, T: Pin> OutputPin for OutputOpenDrain<'d, T> {
321 type Error = Infallible;
322
323 /// Set the output as high.
324 fn set_high(&mut self) -> Result<(), Self::Error> {
325 self.pin.set_high();
326 Ok(())
327 }
328
329 /// Set the output as low.
330 fn set_low(&mut self) -> Result<(), Self::Error> {
331 self.pin.set_low();
332 Ok(())
333 }
334}
335
336impl<'d, T: Pin> InputPin for OutputOpenDrain<'d, T> {
337 type Error = Infallible;
338
339 fn is_high(&self) -> Result<bool, Self::Error> {
340 self.is_low().map(|v| !v)
341 }
342
343 fn is_low(&self) -> Result<bool, Self::Error> {
344 // NOTE(safety) Atomic read
345 let state = unsafe { self.pin.block().idr().read().idr(self.pin.pin() as usize) };
346 Ok(state == vals::Idr::LOW)
347 }
348}
349
350pub(crate) mod sealed { 354pub(crate) mod sealed {
351 use super::*; 355 use super::*;
352 356
@@ -612,3 +616,79 @@ pub(crate) unsafe fn init() {
612 }; 616 };
613 } 617 }
614} 618}
619
620mod eh02 {
621 use super::*;
622
623 impl<'d, T: Pin> InputPin for Input<'d, T> {
624 type Error = Infallible;
625
626 fn is_high(&self) -> Result<bool, Self::Error> {
627 Ok(self.is_high())
628 }
629
630 fn is_low(&self) -> Result<bool, Self::Error> {
631 Ok(self.is_low())
632 }
633 }
634
635 impl<'d, T: Pin> OutputPin for Output<'d, T> {
636 type Error = Infallible;
637
638 fn set_high(&mut self) -> Result<(), Self::Error> {
639 Ok(self.set_high())
640 }
641
642 fn set_low(&mut self) -> Result<(), Self::Error> {
643 Ok(self.set_low())
644 }
645 }
646
647 impl<'d, T: Pin> StatefulOutputPin for Output<'d, T> {
648 fn is_set_high(&self) -> Result<bool, Self::Error> {
649 Ok(self.is_set_high())
650 }
651
652 /// Is the output pin set as low?
653 fn is_set_low(&self) -> Result<bool, Self::Error> {
654 Ok(self.is_set_low())
655 }
656 }
657
658 impl<'d, T: Pin> ToggleableOutputPin for Output<'d, T> {
659 type Error = Infallible;
660 fn toggle(&mut self) -> Result<(), Self::Error> {
661 Ok(self.toggle())
662 }
663 }
664
665 impl<'d, T: Pin> OutputPin for OutputOpenDrain<'d, T> {
666 type Error = Infallible;
667
668 fn set_high(&mut self) -> Result<(), Self::Error> {
669 Ok(self.set_high())
670 }
671
672 fn set_low(&mut self) -> Result<(), Self::Error> {
673 Ok(self.set_low())
674 }
675 }
676
677 impl<'d, T: Pin> StatefulOutputPin for OutputOpenDrain<'d, T> {
678 fn is_set_high(&self) -> Result<bool, Self::Error> {
679 Ok(self.is_set_high())
680 }
681
682 /// Is the output pin set as low?
683 fn is_set_low(&self) -> Result<bool, Self::Error> {
684 Ok(self.is_set_low())
685 }
686 }
687
688 impl<'d, T: Pin> ToggleableOutputPin for OutputOpenDrain<'d, T> {
689 type Error = Infallible;
690 fn toggle(&mut self) -> Result<(), Self::Error> {
691 Ok(self.toggle())
692 }
693 }
694}
diff --git a/examples/stm32f1/src/bin/blinky.rs b/examples/stm32f1/src/bin/blinky.rs
index 1e4f2deec..0d9537453 100644
--- a/examples/stm32f1/src/bin/blinky.rs
+++ b/examples/stm32f1/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embedded_hal::digital::v2::OutputPin;
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
@@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
19 18
20 loop { 19 loop {
21 info!("high"); 20 info!("high");
22 unwrap!(led.set_high()); 21 led.set_high();
23 Timer::after(Duration::from_millis(300)).await; 22 Timer::after(Duration::from_millis(300)).await;
24 23
25 info!("low"); 24 info!("low");
26 unwrap!(led.set_low()); 25 led.set_low();
27 Timer::after(Duration::from_millis(300)).await; 26 Timer::after(Duration::from_millis(300)).await;
28 } 27 }
29} 28}
diff --git a/examples/stm32f3/src/bin/blinky.rs b/examples/stm32f3/src/bin/blinky.rs
index 321643557..e8b8dc23f 100644
--- a/examples/stm32f3/src/bin/blinky.rs
+++ b/examples/stm32f3/src/bin/blinky.rs
@@ -9,7 +9,6 @@ use embassy::executor::Spawner;
9use embassy::time::{Duration, Timer}; 9use embassy::time::{Duration, Timer};
10use embassy_stm32::gpio::{Level, Output, Speed}; 10use embassy_stm32::gpio::{Level, Output, Speed};
11use embassy_stm32::Peripherals; 11use embassy_stm32::Peripherals;
12use embedded_hal::digital::v2::OutputPin;
13use example_common::*; 12use example_common::*;
14 13
15#[embassy::main] 14#[embassy::main]
@@ -20,11 +19,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
20 19
21 loop { 20 loop {
22 info!("high"); 21 info!("high");
23 unwrap!(led.set_high()); 22 led.set_high();
24 Timer::after(Duration::from_millis(1000)).await; 23 Timer::after(Duration::from_millis(1000)).await;
25 24
26 info!("low"); 25 info!("low");
27 unwrap!(led.set_low()); 26 led.set_low();
28 Timer::after(Duration::from_millis(1000)).await; 27 Timer::after(Duration::from_millis(1000)).await;
29 } 28 }
30} 29}
diff --git a/examples/stm32f3/src/bin/button.rs b/examples/stm32f3/src/bin/button.rs
index c5fab138b..131d4af42 100644
--- a/examples/stm32f3/src/bin/button.rs
+++ b/examples/stm32f3/src/bin/button.rs
@@ -6,7 +6,6 @@
6mod example_common; 6mod example_common;
7use cortex_m_rt::entry; 7use cortex_m_rt::entry;
8use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 8use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
9use embedded_hal::digital::v2::{InputPin, OutputPin};
10use example_common::*; 9use example_common::*;
11 10
12#[entry] 11#[entry]
@@ -20,14 +19,14 @@ fn main() -> ! {
20 let mut led2 = Output::new(p.PE15, Level::High, Speed::Low); 19 let mut led2 = Output::new(p.PE15, Level::High, Speed::Low);
21 20
22 loop { 21 loop {
23 if unwrap!(button.is_high()) { 22 if button.is_high() {
24 info!("high"); 23 info!("high");
25 unwrap!(led1.set_high()); 24 led1.set_high();
26 unwrap!(led2.set_low()); 25 led2.set_low();
27 } else { 26 } else {
28 info!("low"); 27 info!("low");
29 unwrap!(led1.set_low()); 28 led1.set_low();
30 unwrap!(led2.set_high()); 29 led2.set_high();
31 } 30 }
32 } 31 }
33} 32}
diff --git a/examples/stm32f4/src/bin/blinky.rs b/examples/stm32f4/src/bin/blinky.rs
index c4857195f..00d67dac0 100644
--- a/examples/stm32f4/src/bin/blinky.rs
+++ b/examples/stm32f4/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embedded_hal::digital::v2::OutputPin;
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
@@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
19 18
20 loop { 19 loop {
21 info!("high"); 20 info!("high");
22 unwrap!(led.set_high()); 21 led.set_high();
23 Timer::after(Duration::from_millis(300)).await; 22 Timer::after(Duration::from_millis(300)).await;
24 23
25 info!("low"); 24 info!("low");
26 unwrap!(led.set_low()); 25 led.set_low();
27 Timer::after(Duration::from_millis(300)).await; 26 Timer::after(Duration::from_millis(300)).await;
28 } 27 }
29} 28}
diff --git a/examples/stm32f4/src/bin/button.rs b/examples/stm32f4/src/bin/button.rs
index 95dee7c74..24eef75b2 100644
--- a/examples/stm32f4/src/bin/button.rs
+++ b/examples/stm32f4/src/bin/button.rs
@@ -6,7 +6,6 @@
6mod example_common; 6mod example_common;
7use cortex_m_rt::entry; 7use cortex_m_rt::entry;
8use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 8use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
9use embedded_hal::digital::v2::{InputPin, OutputPin};
10use example_common::*; 9use example_common::*;
11 10
12#[entry] 11#[entry]
@@ -21,14 +20,14 @@ fn main() -> ! {
21 let mut led3 = Output::new(p.PB14, Level::High, Speed::Low); 20 let mut led3 = Output::new(p.PB14, Level::High, Speed::Low);
22 21
23 loop { 22 loop {
24 if unwrap!(button.is_high()) { 23 if button.is_high() {
25 info!("high"); 24 info!("high");
26 unwrap!(led1.set_high()); 25 led1.set_high();
27 unwrap!(led3.set_low()); 26 led3.set_low();
28 } else { 27 } else {
29 info!("low"); 28 info!("low");
30 unwrap!(led1.set_low()); 29 led1.set_low();
31 unwrap!(led3.set_high()); 30 led3.set_high();
32 } 31 }
33 } 32 }
34} 33}
diff --git a/examples/stm32f4/src/bin/spi.rs b/examples/stm32f4/src/bin/spi.rs
index 0192e1865..b66eb9582 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};
11use embassy_stm32::spi::{Config, Spi}; 11use embassy_stm32::spi::{Config, Spi};
12use embassy_stm32::time::Hertz; 12use embassy_stm32::time::Hertz;
13use embedded_hal::blocking::spi::Transfer; 13use embedded_hal::blocking::spi::Transfer;
14use embedded_hal::digital::v2::OutputPin;
15use example_common::*; 14use example_common::*;
16 15
17#[entry] 16#[entry]
@@ -35,9 +34,9 @@ fn main() -> ! {
35 34
36 loop { 35 loop {
37 let mut buf = [0x0Au8; 4]; 36 let mut buf = [0x0Au8; 4];
38 unwrap!(cs.set_low()); 37 cs.set_low();
39 unwrap!(spi.transfer(&mut buf)); 38 unwrap!(spi.transfer(&mut buf));
40 unwrap!(cs.set_high()); 39 cs.set_high();
41 info!("xfer {=[u8]:x}", buf); 40 info!("xfer {=[u8]:x}", buf);
42 } 41 }
43} 42}
diff --git a/examples/stm32f7/src/bin/blinky.rs b/examples/stm32f7/src/bin/blinky.rs
index c4857195f..00d67dac0 100644
--- a/examples/stm32f7/src/bin/blinky.rs
+++ b/examples/stm32f7/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embedded_hal::digital::v2::OutputPin;
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
@@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
19 18
20 loop { 19 loop {
21 info!("high"); 20 info!("high");
22 unwrap!(led.set_high()); 21 led.set_high();
23 Timer::after(Duration::from_millis(300)).await; 22 Timer::after(Duration::from_millis(300)).await;
24 23
25 info!("low"); 24 info!("low");
26 unwrap!(led.set_low()); 25 led.set_low();
27 Timer::after(Duration::from_millis(300)).await; 26 Timer::after(Duration::from_millis(300)).await;
28 } 27 }
29} 28}
diff --git a/examples/stm32f7/src/bin/button.rs b/examples/stm32f7/src/bin/button.rs
index 95dee7c74..24eef75b2 100644
--- a/examples/stm32f7/src/bin/button.rs
+++ b/examples/stm32f7/src/bin/button.rs
@@ -6,7 +6,6 @@
6mod example_common; 6mod example_common;
7use cortex_m_rt::entry; 7use cortex_m_rt::entry;
8use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 8use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
9use embedded_hal::digital::v2::{InputPin, OutputPin};
10use example_common::*; 9use example_common::*;
11 10
12#[entry] 11#[entry]
@@ -21,14 +20,14 @@ fn main() -> ! {
21 let mut led3 = Output::new(p.PB14, Level::High, Speed::Low); 20 let mut led3 = Output::new(p.PB14, Level::High, Speed::Low);
22 21
23 loop { 22 loop {
24 if unwrap!(button.is_high()) { 23 if button.is_high() {
25 info!("high"); 24 info!("high");
26 unwrap!(led1.set_high()); 25 led1.set_high();
27 unwrap!(led3.set_low()); 26 led3.set_low();
28 } else { 27 } else {
29 info!("low"); 28 info!("low");
30 unwrap!(led1.set_low()); 29 led1.set_low();
31 unwrap!(led3.set_high()); 30 led3.set_high();
32 } 31 }
33 } 32 }
34} 33}
diff --git a/examples/stm32g0/src/bin/blinky.rs b/examples/stm32g0/src/bin/blinky.rs
index c4857195f..00d67dac0 100644
--- a/examples/stm32g0/src/bin/blinky.rs
+++ b/examples/stm32g0/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embedded_hal::digital::v2::OutputPin;
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
@@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
19 18
20 loop { 19 loop {
21 info!("high"); 20 info!("high");
22 unwrap!(led.set_high()); 21 led.set_high();
23 Timer::after(Duration::from_millis(300)).await; 22 Timer::after(Duration::from_millis(300)).await;
24 23
25 info!("low"); 24 info!("low");
26 unwrap!(led.set_low()); 25 led.set_low();
27 Timer::after(Duration::from_millis(300)).await; 26 Timer::after(Duration::from_millis(300)).await;
28 } 27 }
29} 28}
diff --git a/examples/stm32g0/src/bin/button.rs b/examples/stm32g0/src/bin/button.rs
index 4ca2a43b2..e901c5750 100644
--- a/examples/stm32g0/src/bin/button.rs
+++ b/examples/stm32g0/src/bin/button.rs
@@ -6,7 +6,6 @@
6mod example_common; 6mod example_common;
7use cortex_m_rt::entry; 7use cortex_m_rt::entry;
8use embassy_stm32::gpio::{Input, Pull}; 8use embassy_stm32::gpio::{Input, Pull};
9use embedded_hal::digital::v2::InputPin;
10use example_common::*; 9use example_common::*;
11 10
12#[entry] 11#[entry]
@@ -18,7 +17,7 @@ fn main() -> ! {
18 let button = Input::new(p.PC13, Pull::Up); 17 let button = Input::new(p.PC13, Pull::Up);
19 18
20 loop { 19 loop {
21 if unwrap!(button.is_high()) { 20 if button.is_high() {
22 info!("high"); 21 info!("high");
23 } else { 22 } else {
24 info!("low"); 23 info!("low");
diff --git a/examples/stm32g4/src/bin/blinky.rs b/examples/stm32g4/src/bin/blinky.rs
index a43922a63..1dc67f99e 100644
--- a/examples/stm32g4/src/bin/blinky.rs
+++ b/examples/stm32g4/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embedded_hal::digital::v2::OutputPin;
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
@@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
19 18
20 loop { 19 loop {
21 info!("high"); 20 info!("high");
22 unwrap!(led.set_high()); 21 led.set_high();
23 Timer::after(Duration::from_millis(300)).await; 22 Timer::after(Duration::from_millis(300)).await;
24 23
25 info!("low"); 24 info!("low");
26 unwrap!(led.set_low()); 25 led.set_low();
27 Timer::after(Duration::from_millis(300)).await; 26 Timer::after(Duration::from_millis(300)).await;
28 } 27 }
29} 28}
diff --git a/examples/stm32g4/src/bin/button.rs b/examples/stm32g4/src/bin/button.rs
index f0a4c8745..8c0d7d4fe 100644
--- a/examples/stm32g4/src/bin/button.rs
+++ b/examples/stm32g4/src/bin/button.rs
@@ -6,7 +6,6 @@
6mod example_common; 6mod example_common;
7use cortex_m_rt::entry; 7use cortex_m_rt::entry;
8use embassy_stm32::gpio::{Input, Pull}; 8use embassy_stm32::gpio::{Input, Pull};
9use embedded_hal::digital::v2::InputPin;
10use example_common::*; 9use example_common::*;
11 10
12#[entry] 11#[entry]
@@ -18,7 +17,7 @@ fn main() -> ! {
18 let button = Input::new(p.PC13, Pull::Down); 17 let button = Input::new(p.PC13, Pull::Down);
19 18
20 loop { 19 loop {
21 if unwrap!(button.is_high()) { 20 if button.is_high() {
22 info!("high"); 21 info!("high");
23 } else { 22 } else {
24 info!("low"); 23 info!("low");
diff --git a/examples/stm32h7/src/bin/blinky.rs b/examples/stm32h7/src/bin/blinky.rs
index 78edb5e27..7e5934239 100644
--- a/examples/stm32h7/src/bin/blinky.rs
+++ b/examples/stm32h7/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embedded_hal::digital::v2::OutputPin;
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
@@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
19 18
20 loop { 19 loop {
21 info!("high"); 20 info!("high");
22 unwrap!(led.set_high()); 21 led.set_high();
23 Timer::after(Duration::from_millis(500)).await; 22 Timer::after(Duration::from_millis(500)).await;
24 23
25 info!("low"); 24 info!("low");
26 unwrap!(led.set_low()); 25 led.set_low();
27 Timer::after(Duration::from_millis(500)).await; 26 Timer::after(Duration::from_millis(500)).await;
28 } 27 }
29} 28}
diff --git a/examples/stm32h7/src/bin/camera.rs b/examples/stm32h7/src/bin/camera.rs
index d94592071..9e8071bb3 100644
--- a/examples/stm32h7/src/bin/camera.rs
+++ b/examples/stm32h7/src/bin/camera.rs
@@ -11,7 +11,6 @@ use embassy_stm32::interrupt;
11use embassy_stm32::rcc::{Mco, Mco1Source, McoClock}; 11use embassy_stm32::rcc::{Mco, Mco1Source, McoClock};
12use embassy_stm32::time::U32Ext; 12use embassy_stm32::time::U32Ext;
13use embassy_stm32::Peripherals; 13use embassy_stm32::Peripherals;
14use embedded_hal::digital::v2::OutputPin;
15 14
16use defmt_rtt as _; // global logger 15use defmt_rtt as _; // global logger
17use panic_probe as _; 16use panic_probe as _;
@@ -114,11 +113,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
114 defmt::info!("main loop running"); 113 defmt::info!("main loop running");
115 loop { 114 loop {
116 defmt::info!("high"); 115 defmt::info!("high");
117 defmt::unwrap!(led.set_high()); 116 led.set_high();
118 Timer::after(Duration::from_millis(500)).await; 117 Timer::after(Duration::from_millis(500)).await;
119 118
120 defmt::info!("low"); 119 defmt::info!("low");
121 defmt::unwrap!(led.set_low()); 120 led.set_low();
122 Timer::after(Duration::from_millis(500)).await; 121 Timer::after(Duration::from_millis(500)).await;
123 } 122 }
124} 123}
diff --git a/examples/stm32h7/src/bin/mco.rs b/examples/stm32h7/src/bin/mco.rs
index 4cecd9b04..f27bd8ef8 100644
--- a/examples/stm32h7/src/bin/mco.rs
+++ b/examples/stm32h7/src/bin/mco.rs
@@ -9,7 +9,6 @@ use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::rcc::{Mco, Mco1Source, McoClock}; 10use embassy_stm32::rcc::{Mco, Mco1Source, McoClock};
11use embassy_stm32::Peripherals; 11use embassy_stm32::Peripherals;
12use embedded_hal::digital::v2::OutputPin;
13use example_common::*; 12use example_common::*;
14 13
15#[embassy::main] 14#[embassy::main]
@@ -22,11 +21,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
22 21
23 loop { 22 loop {
24 info!("high"); 23 info!("high");
25 unwrap!(led.set_high()); 24 led.set_high();
26 Timer::after(Duration::from_millis(500)).await; 25 Timer::after(Duration::from_millis(500)).await;
27 26
28 info!("low"); 27 info!("low");
29 unwrap!(led.set_low()); 28 led.set_low();
30 Timer::after(Duration::from_millis(500)).await; 29 Timer::after(Duration::from_millis(500)).await;
31 } 30 }
32} 31}
diff --git a/examples/stm32h7/src/bin/rng.rs b/examples/stm32h7/src/bin/rng.rs
index d64ad9bcd..8e03861d5 100644
--- a/examples/stm32h7/src/bin/rng.rs
+++ b/examples/stm32h7/src/bin/rng.rs
@@ -10,7 +10,6 @@ use embassy::traits::rng::Random;
10use embassy_stm32::gpio::{Level, Output, Speed}; 10use embassy_stm32::gpio::{Level, Output, Speed};
11use embassy_stm32::rng::Rng; 11use embassy_stm32::rng::Rng;
12use embassy_stm32::Peripherals; 12use embassy_stm32::Peripherals;
13use embedded_hal::digital::v2::OutputPin;
14use example_common::*; 13use example_common::*;
15 14
16#[embassy::main] 15#[embassy::main]
@@ -23,11 +22,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
23 22
24 loop { 23 loop {
25 info!("high {}", unwrap!(rng.next_u8(16).await)); 24 info!("high {}", unwrap!(rng.next_u8(16).await));
26 unwrap!(led.set_high()); 25 led.set_high();
27 Timer::after(Duration::from_millis(500)).await; 26 Timer::after(Duration::from_millis(500)).await;
28 27
29 info!("low {}", unwrap!(rng.next_u8(16).await)); 28 info!("low {}", unwrap!(rng.next_u8(16).await));
30 unwrap!(led.set_low()); 29 led.set_low();
31 Timer::after(Duration::from_millis(500)).await; 30 Timer::after(Duration::from_millis(500)).await;
32 } 31 }
33} 32}
diff --git a/examples/stm32l0/src/bin/blinky.rs b/examples/stm32l0/src/bin/blinky.rs
index 1198b29da..46e29a897 100644
--- a/examples/stm32l0/src/bin/blinky.rs
+++ b/examples/stm32l0/src/bin/blinky.rs
@@ -9,7 +9,6 @@ use embassy::executor::Spawner;
9use embassy::time::{Duration, Timer}; 9use embassy::time::{Duration, Timer};
10use embassy_stm32::gpio::{Level, Output, Speed}; 10use embassy_stm32::gpio::{Level, Output, Speed};
11use embassy_stm32::Peripherals; 11use embassy_stm32::Peripherals;
12use embedded_hal::digital::v2::OutputPin;
13use example_common::*; 12use example_common::*;
14 13
15#[embassy::main] 14#[embassy::main]
@@ -20,11 +19,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
20 19
21 loop { 20 loop {
22 info!("high"); 21 info!("high");
23 unwrap!(led.set_high()); 22 led.set_high();
24 Timer::after(Duration::from_millis(300)).await; 23 Timer::after(Duration::from_millis(300)).await;
25 24
26 info!("low"); 25 info!("low");
27 unwrap!(led.set_low()); 26 led.set_low();
28 Timer::after(Duration::from_millis(300)).await; 27 Timer::after(Duration::from_millis(300)).await;
29 } 28 }
30} 29}
diff --git a/examples/stm32l0/src/bin/button.rs b/examples/stm32l0/src/bin/button.rs
index c29155302..046c43caf 100644
--- a/examples/stm32l0/src/bin/button.rs
+++ b/examples/stm32l0/src/bin/button.rs
@@ -7,7 +7,6 @@ mod example_common;
7use embassy::executor::Spawner; 7use embassy::executor::Spawner;
8use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 8use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
9use embassy_stm32::Peripherals; 9use embassy_stm32::Peripherals;
10use embedded_hal::digital::v2::{InputPin, OutputPin};
11use example_common::*; 10use example_common::*;
12 11
13#[embassy::main] 12#[embassy::main]
@@ -19,14 +18,14 @@ async fn main(_spawner: Spawner, p: Peripherals) {
19 let mut led2 = Output::new(p.PB5, Level::High, Speed::Low); 18 let mut led2 = Output::new(p.PB5, Level::High, Speed::Low);
20 19
21 loop { 20 loop {
22 if unwrap!(button.is_high()) { 21 if button.is_high() {
23 info!("high"); 22 info!("high");
24 unwrap!(led1.set_high()); 23 led1.set_high();
25 unwrap!(led2.set_low()); 24 led2.set_low();
26 } else { 25 } else {
27 info!("low"); 26 info!("low");
28 unwrap!(led1.set_low()); 27 led1.set_low();
29 unwrap!(led2.set_high()); 28 led2.set_high();
30 } 29 }
31 } 30 }
32} 31}
diff --git a/examples/stm32l0/src/bin/spi.rs b/examples/stm32l0/src/bin/spi.rs
index f768a5227..d30bb8d7a 100644
--- a/examples/stm32l0/src/bin/spi.rs
+++ b/examples/stm32l0/src/bin/spi.rs
@@ -7,7 +7,6 @@ mod example_common;
7 7
8use embassy::executor::Spawner; 8use embassy::executor::Spawner;
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embedded_hal::digital::v2::OutputPin;
11use example_common::*; 10use example_common::*;
12 11
13use embassy_stm32::dma::NoDma; 12use embassy_stm32::dma::NoDma;
@@ -35,9 +34,9 @@ async fn main(_spawner: Spawner, p: Peripherals) {
35 34
36 loop { 35 loop {
37 let mut buf = [0x0Au8; 4]; 36 let mut buf = [0x0Au8; 4];
38 unwrap!(cs.set_low()); 37 cs.set_low();
39 unwrap!(spi.transfer(&mut buf)); 38 unwrap!(spi.transfer(&mut buf));
40 unwrap!(cs.set_high()); 39 cs.set_high();
41 info!("xfer {=[u8]:x}", buf); 40 info!("xfer {=[u8]:x}", buf);
42 } 41 }
43} 42}
diff --git a/examples/stm32l1/src/bin/blinky.rs b/examples/stm32l1/src/bin/blinky.rs
index deabdddba..07c804e9f 100644
--- a/examples/stm32l1/src/bin/blinky.rs
+++ b/examples/stm32l1/src/bin/blinky.rs
@@ -9,7 +9,6 @@ use embassy::executor::Spawner;
9use embassy::time::{Duration, Timer}; 9use embassy::time::{Duration, Timer};
10use embassy_stm32::gpio::{Level, Output, Speed}; 10use embassy_stm32::gpio::{Level, Output, Speed};
11use embassy_stm32::Peripherals; 11use embassy_stm32::Peripherals;
12use embedded_hal::digital::v2::OutputPin;
13use example_common::*; 12use example_common::*;
14 13
15#[embassy::main] 14#[embassy::main]
@@ -20,11 +19,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
20 19
21 loop { 20 loop {
22 info!("high"); 21 info!("high");
23 unwrap!(led.set_high()); 22 led.set_high();
24 Timer::after(Duration::from_millis(1000)).await; 23 Timer::after(Duration::from_millis(1000)).await;
25 24
26 info!("low"); 25 info!("low");
27 unwrap!(led.set_low()); 26 led.set_low();
28 Timer::after(Duration::from_millis(1000)).await; 27 Timer::after(Duration::from_millis(1000)).await;
29 } 28 }
30} 29}
diff --git a/examples/stm32l1/src/bin/spi.rs b/examples/stm32l1/src/bin/spi.rs
index 3cfbe3fc4..9d1a2fc87 100644
--- a/examples/stm32l1/src/bin/spi.rs
+++ b/examples/stm32l1/src/bin/spi.rs
@@ -7,7 +7,6 @@ mod example_common;
7 7
8use embassy::executor::Spawner; 8use embassy::executor::Spawner;
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embedded_hal::digital::v2::OutputPin;
11use example_common::*; 10use example_common::*;
12 11
13use embassy_stm32::dma::NoDma; 12use embassy_stm32::dma::NoDma;
@@ -35,9 +34,9 @@ async fn main(_spawner: Spawner, p: Peripherals) {
35 34
36 loop { 35 loop {
37 let mut buf = [0x0Au8; 4]; 36 let mut buf = [0x0Au8; 4];
38 unwrap!(cs.set_low()); 37 cs.set_low();
39 unwrap!(spi.transfer(&mut buf)); 38 unwrap!(spi.transfer(&mut buf));
40 unwrap!(cs.set_high()); 39 cs.set_high();
41 info!("xfer {=[u8]:x}", buf); 40 info!("xfer {=[u8]:x}", buf);
42 } 41 }
43} 42}
diff --git a/examples/stm32l4/src/bin/blinky.rs b/examples/stm32l4/src/bin/blinky.rs
index 8a65858f8..030283756 100644
--- a/examples/stm32l4/src/bin/blinky.rs
+++ b/examples/stm32l4/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embedded_hal::digital::v2::OutputPin;
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
@@ -18,9 +17,9 @@ async fn main(_spawner: Spawner, p: Peripherals) {
18 let mut led = Output::new(p.PB14, Level::High, Speed::Low); 17 let mut led = Output::new(p.PB14, Level::High, Speed::Low);
19 18
20 loop { 19 loop {
21 unwrap!(led.set_high()); 20 led.set_high();
22 Timer::after(Duration::from_millis(300)).await; 21 Timer::after(Duration::from_millis(300)).await;
23 unwrap!(led.set_low()); 22 led.set_low();
24 Timer::after(Duration::from_millis(300)).await; 23 Timer::after(Duration::from_millis(300)).await;
25 } 24 }
26} 25}
diff --git a/examples/stm32l4/src/bin/button.rs b/examples/stm32l4/src/bin/button.rs
index fd8674549..6073c137e 100644
--- a/examples/stm32l4/src/bin/button.rs
+++ b/examples/stm32l4/src/bin/button.rs
@@ -5,7 +5,6 @@
5#[path = "../example_common.rs"] 5#[path = "../example_common.rs"]
6mod example_common; 6mod example_common;
7use embassy_stm32::gpio::{Input, Pull}; 7use embassy_stm32::gpio::{Input, Pull};
8use embedded_hal::digital::v2::InputPin;
9use example_common::*; 8use example_common::*;
10 9
11#[cortex_m_rt::entry] 10#[cortex_m_rt::entry]
@@ -17,7 +16,7 @@ fn main() -> ! {
17 let button = Input::new(p.PC13, Pull::Up); 16 let button = Input::new(p.PC13, Pull::Up);
18 17
19 loop { 18 loop {
20 if unwrap!(button.is_high()) { 19 if button.is_high() {
21 info!("high"); 20 info!("high");
22 } else { 21 } else {
23 info!("low"); 22 info!("low");
diff --git a/examples/stm32l4/src/bin/spi.rs b/examples/stm32l4/src/bin/spi.rs
index 5b9ae1ce0..1b6e3946e 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};
10use embassy_stm32::spi::{Config, Spi}; 10use embassy_stm32::spi::{Config, Spi};
11use embassy_stm32::time::Hertz; 11use embassy_stm32::time::Hertz;
12use embedded_hal::blocking::spi::Transfer; 12use embedded_hal::blocking::spi::Transfer;
13use embedded_hal::digital::v2::OutputPin;
14use example_common::*; 13use example_common::*;
15 14
16#[cortex_m_rt::entry] 15#[cortex_m_rt::entry]
@@ -34,9 +33,9 @@ fn main() -> ! {
34 33
35 loop { 34 loop {
36 let mut buf = [0x0Au8; 4]; 35 let mut buf = [0x0Au8; 4];
37 unwrap!(cs.set_low()); 36 cs.set_low();
38 unwrap!(spi.transfer(&mut buf)); 37 unwrap!(spi.transfer(&mut buf));
39 unwrap!(cs.set_high()); 38 cs.set_high();
40 info!("xfer {=[u8]:x}", buf); 39 info!("xfer {=[u8]:x}", buf);
41 } 40 }
42} 41}
diff --git a/examples/stm32l4/src/bin/spi_blocking_async.rs b/examples/stm32l4/src/bin/spi_blocking_async.rs
index f092706d4..3be3f21c9 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};
12use embassy_stm32::time::Hertz; 12use embassy_stm32::time::Hertz;
13use embassy_stm32::Peripherals; 13use embassy_stm32::Peripherals;
14use embassy_traits::{adapter::BlockingAsync, spi::FullDuplex}; 14use embassy_traits::{adapter::BlockingAsync, spi::FullDuplex};
15use embedded_hal::digital::v2::{InputPin, OutputPin};
16use example_common::*; 15use example_common::*;
17 16
18#[embassy::main] 17#[embassy::main]
@@ -41,17 +40,17 @@ async fn main(_spawner: Spawner, p: Peripherals) {
41 let ready = Input::new(p.PE1, Pull::Up); 40 let ready = Input::new(p.PE1, Pull::Up);
42 41
43 cortex_m::asm::delay(100_000); 42 cortex_m::asm::delay(100_000);
44 unwrap!(reset.set_high()); 43 reset.set_high();
45 cortex_m::asm::delay(100_000); 44 cortex_m::asm::delay(100_000);
46 45
47 while unwrap!(ready.is_low()) { 46 while ready.is_low() {
48 info!("waiting for ready"); 47 info!("waiting for ready");
49 } 48 }
50 49
51 let write = [0x0A; 10]; 50 let write = [0x0A; 10];
52 let mut read = [0; 10]; 51 let mut read = [0; 10];
53 unwrap!(cs.set_low()); 52 cs.set_low();
54 spi.read_write(&mut read, &write).await.ok(); 53 spi.read_write(&mut read, &write).await.ok();
55 unwrap!(cs.set_high()); 54 cs.set_high();
56 info!("xfer {=[u8]:x}", read); 55 info!("xfer {=[u8]:x}", read);
57} 56}
diff --git a/examples/stm32l4/src/bin/spi_dma.rs b/examples/stm32l4/src/bin/spi_dma.rs
index 4b74c7d7d..d6464bbfa 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};
11use embassy_stm32::time::Hertz; 11use embassy_stm32::time::Hertz;
12use embassy_stm32::Peripherals; 12use embassy_stm32::Peripherals;
13use embassy_traits::spi::FullDuplex; 13use embassy_traits::spi::FullDuplex;
14use embedded_hal::digital::v2::{InputPin, OutputPin};
15use example_common::*; 14use example_common::*;
16 15
17#[embassy::main] 16#[embassy::main]
@@ -38,17 +37,17 @@ async fn main(_spawner: Spawner, p: Peripherals) {
38 let ready = Input::new(p.PE1, Pull::Up); 37 let ready = Input::new(p.PE1, Pull::Up);
39 38
40 cortex_m::asm::delay(100_000); 39 cortex_m::asm::delay(100_000);
41 unwrap!(reset.set_high()); 40 reset.set_high();
42 cortex_m::asm::delay(100_000); 41 cortex_m::asm::delay(100_000);
43 42
44 while unwrap!(ready.is_low()) { 43 while ready.is_low() {
45 info!("waiting for ready"); 44 info!("waiting for ready");
46 } 45 }
47 46
48 let write = [0x0A; 10]; 47 let write = [0x0A; 10];
49 let mut read = [0; 10]; 48 let mut read = [0; 10];
50 unwrap!(cs.set_low()); 49 cs.set_low();
51 spi.read_write(&mut read, &write).await.ok(); 50 spi.read_write(&mut read, &write).await.ok();
52 unwrap!(cs.set_high()); 51 cs.set_high();
53 info!("xfer {=[u8]:x}", read); 52 info!("xfer {=[u8]:x}", read);
54} 53}
diff --git a/examples/stm32wb55/src/bin/blinky.rs b/examples/stm32wb55/src/bin/blinky.rs
index 42522fe9b..e1dbb30de 100644
--- a/examples/stm32wb55/src/bin/blinky.rs
+++ b/examples/stm32wb55/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embedded_hal::digital::v2::OutputPin;
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
@@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
19 18
20 loop { 19 loop {
21 info!("high"); 20 info!("high");
22 unwrap!(led.set_high()); 21 led.set_high();
23 Timer::after(Duration::from_millis(500)).await; 22 Timer::after(Duration::from_millis(500)).await;
24 23
25 info!("low"); 24 info!("low");
26 unwrap!(led.set_low()); 25 led.set_low();
27 Timer::after(Duration::from_millis(500)).await; 26 Timer::after(Duration::from_millis(500)).await;
28 } 27 }
29} 28}
diff --git a/examples/stm32wl55/src/bin/blinky.rs b/examples/stm32wl55/src/bin/blinky.rs
index 3c12a79d0..9ec208c3d 100644
--- a/examples/stm32wl55/src/bin/blinky.rs
+++ b/examples/stm32wl55/src/bin/blinky.rs
@@ -8,7 +8,6 @@ use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed}; 9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embedded_hal::digital::v2::OutputPin;
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main] 13#[embassy::main]
@@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
19 18
20 loop { 19 loop {
21 info!("high"); 20 info!("high");
22 unwrap!(led.set_high()); 21 led.set_high();
23 Timer::after(Duration::from_millis(500)).await; 22 Timer::after(Duration::from_millis(500)).await;
24 23
25 info!("low"); 24 info!("low");
26 unwrap!(led.set_low()); 25 led.set_low();
27 Timer::after(Duration::from_millis(500)).await; 26 Timer::after(Duration::from_millis(500)).await;
28 } 27 }
29} 28}
diff --git a/examples/stm32wl55/src/bin/button.rs b/examples/stm32wl55/src/bin/button.rs
index 55b688663..be8f60e26 100644
--- a/examples/stm32wl55/src/bin/button.rs
+++ b/examples/stm32wl55/src/bin/button.rs
@@ -5,7 +5,6 @@
5#[path = "../example_common.rs"] 5#[path = "../example_common.rs"]
6mod example_common; 6mod example_common;
7use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 7use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
8use embedded_hal::digital::v2::{InputPin, OutputPin};
9use example_common::*; 8use example_common::*;
10 9
11use cortex_m_rt::entry; 10use cortex_m_rt::entry;
@@ -21,12 +20,12 @@ fn main() -> ! {
21 let mut led2 = Output::new(p.PB9, Level::High, Speed::Low); 20 let mut led2 = Output::new(p.PB9, Level::High, Speed::Low);
22 21
23 loop { 22 loop {
24 if button.is_high().unwrap() { 23 if button.is_high() {
25 led1.set_high().unwrap(); 24 led1.set_high();
26 led2.set_low().unwrap(); 25 led2.set_low();
27 } else { 26 } else {
28 led1.set_low().unwrap(); 27 led1.set_low();
29 led2.set_high().unwrap(); 28 led2.set_high();
30 } 29 }
31 } 30 }
32} 31}
diff --git a/examples/stm32wl55/src/bin/subghz.rs b/examples/stm32wl55/src/bin/subghz.rs
index 52fe6e9fa..570bd980f 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};
17use embassy_stm32::interrupt; 17use embassy_stm32::interrupt;
18use embassy_stm32::subghz::*; 18use embassy_stm32::subghz::*;
19use embassy_stm32::Peripherals; 19use embassy_stm32::Peripherals;
20use embedded_hal::digital::v2::OutputPin;
21use example_common::unwrap; 20use example_common::unwrap;
22 21
23const PING_DATA: &str = "PING"; 22const PING_DATA: &str = "PING";
@@ -89,9 +88,9 @@ async fn main(_spawner: embassy::executor::Spawner, p: Peripherals) {
89 88
90 defmt::info!("Radio ready for use"); 89 defmt::info!("Radio ready for use");
91 90
92 unwrap!(led1.set_low()); 91 led1.set_low();
93 92
94 unwrap!(led2.set_high()); 93 led2.set_high();
95 94
96 unwrap!(radio.set_standby(StandbyClk::Rc)); 95 unwrap!(radio.set_standby(StandbyClk::Rc));
97 unwrap!(radio.set_tcxo_mode(&TCXO_MODE)); 96 unwrap!(radio.set_tcxo_mode(&TCXO_MODE));
@@ -110,11 +109,11 @@ async fn main(_spawner: embassy::executor::Spawner, p: Peripherals) {
110 109
111 defmt::info!("Status: {:?}", unwrap!(radio.status())); 110 defmt::info!("Status: {:?}", unwrap!(radio.status()));
112 111
113 unwrap!(led2.set_low()); 112 led2.set_low();
114 113
115 loop { 114 loop {
116 pin.wait_for_rising_edge().await; 115 pin.wait_for_rising_edge().await;
117 unwrap!(led3.set_high()); 116 led3.set_high();
118 unwrap!(radio.set_irq_cfg(&CfgIrq::new().irq_enable_all(Irq::TxDone))); 117 unwrap!(radio.set_irq_cfg(&CfgIrq::new().irq_enable_all(Irq::TxDone)));
119 unwrap!(radio.write_buffer(TX_BUF_OFFSET, PING_DATA_BYTES)); 118 unwrap!(radio.write_buffer(TX_BUF_OFFSET, PING_DATA_BYTES));
120 unwrap!(radio.set_tx(Timeout::DISABLED)); 119 unwrap!(radio.set_tx(Timeout::DISABLED));
@@ -127,6 +126,6 @@ async fn main(_spawner: embassy::executor::Spawner, p: Peripherals) {
127 defmt::info!("TX done"); 126 defmt::info!("TX done");
128 } 127 }
129 unwrap!(radio.clear_irq_status(irq_status)); 128 unwrap!(radio.clear_irq_status(irq_status));
130 unwrap!(led3.set_low()); 129 led3.set_low();
131 } 130 }
132} 131}
diff --git a/tests/stm32/src/bin/gpio.rs b/tests/stm32/src/bin/gpio.rs
index 51ede6cea..305da8d12 100644
--- a/tests/stm32/src/bin/gpio.rs
+++ b/tests/stm32/src/bin/gpio.rs
@@ -8,7 +8,6 @@ use defmt::assert;
8use embassy::executor::Spawner; 8use embassy::executor::Spawner;
9use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; 9use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
10use embassy_stm32::Peripherals; 10use embassy_stm32::Peripherals;
11use embedded_hal::digital::v2::{InputPin, OutputPin};
12use example_common::*; 11use example_common::*;
13 12
14#[embassy::main(config = "config()")] 13#[embassy::main(config = "config()")]
@@ -35,12 +34,12 @@ async fn main(_spawner: Spawner, p: Peripherals) {
35 { 34 {
36 let _a = Output::new(&mut a, Level::Low, Speed::Low); 35 let _a = Output::new(&mut a, Level::Low, Speed::Low);
37 delay(); 36 delay();
38 assert!(b.is_low().unwrap()); 37 assert!(b.is_low());
39 } 38 }
40 { 39 {
41 let _a = Output::new(&mut a, Level::High, Speed::Low); 40 let _a = Output::new(&mut a, Level::High, Speed::Low);
42 delay(); 41 delay();
43 assert!(b.is_high().unwrap()); 42 assert!(b.is_high());
44 } 43 }
45 } 44 }
46 45
@@ -51,38 +50,38 @@ async fn main(_spawner: Spawner, p: Peripherals) {
51 50
52 let mut a = Output::new(&mut a, Level::Low, Speed::Low); 51 let mut a = Output::new(&mut a, Level::Low, Speed::Low);
53 delay(); 52 delay();
54 assert!(b.is_low().unwrap()); 53 assert!(b.is_low());
55 a.set_high().unwrap(); 54 a.set_high();
56 delay(); 55 delay();
57 assert!(b.is_high().unwrap()); 56 assert!(b.is_high());
58 } 57 }
59 58
60 // Test input pulldown 59 // Test input pulldown
61 { 60 {
62 let b = Input::new(&mut b, Pull::Down); 61 let b = Input::new(&mut b, Pull::Down);
63 delay(); 62 delay();
64 assert!(b.is_low().unwrap()); 63 assert!(b.is_low());
65 64
66 let mut a = Output::new(&mut a, Level::Low, Speed::Low); 65 let mut a = Output::new(&mut a, Level::Low, Speed::Low);
67 delay(); 66 delay();
68 assert!(b.is_low().unwrap()); 67 assert!(b.is_low());
69 a.set_high().unwrap(); 68 a.set_high();
70 delay(); 69 delay();
71 assert!(b.is_high().unwrap()); 70 assert!(b.is_high());
72 } 71 }
73 72
74 // Test input pullup 73 // Test input pullup
75 { 74 {
76 let b = Input::new(&mut b, Pull::Up); 75 let b = Input::new(&mut b, Pull::Up);
77 delay(); 76 delay();
78 assert!(b.is_high().unwrap()); 77 assert!(b.is_high());
79 78
80 let mut a = Output::new(&mut a, Level::Low, Speed::Low); 79 let mut a = Output::new(&mut a, Level::Low, Speed::Low);
81 delay(); 80 delay();
82 assert!(b.is_low().unwrap()); 81 assert!(b.is_low());
83 a.set_high().unwrap(); 82 a.set_high();
84 delay(); 83 delay();
85 assert!(b.is_high().unwrap()); 84 assert!(b.is_high());
86 } 85 }
87 86
88 info!("Test OK"); 87 info!("Test OK");