@@ -15,10 +15,14 @@ use core::marker::PhantomData;
1515use core:: ops:: Deref ;
1616
1717use embedded_hal:: delay:: DelayNs ;
18- use stm32h5:: stm32h523:: ADCC ;
1918
2019use 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 } ;
2226
2327use crate :: pwr:: { self , VoltageScale } ;
2428//use crate::rcc::rec::AdcClkSelGetter;
@@ -32,9 +36,13 @@ pub trait Instance:
3236}
3337
3438impl crate :: Sealed for ADC1 { }
39+
40+ #[ cfg( feature = "rm0481" ) ]
3541impl crate :: Sealed for ADC2 { }
3642
3743impl Instance for ADC1 { }
44+
45+ #[ cfg( feature = "rm0481" ) ]
3846impl Instance for ADC2 { }
3947
4048#[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
@@ -194,7 +202,7 @@ impl AdcCalLinear {
194202/// Vref internal signal
195203#[ derive( Default ) ]
196204pub struct Vrefint ;
197- /// Vbat internal signal
205+ /// Vbat/4 (Vbat pin input voltage divided by 4) internal signal
198206#[ derive( Default ) ]
199207pub struct Vbat ;
200208/// Internal temperature sensor
@@ -263,13 +271,48 @@ fn kernel_clk_unwrap(
263271 }
264272}
265273
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+ }
268310
269311/// Initialise ADC12 together
270312///
271313/// Sets all configurable parameters to one-shot defaults,
272314/// performs a boot-time calibration.
315+ #[ cfg( feature = "rm0481" ) ]
273316pub fn adc12 (
274317 adc1 : ADC1 ,
275318 adc2 : ADC2 ,
@@ -308,28 +351,12 @@ pub fn adc12(
308351
309352 // From RM0481:
310353 // 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 ( ) ) ;
312355 adc2. rb . or ( ) . modify ( |_, w| w. op0 ( ) . set_bit ( ) ) ;
313356
314357 ( adc1, adc2)
315358}
316359
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-
333360impl < ADC : Instance > AdcExt < ADC > for ADC {
334361 type Rec = rec:: Adc ;
335362
0 commit comments