@@ -47,6 +47,27 @@ pub trait HrTimer {
47
47
fn as_period_adc_trigger ( & self ) -> super :: adc_trigger:: TimerPeriod < Self :: Timer > ;
48
48
}
49
49
50
+ pub trait HrSlaveTimer : HrTimer
51
+ where
52
+ HrCapt < Self :: Timer , Self :: Prescaler , capture:: Ch1 > : super :: capture:: HrCapture ,
53
+ HrCapt < Self :: Timer , Self :: Prescaler , capture:: Ch2 > : 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 HrCapt < Self :: Timer , Self :: Prescaler , capture:: Ch1 > ;
68
+ fn capture_ch2 ( & mut self ) -> & mut HrCapt < Self :: Timer , Self :: Prescaler , capture:: Ch2 > ;
69
+ }
70
+
50
71
macro_rules! hrtim_timer {
51
72
( $(
52
73
$TIMX: ident:
@@ -135,8 +156,8 @@ macro_rules! hrtim_timer {
135
156
}
136
157
}
137
158
138
- $( // Only for Non-Master timers
139
- impl <PSCL > HrTim <$TIMX, PSCL > {
159
+ $(
160
+ impl <PSCL > HrSlaveTimer for HrTim <$TIMX, PSCL > {
140
161
/// Reset this timer every time the specified event occurs
141
162
///
142
163
/// Behaviour depends on `timer_mode`:
@@ -152,20 +173,31 @@ macro_rules! hrtim_timer {
152
173
/// * `HrTimerMode::Continuous`: Enabling the timer enables and starts it simultaneously.
153
174
/// When the counter reaches the PER value, it rolls-over to 0x0000 and resumes counting.
154
175
/// The counter can be reset at any time
155
- pub fn enable_reset_event<E : super :: event:: TimerResetEventSource <$TIMX , PSCL >>( & mut self , _event: & E ) {
176
+ fn enable_reset_event<E : super :: event:: TimerResetEventSource <Self :: Timer , Self :: Prescaler >>( & mut self , _event: & E ) {
156
177
let tim = unsafe { & * $TIMX:: ptr( ) } ;
157
178
158
179
unsafe { tim. $rstXr. modify( |r, w| w. bits( r. bits( ) | E :: BITS ) ) ; }
159
180
}
160
181
161
182
/// Stop listening to the specified event
162
- pub fn disable_reset_event<E : super :: event:: TimerResetEventSource <$TIMX , PSCL >>( & mut self , _event: & E ) {
183
+ fn disable_reset_event<E : super :: event:: TimerResetEventSource <Self :: Timer , Self :: Prescaler >>( & mut self , _event: & E ) {
163
184
let tim = unsafe { & * $TIMX:: ptr( ) } ;
164
185
165
186
unsafe { tim. $rstXr. modify( |r, w| w. bits( r. bits( ) & !E :: BITS ) ) ; }
166
187
}
188
+
189
+ /// Access the timers first capture channel
190
+ fn capture_ch1( & mut self ) -> & mut HrCapt <Self :: Timer , Self :: Prescaler , capture:: Ch1 > {
191
+ & mut self . capture_ch1
192
+ }
193
+
194
+ /// Access the timers second capture channel
195
+ fn capture_ch2( & mut self ) -> & mut HrCapt <Self :: Timer , Self :: Prescaler , capture:: Ch2 > {
196
+ & mut self . capture_ch2
197
+ }
167
198
}
168
199
200
+
169
201
/// Timer Period event
170
202
impl <DST , PSCL > super :: event:: EventSource <DST , PSCL > for HrTim <$TIMX, PSCL > {
171
203
// $rstXr
@@ -228,16 +260,6 @@ hrtim_timer_adc_trigger! {
228
260
HRTIM_TIMF : [ ( Adc13 : [ ( PER : 1 << 24 ) , ( RST : 1 << 28 ) ] ) , ( Adc24 : [ ( PER : 1 << 24 ) , ] ) , ( Adc579 : [ ( PER : 30 ) , ( RST : 31 ) ] ) , ( Adc6810 : [ ( PER : 31 ) , ] ) ]
229
261
}
230
262
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
-
241
263
/// Master Timer Period event
242
264
impl < DST , PSCL > super :: event:: TimerResetEventSource < DST , PSCL > for HrTim < HRTIM_MASTER , PSCL > {
243
265
const BITS : u32 = 1 << 4 ; // MSTPER
0 commit comments