rp/gpio: fix is_set_high/is_set_low, expand tests.
This commit is contained in:
		@@ -566,13 +566,13 @@ impl<'d, T: Pin> Flex<'d, T> {
 | 
			
		||||
    /// Is the output level high?
 | 
			
		||||
    #[inline]
 | 
			
		||||
    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?
 | 
			
		||||
    #[inline]
 | 
			
		||||
    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
 | 
			
		||||
 
 | 
			
		||||
@@ -21,14 +21,46 @@ async fn main(_spawner: Spawner) {
 | 
			
		||||
        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();
 | 
			
		||||
            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();
 | 
			
		||||
            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 _a = Output::new(&mut a, Level::Low, Speed::Low);
 | 
			
		||||
            let a = Output::new(&mut a, Level::Low, Speed::Low);
 | 
			
		||||
            delay();
 | 
			
		||||
            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();
 | 
			
		||||
            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());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user