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

📄 touch_panel.c

📁 代码用简单的4个IO口外加两个ADC转换接口实现了触摸屏全套控制流程.
💻 C
📖 第 1 页 / 共 4 页
字号:
/*****************************************************************************
*  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"
#include    "eint.h"
#include    "intrCtrl.h"
#include 	"touch_panel.h"
#include 	"touch_panel_buff.h"
#include 	"gpt_sw.h"

#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;
/*Screen ADC Value*/
kal_uint32 ADC_X_START=230;
kal_uint32 ADC_X_END=3867;
kal_uint32 ADC_Y_START=287;
kal_uint32 ADC_Y_END=3853;
kal_uint32 SCREEN_X_START=0;
#if defined(__MMI_MAINLCD_240X320__)
kal_uint32 SCREEN_X_END=240;
#else
kal_uint32 SCREEN_X_END=176;
#endif
kal_uint32 SCREEN_Y_START=0;
#if defined(__MMI_MAINLCD_240X320__)
	#if defined(PROJECT_I100)||defined(PROJECT_V830)
	kal_uint32 SCREEN_Y_END=320+20;
	#else
	kal_uint32 SCREEN_Y_END=320;
	#endif
#else
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;


/*************************************************************************
* 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)
{
   *slope=((double)(coord2-coord1)/((double)(adc2-adc1)));
   *offset=(double)coord1-(*slope)*(double)adc1;      
}
/*************************************************************************
* 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)
{
   IRQMask(IRQ_GPT_CODE);
   /* only mask eint when it's unmasked. */
   if (tp_eint_mask == KAL_FALSE)
   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)
   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)
{
   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;
   /*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);
   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;
   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)
{
   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)
{
   
   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)
{
   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
*
*************************************************************************/
void touch_panel_up_hdr(void)
{
   /*check if the down point is reasonable*/
   if(TP.wait_next_down==KAL_TRUE)
      return;
      
   /*reset temp coordinate*/
   TP.temp.x=0;
   TP.temp.y=0;
   /*stop polling*/     
   GPTI_StopItem(touch_panel_handle);
   GPTI_StopItem(touch_panel_repeat_handle);
   if(TP.skip_unrelease_state==KAL_FALSE)
   {   
   if(TP.area==NON_HAND_WRITING)
   {    
         tp_data_pop(PEN_UP, TP.pre.x, TP.pre.y);
   }   
   else
   {      
         tp_data_pop(STROKE_UP, TP.pre.x, TP.pre.y);
      }   
   }
   else/*TP.skip_unrelease_state==KAL_TRUE*/
      TP.skip_unrelease_state=KAL_FALSE;   
}   
/*************************************************************************
* FUNCTION
*	touch_panel_down_hdr
*
* DESCRIPTION
*	This function is to handle down event.
*
* PARAMETERS
*	None
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void touch_panel_down_hdr(void)
{
   kal_int16  x, y;
   kal_uint16 i;
   kal_bool valid=KAL_FALSE;
   TP.skip_unrelease_state=KAL_FALSE;
   touch_panel_read_adc(&x, &y);
   touch_excute_cali(x,y);
   valid=touch_panel_adc_to_coordinate(&x,&y);/*tranlate*/            
   if(valid==KAL_TRUE)
   {
   TP.pre.x=x; 
   TP.pre.y=y;
      TP.begin.x=x; 
      TP.begin.y=y;
      TP.wait_next_down=KAL_FALSE;
   }
   else
   {
      /*use the previous down coordinate to prevent touch panel controller temp state*/
   	//x=TP.pre.x; 
   	//y=TP.pre.y;
   	TP.wait_next_down=KAL_TRUE;
   	return;
   }		
   TP.temp.x=0;
   TP.temp.y=0;

⌨️ 快捷键说明

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