rp/gpio: fix is_set_high/is_set_low, expand tests.
This commit is contained in:
parent
8a811cfcf7
commit
91c1d17f16
3 changed files with 70 additions and 6 deletions
|
@ -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
|
||||||
|
|
|
@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue