Skip to content

Commit a4d7ca2

Browse files
committed
More work on hrtim eev
1 parent b65cfc4 commit a4d7ca2

File tree

7 files changed

+554
-527
lines changed

7 files changed

+554
-527
lines changed

examples/hrtim_eev.rs

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,39 +57,29 @@ fn main() -> ! {
5757

5858
let pin_a: PA8<Alternate<AF13>> = gpioa.pa8.into_alternate();
5959

60-
// . . . *
61-
// . 33% . . * . .
62-
// .-----. .-----. .--. . .
63-
//out1 | | | | | | . .
64-
// | | | | | | . .
65-
// ------ ----------- ----------- -----------------------------------
66-
// . . . * . .
67-
// . . . * . .
68-
// . . . *-------- . .
69-
//fault . . . | | . .
70-
// . . . | | . .
71-
// ----------------------------------------- --------------------------
72-
// . . . * . .
73-
// . . . * . .
60+
// . . * .
61+
// . 33% . * . . .
62+
// .-----. .--* .-----. .-----. .-----
63+
//out1 | | | | | | | | |
64+
// | | | * | | | | |
65+
// ------ ----------- -------------- ----------- -----------
66+
// . . * . . .
67+
// . . * . . .
68+
// . . *--------* . . .
69+
//eev . . | | . . .
70+
// . . | | . . .
71+
// ------------------------- ------------------------------------------
72+
// . . * . . .
73+
// . . * . . .
7474
let (timer, (mut cr1, _cr2, _cr3, _cr4), mut out1) = dp
7575
.HRTIM_TIMA
7676
.pwm_advanced(pin_a, &mut rcc)
7777
.prescaler(prescaler)
7878
.period(0xFFFF)
79-
//.with_fault_source(fault_source1)
80-
//.with_fault_source(fault_source2)
81-
.with_fault_source(fault_source3) // Set fault source
82-
//.with_fault_source(fault_source4)
83-
//.with_fault_source(fault_source5)
84-
//.with_fault_source(fault_source6)
85-
.fault_action1(FaultAction::ForceInactive)
86-
.fault_action2(FaultAction::ForceInactive)
87-
// alternated every period with one being
88-
// inactive and the other getting to output its wave form
89-
// as normal
9079
.finalize(&mut fault_control);
9180

9281
out1.enable_rst_event(EventSource::Cr1); // Set low on compare match with cr1
82+
out1.enable_rst_event(&eev_input3);
9383
out1.enable_set_event(EventSource::Period); // Set high at new period
9484
cr1.set_duty(timer.get_period() / 3);
9585
//unsafe {((HRTIM_COMMON::ptr() as *mut u8).offset(0x14) as *mut u32).write_volatile(1); }

examples/hrtim_flt_comp.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ fn main() -> ! {
4747
let mut adc1 = dp.ADC1.claim_and_configure(
4848
hal::adc::ClockSource::SystemClock,
4949
&rcc,
50-
hal::adc::config::AdcConfig::default().clock_mode(hal::adc::config::ClockMode::Synchronous_Div_4),
50+
hal::adc::config::AdcConfig::default()
51+
.clock_mode(hal::adc::config::ClockMode::Synchronous_Div_4),
5152
&mut delay,
5253
false,
5354
);

src/hrtim/control.rs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
stm32::{HRTIM_COMMON, RCC},
1010
};
1111

12-
use super::fault::FaultInputs;
12+
use super::{fault::FaultInputs, external_event::EevInputs};
1313

1414
pub trait HrControltExt {
1515
fn hr_control(self, _rcc: &mut Rcc) -> HrTimOngoingCalibration;
@@ -421,7 +421,7 @@ impl HrTimOngoingCalibration {
421421
}
422422
}
423423

424-
pub fn wait_for_calibration(self) -> HrTimCalibrated {
424+
pub fn wait_for_calibration(self) -> (HrTimCalibrated, FaultInputs, EevInputs) {
425425
let common = unsafe { &*HRTIM_COMMON::ptr() };
426426
while common.isr.read().dllrdy().bit_is_clear() {
427427
// Wait until ready
@@ -430,7 +430,11 @@ impl HrTimOngoingCalibration {
430430
// Calibration is now done, it is safe to continue
431431
unsafe { self.init() };
432432

433-
HrTimCalibrated { _x: PhantomData }
433+
(
434+
HrTimCalibrated { _x: PhantomData },
435+
unsafe { FaultInputs::new() },
436+
unsafe { EevInputs::new() },
437+
)
434438
}
435439

436440
pub fn enable_adc_trigger1_source(mut self, trigger: Adc13Trigger) -> Self {
@@ -524,27 +528,17 @@ pub struct HrTimCalibrated {
524528
}
525529

526530
impl HrTimCalibrated {
527-
pub fn constrain(self) -> (HrPwmControl, FaultInputs) {
528-
(
529-
HrPwmControl {
530-
_x: PhantomData,
531-
fault_sys: FltMonitorSys { _x: PhantomData },
532-
fault_1: FltMonitor1 { _x: PhantomData },
533-
fault_2: FltMonitor2 { _x: PhantomData },
534-
fault_3: FltMonitor3 { _x: PhantomData },
535-
fault_4: FltMonitor4 { _x: PhantomData },
536-
fault_5: FltMonitor5 { _x: PhantomData },
537-
fault_6: FltMonitor6 { _x: PhantomData },
538-
},
539-
FaultInputs {
540-
fault_input1: FaultInput1 { _x: PhantomData },
541-
fault_input2: FaultInput2 { _x: PhantomData },
542-
fault_input3: FaultInput3 { _x: PhantomData },
543-
fault_input4: FaultInput4 { _x: PhantomData },
544-
fault_input5: FaultInput5 { _x: PhantomData },
545-
fault_input6: FaultInput6 { _x: PhantomData },
546-
},
547-
)
531+
pub fn constrain(self) -> HrPwmControl {
532+
HrPwmControl {
533+
_x: PhantomData,
534+
fault_sys: FltMonitorSys { _x: PhantomData },
535+
fault_1: FltMonitor1 { _x: PhantomData },
536+
fault_2: FltMonitor2 { _x: PhantomData },
537+
fault_3: FltMonitor3 { _x: PhantomData },
538+
fault_4: FltMonitor4 { _x: PhantomData },
539+
fault_5: FltMonitor5 { _x: PhantomData },
540+
fault_6: FltMonitor6 { _x: PhantomData },
541+
}
548542
}
549543
}
550544

0 commit comments

Comments
 (0)