Merge pull request #779 from danbev/embassy-rp-toggleable-output-impl

Impl ToggleableOutputPin for embassy-rp Output
This commit is contained in:
Dario Nieuwenhuis 2022-05-19 07:12:43 +02:00 committed by GitHub
commit 220c6c83cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -131,6 +131,15 @@ impl<'d, T: Pin> Output<'d, T> {
let val = 1 << self.pin.pin();
unsafe { (self.pin.sio_out().value().read() & val) == 0 }
}
/// Toggle pin output
#[inline]
pub fn toggle(&mut self) {
let val = 1 << self.pin.pin();
unsafe {
self.pin.sio_out().value_xor().write_value(val);
}
}
}
impl<'d, T: Pin> Drop for Output<'d, T> {
@ -295,6 +304,14 @@ mod eh02 {
Ok(self.is_set_low())
}
}
impl<'d, T: Pin> embedded_hal_02::digital::v2::ToggleableOutputPin for Output<'d, T> {
type Error = Infallible;
#[inline]
fn toggle(&mut self) -> Result<(), Self::Error> {
Ok(self.toggle())
}
}
}
#[cfg(feature = "unstable-traits")]