📄 touch_panel.c
字号:
//kal_prompt_trace(MOD_TP_TASK,"touch_panel_event_cb(),TP.state=%d",TP.state);
if(TP.state==DOWN)
{
#ifdef TOUCH_PANEL_PRESSURE
if (KAL_TRUE == tp_fun_ptr->tp_pressure_check())
{
#endif
valid=touch_panel_adc_to_coordinate(&x,&y);/*translate*/
//sprintf(str,"zoom=%d,flick=%d,press=%d",tp_zoom,tp_flick,tp_press);
//kal_print(str);
if(valid==KAL_TRUE)
if(tp_zoom) //new
{
tp_data_pop(CAP_ZOOM, zoomX,zoomY);//new
} //new
if(touch_panel_exceed_penmove(x, y)&&(valid==KAL_TRUE))
{
TP.longtap_state=KAL_FALSE;
// kal_print("SEND PEN_MOVE event");
tp_data_pop(PEN_MOVE, x, y);
#ifdef TOUCH_PANEL_DEBUG
dbg_printWithTime("PEN MOVE x=%d y=%d\r\n",x,y);
#endif
TP.pre.x=x;
TP.pre.y=y;
GPTI_StopItem(touch_panel_repeat_handle);
if(TP.repeat_cnt!=0)/*long tap and reapeat timer*/
{
GPTI_StartItem(touch_panel_repeat_handle,
TP.repeat_cnt,
touch_panel_repeat_cb,
NULL);
}
}
/* else
{
if(valid==KAL_FALSE)
touch_panel_up_hdr();
}
*/
#ifdef TOUCH_PANEL_PRESSURE
}
#endif
/*start polling again*/
touch_panel_event_hdr();
}
}
}
/*************************************************************************
* FUNCTION
* touch_panel_adc_to_coordinate
*
* DESCRIPTION
* This function is to translate ADC to coordinate.
*
* PARAMETERS
* x: x coord.
* y: y coord.
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
/*adc to coordinate*/
kal_bool touch_panel_adc_to_coordinate(kal_int16 *x, kal_int16 *y)
{
char str[100];
*x=(kal_int16)(TPCali.x_slope*(double)(*x)+TPCali.x_offset);
*y=(kal_int16)(TPCali.y_slope*(double)(*y)+TPCali.y_offset);
//sprintf(str," x=%d,y=%d",*x,*y);
// kal_print(str);
if( (SCREEN_X_START<=*x)&&(*x<=SCREEN_X_END)&&
#if defined(__MMI_ADDITIONAL_TOUCH_KEY__)
(SCREEN_Y_START<=*y)&&(*y<=SCREEN_Y_END + 50))
#else
(SCREEN_Y_START<=*y)&&(*y<=SCREEN_Y_END))
#endif
{
// dbg_printWithTime("Valid X=%d Y=%d\r\n",*x,*y);
//kal_prompt_trace(MOD_TP_TASK, "coord.: Valid");
//kal_prompt_trace(MOD_TP_TASK, "coord. (x, y) = (%d, %d)", *x, *y);
//sprintf(str,"x=%d,y=%d,s_x_start=%d,s_y_strt=%d,s_x_end=%d,s_y_end=%d 11 TRUE",*x,*y,SCREEN_X_START,SCREEN_Y_START,SCREEN_X_END,SCREEN_Y_END);
//kal_print(str);
return KAL_TRUE;
}
else
{
//dbg_printWithTime("Invalid X=%d Y=%d\r\n",*x,*y);
//kal_prompt_trace(MOD_TP_TASK, "coord InValid!!. (x, y) = (%d, %d)", *x, *y);
if(*x<SCREEN_X_START)
*x=SCREEN_X_START;
else if (*x>SCREEN_X_END)
*x=SCREEN_X_END;
if(*y<SCREEN_Y_START)
*y=SCREEN_Y_START;
else if (*y>SCREEN_Y_END)
*y=SCREEN_Y_END;
if (tp_cali_mode == KAL_TRUE)
{
//sprintf(str,"x=%d,y=%d,s_x_start=%d,s_y_strt=%d,s_x_end=%d,s_y_end=%d22 TRUE",*x,*y,SCREEN_X_START,SCREEN_Y_START,SCREEN_X_END,SCREEN_Y_END);
//kal_print(str);
return KAL_TRUE;
}
else
{
//kal_prompt_trace(MOD_TP_TASK, "coord.: Invalid");
//sprintf(str,"x=%d,y=%d,s_x_start=%d,s_y_strt=%d,s_x_end=%d,s_y_end=%d FALSE",*x,*y,SCREEN_X_START,SCREEN_Y_START,SCREEN_X_END,SCREEN_Y_END);
//kal_print(str);
return KAL_FALSE;
}
}
}
/*************************************************************************
* FUNCTION
* touch_panel_HISR
*
* DESCRIPTION
* This function is to handle touch event.
*
* PARAMETERS
* None
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
/*touch event HISR, wake up touch panel task*/
#ifdef TOUCH_PANEL_I2C_SUPPORT
kal_uint8 i2c_tp_readflag =0;
//#include "touch_panel_i2c_extern.h"
#endif
kal_uint32 init_count=0;
void tp_i2c_stop(void);
void tp_i2c_start(void);
/*
void Set_touch_panel_state(void)
{
touch_panel_state =0;
EINT_Set_Polarity(TP.eint_chan,touch_panel_state);
GPTI_StopItem(touch_panel_timer);
}
*/
kal_uint8 tp_enlable=1;
void touch_panel_HISR(void)
{
kal_status istatus;
kal_uint8 tst =1;
//char str[100];
//GPIO_WriteIO(1, 5);
#ifdef TOUCH_PANEL_I2C_SUPPORT
//if(!tp_enlable)
//{
//kal_print("tp_enlable 00");
// return;
//}
if(touch_panel_state==0)
{// EINT_Mask(TP.eint_chan);
istatus = kal_set_eg_events(TP.event,1,KAL_OR);
// i2c_tp_readflag = 1;
TP.state =DOWN;
touch_panel_state =1;
EINT_Set_Polarity(TP.eint_chan,touch_panel_state);
}
#else
if (touch_panel_state==touch_down_level)/*low*/
{
#ifdef TOUCH_PANEL_DEBUG
dbg_printWithTime("touch down\r\n");
#endif
TP.state=DOWN;
}
else/*high*/
{
#ifdef TOUCH_PANEL_DEBUG
dbg_printWithTime("touch up\r\n");
#endif
TP.state=UP;
}
#endif
// EINT_UnMask(TP.eint_chan); //开中断
}
/*************************************************************************
* FUNCTION
* touch_panel_read_adc
*
* DESCRIPTION
* This function is to read adc from touch panel module.
*
* PARAMETERS
* x: x coord.
* y: y coord.
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void touch_panel_read_adc(kal_int16 *x, kal_int16 *y)
{
tp_fun_ptr->tp_read_adc(x, y);
}
/*************************************************************************
* FUNCTION
* touch_panel_enable
*
* DESCRIPTION
* This function is to enable/disbale touch panel module.
*
* PARAMETERS
* x: x coord.
* y: y coord.
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
/*enable/disable touch panel*/
void touch_panel_enable(kal_bool enable)
{
/*enable*/
if(enable==KAL_TRUE)
{
/*EINT*/
// kal_print("touch_panel_enable ");
tp_fun_ptr->tp_irq_enable(enable);
EINT_UnMask(TP.eint_chan);
tp_eint_mask = KAL_FALSE;
Cap_touchpal_on_off(1);//qsh
// touch_panel_state =0;
// EINT_Set_Polarity(TP.eint_chan,touch_panel_state);
}
else/*disbale*/
{
//kal_print("touch_panel_enable disbale");
EINT_Mask(TP.eint_chan);
GPTI_StopItem(touch_panel_handle);
GPTI_StopItem(touch_panel_repeat_handle);
tp_fun_ptr->tp_irq_enable(enable);
tp_eint_mask = KAL_TRUE;
Cap_touchpal_on_off(0);//qsh
}
}
/*************************************************************************
* FUNCTION
* touch_panel_init
*
* DESCRIPTION
* This function is to initialize touch panel module.
*
* PARAMETERS
* None
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void touch_custom_init(void)
{
TouchPanel_custom_data_struct *tp_data;
tp_fun_ptr=tp_GetFunc();
tp_data = tp_fun_ptr->tp_get_data();
ADC_X_START=tp_data->x_adc_start;
ADC_X_END=tp_data->x_adc_end;
ADC_Y_START=tp_data->y_adc_start;
ADC_Y_END=tp_data->y_adc_end;
SCREEN_X_START=tp_data->x_coord_start;
SCREEN_X_END=tp_data->x_coord_end;
SCREEN_Y_START=tp_data->y_coord_start;
SCREEN_Y_END=tp_data->y_coord_end;
touch_panel_state=tp_data->eint_down_level;
}
/*touch panel initialization*/
void touch_panel_init(void)
{
char str[100];
#if 1
GPIO_ModeSetup(5,0);
GPIO_InitIO(1,5);
touch_custom_init();
/*external interrupt*/
TP.eint_chan=custom_eint_get_channel(touch_panel_eint_chann);
// sprintf(str,"QSH TEST TP touch_panel_init_no %d",TP.eint_chan);
// kal_print(str);
EINT_Set_HW_Debounce(TP.eint_chan, 5);//5
EINT_Registration(TP.eint_chan,KAL_TRUE,touch_panel_state,touch_panel_HISR, KAL_TRUE);
// EINT_Registration(TP.eint_chan,,touch_panel_state,touch_panel_HISR, KAL_TRUE);
//EINT_Registration(TP.eint_chan,KAL_TRUE,touch_down_level,touch_panel_HISR, KAL_TRUE);
EINT_Mask(TP.eint_chan);
/*event call back*/
touch_panel_cb_registration(touch_panel_sendilm, NULL);
/*get gpt handle*/
GPTI_GetHandle(&touch_panel_handle);
GPTI_GetHandle(&touch_panel_repeat_handle);
GPTI_GetHandle(&touch_panel_timer);//qsh
/*configure default pen/move offset*/
touch_panel_conf_move_offset(MIN_PEN_MOVE_OFFSET, MAX_STROKE_MOVE_OFFSET, 10,10);
/*buff full flag*/
TP.is_buff_full=KAL_FALSE;
/*cali*/
touch_panel_tuning(SCREEN_X_START, ADC_X_START, SCREEN_X_END, ADC_X_END, &TPCali.x_slope, &TPCali.x_offset);
touch_panel_tuning(SCREEN_Y_START, ADC_Y_START, SCREEN_Y_END, ADC_Y_END, &TPCali.y_slope, &TPCali.y_offset);
//touch_panel_start_cali(coord, 2);
#endif
}
/*The following are for tests*/
void touch_panel_test(void)
{
TouchPanelHandAreaStruct handarea[2]={
{{0,0},
{88,110}},
{{0,0},
{88,110}}
};
TouchPanelHandAreaStruct ext_handarea={ {1,1},
{320,240} };
/*MMI should call the following function*/
touch_panel_enable(KAL_TRUE);
touch_panel_conf_handwriting(handarea,2,&ext_handarea);
touch_panle_conf_sample_period(10, 1);/*100ms, 20ms*/
touch_panle_conf_timeout_period(200,100, 200);/*2s, 1s, 2s*/
}
void tp_area_change_to_event(void)
{
TouchPanelHandAreaStruct handarea[2]={
{{0,0},
{0,0}},
{{1,1},
{1,1}}
};
TouchPanelHandAreaStruct ext_handarea={ {1,1},
{176,220} };
touch_panel_conf_handwriting(handarea,2,&ext_handarea);
touch_panel_reset_handwriting();
}
void tp_area_change_to_stroke(void)
{
TouchPanelHandAreaStruct handarea[2]={
{{0,0},
{175,219}},
{{1,1},
{176,219}}
};
TouchPanelHandAreaStruct ext_handarea={ {1,1},
{176,220} };
touch_panel_conf_handwriting(handarea,2,&ext_handarea);
touch_panel_reset(KAL_TRUE);
}
void tp_cali_test(void)
{
TouchPanelCoordStruct coord[2]={
{0,0},
{176,220}
};
touch_panel_start_cali(coord, 2);
}
void tp_cali_end_test(void)
{
touch_panel_stop_cali();
}
void tp_kp_control(kal_uint8 key)
{
switch (key)
{
case 1:
tp_area_change_to_event();
break;
case 2:
tp_area_change_to_stroke();
break;
case 3:
tp_cali_test();
break;
case 4:
tp_cali_end_test();
break;
case 5:
touch_panel_reset_handwriting();
break;
default:
break;
}
}
int tp_is_cali_mode()
{
if (tp_cali_mode)
return 1;
else
return 0;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -