@@ -10,15 +10,16 @@ use defmt_rtt as _;
1010use nrf52840_hal as _;
1111use panic_probe as _;
1212
13- use nrf52840_hal:: gpio:: { Floating , Input , OpenDrain , Output , Pin } ;
13+ use nrf52840_hal:: gpio:: { Input , OpenDrain , Output , Pin , PullUp } ;
1414
1515struct State {
16- input_pin : Pin < Input < Floating > > ,
16+ input_pin : Option < Pin < Input < PullUp > > > ,
1717 output_pin : Pin < Output < OpenDrain > > ,
1818}
1919
2020#[ defmt_test:: tests]
2121mod tests {
22+ use cortex_m:: asm;
2223 use defmt:: { assert, unwrap} ;
2324 use nrf52840_hal:: {
2425 gpio:: { p0, Level , OpenDrainConfig } ,
@@ -33,7 +34,7 @@ mod tests {
3334 let p = unwrap ! ( pac:: Peripherals :: take( ) ) ;
3435 let port0 = p0:: Parts :: new ( p. P0 ) ;
3536
36- let input_pin = port0. p0_28 . into_floating_input ( ) . degrade ( ) ;
37+ let input_pin = Some ( port0. p0_28 . into_pullup_input ( ) . degrade ( ) ) ;
3738 let output_pin = port0
3839 . p0_29
3940 . into_open_drain_output ( OpenDrainConfig :: Standard0Disconnect1 , Level :: High )
@@ -48,15 +49,24 @@ mod tests {
4849 #[ test]
4950 fn set_low_is_low ( state : & mut State ) {
5051 state. output_pin . set_low ( ) . unwrap ( ) ;
51- assert ! ( state. input_pin. is_low( ) . unwrap( ) ) ;
52+ // GPIO operations are not instantaneous so a delay is needed
53+ asm:: delay ( 100 ) ;
54+ assert ! ( state. input_pin. as_ref( ) . unwrap( ) . is_low( ) . unwrap( ) ) ;
5255 }
5356
54- // with the current API we cannot test this w/o an _external_ pull-up
55- /*
5657 #[ test]
57- fn set_high_is_high (state: &mut State) {
58+ fn set_high_is_open ( state : & mut State ) {
5859 state. output_pin . set_high ( ) . unwrap ( ) ;
59- assert!(state.input_pin.is_high().unwrap());
60+ // GPIO operations are not instantaneous so a delay is needed
61+ asm:: delay ( 100 ) ;
62+ assert ! ( state. input_pin. as_ref( ) . unwrap( ) . is_high( ) . unwrap( ) ) ;
63+
64+ let pulled_down_input_pin = state. input_pin . take ( ) . unwrap ( ) . into_pulldown_input ( ) ;
65+ // GPIO operations are not instantaneous so a delay is needed
66+ asm:: delay ( 100 ) ;
67+ assert ! ( pulled_down_input_pin. is_low( ) . unwrap( ) ) ;
68+
69+ // Restore original input pin state
70+ state. input_pin = Some ( pulled_down_input_pin. into_pullup_input ( ) ) ;
6071 }
61- */
6272}
0 commit comments