Skip to content

Commit 4534eaf

Browse files
committed
Add gpio input test
1 parent e9f2277 commit 4534eaf

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

testsuite/tests/gpio_input.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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::{Input, PXx};
10+
11+
struct State {
12+
input_ground: PXx<Input>,
13+
input_vdd: PXx<Input>,
14+
}
15+
16+
#[defmt_test::tests]
17+
mod tests {
18+
use defmt::{assert, unwrap};
19+
use stm32f3xx_hal::{pac, prelude::*};
20+
21+
// Test the defaults with no configuration
22+
#[init]
23+
fn init() -> super::State {
24+
let dp = unwrap!(pac::Peripherals::take());
25+
26+
let mut rcc = dp.RCC.constrain();
27+
let mut gpioc = dp.GPIOC.split(&mut rcc.ahb);
28+
let input_ground = gpioc
29+
.pc3
30+
.into_floating_input(&mut gpioc.moder, &mut gpioc.pupdr)
31+
.downgrade()
32+
.downgrade();
33+
let input_vdd = gpioc
34+
.pc2
35+
.into_floating_input(&mut gpioc.moder, &mut gpioc.pupdr)
36+
.downgrade()
37+
.downgrade();
38+
39+
super::State {
40+
input_ground,
41+
input_vdd,
42+
}
43+
}
44+
45+
#[test]
46+
fn ground_is_low(state: &mut super::State) {
47+
assert!(unwrap!(state.input_ground.is_low()));
48+
}
49+
50+
#[test]
51+
fn vdd_is_high(state: &mut super::State) {
52+
assert!(unwrap!(state.input_vdd.is_high()));
53+
}
54+
}

0 commit comments

Comments
 (0)