Skip to content

Commit b3cbeda

Browse files
committed
implement IoPin
1 parent ab2854f commit b3cbeda

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

src/gpio.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ macro_rules! gpio {
145145
pub mod $gpiox {
146146
use core::marker::PhantomData;
147147

148-
use embedded_hal::digital::v2::{InputPin, OutputPin,
148+
use embedded_hal::digital::v2::{InputPin, OutputPin, IoPin, PinState,
149149
StatefulOutputPin, toggleable};
150150

151151
use crate::rcc::{rec, ResetEnable};
@@ -761,6 +761,46 @@ macro_rules! gpio {
761761
}
762762
}
763763

764+
impl IoPin<Self, Self>
765+
for $PXi<Output<OpenDrain>>
766+
{
767+
type Error = Never;
768+
fn into_input_pin(self) -> Result<Self, Self::Error> {
769+
Ok(self)
770+
}
771+
fn into_output_pin(mut self, state: PinState) -> Result<Self, Self::Error> {
772+
self.set_state(state)?;
773+
Ok(self)
774+
}
775+
}
776+
777+
impl IoPin<$PXi<Input<Floating>>, Self>
778+
for $PXi<Output<PushPull>>
779+
{
780+
type Error = Never;
781+
fn into_input_pin(self) -> Result<$PXi<Input<Floating>>, Self::Error> {
782+
Ok(self.into_floating_input())
783+
}
784+
fn into_output_pin(mut self, state: PinState) -> Result<Self, Self::Error> {
785+
self.set_state(state)?;
786+
Ok(self)
787+
}
788+
}
789+
790+
impl IoPin<Self, $PXi<Output<PushPull>>>
791+
for $PXi<Input<Floating>>
792+
{
793+
type Error = Never;
794+
fn into_input_pin(self) -> Result<Self, Self::Error> {
795+
Ok(self)
796+
}
797+
fn into_output_pin(self, state: PinState) -> Result<$PXi<Output<PushPull>>, Self::Error> {
798+
let mut pin = self.into_push_pull_output();
799+
pin.set_state(state)?;
800+
Ok(pin)
801+
}
802+
}
803+
764804
impl<MODE> ExtiPin for $PXi<Input<MODE>> {
765805
/// Configure EXTI Line $i to trigger from this pin.
766806
fn make_interrupt_source(&mut self, syscfg: &mut SYSCFG) {

0 commit comments

Comments
 (0)