/** * @brief Initializes the ADC1 peripheral according to the specified parameters * @param[in] ADC1_ConversionMode: specifies the conversion mode * can be one of the values of @ref ADC1_ConvMode_TypeDef. * @param[in] ADC1_Channel: specifies the channel to convert * can be one of the values of @ref ADC1_Channel_TypeDef. * @param[in] ADC1_PrescalerSelection: specifies the ADC1 prescaler * can be one of the values of @ref ADC1_PresSel_TypeDef. * @param[in] ADC1_ExtTrigger: specifies the external trigger * can be one of the values of @ref ADC1_ExtTrig_TypeDef. * @param[in] ADC1_ExtTriggerState: specifies the external trigger new state * can be one of the values of @ref FunctionalState. * @param[in] ADC1_Align: specifies the converted data alignement * can be one of the values of @ref ADC1_Align_TypeDef. * @param[in] ADC1_SchmittTriggerChannel: specifies the schmitt trigger channel * can be one of the values of @ref ADC1_SchmittTrigg_TypeDef. * @param[in] ADC1_SchmittTriggerState: specifies the schmitt trigger state * can be one of the values of @ref FunctionalState. * @retval None */ void ADC1_Init(ADC1_ConvMode_TypeDef ADC1_ConversionMode, ADC1_Channel_TypeDef ADC1_Channel, ADC1_PresSel_TypeDef ADC1_PrescalerSelection, ADC1_ExtTrig_TypeDef ADC1_ExtTrigger, FunctionalState ADC1_ExtTriggerState, ADC1_Align_TypeDef ADC1_Align, ADC1_SchmittTrigg_TypeDef ADC1_SchmittTriggerChannel, FunctionalState ADC1_SchmittTriggerState) { /* Check the parameters */ assert_param(IS_ADC1_CONVERSIONMODE_OK(ADC1_ConversionMode)); assert_param(IS_ADC1_CHANNEL_OK(ADC1_Channel)); assert_param(IS_ADC1_PRESSEL_OK(ADC1_PrescalerSelection)); assert_param(IS_ADC1_EXTTRIG_OK(ADC1_ExtTrigger)); assert_param(IS_FUNCTIONALSTATE_OK(((ADC1_ExtTriggerState)))); assert_param(IS_ADC1_ALIGN_OK(ADC1_Align)); assert_param(IS_ADC1_SCHMITTTRIG_OK(ADC1_SchmittTriggerChannel)); assert_param(IS_FUNCTIONALSTATE_OK(ADC1_SchmittTriggerState)); /*-----------------CR1 & CSR configuration --------------------*/ /* Configure the conversion mode and the channel to convert respectively according to ADC1_ConversionMode & ADC1_Channel values & ADC1_Align values */ ADC1_ConversionConfig(ADC1_ConversionMode, ADC1_Channel, ADC1_Align); /* Select the prescaler division factor according to ADC1_PrescalerSelection values */ ADC1_PrescalerConfig(ADC1_PrescalerSelection); /*-----------------CR2 configuration --------------------*/ /* Configure the external trigger state and event respectively according to NewState, ADC1_ExtTrigger */ ADC1_ExternalTriggerConfig(ADC1_ExtTrigger, ADC1_ExtTriggerState); /*------------------TDR configuration ---------------------------*/ /* Configure the schmitt trigger channel and state respectively according to ADC1_SchmittTriggerChannel & ADC1_SchmittTriggerNewState values */ ADC1_SchmittTriggerConfig(ADC1_SchmittTriggerChannel, ADC1_SchmittTriggerState); /* Enable the ADC1 peripheral */ ADC1->CR1 |= ADC1_CR1_ADON; }
/** * @brief Configure the ADC1 prescaler division factor. * @param ADC1_Prescaler: the selected precaler. * It can be one of the values of @ref ADC1_PresSel_TypeDef. * @retval None */ void ADC1_PrescalerConfig(ADC1_PresSel_TypeDef ADC1_Prescaler) { /* Check the parameter */ assert_param(IS_ADC1_PRESSEL_OK(ADC1_Prescaler)); /* Clear the SPSEL bits */ ADC1->CR1 &= (uint8_t)(~ADC1_CR1_SPSEL); /* Select the prescaler division factor according to ADC1_PrescalerSelection values */ ADC1->CR1 |= (uint8_t)(ADC1_Prescaler); }