Merge pull request #1639 from embassy-rs/rp-gpio-set-low-fix

rp/gpio: fix is_set_high/is_set_low, expand tests.
This commit is contained in:
Dario Nieuwenhuis 2023-07-11 13:16:27 +02:00 committed by GitHub
commit c6e2f4a90b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 6 deletions

View File

@ -566,13 +566,13 @@ impl<'d, T: Pin> Flex<'d, T> {
/// Is the output level high? /// Is the output level high?
#[inline] #[inline]
pub fn is_set_high(&self) -> bool { pub fn is_set_high(&self) -> bool {
(self.pin.sio_out().value().read() & self.bit()) == 0 !self.is_set_low()
} }
/// Is the output level low? /// Is the output level low?
#[inline] #[inline]
pub fn is_set_low(&self) -> bool { pub fn is_set_low(&self) -> bool {
!self.is_set_high() (self.pin.sio_out().value().read() & self.bit()) == 0
} }
/// What level output is set to /// What level output is set to

View File

@ -21,14 +21,46 @@ async fn main(_spawner: Spawner) {
let b = Input::new(&mut b, Pull::None); let b = Input::new(&mut b, Pull::None);
{ {
let _a = Output::new(&mut a, Level::Low); let a = Output::new(&mut a, Level::Low);
delay(); delay();
assert!(b.is_low()); assert!(b.is_low());
assert!(!b.is_high());
assert!(a.is_set_low());
assert!(!a.is_set_high());
} }
{ {
let _a = Output::new(&mut a, Level::High); let mut a = Output::new(&mut a, Level::High);
delay();
assert!(!b.is_low());
assert!(b.is_high());
assert!(!a.is_set_low());
assert!(a.is_set_high());
// Test is_set_low / is_set_high
a.set_low();
delay();
assert!(b.is_low());
assert!(a.is_set_low());
assert!(!a.is_set_high());
a.set_high();
delay(); delay();
assert!(b.is_high()); assert!(b.is_high());
assert!(!a.is_set_low());
assert!(a.is_set_high());
// Test toggle
a.toggle();
delay();
assert!(b.is_low());
assert!(a.is_set_low());
assert!(!a.is_set_high());
a.toggle();
delay();
assert!(b.is_high());
assert!(!a.is_set_low());
assert!(a.is_set_high());
} }
} }

View File

@ -40,14 +40,46 @@ async fn main(_spawner: Spawner) {
let b = Input::new(&mut b, Pull::None); let b = Input::new(&mut b, Pull::None);
{ {
let _a = Output::new(&mut a, Level::Low, Speed::Low); let a = Output::new(&mut a, Level::Low, Speed::Low);
delay(); delay();
assert!(b.is_low()); assert!(b.is_low());
assert!(!b.is_high());
assert!(a.is_set_low());
assert!(!a.is_set_high());
} }
{ {
let _a = Output::new(&mut a, Level::High, Speed::Low); let mut a = Output::new(&mut a, Level::High, Speed::Low);
delay();
assert!(!b.is_low());
assert!(b.is_high());
assert!(!a.is_set_low());
assert!(a.is_set_high());
// Test is_set_low / is_set_high
a.set_low();
delay();
assert!(b.is_low());
assert!(a.is_set_low());
assert!(!a.is_set_high());
a.set_high();
delay(); delay();
assert!(b.is_high()); assert!(b.is_high());
assert!(!a.is_set_low());
assert!(a.is_set_high());
// Test toggle
a.toggle();
delay();
assert!(b.is_low());
assert!(a.is_set_low());
assert!(!a.is_set_high());
a.toggle();
delay();
assert!(b.is_high());
assert!(!a.is_set_low());
assert!(a.is_set_high());
} }
} }