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

📄 gui_touch_driveranalog.c

📁 在ARM7处理器S3C444B0X上的脉搏测量仪程序
💻 C
字号:
/***********************************************************************************************************                                                uC/GUI*                        Universal graphic software for embedded applications**                       (c) Copyright 2002, Micrium Inc., Weston, FL*                       (c) Copyright 2002, SEGGER Microcontroller Systeme GmbH**              礐/GUI is protected by international copyright laws. Knowledge of the*              source code may not be used to write a similar product. This file may*              only be used in accordance with a license and should not be redistributed*              in any way. We appreciate your understanding and fairness.*----------------------------------------------------------------------File        : GUITOUCH.CPurpose     : Touch screen manager----------------------------------------------------------------------This module handles the touch screen. It is configured in the fileGUITouch.conf.h (Should be located in the Config\ directory).----------------------------------------------------------------------*/#include <stdio.h>#include <stdlib.h>#include <string.h>#include "LCD_Private.H"      /* private modul definitions & config */#include "GUI_Protected.h"/* Generate code only if configuration says so ! */#if GUI_SUPPORT_TOUCH#include "GUITouchconf.h"    /* Located in GUIx, will include GUITouch.conf.h */#include "..\inc\def.h"#include "..\inc\44b.h"#include "..\inc\44blib.h"#include "ads7843.h"/*************************************************************************          Config defaults************************************************************************/#ifndef GUI_TOUCH_AD_LEFT      /* max value returned by AD-converter */  #define GUI_TOUCH_AD_LEFT 64   #endif#ifndef GUI_TOUCH_AD_RIGHT      /* min value returned by AD-converter */  #define GUI_TOUCH_AD_RIGHT 256    #endif#ifndef GUI_TOUCH_AD_TOP       /* max value returned by AD-converter */  #define GUI_TOUCH_AD_TOP 512#endif#ifndef GUI_TOUCH_AD_BOTTOM      /* min value returned by AD-converter */  #define GUI_TOUCH_AD_BOTTOM 940#endif#ifndef GUI_TOUCH_SWAP_XY    /* Is XY of touch swapped ? */  #define GUI_TOUCH_SWAP_XY 0#endif#ifndef GUI_TOUCH_MIRROR_X  #define GUI_TOUCH_MIRROR_X 0#endif#ifndef GUI_TOUCH_MIRROR_Y  #define GUI_TOUCH_MIRROR_Y 1#endif#ifndef GUI_TOUCH_YSIZE  #define GUI_TOUCH_YSIZE LCD_YSIZE#endif#ifndef GUI_TOUCH_XSIZE  #define GUI_TOUCH_XSIZE LCD_XSIZE#endif/*************************************************************************          Config check************************************************************************//*  *****************************************************************  *                                                               *  *              Global data                                      *  *                                                               *  *****************************************************************The global data below is for debugging purposes only. A "clean"application should not use these values for any other purpose.NEVER write into these values !*///int GUI_TOUCH_yPhys, GUI_TOUCH_xPhys;/******************************************************************       Static data*******************************************************************/typedef struct {int Min; int Max; } tMinMax;static tMinMax xyMinMax[2] = {#if ((GUI_TOUCH_SWAP_XY==0) && (GUI_TOUCH_MIRROR_X==0)) || ((GUI_TOUCH_SWAP_XY) && (GUI_TOUCH_MIRROR_Y==0))  { GUI_TOUCH_AD_LEFT, GUI_TOUCH_AD_RIGHT },#else  { GUI_TOUCH_AD_RIGHT, GUI_TOUCH_AD_LEFT },#endif#if ((GUI_TOUCH_SWAP_XY==0) && (GUI_TOUCH_MIRROR_Y==0)) || ((GUI_TOUCH_SWAP_XY) && (GUI_TOUCH_MIRROR_X==0))  { GUI_TOUCH_AD_TOP,  GUI_TOUCH_AD_BOTTOM }#else  { GUI_TOUCH_AD_BOTTOM,  GUI_TOUCH_AD_TOP }#endif};#ifndef WIN32static int xMin;static int xMax;static int yMin;static int yMax;#endifint touching=0;/***********************************************************************       Convert physical value into (logical) coordinates*/int AD2X(int adx) {  I32 r = adx - xyMinMax[GUI_COORD_X].Min;  r *= GUI_TOUCH_XSIZE - 1;  return r / (xyMinMax[GUI_COORD_X].Max - xyMinMax[GUI_COORD_X].Min);    }int AD2Y(int ady) {  I32 r = ady - xyMinMax[GUI_COORD_Y].Min;  r *= GUI_TOUCH_YSIZE - 1;  return r/(xyMinMax[GUI_COORD_Y].Max - xyMinMax[GUI_COORD_Y].Min);    }/***********************************************************************        Diagnostic routines*/int  GUI_TOUCH_GetxPhys(void) {	if(!TP_IRQ)		return Read_X();	else		return -1; //GUI_TOUCH_xPhys;}int  GUI_TOUCH_GetyPhys(void) {	if(!TP_IRQ)		return Read_Y();	else		return -1; //GUI_TOUCH_xPhys;}/***********************************************************************              SetDefaultCalibration*/void GUI_TOUCH_SetDefaultCalibration(void) {  xyMinMax[0].Min = GUI_TOUCH_AD_LEFT;  xyMinMax[0].Max = GUI_TOUCH_AD_RIGHT;  xyMinMax[1].Min = GUI_TOUCH_AD_TOP;  xyMinMax[1].Max = GUI_TOUCH_AD_BOTTOM;}/***********************************************************************              Calibration*/static int Log2Phys(int l, I32 l0, I32 l1, I32 p0, I32 p1) {  return p0+ ((p1-p0) * (l-l0)) / (l1-l0);}int GUI_TOUCH_Calibrate(int Coord, int Log0, int Log1, int Phys0, int Phys1) {  int l0 = 0;  int l1 = (Coord==GUI_COORD_X) ? LCD_XSIZE-1 : LCD_YSIZE-1;  if (labs(Phys0-Phys1) < 40)    return 1;  if (labs(Log0-Log1) < 40)    return 1;  xyMinMax[Coord].Min = Log2Phys(l0, Log0, Log1, Phys0, Phys1);  xyMinMax[Coord].Max = Log2Phys(l1, Log0, Log1, Phys0, Phys1);  return 0;}#define TP_UP 	0#define TP_DOWN	1static int TpStatus=TP_UP;/***********************************************************************              GUI_TOUCH*/extern void TouchManage(int x,int y);//调用点击事件处理函数,,处理屏幕点击事件处理 int count=0; int x_temp[5]={0,0,0,0,0}; int y_temp[5]={0,0,0,0,0};void __irq TP_EINT3(void);void __irq TP_EINT3(void){	    	static int xPhys, yPhys;  	int  x,y;  	int i=0;  	touching=1; if(rEXTINTPND==8)//是触摸屏中断,或key3中断 {	    rI_ISPC=BIT_EINT4567;	//clear pending_bit   	rEXTINTPND=0xf;   if(TpStatus==TP_UP)	 {	        if(!TP_IRQ)          {	        Delay(50);        	if(!TP_IRQ)        	{           //TpStatus=TP_DOWN;	            if (xyMinMax[GUI_COORD_X].Min < xyMinMax[GUI_COORD_X].Max)             {              xMin = xyMinMax[GUI_COORD_X].Min;              xMax = xyMinMax[GUI_COORD_X].Max;            }            else             {              xMax = xyMinMax[GUI_COORD_X].Min;              xMin = xyMinMax[GUI_COORD_X].Max;            }            if (xyMinMax[GUI_COORD_Y].Min < xyMinMax[GUI_COORD_Y].Max)             {              yMin = xyMinMax[GUI_COORD_Y].Min;              yMax = xyMinMax[GUI_COORD_Y].Max;            }             else             {              yMax = xyMinMax[GUI_COORD_Y].Min;              yMin = xyMinMax[GUI_COORD_Y].Max;            }          	// Execute the state machine which reads the touch           	TP_GetAdXY(&xPhys,&yPhys);            //Convert values into logical values            #if !GUI_TOUCH_SWAP_XY  //Is X/Y swapped ?               x = xPhys;              y = yPhys;               Uart_Printf("\nADX0=%d,ADY0=%d",x,y);            #else              x = yPhys;              y = xPhys;               Uart_Printf("\nADX=%d,ADY=%d",x,y);            #endif                        if ((x <xMin) | (x>xMax)  | (y <yMin) | (y>yMax)) {              GUI_TOUCH_StoreState(-1,-1);              }               else {              x = AD2X(x);              y = AD2Y(y);              GUI_TOUCH_StoreState(x,y);              Uart_Printf("\nx=%d,y=%d,test....ok",x,y);              //======================================================              if(x_temp[0]-x>5||y_temp[0]-y>5)//两次点击偏差太大,表新点击                count=0;              x_temp[count]=x;              y_temp[count]=y;              count++;              if(count>=5)              {                 for(i=1;i<5;i++)                 {                  x_temp[0]+=x_temp[i];                  y_temp[0]+=y_temp[i];                 }                TouchManage(x_temp[0]/5,y_temp[0]/5);//调用点击事件处理函数,,处理屏幕点击事件处理                count=0;               }              //==============================================            }             }         }       }    }    else    {    rI_ISPC=BIT_EINT4567;	//clear pending_bit   	rEXTINTPND=0xf;    }}  void TP_init(void)    {         //TSPX(GPE3) TSMX(GPE4)  TSPY(GPE6) TSMY(GPE7)         //  0		1	       1          0	Uart_Printf("[Touch Screen Test.]\n");    Uart_Printf("Separate X/Y position conversion mode test\n");         rEXTINT=0x0;    rINTCON=0x5;    pISR_EINT4567=(unsigned)TP_EINT3;//	pISR_EINT3    TP_DCLK(1);      TP_CS(1);   // rCLKCON=0x7ff8;  //  rADCPSR=500;    Uart_Printf("\nStylus Down, please...... \n");    rINTMSK=~(BIT_GLOBAL|BIT_EINT4567);//|BIT_EINT7    Uart_Printf("\nStylus Down, please11111111...... \n");    }#elsevoid GUI_TOUCH_DriverAnalog_C(void) {}#endif    /* defined(GUI_SUPPORT_TOUCH) && GUI_SUPPORT_TOUCH */

⌨️ 快捷键说明

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