diff --git a/CHANGELOG.md b/CHANGELOG.md index 4162be2fb..513561b1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Added + +- Implement `InputPin` for `Output` pins ([#114](https://github.com/stm32-rs/stm32f3xx-hal/pull/114)) + ### Fixed - `PLL` was calculated wrong for devices, which do not divide `HSI` ([#67](https://github.com/stm32-rs/stm32f3xx-hal/pull/67)) @@ -28,7 +32,7 @@ let clocks = rcc .use_hse(32.mhz()) .sysclk(72.mhz()) ``` - This is possible through utilizing the divider, which can devide the + This is possible through utilizing the divider, which can divide the external oscillator clock on most devices. Some devices have even the possibility to divide the internal oscillator clock. diff --git a/src/gpio.rs b/src/gpio.rs index 1dd43ab62..4516645ae 100644 --- a/src/gpio.rs +++ b/src/gpio.rs @@ -206,6 +206,31 @@ macro_rules! gpio { } } + #[cfg(feature = "unproven")] + impl InputPin for PXx> { + type Error = Infallible; + + fn is_high(&self) -> Result { + Ok(!self.is_low()?) + } + + fn is_low(&self) -> Result { + // NOTE(unsafe) atomic read with no side effects + Ok(unsafe { + match &self.gpio { + $( + #[cfg(all(any( + $(feature = $device,)+ + ), not(any( + $(feature = $device_except,)* + ))))] + Gpio::$GPIOX => (*$GPIOX::ptr()).idr.read().bits() & (1 << self.i) == 0, + )+ + } + }) + } + } + #[cfg(feature = "unproven")] impl StatefulOutputPin for PXx> { fn is_set_high(&self) -> Result { @@ -412,6 +437,20 @@ macro_rules! gpio { } } + #[cfg(feature = "unproven")] + impl InputPin for $PXx> { + type Error = Infallible; + + fn is_high(&self) -> Result { + Ok(!self.is_low()?) + } + + fn is_low(&self) -> Result { + // NOTE(unsafe) atomic read with no side effects + Ok(unsafe { (*$GPIOX::ptr()).idr.read().bits() & (1 << self.i) == 0 }) + } + } + #[cfg(feature = "unproven")] impl StatefulOutputPin for $PXx> { fn is_set_high(&self) -> Result { @@ -598,6 +637,20 @@ macro_rules! gpio { } } + #[cfg(feature = "unproven")] + impl InputPin for $PXi> { + type Error = Infallible; + + fn is_high(&self) -> Result { + Ok(!self.is_low()?) + } + + fn is_low(&self) -> Result { + // NOTE(unsafe) atomic read with no side effects + Ok(unsafe { (*$GPIOX::ptr()).idr.read().$idri().is_low()}) + } + } + #[cfg(feature = "unproven")] impl StatefulOutputPin for $PXi> { fn is_set_high(&self) -> Result {