Skip to content

Commit 16cd16a

Browse files
committed
Add gpio push pull test
1 parent 4534eaf commit 16cd16a

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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, Output, PXx, PushPull};
10+
11+
struct State {
12+
input_pin: PXx<Input>,
13+
output_pin: PXx<Output<PushPull>>,
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+
29+
let input_pin = gpioc
30+
.pc0
31+
.into_floating_input(&mut gpioc.moder, &mut gpioc.pupdr)
32+
.downgrade()
33+
.downgrade();
34+
let output_pin = gpioc
35+
.pc1
36+
.into_push_pull_output(&mut gpioc.moder, &mut gpioc.otyper)
37+
.downgrade()
38+
.downgrade();
39+
40+
super::State {
41+
input_pin,
42+
output_pin,
43+
}
44+
}
45+
46+
#[test]
47+
fn set_low_is_low(state: &mut super::State) {
48+
unwrap!(state.output_pin.set_low());
49+
assert!(unwrap!(state.output_pin.is_set_low()));
50+
assert!(unwrap!(state.input_pin.is_low()));
51+
}
52+
53+
#[test]
54+
fn set_high_is_high(state: &mut super::State) {
55+
unwrap!(state.output_pin.set_high());
56+
assert!(unwrap!(state.output_pin.is_set_high()));
57+
assert!(unwrap!(state.input_pin.is_high()));
58+
}
59+
}

0 commit comments

Comments
 (0)