/** * @brief Low level ADC driver initialization. * * @notapi */ void adc_lld_init(void) { #if STM32_ADC_USE_ADC1 /* Driver initialization.*/ adcObjectInit(&ADCD1); ADCD1.adc = ADC1; ADCD1.dmastp = STM32_DMA1_STREAM1; ADCD1.dmamode = STM32_DMA_CR_PL(STM32_ADC_ADC1_DMA_PRIORITY) | STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MINC | STM32_DMA_CR_TCIE | STM32_DMA_CR_TEIE | STM32_DMA_CR_EN; /* Temporary activation.*/ rccEnableADC1(FALSE); ADC1->CR1 = 0; ADC1->CR2 = ADC_CR2_ADON; /* Reset calibration just to be safe.*/ ADC1->CR2 = ADC_CR2_ADON | ADC_CR2_RSTCAL; while ((ADC1->CR2 & ADC_CR2_RSTCAL) != 0) ; /* Calibration.*/ ADC1->CR2 = ADC_CR2_ADON | ADC_CR2_CAL; while ((ADC1->CR2 & ADC_CR2_CAL) != 0) ; /* Return the ADC in low power mode.*/ ADC1->CR2 = 0; rccDisableADC1(FALSE); #endif }
/** * @brief Low level ADC driver initialization. * * @notapi */ void adc_lld_init(void) { #if STM32_ADC_USE_ADC1 /* Driver initialization.*/ adcObjectInit(&ADCD1); ADCD1.adc = ADC1; ADCD1.dmastp = STM32_DMA1_STREAM1; ADCD1.dmamode = STM32_DMA_CR_PL(STM32_ADC_ADC1_DMA_PRIORITY) | STM32_DMA_CR_DIR_P2M | STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MINC | STM32_DMA_CR_TCIE | STM32_DMA_CR_DMEIE | STM32_DMA_CR_TEIE; #endif /* The shared vector is initialized on driver initialization and never disabled.*/ nvicEnableVector(12, STM32_ADC_IRQ_PRIORITY); /* Calibration procedure.*/ rccEnableADC1(FALSE); osalDbgAssert(ADC1->CR == 0, "invalid register state"); ADC1->CR |= ADC_CR_ADCAL; while (ADC1->CR & ADC_CR_ADCAL) ; rccDisableADC1(FALSE); }
/** * @brief Deactivates the ADC peripheral. * * @param[in] adcp pointer to the @p ADCDriver object * * @notapi */ void adc_lld_stop(ADCDriver *adcp) { /* If in ready state then disables the ADC clock.*/ if (adcp->state == ADC_READY) { #if STM32_ADC_USE_ADC1 if (&ADCD1 == adcp) { ADC1->CR1 = 0; ADC1->CR2 = 0; dmaStreamRelease(adcp->dmastp); rccDisableADC1(FALSE); } #endif } }
/** * @brief Deactivates the ADC peripheral. * * @param[in] adcp pointer to the @p ADCDriver object * * @notapi */ void adc_lld_stop(ADCDriver *adcp) { /* If in ready state then disables the ADC clock and analog part.*/ if (adcp->state == ADC_READY) { dmaStreamRelease(adcp->dmastp); adcp->adc->CR1 = 0; adcp->adc->CR2 = 0; #if STM32_ADC_USE_ADC1 if (&ADCD1 == adcp) rccDisableADC1(FALSE); #endif } }
/** * @brief Deactivates the ADC peripheral. * * @param[in] adcp pointer to the @p ADCDriver object * * @notapi */ void adc_lld_stop(ADCDriver *adcp) { /* If in ready state then disables the ADC clock.*/ if (adcp->state == ADC_READY) { dmaStreamRelease(adcp->dmastp); #if STM32_ADC_USE_ADC1 if (&ADCD1 == adcp) { adcp->adc->CR1 = 0; adcp->adc->CR2 = 0; rccDisableADC1(FALSE); } #endif #if STM32_ADC_USE_SDADC1 if (&SDADCD1 == adcp) { adcp->sdadc->CR1 = 0; adcp->sdadc->CR2 = 0; rccDisableSDADC1(FALSE); PWR->CR &= ~PWR_CR_SDADC1EN; } #endif #if STM32_ADC_USE_SDADC2 if (&SDADCD2 == adcp) { adcp->sdadc->CR1 = 0; adcp->sdadc->CR2 = 0; rccDisableSDADC2(FALSE); PWR->CR &= ~PWR_CR_SDADC2EN; } #endif #if STM32_ADC_USE_SDADC3 if (&SDADCD3 == adcp) { adcp->sdadc->CR1 = 0; adcp->sdadc->CR2 = 0; rccDisableSDADC3(FALSE); PWR->CR &= ~PWR_CR_SDADC3EN; } #endif } }
/** * @brief Deactivates the ADC peripheral. * * @param[in] adcp pointer to the @p ADCDriver object * * @notapi */ void adc_lld_stop(ADCDriver *adcp) { /* If in ready state then disables the ADC clock and analog part.*/ if (adcp->state == ADC_READY) { dmaStreamRelease(adcp->dmastp); /* Disabling ADC.*/ if (adcp->adc->CR & ADC_CR_ADEN) { adc_lld_stop_adc(adcp->adc); adcp->adc->CR |= ADC_CR_ADDIS; while (adcp->adc->CR & ADC_CR_ADDIS) ; } #if STM32_ADC_USE_ADC1 if (&ADCD1 == adcp) rccDisableADC1(FALSE); #endif } }
/** * @brief Deactivates the ADC peripheral. * * @param[in] adcp pointer to the @p ADCDriver object * * @notapi */ void adc_lld_stop(ADCDriver *adcp) { /* If in ready state then disables the ADC clock.*/ if (adcp->state == ADC_READY) { dmaStreamRelease(adcp->dmastp); adcp->adc->CR1 = 0; adcp->adc->CR2 = 0; #if STM32_ADC_USE_ADC1 if (&ADCD1 == adcp) rccDisableADC1(); #endif #if STM32_ADC_USE_ADC2 if (&ADCD2 == adcp) rccDisableADC2(); #endif #if STM32_ADC_USE_ADC3 if (&ADCD3 == adcp) rccDisableADC3(); #endif } }
void Adc_t::Disable() { ADC1->CR2 = 0; dmaStreamRelease(ADC_DMA); rccDisableADC1(FALSE); }