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

📄 pen.c

📁 最近在國外網站抓到的作業系統 以Arm為基礎去開發的
💻 C
字号:
/*************************************************************************
 *  Copyright (C) Asic Center. 2002
 *  All Rights Reserved
 *
 *  Filename : pen.c
 *  Function : driver of pen device(touch panel), (pendev.c + pen.c)
 *  Revision :
 *		2002-5-9	Pessia	Create this file
 ************************************************************************/
//#include "ppsm\ppsm.h"
#include "m68328.h"
//#include "m68ksys.h"
#include "sysmsg.h"
#include "systsk.h"
#include "pen.h"
#include "ppsmtype.h"

#include "hardware.h"
#include "hardware_reg.h"
#include "HA_typedef.h"

#undef _AD_DEBUG

#ifdef _AD_DEBUG
#include <stdio.h>
#include "sysusr.h"
#include "gpc.h"

extern WORD	en_disp_ad;
#endif

PENDATA PEN_BUF[MAX_PENBUF];
unsigned char PEN_BUF_readcount,PEN_BUF_writecount;

static U16 xpos,ypos;
static void touch_panel_isr( void );

extern STATUS PenRead(P_U16 x, P_U16 y);
extern void PenEnable(void);
extern void PenDisable(void);

#ifdef _AD_DEBUG
static POINTS 	addata[256];
static U8		count = 0;
#endif

static STATUS average_pos2( P_U16 x, P_U16 y )
{
	U32 sumx=0,sumy=0;
	STATUS flag;
	U16 tempx[4];
	U16 tempy[4];
	U16	xs[2], xb[2];
	U16	ys[2], yb[2];
	register U8 i=0;
	U16 difx, dify;

#ifdef _AD_DEBUG
	U32		hGC;
	char	info[20];
static	char	k = 0, t = 10;
	
	if( en_disp_ad )
		hGC = (U32)gSysTcbTbl[SYSTASK_ID-1].gc;
#endif
	*x = 0;
	*y = 0;
	
////	flag = PenRead(&tempx[i], &tempy[i++]);
	flag = PenRead(&tempx[0], &tempy[0]);
#ifdef _AD_DEBUG
	addata[count].x = tempx[0];
	addata[count++].y = tempy[0];
#endif
	if(!flag) goto SCAN_END;
////	flag = PenRead(&tempx[i], &tempy[i++]);
	flag = PenRead(&tempx[1], &tempy[1]);
#ifdef _AD_DEBUG
	addata[count].x = tempx[1];
	addata[count++].y = tempy[1];
#endif
	if(!flag) goto SCAN_END;
////	flag = PenRead(&tempx[i], &tempy[i++]);
	flag = PenRead(&tempx[2], &tempy[2]);
#ifdef _AD_DEBUG
	addata[count].x = tempx[2];
	addata[count++].y = tempy[2];
#endif
	if(!flag) goto SCAN_END;
////	flag = PenRead(&tempx[i], &tempy[i++]);
	flag = PenRead(&tempx[3], &tempy[3]);
#ifdef _AD_DEBUG
	addata[count].x = tempx[3];
	addata[count++].y = tempy[3];
#endif
	if(!flag) goto SCAN_END;
	
	xs[0] = tempx[0] > tempx[1] ? 1 : 0;
	xb[0] = 1 - xs[0];
	xs[1] = tempx[2] > tempx[3] ? 3 : 2;
	xb[1] = 5 - xs[1];
	sumx += ( tempx[xs[0]] > tempx[xs[1]] ? tempx[xs[0]] : tempx[xs[1]] );
	difx = sumx;
	sumx += ( tempx[xb[0]] > tempx[xb[1]] ? tempx[xb[1]] : tempx[xb[0]] );
////	difx = sumx - difx - difx;
	difx = ((sumx - difx) > difx)?((sumx - difx) - difx):(difx - (sumx - difx));
	ys[0] = tempy[0] > tempy[1] ? 1 : 0;
	yb[0] = 1 - ys[0];
	ys[1] = tempy[2] > tempy[3] ? 3 : 2;
	yb[1] = 5 - ys[1];
	sumy += ( tempy[ys[0]] > tempy[ys[1]] ? tempy[ys[0]] : tempy[ys[1]] );
	dify = sumy;
	sumy += ( tempy[yb[0]] > tempy[yb[1]] ? tempy[yb[1]] : tempy[yb[0]] );
////	dify = sumy - dify - dify;
	dify= ((sumy - dify) > dify)?((sumy - dify) - dify):(dify - (sumy - dify));

/*		
	if( difx > 16 || difx < -16 || dify > 16 || dify < -16 )
	{
		flag = 2;
	}
	else
*/			////gfd del
//	if( difx > 68 || dify > 76 )			////gfd: x>4pixel or y>6pixel(AD 的精度是12位);
//	if( difx > 85 || dify > 96 )			////gfd: x>5pixel or y>7.5pixel(AD 的精度是12位);
	if( difx > 42 || dify > 48 )			////gfd: x>5pixel or y>7.5pixel(AD 的精度是11位);
//	if( difx > 21 || dify > 24 )			////gfd: x>5pixel or y>7.5pixel(AD 的精度是10位);
	{
		flag = 2;
	}
	else

	{
		*x = sumx/2;
		*y = sumy/2;
	}

SCAN_END:

#ifdef _AD_DEBUG
	if( en_disp_ad )
	{
		U8	j;
		
		for( j = 0; j < i; j++ )
		{
			k++;
			if( k >= 10 )
			{
				k = 0;
				t = 100 - t;
				SysClearRec( hGC, GPC_WHITE, t, 84, 60, 120, GPC_REPLACE_STYLE );
			}
			sprintf( info, "%04X %04X", tempx[j], tempy[j] );
			SysTextOut( hGC, GPC_BLACK, t, 84+k*12, info, GPC_REPLACE_STYLE );
		}
		k++;
		if( k >= 10 )
		{
			k = 0;
			t = 100 - t;
			SysClearRec( hGC, GPC_WHITE, t, 84, 60, 120, GPC_REPLACE_STYLE );
		}
		sprintf( info, "%04X %04XT", *x, *y );
		SysTextOut( hGC, GPC_BLACK, t, 84+k*12, info, GPC_REPLACE_STYLE );
	}
#endif
	
	return flag;
}


/********************************************************************
*   Function TouchPanelHandler() 
*	param in:		
*	param out: 		
*	description: TouchPanel Timer Handler	
********************************************************************/
unsigned short esram = 0;
void TouchPanelHandler(void)
{
	STATUS flag, kk;
	
	ENTER_CRITICAL_SECTION;
	
	flag = average_pos2(&xpos,&ypos);

	/* test for AD by gfd 
	*(RP)(0x1fff0000 + 4*(esram++)) = xpos;
	*(RP)(0x1fff0000 + 4*(esram++)) = ypos;
	if(esram >0x4800/4)esram = 0x00;
	*/
	if (flag==1)
    {
		if( xpos == 0 || ypos == 0 )
			return;
		
    	if (((PEN_BUF_writecount +1) % MAX_PENBUF) != PEN_BUF_readcount)
		{
			PEN_BUF[PEN_BUF_writecount].x = xpos;
			PEN_BUF[PEN_BUF_writecount].y = ypos;
			PEN_BUF[PEN_BUF_writecount].flag = SM_PENMOVE;
			PEN_BUF_writecount = (PEN_BUF_writecount +1) % MAX_PENBUF;

			set_flg(SYS_EVENT, INTPEN_FLG);
		}
 	}
 	else if (flag==0)
 	{
		if( xpos != 0 || ypos != 0 )
			return;
		
		if (((PEN_BUF_writecount +1) % MAX_PENBUF) != PEN_BUF_readcount)
		{
			PEN_BUF[PEN_BUF_writecount].x = xpos;
			PEN_BUF[PEN_BUF_writecount].y = ypos;
			PEN_BUF[PEN_BUF_writecount].flag = SM_PENUP;
			PEN_BUF_writecount = (PEN_BUF_writecount +1) % MAX_PENBUF;
			 		
			set_flg(SYS_EVENT, INTPEN_FLG);
	
			for(kk=0;kk<0x1000;kk++);
	 		act_cyc(TOUCHTIMER,TCY_OFF);
	 		PenEnable();
	 	}
	}else{; }//wrong AD_VALUE
}

static void touch_panel_isr( void )
{
	P_U32 reg;
	

	if (((PEN_BUF_writecount +1) % MAX_PENBUF) != PEN_BUF_readcount)
	{
		//PEN_BUF[PEN_BUF_writecount].x = 0xffff;
		//PEN_BUF[PEN_BUF_writecount].y = 0xffff;
		PEN_BUF[PEN_BUF_writecount].flag = SM_PENDOWN;
		PEN_BUF_writecount = (PEN_BUF_writecount +1) % MAX_PENBUF;
		set_flg(SYS_EVENT, INTPEN_FLG);
	}
}

void ENT_INT_TP( void )
{
	ent_int();

	#ifdef AD7846
	mask_irq(INT_TP);
	#else
	mask_irq(INT_EXT16);
	#endif
	//ENABLE_INT;
	
	touch_panel_isr();
	
	//DISABLE_INT;
	//if(!((*(RP)(INTC_IRSTAT))&0x200))
	//unmask_irq(INT_TP);		//for timehandler will re-enable tp

	ret_int();
}

⌨️ 快捷键说明

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