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

📄 touch_panel.c

📁 MTK6225
💻 C
📖 第 1 页 / 共 5 页
字号:
/*****************************************************************************
*  Copyright Statement:
*  --------------------
*  This software is protected by Copyright and the information contained
*  herein is confidential. The software may not be copied and the information
*  contained herein may not be used or disclosed except with the written
*  permission of MediaTek Inc. (C) 2005
*
*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
*
*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/

/*****************************************************************************
 *
 * Filename:
 * ---------
 *    touch_panel.c
 *
 * Project:
 * --------
 *   Maui_Software
 *
 * Description:
 * ------------
 *   This Module is touch panel driver.
 *
 * Author:
 * -------
 * -------
 *
 *============================================================================
 *             HISTORY
 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *------------------------------------------------------------------------------
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *============================================================================
 ****************************************************************************/
#if defined(TOUCH_PANEL_SUPPORT) || defined(HAND_WRITING)
#include    "drv_comm.h"
#include 	"stack_common.h"
#include    "syscomp_config.h"   /*MOD_BMT*/
#include 	"stack_msgs.h"
#include 	"app_ltlcom.h"       /* Task message communiction */
#include    "stacklib.h"         /* Basic type for dll, evshed, stacktimer */
#include    "event_shed.h"       /* Event scheduler */
#include    "stack_timer.h"     /*Timer*/
#include    "app_buff_alloc.h"   /*buffer*/
#include    "task_config.h"      /* Task creation */
#include    "stack_ltlcom.h"       /*msg_send_ext_queue.....definitions*/
#include    "reg_base.h"
#include    "gpio_hw.h"
#include    "gpio_sw.h"
#include    "touch_panel_spi.h"   ///Yh888_6225_V004.B&N001
//#include    "touch_panel_i2c.h"//qsh
#include    "eint.h"
#include    "intrCtrl.h"
#include 	"touch_panel.h"
#include 	"touch_panel_buff.h"
#include 	"gpt_sw.h"

#ifndef TOUCH_PANEL_I2C_SUPPORT
#define TOUCH_PANEL_I2C_SUPPORT  //qsh
#endif

#ifdef TOUCH_PANEL_I2C_SUPPORT   ////Yh888_6225_V004.B&N002
typedef enum 
{
	TP_LEVEL_DOWN = 0,
	TP_LEVEL_UP ,
	TP_LEVEL_SLIDE,
	TP_LEVEL_GESTURE   ///light tap
}I2C_TP_STATE;
#endif
#define   touch_down_level   LEVEL_LOW   /*touch down level*/
#define   touch_up_level     LEVEL_HIGH  /*touch up level*/

TouchPanelBufferStruct    touch_panel_data_buffer;
kal_bool    touch_panel_state = touch_down_level; /*touch panel inq level*/


kal_bool send_touch_ilm=KAL_TRUE;
TouchPanelCoordStruct tp_stroke_pre;
static Touch_Panel_Event_enum tp_decode_state=TP_UNKNOWN_EVENT;/*get event state*/

/*GPT timer handle*/
kal_uint8   touch_panel_handle=0;  /*gpt handle*/
kal_uint8   touch_panel_repeat_handle=0;
kal_uint8   touch_panel_timer=0;//qsh 04-21
/*Screen ADC Value*/
//#ifdef TOUCH_PANEL_I2C_SUPPORT   ////Yh888_6225_V004.B&N002
#if 1
kal_uint32 ADC_X_START=0;
kal_uint32 ADC_X_END=3968;
kal_uint32 ADC_Y_START=0;
kal_uint32 ADC_Y_END=5264;
#else
kal_uint32 ADC_X_START=230;
kal_uint32 ADC_X_END=3867;
kal_uint32 ADC_Y_START=287;
kal_uint32 ADC_Y_END=3853;
#endif
kal_uint32 SCREEN_X_START=0;
#if defined(__MMI_MAINLCD_240X320__)   // jonson
/* SZVT  KevinPi  2007/05/16  change parameters for QVGA touch screan */
kal_uint32 SCREEN_X_END=240;// 176;
kal_uint32 SCREEN_Y_START=0;
/* SZVT  KevinPi  2007/05/16  change parameters for QVGA touch screan */
kal_uint32 SCREEN_Y_END=  320 ;//320;// 220;
#elif defined(__MMI_MAINLCD_176X220__)
kal_uint32 SCREEN_X_END=176;
kal_uint32 SCREEN_Y_START=0;
kal_uint32 SCREEN_Y_END=220;
#endif

/*Calibration*/
#define TOUCH_CALIBRATION_POINT_NUM 3
TouchPanelCaliStruct TPCali;  /*Calibration offset and slope*/
static TouchPanelCoordStruct cali_point[TOUCH_CALIBRATION_POINT_NUM];
static TouchPanelCoordStruct cali_point_adc[TOUCH_CALIBRATION_POINT_NUM];
static kal_bool tp_cali_mode=KAL_FALSE;
static kal_uint16 tp_cali_cnt=0;
static kal_bool tp_eint_mask = KAL_FALSE;

extern TouchPanel_customize_function_struct *tp_GetFunc(void);
TouchPanel_customize_function_struct *tp_fun_ptr;

extern kal_uint8	      tp_tapcode ;
extern kal_uint8	      tp_zoom ;
extern kal_uint8	      tp_flick ;
extern kal_uint8	      tp_press;
extern kal_uint8	       finger_num ;//qsh

extern kal_uint8       zoomY;
extern kal_uint8       zoomX;
/*************************************************************************
* FUNCTION
*	touch_panel_tuning
*
* DESCRIPTION
*	This function is to calculate slope and offset.
*
* PARAMETERS
*  coord1: coordinate of calibration point 1
*  coord2: coordinate of calibration point 2
*  adc1:   ADC of calibration point 1
*  adc2:   ADC of calibration point 1
*  slope:  slope of calibration
*  offset: offset of calibration
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void touch_panel_tuning(kal_int16 coord1, kal_uint16 adc1,
                        kal_int16 coord2, kal_uint16 adc2,
                        double *slope,     double *offset)
{
char str[100];

//coord1=SCREEN_X_START=0,adc1= ADC_X_START=287,coord2= SCREEN_X_END=339,adc2= ADC_X_END=3853
//x_slop=0.0657135
//x_offset=-15.114105

//y_slop=0.095064498
//y_offset=-27.2835109


   *slope=((double)(coord2-coord1)/((double)(adc2-adc1)));
   *offset=(double)coord1-(*slope)*(double)adc1;      

   //sprintf(str,"coord2=%d,coord1=%d,adc2=%d,adc1=%d,slope=%f",coord2,coord1,adc2,adc1,*slope);
   //kal_print(str);

   //sprintf(str,"offset=%f",*offset);
   //kal_print(str);
}
/*************************************************************************
* FUNCTION
*	touch_panel_flush
*
* DESCRIPTION
*	This function is to flush all data in ring buffer.
*
* PARAMETERS
*  None
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/   
void touch_panel_flush(void)
{

   //kal_print("tp touch_panel_flush");

   IRQMask(IRQ_GPT_CODE);
   /* only mask eint when it's unmasked. */
 if (tp_eint_mask == KAL_FALSE)	//xiong 07/06/06  //qsh 4-15
   EINT_Mask(TP.eint_chan);
   touch_flush_data_buffer();
   /*reset decode state*/
   tp_decode_state=TP_UNKNOWN_EVENT;
   /*recover from buffer full*/
   TP.is_buff_full=KAL_FALSE;
   GPTI_StopItem(touch_panel_handle);
   GPTI_StopItem(touch_panel_repeat_handle);
   TP.skip_unrelease_state=KAL_TRUE;

      
   if (tp_eint_mask == KAL_FALSE)	//xiong 07/06/06  //qsh 4-15
   EINT_UnMask(TP.eint_chan);
   IRQUnmask(IRQ_GPT_CODE);
   
}
/*************************************************************************
* FUNCTION
*	touch_panel_flush
*
* DESCRIPTION
*	This function is to reset touch panel driver. 
*
* PARAMETERS
*  skip_unrelease_enable: skip the first unrelease events or not.
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/  
void touch_panel_reset(kal_bool skip_unrelease_enable)
{
    //kal_prompt_trace(MOD_TP_TASK, "touch_panel_reset()" );
kal_print("tp touch_panel_reset");
   IRQMask(IRQ_GPT_CODE);
   EINT_Mask(TP.eint_chan);
   /*stop calibration*/
   touch_panel_stop_cali();
   /*flush ring buffer*/   
   touch_flush_data_buffer();
   /*reset decode state*/
   tp_decode_state=TP_UNKNOWN_EVENT;
   /*configure default pen/move offset*/
   //touch_panel_conf_move_offset(MIN_PEN_MOVE_OFFSET, MAX_STROKE_MOVE_OFFSET, 10);
   /*buff full flag*/
   TP.is_buff_full=KAL_FALSE;
   TP.ext_enable=KAL_FALSE;   //qsh 4-15
   /*skip the first unrelease events or not*/
   TP.skip_unrelease_enable=skip_unrelease_enable;
   if(TP.skip_unrelease_enable)
   {
      TP.skip_unrelease_state=KAL_TRUE;
      #ifdef TOUCH_PANEL_DEBUG
      dbg_printWithTime("reset and skip");
      #endif
   }   
   else
   {
      TP.skip_unrelease_state=KAL_FALSE;   
      #ifdef TOUCH_PANEL_DEBUG
      dbg_printWithTime("reset but not skip");
      #endif
   }   
   /*stop polling*/
   GPTI_StopItem(touch_panel_handle);
   GPTI_StopItem(touch_panel_repeat_handle);

   touch_panel_state = 0; //qsh 
   EINT_Set_Polarity(TP.eint_chan,touch_panel_state);//qsh
   
   EINT_UnMask(TP.eint_chan);
   IRQUnmask(IRQ_GPT_CODE);
  
}
/*************************************************************************
* FUNCTION
*	touch_panel_start_cali
*
* DESCRIPTION
*	This function is to do coordinate calibration. 
*
* PARAMETERS
*  point: coordiante of calibration points
*  num:   number of calibration points
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void touch_panel_start_cali(TouchPanelCoordStruct *point, kal_uint16 num)
{
   #if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
   #else
   
   kal_uint32 i;
  kal_print("tp touch_panel_start_cali");
   for(i=0;i<num;i++)
   {
      cali_point[i].x=point[i].x;   
      cali_point[i].y=point[i].y;
   }      
   #endif
   tp_cali_mode=KAL_TRUE;
}
/*************************************************************************
* FUNCTION
*	touch_panel_stop_cali
*
* DESCRIPTION
*	This function is to stop coordinate calibration.
*
* PARAMETERS
*	None
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void touch_panel_stop_cali(void)
{
    //kal_prompt_trace(MOD_TP_TASK, "touch_panel_stop_cali()" );
  kal_print("tp touch_panel_stop_cali");
   tp_cali_mode=KAL_FALSE;  
   tp_cali_cnt=0;  
   cali_point[0].x=0;   
   cali_point[0].y=0;
   cali_point[1].x=0;
   cali_point[1].y=0;      
}
/*************************************************************************
* FUNCTION
*	touch_panel_set_cali
*
* DESCRIPTION
*	This function is to set coordinate calibration.
*
* PARAMETERS
*	cali: calibration data
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
/*MMI configures calibration accodring to the value in the NVRAM*/
void touch_panel_set_cali(TouchPanelCaliStruct cali)
{

  // kal_print("tp touch_panel_set_cali");
   TPCali.x_slope= cali.x_slope;
   TPCali.x_offset= cali.x_offset;
   TPCali.y_slope= cali.y_slope;
   TPCali.y_offset= cali.y_offset;
}
/*************************************************************************
* FUNCTION
*	touch_panel_read_cali
*
* DESCRIPTION
*	This function is to read coordinate calibration.
*
* PARAMETERS
*	cali: the pointer to read calibraion data
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
/*MMI reads calibration after receiving MSG_ID_TP_CALI_DONE*/
/*and stores it in NVRAM*/
void touch_panel_read_cali(TouchPanelCaliStruct *cali)
{
   //kal_print("tp touch_panel_read_cali");
   cali->x_slope =TPCali.x_slope;  
   cali->x_offset=TPCali.x_offset;
   cali->y_slope =TPCali.y_slope;  
   cali->y_offset=TPCali.y_offset;
}  
   
/*************************************************************************
* FUNCTION
*	touch_panel_cb_registration
*
* DESCRIPTION
*	This function is to register touch event callback function.
*
* PARAMETERS
*	None
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void touch_panel_cb_registration (TP_EVENT_FUNC Callback, void *parameter)
{

   TP.touch_panel_event_cb=Callback;
   TP.cb_para=parameter;
}
/*************************************************************************
* FUNCTION
*	touch_panel_up_hdr
*
* DESCRIPTION
*	This function is to handle up event.
*
* PARAMETERS
*	None
*
* RETURNS
*	None
*
* GLOBALS AFFECTED

⌨️ 快捷键说明

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