@@ -15,10 +15,14 @@ use core::marker::PhantomData;
15
15
use core:: ops:: Deref ;
16
16
17
17
use embedded_hal:: delay:: DelayNs ;
18
- use stm32h5:: stm32h523:: ADCC ;
19
18
20
19
use crate :: rcc:: rec:: AdcDacClkSelGetter ;
21
- use crate :: stm32:: { ADC1 , ADC2 } ;
20
+
21
+ #[ cfg( feature = "rm0492" ) ]
22
+ use crate :: stm32:: { ADC1 , ADC1 as ADCC } ;
23
+
24
+ #[ cfg( feature = "rm0481" ) ]
25
+ use crate :: stm32:: { ADC1 , ADC2 , ADCC } ;
22
26
23
27
use crate :: pwr:: { self , VoltageScale } ;
24
28
//use crate::rcc::rec::AdcClkSelGetter;
@@ -32,9 +36,13 @@ pub trait Instance:
32
36
}
33
37
34
38
impl crate :: Sealed for ADC1 { }
39
+
40
+ #[ cfg( feature = "rm0481" ) ]
35
41
impl crate :: Sealed for ADC2 { }
36
42
37
43
impl Instance for ADC1 { }
44
+
45
+ #[ cfg( feature = "rm0481" ) ]
38
46
impl Instance for ADC2 { }
39
47
40
48
#[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
@@ -194,7 +202,7 @@ impl AdcCalLinear {
194
202
/// Vref internal signal
195
203
#[ derive( Default ) ]
196
204
pub struct Vrefint ;
197
- /// Vbat internal signal
205
+ /// Vbat/4 (Vbat pin input voltage divided by 4) internal signal
198
206
#[ derive( Default ) ]
199
207
pub struct Vbat ;
200
208
/// Internal temperature sensor
@@ -263,13 +271,48 @@ fn kernel_clk_unwrap(
263
271
}
264
272
}
265
273
266
- // ADC12 is a unique case where a single reset line is used to control two
267
- // peripherals that have separate peripheral definitions in the SVD.
274
+ #[ cfg( feature = "rm0492" ) ]
275
+ pub fn adc1 (
276
+ adc1 : ADC1 ,
277
+ f_adc : impl Into < Hertz > ,
278
+ delay : & mut impl DelayNs ,
279
+ prec : rec:: Adc ,
280
+ clocks : & CoreClocks ,
281
+ pwrcfg : & pwr:: PowerConfiguration ,
282
+ ) -> Adc < ADC1 , Disabled > {
283
+ // Consume ADC register block, produce ADC1/2 with default settings
284
+ let mut adc1 = Adc :: < ADC1 , Disabled > :: default_from_rb ( adc1) ;
285
+
286
+ // Check adc_ker_ck_input
287
+ kernel_clk_unwrap ( & prec, clocks) ;
288
+
289
+ // Enable AHB clock
290
+ let prec = prec. enable ( ) ;
291
+
292
+ // Power Down
293
+ adc1. power_down ( ) ;
294
+
295
+ // Reset peripheral
296
+ let prec = prec. reset ( ) ;
297
+
298
+ // Power Up, Preconfigure and Calibrate
299
+ adc1. power_up ( delay) ;
300
+ adc1. configure_clock ( f_adc. into ( ) , prec, clocks, pwrcfg) ; // ADC12_COMMON
301
+ adc1. preconfigure ( ) ;
302
+ adc1. calibrate ( ) ;
303
+
304
+ // From RM0481:
305
+ // This option bit must be set to 1 when ADCx_INP0 or ADCx_INN1 channel is selected
306
+ adc1. rb . or ( ) . modify ( |_, w| w. op0 ( ) . set_bit ( ) ) ;
307
+
308
+ adc1
309
+ }
268
310
269
311
/// Initialise ADC12 together
270
312
///
271
313
/// Sets all configurable parameters to one-shot defaults,
272
314
/// performs a boot-time calibration.
315
+ #[ cfg( feature = "rm0481" ) ]
273
316
pub fn adc12 (
274
317
adc1 : ADC1 ,
275
318
adc2 : ADC2 ,
@@ -308,28 +351,12 @@ pub fn adc12(
308
351
309
352
// From RM0481:
310
353
// This option bit must be set to 1 when ADCx_INP0 or ADCx_INN1 channel is selected
311
- adc2 . rb . or ( ) . modify ( |_, w| w. op0 ( ) . set_bit ( ) ) ;
354
+ adc1 . rb . or ( ) . modify ( |_, w| w. op0 ( ) . set_bit ( ) ) ;
312
355
adc2. rb . or ( ) . modify ( |_, w| w. op0 ( ) . set_bit ( ) ) ;
313
356
314
357
( adc1, adc2)
315
358
}
316
359
317
- /// Free both ADC1 and ADC2 along with PREC.
318
- ///
319
- /// Since ADC1 and ADC2 are controlled together, they are freed together.
320
- pub fn free_adc12 < ED > (
321
- adc1 : Adc < ADC1 , ED > ,
322
- adc2 : Adc < ADC2 , ED > ,
323
- ) -> ( ADC1 , ADC2 , rec:: Adc ) {
324
- (
325
- adc1. rb ,
326
- adc2. rb ,
327
- rec:: Adc {
328
- _marker : PhantomData ,
329
- } ,
330
- )
331
- }
332
-
333
360
impl < ADC : Instance > AdcExt < ADC > for ADC {
334
361
type Rec = rec:: Adc ;
335
362
0 commit comments