/**
******************************************************************************************************************************************************************************************
*@file                       cpu_gpadc.h
*@author         
*@data                       
*@version                    v1.0
*@par Copyright(c):
*
*@par History:
*     version:author,date,desc
*     v1.0   :create this file
*
*******************************************************************************************************************************************************************************************
*/
#ifndef _CPU_GPADC_
#define _CPU_GPADC_

#include "cpu.h"

typedef struct
{
	uint32_t gpadc_gain;
	
	uint32_t gpadc_vcm_sel;
	
	uint32_t gpadc_in_mode;                                           
																	
	uint32_t gapdc_ch_sel;           

	uint32_t gpadc_sel1;    

	uint32_t gpadc_sel2;    	

	uint32_t gpadc_sample_rate;                                            

	uint32_t gpadc_write_in_mode;                                           

	uint32_t gpadc_en;              
	
	uint32_t gpadc_fifo_threshold;
	
	uint32_t gpadc_fifo_flush;
	
	uint32_t gpadc_dma_en;
	
	uint32_t gpadc_dma_rdlr;
	
}gpadc_init_type_def;

/*gpadc_gain*/
#define GPADC_Gain_05		((uint32_t)0x0000 << 14)
#define GPADC_Gain_1		((uint32_t)0x0001 << 14)
#define GPADC_Gain_2		((uint32_t)0x0002 << 14)
#define GPADC_Gain_4		((uint32_t)0x0003 << 14)

/*gpadc_vcm_sel*/
#define GPADC_VCM_045		((uint32_t)0x0000 << 4)
#define GPADC_VCM_050		((uint32_t)0x0001 << 4)
#define GPADC_VCM_055		((uint32_t)0x0002 << 4)
#define GPADC_VCM_060		((uint32_t)0x0003 << 4)
#define GPADC_VCM_065		((uint32_t)0x0004 << 4)
#define GPADC_VCM_070		((uint32_t)0x0005 << 4)
#define GPADC_VCM_075		((uint32_t)0x0006 << 4)
#define GPADC_VCM_080		((uint32_t)0x0007 << 4)

/*gpadc_in_mode*/
#define GPADC_SINGLE_IN		((uint32_t)0x0000 << 3)
#define GPADC_DIFF_IN		((uint32_t)0x0001 << 3)

/*gapdc_ch_sel*/
#define GPADC_CH_OFFSET		((uint32_t)0x0000 << 1)
#define GPADC_CH_TEMP		((uint32_t)0x0001 << 1)
#define GPADC_CH_CELL		((uint32_t)0x0002 << 1)
#define GPADC_CH_GPIO		((uint32_t)0x0003 << 1)



/*gpadc_en*/
#define GPADC_OPEN			((uint32_t)0x0001)
#define GPADC_DOWN			((uint32_t)0x0000)

/*GPADC_DMA_EN*/
#define GPADC_DMA_OPEN		((uint32_t)0x0001)
#define GPADC_DMA_DOWN		((uint32_t)0x0000)

/*gpadc_write_in_mode*/
#define GPADC_MODE_SINGLE	((uint32_t)0x0000  << 1)
#define GPADC_MODE_MANY		((uint32_t)0x0001  << 1)
#define GPADC_MODE_CONTINU	((uint32_t)0x0002  << 1)

/*gpadc_sample_rate*/
#define GPADC_SAMPLERATE_2k         2000
#define GPADC_SAMPLERATE_4k         4000
#define GPADC_SAMPLERATE_8k         8000
#define GPADC_SAMPLERATE_16k        16000
#define GPADC_SAMPLERATE_32k        32000

#define GPADC_IT_DONE_CLEAR					((uint32_t)0x0001)				
#define GPADC_IT_ALERT_CLEAR				((uint32_t)0x0002)				
#define GPADC_IT_OVFL_CLEAR					((uint32_t)0x0004)				
#define GPADC_IT_DONE_EN					((uint32_t)0x0001)				
#define GPADC_IT_ALERT_EN					((uint32_t)0x0002)				
#define GPADC_IT_OVFL_EN					((uint32_t)0x0004)				
#define GPADC_IT_DONE_MASK					((uint32_t)0x0001)				
#define GPADC_IT_ALERT_MASK					((uint32_t)0x0002)				
#define GPADC_IT_OVFL_MASK					((uint32_t)0x0004)	


void gpadc_init(gpadc_init_type_def* gpadc_init_struct);
void gpadc_cmd(functional_state_t new_state);
void gpadc_it_config(uint32_t gpadc_it_en,functional_state_t new_state);
uint16_t gpadc_receive_fifo_data(void);
uint16_t gpadc_receive_data(void);
uint32_t gpadc_receive_fifo_level(void);
void gpadc_clear_it_pending_bit(uint32_t gpadc_it);

#endif
