⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 touch_panel.c

📁 8032底层驱动部分。因为可以移植 所以单独来拿出来
💻 C
📖 第 1 页 / 共 4 页
字号:
   EINT_UnMask(TP.eint_chan);
   IRQUnmask(IRQ_GPT_CODE);
   return result;      
}

/*************************************************************************
* FUNCTION
*	touch_panel_conf_move_offset
*
* DESCRIPTION
*	This function is to configure pen move offset and stroke move offset.
*
* PARAMETERS
*	pen_offset: pen move offset
*	stroke_offset: stroke move offset
*
* RETURNS
*
* GLOBALS AFFECTED
*
*************************************************************************/
void touch_panel_conf_move_offset(kal_uint16 pen_offset, kal_uint16 stroke_offset, 
                                  kal_uint16 longtap_pen_offset,
                                  kal_uint16 longtap_stroke_offset)
{
   TP.pen_offset=pen_offset;
   TP.storke_offset=stroke_offset;      
   TP.longtap_pen_offset=longtap_pen_offset;
   TP.longtap_stroke_offset=longtap_stroke_offset;
}  


/*************************************************************************
* FUNCTION
*	touch_panel_exceed_penmove
*
* DESCRIPTION
*	This function is pen move event filter.
*
* PARAMETERS
*	x: x coord.
*	y: y coord.
*
* RETURNS
*	exceed MIN_PEN_MOVE_OFFSET or not
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_bool touch_panel_exceed_penmove(kal_int16 x, kal_int16 y)
{
   kal_int16 x_diff, y_diff;
   
   if(x>TP.pre.x)   
      x_diff=x-TP.pre.x;
   else
      x_diff=TP.pre.x-x;   
   if(y>TP.pre.y)   
      y_diff=y-TP.pre.y;
   else
      y_diff=TP.pre.y-y;      
          
   if(TP.longtap_state==KAL_FALSE)/*normal*/
   {
   if((x_diff>=TP.pen_offset||y_diff>=TP.pen_offset)
       &&(x_diff<NONHAND_WRITING_MAX_OFFSET)&&(y_diff<NONHAND_WRITING_MAX_OFFSET))   
      return KAL_TRUE;          
   else
      return KAL_FALSE;   
}  
   else/*longtap*/
   {
      if((x_diff>=TP.longtap_pen_offset||y_diff>=TP.longtap_pen_offset)
          &&(x_diff<NONHAND_WRITING_MAX_OFFSET)&&(y_diff<NONHAND_WRITING_MAX_OFFSET))   
         return KAL_TRUE;          
      else
         return KAL_FALSE;   
      
   }         
}  

/*************************************************************************
* FUNCTION
*	touch_panel_longtap_handwriting_filter
*
* DESCRIPTION
*	This function is to check longtap event in handwriting area.
*
* PARAMETERS
*	x: x coord.
*	y: y coord.
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void touch_panel_longtap_handwriting_filter(kal_int16 x, kal_int16 y)
{
   kal_int16 x_diff, y_diff;      
   
   if(x>TP.begin.x)   
      x_diff=x-TP.begin.x;
   else
      x_diff=TP.begin.x-x;    
      
   if(y>TP.begin.y)    
      y_diff=y-TP.begin.y;
   else
      y_diff=TP.begin.y-y;    
      
   if(x_diff>TP.longtap_stroke_offset||y_diff>TP.longtap_stroke_offset)/*handwriting long tap*/   
   {
      GPTI_StopItem(touch_panel_repeat_handle);          
      TP.longtap_state=KAL_FALSE;
   }   
}  
/*************************************************************************
* FUNCTION
*	touch_panel_stroke_filter
*
* DESCRIPTION
*	This function is stroke move event filter.
*
* PARAMETERS
*	x: x coord.
*	y: y coord.
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void touch_panel_stroke_filter(kal_int16 x, kal_int16 y)
{
   kal_int16 x_diff, y_diff;
   //TouchPanelCoordStruct diff;
   if(TP.longtap_state==KAL_TRUE)
      touch_panel_longtap_handwriting_filter(x, y);
      
   if(x>TP.pre.x)   
      x_diff=x-TP.pre.x;
   else
      x_diff=TP.pre.x-x;    
      
   if(y>TP.pre.y)    
      y_diff=y-TP.pre.y;
   else
      y_diff=TP.pre.y-y;     
         
   if((x_diff>TP.storke_offset||y_diff>TP.storke_offset)
       &&(x_diff<HAND_WRITING_MAX_OFFSET)&&(y_diff<HAND_WRITING_MAX_OFFSET))
   {           
      if(TP.temp.x==0&&TP.temp.y==0)      
      {
         tp_data_pop(STROKE_MOVE,(x-TP.pre.x) ,(y-TP.pre.y));
         TP.pre.x=x;
         TP.pre.y=y;
      }   
      else
      {
         /*use the previous point*/
         tp_data_pop(STROKE_MOVE, (TP.temp.x-TP.pre.x), (TP.temp.y-TP.pre.y));
         TP.pre.x=TP.temp.x;
         TP.pre.y=TP.temp.y;
         if(x>TP.pre.x)   
            x_diff=x-TP.pre.x;
         else
            x_diff=TP.pre.x-x;   
      
         if(y>TP.pre.y)   
            y_diff=y-TP.pre.y;
         else         
            y_diff=TP.pre.y-y;          
            
         if((x_diff>TP.storke_offset||y_diff>TP.storke_offset))
         {
            tp_data_pop(STROKE_MOVE, (x-TP.pre.x), (y-TP.pre.y));
            TP.pre.x=x;
            TP.pre.y=y;
            TP.temp.x=0;
            TP.temp.y=0;
         }   
         else
         {
            TP.temp.x=x;
            TP.temp.y=y;
         }                                    
      }                        
   }
   else     
   {
      TP.temp.x=x;
      TP.temp.y=y;  
   }   
} 

/*************************************************************************
* FUNCTION
*	tp_data_pop
*
* DESCRIPTION
*	This function is to "push" data to buffer.
*
* PARAMETERS
*	x: x coord.
*	y: y coord.
*  event: event type
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/  
kal_uint16 tp_roomleft_min=TOUCH_PANEL_BUFFER_SIZE;
void tp_data_pop(Touch_Panel_Event_enum event, kal_int16 x, kal_int16 y)
{
   kal_uint16 roomleft=0;
   
   tp_get_buf_roomleft(roomleft);   
   /*To get minimum roomleft*/
   if(roomleft<tp_roomleft_min)
      tp_roomleft_min=roomleft;
   
   if(TP.is_buff_full==KAL_TRUE)
      return;
   
   if(roomleft<=BASIC_EVENT_UNIT)
   {
       //if(roomleft>=1)
         //touhc_push_data_to_buffer(PEN_ABORT);         
       /*stop collect events until ring buffer is clean*/
       TP.is_buff_full=KAL_TRUE;
       return;
   }    
   
   if(event==STROKE_MOVE) 
   {
      #ifdef TOUCH_PANEL_DEBUG
      dbg_printWithTime("Move %d,%d\r\n",(kal_int16)x,(kal_int16)y);
      #endif
      /*to avoid STROKE_UP data show in the packet*/
      if(x==STROKE_UP||x==STROKE_LONGTAP)
         x--;
      if(y==STROKE_UP||y==STROKE_LONGTAP)
         y--;   
      touhc_push_data_to_buffer(x,event);/*diff_x*/
      touhc_push_data_to_buffer(y,event);/*diff_y*/   
   }   
   else if(event==STROKE_LONGTAP) 
   {
      touhc_push_data_to_buffer(event,event);/*diff_x*/
   }   
   else if(event==STROKE_UP) 
   {
      touhc_push_data_to_buffer(event, event);         
   }
   else
   {
      //if(roomleft>=BASIC_EVENT_UNIT)
      {
         touhc_push_data_to_buffer(event, event);   
         touhc_push_data_to_buffer(x>>8, event);   
         touhc_push_data_to_buffer(x, event);
	      touhc_push_data_to_buffer(y>>8, event);   
	      touhc_push_data_to_buffer(y, event);   
	   }
   }   
      
}   
  
/*************************************************************************
* FUNCTION
*	touch_panel_check_cali
*
* DESCRIPTION
*	This function is to check calibration result.
*
* PARAMETERS
*	x: x coord.
*	y: y coord.
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/   
kal_bool touch_panel_check_cali_stage3(void)
{
   kal_int16 x, y, x_diff, y_diff;
   double x_slope, y_slope, x_offset, y_offset; 
      
   touch_panel_tuning(cali_point[0].x, cali_point_adc[0].x, 
                      cali_point[1].x, cali_point_adc[1].x, 
                      &x_slope, &x_offset);
   touch_panel_tuning(cali_point[0].y, cali_point_adc[0].y, 
                      cali_point[1].y, cali_point_adc[1].y, 
                      &y_slope, &y_offset); 
        
   x=(kal_int16)(x_slope*(double)(cali_point_adc[2].x)+x_offset);   
   y=(kal_int16)(y_slope*(double)(cali_point_adc[2].y)+y_offset); 
   
   x_diff=cali_point[2].x-x;
   y_diff=cali_point[2].y-y;
   if(x_diff>TOUCH_PANEL_CALI_CHECK_OFFSET||x_diff<-TOUCH_PANEL_CALI_CHECK_OFFSET||
      y_diff>TOUCH_PANEL_CALI_CHECK_OFFSET||y_diff<-TOUCH_PANEL_CALI_CHECK_OFFSET)
      return KAL_FALSE;
   
   return KAL_TRUE;
}   

kal_bool touch_panel_check_cali_stage1(void)
{
   kal_int32 x_adc_range, x_coord_range, x_adc_high, x_adc_low;   
   kal_int32 y_adc_range, y_coord_range, y_adc_high, y_adc_low;
   
   /*use the relative ADC difference*/
   /*X ADC Diff*/
   if(cali_point_adc[1].x>=cali_point_adc[0].x)
      x_adc_range=cali_point_adc[1].x-cali_point_adc[0].x;   
   else
      x_adc_range=cali_point_adc[0].x-cali_point_adc[1].x;   
   /*Y ADC Diff*/   
   if(cali_point_adc[1].y>=cali_point_adc[0].y)   
      y_adc_range=cali_point_adc[1].y-cali_point_adc[0].y;   
   else
      y_adc_range=cali_point_adc[0].y-cali_point_adc[1].y; 
                 
   /*X Coord Diff*/   
   if(cali_point[1].x>=cali_point[0].x)         
      x_coord_range=cali_point[1].x-cali_point[0].x;   
   else
      x_coord_range=cali_point[0].x-cali_point[1].x;      
   /*Y Coord Diff*/      
   if(cali_point[1].y>=cali_point[0].y)   
      y_coord_range=cali_point[1].y-cali_point[0].y;  
   else   
      y_coord_range=cali_point[0].y-cali_point[1].y;  
               
   x_adc_high=x_coord_range*(ADC_X_END-ADC_X_START)*150/(SCREEN_X_END-SCREEN_X_START)/100; 
   x_adc_low=x_coord_range*(ADC_X_END-ADC_X_START)*50/(SCREEN_X_END-SCREEN_X_START)/100;
   y_adc_high=y_coord_range*(ADC_Y_END-ADC_Y_START)*150/(SCREEN_Y_END-SCREEN_Y_START)/100; 
   y_adc_low=y_coord_range*(ADC_Y_END-ADC_Y_START)*50/(SCREEN_Y_END-SCREEN_Y_START)/100;       
   #ifdef TOUCH_PANEL_DEBUG
   dbg_printWithTime("x adc diff=%d high=%d low=%d\r\n",x_adc_range,x_adc_high,x_adc_low ); 
   dbg_printWithTime("y adc diff=%d high=%d low=%d\r\n",y_adc_range,y_adc_high,y_adc_low );                        
   #endif
   if((x_adc_range<x_adc_low) || (x_adc_range>x_adc_high))
      return KAL_FALSE;
   if((y_adc_range<y_adc_low) || (y_adc_range>y_adc_high))
      return KAL_FALSE;                           
   return KAL_TRUE;      
}
kal_bool touch_panel_check_cali_stage2(void)
{   
   kal_int32 x02_diff, y02_diff, x12_diff, y12_diff;
      
   /*use the point 3 to check if the previous 2 two points are opposite*/      
   if(cali_point_adc[1].x>=cali_point_adc[0].x)/*1>2>0*/
   {
      x12_diff=cali_point_adc[1].x-cali_point_adc[2].x;
      x02_diff=cali_point_adc[2].x-cali_point_adc[0].x;            
   }
   else/*0>2>1*/
   {  
      x12_diff=cali_point_adc[2].x-cali_point_adc[1].x;
      x02_diff=cali_point_adc[0].x-cali_point_adc[2].x;            
   }            
   if(cali_point_adc[1].y>=cali_point_adc[0].y)/*1>2>0*/
   {
      y12_diff=cali_point_adc[1].y-cali_point_adc[2].y;
      y02_diff=cali_point_adc[2].y-cali_point_adc[0].y;            
   }
   else/*0>2>1*/
   {  
      y12_diff=cali_point_adc[2].y-cali_point_adc[1].y;
      y02_diff=cali_point_adc[0].y-cali_point_adc[2].y;            
   }   
      
   if(y12_diff>y02_diff||x12_diff>x02_diff)
      return KAL_FALSE;      
   return KAL_TRUE;
}
kal_bool touch_panel_check_cali(void)
{
   kal_bool result1, result2, result3;
   result1=touch_panel_check_cali_stage1();
   result2=touch_panel_check_cali_stage2();
   result3=touch_panel_check_cali_stage3();
      
   if(result1==KAL_TRUE&&result2==KAL_TRUE&&result3==KAL_TRUE)
      return KAL_TRUE;
   else   
      return KAL_FALSE;
}

/*************************************************************************
* FUNCTION
*	touch_excute_cali
*
* DESCRIPTION
*	This function is to excute calibration.
*
* PARAMETERS
*	x: x coord.
*	y: y coord.
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/   
void touch_excute_cali(kal_int16 x_adc, kal_int16 y_adc)
{
   ilm_struct *tp_ilm;
   tp_cali_done_struct *local_para;
   kal_bool cali_result;
   module_type owner=0;
   if(tp_cali_mode==KAL_FALSE)
      return;
   if(tp_cali_cnt==0)         
   {
      #ifdef TOUCH_PANEL_DEBUG
      dbg_printWithTime("1st Cali %d,%d\r\n",x_adc,y_adc);
      #endif
      //touch_panel_read_adc(&(cali_point_adc[0].x),&(cali_point_adc[0].y));
      tp_cali_cnt++;
      cali_point_adc[0].x=x_adc;
      cali_point_adc[0].y=y_adc;      
   }         
   else if(tp_cali_cnt==1)   
   {
      #ifdef TOUCH_PANEL_DEBUG
      dbg_printWithTime("2nd Cali %d,%d\r\n",x_adc,y_adc);
      #endif
      tp_cali_cnt++;
      cali_point_adc[1].x=x_adc;
      cali_point_adc[1].y=y_adc;          
   }
   else if(tp_cali_cnt==2)
   {      
      cali_point_adc[2].x=x_adc;
      cali_point_adc[2].y=y_adc;          
      tp_cali_mode=KAL_FALSE;
      tp_cali_cnt=0;
      cali_result=touch_panel_check_cali();
      
      if(cali_result==KAL_TRUE) 
      {
      touch_panel_tuning(cali_point[0].x, cali_point_adc[0].x, 
                         cali_point[1].x, cali_point_adc[1].x, 
                         &TPCali.x_slope, &TPCali.x_offset);
      touch_panel_tuning(cali_point[0].y, cali_point_adc[0].y, 
                         cali_point[1].y, cali_point_adc[1].y, 
                         &TPCali.y_slope, &TPCali.y_offset);      
      #ifdef TOUCH_PANEL_DEBUG                  
      dbg_printWithTime("x slope=%f off=%f\r\n",TPCali.x_slope,TPCali.x_offset);                         
      dbg_printWithTime("y slope=%f off=%f\r\n",TPCali.y_slope,TPCali.y_offset);                         

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -