@@ -134,22 +134,10 @@ impl<State> Adc<State> {
134
134
while self . rb . cr . read ( ) . aden ( ) . bit_is_set ( ) { }
135
135
}
136
136
137
- fn write_smpr ( & mut self ) {
138
- self . rb
139
- . smpr
140
- . modify ( |_, w| w. smp ( ) . bits ( self . sample_time as u8 ) ) ;
141
- }
142
- }
143
-
144
- impl < WORD , PIN > OneShot < Adc < Ready > , WORD , PIN > for Adc < Ready >
145
- where
146
- WORD : From < u16 > ,
147
- PIN : Channel < Adc < Ready > , ID = u8 > ,
148
- {
149
- type Error = ( ) ;
150
-
151
- fn read ( & mut self , _pin : & mut PIN ) -> nb:: Result < WORD , Self :: Error > {
152
- self . power_up ( ) ;
137
+ fn configure < Chan > ( & mut self , _channel : & Chan )
138
+ where
139
+ Chan : Channel < Adc < Ready > , ID =u8 > ,
140
+ {
153
141
self . rb . cfgr1 . modify ( |_, w| {
154
142
// Safe, as `self.precision` is of type `Precision`, which defines
155
143
// only valid values.
@@ -160,15 +148,32 @@ where
160
148
w. align ( ) . bit ( self . align == Align :: Left )
161
149
} ) ;
162
150
163
- self . write_smpr ( ) ;
151
+ self . rb
152
+ . smpr
153
+ . modify ( |_, w| w. smp ( ) . bits ( self . sample_time as u8 ) ) ;
164
154
165
155
self . rb . chselr . write ( |w|
166
156
// Safe, as long as there are no `Channel` implementations that
167
157
// define invalid values.
168
- unsafe { w. bits ( 0b1 << PIN :: channel ( ) ) } ) ;
158
+ unsafe { w. bits ( 0b1 << Chan :: channel ( ) ) }
159
+ ) ;
169
160
170
161
self . rb . isr . modify ( |_, w| w. eos ( ) . set_bit ( ) ) ;
171
162
self . rb . cr . modify ( |_, w| w. adstart ( ) . set_bit ( ) ) ;
163
+ }
164
+ }
165
+
166
+ impl < WORD , PIN > OneShot < Adc < Ready > , WORD , PIN > for Adc < Ready >
167
+ where
168
+ WORD : From < u16 > ,
169
+ PIN : Channel < Adc < Ready > , ID = u8 > ,
170
+ {
171
+ type Error = ( ) ;
172
+
173
+ fn read ( & mut self , pin : & mut PIN ) -> nb:: Result < WORD , Self :: Error > {
174
+ self . power_up ( ) ;
175
+ self . configure ( pin) ;
176
+
172
177
while self . rb . isr . read ( ) . eos ( ) . bit_is_clear ( ) { }
173
178
174
179
let res = self . rb . dr . read ( ) . bits ( ) as u16 ;
0 commit comments