Skip to content

Commit f7675d7

Browse files
committed
let helpers conjure gpioa
1 parent 80e7412 commit f7675d7

File tree

2 files changed

+12
-27
lines changed

2 files changed

+12
-27
lines changed

tests/common/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ impl<const CYCLES_PER_US: u32> Timer<CYCLES_PER_US> {
2020
}
2121

2222
#[allow(dead_code)]
23-
pub fn is_pax_low(gpioa: &stm32::gpioa::RegisterBlock, pin: u8) -> bool {
23+
pub fn is_pax_low(pin: u8) -> bool {
24+
let gpioa = unsafe { &*GPIOA::PTR };
2425
gpioa.idr().read().idr(pin).is_low()
2526
}
2627

@@ -31,21 +32,19 @@ pub struct ErrorTimedOut;
3132
#[allow(dead_code)]
3233
pub fn await_lo<const CYCLES_PER_US: u32>(
3334
timer: &Timer<CYCLES_PER_US>,
34-
gpioa: &stm32::gpioa::RegisterBlock,
3535
pin: u8,
3636
timeout: MicrosDurationU32,
3737
) -> Result<MicrosDurationU32, ErrorTimedOut> {
38-
await_p(timer, || is_pax_low(gpioa, pin), timeout)
38+
await_p(timer, || is_pax_low(pin), timeout)
3939
}
4040

4141
#[allow(dead_code)]
4242
pub fn await_hi<const CYCLES_PER_US: u32>(
4343
timer: &Timer<CYCLES_PER_US>,
44-
gpioa: &stm32::gpioa::RegisterBlock,
4544
pin: u8,
4645
timeout: MicrosDurationU32,
4746
) -> Result<MicrosDurationU32, ErrorTimedOut> {
48-
await_p(timer, || !is_pax_low(gpioa, pin), timeout)
47+
await_p(timer, || !is_pax_low(pin), timeout)
4948
}
5049

5150
#[allow(dead_code)]

tests/nucleo-g474.rs

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,11 @@ mod tests {
5959

6060
pin.set_high();
6161
delay.delay(1.millis()); // Give the pin plenty of time to go high
62-
{
63-
let gpioa = unsafe { &*GPIOA::PTR };
64-
assert!(!is_pax_low(gpioa, pin_num));
65-
}
62+
assert!(!is_pax_low(pin_num));
6663

6764
pin.set_low();
6865
delay.delay(1.millis()); // Give the pin plenty of time to go low
69-
{
70-
let gpioa = unsafe { &*GPIOA::PTR };
71-
assert!(is_pax_low(gpioa, pin_num));
72-
}
66+
assert!(is_pax_low(pin_num));
7367
}
7468

7569
#[test]
@@ -96,18 +90,12 @@ mod tests {
9690
pin.set_high();
9791
delay.delay(1.millis()); // Give the pin plenty of time to go high
9892
assert!(pin.is_high());
99-
{
100-
let gpioa = unsafe { &*GPIOA::PTR };
101-
assert!(!is_pax_low(gpioa, pin_num));
102-
}
93+
assert!(!is_pax_low(pin_num));
10394

10495
pin.set_low();
10596
delay.delay(1.millis()); // Give the pin plenty of time to go low
10697
assert!(pin.is_low());
107-
{
108-
let gpioa = unsafe { &*GPIOA::PTR };
109-
assert!(is_pax_low(gpioa, pin_num));
110-
}
98+
assert!(is_pax_low(pin_num));
11199
}
112100

113101
#[test]
@@ -132,21 +120,19 @@ mod tests {
132120
pwm.set_duty_cycle_percent(50).unwrap();
133121
pwm.enable();
134122

135-
let gpioa = unsafe { &*GPIOA::PTR };
136-
137123
let min: MicrosDurationU32 = 495u32.micros();
138124
let max: MicrosDurationU32 = 505u32.micros();
139125

140126
debug!("Awaiting first rising edge...");
141-
let duration_until_lo = await_lo(&timer, gpioa, pin_num, max).unwrap();
142-
let first_lo_duration = await_hi(&timer, gpioa, pin_num, max).unwrap();
127+
let duration_until_lo = await_lo(&timer, pin_num, max).unwrap();
128+
let first_lo_duration = await_hi(&timer, pin_num, max).unwrap();
143129

144130
let mut hi_duration = 0.micros();
145131
let mut lo_duration = 0.micros();
146132

147133
for _ in 0..10 {
148134
// Make sure the timer half periods are within 495-505us
149-
hi_duration = await_lo(&timer, gpioa, pin_num, max).unwrap();
135+
hi_duration = await_lo(&timer, pin_num, max).unwrap();
150136
assert!(
151137
hi_duration > min && hi_duration < max,
152138
"hi: {} < {} < {}",
@@ -155,7 +141,7 @@ mod tests {
155141
max
156142
);
157143

158-
lo_duration = await_hi(&timer, gpioa, pin_num, max).unwrap();
144+
lo_duration = await_hi(&timer, pin_num, max).unwrap();
159145
assert!(
160146
lo_duration > min && lo_duration < max,
161147
"lo: {} < {} < {}",

0 commit comments

Comments
 (0)