66*/
77use core:: marker:: PhantomData ;
88
9- #[ cfg( any( feature = "stm32f100" , feature = "stm32f103" , feature = "connectivity" , ) ) ]
10- use crate :: pac:: TIM1 ;
11- #[ cfg( feature = "medium" ) ]
12- use crate :: pac:: TIM4 ;
13- use crate :: pac:: { TIM2 , TIM3 } ;
9+ use crate :: pac;
1410use embedded_hal_02 as hal;
1511pub use hal:: Direction ;
1612
@@ -70,16 +66,16 @@ pub struct Qei<TIM, REMAP, PINS> {
7066 _remap : PhantomData < REMAP > ,
7167}
7268
73- #[ cfg( any( feature = "stm32f100" , feature = "stm32f103" , feature = "connectivity" , ) ) ]
74- impl Timer < TIM1 > {
69+ #[ cfg( any( feature = "stm32f100" , feature = "stm32f103" , feature = "connectivity" ) ) ]
70+ impl Timer < pac :: TIM1 > {
7571 pub fn qei < REMAP , PINS > (
7672 self ,
7773 pins : PINS ,
7874 mapr : & mut MAPR ,
7975 options : QeiOptions ,
80- ) -> Qei < TIM1 , REMAP , PINS >
76+ ) -> Qei < pac :: TIM1 , REMAP , PINS >
8177 where
82- REMAP : Remap < Periph = TIM1 > ,
78+ REMAP : Remap < Periph = pac :: TIM1 > ,
8379 PINS : Pins < REMAP > ,
8480 {
8581 mapr. modify_mapr ( |_, w| unsafe { w. tim1_remap ( ) . bits ( REMAP :: REMAP ) } ) ;
@@ -89,15 +85,15 @@ impl Timer<TIM1> {
8985 }
9086}
9187
92- impl Timer < TIM2 > {
88+ impl Timer < pac :: TIM2 > {
9389 pub fn qei < REMAP , PINS > (
9490 self ,
9591 pins : PINS ,
9692 mapr : & mut MAPR ,
9793 options : QeiOptions ,
98- ) -> Qei < TIM2 , REMAP , PINS >
94+ ) -> Qei < pac :: TIM2 , REMAP , PINS >
9995 where
100- REMAP : Remap < Periph = TIM2 > ,
96+ REMAP : Remap < Periph = pac :: TIM2 > ,
10197 PINS : Pins < REMAP > ,
10298 {
10399 mapr. modify_mapr ( |_, w| unsafe { w. tim2_remap ( ) . bits ( REMAP :: REMAP ) } ) ;
@@ -107,15 +103,15 @@ impl Timer<TIM2> {
107103 }
108104}
109105
110- impl Timer < TIM3 > {
106+ impl Timer < pac :: TIM3 > {
111107 pub fn qei < REMAP , PINS > (
112108 self ,
113109 pins : PINS ,
114110 mapr : & mut MAPR ,
115111 options : QeiOptions ,
116- ) -> Qei < TIM3 , REMAP , PINS >
112+ ) -> Qei < pac :: TIM3 , REMAP , PINS >
117113 where
118- REMAP : Remap < Periph = TIM3 > ,
114+ REMAP : Remap < Periph = pac :: TIM3 > ,
119115 PINS : Pins < REMAP > ,
120116 {
121117 mapr. modify_mapr ( |_, w| unsafe { w. tim3_remap ( ) . bits ( REMAP :: REMAP ) } ) ;
@@ -126,15 +122,15 @@ impl Timer<TIM3> {
126122}
127123
128124#[ cfg( feature = "medium" ) ]
129- impl Timer < TIM4 > {
125+ impl Timer < pac :: TIM4 > {
130126 pub fn qei < REMAP , PINS > (
131127 self ,
132128 pins : PINS ,
133129 mapr : & mut MAPR ,
134130 options : QeiOptions ,
135- ) -> Qei < TIM4 , REMAP , PINS >
131+ ) -> Qei < pac :: TIM4 , REMAP , PINS >
136132 where
137- REMAP : Remap < Periph = TIM4 > ,
133+ REMAP : Remap < Periph = pac :: TIM4 > ,
138134 PINS : Pins < REMAP > ,
139135 {
140136 mapr. modify_mapr ( |_, w| w. tim4_remap ( ) . bit ( REMAP :: REMAP == 1 ) ) ;
@@ -145,68 +141,61 @@ impl Timer<TIM4> {
145141}
146142
147143macro_rules! hal {
148- ( $( $TIMX: ident: ( $timX: ident, $timXen: ident, $timXrst: ident) , ) +) => {
149- $(
150- impl <REMAP , PINS > Qei <$TIMX, REMAP , PINS > {
151- fn $timX( tim: $TIMX, pins: PINS , options: QeiOptions ) -> Self {
152- // Configure TxC1 and TxC2 as captures
153- tim. ccmr1_input( ) . write( |w| w. cc1s( ) . ti1( ) . cc2s( ) . ti2( ) ) ;
154-
155- // enable and configure to capture on rising edge
156- tim. ccer( ) . write( |w| {
157- w. cc1e( )
158- . set_bit( )
159- . cc1p( )
160- . clear_bit( )
161- . cc2e( )
162- . set_bit( )
163- . cc2p( )
164- . clear_bit( )
165- } ) ;
166-
167- // configure as quadrature encoder
168- tim. smcr( ) . write( |w| w. sms( ) . set( options. slave_mode as u8 ) ) ;
169-
170- tim. arr( ) . write( |w| w. arr( ) . set( options. auto_reload_value) ) ;
171- tim. cr1( ) . write( |w| w. cen( ) . set_bit( ) ) ;
172-
173- Qei { tim, pins, _remap: PhantomData }
144+ ( $TIMX: ty: $timX: ident, $timXen: ident, $timXrst: ident) => {
145+ impl <REMAP , PINS > Qei <$TIMX, REMAP , PINS > {
146+ fn $timX( tim: $TIMX, pins: PINS , options: QeiOptions ) -> Self {
147+ // Configure TxC1 and TxC2 as captures
148+ tim. ccmr1_input( ) . write( |w| w. cc1s( ) . ti1( ) . cc2s( ) . ti2( ) ) ;
149+
150+ // enable and configure to capture on rising edge
151+ tim. ccer( ) . write( |w| {
152+ w. cc1e( ) . set_bit( ) ;
153+ w. cc1p( ) . clear_bit( ) ;
154+ w. cc2e( ) . set_bit( ) ;
155+ w. cc2p( ) . clear_bit( )
156+ } ) ;
157+
158+ // configure as quadrature encoder
159+ tim. smcr( ) . write( |w| w. sms( ) . set( options. slave_mode as u8 ) ) ;
160+
161+ tim. arr( ) . write( |w| w. arr( ) . set( options. auto_reload_value) ) ;
162+ tim. cr1( ) . write( |w| w. cen( ) . set_bit( ) ) ;
163+
164+ Qei {
165+ tim,
166+ pins,
167+ _remap: PhantomData ,
174168 }
169+ }
175170
176- pub fn release( self ) -> ( $TIMX, PINS ) {
177- ( self . tim, self . pins)
178- }
171+ pub fn release( self ) -> ( $TIMX, PINS ) {
172+ ( self . tim, self . pins)
179173 }
174+ }
180175
181- impl <REMAP , PINS > hal:: Qei for Qei <$TIMX, REMAP , PINS > {
182- type Count = u16 ;
176+ impl <REMAP , PINS > hal:: Qei for Qei <$TIMX, REMAP , PINS > {
177+ type Count = u16 ;
183178
184- fn count( & self ) -> u16 {
185- self . tim. cnt( ) . read( ) . cnt( ) . bits( )
186- }
179+ fn count( & self ) -> u16 {
180+ self . tim. cnt( ) . read( ) . cnt( ) . bits( )
181+ }
187182
188- fn direction( & self ) -> Direction {
189- if self . tim. cr1( ) . read( ) . dir( ) . bit_is_clear( ) {
190- Direction :: Upcounting
191- } else {
192- Direction :: Downcounting
193- }
183+ fn direction( & self ) -> Direction {
184+ if self . tim. cr1( ) . read( ) . dir( ) . bit_is_clear( ) {
185+ Direction :: Upcounting
186+ } else {
187+ Direction :: Downcounting
194188 }
195189 }
196-
197- ) +
198- }
190+ }
191+ } ;
199192}
200193
201- #[ cfg( any( feature = "stm32f100" , feature = "stm32f103" , feature = "connectivity" , ) ) ]
202- hal ! {
203- TIM1 : ( _tim1, tim1en, tim1rst) ,
204- }
205- hal ! {
206- TIM2 : ( _tim2, tim2en, tim2rst) ,
207- TIM3 : ( _tim3, tim3en, tim3rst) ,
208- }
194+ #[ cfg( any( feature = "stm32f100" , feature = "stm32f103" , feature = "connectivity" ) ) ]
195+ hal ! ( pac:: TIM1 : _tim1, tim1en, tim1rst) ;
196+
197+ hal ! ( pac:: TIM2 : _tim2, tim2en, tim2rst) ;
198+ hal ! ( pac:: TIM3 : _tim3, tim3en, tim3rst) ;
199+
209200#[ cfg( feature = "medium" ) ]
210- hal ! {
211- TIM4 : ( _tim4, tim4en, tim4rst) ,
212- }
201+ hal ! ( pac:: TIM4 : _tim4, tim4en, tim4rst) ;
0 commit comments