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

📄 drv_touchpanel.c

📁 Epson系列芯片开发的例子
💻 C
📖 第 1 页 / 共 2 页
字号:
 *		2:	AD sampling not correct,maybe do again(designed by user)
 **************************************************************************************************************/
unsigned char ucTouchPanelGetCoordinate( unsigned short *pusXADValue, unsigned short *pusYADValue )
{
	unsigned char i, ucCurrentSampleTime = 0;
	
	unsigned short usXADValue, usYADValue, j;
	
	*(volatile unsigned char *)INT_FADE_FCTM_FP4_ADDR |= 0x01;	// Reset A/D interrupt factor flag

	// Sample Rx:BXH(P32)=0;BXL(P33)=1;BYH(P34)=1;BYL(P35)=0
	*( volatile unsigned char * )IO_P3D_ADDR |= 0x18;
	*( volatile unsigned char * )IO_P3D_ADDR &= 0x0DB;
	
	for( j = 0; j < 500; j++ )
		asm("nop");

	*( volatile unsigned char * )AD_CS_ADDR = (AD_CE_1 | AD_CS_1);		// AD1 for Rx sampling

	while ( ucCurrentSampleTime < MAXSAMPLENUM )
	{
		*( volatile unsigned char * )AD_OWE_ADDR |= AD_ADST_RUN;		// start run AD
		
		// waiting Rx coordinate got
		while( (*(volatile unsigned char * )INT_FADE_FCTM_FP4_ADDR & 0x01 ) == 0 )
		{;}
		*( volatile unsigned char * )INT_FADE_FCTM_FP4_ADDR |= 0x01;	// Reset A/D interrupt factor flag
		usaXY[ ucCurrentSampleTime ][ 0 ] = *( volatile unsigned short * )AD_ADD_ADDR;	// got Rx data
		ucCurrentSampleTime++;
	}

	ucCurrentSampleTime = 0;

	// Sample Ry:BXH(P32)=1;BXL(P33)=0;BYH(P34)=0;BYL(P35)=1
	*( volatile unsigned char * )IO_P3D_ADDR |= 0x24;
	*( volatile unsigned char * )IO_P3D_ADDR &= 0x0E7;
	for( j = 0; j < 450; j++ )						// 250 when 30MHz/15MHz
		asm("nop");
				
	*( volatile unsigned char * )AD_CS_ADDR = ( AD_CE_0 | AD_CS_0 );	// AD0 for Ry sampling

	while ( ucCurrentSampleTime < MAXSAMPLENUM )
	{		
		*( volatile unsigned char * )AD_OWE_ADDR |= AD_ADST_RUN;		// start run AD
		
		// waiting Ry coordinate got
		while( ((*(volatile unsigned char * )INT_FADE_FCTM_FP4_ADDR & 0x01) == 0 ))
		{;}
		*( volatile unsigned char * )INT_FADE_FCTM_FP4_ADDR |= 0x01;	// Reset A/D interrupt factor flag
		usaXY[ ucCurrentSampleTime ][ 1 ] = *( volatile unsigned short * )AD_ADD_ADDR;	// got Ry data
		ucCurrentSampleTime++;
	}
	
	// Calculate the everage data of AD_results & check the validate numbers among them
	if(( ucTouchPanelAverageADValue( MAXSAMPLENUM, &usXADValue, &usYADValue )))
	{
		if (( usXADValue < 50 ) || ( usXADValue > 0x390 ) || 
			( usYADValue < 50 ) || ( usYADValue > 0x390 ))
		{
			i = 1;			
		}
		else
		{
			*pusXADValue = usXADValue;
			*pusYADValue = usYADValue;
			i = 0;
		}
	}
	else
		i = 2;

	return( i );
}

/***************************************************************************
 * vTouchPanelDitherHandler
 *   Type :	void
 *   Input:	ucDelayMiliSecond: Delay time
 *   Ret val :	none
 *   Argument :	void
 *   Function :	Delay a time of "ucDelayMiliSecond"ms.
 ***************************************************************************/
void vTouchPanelDitherHandler( unsigned char ucDelayMiliSecond )
{
	// Set 16bit timer3 prescaler [0x4014A]: Set 16bit timer3 prescaler (CLK/4096)
	*(volatile unsigned char *)PRESC_P16TS3_ADDR = PRESC_PTONL_ON | PRESC_CLKDIVL_SEL7;

	// Set 16bit timer3 comparison match B data [0x4819A]
	// Set comparison match B data
	*(volatile unsigned short *)T16P_CR3B_ADDR = MAINCLK / 4096 / 1000 * ucDelayMiliSecond - 1;

	// Set 16bit timer3 mode [0x4819E]
	*(volatile unsigned char *)T16P_PRUN3_ADDR = T16P_SELFM_NOR | T16P_SELCRB_DIS | T16P_OUTINV_NOR | \
						T16P_CKSL_INT | T16P_PTM_OFF | T16P_PSET_ON | T16P_PRUN_STOP;

	// Set 16bit timer3 interrupt priority level 4 on interrupt controller [0x40267]
	*(volatile unsigned char *)INT_P16T2_P16T3_ADDR &= 0x0F;
	*(volatile unsigned char *)INT_P16T2_P16T3_ADDR |= INT_PRIH_LVL4;

	// Reset 16bit timer3 interrupt factor flag on interrupt controller [0x40283]
	// Reset 16bit timer3 comparison match B interrupt flag
	*(volatile unsigned char *)INT_F16T2_F16T3_ADDR = INT_F16TU3;

	// Set 16bit timer3 interrupt enable on interrupt controller [0x40273]
	// Set 16bit timer3 comparison match B interrupt enable
	*(volatile unsigned char *)INT_E16T2_E16T3_ADDR |= INT_E16TU3;	
	
	// Run 16bit timer3 [0x4819E]
	*(volatile unsigned char *)T16P_PRUN3_ADDR |= T16P_PRUN_RUN;

/*	
	//0x40160
	//*(volatile unsigned char *)T8P_PTRUN0_ADDR = T8P_PTOUT_OFF | T8P_PTRUN_STOP;
	//0x40146
	*(volatile unsigned char *)PRESC_P8T_ADDR &= 0x0FE;		// not direct from prescallar, but by devision
	//0x4014d
	*(volatile unsigned char *)PRESC_P8TS0_P8TS1_ADDR |= 0x70;	// 4096 devisin(60M/4096=14.6484375KHz=0.06827ms)
	//0x40161, reload data register
	*(volatile unsigned char *)T8P_RLD0_ADDR |= ucDelayMiliSecond * MAINCLK / 4096 / 1000 - 1;// Reload data, 0xff cause 25ms when 40MHz
	//0x40275
	*(volatile unsigned char *)INT_E8TU_ADDR |=INT_E8TU0;		// Enable 8 bits Timer0 underflow interrupt
	//0x40160
	*(volatile unsigned char *)T8P_PTRUN0_ADDR |= T8P_PTRUN_RUN | T8P_PSET_ON;
*/
}

/***********************************************************************************
 * vTouchPanelScanStop
 *   Type :	void
 *   Input:	void
 *   Ret val :	none
 *   Argument :	void
 *   Function :	Stop the time interruption for TouchPanel scan.
 ***********************************************************************************/
void vTouchPanelScanStop(void)
{
	// [0x4819E]
	*(volatile unsigned char *)T16P_PRUN3_ADDR &= ~T16P_PRUN_RUN;	// Stop 16 bits Timer 3
	
	// Reset 16bit timer3 interrupt factor flag on interrupt controller [0x40283]
	// Reset 16bit timer3 comparison match B interrupt flag
	*(volatile unsigned char *)INT_F16T2_F16T3_ADDR = INT_F16TU3;

	// Set 16bit timer3 interrupt enable on interrupt controller [0x40273]
	// Set 16bit timer3 comparison match B interrupt enable
	*(volatile unsigned char *)INT_E16T2_E16T3_ADDR &= ~INT_E16TU3;	
	
/*	
	//0x40160
	*(volatile unsigned char *)T8P_PTRUN0_ADDR = T8P_PTRUN_STOP;	// Stop 8 bits Timer 0
	//0x40275
	*(volatile unsigned char *)INT_E8TU_ADDR &= 0xfe;		// Disable 8 bits Timer0 underflow interrupt. 
*/
}

/***********************************************************************************
 * vIntTouchPanelScanHandler
 *   Type :	void
 *   Input:	void
 *   Ret val :	none
 *   Argument :	void
 *   Function :	Scan the TouchPanel get the coordinate.
 ***********************************************************************************/
void vIntTouchPanelScanHandler( void )
{
	asm("pushn	%r15");
	*(volatile unsigned char *)40283 |= 0x40;			// reset the 16 bits timer 3 interrupt flag
	switch( ucTouchPanelStatus = ucTouchPanelGetCoordinate( &usADValueX, &usADValueY ) )
	{
		case	0:						//Pen down
			vTouchPanelScanStop( );
			vTouchPanelDitherHandler( TOUCHPANELSCANGAP );
			break;
		case	1:						//Pen up
			vTouchPanelScanStop( );
			//[0x402DD]
 			*(volatile unsigned char *)IO_P3D_ADDR |= 0x34;	// set P34(BYH) = 1,P32(BXH) = 1,P35(BYL) = 1,
			*(volatile unsigned char *)IO_P3D_ADDR &= 0x0F7;// set P33(BXL) = 0
			*( volatile unsigned char * )0x40280 |= 0x20;		// reset FPK1 interrupt flag
			*(volatile unsigned char *)IN_SMPK1_ADDR |= 0x04;	//Enable K62 ( #PENINT ) interrupt
			break;
		case	2:						//Dithering
			break;
		default:
			break;
	}
	asm("popn	%r15");
	asm("reti");
}

/***************************************************************************************************************
 * vIntTouchPanelAD
 *   Type :	void
 *   Ret val :	none
 *   Argument :	void
 *   Function :	interrupt service for Touch panel AD & Voice recorder AD
 *              1. check the AD source.
 *		2. Got AD convertion data, put into corresponding buffers
 *
 ***************************************************************************************************************/
void vIntTouchPanelAD( void )
{	
	asm("pushn	%r15");			// save r1,r2...r15
	asm("ld.w	%r9,%psr");		// EI,enable interrupt
	asm("or 	%r9,0x10");
	asm("ld.w	%psr,%r9");

	if ( *(volatile unsigned char *)AD_CS_ADDR == (AD_CE_1 | AD_CS_1 ))
		usaXY[ucCurrentSampleTime][1] = *(volatile unsigned short *)AD_ADD_ADDR;	// got Rx data
		
	if ( *(volatile unsigned char *)AD_CS_ADDR == (AD_CE_0 | AD_CS_0 ))
		usaXY[ucCurrentSampleTime][0] = *(volatile unsigned short *)AD_ADD_ADDR;	// got Ry data
	
	// Reset A/D interrupt factor flag
	*(volatile unsigned char *)INT_FADE_FCTM_FP4_ADDR |= 0x01;

	asm("popn	%r15");			// restore r1,r2...r15
	asm("reti");
}

⌨️ 快捷键说明

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