Skip to content

Commit e3d8ea3

Browse files
committed
Add gpio output open drain test
1 parent 16cd16a commit e3d8ea3

File tree

1 file changed

+61
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)