@@ -139,7 +139,12 @@ impl Adc<Ready> {
139
139
///
140
140
/// The `channel` argument specifies which channel should be converted.
141
141
///
142
- /// In addition to the preceeding argument that configures the ADC,
142
+ /// The `trigger` argument specifies the trigger that will start each
143
+ /// conversion sequence. This only configures the ADC peripheral to accept
144
+ /// this trigger. The trigger itself must also be configured using its own
145
+ /// peripheral API.
146
+ ///
147
+ /// In addition to the preceeding arguments that configure the ADC,
143
148
/// additional arguments are required to configure the DMA transfer that is
144
149
/// used to read the results from the ADC:
145
150
/// - `dma` is a handle to the DMA peripheral.
@@ -153,6 +158,7 @@ impl Adc<Ready> {
153
158
#[ cfg( feature = "stm32l0x2" ) ]
154
159
pub fn start < Chan , DmaChan , Buf > ( mut self ,
155
160
channel : Chan ,
161
+ trigger : Option < Trigger > ,
156
162
dma : & mut dma:: Handle ,
157
163
dma_chan : DmaChan ,
158
164
buffer : Pin < Buf > ,
@@ -205,8 +211,10 @@ impl Adc<Ready> {
205
211
}
206
212
. start ( ) ;
207
213
214
+ let continous = trigger. is_none ( ) ;
215
+
208
216
self . power_up ( ) ;
209
- self . configure ( & channel, true ) ;
217
+ self . configure ( & channel, continous , trigger ) ;
210
218
211
219
Adc {
212
220
rb : self . rb ,
@@ -260,7 +268,11 @@ impl<State> Adc<State> {
260
268
while self . rb . cr . read ( ) . aden ( ) . bit_is_set ( ) { }
261
269
}
262
270
263
- fn configure < Chan > ( & mut self , _channel : & Chan , cont : bool )
271
+ fn configure < Chan > ( & mut self ,
272
+ _channel : & Chan ,
273
+ cont : bool ,
274
+ trigger : Option < Trigger > ,
275
+ )
264
276
where
265
277
Chan : Channel < Adc < Ready > , ID =u8 > ,
266
278
{
@@ -272,7 +284,16 @@ impl<State> Adc<State> {
272
284
// DMA circular mode
273
285
. dmacfg ( ) . set_bit ( )
274
286
// Generate DMA requests
275
- . dmaen ( ) . set_bit ( )
287
+ . dmaen ( ) . set_bit ( ) ;
288
+
289
+ if let Some ( trigger) = trigger {
290
+ // Select hardware trigger
291
+ w. extsel ( ) . bits ( trigger as u8 ) ;
292
+ // Enable hardware trigger on rising edge
293
+ w. exten ( ) . rising_edge ( ) ;
294
+ }
295
+
296
+ w
276
297
} ) ;
277
298
278
299
self . rb
@@ -299,7 +320,7 @@ where
299
320
300
321
fn read ( & mut self , pin : & mut PIN ) -> nb:: Result < WORD , Self :: Error > {
301
322
self . power_up ( ) ;
302
- self . configure ( pin, false ) ;
323
+ self . configure ( pin, false , None ) ;
303
324
304
325
while self . rb . isr . read ( ) . eos ( ) . bit_is_clear ( ) { }
305
326
@@ -327,6 +348,38 @@ pub struct Active<DmaChan, Buf> {
327
348
}
328
349
329
350
351
+ /// Hardware triggers that can start an ADC conversion
352
+ #[ repr( u8 ) ]
353
+ pub enum Trigger {
354
+ /// TRG0
355
+ TIM6_TRGO = 0b000 ,
356
+
357
+ /// TRG1
358
+ TIM21_CH2 = 0b001 ,
359
+
360
+ /// TRG2
361
+ TIM2_TRGO = 0b010 ,
362
+
363
+ /// TRG3
364
+ TIM2_CH4 = 0b011 ,
365
+
366
+ /// TRG4
367
+ TIM22_TRGO = 0b100 ,
368
+
369
+ /// TRG5
370
+ ///
371
+ /// Only available on Category 5 devices.
372
+ #[ cfg( any( feature = "stm32l072" , feature = "stm32l082" ) ) ]
373
+ TIM2_CH3 = 0b101 ,
374
+
375
+ /// TRG6
376
+ TIM3_TRGO = 0b110 ,
377
+
378
+ /// TRG7
379
+ EXTI11 = 0b111 ,
380
+ }
381
+
382
+
330
383
/// Provides access to the buffer that the DMA writes ADC values into
331
384
///
332
385
/// Since the DMA transfer takes ownership of the buffer, we need to access it
0 commit comments