@@ -75,16 +75,17 @@ pub enum AsyncClockDiv {
75
75
/// ADC injected trigger source selection
76
76
#[ derive( Copy , Clone , PartialEq ) ]
77
77
pub enum InjTrigSource {
78
- TRG_0 = 0b000 , // TIM1_TRGO2
79
- TRG_1 = 0b001 , // TIM1_CC4
80
- TRG_2 = 0b010 , // TIM2_TRGO
81
- TRG_3 = 0b011 , // TIM3_TRGO
82
- TRG_4 = 0b100 , // TIM15_TRGO
83
- TRG_5 = 0b101 , // TIM6_TRGO
84
- TRG_6 = 0b110 , // TIM4_TRGO
85
- TRG_7 = 0b111 , // EXTI11
78
+ TRG_0 = 0b000 , // TIM1_TRGO2
79
+ TRG_1 = 0b001 , // TIM1_CC4
80
+ TRG_2 = 0b010 , // TIM2_TRGO
81
+ TRG_3 = 0b011 , // TIM3_TRGO
82
+ TRG_4 = 0b100 , // TIM15_TRGO
83
+ TRG_5 = 0b101 , // TIM6_TRGO
84
+ TRG_6 = 0b110 , // TIM4_TRGO
85
+ TRG_7 = 0b111 , // EXTI11
86
86
}
87
87
88
+
88
89
/// Analog to Digital converter interface
89
90
pub struct Adc {
90
91
rb : ADC ,
@@ -193,10 +194,8 @@ impl Adc {
193
194
}
194
195
195
196
/// The nuber of bits, the oversampling result is shifted in bits at the end of oversampling
196
- pub fn set_oversamling_shift ( & mut self , nrbits : u8 ) {
197
- self . rb
198
- . cfgr2
199
- . modify ( |_, w| unsafe { w. ovss ( ) . bits ( nrbits) } ) ;
197
+ pub fn set_oversamling_shift ( & mut self , nrbits : u8 ) {
198
+ self . rb . cfgr2 . modify ( |_, w| unsafe { w. ovss ( ) . bits ( nrbits) } ) ;
200
199
}
201
200
202
201
/// Oversampling of adc according to datasheet of stm32g0, when oversampling is enabled
@@ -209,27 +208,25 @@ impl Adc {
209
208
/// 110: 128x
210
209
/// 111: 256x
211
210
212
- pub fn set_oversamling_ratio ( & mut self , multyply : u8 ) {
213
- self . rb
214
- . cfgr2
215
- . modify ( |_, w| unsafe { w. ovsr ( ) . bits ( multyply) } ) ;
211
+ pub fn set_oversamling_ratio ( & mut self , multyply : u8 ) {
212
+ self . rb . cfgr2 . modify ( |_, w| unsafe { w. ovsr ( ) . bits ( multyply) } ) ;
216
213
}
217
214
218
215
pub fn oversamling_enable ( & mut self ) {
219
- self . rb . cfgr2 . modify ( |_, w| unsafe { w. ovse ( ) . set_bit ( ) } ) ;
216
+ self . rb . cfgr2 . modify ( |_, w| unsafe { w. ovse ( ) . set_bit ( ) } ) ;
220
217
}
221
218
222
219
pub fn start_injected ( & mut self ) {
223
- self . rb . cr . modify ( |_, w| w. adstart ( ) . set_bit ( ) ) ;
220
+ self . rb . cr . modify ( |_, w| w. adstart ( ) . set_bit ( ) ) ;
224
221
// ADSTART bit is cleared to 0 bevor using this function
225
222
// enable self.rb.isr.eos() flag is set after each converstion
226
223
self . rb . ier . modify ( |_, w| w. eocie ( ) . set_bit ( ) ) ; // end of sequence interupt enable
227
224
}
228
225
229
- pub fn stop_injected ( & mut self ) {
230
- // ?????? or is it reset after each conversion?
226
+
227
+ pub fn stop_injected ( & mut self ) { // ?????? or is it reset after each conversion?
231
228
// ADSTART bit is cleared to 0 bevor using this function
232
- // disable EOS interrupt
229
+ // disable EOS interrupt
233
230
// maybe self.rb.cr.adstp().set_bit() must be performed before interrupt is disabled + wait abortion
234
231
self . rb . ier . modify ( |_, w| w. eocie ( ) . clear_bit ( ) ) ; // end of sequence interupt disable
235
232
}
@@ -258,32 +255,39 @@ where
258
255
{
259
256
type Error = ( ) ;
260
257
261
- fn prepare_injected ( & mut self , _pin : & mut PIN , triger_source : InjTrigSource ) {
262
- // set the clock mode to synchronous one
258
+ fn prepare_injected ( & mut self , _pin : & mut PIN , triger_source : InjTrigSource ) {
259
+ // set the clock mode to synchronous one
263
260
// self.rb.cfgr2.ckmode().bits(CLCOKMODE) // CLOCKMODE = 01 or 10 for PCLK/2 or PCLK/4
264
261
262
+
265
263
// self.set_injected_trigger_source(triger_source as InjTrigSource);
266
- self . rb
267
- . cfgr1
268
- . modify ( |_, w| unsafe { w. exten ( ) . bits ( 1 ) . extsel ( ) . bits ( triger_source as u8 ) } ) ;
264
+ self . rb . cfgr1 . modify ( |_, w| unsafe {
265
+ w. exten ( )
266
+ . bits ( 1 )
267
+ . extsel ( )
268
+ . bits ( triger_source as u8 )
269
+ } ) ;
269
270
270
271
self . rb . cfgr1 . modify ( |_, w| unsafe {
271
- w. res ( ) // set ADC resolution bits (ADEN must be =0)
272
+ w. res ( ) // set ADC resolution bits (ADEN must be =0)
272
273
. bits ( self . precision as u8 )
273
- . align ( ) // set alignment bit is (ADSTART must be 0)
274
+ . align ( ) // set alignment bit is (ADSTART must be 0)
274
275
. bit ( self . align == Align :: Left )
275
276
} ) ;
276
277
277
278
self . power_up ( ) ;
278
279
279
280
self . rb
280
- . smpr // set sampling time set 1 (ADSTART must be 0)
281
+ . smpr // set sampling time set 1 (ADSTART must be 0)
281
282
. modify ( |_, w| unsafe { w. smp1 ( ) . bits ( self . sample_time as u8 ) } ) ;
282
283
283
284
self . rb
284
- . chselr ( ) // set activ channel acording chapter 15.12.9 (ADC_CFGR1; CHSELRMOD=0)
285
+ . chselr ( ) // set activ channel acording chapter 15.12.9 (ADC_CFGR1; CHSELRMOD=0)
285
286
. modify ( |_, w| unsafe { w. chsel ( ) . bits ( 1 << PIN :: channel ( ) ) } ) ;
287
+
286
288
}
289
+
290
+
287
291
}
288
292
289
293
pub trait DmaMode < ADC > {
@@ -294,25 +298,27 @@ pub trait DmaMode<ADC> {
294
298
}
295
299
296
300
impl DmaMode < Adc > for Adc {
301
+
297
302
type Error = ( ) ;
298
303
299
304
fn dma_enable ( & mut self , enable : bool ) {
300
305
if enable {
301
- self . rb . cfgr1 . modify ( |_, w| w. dmaen ( ) . set_bit ( ) ) ; // enable dma beeing called
306
+ self . rb . cfgr1 . modify ( |_, w| w. dmaen ( ) . set_bit ( ) ) ; // enable dma beeing called
302
307
} else {
303
- self . rb . cfgr1 . modify ( |_, w| w. dmaen ( ) . clear_bit ( ) ) ; // disable dma beeing called
308
+ self . rb . cfgr1 . modify ( |_, w| w. dmaen ( ) . clear_bit ( ) ) ; // disable dma beeing called
304
309
}
305
310
}
306
-
311
+
307
312
fn dma_circualr_mode ( & mut self , enable : bool ) {
308
313
if enable {
309
- self . rb . cfgr1 . modify ( |_, w| w. dmacfg ( ) . set_bit ( ) ) ; // activate circular mode
314
+ self . rb . cfgr1 . modify ( |_, w| w. dmacfg ( ) . set_bit ( ) ) ; // activate circular mode
310
315
} else {
311
- self . rb . cfgr1 . modify ( |_, w| w. dmacfg ( ) . clear_bit ( ) ) ; // disable circular mode
316
+ self . rb . cfgr1 . modify ( |_, w| w. dmacfg ( ) . clear_bit ( ) ) ; // disable circular mode
312
317
}
313
318
}
314
319
}
315
320
321
+
316
322
impl < WORD , PIN > OneShot < Adc , WORD , PIN > for Adc
317
323
where
318
324
WORD : From < u16 > ,
0 commit comments