aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-12-06 20:12:29 +0000
committerGitHub <[email protected]>2022-12-06 20:12:29 +0000
commit40f0272dd0007616c1c92b5fb51fb723a3d47d30 (patch)
tree354a1a98e66bef55cb7f7c3d79df34327cadeed2
parent5e94b8060b7f1af8118ca1f943181ce70be92057 (diff)
parent54c153673d9e79ea36f687fbdfa3e6f56ff62fc8 (diff)
Merge #1099
1099: rp: implement input for OutputOpenDrain r=Dirbaio a=Dirbaio Needed for onewire and similar protocols. Co-authored-by: Dario Nieuwenhuis <[email protected]>
-rw-r--r--embassy-rp/src/gpio.rs32
-rw-r--r--tests/rp/src/bin/gpio.rs28
2 files changed, 57 insertions, 3 deletions
diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs
index 71390306f..930de2068 100644
--- a/embassy-rp/src/gpio.rs
+++ b/embassy-rp/src/gpio.rs
@@ -411,6 +411,16 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> {
411 pub fn toggle(&mut self) { 411 pub fn toggle(&mut self) {
412 self.pin.toggle_set_as_output() 412 self.pin.toggle_set_as_output()
413 } 413 }
414
415 #[inline]
416 pub fn is_high(&self) -> bool {
417 self.pin.is_high()
418 }
419
420 #[inline]
421 pub fn is_low(&self) -> bool {
422 self.pin.is_low()
423 }
414} 424}
415 425
416/// GPIO flexible pin. 426/// GPIO flexible pin.
@@ -791,6 +801,18 @@ mod eh02 {
791 } 801 }
792 } 802 }
793 803
804 impl<'d, T: Pin> embedded_hal_02::digital::v2::InputPin for OutputOpenDrain<'d, T> {
805 type Error = Infallible;
806
807 fn is_high(&self) -> Result<bool, Self::Error> {
808 Ok(self.is_high())
809 }
810
811 fn is_low(&self) -> Result<bool, Self::Error> {
812 Ok(self.is_low())
813 }
814 }
815
794 impl<'d, T: Pin> embedded_hal_02::digital::v2::OutputPin for OutputOpenDrain<'d, T> { 816 impl<'d, T: Pin> embedded_hal_02::digital::v2::OutputPin for OutputOpenDrain<'d, T> {
795 type Error = Infallible; 817 type Error = Infallible;
796 818
@@ -946,6 +968,16 @@ mod eh1 {
946 } 968 }
947 } 969 }
948 970
971 impl<'d, T: Pin> embedded_hal_1::digital::InputPin for OutputOpenDrain<'d, T> {
972 fn is_high(&self) -> Result<bool, Self::Error> {
973 Ok(self.is_high())
974 }
975
976 fn is_low(&self) -> Result<bool, Self::Error> {
977 Ok(self.is_low())
978 }
979 }
980
949 impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Flex<'d, T> { 981 impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Flex<'d, T> {
950 type Error = Infallible; 982 type Error = Infallible;
951 } 983 }
diff --git a/tests/rp/src/bin/gpio.rs b/tests/rp/src/bin/gpio.rs
index af22fe27d..80e92d0fd 100644
--- a/tests/rp/src/bin/gpio.rs
+++ b/tests/rp/src/bin/gpio.rs
@@ -78,6 +78,7 @@ async fn main(_spawner: Spawner) {
78 a.set_as_input(); 78 a.set_as_input();
79 79
80 // When an OutputOpenDrain is high, it doesn't drive the pin. 80 // When an OutputOpenDrain is high, it doesn't drive the pin.
81 b.set_high();
81 a.set_pull(Pull::Up); 82 a.set_pull(Pull::Up);
82 delay(); 83 delay();
83 assert!(a.is_high()); 84 assert!(a.is_high());
@@ -85,9 +86,8 @@ async fn main(_spawner: Spawner) {
85 delay(); 86 delay();
86 assert!(a.is_low()); 87 assert!(a.is_low());
87 88
88 b.set_low();
89
90 // When an OutputOpenDrain is low, it drives the pin low. 89 // When an OutputOpenDrain is low, it drives the pin low.
90 b.set_low();
91 a.set_pull(Pull::Up); 91 a.set_pull(Pull::Up);
92 delay(); 92 delay();
93 assert!(a.is_low()); 93 assert!(a.is_low());
@@ -95,14 +95,36 @@ async fn main(_spawner: Spawner) {
95 delay(); 95 delay();
96 assert!(a.is_low()); 96 assert!(a.is_low());
97 97
98 // Check high again
98 b.set_high(); 99 b.set_high();
99
100 a.set_pull(Pull::Up); 100 a.set_pull(Pull::Up);
101 delay(); 101 delay();
102 assert!(a.is_high()); 102 assert!(a.is_high());
103 a.set_pull(Pull::Down); 103 a.set_pull(Pull::Down);
104 delay(); 104 delay();
105 assert!(a.is_low()); 105 assert!(a.is_low());
106
107 // When an OutputOpenDrain is high, it reads the input value in the pin.
108 b.set_high();
109 a.set_as_input();
110 a.set_pull(Pull::Up);
111 delay();
112 assert!(b.is_high());
113 a.set_as_output();
114 a.set_low();
115 delay();
116 assert!(b.is_low());
117
118 // When an OutputOpenDrain is low, it always reads low.
119 b.set_low();
120 a.set_as_input();
121 a.set_pull(Pull::Up);
122 delay();
123 assert!(b.is_low());
124 a.set_as_output();
125 a.set_low();
126 delay();
127 assert!(b.is_low());
106 } 128 }
107 129
108 // FLEX 130 // FLEX