@@ -9,6 +9,8 @@ pub struct HrCapt<TIM, PSCL, CH> {
9
9
_x : PhantomData < ( TIM , PSCL , CH ) > ,
10
10
}
11
11
12
+ #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
13
+ #[ derive( Copy , Clone , Debug ) ]
12
14
pub enum CountingDirection {
13
15
Up = 0 ,
14
16
Down = 1 ,
@@ -23,7 +25,7 @@ pub trait CaptureEvent<TIM, PSCL> {
23
25
const BITS : u32 ;
24
26
}
25
27
26
- trait HrCapture {
28
+ pub trait HrCapture {
27
29
fn get ( & self ) -> ( u16 , CountingDirection ) ;
28
30
29
31
/// Get number of ticks relative to beginning of upcounting
@@ -43,10 +45,14 @@ trait HrCapture {
43
45
let dir_bit = dir as u32 ;
44
46
dir_bit << 16 | u32:: from ( value)
45
47
}
48
+
49
+ fn clear_interrupt ( & mut self ) ;
50
+
51
+ fn is_pending ( & self ) -> bool ;
46
52
}
47
53
48
54
macro_rules! impl_capture {
49
- ( $( $TIMX: ident: $CH: ident, $cptXYr: ident, $cptXYcr: ident, $cptXx: ident) ,+) => {
55
+ ( $( $TIMX: ident: $CH: ident, $cptXYr: ident, $cptXYcr: ident, $cptXx: ident, $dier : ident , $icr : ident , $isr : ident , $cptXie : ident , $cptXc : ident , $cptX : ident ) ,+) => {
50
56
$( impl <PSCL > HrCapt <$TIMX, PSCL , $CH> {
51
57
/// Add event to capture
52
58
///
@@ -78,6 +84,15 @@ macro_rules! impl_capture {
78
84
79
85
tim. $cptXYcr. modify( |_, w| w. swcpt( ) . set_bit( ) ) ;
80
86
}
87
+
88
+ // TODO: It would be sufficient to instead of hr_control only require exclusive access to the owning timer
89
+ // however that would be hard to do since typically the capture device is a field of that same timer.
90
+ // Would it make more sense to have this method direcly on HrTim instead?
91
+ pub fn enable_interrupt( & mut self , enable: bool , _hr_control: & mut super :: HrPwmControl ) {
92
+ let tim = unsafe { & * $TIMX:: ptr( ) } ;
93
+
94
+ tim. $dier. modify( |_r, w| w. $cptXie( ) . bit( enable) ) ;
95
+ }
81
96
}
82
97
83
98
impl <PSCL > HrCapture for HrCapt <$TIMX, PSCL , $CH> {
@@ -92,26 +107,40 @@ macro_rules! impl_capture {
92
107
93
108
( value, dir)
94
109
}
110
+
111
+ fn clear_interrupt( & mut self ) {
112
+ let tim = unsafe { & * $TIMX:: ptr( ) } ;
113
+
114
+ // No need for exclusive access since this is a write only register
115
+ tim. $icr. write( |w| w. $cptXc( ) . set_bit( ) ) ;
116
+ }
117
+
118
+ fn is_pending( & self ) -> bool {
119
+ let tim = unsafe { & * $TIMX:: ptr( ) } ;
120
+
121
+ // No need for exclusive access since this is a read only register
122
+ tim. $isr. read( ) . $cptX( ) . bit( )
123
+ }
95
124
} ) +
96
125
} ;
97
126
}
98
127
99
128
impl_capture ! {
100
- HRTIM_TIMA : Ch1 , cpt1ar, cpt1acr, cpt1x,
101
- HRTIM_TIMA : Ch2 , cpt2ar, cpt2acr, cpt2x,
129
+ HRTIM_TIMA : Ch1 , cpt1ar, cpt1acr, cpt1x, timadier , timaicr , timaisr , cpt1ie , cpt1c , cpt1 ,
130
+ HRTIM_TIMA : Ch2 , cpt2ar, cpt2acr, cpt2x, timadier , timaicr , timaisr , cpt2ie , cpt2c , cpt2 ,
102
131
103
- HRTIM_TIMB : Ch1 , cpt1br, cpt1bcr, cpt1x,
104
- HRTIM_TIMB : Ch2 , cpt2br, cpt2bcr, cpt2x,
132
+ HRTIM_TIMB : Ch1 , cpt1br, cpt1bcr, cpt1x, timbdier , timbicr , timbisr , cpt1ie , cpt1c , cpt1 ,
133
+ HRTIM_TIMB : Ch2 , cpt2br, cpt2bcr, cpt2x, timbdier , timbicr , timbisr , cpt2ie , cpt2c , cpt2 ,
105
134
106
- HRTIM_TIMC : Ch1 , cpt1cr, cpt1ccr, cpt1x,
107
- HRTIM_TIMC : Ch2 , cpt2cr, cpt2ccr, cpt2x,
135
+ HRTIM_TIMC : Ch1 , cpt1cr, cpt1ccr, cpt1x, timcdier , timcicr , timcisr , cpt1ie , cpt1c , cpt1 ,
136
+ HRTIM_TIMC : Ch2 , cpt2cr, cpt2ccr, cpt2x, timcdier , timcicr , timcisr , cpt2ie , cpt2c , cpt2 ,
108
137
109
- HRTIM_TIMD : Ch1 , cpt1dr, cpt1dcr, cpt1x,
110
- HRTIM_TIMD : Ch2 , cpt2dr, cpt2dcr, cpt2x,
138
+ HRTIM_TIMD : Ch1 , cpt1dr, cpt1dcr, cpt1x, timddier , timdicr , timdisr , cpt1ie , cpt1c , cpt1 ,
139
+ HRTIM_TIMD : Ch2 , cpt2dr, cpt2dcr, cpt2x, timddier , timdicr , timdisr , cpt2ie , cpt2c , cpt2 ,
111
140
112
- HRTIM_TIME : Ch1 , cpt1er, cpt1ecr, cpt1x,
113
- HRTIM_TIME : Ch2 , cpt2er, cpt2ecr, cpt2x,
141
+ HRTIM_TIME : Ch1 , cpt1er, cpt1ecr, cpt1x, timedier , timeicr , timeisr , cpt1ie , cpt1c , cpt1 ,
142
+ HRTIM_TIME : Ch2 , cpt2er, cpt2ecr, cpt2x, timedier , timeicr , timeisr , cpt2ie , cpt2c , cpt2 ,
114
143
115
- HRTIM_TIMF : Ch1 , cpt1fr, cpt1fcr, cpt1x,
116
- HRTIM_TIMF : Ch2 , cpt2fr, cpt2fcr, cpt2x
144
+ HRTIM_TIMF : Ch1 , cpt1fr, cpt1fcr, cpt1x, timfdier , timficr , timfisr , cpt1ie , cpt1c , cpt1 ,
145
+ HRTIM_TIMF : Ch2 , cpt2fr, cpt2fcr, cpt2x, timfdier , timficr , timfisr , cpt2ie , cpt2c , cpt2
117
146
}
0 commit comments