From 722931c2be4954f82224268192915f37be81d4bb Mon Sep 17 00:00:00 2001 From: Andrey Zgarbul Date: Thu, 10 Jun 2021 06:30:23 +0300 Subject: [PATCH 1/2] OutputPinInfallible --- CHANGELOG.md | 2 + examples/blinky.rs | 5 +- examples/blinky_generic.rs | 5 +- examples/blinky_rtc.rs | 5 +- examples/blinky_rtcalarm_irq.rs | 1 - examples/blinky_timer_irq.rs | 1 - examples/can-loopback.rs | 3 +- examples/delay.rs | 5 +- examples/exti.rs | 2 +- examples/led.rs | 19 +------ examples/mfrc522.rs | 4 +- examples/multi_mode_gpio.rs | 9 ++- examples/nojtag.rs | 6 +- examples/timer-interrupt-rtic.rs | 5 +- examples/usb_serial.rs | 3 +- examples/usb_serial_interrupt.rs | 3 +- examples/usb_serial_rtic.rs | 3 +- src/gpio.rs | 94 +++++++++++++++++++++++++++++--- src/prelude.rs | 32 +++++++++-- 19 files changed, 143 insertions(+), 64 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c38547a..0f972d6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added +- `InputPin`, `OutputPin`, `StatefulOutputPin`, `ToggleableOutputPin` traits. + Add them to prelude instead of `embedded_hal`'s - Support for OpenDrain pin configuration on SPI CLK and MOSI pins - LSB/MSB bit format selection for `SPI` - Support for CAN peripherals with the `bxcan` crate diff --git a/examples/blinky.rs b/examples/blinky.rs index 9fae270c..353d5eb6 100644 --- a/examples/blinky.rs +++ b/examples/blinky.rs @@ -14,7 +14,6 @@ use panic_halt as _; use nb::block; use cortex_m_rt::entry; -use embedded_hal::digital::v2::OutputPin; use stm32f1xx_hal::{pac, prelude::*, timer::Timer}; #[entry] @@ -45,8 +44,8 @@ fn main() -> ! { // Wait for the timer to trigger an update and change the state of the LED loop { block!(timer.wait()).unwrap(); - led.set_high().unwrap(); + led.set_high(); block!(timer.wait()).unwrap(); - led.set_low().unwrap(); + led.set_low(); } } diff --git a/examples/blinky_generic.rs b/examples/blinky_generic.rs index 5809d4be..1a3f1cea 100644 --- a/examples/blinky_generic.rs +++ b/examples/blinky_generic.rs @@ -9,7 +9,6 @@ use panic_halt as _; use nb::block; use cortex_m_rt::entry; -use embedded_hal::digital::v2::OutputPin; use stm32f1xx_hal::{pac, prelude::*, timer::Timer}; #[entry] @@ -39,11 +38,11 @@ fn main() -> ! { loop { block!(timer.wait()).unwrap(); for led in leds.iter_mut() { - led.set_high().unwrap(); + led.set_high(); } block!(timer.wait()).unwrap(); for led in leds.iter_mut() { - led.set_low().unwrap(); + led.set_low(); } } } diff --git a/examples/blinky_rtc.rs b/examples/blinky_rtc.rs index 0cfd52d3..d23c01a0 100644 --- a/examples/blinky_rtc.rs +++ b/examples/blinky_rtc.rs @@ -15,7 +15,6 @@ use panic_halt as _; use stm32f1xx_hal::{pac, prelude::*, rtc::Rtc}; use cortex_m_rt::entry; -use embedded_hal::digital::v2::OutputPin; use nb::block; #[entry] @@ -43,10 +42,10 @@ fn main() -> ! { rtc.set_alarm(5); block!(rtc.wait_alarm()).unwrap(); if led_on { - led.set_low().unwrap(); + led.set_low(); led_on = false; } else { - led.set_high().unwrap(); + led.set_high(); led_on = true; } } diff --git a/examples/blinky_rtcalarm_irq.rs b/examples/blinky_rtcalarm_irq.rs index 8a684459..4c263086 100644 --- a/examples/blinky_rtcalarm_irq.rs +++ b/examples/blinky_rtcalarm_irq.rs @@ -24,7 +24,6 @@ use crate::hal::{ use core::cell::RefCell; use cortex_m::{asm::wfi, interrupt::Mutex}; use cortex_m_rt::entry; -use embedded_hal::digital::v2::OutputPin; // A type definition for the GPIO pin to be used for our LED type LEDPIN = gpioc::PC13>; diff --git a/examples/blinky_timer_irq.rs b/examples/blinky_timer_irq.rs index cc9bf57c..0c0c0a6c 100644 --- a/examples/blinky_timer_irq.rs +++ b/examples/blinky_timer_irq.rs @@ -24,7 +24,6 @@ use crate::hal::{ use core::cell::RefCell; use cortex_m::{asm::wfi, interrupt::Mutex}; use cortex_m_rt::entry; -use embedded_hal::digital::v2::OutputPin; // NOTE You can uncomment 'hprintln' here and in the code below for a bit more // verbosity at runtime, at the cost of throwing off the timing of the blink diff --git a/examples/can-loopback.rs b/examples/can-loopback.rs index fa4277d6..e13c0ea3 100644 --- a/examples/can-loopback.rs +++ b/examples/can-loopback.rs @@ -11,7 +11,6 @@ use bxcan::{ use panic_halt as _; use cortex_m_rt::entry; -use embedded_hal::digital::v2::OutputPin; use nb::block; use stm32f1xx_hal::{can::Can, pac, prelude::*}; @@ -111,7 +110,7 @@ fn main() -> ! { let mut gpiob = dp.GPIOB.split(&mut rcc.apb2); let mut led = gpiob.pb9.into_push_pull_output(&mut gpiob.crh); - led.set_high().unwrap(); + led.set_high(); loop {} } diff --git a/examples/delay.rs b/examples/delay.rs index e95a50b8..073e1d0d 100644 --- a/examples/delay.rs +++ b/examples/delay.rs @@ -7,7 +7,6 @@ use panic_halt as _; use cortex_m_rt::entry; -use embedded_hal::digital::v2::OutputPin; use stm32f1xx_hal::{delay::Delay, pac, prelude::*}; #[entry] @@ -34,9 +33,9 @@ fn main() -> ! { let mut delay = Delay::new(cp.SYST, clocks); loop { - led.set_high().unwrap(); + led.set_high(); delay.delay_ms(1_000_u16); - led.set_low().unwrap(); + led.set_low(); delay.delay_ms(1_000_u16); } } diff --git a/examples/exti.rs b/examples/exti.rs index 4e6e2883..abad4b8f 100644 --- a/examples/exti.rs +++ b/examples/exti.rs @@ -29,7 +29,7 @@ fn EXTI9_5() { let int_pin = unsafe { &mut *INT_PIN.as_mut_ptr() }; if int_pin.check_interrupt() { - led.toggle().unwrap(); + led.toggle(); // if we don't clear this bit, the ISR would trigger indefinitely int_pin.clear_interrupt_pending_bit(); diff --git a/examples/led.rs b/examples/led.rs index 2b11679e..86c995bc 100644 --- a/examples/led.rs +++ b/examples/led.rs @@ -16,7 +16,6 @@ use panic_halt as _; use cortex_m_rt::entry; -use embedded_hal::digital::v2::OutputPin; use stm32f1xx_hal::{pac, prelude::*}; #[entry] @@ -27,25 +26,13 @@ fn main() -> ! { let mut gpioc = p.GPIOC.split(&mut rcc.apb2); #[cfg(feature = "stm32f100")] - gpioc - .pc9 - .into_push_pull_output(&mut gpioc.crh) - .set_high() - .unwrap(); + gpioc.pc9.into_push_pull_output(&mut gpioc.crh).set_high(); #[cfg(feature = "stm32f101")] - gpioc - .pc9 - .into_push_pull_output(&mut gpioc.crh) - .set_high() - .unwrap(); + gpioc.pc9.into_push_pull_output(&mut gpioc.crh).set_high(); #[cfg(any(feature = "stm32f103", feature = "stm32f105", feature = "stm32f107"))] - gpioc - .pc13 - .into_push_pull_output(&mut gpioc.crh) - .set_low() - .unwrap(); + gpioc.pc13.into_push_pull_output(&mut gpioc.crh).set_low(); loop {} } diff --git a/examples/mfrc522.rs b/examples/mfrc522.rs index 2edaad9a..9f1fa81e 100644 --- a/examples/mfrc522.rs +++ b/examples/mfrc522.rs @@ -7,7 +7,7 @@ use panic_itm as _; use cortex_m::iprintln; use cortex_m_rt::entry; -use embedded_hal::digital::{v1_compat::OldOutputPin, v2::OutputPin}; +use embedded_hal::digital::v1_compat::OldOutputPin; use mfrc522::Mfrc522; use stm32f1xx_hal::{pac, prelude::*, spi::Spi}; @@ -42,7 +42,7 @@ fn main() -> ! { let mut mfrc522 = Mfrc522::new(spi, OldOutputPin::from(nss)).unwrap(); let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh); - led.set_high().unwrap(); + led.set_high(); loop { if let Ok(atqa) = mfrc522.reqa() { diff --git a/examples/multi_mode_gpio.rs b/examples/multi_mode_gpio.rs index 58bcd145..8df080f3 100644 --- a/examples/multi_mode_gpio.rs +++ b/examples/multi_mode_gpio.rs @@ -8,7 +8,6 @@ use nb::block; use cortex_m_rt::entry; use cortex_m_semihosting::hprintln; -use embedded_hal::digital::v2::{InputPin, OutputPin}; use stm32f1xx_hal::{gpio::State, pac, prelude::*, timer::Timer}; #[entry] @@ -37,16 +36,16 @@ fn main() -> ! { // Wait for the timer to trigger an update and change the state of the LED loop { block!(timer.wait()).unwrap(); - hprintln!("{}", pin.is_high().unwrap()).unwrap(); + hprintln!("{}", pin.is_high()).unwrap(); pin.as_push_pull_output(&mut gpioc.crh, |out| { - out.set_high().unwrap(); + out.set_high(); block!(timer.wait()).unwrap(); - out.set_low().unwrap(); + out.set_low(); block!(timer.wait()).unwrap(); }); pin.as_push_pull_output_with_state(&mut gpioc.crh, State::High, |out| { block!(timer.wait()).unwrap(); - out.set_low().unwrap(); + out.set_low(); block!(timer.wait()).unwrap(); }); } diff --git a/examples/nojtag.rs b/examples/nojtag.rs index 2342411f..d66167d6 100644 --- a/examples/nojtag.rs +++ b/examples/nojtag.rs @@ -25,9 +25,9 @@ fn main() -> ! { let mut pb4 = pb4.into_push_pull_output(&mut gpiob.crl); loop { - pa15.toggle().unwrap(); - pb3.toggle().unwrap(); - pb4.toggle().unwrap(); + pa15.toggle(); + pb3.toggle(); + pb4.toggle(); cortex_m::asm::delay(8_000_000); } } diff --git a/examples/timer-interrupt-rtic.rs b/examples/timer-interrupt-rtic.rs index acabfcf8..5068b4c2 100644 --- a/examples/timer-interrupt-rtic.rs +++ b/examples/timer-interrupt-rtic.rs @@ -13,7 +13,6 @@ use panic_halt as _; use rtic::app; -use embedded_hal::digital::v2::OutputPin; use stm32f1xx_hal::{ gpio::{gpioc::PC13, Output, PushPull, State}, pac, @@ -85,10 +84,10 @@ const APP: () = { if *cx.resources.led_state { // Uses resources managed by rtic to turn led off (on bluepill) - cx.resources.led.set_high().unwrap(); + cx.resources.led.set_high(); *cx.resources.led_state = false; } else { - cx.resources.led.set_low().unwrap(); + cx.resources.led.set_low(); *cx.resources.led_state = true; } *COUNT += 1; diff --git a/examples/usb_serial.rs b/examples/usb_serial.rs index d4c53221..3972de44 100644 --- a/examples/usb_serial.rs +++ b/examples/usb_serial.rs @@ -13,9 +13,8 @@ extern crate panic_semihosting; use cortex_m::asm::delay; use cortex_m_rt::entry; -use embedded_hal::digital::v2::OutputPin; use stm32f1xx_hal::usb::{Peripheral, UsbBus}; -use stm32f1xx_hal::{prelude::*, stm32}; +use stm32f1xx_hal::{pac, prelude::*}; use usb_device::prelude::*; use usbd_serial::{SerialPort, USB_CLASS_CDC}; diff --git a/examples/usb_serial_interrupt.rs b/examples/usb_serial_interrupt.rs index 54e61f0b..2674176b 100644 --- a/examples/usb_serial_interrupt.rs +++ b/examples/usb_serial_interrupt.rs @@ -7,8 +7,7 @@ extern crate panic_semihosting; use cortex_m::asm::{delay, wfi}; use cortex_m_rt::entry; -use embedded_hal::digital::v2::OutputPin; -use stm32f1xx_hal::pac::{interrupt, Interrupt}; +use stm32f1xx_hal::pac::{self, interrupt, Interrupt}; use stm32f1xx_hal::usb::{Peripheral, UsbBus, UsbBusType}; use stm32f1xx_hal::{prelude::*, stm32}; use usb_device::{bus::UsbBusAllocator, prelude::*}; diff --git a/examples/usb_serial_rtic.rs b/examples/usb_serial_rtic.rs index 5735b815..ac0dc2da 100644 --- a/examples/usb_serial_rtic.rs +++ b/examples/usb_serial_rtic.rs @@ -7,7 +7,6 @@ extern crate panic_semihosting; use cortex_m::asm::delay; -use embedded_hal::digital::v2::OutputPin; use rtic::app; use stm32f1xx_hal::prelude::*; use stm32f1xx_hal::usb::{Peripheral, UsbBus, UsbBusType}; @@ -45,7 +44,7 @@ const APP: () = { // This forced reset is needed only for development, without it host // will not reset your device when you upload new firmware. let mut usb_dp = gpioa.pa12.into_push_pull_output(&mut gpioa.crh); - usb_dp.set_low().unwrap(); + usb_dp.set_low(); delay(clocks.sysclk().0 / 100); let usb_dm = gpioa.pa11; diff --git a/src/gpio.rs b/src/gpio.rs index 918330eb..92b0de4f 100644 --- a/src/gpio.rs +++ b/src/gpio.rs @@ -74,6 +74,84 @@ //! let mut mfrc522 = Mfrc522::new(spi, OldOutputPin::from(nss)).unwrap(); //! ``` +mod infallible { + use core::convert::Infallible; + use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin}; + pub trait OutputPinInfallible: OutputPin { + fn set_low(&mut self); + fn set_high(&mut self); + } + + pub trait StatefulOutputPinInfallible: + StatefulOutputPin + OutputPin + { + fn is_set_low(&self) -> bool; + fn is_set_high(&self) -> bool; + } + + pub trait InputPinInfallible: InputPin { + fn is_low(&self) -> bool; + fn is_high(&self) -> bool; + } + + pub trait ToggleableOutputPinInfallible: ToggleableOutputPin { + fn toggle(&mut self); + } + + impl OutputPinInfallible for T + where + T: OutputPin, + { + #[inline(always)] + fn set_low(&mut self) { + ::set_low(self).unwrap() + } + #[inline(always)] + fn set_high(&mut self) { + ::set_high(self).unwrap() + } + } + + impl StatefulOutputPinInfallible for T + where + T: StatefulOutputPin + OutputPin, + { + #[inline(always)] + fn is_set_low(&self) -> bool { + ::is_set_low(self).unwrap() + } + #[inline(always)] + fn is_set_high(&self) -> bool { + ::is_set_high(self).unwrap() + } + } + + impl InputPinInfallible for T + where + T: InputPin, + { + #[inline(always)] + fn is_low(&self) -> bool { + ::is_low(self).unwrap() + } + #[inline(always)] + fn is_high(&self) -> bool { + ::is_high(self).unwrap() + } + } + + impl ToggleableOutputPinInfallible for T + where + T: ToggleableOutputPin, + { + #[inline(always)] + fn toggle(&mut self) { + ::toggle(self).unwrap() + } + } +} +pub use infallible::*; + use core::marker::PhantomData; use crate::afio; @@ -1133,13 +1211,13 @@ macro_rules! impl_pxx { type Error = Infallible; fn set_high(&mut self) -> Result<(), Infallible> { match self { - $(Pxx::$pin(pin) => pin.set_high()),* + $(Pxx::$pin(pin) => OutputPin::set_high(pin)),* } } fn set_low(&mut self) -> Result<(), Infallible> { match self { - $(Pxx::$pin(pin) => pin.set_low()),* + $(Pxx::$pin(pin) => OutputPin::set_low(pin)),* } } } @@ -1147,13 +1225,13 @@ macro_rules! impl_pxx { impl StatefulOutputPin for Pxx> { fn is_set_high(&self) -> Result { match self { - $(Pxx::$pin(pin) => pin.is_set_high()),* + $(Pxx::$pin(pin) => StatefulOutputPin::is_set_high(pin)),* } } fn is_set_low(&self) -> Result { match self { - $(Pxx::$pin(pin) => pin.is_set_low()),* + $(Pxx::$pin(pin) => StatefulOutputPin::is_set_low(pin)),* } } } @@ -1162,13 +1240,13 @@ macro_rules! impl_pxx { type Error = Infallible; fn is_high(&self) -> Result { match self { - $(Pxx::$pin(pin) => pin.is_high()),* + $(Pxx::$pin(pin) => InputPin::is_high(pin)),* } } fn is_low(&self) -> Result { match self { - $(Pxx::$pin(pin) => pin.is_low()),* + $(Pxx::$pin(pin) => InputPin::is_low(pin)),* } } } @@ -1177,13 +1255,13 @@ macro_rules! impl_pxx { type Error = Infallible; fn is_high(&self) -> Result { match self { - $(Pxx::$pin(pin) => pin.is_high()),* + $(Pxx::$pin(pin) => InputPin::is_high(pin)),* } } fn is_low(&self) -> Result { match self { - $(Pxx::$pin(pin) => pin.is_low()),* + $(Pxx::$pin(pin) => InputPin::is_low(pin)),* } } } diff --git a/src/prelude.rs b/src/prelude.rs index ff349473..ae649293 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -7,9 +7,33 @@ pub use crate::dma::ReadDma as _stm32_hal_dma_ReadDma; pub use crate::dma::WriteDma as _stm32_hal_dma_WriteDma; pub use crate::flash::FlashExt as _stm32_hal_flash_FlashExt; pub use crate::gpio::GpioExt as _stm32_hal_gpio_GpioExt; -pub use crate::hal::adc::OneShot as _embedded_hal_adc_OneShot; -pub use crate::hal::digital::v2::StatefulOutputPin as _embedded_hal_digital_StatefulOutputPin; -pub use crate::hal::digital::v2::ToggleableOutputPin as _embedded_hal_digital_ToggleableOutputPin; -pub use crate::hal::prelude::*; +pub use crate::gpio::InputPinInfallible as _stm32_hal_gpio_InputPinInfallible; +pub use crate::gpio::OutputPinInfallible as _stm32_hal_gpio_OutputPinInfallible; +pub use crate::gpio::StatefulOutputPinInfallible as _stm32_hal_gpio_StatefulOutputPinInfallible; +pub use crate::gpio::ToggleableOutputPinInfallible as _stm32_hal_gpio_ToggleableOutputPinInfallible; pub use crate::rcc::RccExt as _stm32_hal_rcc_RccExt; pub use crate::time::U32Ext as _stm32_hal_time_U32Ext; + +pub use crate::hal::adc::OneShot as _embedded_hal_adc_OneShot; +pub use crate::hal::blocking::delay::DelayMs as _embedded_hal_blocking_delay_DelayMs; +pub use crate::hal::blocking::delay::DelayUs as _embedded_hal_blocking_delay_DelayUs; +pub use crate::hal::blocking::i2c::{ + Read as _embedded_hal_blocking_i2c_Read, Write as _embedded_hal_blocking_i2c_Write, + WriteRead as _embedded_hal_blocking_i2c_WriteRead, +}; +pub use crate::hal::blocking::rng::Read as _embedded_hal_blocking_rng_Read; +pub use crate::hal::blocking::serial::Write as _embedded_hal_blocking_serial_Write; +pub use crate::hal::blocking::spi::{ + Transfer as _embedded_hal_blocking_spi_Transfer, Write as _embedded_hal_blocking_spi_Write, +}; +pub use crate::hal::serial::Read as _embedded_hal_serial_Read; +pub use crate::hal::serial::Write as _embedded_hal_serial_Write; +pub use crate::hal::spi::FullDuplex as _embedded_hal_spi_FullDuplex; +pub use crate::hal::timer::CountDown as _embedded_hal_timer_CountDown; +pub use crate::hal::watchdog::Watchdog as _embedded_hal_watchdog_Watchdog; +pub use crate::hal::watchdog::WatchdogDisable as _embedded_hal_watchdog_WatchdogDisable; +pub use crate::hal::watchdog::WatchdogEnable as _embedded_hal_watchdog_WatchdogEnable; +pub use crate::hal::Capture as _embedded_hal_Capture; +pub use crate::hal::Pwm as _embedded_hal_Pwm; +pub use crate::hal::PwmPin as _embedded_hal_PwmPin; +pub use crate::hal::Qei as _embedded_hal_Qei; From 7f9cb685bf363e52315ce2ef2bf08396294f0714 Mon Sep 17 00:00:00 2001 From: Andrey Zgarbul Date: Thu, 10 Jun 2021 12:09:12 +0300 Subject: [PATCH 2/2] don't reexport --- CHANGELOG.md | 2 +- examples/blinky.rs | 2 +- examples/blinky_generic.rs | 2 +- examples/blinky_rtc.rs | 2 +- examples/blinky_rtcalarm_irq.rs | 2 +- examples/blinky_timer_irq.rs | 2 +- examples/can-loopback.rs | 2 +- examples/delay.rs | 2 +- examples/exti.rs | 2 +- examples/led.rs | 2 +- examples/mfrc522.rs | 2 +- examples/multi_mode_gpio.rs | 7 ++++++- examples/nojtag.rs | 2 +- examples/timer-interrupt-rtic.rs | 1 + examples/usb_serial.rs | 8 ++++++-- examples/usb_serial_interrupt.rs | 9 ++++++--- examples/usb_serial_rtic.rs | 7 +++++-- src/gpio.rs | 3 +-- src/prelude.rs | 4 ---- 19 files changed, 37 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f972d6a..dd7ffde6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added - `InputPin`, `OutputPin`, `StatefulOutputPin`, `ToggleableOutputPin` traits. - Add them to prelude instead of `embedded_hal`'s + Remove `embedded_hal` gpio traits from prelude. - Support for OpenDrain pin configuration on SPI CLK and MOSI pins - LSB/MSB bit format selection for `SPI` - Support for CAN peripherals with the `bxcan` crate diff --git a/examples/blinky.rs b/examples/blinky.rs index 353d5eb6..21a52fa5 100644 --- a/examples/blinky.rs +++ b/examples/blinky.rs @@ -14,7 +14,7 @@ use panic_halt as _; use nb::block; use cortex_m_rt::entry; -use stm32f1xx_hal::{pac, prelude::*, timer::Timer}; +use stm32f1xx_hal::{gpio::infallible::*, pac, prelude::*, timer::Timer}; #[entry] fn main() -> ! { diff --git a/examples/blinky_generic.rs b/examples/blinky_generic.rs index 1a3f1cea..446cbacb 100644 --- a/examples/blinky_generic.rs +++ b/examples/blinky_generic.rs @@ -9,7 +9,7 @@ use panic_halt as _; use nb::block; use cortex_m_rt::entry; -use stm32f1xx_hal::{pac, prelude::*, timer::Timer}; +use stm32f1xx_hal::{gpio::infallible::*, pac, prelude::*, timer::Timer}; #[entry] fn main() -> ! { diff --git a/examples/blinky_rtc.rs b/examples/blinky_rtc.rs index d23c01a0..f44f6cc8 100644 --- a/examples/blinky_rtc.rs +++ b/examples/blinky_rtc.rs @@ -12,7 +12,7 @@ use panic_halt as _; -use stm32f1xx_hal::{pac, prelude::*, rtc::Rtc}; +use stm32f1xx_hal::{gpio::infallible::*, pac, prelude::*, rtc::Rtc}; use cortex_m_rt::entry; use nb::block; diff --git a/examples/blinky_rtcalarm_irq.rs b/examples/blinky_rtcalarm_irq.rs index 4c263086..650d87a1 100644 --- a/examples/blinky_rtcalarm_irq.rs +++ b/examples/blinky_rtcalarm_irq.rs @@ -15,7 +15,7 @@ use panic_halt as _; use stm32f1xx_hal as hal; use crate::hal::{ - gpio::{gpioc, Output, PushPull}, + gpio::{gpioc, infallible::*, Output, PushPull}, pac::{interrupt, Interrupt, Peripherals, EXTI}, prelude::*, rtc::Rtc, diff --git a/examples/blinky_timer_irq.rs b/examples/blinky_timer_irq.rs index 0c0c0a6c..0f33077e 100644 --- a/examples/blinky_timer_irq.rs +++ b/examples/blinky_timer_irq.rs @@ -15,7 +15,7 @@ use panic_halt as _; use stm32f1xx_hal as hal; use crate::hal::{ - gpio::{gpioc, Output, PushPull}, + gpio::{gpioc, infallible::*, Output, PushPull}, pac::{interrupt, Interrupt, Peripherals, TIM2}, prelude::*, timer::{CountDownTimer, Event, Timer}, diff --git a/examples/can-loopback.rs b/examples/can-loopback.rs index e13c0ea3..4f9684b2 100644 --- a/examples/can-loopback.rs +++ b/examples/can-loopback.rs @@ -12,7 +12,7 @@ use panic_halt as _; use cortex_m_rt::entry; use nb::block; -use stm32f1xx_hal::{can::Can, pac, prelude::*}; +use stm32f1xx_hal::{can::Can, gpio::infallible::*, pac, prelude::*}; #[entry] fn main() -> ! { diff --git a/examples/delay.rs b/examples/delay.rs index 073e1d0d..1132cb56 100644 --- a/examples/delay.rs +++ b/examples/delay.rs @@ -7,7 +7,7 @@ use panic_halt as _; use cortex_m_rt::entry; -use stm32f1xx_hal::{delay::Delay, pac, prelude::*}; +use stm32f1xx_hal::{delay::Delay, gpio::infallible::*, pac, prelude::*}; #[entry] fn main() -> ! { diff --git a/examples/exti.rs b/examples/exti.rs index abad4b8f..4b2eb3a2 100644 --- a/examples/exti.rs +++ b/examples/exti.rs @@ -12,7 +12,7 @@ use core::mem::MaybeUninit; use cortex_m_rt::entry; use pac::interrupt; use stm32f1xx_hal::gpio::*; -use stm32f1xx_hal::{pac, prelude::*}; +use stm32f1xx_hal::{gpio::infallible::*, pac, prelude::*}; // These two are owned by the ISR. main() may only access them during the initialization phase, // where the interrupt is not yet enabled (i.e. no concurrent accesses can occur). diff --git a/examples/led.rs b/examples/led.rs index 86c995bc..92542687 100644 --- a/examples/led.rs +++ b/examples/led.rs @@ -16,7 +16,7 @@ use panic_halt as _; use cortex_m_rt::entry; -use stm32f1xx_hal::{pac, prelude::*}; +use stm32f1xx_hal::{gpio::infallible::*, pac, prelude::*}; #[entry] fn main() -> ! { diff --git a/examples/mfrc522.rs b/examples/mfrc522.rs index 9f1fa81e..44d15bc6 100644 --- a/examples/mfrc522.rs +++ b/examples/mfrc522.rs @@ -9,7 +9,7 @@ use cortex_m::iprintln; use cortex_m_rt::entry; use embedded_hal::digital::v1_compat::OldOutputPin; use mfrc522::Mfrc522; -use stm32f1xx_hal::{pac, prelude::*, spi::Spi}; +use stm32f1xx_hal::{gpio::infallible::*, pac, prelude::*, spi::Spi}; #[entry] fn main() -> ! { diff --git a/examples/multi_mode_gpio.rs b/examples/multi_mode_gpio.rs index 8df080f3..2c004e76 100644 --- a/examples/multi_mode_gpio.rs +++ b/examples/multi_mode_gpio.rs @@ -8,7 +8,12 @@ use nb::block; use cortex_m_rt::entry; use cortex_m_semihosting::hprintln; -use stm32f1xx_hal::{gpio::State, pac, prelude::*, timer::Timer}; +use stm32f1xx_hal::{ + gpio::{infallible::*, State}, + pac, + prelude::*, + timer::Timer, +}; #[entry] fn main() -> ! { diff --git a/examples/nojtag.rs b/examples/nojtag.rs index d66167d6..48672c59 100644 --- a/examples/nojtag.rs +++ b/examples/nojtag.rs @@ -7,7 +7,7 @@ use panic_halt as _; use cortex_m_rt::entry; -use stm32f1xx_hal::{pac, prelude::*}; +use stm32f1xx_hal::{gpio::infallible::*, pac, prelude::*}; #[entry] fn main() -> ! { diff --git a/examples/timer-interrupt-rtic.rs b/examples/timer-interrupt-rtic.rs index 5068b4c2..4714bbb9 100644 --- a/examples/timer-interrupt-rtic.rs +++ b/examples/timer-interrupt-rtic.rs @@ -14,6 +14,7 @@ use panic_halt as _; use rtic::app; use stm32f1xx_hal::{ + gpio::infallible::*, gpio::{gpioc::PC13, Output, PushPull, State}, pac, prelude::*, diff --git a/examples/usb_serial.rs b/examples/usb_serial.rs index 3972de44..08e9e1b3 100644 --- a/examples/usb_serial.rs +++ b/examples/usb_serial.rs @@ -13,8 +13,12 @@ extern crate panic_semihosting; use cortex_m::asm::delay; use cortex_m_rt::entry; -use stm32f1xx_hal::usb::{Peripheral, UsbBus}; -use stm32f1xx_hal::{pac, prelude::*}; +use stm32f1xx_hal::{ + gpio::infallible::*, + pac, + prelude::*, + usb::{Peripheral, UsbBus}, +}; use usb_device::prelude::*; use usbd_serial::{SerialPort, USB_CLASS_CDC}; diff --git a/examples/usb_serial_interrupt.rs b/examples/usb_serial_interrupt.rs index 2674176b..29b84db8 100644 --- a/examples/usb_serial_interrupt.rs +++ b/examples/usb_serial_interrupt.rs @@ -7,9 +7,12 @@ extern crate panic_semihosting; use cortex_m::asm::{delay, wfi}; use cortex_m_rt::entry; -use stm32f1xx_hal::pac::{self, interrupt, Interrupt}; -use stm32f1xx_hal::usb::{Peripheral, UsbBus, UsbBusType}; -use stm32f1xx_hal::{prelude::*, stm32}; +use stm32f1xx_hal::{ + gpio::infallible::*, + pac::{self, interrupt, Interrupt}, + prelude::*, + usb::{Peripheral, UsbBus, UsbBusType}, +}; use usb_device::{bus::UsbBusAllocator, prelude::*}; use usbd_serial::{SerialPort, USB_CLASS_CDC}; diff --git a/examples/usb_serial_rtic.rs b/examples/usb_serial_rtic.rs index ac0dc2da..b507d95d 100644 --- a/examples/usb_serial_rtic.rs +++ b/examples/usb_serial_rtic.rs @@ -8,8 +8,11 @@ extern crate panic_semihosting; use cortex_m::asm::delay; use rtic::app; -use stm32f1xx_hal::prelude::*; -use stm32f1xx_hal::usb::{Peripheral, UsbBus, UsbBusType}; +use stm32f1xx_hal::{ + gpio::infallible::*, + prelude::*, + usb::{Peripheral, UsbBus, UsbBusType}, +}; use usb_device::bus; use usb_device::prelude::*; use usbd_serial::{SerialPort, USB_CLASS_CDC}; diff --git a/src/gpio.rs b/src/gpio.rs index 92b0de4f..c62b1f06 100644 --- a/src/gpio.rs +++ b/src/gpio.rs @@ -74,7 +74,7 @@ //! let mut mfrc522 = Mfrc522::new(spi, OldOutputPin::from(nss)).unwrap(); //! ``` -mod infallible { +pub mod infallible { use core::convert::Infallible; use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin}; pub trait OutputPinInfallible: OutputPin { @@ -150,7 +150,6 @@ mod infallible { } } } -pub use infallible::*; use core::marker::PhantomData; diff --git a/src/prelude.rs b/src/prelude.rs index ae649293..9fa9b7ae 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -7,10 +7,6 @@ pub use crate::dma::ReadDma as _stm32_hal_dma_ReadDma; pub use crate::dma::WriteDma as _stm32_hal_dma_WriteDma; pub use crate::flash::FlashExt as _stm32_hal_flash_FlashExt; pub use crate::gpio::GpioExt as _stm32_hal_gpio_GpioExt; -pub use crate::gpio::InputPinInfallible as _stm32_hal_gpio_InputPinInfallible; -pub use crate::gpio::OutputPinInfallible as _stm32_hal_gpio_OutputPinInfallible; -pub use crate::gpio::StatefulOutputPinInfallible as _stm32_hal_gpio_StatefulOutputPinInfallible; -pub use crate::gpio::ToggleableOutputPinInfallible as _stm32_hal_gpio_ToggleableOutputPinInfallible; pub use crate::rcc::RccExt as _stm32_hal_rcc_RccExt; pub use crate::time::U32Ext as _stm32_hal_time_U32Ext;