📄 touch_panel.c
字号:
#endif
}
#ifdef TOUCH_PANEL_DEBUG
dbg_printWithTime("cali result=%d\r\n",cali_result);
#endif
local_para = (tp_cali_done_struct *)
construct_local_para(sizeof(tp_cali_done_struct),TD_UL);
local_para->result=cali_result;
#ifdef TOUCH_PANEL_DEBUG
owner=MOD_SSDBG1;
#else
owner=MOD_MMI;
#endif
DRV_BuildPrimitive(tp_ilm,
MOD_TP_TASK,
owner,
MSG_ID_TP_CALI_DONE,
local_para);
msg_send_ext_queue(tp_ilm);
}
}
/*************************************************************************
* FUNCTION
* touch_panel_longtap_cb
*
* DESCRIPTION
* This function is long tap timer callback function.
*
* PARAMETERS
* Parameter
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void touch_panel_longtap_cb(void *parameter)
{
if(TP.state==DOWN)
{
if(TP.area==HAND_WRITING)
{
tp_data_pop(STROKE_LONGTAP, TP.pre.x, TP.pre.y);
}
else
{
tp_data_pop(PEN_LONGTAP, TP.pre.x, TP.pre.y);
#ifdef TOUCH_PANEL_DEBUG
dbg_printWithTime("PEN LONGTAP x=%d y=%d\r\n",TP.pre.x,TP.pre.y);
#endif
if(TP.repeat_cnt!=0)
{
GPTI_StartItem(touch_panel_repeat_handle,
TP.repeat_cnt,
touch_panel_repeat_cb,
NULL);
}
}
}
}
/*************************************************************************
* FUNCTION
* touch_panel_repeat_cb
*
* DESCRIPTION
* This function is repeat timer callback function.
*
* PARAMETERS
* Parameter
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void touch_panel_repeat_cb(void *parameter)
{
if(TP.state==DOWN)
{
tp_data_pop(PEN_REPEAT, TP.pre.x, TP.pre.y);
#ifdef TOUCH_PANEL_DEBUG
dbg_printWithTime("PEN REPEAT x=%d y=%d\r\n",TP.pre.x,TP.pre.y);
#endif
if(TP.repeat_cnt!=0)
{
GPTI_StartItem(touch_panel_repeat_handle,
TP.repeat_cnt,
touch_panel_repeat_cb,
NULL);
}
}
}
/*************************************************************************
* FUNCTION
* touch_panel_stroke_cb
*
* DESCRIPTION
* This function is polling timer callback function in handwriting area.
*
* PARAMETERS
* Parameter
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void touch_panel_stroke_cb(void *parameter)
{
kal_int16 x, y;
kal_bool valid=KAL_FALSE;
if(TP.state==DOWN)
{
touch_panel_read_adc(&x, &y);
valid=touch_panel_adc_to_coordinate(&x,&y);/*translate*/
if(valid==KAL_TRUE)
touch_panel_stroke_filter(x, y);
/*start polling again*/
touch_panel_stroke_hdr();
}
}
/*************************************************************************
* FUNCTION
* touch_panel_event_cb
*
* DESCRIPTION
* This function is polling timer callback function in non-handwriting.
*
* PARAMETERS
* Parameter
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
/*Event timer callback function*/
void touch_panel_event_cb(void *parameter)
{
kal_int16 x=0, y=0;
kal_bool valid=KAL_FALSE;
if(TP.state==DOWN)
{
touch_panel_read_adc(&x, &y);
valid=touch_panel_adc_to_coordinate(&x,&y);/*translate*/
if(touch_panel_exceed_penmove(x, y)&&(valid==KAL_TRUE))
{
TP.longtap_state=KAL_FALSE;
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);
}
}
/*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)
{
*x=(kal_int16)(TPCali.x_slope*(double)(*x)+TPCali.x_offset);
*y=(kal_int16)(TPCali.y_slope*(double)(*y)+TPCali.y_offset);
if( (SCREEN_X_START<=*x)&&(*x<=SCREEN_X_END)&&
(SCREEN_Y_START<=*y)&&(*y<=SCREEN_Y_END))
{
// dbg_printWithTime("Valid X=%d Y=%d\r\n",*x,*y);
return KAL_TRUE;
}
else
{
//dbg_printWithTime("Invalid X=%d Y=%d\r\n",*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;
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*/
void touch_panel_HISR(void)
{
kal_set_eg_events(TP.event,1,KAL_OR);
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;
}
touch_panel_state = !touch_panel_state;
EINT_Set_Polarity(TP.eint_chan,touch_panel_state);
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*/
tp_fun_ptr->tp_irq_enable(enable);
EINT_UnMask(TP.eint_chan);
tp_eint_mask = KAL_FALSE;
}
else/*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;
}
}
/*************************************************************************
* 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)
{
touch_custom_init();
/*external interrupt*/
TP.eint_chan=custom_eint_get_channel(touch_panel_eint_chann);
EINT_Set_HW_Debounce(TP.eint_chan, 5);
EINT_Registration(TP.eint_chan,KAL_TRUE,touch_panel_state,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);
/*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);
}
/*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},
{176,220} };
/*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;
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -