/*******************************************************************************
* @Copyright (c)    :(C)2020, Qingdao ieslab Co., Ltd
* @FileName         :hc32_adc_driver.h
* @Author           :Kv-L
* @Version          :V1.0
* @Date             :2020年7月1日 17:57:05
* @Description      :电压转换范围：0~2.5V;  最大连续转换次数：80次
*******************************************************************************/

/*********************************VREFINT***************************************
* typ voltage :1.212V
* Min ADC sampling time : 4us
*
*******************************************************************************/
/*************************external channels*************************************
* 采样电容：CADC = 5pF；
* 允许最大外部输入电阻：RAIN = 50KΩ；
* 内部电阻：RADC = ？；
* 取60RC = 15us经测试足够给采样电容充满电。
* 外部输入通道以最小采样时间15us计算。
*******************************************************************************/

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __UWater_ADC_DRIVER_H
#define __UWater_ADC_DRIVER_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "sys_config.h"
#include "ddl.h"
#include "type.h"

/* Exported types ------------------------------------------------------------*/

/* Exported constants --------------------------------------------------------*/

/* Exported macro ------------------------------------------------------------*/
/*ADCs to use*/

/*External analog input channel selection*/
#if (HARDWARE_VERSION==0x14)//方壳表
#define ADC_IN0     0       //PA00   //use:1     ;not use:0
#define ADC_IN1     0       //PA01   
#define ADC_IN2     0       //PA02
#define ADC_IN3     0       //PA03
#define ADC_IN4     0       //PA04
#define ADC_IN5     1       //PA05
#define ADC_IN6     0       //PA06
#define ADC_IN7     0       //PA07
#define ADC_IN8     0       //PB00
#define ADC_IN9     0       //PB01
#define ADC_IN10    1       //PC00
#define ADC_IN11    0       //PC01
#define ADC_IN12    1       //PC02
#define ADC_IN13    1       //PC03
#define ADC_IN14    0       //PC04
#define ADC_IN15    0       //PC05
#define ADC_IN16    0       //PB02
#define ADC_IN17    0       //PB10
#define ADC_IN18    0       //PB11
#define ADC_IN19    0       //PB12
#define ADC_IN20    0       //PB13
#define ADC_IN21    0       //PB14
#define ADC_IN22    0       //PB15
#define ADC_IN23    0       //PE15
#define ADC_IN24    0       //PE14
#define ADC_IN25    0       //PE13

#elif (HARDWARE_VERSION==0x18)//圆壳表
#define ADC_IN0     0       //PA00   //use:1     ;not use:0
#define ADC_IN1     0       //PA01   
#define ADC_IN2     0       //PA02
#define ADC_IN3     0       //PA03
#define ADC_IN4     0       //PA04
#define ADC_IN5     0       //PA05//T1_ADC_MCU
#define ADC_IN6     0       //PA06
#define ADC_IN7     1       //PA07
#define ADC_IN8     0       //PB00
#define ADC_IN9     0       //PB01
#define ADC_IN10    1       //PC00//BAT_CHECK_MCU
#define ADC_IN11    0       //PC01
#define ADC_IN12    1       //PC02//NB_PSM_CHECK
#define ADC_IN13    1       //PC03//VALVE_ADC_V_MCU
#define ADC_IN14    0       //PC04
#define ADC_IN15    0       //PC05
#define ADC_IN16    0       //PB02
#define ADC_IN17    0       //PB10
#define ADC_IN18    0       //PB11
#define ADC_IN19    0       //PB12
#define ADC_IN20    0       //PB13
#define ADC_IN21    0       //PB14
#define ADC_IN22    0       //PB15
#define ADC_IN23    0       //PE15
#define ADC_IN24    0       //PE14
#define ADC_IN25    0       //PE13
#endif




/*Main machine states*/
#define ADC_IDLE            0
#define ADC_CFGADC			1
#define ADC_START			2
#define ADC_CONV			3
#define ADC_END				4

/*states*/
#define ADC_OK              0x00
#define ADC_START_ERROR     0x01
#define ADC_CONV_TIMEOUT	0x02

/*convert result array*/
#define MIN     0
#define SUM     1
#define MAX     2
#define MINCONVNUM	3
/*Max conv num*/
#define MAXCONVNUM  80  //max:86!
/*adc_timeout*/
#define  ADC_TIMEOUT  100  //单位：us
/* Exported functions ------------------------------------------------------- */
void AdcStartConvert( u8 AdcChannel, u32 ConvNum, u32 TimeInterval, u32 *ConvResult, u8 *ConvIfDone);
void AdcMachineDriver(void);
u8 AdcIfIdle(void);
u8 AdcGetStatus(void);
u8 AdcIfSleep(void);
void AdcPreSleep(void);
void AdcWakeSleep(void);
#ifdef __cplusplus
}
#endif

#endif /* __UWater_ADC_DRIVER_H */

/***************************************************************END OF FILE****/
