Clean up stmf0 adc init.
authorBart Massey <bart.massey@gmail.com>
Tue, 9 Feb 2016 02:55:28 +0000 (18:55 -0800)
committerKeith Packard <keithp@keithp.com>
Tue, 9 Feb 2016 02:55:28 +0000 (18:55 -0800)
This better matches the documented cal sequence.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/stmf0/ao_adc_fast.c

index 26e6691c914c87169d72905dbcdfe06ea393cca1..f6740b0e34733d557f745756e81ba8276dd4be9b 100644 (file)
@@ -83,7 +83,6 @@ void
 ao_adc_init(void)
 {
        uint32_t        chselr;
-       int             i;
 
        /* Reset ADC */
        stm_rcc.apb2rstr |= (1 << STM_RCC_APB2RSTR_ADCRST);
@@ -157,12 +156,13 @@ ao_adc_init(void)
        /* Shortest sample time */
        stm_adc.smpr = STM_ADC_SMPR_SMP_1_5 << STM_ADC_SMPR_SMP;
 
+       /* Turn off enable and start */
+       stm_adc.cr &= ~((1 << STM_ADC_CR_ADEN) | (1 << STM_ADC_CR_ADSTART));
+
        /* Calibrate */
        stm_adc.cr |= (1 << STM_ADC_CR_ADCAL);
-       for (i = 0; i < 0xf000; i++) {
-               if ((stm_adc.cr & (1 << STM_ADC_CR_ADCAL)) == 0)
-                       break;
-       }
+       while ((stm_adc.cr & (1 << STM_ADC_CR_ADCAL)) != 0)
+               ;
 
        /* Enable */
        stm_adc.cr |= (1 << STM_ADC_CR_ADEN);