Skip to content

Commit 5ba64f8

Browse files
committed
HRTIM: Move some inherent methods to traits on HrTim
1 parent 6887958 commit 5ba64f8

File tree

1 file changed

+39
-14
lines changed

1 file changed

+39
-14
lines changed

src/hrtim/timer.rs

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,27 @@ pub trait HrTimer {
4747
fn as_period_adc_trigger(&self) -> super::adc_trigger::TimerPeriod<Self::Timer>;
4848
}
4949

50+
pub trait HrSlaveTimer: HrTimer
51+
{
52+
type CaptureCh1: super::capture::HrCapture;
53+
type CaptureCh2: super::capture::HrCapture;
54+
55+
/// Start listening to the specified event
56+
fn enable_reset_event<E: super::event::TimerResetEventSource<Self::Timer, Self::Prescaler>>(
57+
&mut self,
58+
_event: &E,
59+
);
60+
61+
/// Stop listening to the specified event
62+
fn disable_reset_event<E: super::event::TimerResetEventSource<Self::Timer, Self::Prescaler>>(
63+
&mut self,
64+
_event: &E,
65+
);
66+
67+
fn capture_ch1(&mut self) -> &mut Self::CaptureCh1;
68+
fn capture_ch2(&mut self) -> &mut Self::CaptureCh2;
69+
}
70+
5071
macro_rules! hrtim_timer {
5172
($(
5273
$TIMX:ident:
@@ -135,8 +156,11 @@ macro_rules! hrtim_timer {
135156
}
136157
}
137158

138-
$(// Only for Non-Master timers
139-
impl<PSCL> HrTim<$TIMX, PSCL> {
159+
$(
160+
impl<PSCL> HrSlaveTimer for HrTim<$TIMX, PSCL> {
161+
type CaptureCh1 = HrCapt<Self::Timer, Self::Prescaler, capture::Ch1>;
162+
type CaptureCh2 = HrCapt<Self::Timer, Self::Prescaler, capture::Ch2>;
163+
140164
/// Reset this timer every time the specified event occurs
141165
///
142166
/// Behaviour depends on `timer_mode`:
@@ -152,20 +176,31 @@ macro_rules! hrtim_timer {
152176
/// * `HrTimerMode::Continuous`: Enabling the timer enables and starts it simultaneously.
153177
/// When the counter reaches the PER value, it rolls-over to 0x0000 and resumes counting.
154178
/// The counter can be reset at any time
155-
pub fn enable_reset_event<E: super::event::TimerResetEventSource<$TIMX, PSCL>>(&mut self, _event: &E) {
179+
fn enable_reset_event<E: super::event::TimerResetEventSource<Self::Timer, Self::Prescaler>>(&mut self, _event: &E) {
156180
let tim = unsafe { &*$TIMX::ptr() };
157181

158182
unsafe { tim.$rstXr.modify(|r, w| w.bits(r.bits() | E::BITS)); }
159183
}
160184

161185
/// Stop listening to the specified event
162-
pub fn disable_reset_event<E: super::event::TimerResetEventSource<$TIMX, PSCL>>(&mut self, _event: &E) {
186+
fn disable_reset_event<E: super::event::TimerResetEventSource<Self::Timer, Self::Prescaler>>(&mut self, _event: &E) {
163187
let tim = unsafe { &*$TIMX::ptr() };
164188

165189
unsafe { tim.$rstXr.modify(|r, w| w.bits(r.bits() & !E::BITS)); }
166190
}
191+
192+
/// Access the timers first capture channel
193+
fn capture_ch1(&mut self) -> &mut Self::CaptureCh1 {
194+
&mut self.capture_ch1
195+
}
196+
197+
/// Access the timers second capture channel
198+
fn capture_ch2(&mut self) -> &mut Self::CaptureCh2 {
199+
&mut self.capture_ch2
200+
}
167201
}
168202

203+
169204
/// Timer Period event
170205
impl<DST, PSCL> super::event::EventSource<DST, PSCL> for HrTim<$TIMX, PSCL> {
171206
// $rstXr
@@ -228,16 +263,6 @@ hrtim_timer_adc_trigger! {
228263
HRTIM_TIMF: [(Adc13: [(PER: 1 << 24), (RST: 1 << 28)]), (Adc24: [(PER: 1 << 24), ]), (Adc579: [(PER: 30), (RST: 31)]), (Adc6810: [(PER: 31), ])]
229264
}
230265

231-
impl<TIM, PSCL> HrTim<TIM, PSCL> {
232-
pub fn capture_ch1(&mut self) -> &mut HrCapt<TIM, PSCL, capture::Ch1> {
233-
&mut self.capture_ch1
234-
}
235-
236-
pub fn capture_ch2(&mut self) -> &mut HrCapt<TIM, PSCL, capture::Ch2> {
237-
&mut self.capture_ch2
238-
}
239-
}
240-
241266
/// Master Timer Period event
242267
impl<DST, PSCL> super::event::TimerResetEventSource<DST, PSCL> for HrTim<HRTIM_MASTER, PSCL> {
243268
const BITS: u32 = 1 << 4; // MSTPER

0 commit comments

Comments
 (0)