aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-nrf/src/gpio.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs
index a47fb8350..27c18383f 100644
--- a/embassy-nrf/src/gpio.rs
+++ b/embassy-nrf/src/gpio.rs
@@ -152,6 +152,12 @@ impl<'d, T: Pin> Output<'d, T> {
152 self.pin.set_low() 152 self.pin.set_low()
153 } 153 }
154 154
155 /// Toggle the output level.
156 #[inline]
157 pub fn toggle(&mut self) {
158 self.pin.toggle()
159 }
160
155 /// Set the output level. 161 /// Set the output level.
156 #[inline] 162 #[inline]
157 pub fn set_level(&mut self, level: Level) { 163 pub fn set_level(&mut self, level: Level) {
@@ -310,6 +316,16 @@ impl<'d, T: Pin> Flex<'d, T> {
310 self.pin.set_low() 316 self.pin.set_low()
311 } 317 }
312 318
319 /// Toggle the output level.
320 #[inline]
321 pub fn toggle(&mut self) {
322 if self.is_set_low() {
323 self.set_high()
324 } else {
325 self.set_low()
326 }
327 }
328
313 /// Set the output level. 329 /// Set the output level.
314 #[inline] 330 #[inline]
315 pub fn set_level(&mut self, level: Level) { 331 pub fn set_level(&mut self, level: Level) {
@@ -538,6 +554,15 @@ mod eh02 {
538 } 554 }
539 } 555 }
540 556
557 impl<'d, T: Pin> embedded_hal_02::digital::v2::ToggleableOutputPin for Output<'d, T> {
558 type Error = Infallible;
559 #[inline]
560 fn toggle(&mut self) -> Result<(), Self::Error> {
561 self.toggle();
562 Ok(())
563 }
564 }
565
541 /// Implement [`embedded_hal_02::digital::v2::InputPin`] for [`Flex`]; 566 /// Implement [`embedded_hal_02::digital::v2::InputPin`] for [`Flex`];
542 /// 567 ///
543 /// If the pin is not in input mode the result is unspecified. 568 /// If the pin is not in input mode the result is unspecified.
@@ -574,6 +599,15 @@ mod eh02 {
574 Ok(self.ref_is_set_low()) 599 Ok(self.ref_is_set_low())
575 } 600 }
576 } 601 }
602
603 impl<'d, T: Pin> embedded_hal_02::digital::v2::ToggleableOutputPin for Flex<'d, T> {
604 type Error = Infallible;
605 #[inline]
606 fn toggle(&mut self) -> Result<(), Self::Error> {
607 self.toggle();
608 Ok(())
609 }
610 }
577} 611}
578 612
579impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Input<'d, T> { 613impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Input<'d, T> {