diff options
| -rw-r--r-- | embassy-rp/src/gpio.rs | 4 | ||||
| -rw-r--r-- | tests/rp/src/bin/gpio.rs | 36 | ||||
| -rw-r--r-- | tests/stm32/src/bin/gpio.rs | 36 |
3 files changed, 70 insertions, 6 deletions
diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs index d18fb909c..a3d330cdc 100644 --- a/embassy-rp/src/gpio.rs +++ b/embassy-rp/src/gpio.rs | |||
| @@ -566,13 +566,13 @@ impl<'d, T: Pin> Flex<'d, T> { | |||
| 566 | /// Is the output level high? | 566 | /// Is the output level high? |
| 567 | #[inline] | 567 | #[inline] |
| 568 | pub fn is_set_high(&self) -> bool { | 568 | pub fn is_set_high(&self) -> bool { |
| 569 | (self.pin.sio_out().value().read() & self.bit()) == 0 | 569 | !self.is_set_low() |
| 570 | } | 570 | } |
| 571 | 571 | ||
| 572 | /// Is the output level low? | 572 | /// Is the output level low? |
| 573 | #[inline] | 573 | #[inline] |
| 574 | pub fn is_set_low(&self) -> bool { | 574 | pub fn is_set_low(&self) -> bool { |
| 575 | !self.is_set_high() | 575 | (self.pin.sio_out().value().read() & self.bit()) == 0 |
| 576 | } | 576 | } |
| 577 | 577 | ||
| 578 | /// What level output is set to | 578 | /// What level output is set to |
diff --git a/tests/rp/src/bin/gpio.rs b/tests/rp/src/bin/gpio.rs index 51112d319..946b7dc88 100644 --- a/tests/rp/src/bin/gpio.rs +++ b/tests/rp/src/bin/gpio.rs | |||
| @@ -21,14 +21,46 @@ async fn main(_spawner: Spawner) { | |||
| 21 | let b = Input::new(&mut b, Pull::None); | 21 | let b = Input::new(&mut b, Pull::None); |
| 22 | 22 | ||
| 23 | { | 23 | { |
| 24 | let _a = Output::new(&mut a, Level::Low); | 24 | let a = Output::new(&mut a, Level::Low); |
| 25 | delay(); | 25 | delay(); |
| 26 | assert!(b.is_low()); | 26 | assert!(b.is_low()); |
| 27 | assert!(!b.is_high()); | ||
| 28 | assert!(a.is_set_low()); | ||
| 29 | assert!(!a.is_set_high()); | ||
| 27 | } | 30 | } |
| 28 | { | 31 | { |
| 29 | let _a = Output::new(&mut a, Level::High); | 32 | let mut a = Output::new(&mut a, Level::High); |
| 30 | delay(); | 33 | delay(); |
| 34 | assert!(!b.is_low()); | ||
| 31 | assert!(b.is_high()); | 35 | assert!(b.is_high()); |
| 36 | assert!(!a.is_set_low()); | ||
| 37 | assert!(a.is_set_high()); | ||
| 38 | |||
| 39 | // Test is_set_low / is_set_high | ||
| 40 | a.set_low(); | ||
| 41 | delay(); | ||
| 42 | assert!(b.is_low()); | ||
| 43 | assert!(a.is_set_low()); | ||
| 44 | assert!(!a.is_set_high()); | ||
| 45 | |||
| 46 | a.set_high(); | ||
| 47 | delay(); | ||
| 48 | assert!(b.is_high()); | ||
| 49 | assert!(!a.is_set_low()); | ||
| 50 | assert!(a.is_set_high()); | ||
| 51 | |||
| 52 | // Test toggle | ||
| 53 | a.toggle(); | ||
| 54 | delay(); | ||
| 55 | assert!(b.is_low()); | ||
| 56 | assert!(a.is_set_low()); | ||
| 57 | assert!(!a.is_set_high()); | ||
| 58 | |||
| 59 | a.toggle(); | ||
| 60 | delay(); | ||
| 61 | assert!(b.is_high()); | ||
| 62 | assert!(!a.is_set_low()); | ||
| 63 | assert!(a.is_set_high()); | ||
| 32 | } | 64 | } |
| 33 | } | 65 | } |
| 34 | 66 | ||
diff --git a/tests/stm32/src/bin/gpio.rs b/tests/stm32/src/bin/gpio.rs index 67f44317e..aad174431 100644 --- a/tests/stm32/src/bin/gpio.rs +++ b/tests/stm32/src/bin/gpio.rs | |||
| @@ -40,14 +40,46 @@ async fn main(_spawner: Spawner) { | |||
| 40 | let b = Input::new(&mut b, Pull::None); | 40 | let b = Input::new(&mut b, Pull::None); |
| 41 | 41 | ||
| 42 | { | 42 | { |
| 43 | let _a = Output::new(&mut a, Level::Low, Speed::Low); | 43 | let a = Output::new(&mut a, Level::Low, Speed::Low); |
| 44 | delay(); | 44 | delay(); |
| 45 | assert!(b.is_low()); | 45 | assert!(b.is_low()); |
| 46 | assert!(!b.is_high()); | ||
| 47 | assert!(a.is_set_low()); | ||
| 48 | assert!(!a.is_set_high()); | ||
| 46 | } | 49 | } |
| 47 | { | 50 | { |
| 48 | let _a = Output::new(&mut a, Level::High, Speed::Low); | 51 | let mut a = Output::new(&mut a, Level::High, Speed::Low); |
| 49 | delay(); | 52 | delay(); |
| 53 | assert!(!b.is_low()); | ||
| 50 | assert!(b.is_high()); | 54 | assert!(b.is_high()); |
| 55 | assert!(!a.is_set_low()); | ||
| 56 | assert!(a.is_set_high()); | ||
| 57 | |||
| 58 | // Test is_set_low / is_set_high | ||
| 59 | a.set_low(); | ||
| 60 | delay(); | ||
| 61 | assert!(b.is_low()); | ||
| 62 | assert!(a.is_set_low()); | ||
| 63 | assert!(!a.is_set_high()); | ||
| 64 | |||
| 65 | a.set_high(); | ||
| 66 | delay(); | ||
| 67 | assert!(b.is_high()); | ||
| 68 | assert!(!a.is_set_low()); | ||
| 69 | assert!(a.is_set_high()); | ||
| 70 | |||
| 71 | // Test toggle | ||
| 72 | a.toggle(); | ||
| 73 | delay(); | ||
| 74 | assert!(b.is_low()); | ||
| 75 | assert!(a.is_set_low()); | ||
| 76 | assert!(!a.is_set_high()); | ||
| 77 | |||
| 78 | a.toggle(); | ||
| 79 | delay(); | ||
| 80 | assert!(b.is_high()); | ||
| 81 | assert!(!a.is_set_low()); | ||
| 82 | assert!(a.is_set_high()); | ||
| 51 | } | 83 | } |
| 52 | } | 84 | } |
| 53 | 85 | ||
