/*--------------------------------------------------------------------------
Header file for ADC.
--------------------------------------------------------------------------*/

#ifndef __ADC_H__
#define __ADC_H__

// Example Code

void ADC_start(unsigned char Length);
void ADC_Init(void);
void ADC_stop(void);
void ADC_SetInputSource(unsigned char nInputSel, unsigned char nChannelNO, unsigned char nMode);
void ADC_GetSampleResult(unsigned int *pResult, unsigned char nLength);
void ADC_TimerTrigger(unsigned char nData);
void ADC_TimerTriggerCounter(unsigned int Counter);
void ADC_EnableIE(unsigned int Mode);
//===============================
//DEFINITIONs
//===============================
#define d_ADCnEN            0x01
#define d_ADC_CLK_Sel       d_ADC_CLK_DIV6

#define d_ADC_CLK_DIV2      0x00
#define d_ADC_CLK_DIV4      0x01
#define d_ADC_CLK_DIV6      0x02
#define d_ADC_CLK_DIV8      0X03
#define d_ADC_CLK_DIV10     0x04
#define d_ADC_CLK_DIV12     0x05
#define d_ADC_CLK_DIV14     0x06
#define d_ADC_CLK_DIV16     0x07
#define d_ADC_CLK_DIV18     0x08
#define d_ADC_CLK_DIV20     0x09
#define d_ADC_CLK_DIV22     0x0A
#define d_ADC_CLK_DIV24     0x0B
#define d_ADC_CLK_DIV26     0x0C
#define d_ADC_CLK_DIV28     0x0D
#define d_ADC_CLK_DIV30     0x0E
#define d_ADC_CLK_DIV32     0x0F
#define d_ADC_CLK_DIV34     0x10
#define d_ADC_CLK_DIV36     0x11
#define d_ADC_CLK_DIV38     0x12
#define d_ADC_CLK_DIV40     0x13
#define d_ADC_CLK_DIV42     0x14
#define d_ADC_CLK_DIV44     0x15
#define d_ADC_CLK_DIV46     0x16
#define d_ADC_CLK_DIV48     0x17
#define d_ADC_CLK_DIV50     0x18
#define d_ADC_CLK_DIV52     0x19
#define d_ADC_CLK_DIV54     0x1A
#define d_ADC_CLK_DIV56     0x1B
#define d_ADC_CLK_DIV58     0x1C
#define d_ADC_CLK_DIV60     0x1D
#define d_ADC_CLK_DIV62     0x1E
#define d_ADC_CLK_DIV64     0x1F

#define d_ADC_CH0_IN        	0x00
#define d_ADC_CH1_IN        	0x01
#define d_ADC_CH2_IN        	0x02
#define d_ADC_CH3_IN        	0x03
#define d_ADC_CH4_IN        	0x04
#define d_ADC_CH5_IN        	0x05
#define d_ADC_CH6_IN        	0x06
#define d_ADC_CH7_IN        	0x07
#define d_ADC_CH8_IN        	0x08
#define d_ADC_OPA_OUT_IN    	0x0D
#define d_ADC_OPA_OUT_AVG_IN  0x0E
#define d_ADC_BG_06V_IN       0x0F
#define d_ADC_BG_06V_IN       0x0F


#define d_ADC_INPUT_1ST       0
#define d_ADC_INPUT_2ND       1
#define d_ADC_INPUT_3RD       2
#define d_ADC_INPUT_4TH       3

#define d_ADC_MODE_continue   0
#define d_ADC_MODE_SINGLE     1

#define d_ADC_INT_SINGLE      0x01     // completion of a conversion on ADC
#define d_ADC_INT_SEQUENCE    0x02     // completion of a conversion on sequence
#define d_ADC_INT_1ST         0x10
#define d_ADC_INT_2ND         0x20
#define d_ADC_INT_3RD         0x30
#define d_ADC_INT_4TH         0x40


#define d_ADC_TIMER_MODE_SINGLE      (0x00 << 0x06)
#define d_ADC_TIMER_MODE_CONTINUOUS  (0x01 << 0x06)

#define d_ADC_TIMER_INACTIVE_DISABLE (0x00 << 0x05)
#define d_ADC_TIMER_INACTIVE_ENABLE  (0x01 << 0x05)

#define d_ADC_TIMER_ALIGN_ENABLE     (0x00 << 0x04)
#define d_ADC_TIMER_ALIGN_DISABLE    (0x01 << 0x04)

#define d_ADC_TIMER_CHANNEL_PWM0    0x00 
#define d_ADC_TIMER_CHANNEL_PWM1    0x01 
#define d_ADC_TIMER_CHANNEL_PWM2    0x02 
#define d_ADC_TIMER_CHANNEL_PWM3    0x03 
#define d_ADC_TIMER_CHANNEL_PWM4    0x04 
#define d_ADC_TIMER_CHANNEL_PWM5    0x05 

#endif
