4
4
NOTE: In some cases you need to specify remap you need, especially for TIM2
5
5
(see [Alternate function remapping](super::timer)):
6
6
*/
7
- use core:: marker:: PhantomData ;
8
-
9
7
use crate :: pac;
10
8
use embedded_hal_02 as hal;
11
9
pub use hal:: Direction ;
12
10
13
- use crate :: afio:: MAPR ;
14
-
15
- use crate :: timer:: pwm_input:: Pins ;
16
- use crate :: timer:: { pins:: sealed:: Remap , Timer } ;
11
+ use crate :: rcc:: Clocks ;
12
+ use crate :: timer:: { InPins , InputPins , Timer } ;
17
13
18
14
/// SMS (Slave Mode Selection) register
19
15
#[ derive( Copy , Clone , Debug ) ]
@@ -60,90 +56,122 @@ impl Default for QeiOptions {
60
56
}
61
57
}
62
58
63
- pub struct Qei < TIM , REMAP , PINS > {
59
+ pub struct Qei < TIM : InputPins > {
64
60
tim : TIM ,
65
- pins : PINS ,
66
- _remap : PhantomData < REMAP > ,
61
+ pins : ( TIM :: InCh1 , TIM :: InCh2 ) ,
62
+ }
63
+
64
+ pub trait QeiExt : Sized + InputPins {
65
+ fn qei (
66
+ self ,
67
+ pins : impl Into < InPins < Self :: InCh1 , Self :: InCh2 > > ,
68
+ options : QeiOptions ,
69
+ clocks : & Clocks ,
70
+ ) -> Qei < Self > ;
67
71
}
68
72
69
73
#[ cfg( any( feature = "stm32f100" , feature = "stm32f103" , feature = "connectivity" ) ) ]
70
- impl Timer < pac:: TIM1 > {
71
- pub fn qei < REMAP , PINS > (
74
+ impl QeiExt for pac:: TIM1 {
75
+ fn qei (
72
76
self ,
73
- pins : PINS ,
74
- mapr : & mut MAPR ,
77
+ pins : impl Into < InPins < Self :: InCh1 , Self :: InCh2 > > ,
75
78
options : QeiOptions ,
76
- ) -> Qei < pac:: TIM1 , REMAP , PINS >
77
- where
78
- REMAP : Remap < Periph = pac:: TIM1 > ,
79
- PINS : Pins < REMAP > ,
80
- {
81
- mapr. modify_mapr ( |_, w| unsafe { w. tim1_remap ( ) . bits ( REMAP :: REMAP ) } ) ;
79
+ clocks : & Clocks ,
80
+ ) -> Qei < Self > {
81
+ Timer :: new ( self , clocks) . qei ( pins, options)
82
+ }
83
+ }
82
84
85
+ #[ cfg( any( feature = "stm32f100" , feature = "stm32f103" , feature = "connectivity" ) ) ]
86
+ impl Timer < pac:: TIM1 > {
87
+ pub fn qei (
88
+ self ,
89
+ pins : impl Into < InPins < <pac:: TIM1 as InputPins >:: InCh1 , <pac:: TIM1 as InputPins >:: InCh2 > > ,
90
+ options : QeiOptions ,
91
+ ) -> Qei < pac:: TIM1 > {
83
92
let Self { tim, clk : _ } = self ;
84
93
Qei :: _tim1 ( tim, pins, options)
85
94
}
86
95
}
87
96
88
- impl Timer < pac:: TIM2 > {
89
- pub fn qei < REMAP , PINS > (
97
+ impl QeiExt for pac:: TIM2 {
98
+ fn qei (
90
99
self ,
91
- pins : PINS ,
92
- mapr : & mut MAPR ,
100
+ pins : impl Into < InPins < Self :: InCh1 , Self :: InCh2 > > ,
93
101
options : QeiOptions ,
94
- ) -> Qei < pac:: TIM2 , REMAP , PINS >
95
- where
96
- REMAP : Remap < Periph = pac:: TIM2 > ,
97
- PINS : Pins < REMAP > ,
98
- {
99
- mapr. modify_mapr ( |_, w| unsafe { w. tim2_remap ( ) . bits ( REMAP :: REMAP ) } ) ;
102
+ clocks : & Clocks ,
103
+ ) -> Qei < Self > {
104
+ Timer :: new ( self , clocks) . qei ( pins, options)
105
+ }
106
+ }
100
107
108
+ impl Timer < pac:: TIM2 > {
109
+ pub fn qei (
110
+ self ,
111
+ pins : impl Into < InPins < <pac:: TIM2 as InputPins >:: InCh1 , <pac:: TIM2 as InputPins >:: InCh2 > > ,
112
+ options : QeiOptions ,
113
+ ) -> Qei < pac:: TIM2 > {
101
114
let Self { tim, clk : _ } = self ;
102
115
Qei :: _tim2 ( tim, pins, options)
103
116
}
104
117
}
105
118
106
- impl Timer < pac:: TIM3 > {
107
- pub fn qei < REMAP , PINS > (
119
+ impl QeiExt for pac:: TIM3 {
120
+ fn qei (
108
121
self ,
109
- pins : PINS ,
110
- mapr : & mut MAPR ,
122
+ pins : impl Into < InPins < Self :: InCh1 , Self :: InCh2 > > ,
111
123
options : QeiOptions ,
112
- ) -> Qei < pac:: TIM3 , REMAP , PINS >
113
- where
114
- REMAP : Remap < Periph = pac:: TIM3 > ,
115
- PINS : Pins < REMAP > ,
116
- {
117
- mapr. modify_mapr ( |_, w| unsafe { w. tim3_remap ( ) . bits ( REMAP :: REMAP ) } ) ;
124
+ clocks : & Clocks ,
125
+ ) -> Qei < Self > {
126
+ Timer :: new ( self , clocks) . qei ( pins, options)
127
+ }
128
+ }
118
129
130
+ impl Timer < pac:: TIM3 > {
131
+ pub fn qei (
132
+ self ,
133
+ pins : impl Into < InPins < <pac:: TIM3 as InputPins >:: InCh1 , <pac:: TIM3 as InputPins >:: InCh2 > > ,
134
+ options : QeiOptions ,
135
+ ) -> Qei < pac:: TIM3 > {
119
136
let Self { tim, clk : _ } = self ;
120
137
Qei :: _tim3 ( tim, pins, options)
121
138
}
122
139
}
123
140
124
141
#[ cfg( feature = "medium" ) ]
125
- impl Timer < pac:: TIM4 > {
126
- pub fn qei < REMAP , PINS > (
142
+ impl QeiExt for pac:: TIM4 {
143
+ fn qei (
127
144
self ,
128
- pins : PINS ,
129
- mapr : & mut MAPR ,
145
+ pins : impl Into < InPins < Self :: InCh1 , Self :: InCh2 > > ,
130
146
options : QeiOptions ,
131
- ) -> Qei < pac:: TIM4 , REMAP , PINS >
132
- where
133
- REMAP : Remap < Periph = pac:: TIM4 > ,
134
- PINS : Pins < REMAP > ,
135
- {
136
- mapr. modify_mapr ( |_, w| w. tim4_remap ( ) . bit ( REMAP :: REMAP == 1 ) ) ;
147
+ clocks : & Clocks ,
148
+ ) -> Qei < Self > {
149
+ Timer :: new ( self , & clocks) . qei ( pins, options)
150
+ }
151
+ }
137
152
153
+ #[ cfg( feature = "medium" ) ]
154
+ impl Timer < pac:: TIM4 > {
155
+ pub fn qei (
156
+ self ,
157
+ pins : impl Into < InPins < <pac:: TIM4 as InputPins >:: InCh1 , <pac:: TIM4 as InputPins >:: InCh2 > > ,
158
+ options : QeiOptions ,
159
+ ) -> Qei < pac:: TIM4 > {
138
160
let Self { tim, clk : _ } = self ;
139
161
Qei :: _tim4 ( tim, pins, options)
140
162
}
141
163
}
142
164
143
165
macro_rules! hal {
144
166
( $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 {
167
+ impl Qei <$TIMX> {
168
+ fn $timX(
169
+ tim: $TIMX,
170
+ pins: impl Into <InPins <<$TIMX as InputPins >:: InCh1 , <$TIMX as InputPins >:: InCh2 >>,
171
+ options: QeiOptions ,
172
+ ) -> Self {
173
+ let pins = pins. into( ) ;
174
+
147
175
// Configure TxC1 and TxC2 as captures
148
176
tim. ccmr1_input( ) . write( |w| w. cc1s( ) . ti1( ) . cc2s( ) . ti2( ) ) ;
149
177
@@ -163,17 +191,21 @@ macro_rules! hal {
163
191
164
192
Qei {
165
193
tim,
166
- pins,
167
- _remap: PhantomData ,
194
+ pins: ( pins. c1, pins. c2) ,
168
195
}
169
196
}
170
197
171
- pub fn release( self ) -> ( $TIMX, PINS ) {
198
+ pub fn release(
199
+ self ,
200
+ ) -> (
201
+ $TIMX,
202
+ ( <$TIMX as InputPins >:: InCh1 , <$TIMX as InputPins >:: InCh2 ) ,
203
+ ) {
172
204
( self . tim, self . pins)
173
205
}
174
206
}
175
207
176
- impl < REMAP , PINS > hal:: Qei for Qei <$TIMX, REMAP , PINS > {
208
+ impl hal:: Qei for Qei <$TIMX> {
177
209
type Count = u16 ;
178
210
179
211
fn count( & self ) -> u16 {
0 commit comments