Skip to content

Commit

Permalink
generic: port: Implement embedded-hal OutputPin trait
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcuss2 authored Jul 22, 2021
1 parent ca93b59 commit 2996b4a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions avr-hal-generic/src/port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! Please take a look at the documentation for [`Pin`] for a detailed explanation.
use core::marker::PhantomData;
use embedded_hal::digital::v2::OutputPin;

pub trait PinMode: crate::Sealed {}
/// GPIO pin modes
Expand Down Expand Up @@ -284,6 +285,21 @@ impl<PIN: PinOps> Pin<mode::Output, PIN> {
}
}

// Implements OutputPin from embedded-hal to make sure external libraries work
impl<PIN: PinOps> OutputPin for Pin<mode::Output, PIN> {
type Error = core::convert::Infallible;

fn set_high(&mut self) -> Result<(), Self::Error> {
self.set_high();
Ok(())
}

fn set_low(&mut self) -> Result<(), Self::Error> {
self.set_low();
Ok(())
}
}

/// # Digital Input
impl<PIN: PinOps, IMODE: mode::InputMode> Pin<mode::Input<IMODE>, PIN> {
/// Check whether the pin is driven high.
Expand Down

0 comments on commit 2996b4a

Please sign in to comment.