Skip to content

Commit 0e90dd0

Browse files
committed
Move dac test so it can check using other pin
1 parent f478984 commit 0e90dd0

File tree

2 files changed

+33
-29
lines changed

2 files changed

+33
-29
lines changed

tests/nucleo-g474.rs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -328,35 +328,6 @@ mod tests {
328328
debug!("temp: {}°C", temp);
329329
assert!((20.0..35.0).contains(&temp), "20.0 < {} < 35.0", temp);
330330
}
331-
332-
#[test]
333-
fn dac() {
334-
use super::*;
335-
336-
// TODO: Is it ok to steal these?
337-
let cp = unsafe { stm32::CorePeripherals::steal() };
338-
let dp = unsafe { stm32::Peripherals::steal() };
339-
let mut rcc = dp.RCC.constrain();
340-
let mut delay = cp.SYST.delay(&rcc.clocks);
341-
342-
let gpioa = dp.GPIOA.split(&mut rcc);
343-
let _pa1_important_dont_use_as_output = gpioa.pa1.into_floating_input();
344-
let pa4 = gpioa.pa4.into_analog();
345-
let dac1ch1 = dp.DAC1.constrain(pa4, &mut rcc);
346-
347-
let gpioa = unsafe { &*GPIOA::PTR };
348-
349-
// dac_manual will have its value set manually
350-
let mut dac = dac1ch1.calibrate_buffer(&mut delay).enable(&mut rcc);
351-
352-
dac.set_value(0);
353-
delay.delay_ms(1);
354-
assert!(is_pax_low(gpioa, 4));
355-
356-
dac.set_value(4095);
357-
delay.delay_ms(1);
358-
assert!(!is_pax_low(gpioa, 4));
359-
}
360331
}
361332

362333
fn is_pax_low(gpioa: &stm32::gpioa::RegisterBlock, x: u8) -> bool {

tests/nucleo-g474_w_jumpers.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,35 @@ mod tests {
3030

3131
use crate::VREF_ADC_BITS;
3232

33+
#[test]
34+
fn dac() {
35+
use super::*;
36+
37+
// TODO: Is it ok to steal these?
38+
let cp = unsafe { stm32::CorePeripherals::steal() };
39+
let dp = unsafe { stm32::Peripherals::steal() };
40+
let mut rcc = dp.RCC.constrain();
41+
let mut delay = cp.SYST.delay(&rcc.clocks);
42+
43+
let gpioa = dp.GPIOA.split(&mut rcc);
44+
let _pa1_important_dont_use_as_output = gpioa.pa1.into_floating_input();
45+
let pa4 = gpioa.pa4.into_analog();
46+
let dac1ch1 = dp.DAC1.constrain(pa4, &mut rcc);
47+
48+
let gpioa = unsafe { &*stm32::GPIOA::PTR };
49+
50+
// dac_manual will have its value set manually
51+
let mut dac = dac1ch1.calibrate_buffer(&mut delay).enable(&mut rcc);
52+
53+
dac.set_value(0);
54+
delay.delay_ms(1);
55+
assert!(is_pax_low(gpioa, 1));
56+
57+
dac.set_value(4095);
58+
delay.delay_ms(1);
59+
assert!(!is_pax_low(gpioa, 1));
60+
}
61+
3362
#[test]
3463
fn opamp_follower_dac_adc() {
3564
let super::Peripherals {
@@ -255,6 +284,10 @@ mod tests {
255284
}
256285
}
257286

287+
fn is_pax_low(gpioa: &stm32::gpioa::RegisterBlock, x: u8) -> bool {
288+
gpioa.idr().read().idr(x).is_low()
289+
}
290+
258291
/// Vrefint = 1.212V typical
259292
/// Vref+ = 3.3V for nucleo
260293
/// 1.212V/3.3V*4095 = 1504 adc value

0 commit comments

Comments
 (0)