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