Skip to content

Commit 820c5e4

Browse files
Merge #138
138: Provide v2_compat for ToggleableOutputPin r=ryankurte a=little-arhat fixes #137 Co-authored-by: Roma Sokolov <[email protected]>
2 parents 9e6ab5a + 3746b22 commit 820c5e4

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/digital/v2_compat.rs

+36
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ where
3939
}
4040
}
4141

42+
#[cfg(feature = "unproven")]
43+
#[allow(deprecated)]
44+
impl<T> v2::toggleable::Default for T where T: v1::toggleable::Default {}
4245

4346
/// Implementation of fallible `v2::InputPin` for `v1::InputPin` digital traits
4447
#[cfg(feature = "unproven")]
@@ -81,6 +84,20 @@ mod tests {
8184
}
8285
}
8386

87+
#[allow(deprecated)]
88+
impl v1::StatefulOutputPin for OldOutputPinImpl {
89+
fn is_set_low(&mut self) -> bool {
90+
self.state == false
91+
}
92+
93+
fn is_set_high(&mut self) -> bool {
94+
self.state == true
95+
}
96+
}
97+
98+
#[allow(deprecated)]
99+
impl v1::toggleable::Default for OldOutputPinImpl {}
100+
84101
struct NewOutputPinConsumer<T: v2::OutputPin> {
85102
_pin: T,
86103
}
@@ -92,6 +109,25 @@ mod tests {
92109
}
93110
}
94111

112+
struct NewToggleablePinConsumer<T: v2::ToggleableOutputPin> {
113+
_pin: T,
114+
}
115+
116+
impl<T> NewToggleablePinConsumer<T>
117+
where
118+
T: v2::OutputPin,
119+
{
120+
pub fn new(pin: T) -> NewToggleablePinConsumer<T> {
121+
NewToggleablePinConsumer { _pin: pin }
122+
}
123+
}
124+
125+
#[test]
126+
fn v2_v1_toggleable_implicit() {
127+
let i = OldOutputPinImpl { state: false };
128+
let _c = NewToggleablePinConsumer::new(i);
129+
}
130+
95131
#[test]
96132
fn v2_v1_output_implicit() {
97133
let i = OldOutputPinImpl{state: false};

0 commit comments

Comments
 (0)