Skip to content

Commit 4ecf7df

Browse files
committed
more IoPin cleanups
1 parent cf1eace commit 4ecf7df

File tree

2 files changed

+24
-52
lines changed

2 files changed

+24
-52
lines changed

src/gpio/hal_02.rs

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use core::convert::Infallible;
22

33
use super::{
44
dynamic::PinModeError, DynamicPin, ErasedPin, Input, OpenDrain, Output, PartiallyErasedPin,
5-
Pin, PinState, PushPull,
5+
Pin, PinMode, PinState,
66
};
77

88
use embedded_hal::digital::v2::{
@@ -88,7 +88,10 @@ impl<const P: char, const N: u8> IoPin<Self, Self> for Pin<P, N, Output<OpenDrai
8888
}
8989
}
9090

91-
impl<const P: char, const N: u8> IoPin<Pin<P, N, Input>, Self> for Pin<P, N, Output<OpenDrain>> {
91+
impl<const P: char, const N: u8, Otype> IoPin<Pin<P, N, Input>, Self> for Pin<P, N, Output<Otype>>
92+
where
93+
Output<Otype>: PinMode,
94+
{
9295
type Error = Infallible;
9396
fn into_input_pin(self) -> Result<Pin<P, N, Input>, Self::Error> {
9497
Ok(self.into_input())
@@ -99,34 +102,17 @@ impl<const P: char, const N: u8> IoPin<Pin<P, N, Input>, Self> for Pin<P, N, Out
99102
}
100103
}
101104

102-
impl<const P: char, const N: u8> IoPin<Self, Pin<P, N, Output<OpenDrain>>> for Pin<P, N, Input> {
105+
impl<const P: char, const N: u8, Otype> IoPin<Self, Pin<P, N, Output<Otype>>> for Pin<P, N, Input>
106+
where
107+
Output<Otype>: PinMode,
108+
{
103109
type Error = Infallible;
104110
fn into_input_pin(self) -> Result<Self, Self::Error> {
105111
Ok(self)
106112
}
107-
fn into_output_pin(self, state: PinState) -> Result<Pin<P, N, Output<OpenDrain>>, Self::Error> {
108-
Ok(self.into_open_drain_output_in_state(state))
109-
}
110-
}
111-
112-
impl<const P: char, const N: u8> IoPin<Pin<P, N, Input>, Self> for Pin<P, N, Output<PushPull>> {
113-
type Error = Infallible;
114-
fn into_input_pin(self) -> Result<Pin<P, N, Input>, Self::Error> {
115-
Ok(self.into_input())
116-
}
117-
fn into_output_pin(mut self, state: PinState) -> Result<Self, Self::Error> {
118-
self.set_state(state);
119-
Ok(self)
120-
}
121-
}
122-
123-
impl<const P: char, const N: u8> IoPin<Self, Pin<P, N, Output<PushPull>>> for Pin<P, N, Input> {
124-
type Error = Infallible;
125-
fn into_input_pin(self) -> Result<Self, Self::Error> {
126-
Ok(self)
127-
}
128-
fn into_output_pin(self, state: PinState) -> Result<Pin<P, N, Output<PushPull>>, Self::Error> {
129-
Ok(self.into_push_pull_output_in_state(state))
113+
fn into_output_pin(mut self, state: PinState) -> Result<Pin<P, N, Output<Otype>>, Self::Error> {
114+
self._set_state(state);
115+
Ok(self.into_mode())
130116
}
131117
}
132118

src/gpio/hal_1.rs

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use core::convert::Infallible;
22

3-
use super::{ErasedPin, Input, OpenDrain, Output, PartiallyErasedPin, Pin, PushPull};
3+
use super::{ErasedPin, Input, OpenDrain, Output, PartiallyErasedPin, Pin, PinMode};
44

55
pub use embedded_hal_one::digital::PinState;
66
use embedded_hal_one::digital::{
@@ -89,7 +89,10 @@ impl<const P: char, const N: u8> IoPin<Self, Self> for Pin<P, N, Output<OpenDrai
8989
}
9090
}
9191

92-
impl<const P: char, const N: u8> IoPin<Pin<P, N, Input>, Self> for Pin<P, N, Output<OpenDrain>> {
92+
impl<const P: char, const N: u8, Otype> IoPin<Pin<P, N, Input>, Self> for Pin<P, N, Output<Otype>>
93+
where
94+
Output<Otype>: PinMode,
95+
{
9396
type Error = Infallible;
9497
fn into_input_pin(self) -> Result<Pin<P, N, Input>, Self::Error> {
9598
Ok(self.into_input())
@@ -100,34 +103,17 @@ impl<const P: char, const N: u8> IoPin<Pin<P, N, Input>, Self> for Pin<P, N, Out
100103
}
101104
}
102105

103-
impl<const P: char, const N: u8> IoPin<Self, Pin<P, N, Output<OpenDrain>>> for Pin<P, N, Input> {
106+
impl<const P: char, const N: u8, Otype> IoPin<Self, Pin<P, N, Output<Otype>>> for Pin<P, N, Input>
107+
where
108+
Output<Otype>: PinMode,
109+
{
104110
type Error = Infallible;
105111
fn into_input_pin(self) -> Result<Self, Self::Error> {
106112
Ok(self)
107113
}
108-
fn into_output_pin(self, state: PinState) -> Result<Pin<P, N, Output<OpenDrain>>, Self::Error> {
109-
Ok(self.into_open_drain_output_in_state(into_state(state)))
110-
}
111-
}
112-
113-
impl<const P: char, const N: u8> IoPin<Pin<P, N, Input>, Self> for Pin<P, N, Output<PushPull>> {
114-
type Error = Infallible;
115-
fn into_input_pin(self) -> Result<Pin<P, N, Input>, Self::Error> {
116-
Ok(self.into_input())
117-
}
118-
fn into_output_pin(mut self, state: PinState) -> Result<Self, Self::Error> {
119-
self.set_state(into_state(state));
120-
Ok(self)
121-
}
122-
}
123-
124-
impl<const P: char, const N: u8> IoPin<Self, Pin<P, N, Output<PushPull>>> for Pin<P, N, Input> {
125-
type Error = Infallible;
126-
fn into_input_pin(self) -> Result<Self, Self::Error> {
127-
Ok(self)
128-
}
129-
fn into_output_pin(self, state: PinState) -> Result<Pin<P, N, Output<PushPull>>, Self::Error> {
130-
Ok(self.into_push_pull_output_in_state(into_state(state)))
114+
fn into_output_pin(mut self, state: PinState) -> Result<Pin<P, N, Output<Otype>>, Self::Error> {
115+
self._set_state(into_state(state));
116+
Ok(self.into_mode())
131117
}
132118
}
133119

0 commit comments

Comments
 (0)