From da979443226260e5e4b63560337980556f046159 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Thu, 19 May 2022 05:33:42 +0200 Subject: [PATCH] Impl ToggleableOutputPin for embassy-rp Output --- embassy-rp/src/gpio.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs index 28dfce47..596dd64c 100644 --- a/embassy-rp/src/gpio.rs +++ b/embassy-rp/src/gpio.rs @@ -131,6 +131,16 @@ 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) { + if self.is_set_low() { + self.set_high() + } else { + self.set_low() + } + } } impl<'d, T: Pin> Drop for Output<'d, T> { @@ -295,6 +305,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")]