📄 touch.c
字号:
#include "public.h"
//#include "touch.h"
//#include "dsa.h"
unsigned char CountTouchPanelTimer10ms;
TouchDriver_Handle *gTouchDriver_Handle = 0;
#ifdef TOUCH_PANEL_DRIVER_TSC2003
void write_tsc2003(unsigned char iDeviceAddr, unsigned char command )
{
int loop;
for (loop=0; loop<tsc2003_wr_loop_max; loop++)
{
I2CStart();
if(0==I2COut8Bit(iDeviceAddr))
{
if(0==I2COut8Bit(command))
{
I2CStop();
break;
}
}
init_I2C();
}
}
int read_tsc2003(unsigned char iDeviceAddr)
{
int data=0;
int loop;
for (loop=0; loop<tsc2003_wr_loop_max; loop++)
{
//i2c_start_sig();
I2CStart();
if(0 == I2COut8Bit(iDeviceAddr))
{
data = I2CIn16Bit();//i2c_2bytes_r();/*use 12bit mode*///i2c_byte_r(1); ....................?????????
//i2c_stop_sig();
I2CStop();
break;
}
init_I2C();
}
data = ((data>>4)&0x0fff);
//data = data>>4;
return data;
}
unsigned char is_touched(void)
{
unsigned char penirq_flag;
write_tsc2003( TSC2003_write, 0xb0 );//TSC2007 reset pd0,pd1,is nessary!!!
//need set gpio.
penirq_flag = PINin_TOUCH_DET;//GPIO_I_GET(PENIRQ_STATUS_GPIO);
if(penirq_flag == 0)
{
return 1;
debug("Touch");
}
else
{
debug("no touch");
return 0;
}
}
int get_x_coordinate(void)
{
int X=0;
write_tsc2003( TSC2003_write,command_x );
X= read_tsc2003(TSC2003_read);
return X;
}
int get_y_coordinate(void)
{
int Y=0;
write_tsc2003( TSC2003_write,command_y );
Y= read_tsc2003(TSC2003_read);
return Y;
}
void TouchPanelMain(void)
{
if(CountTouchPanelTimer10ms == 0)
{
polling_tsc2003_100ms();
CountTouchPanelTimer10ms = 10;
}
}
void polling_tsc2003_100ms(void)
{
int x_change_range;
int y_change_range;
if(is_touched() == 1)
{
gTouchDriver_Handle->counter_flag ++;
gTouchDriver_Handle->temp_x= get_x_coordinate();
gTouchDriver_Handle->temp_y= get_y_coordinate();
if(gTouchDriver_Handle->counter_flag > touch_times)
{
if(gTouchDriver_Handle->Touch_x_now < gTouchDriver_Handle->temp_x)
x_change_range = gTouchDriver_Handle->temp_x - gTouchDriver_Handle->Touch_x_now;
else
x_change_range = gTouchDriver_Handle->Touch_x_now - gTouchDriver_Handle->temp_x;
if(gTouchDriver_Handle->Touch_y_now < gTouchDriver_Handle->temp_y)
y_change_range = gTouchDriver_Handle->temp_y - gTouchDriver_Handle->Touch_y_now;
else
y_change_range = gTouchDriver_Handle->Touch_y_now - gTouchDriver_Handle->temp_y;
gTouchDriver_Handle->event_id = LONG_PRESS;
if((x_change_range>x_keep_range)||(y_change_range>y_keep_range))
{
gTouchDriver_Handle->Touch_x_now= gTouchDriver_Handle->temp_x;
gTouchDriver_Handle->Touch_y_now= gTouchDriver_Handle->temp_y;
}
if(gTouchDriver_Handle->counter_flag==255)
gTouchDriver_Handle->counter_flag = touch_times ;
//Give the x/y/event id to upper layer here for long time press
/*
gTouchAction.gCoordinate.horizontal = gTouchDriver_Handle->Touch_x_now;
gTouchAction.gCoordinate.vertical = gTouchDriver_Handle->Touch_y_now;
gTouchAction.EVENT_ID = LONG_PRESS;
*/
}
else if(gTouchDriver_Handle->counter_flag <= touch_times)
{
gTouchDriver_Handle->Touch_x_now = gTouchDriver_Handle->temp_x;
gTouchDriver_Handle->Touch_y_now = gTouchDriver_Handle->temp_y;
gTouchDriver_Handle->event_id = SHORT_PRESS;
}
//printf("Touch_x_now,Touch_y_now are %d,%d\n", gTouchDriver_Handle->Touch_x_now,gTouchDriver_Handle->Touch_y_now);
}
else
{
if((gTouchDriver_Handle->event_id == SHORT_PRESS)||(gTouchDriver_Handle->event_id == LONG_PRESS))
{
//Give the x/y/event id to upper layer here for long time press
//Remeber here the value of event_id which for upper layer must be SHORT_PRESS
/*
gTouchAction.gCoordinate.horizontal = gTouchDriver_Handle->Touch_x_now;
gTouchAction.gCoordinate.vertical = gTouchDriver_Handle->Touch_y_now;
gTouchAction.EVENT_ID = SHORT_PRESS;
*/
//dsa_send_data(SEND_TOUCH_PRESS_FLAG,gTouchDriver_Handle->event_id);
//dsa_send_data(SEND_TOUCH_PANEL_X,(BYTE)gTouchDriver_Handle->Touch_x_now);
//dsa_send_data(SEND_TOUCH_PANEL_Y,(BYTE)gTouchDriver_Handle->Touch_y_now);
ADDSendCommandToBuff(SEND_TOUCH_PRESS_FLAG,gTouchDriver_Handle->event_id);
ADDSendCommandToBuff(SEND_TOUCH_PANEL_X,(unsigned char)gTouchDriver_Handle->Touch_x_now);
ADDSendCommandToBuff(SEND_TOUCH_PANEL_Y,(unsigned char)gTouchDriver_Handle->Touch_y_now);
debug_val("TOUCH X",gTouchDriver_Handle->Touch_x_now);
debug_val("TOUCH Y",gTouchDriver_Handle->Touch_y_now);
// SCI_SendPromter("X", &gTouchDriver_Handle->Touch_x_now,1);
// SCI_SendPromter("Y", &gTouchDriver_Handle->Touch_y_now,1);
}
gTouchDriver_Handle->event_id = NO_TOUCH;
gTouchDriver_Handle->Touch_x_now= 0;
gTouchDriver_Handle->Touch_y_now= 0;
gTouchDriver_Handle->temp_x = 0;
gTouchDriver_Handle->temp_y = 0;
gTouchDriver_Handle->counter_flag = 0;
//printf("There is no touch in the four-line-touch-screen!\n");
}
}
void TouchPanelInit(void)
{
PD_TOUCH_DET = 0;
PCR1_TOUCH_DET = 1;
PCR2_TOUCH_DET = 1;
//PD_DSADATA = 1;
}
void TouchPanelTimer10ms(void)
{
if(CountTouchPanelTimer10ms > 0)
CountTouchPanelTimer10ms --;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -