CH32V003模拟/数字转换(ADC)介绍
  ADC 模块包含 1 个 10 位的逐次逼近型的模拟数字转换器,最高允许 24MHz 的输入时钟。支持 8个外部通道和 2 个内部信号源采样源。可完成通道的单次转换、连续转换,通道间自动扫描模式、间断模式、外部触发模式、双重采样、触发延迟等功能。可以通过模拟看门狗功能监测通道电压是否在阈值范围内。
主要特性
- 10 位分辨率
- 支持 8 个外部通道和 2 个内部信号源采样
- 多通道的多种采样转换方式:单次、连续、扫描、触发、间断等
- 数据对齐模式:左对齐、右对齐
- 采样时间可按通道分别编程
- 规则转换和注入转换均支持外部触发
- 模拟看门狗监测通道电压,自校准功能
- ADC 通道输入范围:0≤VIN≤VDDA
- 触发延迟
功能描述
模块结构

ADC 配置
- 
模块上电   ADC_CTLR2 寄存器的 ADON 位为 1 表示 ADC 模块上电。当 ADC 模块从断电模式(ADON=0)下进入上电状态(ADON=1)后,需要延迟一段时间 tSTAB用于模块稳定时间。之后再次写入 ADON 位为 1,用于作为软件启动 ADC 转换的启动信号。通过清除 ADON 位为 0,可以终止当前转换并将 ADC 模块置于断电模式,这个状态下,ADC 几乎不耗电。 
- 
采样时钟   模块的寄存器操作基于 AHBCLK(AHB 总线)时钟,其转换单元的时钟基准 ADCCLK,由 RCC_CFGR0寄存器的 ADCPRE 域配置分频,最大不能超过 24MHz。 
- 
通道配置   ADC 模块提供了 10 个通道采样源,包括 8 个外部通道和 2 个内部通道。它们可以配置到两种转换组中:规则组和注入组。以实现任意多个通道上以任意顺序进行一系列转换构成的组转换。   转换组:   规则组:由多达 16 个转换组成。规则通道和它们的转换顺序在 ADC_RSQRx 寄存器中设置。   规则组中转换的总数量应写入 ADC_RSQR1 寄存器的 RLEN[3:0]中。   注入组:由多达 4 个转换组成。注入通道和它们的转换顺序在 ADC_ISQR 寄存器中设置。   注入组里的转换总数量应写入 ADC_ISQR 寄存器的 ILEN[1:0]中。 注:如果 ADC_RSQRx 或 ADC_ISQR 寄存器在转换期间被更改,当前的转换被终止,一个新的启动信号将发送到 ADC 以转换新选择的组。 2 个内部通道:   Vref 内部参考电压:连接 ADC_IN8 通道。   Vcal 内部校准电压:连接 ADC_IN9 通道,2 档可选 
- 
校准   ADC 有一个内置自校准模式。经过校准环节可大幅减小因内部电容器组的变化而造成的精准度误差。在校准期间,在每个电容器上都会计算出一个误差修正码,用于消除在随后的转换中每个电容器上产生的误差。   通过写 ADC_CTLR2 寄存器的 RSTCAL 位置 1 初始化校准寄存器,等待 RSTCAL 硬件清 0 表示初始化完成。置位 CAL 位,启动校准功能,一旦校准结束,硬件会自动清除 CAL 位,将校准码存储到ADC_RDATAR 中。之后可以开始正常的转换功能。建议在 ADC 模块上电时执行一次 ADC 校准。 注:启动校准前,必须保证 ADC 模块处于上电状态(ADON=1)超过至少两个 ADC 时钟周期。 
- 
可编程采样时间   ADC 使用若干个 ADCCLK 周期对输入电压采样,通道的采样周期数目可以通过 ADC_SAMPTR1 和ADC_SAMPTR2 寄存器中的 SMPx[2:0]位更改。每个通道可以分别使用不同的时间采样。 总转换时间如下计算:   TCONV = 采样时间 + 11TADCCLK   ADC的规则通道转换支持DMA功能。规则通道转换的值储存在一个仅有的数据寄存器ADC_RDATAR中,为防止连续转换多个规则通道时,没有及时取走 ADC_RDATAR 寄存器中的数据,可以开启 ADC的 DMA 功能。硬件会在规则通道的转换结束时(EOC 置位)产生 DMA 请求,并将转换的数据从ADC_RDATAR 寄存器传输到用户指定的目的地址。   对 DMA 控制器模块的通道配置完成后,写 ADC_CTLR2 寄存器的 DMA 位置 1,开启 ADC 的 DMA 功能。 注:注入组转换不支持 DMA 功能。 
- 
数据对齐   ADC_CTLR2 寄存器中的 ALIGN 位选择 ADC 转换后的数据存储对齐方式。12 位数据支持左对齐和右对齐模式。   规则组通道的数据寄存器 ADC_RDATAR 保存的是实际转换的 12 位数字值;而注入组通道的数据寄存器 ADC_IDATARx 是实际转换的数据减去 ADC_IOFRx 寄存器的定义的偏移量后写入的值,会存在正负情况,所以有符号位(SIGNB)。   数据左对齐
  
   数据右对齐
  
 
外部触发源
  ADC 转换的启动事件可以由外部事件触发。如果设置了 ADC_CTLR2 寄存器的 EXTTRIG 或JEXTTRIG 位,则可分别通过外部事件触发规则组或注入组通道的转换。此时,EXTSEL[2:0]和JEXTSEL[2:0]位的配置决定规则组和注入组的外部事件源。
  规则组通道的外部触发源

  注入组通道的外部触发源

转换模式
 注:规则组和注入组的外部触发事件是不一样的,而且‘ACON’位只能启动规则组通道转换,所以规则组和注入组通道转换的启动事件独立。
注:规则组和注入组的外部触发事件是不一样的,而且‘ACON’位只能启动规则组通道转换,所以规则组和注入组通道转换的启动事件独立。
- 
单次单通道转换模式   此模式下,对当前 1 个通道只执行一次转换。该模式对规则组或注入组中排序第 1 的通道执行转换,其中通过设置 ADC_CTLR2 寄存器的 ADON 位置 1(只适用于规则通道)启动也可通过外部触发启动(适用于规则通道或注入通道)。一旦选择通道的转换完成将:   如果转换的是规则组通道,则转换数据被储存在 16 位 ADC_RDATAR 寄存器中,EOC 标志被置位,如果设置了 EOCIE 位,将触发 ADC 中断。   如果转换的是注入组通道,则转换数据被储存在 16 位 ADC_IDATAR1 寄存器中,EOC 和 JEOC 标志被置位,如果设置了 JEOCIE 或 EOCIE 位,将触发 ADC 中断。 
- 
单次扫描模式转换   通过设置 ADC_CTLR1 寄存器的 SCAN 位为 1 进入 ADC 扫描模式。此模式用来扫描一组模拟通道,对被 ADC_RSQRx 寄存器(对规则通道)或 ADC_ISQR(对注入通道)选中的所有通道逐个执行单次转换,当前通道转换结束时,同一组的下一个通道被自动转换。   在扫描模式里,根据 IAUTO 位的状态,又分为触发注入方式和自动注入方式。
 触发注入
   IAUTO 位为 0,当在扫描规则组通道过程中,发生了注入组通道转换的触发事件,当前转换被复位,注入通道的序列被以单次扫描方式进行,在所有选中的注入组通道扫描转换结束后,恢复上次被中断的规则组通道转换。   如果当前在扫描注入组通道序列时,发生了规则通道的启动事件,注入组转换不会被中断,而是在注入序列转换完成后再执行规则序列的转换。 注:使用触发的注入转换时,必须保证触发事件的间隔长于注入序列。例如,完成注入序列的转换总体时间需要 28 个 ADCCLK,那么触发注入通道的事件间隔时间最小值为 29 个 ADCCLK。 自动注入   IAUTO 位为 1,在扫描完规则组选中的所有通道转换后,自动进行注入组选中通道的转换。这种方式可以用来转换ADC_RSQRx 和 ADC_ISQR 寄存器中多达 20 个转换序列。   此模式里,必须禁止注入通道的外部触发(JEXTTRIG=0)。 注:对于 ADC 时钟预分频系数(ADCPRE[1:0])为 4 至 8 时,当从规则转换切换到注入序列或从注入转换切换到规则序列时,会自动插入 1 个 ADCCLK 间隔;当 ADC 时钟预分频系数为 2 时,则有 2 个ADCCLK 间隔的延迟。 
- 
单次间断模式转换   通过设置 ADC_CTLR1 寄存器的 RDISCEN 或 IDISCEN 位为 1 进入规则组或注入组的间断模式。此模式区别扫描模式中扫描完整的一组通道,而是将一组通道分为多个短序列,每次外部触发事件将执行一个短序列的扫描转换。   短序列的长度 n(n<=8)定义在 ADC_CTLR1 寄存器的 DISCNUM[2:0]中,当 RDISCEN 为 1,则是规则组的间断模式,待转换总长度定义在 ADC_RSQR1 寄存器的 RLEN[3:0]中;当 IDISCEN 为 1,则是注入组的间断模式,待转换总长度定义在 ADC_ISQR 寄存器的 ILEN[1:0]中。不能同时将规则组和注入组设置为间断模式。 规则组间断模式举例:   RDISCEN=1,DISCNUM[2:0]=3,RLEN[3:0]=8,待转换通道=1,3,2,5,8,4,10,6   第 1 次外部触发:转换序列为:1,3,2   第 2 次外部触发:转换序列为:5,8,4   第 3 次外部触发:转换序列为:10,6,同时产生 EOC 事件   第 4 次外部触发:转换序列为:1,3,2 注入组间断模式举例:   IDISCEN=1,DISCNUM[2:0]=1,ILEN[1:0]=3,待转换通道=1,3,2   第 1 次外部触发:转换序列为:1   第 2 次外部触发:转换序列为:3   第 3 次外部触发:转换序列为:2,同时产生 EOC 和 JEOC 事件   第 4 次外部触发:转换序列为:1 注: 
- 当以间断模式转换一个规则组或注入组时,转换序列结束后不自动从头开始。当所有子组被转换完成,下一次触发事件启动第一个子组的转换
- 不能同时使用自动注入(IAUTO=1)和间断模式。
- 不能同时为规则组和注入组设置间断模式,间断模式只能用于一组转换。
模拟看门狗
  如果被 ADC 转换的模拟电压低于低阀值或高于高阀值,AWD 模拟看门狗状态位被设置。阀值设置位于 ADC_WDHTR 和 ADC_WDLTR 寄存器的最低 10 个有效位中。通过设置 ADC_CTLR1 寄存器的 AWDIE位以允许产生相应中断。
  模拟看门狗阈值区

  配置 ADC_CTLR1 寄存器的 AWDSGL、RAWDEN、IAWDEN 及 AWDCH[4:0]位选择模拟看门狗警戒的通道,具体关系见下表:
  模拟看门狗通道选择

库函数文件中函数介绍
/*********************************************************************
 * @fn      ADC_DeInit
 *
 * [url=home.php?mod=space&uid=2666770]@Brief[/url]   Deinitializes the ADCx peripheral registers to their default
 *        reset values.
 *
 * [url=home.php?mod=space&uid=3142012]@param[/url]   ADCx - where x can be 1 to select the ADC peripheral.
 *
 * [url=home.php?mod=space&uid=1141835]@Return[/url]  none
 */
void ADC_DeInit(ADC_TypeDef *ADCx);
/*********************************************************************
 * @fn      ADC_Init
 *
 * @brief   Initializes the ADCx peripheral according to the specified
 *        parameters in the ADC_InitStruct.
 *
 * @param   ADCx - where x can be 1  to select the ADC peripheral.
 *          ADC_InitStruct - pointer to an ADC_InitTypeDef structure that
 *        contains the configuration information for the specified ADC
 *        peripheral.
 *
 * @return  none
 */
void ADC_Init(ADC_TypeDef *ADCx, ADC_InitTypeDef *ADC_InitStruct);
/*********************************************************************
 * @fn      ADC_StructInit
 *
 * @brief   Fills each ADC_InitStruct member with its default value.
 *
 * @param   ADC_InitStruct - pointer to an ADC_InitTypeDef structure that
 *        contains the configuration information for the specified ADC
 *        peripheral.
 *
 * @return  none
 */
void ADC_StructInit(ADC_InitTypeDef *ADC_InitStruct);
/*********************************************************************
 * @fn      ADC_Cmd
 *
 * @brief   Enables or disables the specified ADC peripheral.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *          NewState - ENABLE or DISABLE.
 *
 * @return  none
 */
void ADC_Cmd(ADC_TypeDef *ADCx, FunctionalState NewState);
/*********************************************************************
 * @fn      ADC_DMACmd
 *
 * @brief   Enables or disables the specified ADC DMA request.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *          NewState - ENABLE or DISABLE.
 *
 * @return  none
 */
void ADC_DMACmd(ADC_TypeDef *ADCx, FunctionalState NewState);
/*********************************************************************
 * @fn      ADC_ITConfig
 *
 * @brief   Enables or disables the specified ADC interrupts.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *          ADC_IT - specifies the ADC interrupt sources to be enabled or disabled.
 *            ADC_IT_EOC - End of conversion interrupt mask.
 *            ADC_IT_AWD - Analog watchdog interrupt mask.
 *            ADC_IT_JEOC - End of injected conversion interrupt mask.
 *          NewState - ENABLE or DISABLE.
 *
 * @return  none
 */
void ADC_ITConfig(ADC_TypeDef *ADCx, uint16_t ADC_IT, FunctionalState NewState);
/*********************************************************************
 * @fn      ADC_ResetCalibration
 *
 * @brief   Resets the selected ADC calibration registers.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *
 * @return  none
 */
void ADC_ResetCalibration(ADC_TypeDef *ADCx);
/*********************************************************************
 * @fn      ADC_GetResetCalibrationStatus
 *
 * @brief   Gets the selected ADC reset calibration registers status.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *
 * @return  FlagStatus: SET or RESET.
 */
FlagStatus ADC_GetResetCalibrationStatus(ADC_TypeDef *ADCx);
/*********************************************************************
 * @fn      ADC_StartCalibration
 *
 * @brief   Starts the selected ADC calibration process.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *
 * @return  None
 */
void ADC_StartCalibration(ADC_TypeDef *ADCx);
/*********************************************************************
 * @fn      ADC_GetCalibrationStatus
 *
 * @brief   Gets the selected ADC calibration status.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *
 * @return  FlagStatus: SET or RESET.
 */
FlagStatus ADC_GetCalibrationStatus(ADC_TypeDef *ADCx);
/*********************************************************************
 * @fn      ADC_SoftwareStartConvCmd
 *
 * @brief   Enables or disables the selected ADC software start conversion.
 *
 * @param   ADCx - where x can be 1 or 2 to select the ADC peripheral.
 *          NewState - ENABLE or DISABLE.
 *
 * @return  None
 */
void ADC_SoftwareStartConvCmd(ADC_TypeDef *ADCx, FunctionalState NewState);
/*********************************************************************
 * @fn      ADC_GetSoftwareStartConvStatus
 *
 * @brief   Gets the selected ADC Software start conversion Status.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *
 * @return  FlagStatus - SET or RESET.
 */
FlagStatus ADC_GetSoftwareStartConvStatus(ADC_TypeDef *ADCx);
/*********************************************************************
 * @fn      ADC_DiscModeChannelCountConfig
 *
 * @brief   Configures the discontinuous mode for the selected ADC regular
 *        group channel.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *          Number - specifies the discontinuous mode regular channel
 *            count value(1-8).
 *
 * @return  None
 */
void ADC_DiscModeChannelCountConfig(ADC_TypeDef *ADCx, uint8_t Number);
/*********************************************************************
 * @fn      ADC_DiscModeCmd
 *
 * @brief   Enables or disables the discontinuous mode on regular group
 *        channel for the specified ADC.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *          NewState - ENABLE or DISABLE.
 *
 * @return  None
 */
void ADC_DiscModeCmd(ADC_TypeDef *ADCx, FunctionalState NewState);
/*********************************************************************
 * @fn      ADC_RegularChannelConfig
 *
 * @brief   Configures for the selected ADC regular channel its corresponding
 *        rank in the sequencer and its sample time.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *          ADC_Channel - the ADC channel to configure.
 *            ADC_Channel_0 - ADC Channel0 selected.
 *            ADC_Channel_1 - ADC Channel1 selected.
 *            ADC_Channel_2 - ADC Channel2 selected.
 *            ADC_Channel_3 - ADC Channel3 selected.
 *            ADC_Channel_4 - ADC Channel4 selected.
 *            ADC_Channel_5 - ADC Channel5 selected.
 *            ADC_Channel_6 - ADC Channel6 selected.
 *            ADC_Channel_7 - ADC Channel7 selected.
 *            ADC_Channel_Vrefint - ADC Channel8 selected.
 *            ADC_Channel_Vcalint - ADC Channel9 selected.
 *          Rank - The rank in the regular group sequencer.
 *            This parameter must be between 1 to 16.
 *          ADC_SampleTime - The sample time value to be set for the selected channel.
 *            ADC_SampleTime_3Cycles - Sample time equal to 3 cycles.
 *            ADC_SampleTime_9Cycles - Sample time equal to 9 cycles.
 *            ADC_SampleTime_15Cycles - Sample time equal to 15 cycles.
 *            ADC_SampleTime_30Cycles - Sample time equal to 30 cycles.
 *            ADC_SampleTime_43Cycles - Sample time equal to 43 cycles.
 *            ADC_SampleTime_57Cycles - Sample time equal to 57 cycles.
 *            ADC_SampleTime_73Cycles - Sample time equal to 73 cycles.
 *            ADC_SampleTime_241Cycles - Sample time equal to 241 cycles.
 *
 * @return  None
 */
void ADC_RegularChannelConfig(ADC_TypeDef *ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime);
/*********************************************************************
 * @fn      ADC_ExternalTrigConvCmd
 *
 * @brief   Enables or disables the ADCx conversion through external trigger.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *          NewState - ENABLE or DISABLE.
 *
 * @return  None
 */
void ADC_ExternalTrigConvCmd(ADC_TypeDef *ADCx, FunctionalState NewState);
/*********************************************************************
 * @fn      ADC_GetConversionValue
 *
 * @brief   Returns the last ADCx conversion result data for regular channel.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *
 * @return  ADCx->RDATAR - The Data conversion value.
 */
uint16_t ADC_GetConversionValue(ADC_TypeDef *ADCx);
/*********************************************************************
 * @fn      ADC_AutoInjectedConvCmd
 *
 * @brief   Enables or disables the selected ADC automatic injected group
 *        conversion after regular one.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *          NewState - ENABLE or DISABLE.
 *
 * @return  None
 */
void ADC_AutoInjectedConvCmd(ADC_TypeDef *ADCx, FunctionalState NewState);
/*********************************************************************
 * @fn      ADC_InjectedDiscModeCmd
 *
 * @brief   Enables or disables the discontinuous mode for injected group
 *        channel for the specified ADC.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *          NewState - ENABLE or DISABLE.
 *
 * @return  None
 */
void ADC_InjectedDiscModeCmd(ADC_TypeDef *ADCx, FunctionalState NewState);
/*********************************************************************
 * @fn      ADC_ExternalTrigInjectedConvConfig
 *
 * @brief   Configures the ADCx external trigger for injected channels conversion.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *          ADC_ExternalTrigInjecConv - specifies the ADC trigger to start
 *        injected conversion.
 *            ADC_ExternalTrigInjecConv_T1_CC3 - Timer1 capture compare3 selected.
 *            ADC_ExternalTrigInjecConv_T1_CC4 - Timer1 capture compare4 selected.
 *            ADC_ExternalTrigInjecConv_T2_CC3 - Timer2 capture compare3 selected.
 *            ADC_ExternalTrigInjecConv_T2_CC4 - Timer2 capture compare4 selected.
 *            ADC_ExternalTrigInjecConv_Ext_PD1_PA2 - PD1 or PA2 selected.
 *        line 15 event selected.
 *            ADC_ExternalTrigInjecConv_None: Injected conversion started
 *        by software and not by external trigger.
 *
 * @return  None
 */
void ADC_ExternalTrigInjectedConvConfig(ADC_TypeDef *ADCx, uint32_t ADC_ExternalTrigInjecConv);
/*********************************************************************
 * @fn      ADC_ExternalTrigInjectedConvCmd
 *
 * @brief   Enables or disables the ADCx injected channels conversion through
 *        external trigger.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *          NewState - ENABLE or DISABLE.
 *
 * @return  None
 */
void ADC_ExternalTrigInjectedConvCmd(ADC_TypeDef *ADCx, FunctionalState NewState);
/*********************************************************************
 * @fn      ADC_SoftwareStartInjectedConvCmd
 *
 * @brief   Enables or disables the selected ADC start of the injected
 *        channels conversion.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *          NewState - ENABLE or DISABLE.
 *
 * @return  None
 */
void ADC_SoftwareStartInjectedConvCmd(ADC_TypeDef *ADCx, FunctionalState NewState);
/*********************************************************************
 * @fn      ADC_GetSoftwareStartInjectedConvCmdStatus
 *
 * @brief   Gets the selected ADC Software start injected conversion Status.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *
 * @return  FlagStatus: SET or RESET.
 */
FlagStatus ADC_GetSoftwareStartInjectedConvCmdStatus(ADC_TypeDef *ADCx);
/*********************************************************************
 * @fn      ADC_InjectedChannelConfig
 *
 * @brief   Configures for the selected ADC injected channel its corresponding
 *        rank in the sequencer and its sample time.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *          ADC_Channel - the ADC channel to configure.
 *            ADC_Channel_0 - ADC Channel0 selected.
 *            ADC_Channel_1 - ADC Channel1 selected.
 *            ADC_Channel_2 - ADC Channel2 selected.
 *            ADC_Channel_3 - ADC Channel3 selected.
 *            ADC_Channel_4 - ADC Channel4 selected.
 *            ADC_Channel_5 - ADC Channel5 selected.
 *            ADC_Channel_6 - ADC Channel6 selected.
 *            ADC_Channel_7 - ADC Channel7 selected.
 *            ADC_Channel_Vrefint - ADC Channel8 selected.
 *            ADC_Channel_Vcalint - ADC Channel9 selected.
 *          Rank - The rank in the regular group sequencer.
 *            This parameter must be between 1 to 16.
 *          ADC_SampleTime - The sample time value to be set for the selected channel.
 *            ADC_SampleTime_3Cycles - Sample time equal to 3 cycles.
 *            ADC_SampleTime_9Cycles - Sample time equal to 9 cycles.
 *            ADC_SampleTime_15Cycles - Sample time equal to 15 cycles.
 *            ADC_SampleTime_30Cycles - Sample time equal to 30 cycles.
 *            ADC_SampleTime_43Cycles - Sample time equal to 43 cycles.
 *            ADC_SampleTime_57Cycles - Sample time equal to 57 cycles.
 *            ADC_SampleTime_73Cycles - Sample time equal to 73 cycles.
 *            ADC_SampleTime_241Cycles - Sample time equal to 241 cycles.
 *
 * @return  None
 */
void ADC_InjectedChannelConfig(ADC_TypeDef *ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime);
/*********************************************************************
 * @fn      ADC_InjectedSequencerLengthConfig
 *
 * @brief   Configures the sequencer length for injected channels.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *          Length - The sequencer length.
 *            This parameter must be a number between 1 to 4.
 *
 * @return  None
 */
void ADC_InjectedSequencerLengthConfig(ADC_TypeDef *ADCx, uint8_t Length);
/*********************************************************************
 * @fn      ADC_SetInjectedOffset
 *
 * @brief   Set the injected channels conversion value offset.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *          ADC_InjectedChannel: the ADC injected channel to set its offset.
 *            ADC_InjectedChannel_1 - Injected Channel1 selected.
 *            ADC_InjectedChannel_2 - Injected Channel2 selected.
 *            ADC_InjectedChannel_3 - Injected Channel3 selected.
 *            ADC_InjectedChannel_4 - Injected Channel4 selected.
 *          Offset - the offset value for the selected ADC injected channel.
 *            This parameter must be a 10bit value.
 *
 * @return  None
 */
void ADC_SetInjectedOffset(ADC_TypeDef *ADCx, uint8_t ADC_InjectedChannel, uint16_t Offset);
/*********************************************************************
 * @fn      ADC_GetInjectedConversionValue
 *
 * @brief   Returns the ADC injected channel conversion result.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *          ADC_InjectedChannel - the ADC injected channel to set its offset.
 *            ADC_InjectedChannel_1 - Injected Channel1 selected.
 *            ADC_InjectedChannel_2 - Injected Channel2 selected.
 *            ADC_InjectedChannel_3 - Injected Channel3 selected.
 *            ADC_InjectedChannel_4 - Injected Channel4 selected.
 *
 * @return  tmp - The Data conversion value.
 */
uint16_t ADC_GetInjectedConversionValue(ADC_TypeDef *ADCx, uint8_t ADC_InjectedChannel);
/*********************************************************************
 * @fn      ADC_AnalogWatchdogCmd
 *
 * @brief   Enables or disables the analog watchdog on single/all regular
 *        or injected channels.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *          ADC_AnalogWatchdog - the ADC analog watchdog configuration.
 *            ADC_AnalogWatchdog_SingleRegEnable - Analog watchdog on a
 *        single regular channel.
 *            ADC_AnalogWatchdog_SingleInjecEnable - Analog watchdog on a
 *        single injected channel.
 *            ADC_AnalogWatchdog_SingleRegOrInjecEnable - Analog watchdog
 *        on a single regular or injected channel.
 *            ADC_AnalogWatchdog_AllRegEnable - Analog watchdog on  all
 *        regular channel.
 *            ADC_AnalogWatchdog_AllInjecEnable - Analog watchdog on  all
 *        injected channel.
 *            ADC_AnalogWatchdog_AllRegAllInjecEnable - Analog watchdog on
 *        all regular and injected channels.
 *            ADC_AnalogWatchdog_None - No channel guarded by the analog
 *        watchdog.
 *
 * @return  none
 */
void ADC_AnalogWatchdogCmd(ADC_TypeDef *ADCx, uint32_t ADC_AnalogWatchdog);
/*********************************************************************
 * @fn      ADC_AnalogWatchdogThresholdsConfig
 *
 * @brief   Configures the high and low thresholds of the analog watchdog.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *          HighThreshold - the ADC analog watchdog High threshold value.
 *            This parameter must be a 10bit value.
 *          LowThreshold - the ADC analog watchdog Low threshold value.
 *            This parameter must be a 10bit value.
 *
 * @return  none
 */
void ADC_AnalogWatchdogThresholdsConfig(ADC_TypeDef *ADCx, uint16_t HighThreshold, uint16_t LowThreshold);
/*********************************************************************
 * @fn      ADC_AnalogWatchdogSingleChannelConfig
 *
 * @brief   Configures the analog watchdog guarded single channel.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *          ADC_Channel - the ADC channel to configure.
 *            ADC_Channel_0 - ADC Channel0 selected.
 *            ADC_Channel_1 - ADC Channel1 selected.
 *            ADC_Channel_2 - ADC Channel2 selected.
 *            ADC_Channel_3 - ADC Channel3 selected.
 *            ADC_Channel_4 - ADC Channel4 selected.
 *            ADC_Channel_5 - ADC Channel5 selected.
 *            ADC_Channel_6 - ADC Channel6 selected.
 *            ADC_Channel_7 - ADC Channel7 selected.
 *            ADC_Channel_Vrefint - ADC Channel8 selected.
 *            ADC_Channel_Vcalint - ADC Channel9 selected.
 *
 * @return  None
 */
void ADC_AnalogWatchdogSingleChannelConfig(ADC_TypeDef *ADCx, uint8_t ADC_Channel);
/*********************************************************************
 * @fn      ADC_GetFlagStatus
 *
 * @brief   Checks whether the specified ADC flag is set or not.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *          ADC_FLAG - specifies the flag to check.
 *            ADC_FLAG_AWD - Analog watchdog flag.
 *            ADC_FLAG_EOC - End of conversion flag.
 *            ADC_FLAG_JEOC - End of injected group conversion flag.
 *            ADC_FLAG_JSTRT - Start of injected group conversion flag.
 *            ADC_FLAG_STRT - Start of regular group conversion flag.
 *
 * @return  FlagStatus: SET or RESET.
 */
FlagStatus ADC_GetFlagStatus(ADC_TypeDef *ADCx, uint8_t ADC_FLAG);
/*********************************************************************
 * @fn      ADC_ClearFlag
 *
 * @brief   Clears the ADCx's pending flags.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *          ADC_FLAG - specifies the flag to clear.
 *            ADC_FLAG_AWD - Analog watchdog flag.
 *            ADC_FLAG_EOC - End of conversion flag.
 *            ADC_FLAG_JEOC - End of injected group conversion flag.
 *            ADC_FLAG_JSTRT - Start of injected group conversion flag.
 *            ADC_FLAG_STRT - Start of regular group conversion flag.
 *
 * @return  none
 */
void ADC_ClearFlag(ADC_TypeDef *ADCx, uint8_t ADC_FLAG);
/*********************************************************************
 * @fn      ADC_GetITStatus
 *
 * @brief   Checks whether the specified ADC interrupt has occurred or not.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *          ADC_IT - specifies the ADC interrupt source to check.
 *            ADC_IT_EOC - End of conversion interrupt mask.
 *            ADC_IT_AWD - Analog watchdog interrupt mask.
 *            ADC_IT_JEOC - End of injected conversion interrupt mask.
 *
 * @return  ITStatus: SET or RESET.
 */
ITStatus ADC_GetITStatus(ADC_TypeDef *ADCx, uint16_t ADC_IT);
/*********************************************************************
 * @fn      ADC_ClearITPendingBit
 *
 * @brief   Clears the ADCx's interrupt pending bits.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *          ADC_IT - specifies the ADC interrupt pending bit to clear.
 *            ADC_IT_EOC - End of conversion interrupt mask.
 *            ADC_IT_AWD - Analog watchdog interrupt mask.
 *            ADC_IT_JEOC - End of injected conversion interrupt mask.
 *
 * @return  none
 */
void ADC_ClearITPendingBit(ADC_TypeDef *ADCx, uint16_t ADC_IT);
/*********************************************************************
 * @fn      ADC_Calibration_Vol
 *
 * @brief   ADC calibration voltage.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *          ADC_CALVOL - ADC calibration voltage.
 *            ADC_CALVOL_50PERCENT - 50% VDD.
 *            ADC_CALVOL_75PERCENT - 75% VDD.
 *
 * @return  none
 */
void ADC_Calibration_Vol(ADC_TypeDef *ADCx, uint32_t ADC_CALVOL);
/*********************************************************************
 * @fn      ADC_ExternalTrig_DLY
 *
 * @brief   ADC external trigger sources delay channels and time.
 *
 * @param   ADCx - where x can be 1 to select the ADC peripheral.
 *          channel - ADC external trigger sources delay channels.
 *            ADC_ExternalTrigRegul_DLY - External trigger sources regular.
 *            ADC_ExternalTrigInjec_DLY - External trigger sources injected.
 *          DelayTim - ADC external trigger sources delay time
 *              This parameter must range from 0 to 0x1FF.
 *
 * @return  none
 */
void ADC_ExternalTrig_DLY(ADC_TypeDef *ADCx, uint32_t channel, uint16_t DelayTim);