Merge pull request #2359 from embassy-rs/nrf-toggle

nrf/gpio: add toggle.
This commit is contained in:
Dario Nieuwenhuis 2023-12-26 23:06:18 +00:00 committed by GitHub
commit 1f7209966c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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> {