@@ -44,7 +44,6 @@ pub struct Adc<ADC> {
44
44
/// ADC Register
45
45
adc : ADC ,
46
46
clocks : Clocks ,
47
- clock_mode : ClockMode ,
48
47
operation_mode : Option < OperationMode > ,
49
48
}
50
49
@@ -124,39 +123,6 @@ pub enum OperationMode {
124
123
OneShot ,
125
124
}
126
125
127
- #[ derive( Clone , Copy , PartialEq ) ]
128
- /// ADC Clock Mode
129
- // TODO: Add Asynchronous mode
130
- #[ non_exhaustive]
131
- pub enum ClockMode {
132
- // /// Use Kernel Clock adc_ker_ck_input divided by PRESC. Asynchronous to AHB clock
133
- // Asynchronous,
134
- /// Use AHB clock rcc_hclk3. In this case rcc_hclk must equal sys_d1cpre_ck
135
- SyncDiv1 ,
136
- /// Use AHB clock rcc_hclk3 divided by 2
137
- SyncDiv2 ,
138
- /// Use AHB clock rcc_hclk3 divided by 4
139
- SyncDiv4 ,
140
- }
141
-
142
- impl Default for ClockMode {
143
- fn default ( ) -> Self {
144
- ClockMode :: SyncDiv2
145
- }
146
- }
147
-
148
- // ADC3_2 returns a pointer to a adc1_2 type, so this from is ok for both.
149
- impl From < ClockMode > for CKMODE_A {
150
- fn from ( clock_mode : ClockMode ) -> Self {
151
- match clock_mode {
152
- //ClockMode::Asynchronous => CKMODE_A::ASYNCHRONOUS,
153
- ClockMode :: SyncDiv1 => CKMODE_A :: SYNCDIV1 ,
154
- ClockMode :: SyncDiv2 => CKMODE_A :: SYNCDIV2 ,
155
- ClockMode :: SyncDiv4 => CKMODE_A :: SYNCDIV4 ,
156
- }
157
- }
158
- }
159
-
160
126
/// ADC data register alignment
161
127
#[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
162
128
#[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
@@ -311,22 +277,27 @@ where
311
277
///
312
278
pub fn new (
313
279
adc : ADC ,
314
- frequency : impl Into < Generic < u32 > > ,
280
+ // TODO: frequency is not a possible input
281
+ // Frequency can not be set per ADC peripheral, and therefor
282
+ // is no option for Adc::new()
283
+ // This has doe be configured with an external function,
284
+ // and thus is maye a candidate for a more general RccClocksManangement thingy.
285
+ // frequency: impl Into<Generic<u32>>,
286
+ clocks : Clocks ,
315
287
// adc_shared : &mut <ADC as Instance>::SharedInstance,
316
288
ahb : & mut AHB ,
317
- clocks : Clocks ,
318
289
) -> Self {
319
290
let mut adc = Self {
320
291
adc,
321
292
clocks,
322
- clock_mode : ClockMode :: SyncDiv1 ,
323
293
operation_mode : None ,
324
294
} ;
325
295
326
296
// if !(adc.clocks_welldefined(clocks)) {
327
297
// crate::panic!("Clock settings not well defined");
328
298
// }
329
299
300
+
330
301
ADC :: enable_clock ( ahb) ;
331
302
// if !(ADC::enable_clock(ahb)){
332
303
// crate::panic!("Clock already enabled with a different setting");
@@ -340,7 +311,7 @@ where
340
311
// ADEN bit cannot be set during ADCAL=1
341
312
// and 4 ADC clock cycle after the ADCAL
342
313
// bit is cleared by hardware
343
- adc. wait_adc_clk_cycles ( 4 ) ;
314
+ adc. wait_adc_clk_cycles ( 4 , clocks ) ;
344
315
adc. enable ( ) ;
345
316
346
317
adc
@@ -440,18 +411,15 @@ where
440
411
. modify ( |_, w| w. adcaldif ( ) . single_ended ( ) . adcal ( ) . calibration ( ) ) ;
441
412
442
413
while self . adc . cr . read ( ) . adcal ( ) . is_calibration ( ) { }
414
+ defmt:: info!( "{}" , & "hi" ) ;
443
415
}
444
416
445
- fn wait_adc_clk_cycles ( & self , cycles : u32 ) {
446
- // using a match statement here so compilation will fail once asynchronous clk
447
- // mode is implemented (CKMODE[1:0] = 00b). This will force whoever is working
448
- // on it to rethink what needs to be done here :)
449
- let adc_per_cpu_cycles = match self . clock_mode {
450
- ClockMode :: SyncDiv1 => 1 ,
451
- ClockMode :: SyncDiv2 => 2 ,
452
- ClockMode :: SyncDiv4 => 4 ,
453
- } ;
454
- asm:: delay ( adc_per_cpu_cycles * cycles) ;
417
+ fn wait_adc_clk_cycles ( & self , cycles : u32 , clocks : Clocks ) {
418
+ let frequency = ADC :: clock ( & clocks) ;
419
+ let cpu_cycles = cycles * clocks. sysclk ( ) . 0 / frequency. 0 ;
420
+ defmt:: info!( "{}" , cpu_cycles) ;
421
+
422
+ asm:: delay ( cpu_cycles) ;
455
423
}
456
424
457
425
fn advregen_enable ( & mut self ) {
0 commit comments