@@ -156,8 +156,8 @@ impl Adc<Ready> {
156
156
///
157
157
/// Panics, if `buffer` is larger than 65535.
158
158
#[ cfg( feature = "stm32l0x2" ) ]
159
- pub fn start < Chan , DmaChan , Buf > ( mut self ,
160
- channel : Chan ,
159
+ pub fn start < DmaChan , Buf > ( mut self ,
160
+ channels : impl Into < Channels > ,
161
161
trigger : Option < Trigger > ,
162
162
dma : & mut dma:: Handle ,
163
163
dma_chan : DmaChan ,
@@ -166,7 +166,6 @@ impl Adc<Ready> {
166
166
-> Adc < Active < DmaChan , Buf > >
167
167
where
168
168
DmaToken : dma:: Target < DmaChan > ,
169
- Chan : Channel < Self , ID =u8 > ,
170
169
Buf : DerefMut + ' static ,
171
170
Buf :: Target : AsMutSlice < Element =u16 > ,
172
171
DmaChan : dma:: Channel ,
@@ -214,7 +213,7 @@ impl Adc<Ready> {
214
213
let continous = trigger. is_none ( ) ;
215
214
216
215
self . power_up ( ) ;
217
- self . configure ( & channel , continous, trigger) ;
216
+ self . configure ( channels , continous, trigger) ;
218
217
219
218
Adc {
220
219
rb : self . rb ,
@@ -268,14 +267,11 @@ impl<State> Adc<State> {
268
267
while self . rb . cr . read ( ) . aden ( ) . bit_is_set ( ) { }
269
268
}
270
269
271
- fn configure < Chan > ( & mut self ,
272
- _channel : & Chan ,
270
+ fn configure ( & mut self ,
271
+ channels : impl Into < Channels > ,
273
272
cont : bool ,
274
273
trigger : Option < Trigger > ,
275
- )
276
- where
277
- Chan : Channel < Adc < Ready > , ID =u8 > ,
278
- {
274
+ ) {
279
275
self . rb . cfgr1 . write ( |w| {
280
276
w
281
277
. res ( ) . bits ( self . precision as u8 )
@@ -303,7 +299,7 @@ impl<State> Adc<State> {
303
299
self . rb . chselr . write ( |w|
304
300
// Safe, as long as there are no `Channel` implementations that
305
301
// define invalid values.
306
- unsafe { w. bits ( 0b1 << Chan :: channel ( ) ) }
302
+ unsafe { w. bits ( channels . into ( ) . flags ) }
307
303
) ;
308
304
309
305
self . rb . isr . modify ( |_, w| w. eos ( ) . set_bit ( ) ) ;
@@ -318,9 +314,9 @@ where
318
314
{
319
315
type Error = ( ) ;
320
316
321
- fn read ( & mut self , pin : & mut PIN ) -> nb:: Result < WORD , Self :: Error > {
317
+ fn read ( & mut self , _ : & mut PIN ) -> nb:: Result < WORD , Self :: Error > {
322
318
self . power_up ( ) ;
323
- self . configure ( pin , false , None ) ;
319
+ self . configure ( Channels { flags : 0x1 << PIN :: channel ( ) } , false , None ) ;
324
320
325
321
while self . rb . isr . read ( ) . eos ( ) . bit_is_clear ( ) { }
326
322
@@ -348,6 +344,33 @@ pub struct Active<DmaChan, Buf> {
348
344
}
349
345
350
346
347
+ /// A collection of channels
348
+ ///
349
+ /// Used to set up multi-channel conversions.
350
+ pub struct Channels {
351
+ flags : u32 ,
352
+ }
353
+
354
+ impl Channels {
355
+ /// Adds a channel to the collection
356
+ pub fn add < C > ( & mut self , _: C )
357
+ where C : Channel < Adc < Ready > , ID =u8 >
358
+ {
359
+ self . flags |= 0x1 << C :: channel ( )
360
+ }
361
+ }
362
+
363
+ impl < C > From < C > for Channels
364
+ where C : Channel < Adc < Ready > , ID =u8 >
365
+ {
366
+ fn from ( channel : C ) -> Self {
367
+ let mut c = Channels { flags : 0 } ;
368
+ c. add ( channel) ;
369
+ c
370
+ }
371
+ }
372
+
373
+
351
374
/// Hardware triggers that can start an ADC conversion
352
375
#[ repr( u8 ) ]
353
376
pub enum Trigger {
0 commit comments