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

📄 touch_panel.c

📁 8032底层驱动部分。因为可以移植 所以单独来拿出来
💻 C
📖 第 1 页 / 共 4 页
字号:
            if((TP.ext_handarea.min.x!=TP.ext_handarea.max.x)&&
               (TP.ext_handarea.min.y!=TP.ext_handarea.max.y))
            {
               TP.ext_enable=KAL_TRUE;/*use extended handwriting area*/
            }   
            break;   
         }
         else/*non-handwriting*/
         {
            TP.area=NON_HAND_WRITING;                  
         }                  
      }      
   }         
   else/*extend handwriting area*/
   {
      if((x>=TP.ext_handarea.min.x)&&(y>=TP.ext_handarea.min.y)&&
         (x<=TP.ext_handarea.max.x)&&(y<=TP.ext_handarea.max.y))
      {
         TP.area=HAND_WRITING;         
      }
      else/*non-handwriting*/
      {
         TP.area=NON_HAND_WRITING;                  
      }
   }   
   if(TP.area==HAND_WRITING)            
   {            
      tp_data_pop(STROKE_DOWN, x, y);            
      touch_panel_stroke_hdr();
      touch_start_handwriting_longtap();      
   }
   else/*non-handwriting*/
   {            
      tp_data_pop(PEN_DOWN, x, y);            
      touch_panel_event_hdr();
      touch_start_longtap();
   }   
} 
/*************************************************************************
* FUNCTION
*	touch_panel_sendilm
*
* DESCRIPTION
*	This function is to send touch event indication to upper layer.
*
* PARAMETERS
*	None
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/  
/*send touch event indication to upper layer*/
void touch_panel_sendilm(void *para, Touch_Panel_Event_enum state)
{
   ilm_struct *tp_ilm;
   module_type owner=0;
   
   
   if (send_touch_ilm)
   {
   	#ifdef TOUCH_PANEL_DEBUG
   		owner=MOD_SSDBG1;
   	#else
   		owner=MOD_MMI;
   	#endif
   	
      send_touch_ilm = KAL_FALSE;
      DRV_BuildPrimitive(tp_ilm,
                         MOD_TP_TASK,
                         owner,
                         MSG_ID_TP_EVENT_IND,
                         NULL);   
      msg_send_ext_queue(tp_ilm);
   }   
}  
/*************************************************************************
* FUNCTION
*	touch_panel_conf_handwriting
*
* DESCRIPTION
*	This function is to configure handwriting area.
*
* PARAMETERS
*	area: handwriting area
*  n: number of handwriting areas
*  ext_area: extended handwriting area
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/ 
void touch_panel_conf_handwriting(TouchPanelHandAreaStruct *area, kal_uint16 n, 
                              TouchPanelHandAreaStruct  *ext_area)
{
   kal_uint32 i;
      
   /*n handwriting area*/       
   for(i=0;i<n;i++)
   {      
      TP.handarea[i]=*(area+i);
   }   
   /*extended handwriting area*/
   TP.ext_handarea=*ext_area;
   TP.hand_num=n;
}                                     
/*************************************************************************
* FUNCTION
*	touch_panel_reset_handwriting
*
* DESCRIPTION
*	This function is to reset handwriting area as normal.
*
* PARAMETERS
*	None
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/ 
void touch_panel_reset_handwriting(void)                               
{
   kal_uint32 savedMask;
   savedMask = SaveAndSetIRQMask();
   /*MMI will reset handwriting area*/
   TP.ext_enable=KAL_FALSE;
   RestoreIRQMask(savedMask);
}                     
/*************************************************************************
* FUNCTION
*	touch_panle_conf_sample_period
*
* DESCRIPTION
*	This function is to configure sample period in handwriting and non-handwriting area.
*
* PARAMETERS
*	low:  sample period in non-handwriting area
*  high: sample period in handwriting area
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/                       
/*configure sample period in non-handwriting and handwriting area*/
void touch_panle_conf_sample_period(kal_uint32 low, kal_uint32 high)
{
   TP.low_sample_period=low;
   TP.high_sample_period=high;
}   
/*************************************************************************
* FUNCTION
*	touch_panle_conf_timeout_period
*
* DESCRIPTION
*	This function is to configure period of long tap and repeat event.
*
* PARAMETERS
*	long tap: long tap event period
*  repeat:  repeat event period
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/                       
/*configure longtap and repeat period*/
void touch_panle_conf_timeout_period(kal_uint32 longtap, 
                                     kal_uint32 repeat,
                                     kal_uint32 handwriting_longtap)
{
   TP.handwriting_longtap_cnt=handwriting_longtap;
   TP.longtap_cnt=longtap;
   TP.repeat_cnt=repeat;
}
/*************************************************************************
* FUNCTION
*	touch_panel_event_hdr
*
* DESCRIPTION
*	This function is to handle down event in non-handwriting area.
*
* PARAMETERS
*	None
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/ 
/*start timer in non-handwriting area*/
void touch_panel_event_hdr(void)
{
   if(TP.low_sample_period!=0)
   {
      GPTI_StartItem(touch_panel_handle,                  
                     TP.low_sample_period,
                     touch_panel_event_cb,
                     NULL);
   }                     
}  
/*************************************************************************
* FUNCTION
*	touch_start_longtap
*
* DESCRIPTION
*	This function is to long tap timer.
*
* PARAMETERS
*	None
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void touch_start_longtap(void)
{
   if(TP.longtap_cnt!=0)          
   {
      TP.longtap_state=KAL_TRUE;
      GPTI_StartItem(touch_panel_repeat_handle,                  
                     TP.longtap_cnt,
                     touch_panel_longtap_cb,
                     NULL);  
   }   
}   
/*************************************************************************
* FUNCTION
*	touch_start_handwriting_longtap
*
* DESCRIPTION
*	This function is to start long tap timer in handwriting area.
*
* PARAMETERS
*	None
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void touch_start_handwriting_longtap(void)
{
   if(TP.handwriting_longtap_cnt!=0)          
   {
      TP.longtap_state=KAL_TRUE;
      GPTI_StartItem(touch_panel_repeat_handle,                  
                     TP.handwriting_longtap_cnt,/*stroke long tap*/
                     touch_panel_longtap_cb,
                     NULL);  
   }   
}
/*************************************************************************
* FUNCTION
*	touch_panel_stroke_hdr
*
* DESCRIPTION
*	This function is to handle down event in handwriting area.
*
* PARAMETERS
*	None
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void touch_panel_stroke_hdr(void)
{
     if(TP.high_sample_period!=0)
   {
      GPTI_StartItem(touch_panel_handle,                  
                     TP.high_sample_period,
                     touch_panel_stroke_cb,
                     NULL);
   }    
}                              
/*************************************************************************
* FUNCTION
*	touch_panel_get_event
*
* DESCRIPTION
*	This function is to get event from ring buffer.
*
* PARAMETERS
*	data: touch event
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
/*Get touch panel coord. value*/
kal_bool touch_panel_get_event(TouchPanelEventStruct *touch_data)
{
   kal_bool result;
   kal_uint8 hign_data=0, low_data=0;
   kal_int8 diff;
   kal_uint16 avail=0;
   //TouchPanelEventStruct data;
   IRQMask(IRQ_GPT_CODE);
   /* only mask eint when it's unmasked. */
   if (tp_eint_mask == KAL_FALSE)
   EINT_Mask(TP.eint_chan);   
   
   if(TP.is_buff_full==KAL_TRUE)
   {
      touch_data->event=PEN_ABORT;
      touch_data->x_adc=0;
      touch_data->y_adc=0;
      if (tp_eint_mask == KAL_FALSE)
         EINT_UnMask(TP.eint_chan);
      IRQUnmask(IRQ_GPT_CODE);
      return KAL_TRUE;
   }
   
   tp_get_buf_avail(avail); 
   if(touch_panel_data_buffer.touch_buffer_rindex != touch_panel_data_buffer.touch_buffer_windex)   	
   {            
      if(tp_decode_state==TP_UNKNOWN_EVENT)            
      {/*complete x and y*/         
         touch_pop_data_from_buffer(touch_data->event);          
         if(touch_data->event!=STROKE_UP)/*stroke end*/
         {
            touch_pop_data_from_buffer(hign_data);/*high*/
            touch_pop_data_from_buffer(low_data);/*low*/
            touch_data->x_adc=(hign_data<<8);     
            touch_data->x_adc|=low_data;     
            touch_pop_data_from_buffer(hign_data);/*high*/
            touch_pop_data_from_buffer(low_data);/*low*/
            touch_data->y_adc=(hign_data<<8);               
            touch_data->y_adc|=low_data;     
         }   
         if(touch_data->event==STROKE_DOWN)
         {
            tp_decode_state=STROKE_MOVE;
            tp_stroke_pre.x=touch_data->x_adc;
            tp_stroke_pre.y=touch_data->y_adc;
         }    
      }
      else if(tp_decode_state==STROKE_MOVE)    
      { 
         touch_pop_data_from_buffer(diff);
         if((kal_uint8)diff==STROKE_UP) 
         {
            touch_data->event=STROKE_UP;
            touch_data->x_adc=tp_stroke_pre.x;//0;
            touch_data->y_adc=tp_stroke_pre.y;//0;
            tp_decode_state=TP_UNKNOWN_EVENT;
            tp_stroke_pre.x=0;
            tp_stroke_pre.y=0;
         }                         
         else if((kal_uint8)diff==STROKE_LONGTAP) 
         {
            //touch_pop_data_from_buffer(diff);
            touch_data->x_adc=tp_stroke_pre.x;//0;
            touch_data->y_adc=tp_stroke_pre.y;//0;
            touch_data->event=STROKE_LONGTAP;
         }   
         else/*delta x, delta y*/
         {     
            /*x*/    
            touch_data->x_adc=(kal_int16)((kal_int16)tp_stroke_pre.x+(kal_int16)diff);
            tp_stroke_pre.x=touch_data->x_adc;
            /*y*/
            touch_pop_data_from_buffer(diff);         
            touch_data->y_adc=(kal_int16)((kal_int16)tp_stroke_pre.y+(kal_int16)diff);;
            tp_stroke_pre.y=touch_data->y_adc;
            touch_data->event=STROKE_MOVE;
         }
      } 
     result = KAL_TRUE;
   }
   else
   {
      send_touch_ilm = KAL_TRUE;
      result = KAL_FALSE;
   }      
   if (tp_eint_mask == KAL_FALSE)
   EINT_UnMask(TP.eint_chan);
   IRQUnmask(IRQ_GPT_CODE);
   return result;      
}   
/*************************************************************************
* FUNCTION
*	touch_panel_peek_event
*
* DESCRIPTION
*	This function is to peek event from ring buffer.
*
* PARAMETERS
*	data: touch event
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_bool touch_panel_peek_event(TouchPanelEventStruct *touch_data)
{
   kal_bool result;
   //kal_uint8 hign_data=0, low_data=0;
   kal_uint8 peek_data[5];
   //kal_int8 diff;
   //TouchPanelEventStruct data;
   IRQMask(IRQ_GPT_CODE);
   /* only mask eint when it's unmasked. */
   if (tp_eint_mask == KAL_FALSE)
   EINT_Mask(TP.eint_chan);   
   if (touch_panel_data_buffer.touch_buffer_rindex != touch_panel_data_buffer.touch_buffer_windex)
   {                  
      if(tp_decode_state==TP_UNKNOWN_EVENT)            
      {/*complete x and y*/         
         touch_peek_data_from_buffer(peek_data,5);   
         touch_data->event=peek_data[0];            
         if(peek_data[0]!=STROKE_UP)/*stroke end*/
         {
            touch_data->x_adc=(peek_data[1]<<8);     
            touch_data->x_adc|=peek_data[2];     
            touch_data->y_adc=(peek_data[3]<<8);               
            touch_data->y_adc|=peek_data[4];                       
         }            
      }
      else if(tp_decode_state==STROKE_MOVE)    
{
         touch_peek_data_from_buffer(peek_data,3);   
         if((kal_uint8)peek_data[0]==STROKE_UP) 
         {
            touch_data->event=STROKE_UP;
            touch_data->x_adc=0;
            touch_data->x_adc=0;            
         }                         
         else/*delta x, delta y*/
         {     
            /*x*/    
            touch_data->x_adc=(kal_int16)((kal_int16)tp_stroke_pre.x+(kal_int16)peek_data[1]);            
            /*y*/            
            touch_data->y_adc=(kal_int16)((kal_int16)tp_stroke_pre.y+(kal_int16)peek_data[2]);;                        
         }
      }       
     result = KAL_TRUE;
   }
   else   
   {
      send_touch_ilm = KAL_TRUE;
      result = KAL_FALSE;
   }
      
   if (tp_eint_mask == KAL_FALSE)

⌨️ 快捷键说明

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