Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/digital/v2_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ where
}
}

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

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

#[allow(deprecated)]
impl v1::StatefulOutputPin for OldOutputPinImpl {
fn is_set_low(&self) -> bool {
self.state == false
}

fn is_set_high(&self) -> bool {
self.state == true
}
}

#[allow(deprecated)]
impl v1::toggleable::Default for OldOutputPinImpl {}

struct NewOutputPinConsumer<T: v2::OutputPin> {
_pin: T,
}
Expand All @@ -92,6 +109,25 @@ mod tests {
}
}

struct NewToggleablePinConsumer<T: v2::ToggleableOutputPin> {
_pin: T,
}

impl<T> NewToggleablePinConsumer<T>
where
T: v2::ToggleableOutputPin,
{
pub fn new(pin: T) -> NewToggleablePinConsumer<T> {
NewToggleablePinConsumer { _pin: pin }
}
}

#[test]
fn v2_v1_toggleable_implicit() {
let i = OldOutputPinImpl { state: false };
let _c = NewToggleablePinConsumer::new(i);
}

#[test]
fn v2_v1_output_implicit() {
let i = OldOutputPinImpl{state: false};
Expand Down