nrf/gpio: add toggle.

This commit is contained in:
Dario Nieuwenhuis 2023-12-26 17:35:49 +01:00
parent eebfee189a
commit 7fa954c027

View File

@ -152,6 +152,12 @@ impl<'d, T: Pin> Output<'d, T> {
self.pin.set_low()
}
/// Toggle the output level.
#[inline]
pub fn toggle(&mut self) {
self.pin.toggle()
}
/// Set the output level.
#[inline]
pub fn set_level(&mut self, level: Level) {
@ -310,6 +316,16 @@ impl<'d, T: Pin> Flex<'d, T> {
self.pin.set_low()
}
/// Toggle the output level.
#[inline]
pub fn toggle(&mut self) {
if self.is_set_low() {
self.set_high()
} else {
self.set_low()
}
}
/// Set the output level.
#[inline]
pub fn set_level(&mut self, level: Level) {
@ -538,6 +554,15 @@ mod eh02 {
}
}
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> {
self.toggle();
Ok(())
}
}
/// Implement [`embedded_hal_02::digital::v2::InputPin`] for [`Flex`];
///
/// If the pin is not in input mode the result is unspecified.
@ -574,6 +599,15 @@ mod eh02 {
Ok(self.ref_is_set_low())
}
}
impl<'d, T: Pin> embedded_hal_02::digital::v2::ToggleableOutputPin for Flex<'d, T> {
type Error = Infallible;
#[inline]
fn toggle(&mut self) -> Result<(), Self::Error> {
self.toggle();
Ok(())
}
}
}
impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Input<'d, T> {