mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-10-29 21:30:54 +00:00
nrf/gpio: add toggle.
This commit is contained in:
parent
eebfee189a
commit
7fa954c027
@ -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> {
|
||||
|
Loading…
Reference in New Issue
Block a user