#ifndef TP_DRV_H_
#define TP_DRV_H_

#include "i2c_drv.h"
#include "eport_drv.h"
#include "type.h"

#define RESISTIVE					0
#define CAPACITIVE				1
#define TOUCHPANEL				RESISTIVE

#define 		I2C_addr				0x28
#define 		gt911_addr			0x28
#define 		ft5216_addr			0x70
#define 		cjt540_addr			0x34

extern void I2C_delay(UINT32 val);
extern u8 I2C_Start(void);
extern void I2C_Stop(void);
extern void I2C_SendAck(u8 ack);  //参数 0=ack  1=noack
extern void I2C_write_byte(const u8 s);
extern u8 I2C_read_byte(void);
extern u8 I2C_WaitAck(void);     //返回值 0=ack  1=noack


/*------RTP GPIO --------*///  XM=X- XP=X+ YM=Y- YP=Y+  
#define		RTP_XM_OUT			 EPORT_ConfigGpio(EPORT_PIN33, GPIO_OUTPUT)   			    //X-配置为GPIO输出
#define		RTP_XM_IN		  	 EPORT_ConfigGpio(EPORT_PIN33, GPIO_INPUT) 			 			  //X-配置为GPIO输入
#define		RTP_XM_UP		  	 EPORT_PullupConfig(EPORT_PIN33, ENABLE)							  //X-配置为上拉
#define		RTP_XM_DOWN		   EPORT_PullupConfig(EPORT_PIN33, DISABLE)							  //X-配置为下拉
#define		RTP_XM_LEVEL(x)	 ((x==1)?EPORT_WriteGpioData(EPORT_PIN33, Bit_SET):EPORT_WriteGpioData(EPORT_PIN33, Bit_RESET))		//X-输出高低电平

#define		RTP_XP_OUT		 	I2C_ConfigGpio(I2C_SDA, GPIO_OUTPUT)
#define		RTP_XP_IN		   	I2C_ConfigGpio(I2C_SDA, GPIO_INPUT)	
#define		RTP_XP_UP		   	I2C->PCR |= (1<<1)
#define		RTP_XP_DOWN		 	I2C->PCR &=~(1<<1)
#define		RTP_XP_LEVEL(x)	((x==1)?I2C_WriteGpioData(I2C_SDA, Bit_SET):I2C_WriteGpioData(I2C_SDA, Bit_RESET))

#define		RTP_YM_OUT		 	EPORT_ConfigGpio(EPORT_PIN34, GPIO_OUTPUT)
#define		RTP_YM_IN		   	EPORT_ConfigGpio(EPORT_PIN34, GPIO_INPUT)
#define		RTP_YM_UP		  	EPORT_PullupConfig(EPORT_PIN34, ENABLE)
#define		RTP_YM_DOWN		 	EPORT_PullupConfig(EPORT_PIN34, DISABLE)
#define		RTP_YM_LEVEL(x)	((x==1)?EPORT_WriteGpioData(EPORT_PIN34, Bit_SET):EPORT_WriteGpioData(EPORT_PIN34, Bit_RESET))

#define		RTP_YP_OUT		 	I2C_ConfigGpio(I2C_SCL, GPIO_OUTPUT)
#define		RTP_YP_IN		   	I2C_ConfigGpio(I2C_SCL, GPIO_INPUT)
#define		RTP_YP_UP		   	I2C->PCR |= (1<<0)
#define		RTP_YP_DOWN		 	I2C->PCR &=~(1<<0)
#define		RTP_YP_LEVEL(x)	((x==1)?I2C_WriteGpioData(I2C_SCL, Bit_SET):I2C_WriteGpioData(I2C_SCL, Bit_RESET))

/*------CTP GPIO --------*/
#define     SCL_OUTPUT                  I2C_ConfigGpio(I2C_SCL,GPIO_OUTPUT)
#define     SCL_Pullup                  I2C->PCR|=(Bit_SET<<I2C_SCL)
#define     SCL_High                    I2C_WriteGpioData(I2C_SCL,Bit_SET)
#define     SCL_Low                     I2C_WriteGpioData(I2C_SCL,Bit_RESET)

#define     SDA_OUTPUT                  I2C_ConfigGpio(I2C_SDA,GPIO_OUTPUT)				
#define     SDA_INPUT                   I2C_ConfigGpio(I2C_SDA,GPIO_INPUT)
#define     SDA_Pullup                  I2C->PCR|=(Bit_SET<<I2C_SDA)
#define     GetSDABit                   I2C_ReadGpioData(I2C_SDA)
#define     SDA_High                   	I2C_WriteGpioData(I2C_SDA,Bit_SET)
#define     SDA_Low                     I2C_WriteGpioData(I2C_SDA,Bit_RESET)

#define     RST_OUTPUT                  EPORT_ConfigGpio(EPORT_PIN34, GPIO_OUTPUT)
#define     RST_High                   	EPORT_WriteGpioData(EPORT_PIN34,Bit_SET)
#define     RST_Low                    	EPORT_WriteGpioData(EPORT_PIN34,Bit_RESET)

#define     INT_OUTPUT                  EPORT_ConfigGpio(EPORT_PIN33, GPIO_OUTPUT)
#define     INT_INPUT                   EPORT_ConfigGpio(EPORT_PIN33, GPIO_INPUT)
#define     INT_Interrupt               EPORT_Init(EPORT_PIN33,RISING_EDGE_INT)
#define		GET_INT_Bit									EPORT_ReadGpioData(EPORT_PIN33)
#define     INT_High                    EPORT_WriteGpioData(EPORT_PIN33,Bit_SET)
#define     INT_Low                     EPORT_WriteGpioData(EPORT_PIN33,Bit_RESET)


#endif
