extend input pull test
also check the input state of the pin configured in pull up/down mode
@@ -14,7 +14,7 @@ use nrf52840_hal::gpio::{Floating, Input, Pin};
struct State {
input_pin: Pin<Input<Floating>>,
- pull_pin: Option<Pin<Input<Floating>>>,
+ puller_pin: Option<Pin<Input<Floating>>>,
}
#[defmt_test::tests]
@@ -31,33 +31,57 @@ mod tests {
let port0 = p0::Parts::new(p.P0);
let input_pin = port0.p0_28.into_floating_input().degrade();
- let pull_pin = Some(port0.p0_29.into_floating_input().degrade());
+ let puller_pin = Some(port0.p0_29.into_floating_input().degrade());
State {
input_pin,
- pull_pin,
+ puller_pin,
}
}
#[test]
fn pulldown_is_low(state: &mut State) {
- let pull_pin = unwrap!(state.pull_pin.take());
+ let puller_pin = unwrap!(state.puller_pin.take());
- let pulldown_pin = pull_pin.into_pulldown_input();
+ let pulldown_pin = puller_pin.into_pulldown_input();
+ // GPIO re-configuration is not instantaneous so a delay is needed
+ asm::delay(100);
+ assert!(pulldown_pin.is_low().unwrap());
+
+ state.puller_pin = Some(pulldown_pin.into_floating_input());
+ }
+
+ #[test]
+ fn pulldown_drives_low(state: &mut State) {
+ let puller_pin = unwrap!(state.puller_pin.take());
+
+ let pulldown_pin = puller_pin.into_pulldown_input();
assert!(state.input_pin.is_low().unwrap());
- state.pull_pin = Some(pulldown_pin.into_floating_input());
+ state.puller_pin = Some(pulldown_pin.into_floating_input());
}
#[test]
fn pullup_is_high(state: &mut State) {
- let pull_pin = unwrap!(state.pull_pin.take());
+ let puller_pin = unwrap!(state.puller_pin.take());
+
+ let pullup_pin = puller_pin.into_pullup_input();
+ // GPIO re-configuration is not instantaneous so a delay is needed
+ asm::delay(100);
+ assert!(pullup_pin.is_high().unwrap());
+
+ state.puller_pin = Some(pullup_pin.into_floating_input());
+ }
+
+ #[test]
+ fn pullup_drives_high(state: &mut State) {
+ let puller_pin = unwrap!(state.puller_pin.take());
- let pullup_pin = pull_pin.into_pullup_input();
+ let pullup_pin = puller_pin.into_pullup_input();
// GPIO re-configuration is not instantaneous so a delay is needed
asm::delay(100);
assert!(state.input_pin.is_high().unwrap());
- state.pull_pin = Some(pullup_pin.into_floating_input());
+ state.puller_pin = Some(pullup_pin.into_floating_input());
}
}
