1- use crate :: { hal , stm32} ;
1+ use crate :: stm32;
22
33use super :: timer;
4+
5+ #[ cfg( feature = "stm32g4" ) ]
46use crate :: mcu:: DmaMuxResources ;
5- use hal :: dma :: traits :: TargetAddress ;
6- use hal:: dma:: PeripheralToMemory ;
7- use stm32 :: { HRTIM_TIMA , HRTIM_TIMB , HRTIM_TIMC , HRTIM_TIMD , HRTIM_TIME , HRTIM_TIMF } ;
7+ # [ cfg ( feature = "stm32g4" ) ]
8+ use crate :: hal:: dma:: PeripheralToMemory ;
9+
810use core:: marker:: PhantomData ;
11+ #[ cfg( feature = "hrtim_v2" ) ]
12+ use stm32:: HRTIM_TIMF ;
13+ use stm32:: { HRTIM_TIMA , HRTIM_TIMB , HRTIM_TIMC , HRTIM_TIMD , HRTIM_TIME } ;
914
1015pub struct Ch1 ;
1116pub struct Ch2 ;
@@ -27,6 +32,7 @@ pub struct HrCapt<TIM, PSCL, CH, DMA> {
2732#[ derive( Copy , Clone , Debug ) ]
2833pub enum CountingDirection {
2934 Up = 0 ,
35+ #[ cfg( feature = "hrtim_v2" ) ]
3036 Down = 1 ,
3137}
3238
@@ -129,6 +135,7 @@ pub trait HrCapture {
129135 // The capture counter always counts up and restarts at period
130136 match dir {
131137 CountingDirection :: Up => i32:: from ( value) ,
138+ #[ cfg( feature = "hrtim_v2" ) ]
132139 CountingDirection :: Down => i32:: from ( value) - i32:: from ( period) ,
133140 }
134141 }
@@ -140,10 +147,14 @@ pub trait HrCapture {
140147
141148pub fn dma_value_to_dir_and_value ( x : u32 ) -> ( u16 , CountingDirection ) {
142149 let value = ( x & 0xFFFF ) as u16 ;
150+ #[ cfg( feature = "hrtim_v2" ) ]
143151 match x & ( 1 << 16 ) != 0 {
144152 true => ( value, CountingDirection :: Down ) ,
145153 false => ( value, CountingDirection :: Up ) ,
146154 }
155+
156+ #[ cfg( any( feature = "hrtim_v1" , feature = "hrtim_v1_1" ) ) ]
157+ ( value, CountingDirection :: Up )
147158}
148159
149160pub fn dma_value_to_signed ( x : u32 , period : u16 ) -> i32 {
@@ -152,6 +163,7 @@ pub fn dma_value_to_signed(x: u32, period: u16) -> i32 {
152163 // The capture counter always counts up and restarts at period
153164 match dir {
154165 CountingDirection :: Up => i32:: from ( value) ,
166+ #[ cfg( feature = "hrtim_v2" ) ]
155167 CountingDirection :: Down => i32:: from ( value) - i32:: from ( period) ,
156168 }
157169}
@@ -219,10 +231,14 @@ macro_rules! impl_capture {
219231 let tim = unsafe { & * $TIMX:: ptr( ) } ;
220232 let data = tim. $cptXr( ) . read( ) ;
221233
234+ #[ cfg( feature = "hrtim_v2" ) ]
222235 let dir = match data. dir( ) . bit( ) {
223236 true => CountingDirection :: Down ,
224237 false => CountingDirection :: Up ,
225238 } ;
239+ #[ cfg( any( feature = "hrtim_v1" , feature = "hrtim_v1_1" ) ) ]
240+ let dir = CountingDirection :: Up ;
241+
226242 let value = data. cpt( ) . bits( ) ;
227243
228244 ( value, dir)
@@ -243,7 +259,8 @@ macro_rules! impl_capture {
243259 }
244260 }
245261
246- unsafe impl <PSCL > TargetAddress <PeripheralToMemory > for HrCapt <$TIMX, PSCL , $CH, Dma > {
262+ #[ cfg( feature = "stm32g4" ) ]
263+ unsafe impl <PSCL > crate :: hal:: dma:: traits:: TargetAddress <PeripheralToMemory > for HrCapt <$TIMX, PSCL , $CH, Dma > {
247264 #[ inline( always) ]
248265 fn address( & self ) -> u32 {
249266 let tim = unsafe { & * $TIMX:: ptr( ) } ;
@@ -262,6 +279,10 @@ impl_capture! {
262279 HRTIM_TIMB ,
263280 HRTIM_TIMC ,
264281 HRTIM_TIMD ,
265- HRTIM_TIME ,
282+ HRTIM_TIME
283+ }
284+
285+ #[ cfg( feature = "hrtim_v2" ) ]
286+ impl_capture ! {
266287 HRTIM_TIMF
267288}
0 commit comments