Skip to content

Commit 20bf75c

Browse files
committed
Add pull up and down test
1 parent e3d8ea3 commit 20bf75c

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

testsuite/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ harness = false
2020
name = "gpio_output_open_drain"
2121
harness = false
2222

23+
[[test]]
24+
name = "gpio_input_puller"
25+
harness = false
26+
2327
[dev-dependencies]
2428
cfg-if = "1.0"
2529
cortex-m = "0.7.0"

testsuite/tests/gpio_input_puller.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#![no_std]
2+
#![no_main]
3+
4+
use defmt_rtt as _;
5+
use panic_probe as _;
6+
7+
use stm32f3xx_hal as hal;
8+
9+
use hal::gpio::gpioc;
10+
use hal::gpio::Resistor;
11+
use hal::gpio::{Input, PXx};
12+
use hal::{pac, prelude::*};
13+
14+
struct State {
15+
observer: PXx<Input>,
16+
puller: gpioc::PC1<Input>,
17+
pupdr: gpioc::PUPDR,
18+
}
19+
20+
#[defmt_test::tests]
21+
mod tests {
22+
use super::*;
23+
use defmt::{assert, unwrap};
24+
25+
// Test the defaults with no configuration
26+
#[init]
27+
fn init() -> super::State {
28+
let dp = unwrap!(pac::Peripherals::take());
29+
30+
let mut rcc = dp.RCC.constrain();
31+
let mut gpioc = dp.GPIOC.split(&mut rcc.ahb);
32+
33+
let mut observer = gpioc
34+
.pc0
35+
.into_floating_input(&mut gpioc.moder, &mut gpioc.pupdr);
36+
observer.set_internal_resistor(&mut gpioc.pupdr, Resistor::Floating);
37+
38+
let observer = observer.downgrade().downgrade();
39+
40+
let puller = gpioc
41+
.pc1
42+
.into_floating_input(&mut gpioc.moder, &mut gpioc.pupdr);
43+
44+
let pupdr = gpioc.pupdr;
45+
46+
super::State {
47+
observer,
48+
puller,
49+
pupdr,
50+
}
51+
}
52+
53+
#[test]
54+
fn pulldown_is_low(state: &mut super::State) {
55+
state
56+
.puller
57+
.set_internal_resistor(&mut state.pupdr, Resistor::PullDown);
58+
assert!(unwrap!(state.puller.is_low()));
59+
assert!(unwrap!(state.observer.is_low()));
60+
}
61+
62+
#[test]
63+
fn set_high_is_high(state: &mut super::State) {
64+
state
65+
.puller
66+
.set_internal_resistor(&mut state.pupdr, Resistor::PullUp);
67+
assert!(unwrap!(state.puller.is_high()));
68+
assert!(unwrap!(state.observer.is_high()));
69+
}
70+
}

0 commit comments

Comments
 (0)