@@ -9,6 +9,8 @@ pub struct HrCapt<TIM, PSCL, CH> {
99 _x : PhantomData < ( TIM , PSCL , CH ) > ,
1010}
1111
12+ #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
13+ #[ derive( Copy , Clone , Debug ) ]
1214pub enum CountingDirection {
1315 Up = 0 ,
1416 Down = 1 ,
@@ -23,7 +25,7 @@ pub trait CaptureEvent<TIM, PSCL> {
2325 const BITS : u32 ;
2426}
2527
26- trait HrCapture {
28+ pub trait HrCapture {
2729 fn get ( & self ) -> ( u16 , CountingDirection ) ;
2830
2931 /// Get number of ticks relative to beginning of upcounting
@@ -43,10 +45,14 @@ trait HrCapture {
4345 let dir_bit = dir as u32 ;
4446 dir_bit << 16 | u32:: from ( value)
4547 }
48+
49+ fn clear_interrupt ( & mut self ) ;
50+
51+ fn is_pending ( & self ) -> bool ;
4652}
4753
4854macro_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 ) ,+) => {
5056 $( impl <PSCL > HrCapt <$TIMX, PSCL , $CH> {
5157 /// Add event to capture
5258 ///
@@ -78,6 +84,15 @@ macro_rules! impl_capture {
7884
7985 tim. $cptXYcr. modify( |_, w| w. swcpt( ) . set_bit( ) ) ;
8086 }
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+ }
8196 }
8297
8398 impl <PSCL > HrCapture for HrCapt <$TIMX, PSCL , $CH> {
@@ -92,26 +107,40 @@ macro_rules! impl_capture {
92107
93108 ( value, dir)
94109 }
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+ }
95124 } ) +
96125 } ;
97126}
98127
99128impl_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 ,
102131
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 ,
105134
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 ,
108137
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 ,
111140
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 ,
114143
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
117146}
0 commit comments