Skip to content

Commit 851c67f

Browse files
committed
even more eev hrtim
1 parent a4d7ca2 commit 851c67f

File tree

3 files changed

+101
-10
lines changed

3 files changed

+101
-10
lines changed

src/hrtim/external_event.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,22 +227,21 @@ where
227227
}
228228
}
229229

230-
pub trait BuilderToEventSourceBuilder {
231-
fn finalize<PSCL, TIM>(self, _calibrated: &mut HrTimCalibrated) -> ExternalEventSourceBuilder<TIM>;
230+
pub trait ToExternalEventSource {
231+
fn finalize<PSCL, TIM>(self, _calibrated: &mut HrTimCalibrated) -> ExternalEventSource;
232232
}
233233

234-
This is something every (timerX, eevY) pair should have....
235-
struct ExternalEventSourceBuilder<TIM> {
236-
filter: u8,
237-
is_latching: bool,
234+
#[derive(Copy, Clone)]
235+
struct ExternalEventMuxOut<const N: u8> {
236+
_x: PhantomData<()>,
238237
}
239238

240239
macro_rules! impl_eev1_5_to_es {
241240
($eev:ident, $N:literal, $eeXsrc:ident, $eeXpol:ident, $eeXsns:ident, $eeXfast:ident) => {
242241
impl<const IS_FAST: bool> ExternalEventBuilder1To5 for SourceBuilder<$N, IS_FAST> {}
243242

244-
impl<const IS_FAST: bool> BuilderToEventSourceBuilder for SourceBuilder<$N, IS_FAST> {
245-
fn finalize<PSCL, TIM>(self, _calibrated: &mut HrTimCalibrated) -> ExternalEventSourceBuilder {
243+
impl<const IS_FAST: bool> ToExternalEventSource for SourceBuilder<$N, IS_FAST> {
244+
fn finalize<PSCL, TIM>(self, _calibrated: &mut HrTimCalibrated) -> ExternalEventSource {
246245
let SourceBuilder {
247246
src_bits,
248247
edge_or_polarity_bits,
@@ -277,7 +276,7 @@ macro_rules! impl_eev6_10_to_es {
277276
($eev:ident, $N:literal, $eeXsrc:ident, $eeXpol:ident, $eeXsns:ident, $eeXf:ident) => {
278277
impl ExternalEventBuilder6To10 for SourceBuilder<$N, false> {}
279278

280-
impl ExternalEventToEventSource for SourceBuilder<$N, false> {
279+
impl ToExternalEventSource for SourceBuilder<$N, false> {
281280
fn finalize<PSCL, TIM>(self, _calibrated: &mut HrTimCalibrated) -> ExternalEventSource {
282281
let SourceBuilder {
283282
src_bits,

src/hrtim/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub mod external_event;
66
pub mod fault;
77
pub mod output;
88
pub mod timer;
9+
pub mod timer_eev_cfg;
910

1011
use core::marker::PhantomData;
1112
use core::mem::MaybeUninit;
@@ -195,6 +196,7 @@ pub struct HrPwmBuilder<TIM, PSCL, PS, OUT> {
195196
repetition_counter: u8,
196197
deadtime: Option<DeadtimeConfig>,
197198
enable_repetition_interrupt: bool,
199+
eev_cfg: EevCfg,
198200
out1_polarity: Polarity,
199201
out2_polarity: Polarity,
200202
}
@@ -413,6 +415,7 @@ macro_rules! hrtim_common_methods {
413415
repetition_counter,
414416
deadtime,
415417
enable_repetition_interrupt,
418+
eev_cfg,
416419
out1_polarity,
417420
out2_polarity,
418421
} = self;
@@ -441,6 +444,7 @@ macro_rules! hrtim_common_methods {
441444
repetition_counter,
442445
deadtime,
443446
enable_repetition_interrupt,
447+
eev_cfg,
444448
out1_polarity,
445449
out2_polarity,
446450
}
@@ -479,6 +483,12 @@ macro_rules! hrtim_common_methods {
479483

480484
self
481485
}
486+
487+
pub fn eev_cfg(mut self, eev_cfg: Stuff) -> Self {
488+
self.eev_cfg = eev_cfg;
489+
490+
self
491+
}
482492
};
483493
}
484494

@@ -554,7 +564,10 @@ macro_rules! hrtim_hal {
554564
OUT: ToHrOut,
555565
{
556566
pub fn finalize(self, _control: &mut HrPwmControl) -> (HrTim<$TIMX, PSCL>, (HrCr1<$TIMX, PSCL>, HrCr2<$TIMX, PSCL>, HrCr3<$TIMX, PSCL>, HrCr4<$TIMX, PSCL>), OUT) {
557-
hrtim_finalize_body!(self, PreloadSource, $TIMX: ($timXcr, ck_pscx, $perXr, perx, $tXcen, $rep, $repx, $dier, $repie, $timXcr2, $fltXr, $outXr, $dtXr),)
567+
hrtim_finalize_body!(
568+
self, PreloadSource,
569+
$TIMX: ($timXcr, ck_pscx, $perXr, perx, $tXcen, $rep, $repx, $dier, $repie, $timXcr2, $fltXr, $outXr, $dtXr),
570+
)
558571
}
559572

560573
hrtim_common_methods!($TIMX, PreloadSource);

src/hrtim/timer_eev_cfg.rs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
use core::marker::PhantomData;
2+
3+
struct EevCfgs<TIM> {
4+
eev1: EevCfg<TIM>,
5+
eev2: EevCfg<TIM>,
6+
eev3: EevCfg<TIM>,
7+
eev4: EevCfg<TIM>,
8+
eev5: EevCfg<TIM>,
9+
eev6: EevCfg<TIM>,
10+
eev7: EevCfg<TIM>,
11+
eev8: EevCfg<TIM>,
12+
eev9: EevCfg<TIM>,
13+
eev10: EevCfg<TIM>,
14+
}
15+
16+
#[derive(Default)]
17+
struct EevCfg<TIM> {
18+
_x: PhantomData<TIM>,
19+
filter_bits: u8,
20+
latch_bit: u8,
21+
}
22+
23+
impl<TIM> EevCfg<TIM> {
24+
pub fn filter(mut self, stuff: u8) {
25+
self.filter_bits = stuff;
26+
self
27+
}
28+
29+
/// NOTE: This can not be set if eev is in fast mode AND using a
30+
pub fn latching(mut self) -> Self {
31+
self.latch_bit = true;
32+
self
33+
}
34+
}
35+
36+
/// Note: Whenever a compare register is used for filtering, the value must be strictly above 0.
37+
pub enum EventFilter {
38+
None = 0b0000,
39+
40+
/// Blanking from reset/rollover to Cmp1
41+
BlankingResetToCmp1 = 0b0001,
42+
43+
/// This depends on counter mode:
44+
/// * Up-counting mode: Blanking from reset/rollover to Cmp2
45+
/// * Up-down mode: Blanking from Cmp1 to Cmp2(only during up counting)
46+
BlankingResetToCmp2OrCmp1ToCmp2InUdm = 0b0010,
47+
48+
/// Blanking from reset/rollover to Cmp3
49+
BlankingResetToCmp3 = 0b0011,
50+
51+
/// This depends on counter mode:
52+
/// * Up-counting mode: Blanking from reset/rollover to Cmp4
53+
/// * Up-down mode: Blanking from Cmp3 to Cmp4(only during up counting)
54+
BlankingResetToCmp4OrCmp3ToCmp4InUdm = 0b0100,
55+
56+
BlankingSource1 = 0b0101,
57+
BlankingSource2 = 0b0110,
58+
BlankingSource3 = 0b0111,
59+
BlankingSource4 = 0b1000,
60+
BlankingSource5 = 0b1001,
61+
BlankingSource6 = 0b1010,
62+
BlankingSource7 = 0b1011,
63+
BlankingSource8 = 0b1100,
64+
65+
/// This depends on counter mode:
66+
/// * Up-counting mode: Windowing from reset/rollover to Cmp2
67+
/// * Up-down mode: Windowing from Cmp2 to Cmp3(only during up counting)
68+
WindowingResetToCmp2OrCmp2ToCmp3InUdm = 0b1101,
69+
70+
/// This depends on counter mode:
71+
/// * Up-counting mode: Windowing from reset/rollover to Cmp3
72+
/// * Up-down mode: Windowing from Cmp2 to Cmp3(only during down counting)
73+
WindowingResetToCmp3OrCmp2ToCmp3InUdm = 0b1110,
74+
75+
Windowing from another timing unit: TIMWIN source (see Table 227 for details) in upcounting mode (UDM bit reset)
76+
In up-down counting mode (UDM bit set): windowing from compare 2 during the up-counting
77+
phase to compare 3 during the down-counting phase.
78+
Windowing
79+
}

0 commit comments

Comments
 (0)