#ifndef __ADC_DEMO_H__
#define __ADC_DEMO_H__

#include "type.h"

/*ADC configuration register 1:ADC_CFGR1*/
#define ADC_ANALOG_INPUT_DIFF_MASK                       ((uint32_t)(1<<31))
#define ADC_OVERRUN_MODE_MASK                            ((uint32_t)(1<<30))
#define ADC_QADC_CLK_DISABLE_MASK                        ((uint32_t)(1<<29))
#define ADC_SAMPLE_OUTPUT_BUFFER_EN                      ((uint32_t)(1<<28))
#define ADC_DISCONTINUOUS_EN                             ((uint32_t)(1<<23)) 
#define ADC_AUTO_OFF_MODE_EN                             ((uint32_t)(1<<22))
#define ADC_WAIT_CONVERSION_MODE_MASK                    ((uint32_t)(1<<21))
#define ADC_CONTINUOUS_CONVERSION_MASK                   ((uint32_t)(1<<20))
#define ADC_EXTERNAL_VREF_MASK                           ((uint32_t)(1<<15))
#define ADC_CFGR1_ALIGN_LEFT_ALIGNMENT                   ((uint32_t)(1<<10))
#define ADC_CFGR1_ALIGN_RIGHT_ALIGNMENT                  ((uint32_t)(0<<10))
#define ADC_LEFT_ALIGNMENT_MASK                          ((uint32_t)(1<<10))
#define ADC_CFGR1_RES_10BIT                              ((uint32_t)(1<<8))
#define ADC_CFGR1_DMATH_2                                ((uint32_t)(2<<4))
#define ADC_DMA_ACCESS_EN                                ((uint32_t)(1<<0))
#define ADC_CFGR1_SEQ_LEN_SHIFT                          ((uint32_t)(24))

typedef struct
{
	uint8_t channel;    /*< ADC通道号，参照ADC_ChannelTypeDef定义 */
	uint8_t resolution; /*< ADC采样精度设置，参照ADC_ResTypeDef定义 */
	uint8_t clk_div;    /*< ADC时钟分频 - QCLK = SYS_CLK/clk_div */
	uint8_t stab_time;  /*< ADC转化开始稳定时间约2us - 2*(10^-6)*(1/QCLK) */
	uint8_t smp_time;   /*< ADC采样时间 - (smp_time + 2)*QCLKs */

	uint8_t vref;     /*< ADC基准电压源选择，参照ADC_VrefTypeDef定义 */
	uint8_t align;    /*< ADC采样值对其方式，参照ADC_AlignTypeDef定义 */
	uint8_t conv;     /*< ADC采样转换模式，参照ADC_ConvModeTypeDef定义 */
	uint8_t overrun;  /*< ADC采样转换模式，参照ADC_OverrunManagTypeDef定义 */
	uint8_t int_kind; /*< ADC采样中断类型选择 */
} ADC_InitTypeDef;

typedef enum
{
	ADC_CLK_DIV_1 = 0,
	ADC_CLK_DIV_2,
	ADC_CLK_DIV_3,
	ADC_CLK_DIV_4,
	ADC_CLK_DIV_5,
	ADC_CLK_DIV_6,
	ADC_CLK_DIV_7,
	ADC_CLK_DIV_8,
	ADC_CLK_DIV_9,
	ADC_CLK_DIV_10,
	ADC_CLK_DIV_11,
	ADC_CLK_DIV_12,
	ADC_CLK_DIV_13,
	ADC_CLK_DIV_14,
	ADC_CLK_DIV_15,
	ADC_CLK_DIV_16
} ADC_ClkDivTypeDef;


extern void ADC_Init(ADC_InitTypeDef *adc,u16 channel);
extern uint16_t ADC_GetConversionValue(u16 channel);


  
#endif  /* __ADC_DEMO_H__*/

