Skip to content

Commit 515c443

Browse files
committed
Cleanup after rabase
1 parent 76222c3 commit 515c443

File tree

5 files changed

+27
-81
lines changed

5 files changed

+27
-81
lines changed

examples/utils/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
//! Utilities for examples
22
33
pub mod logger;
4-
pub mod test;

examples/utils/test.rs

Lines changed: 0 additions & 49 deletions
This file was deleted.

tests/nucleo-g474_hrtim.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33

44
// Requires a jumper from A1<->A2 (arduino naming) aka PA1<->PA4
55

6-
#[path = "../examples/utils/mod.rs"]
7-
mod utils;
8-
96
mod common;
107

118
use common::test_pwm;

tests/nucleo-g474_w_jumpers-hrtim.rs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
// Requires a jumper from A1<->A2 (arduino naming) aka PA1<->PA4
55

6-
#[path = "../examples/utils/mod.rs"]
7-
mod utils;
6+
mod common;
87

98
use core::ops::Sub;
109

@@ -34,6 +33,7 @@ use stm32g4xx_hal::stasis::{Freeze, Frozen};
3433

3534
pub const F_SYS: HertzU32 = HertzU32::MHz(120);
3635
pub const CYCLES_PER_US: u32 = F_SYS.raw() / 1_000_000;
36+
type Timer = crate::common::Timer<CYCLES_PER_US>;
3737

3838
pub fn enable_timer(cp: &mut stm32::CorePeripherals) {
3939
cp.DCB.enable_trace();
@@ -54,9 +54,7 @@ mod tests {
5454
use stm32g4xx_hal::{dac::DacOut, stm32::GPIOA};
5555

5656
use crate::{
57-
abs_diff, now,
58-
utils::test::{await_hi, await_lo},
59-
F_SYS,
57+
abs_diff, common::{await_hi, await_lo}, now, F_SYS
6058
};
6159

6260
/// | \
@@ -78,7 +76,7 @@ mod tests {
7876
let cr2_ticks_per_dac_trigger = 1024;
7977

8078
let crate::Peripherals {
81-
mut timer,
79+
mut hrtimer,
8280
mut hr_control,
8381
eev_input4,
8482
comp,
@@ -88,22 +86,24 @@ mod tests {
8886
pa2,
8987
rcc,
9088
delay,
89+
timer
9190
} = super::setup(
9291
prescaler,
9392
period,
9493
dac_step_per_trigger,
9594
cr2_ticks_per_dac_trigger,
9695
);
96+
let pin_num = 8;
9797

98-
timer.cr1.set_duty(period / 10); // Set blanking window to give the ref_dac time to reset
98+
hrtimer.cr1.set_duty(period / 10); // Set blanking window to give the ref_dac time to reset
9999
//out.enable_rst_event(&cr1); // Set low on compare match with cr1
100-
timer.out.enable_rst_event(&eev_input4); // Set low on compare match with cr1
101-
timer.out.enable_set_event(&timer.timer); // Set high at new period
100+
hrtimer.out.enable_rst_event(&eev_input4); // Set low on compare match with cr1
101+
hrtimer.out.enable_set_event(&hrtimer.timer); // Set high at new period
102102

103-
timer.out.enable();
104-
timer.timer.start(&mut hr_control.control);
103+
hrtimer.out.enable();
104+
hrtimer.timer.start(&mut hr_control.control);
105105

106-
defmt::println!("state: {}", timer.out.get_state());
106+
defmt::println!("state: {}", hrtimer.out.get_state());
107107

108108
//out.enable_rst_event(&eev_input4);
109109

@@ -120,7 +120,7 @@ mod tests {
120120
let out = comp.output();
121121
let ref_dac = ref_dac.get_value();
122122
let value_dac = value_dac.get_value();
123-
let cnt = timer.timer.get_counter_value();
123+
let cnt = hrtimer.timer.get_counter_value();
124124
defmt::println!(
125125
"out: {}, ref: {}, val: {}, cnt: {}",
126126
out,
@@ -151,12 +151,12 @@ mod tests {
151151
let out = comp.output();
152152
defmt::println!("out: {}", out);
153153
}
154-
let duration_until_lo = await_lo(gpioa, 8, timeout, now).unwrap();
155-
let first_lo_duration = await_hi(gpioa, 8, timeout, now);
154+
let duration_until_lo = await_lo(&timer, pin_num, timeout).unwrap();
155+
let first_lo_duration = await_hi(&timer, pin_num, timeout);
156156

157157
let (period, duty) = match first_lo_duration {
158158
Ok(lo_duration) => {
159-
let duty = await_lo(gpioa, 8, timeout, now).unwrap();
159+
let duty = await_lo(&timer, pin_num, timeout).unwrap();
160160
let period = lo_duration + duty;
161161
(period, duty)
162162
}
@@ -194,7 +194,7 @@ fn abs_diff<T: Ord + Sub + Copy>(a: T, b: T) -> T::Output {
194194
const VREF_ADC_BITS: u16 = 1504;
195195

196196
struct Peripherals<PSCL> {
197-
timer:
197+
hrtimer:
198198
HrParts<HRTIM_TIMA, PSCL, HrOut1<HRTIM_TIMA, PSCL, DacResetOnCounterReset, DacStepOnCmp2>, DacResetOnCounterReset, DacStepOnCmp2>,
199199
hr_control: HrPwmControl,
200200
eev_input4: ExternalEventSource<4, false>,
@@ -205,6 +205,7 @@ struct Peripherals<PSCL> {
205205
pa2: gpio::gpioa::PA2<gpio::Analog>,
206206
rcc: rcc::Rcc,
207207
delay: delay::SystDelay,
208+
timer: Timer,
208209
}
209210

210211
fn setup<PSCL: HrtimPrescaler>(
@@ -217,8 +218,9 @@ fn setup<PSCL: HrtimPrescaler>(
217218
//DAC1_OUT1 PA4 -> A2
218219

219220
// TODO: Is it ok to steal these?
220-
let mut cp = unsafe { stm32::CorePeripherals::steal() };
221-
let dp = unsafe { stm32::Peripherals::steal() };
221+
let mut cp = stm32::CorePeripherals::take().unwrap();
222+
let dp = stm32::Peripherals::take().unwrap();
223+
let timer = Timer::enable_timer(&mut cp);
222224
// Set system frequency to 16MHz * 15/1/2 = 120MHz
223225
// This would lead to HrTim running at 120MHz * 32 = 3.84...
224226
defmt::info!("rcc");
@@ -281,7 +283,7 @@ fn setup<PSCL: HrtimPrescaler>(
281283
let mut hr_control = hr_control.constrain();
282284
let eev_cfgs =
283285
EevCfgs::default().eev4(EevCfg::default().filter(EventFilter::BlankingResetToCmp1));
284-
let mut timer: HrParts<_, PSCL, HrOut1<_, PSCL, DacResetOnCounterReset, DacStepOnCmp2>, DacResetOnCounterReset, DacStepOnCmp2> = dp
286+
let mut hrtimer: HrParts<_, PSCL, HrOut1<_, PSCL, DacResetOnCounterReset, DacStepOnCmp2>, DacResetOnCounterReset, DacStepOnCmp2> = dp
285287
.HRTIM_TIMA
286288
.pwm_advanced(pa8)
287289
.prescaler(prescaler)
@@ -290,14 +292,14 @@ fn setup<PSCL: HrtimPrescaler>(
290292
.eev_cfg(eev_cfgs)
291293
.finalize(&mut hr_control);
292294

293-
timer.cr2.set_duty(cr2_ticks_per_dac_trigger);
295+
hrtimer.cr2.set_duty(cr2_ticks_per_dac_trigger);
294296
let ref_dac = ref_dac.enable_sawtooth_generator(
295297
SawtoothConfig::with_slope(
296298
stm32g4xx_hal::dac::CountingDirection::Decrement,
297299
dac_step_per_trigger,
298300
)
299-
.inc_trigger(&timer.cr2)
300-
.reset_trigger(&timer.timer),
301+
.inc_trigger(&hrtimer.cr2)
302+
.reset_trigger(&hrtimer.timer),
301303
&mut rcc,
302304
);
303305

@@ -306,9 +308,8 @@ fn setup<PSCL: HrtimPrescaler>(
306308
.comparator(pa1, comp_ref, comparator::Config::default(), &rcc.clocks)
307309
.enable();
308310

309-
let timer: HrParts<_, _, HrOut1<_, _, DacResetOnCounterReset, DacStepOnCmp2>, _, _> = timer;
310311
Peripherals {
311-
timer,
312+
hrtimer,
312313
hr_control,
313314
eev_input4,
314315
comp,
@@ -318,5 +319,6 @@ fn setup<PSCL: HrtimPrescaler>(
318319
pa2,
319320
rcc,
320321
delay,
322+
timer,
321323
}
322324
}

tests/nucleo-g474_w_jumpers.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33

44
// Requires a jumper from A1<->A2 (arduino naming) aka PA1<->PA4
55

6-
#[path = "../examples/utils/mod.rs"]
7-
mod utils;
8-
96
mod common;
107

118
use stm32g4xx_hal::adc::{self, AdcClaim, AdcCommonExt};

0 commit comments

Comments
 (0)