#ifndef __TOUCH_H__
#define __TOUCH_H__
#include <intrins.h>
#include"LCD drive.h"


			#if 0
			/* touch panel interface define */
			sbit DCLK	   =    P3^6;   
			sbit CS        =    P3^7;
			sbit DIN       =    P3^5;
			sbit BUSY      =    P3^3;	
			sbit DOUT      =    P3^4;																						   
			sbit Penirq    =    P3^3;   //触碰触摸屏时，ADS7843/XPT2046的笔中断Penirq引脚产生低电平中断信号;
			                            //没有碰触触摸屏时，触摸控制芯片的笔中断引脚输出为高电平。
			struct struct1       //定义一个类型名为struct1的结构,包含两个成员x和y
			{
				unsigned int x;         //成员x
				unsigned int y;         //成员y
			};  
			/* LCD color */
			#define White          0xFFFF
			#define Black          0x0000
			#define Blue           0x001F
			#define Blue2          0x051F
			#define Red            0xF800
			#define Magenta        0xF81F
			#define Green          0x07E0
			#define Cyan           0x7FFF
			#define Yellow         0xFFE0
			
			
			extern struct struct1 coordinate;      //定义一个名为Tp_pix的结构变量,用于存放处理后的触摸坐标参数
			extern unsigned int  lx,ly;  
			
			void drawpoint(unsigned char x,unsigned int y,unsigned int color);
			void LCD_SetPos(unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1);
			void start_7843();
			void Write_7843();          //SPI写8位命令到触摸控制IC
			unsigned int Read_7843();   //SPI 读数据
			struct struct1 AD7843() ;
			unsigned char pix_filter(struct struct1 pix1,struct struct1 pix2);
			unsigned char Getpix();
			#endif
typedef unsigned long  u32;
typedef unsigned short u16;
typedef unsigned char  u8;



//画笔颜色
#define WHITE         	 0xFFFF
#define BLACK         	 0x0000	  
#define BLUE         	 0x001F  
#define BRED             0XF81F
#define GRED 			 0XFFE0
#define GBLUE			 0X07FF
#define RED           	 0xF800
#define MAGENTA       	 0xF81F
#define GREEN         	 0x07E0
#define CYAN          	 0x7FFF
#define YELLOW        	 0xFFE0
#define BROWN 			 0XBC40 //棕色
#define BRRED 			 0XFC07 //棕红色
#define GRAY  			 0X8430 //灰色																						   

#define TP_PRES_DOWN 0x80  //触屏被按下	  
#define TP_CATH_PRES 0x40  //有按键按下了 	  
										    
//触摸屏控制器
typedef struct
{
	u8 a;			//初始化触摸屏控制器
	u8 (*scan)(u8);				//扫描触摸屏.0,屏幕扫描;1,物理坐标;	 
	void (*adjust)(void);		//触摸屏校准
	u16 x0;						//原始坐标(第一次按下时的坐标)
	u16 y0;
	u16 x; 						//当前坐标(此次扫描时,触屏的坐标)
	u16 y;						   	    
	u8  sta;					//笔的状态 
								//b7:按下1/松开0; 
	                            //b6:0,没有按键按下;1,有按键按下.         			  
////////////////////////触摸屏校准参数/////////////////////////								
	float xfac;					
	float yfac;
	short xoff;
	short yoff;	   
//新增的参数,当触摸屏的左右上下完全颠倒时需要用到.
//touchtype=0的时候,适合左右为X坐标,上下为Y坐标的TP.
//touchtype=1的时候,适合左右为Y坐标,上下为X坐标的TP.
	u8 touchtype;
}_m_tp_dev;

extern _m_tp_dev tp_dev;	 	//触屏控制器在touch.c里面定义

//与触摸屏芯片连接引脚	   
sbit PEN  	=    P3^3;
sbit DOUT 	=    P3^4;   	//PF8  MISO
sbit TDIN 	=    P3^5;  	//PF9  MOSI
sbit TCL 	=    P3^6;  	//PB1  SCLK
sbit TCS  	=    P3^7;  	//PB2  CS  
     
void TP_Adj_Info_Show(u16 x0,u16 y0,u16 x1,u16 y1,u16 x2,u16 y2,u16 x3,u16 y3,u16 fac);//显示校准信息

void Write_7843(unsigned char temp);
void TP_Write_Byte(u8 num);						//向控制芯片写入一个数据
u16 TP_Read_AD(u8 CMD);							//读取AD转换值
u16 TP_Read_XOY(u8 xy);							//带滤波的坐标读取(X/Y)
u8 TP_Read_XY(u16 *x,u16 *y);					//双方向读取(X+Y)
u8 TP_Read_XY2(u16 *x,u16 *y);					//带加强滤波的双方向坐标读取
void TP_Drow_Touch_Point(u16 x,u16 y,u16 color);//画一个坐标校准点
void TP_Draw_Big_Point(u16 x,u16 y,u16 color);	//画一个大点
u8 TP_Scan(u8 tp);								//扫描
void TP_Save_Adjdata(void);						//保存校准参数
u8 TP_Get_Adjdata(void);						//读取校准参数
void TP_Adjust(void);							//触摸屏校准
u8 TP_Init(void);								//初始化
void LCD_DrawLine(u16 x1, u16 y1, u16 x2, u16 y2);
void LCD_DrawPoint(u16 x,u16 y);
void LCD_ShowString(u16 x,u16 y,u16 width,u16 height,u8 size,u8 *p);
void LCD_ShowChar(u16 x,u16 y,u8 num,u8 size,u8 mode);
void Draw_Circle(u16 x0,u16 y0,u8 r);
void LCD_ShowNum(u16 x,u16 y,u32 num,u8 len,u8 size);
void LCD_SetPos(unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1);
u32 LCD_Pow(u8 m,u8 n);
void Load_Drow_Dialog(void);																 



 

     

#endif