aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-rp/src/gpio.rs38
-rw-r--r--tests/rp/src/bin/gpio.rs34
2 files changed, 72 insertions, 0 deletions
diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs
index 2fb2d65c2..9b5faac15 100644
--- a/embassy-rp/src/gpio.rs
+++ b/embassy-rp/src/gpio.rs
@@ -146,6 +146,12 @@ impl<'d> Input<'d> {
146 self.pin.get_level() 146 self.pin.get_level()
147 } 147 }
148 148
149 /// Configure the input logic inversion of this pin.
150 #[inline]
151 pub fn set_inversion(&mut self, invert: bool) {
152 self.pin.set_input_inversion(invert)
153 }
154
149 /// Wait until the pin is high. If it is already high, return immediately. 155 /// Wait until the pin is high. If it is already high, return immediately.
150 #[inline] 156 #[inline]
151 pub async fn wait_for_high(&mut self) { 157 pub async fn wait_for_high(&mut self) {
@@ -382,6 +388,12 @@ impl<'d> Output<'d> {
382 self.pin.set_slew_rate(slew_rate) 388 self.pin.set_slew_rate(slew_rate)
383 } 389 }
384 390
391 /// Configure the output logic inversion of this pin.
392 #[inline]
393 pub fn set_inversion(&mut self, invert: bool) {
394 self.pin.set_output_inversion(invert)
395 }
396
385 /// Set the output as high. 397 /// Set the output as high.
386 #[inline] 398 #[inline]
387 pub fn set_high(&mut self) { 399 pub fn set_high(&mut self) {
@@ -685,6 +697,30 @@ impl<'d> Flex<'d> {
685 self.pin.sio_oe().value_xor().write_value(self.bit()) 697 self.pin.sio_oe().value_xor().write_value(self.bit())
686 } 698 }
687 699
700 /// Configure the input logic inversion of this pin.
701 #[inline]
702 pub fn set_input_inversion(&mut self, invert: bool) {
703 self.pin.gpio().ctrl().modify(|w| {
704 w.set_inover(if invert {
705 pac::io::vals::Inover::INVERT
706 } else {
707 pac::io::vals::Inover::NORMAL
708 })
709 });
710 }
711
712 /// Configure the output logic inversion of this pin.
713 #[inline]
714 pub fn set_output_inversion(&mut self, invert: bool) {
715 self.pin.gpio().ctrl().modify(|w| {
716 w.set_outover(if invert {
717 pac::io::vals::Outover::INVERT
718 } else {
719 pac::io::vals::Outover::NORMAL
720 })
721 });
722 }
723
688 /// Get whether the pin input level is high. 724 /// Get whether the pin input level is high.
689 #[inline] 725 #[inline]
690 pub fn is_high(&self) -> bool { 726 pub fn is_high(&self) -> bool {
@@ -815,6 +851,8 @@ impl<'d> Drop for Flex<'d> {
815 self.pin.pad_ctrl().write(|_| {}); 851 self.pin.pad_ctrl().write(|_| {});
816 self.pin.gpio().ctrl().write(|w| { 852 self.pin.gpio().ctrl().write(|w| {
817 w.set_funcsel(pac::io::vals::Gpio0ctrlFuncsel::NULL as _); 853 w.set_funcsel(pac::io::vals::Gpio0ctrlFuncsel::NULL as _);
854 w.set_inover(pac::io::vals::Inover::NORMAL);
855 w.set_outover(pac::io::vals::Outover::NORMAL);
818 }); 856 });
819 self.pin.io().int_dormant_wake().inte(idx / 8).write_clear(|w| { 857 self.pin.io().int_dormant_wake().inte(idx / 8).write_clear(|w| {
820 w.set_edge_high(idx % 8, true); 858 w.set_edge_high(idx % 8, true);
diff --git a/tests/rp/src/bin/gpio.rs b/tests/rp/src/bin/gpio.rs
index 614b6317a..8bd0df8d8 100644
--- a/tests/rp/src/bin/gpio.rs
+++ b/tests/rp/src/bin/gpio.rs
@@ -67,6 +67,40 @@ async fn main(_spawner: Spawner) {
67 } 67 }
68 } 68 }
69 69
70 // Test input inversion
71 {
72 let mut b = Input::new(b.reborrow(), Pull::None);
73 b.set_inversion(true);
74 // no pull, the status is undefined
75
76 let mut a = Output::new(a.reborrow(), Level::Low);
77 delay();
78 assert!(b.is_high());
79 a.set_high();
80 delay();
81 assert!(b.is_low());
82
83 b.set_inversion(false);
84 a.set_inversion(true);
85
86 a.set_low();
87 delay();
88 assert!(b.is_high());
89
90 a.set_high();
91 delay();
92 assert!(b.is_low());
93
94 b.set_inversion(true);
95 a.set_high();
96 delay();
97 assert!(b.is_high());
98
99 a.set_high();
100 delay();
101 assert!(b.is_high());
102 }
103
70 // Test input no pull 104 // Test input no pull
71 { 105 {
72 let b = Input::new(b.reborrow(), Pull::None); 106 let b = Input::new(b.reborrow(), Pull::None);