#include "touchscreen.h"
#include "my_common.h"
#include "stdlib.h"
#include "math.h"

u16 tp_x[CT_MAX_TOUCH];        //当前坐标
u16 tp_y[CT_MAX_TOUCH];
u16 tp_sta;
u8 tp_touchtype;

/**
  *****************************************************************************
  * @功能描述: 触摸按键扫描
  *
  * @输入参数: tp:0,屏幕坐标;1,物理坐标
  *
  * @返回值   : 当前触屏状态:0,触屏无触摸;1,触屏有触摸
  *****************************************************************************
**/
u8 TP_Scan()
{
    if(PEN==0)
    {                                    //有按键按下
        if((tp_sta&TP_PRES_DOWN)==0)
        {          //之前没有被按下
            tp_sta=TP_PRES_DOWN|TP_CATH_PRES;   //按键按下
            tp_x[4]=tp_x[0];                //记录第一次按下时的坐标
            tp_y[4]=tp_y[0];
        }
    }
    else
    {
        if(tp_sta&TP_PRES_DOWN)
        {               //之前是被按下的
            tp_sta&=~(1<<7);                    //标记按键松开
        }
        else
        {                                    //之前就没有被按下
            tp_x[4]=0;
            tp_y[4]=0;
            tp_x[0]=0xffff;
            tp_y[0]=0xffff;
        }
    }
    return tp_sta&TP_PRES_DOWN;//返回当前的触屏状态
}

/***************触摸屏初始化***************/
void TP_Init(void)
{

	GT9147_Init();
	tp_touchtype|=0X80;                //电容屏
	tp_touchtype|=lcd_dir&0X01;     //横屏还是竖屏

}
