/***********************************************************************************************************
 * Copyright (c)  2021 - 2022, Unicmicro Co.,Ltd .
 * All rights reserved.
 * Filename    : adc.h
 * Description : adc driver header file
 * Author(s)   : yanhaihua
 * Version     : V1.0
 * Modify date : 2021-09-23
 ***********************************************************************************************************/
#ifndef _ADC_H_
#define _ADC_H_

#include  "config.h"

#ifdef UM2080F32_USING_ADC

/************************************************** ADC参考电压源选择 ADC_ICR ******************************/
#define ADC_REF_VDDH								0														/* 选择VDDH作为ADC电压源 */
#define ADC_REF_VREF								3														/* 选择内部VREF作为ADC电压源 */

#define ADC_SINGLE_MODE								0														/* ADC单次转换 */
#define ADC_CONTINUOUS_MODE							1														/* ADC连续转换 */

/************************************************** REG ADC_ICR ********************************************/
#define ADC_SAMPL_RATE_200k_SPS						8			
#define ADC_SAMPL_RATE_100K_SPS						16			
#define ADC_SAMPL_RATE_50K_SPS						32			
#define ADC_SAMPL_RATE_25K_SPS						64			
#define ADC_SAMPL_RATE_12500_SPS					128	
#define ADC_SAMPL_RATE_LOWSPEED						32768

typedef enum
{
	ADC_IRQ_CH0_INT_EN								= 0,
	ADC_IRQ_CH3_INT_EN								= 3,
	ADC_IRQ_CH4_INT_EN								= 4,
	ADC_IRQ_CH5_INT_EN								= 5,
	ADC_IRQ_RX_IEN									= 8,
	ADC_IRQ_RX_FIFO_FULL_EN							= 9,
}em_adc_irq_type;

void adc_init(uint8_t vref_sel,uint32_t div,uint8_t work_mode);

void adc_deinit(void);

void adc_chn_enable(uint8_t chn);

void adc_convert_start(void);

void adc_convert_stop(void);

uint16_t adc_get_data(uint8_t ch_num);

void adc_irq_init(em_enable_t irq_enable, em_adc_irq_type irq_type,void (*pfunc)());

#endif
#endif
