📄 toucher.c
字号:
*pUncalY = (ULONG)( ( ( rgPointSamples[ 0 ].YSample + rgPointSamples[ 2 ].YSample ) >> 1 ) );
}
else
{
*pUncalY = (ULONG)( ( ( rgPointSamples[ 1 ].YSample + rgPointSamples[ 2 ].YSample ) >> 1 ) );
}
//
// Validate the coordinates and set the tip state accordingly.
//
if ( dlXDiff0 > DELTA_X_COORD_VARIANCE ||
dlXDiff1 > DELTA_X_COORD_VARIANCE ||
dlXDiff2 > DELTA_X_COORD_VARIANCE ||
dlYDiff0 > DELTA_Y_COORD_VARIANCE ||
dlYDiff1 > DELTA_Y_COORD_VARIANCE ||
dlYDiff2 > DELTA_Y_COORD_VARIANCE )
{
//#ifdef DBGPOINTS1
/*DEBUGMSG( ZONE_SAMPLES, (TEXT("Sample 0: X 0x%x Y 0x%x\r\n"),
rgPointSamples[ 0 ].XSample, rgPointSamples[ 0 ].YSample) );
DEBUGMSG( ZONE_SAMPLES, (TEXT("Sample 1: X 0x%x Y 0x%x\r\n"),
rgPointSamples[ 1 ].XSample, rgPointSamples[ 1 ].YSample) );
DEBUGMSG( ZONE_SAMPLES, (TEXT("Sample 2: X 0x%x Y 0x%x\r\n"),
rgPointSamples[ 2 ].XSample, rgPointSamples[ 2 ].YSample) ); */
if ( dlXDiff0 > DELTA_X_COORD_VARIANCE )
DEBUGMSG( ZONE_SAMPLES, (TEXT("XDiff0 too large 0x%x\r\n"), dlXDiff0) );
if ( dlXDiff1 > DELTA_X_COORD_VARIANCE )
DEBUGMSG( ZONE_SAMPLES, (TEXT("XDiff1 too large 0x%x\r\n"), dlXDiff1) );
if ( dlXDiff2 > DELTA_X_COORD_VARIANCE )
DEBUGMSG( ZONE_SAMPLES, (TEXT("XDiff2 too large 0x%x\r\n"), dlXDiff2) );
if ( dlYDiff0 > DELTA_Y_COORD_VARIANCE )
DEBUGMSG( ZONE_SAMPLES, (TEXT("YDiff0 too large 0x%x\r\n"), dlYDiff0) );
if ( dlYDiff1 > DELTA_Y_COORD_VARIANCE )
DEBUGMSG( ZONE_SAMPLES, (TEXT("YDiff1 too large 0x%x\r\n"), dlYDiff1) );
if ( dlYDiff2 > DELTA_Y_COORD_VARIANCE )
DEBUGMSG( ZONE_SAMPLES, (TEXT("YDiff2 too large 0x%x\r\n"), dlYDiff2) );
//#endif // DBGPOINTS1
}
else
{
//
// Sample is valid. Set tip state accordingly.
//
*pSampleFlags = SAMPLE_VALID | SAMPLE_DOWN;//TouchSampleValidFlag | TouchSampleDownFlag;
}
//DEBUGMSG( ZONE_SAMPLES, (TEXT("Filtered - SampleFlags: 0x%x X: 0x%x Y: 0x%x\r\n"),
// *pSampleFlags, *pUncalX, *pUncalY) );
}
// **************************************************
// 申明:static BOOL Touch_Pen_filtering(INT *px, INT *py)
// 参数:
// INT px -
// INT py
// 返回值:
// TRUE/FALSE 创建(成功/失败)
// 功能描述:
// 检查x,y的有效性
// 引用:
// **************************************************
static BOOL Touch_Pen_filtering(int *px, int *py)
{
BOOL RetVal = TRUE;
// TRUE : Valid pen sample
// FALSE : Invalid pen sample
static int count = 0;
static int x[2], y[2];
int TmpX, TmpY;
int dx, dy;
count++;
if (count > 2)
{
// apply filtering rule
count = 2;
// average between x,y[0] and *px,y
TmpX = (x[0] + *px) / 2;
TmpY = (y[0] + *py) / 2;
// difference between x,y[1] and TmpX,Y
dx = (x[1] > TmpX) ? (x[1] - TmpX) : (TmpX - x[1]);
dy = (y[1] > TmpY) ? (y[1] - TmpY) : (TmpY - y[1]);
if ((dx > FILTER_LIMIT) || (dy > FILTER_LIMIT)) {
// Invalid pen sample
*px = x[1];
*py = y[1]; // previous valid sample
RetVal = FALSE;
count = 0;
} else {
// Valid pen sample
x[0] = x[1]; y[0] = y[1];
x[1] = *px; y[1] = *py; // reserve pen samples
RetVal = TRUE;
}
} else { // till 2 samples, no filtering rule
x[0] = x[1]; y[0] = y[1];
x[1] = *px; y[1] = *py; // reserve pen samples
RetVal = FALSE; // <- TRUE jylee 2003.03.04
}
return RetVal;
}
// **************************************************
// 申明:void TouchPanelPowerOn( void )
// 参数:
// 无
// 返回值:
// TRUE/FALSE (成功/失败)
// 功能描述:
// 加电操作/使Touch可以工作
// 引用:
// ************************************************
static void TouchPanelPowerOn( void )
{
DWORD tmp = 0;
//RETAILMSG(1,(TEXT("TouchPanelPowerOn entry.\r\n")));
//
// Setup GPIOs for touch
//
// Clear GPG15, 14, 13, 12
v_pIOPregs->rGPGCON &= ~((0x03 << 30)|(0x03 << 28)|(0x03 << 26)|(0x03 << 24));
// Set GPG15 to use as nYPON, GPG14 to use as YMON, GPG13 to use as nXPON, GPG12 to use as XMON
v_pIOPregs->rGPGCON |= ((0x03 << 30)|(0x03 << 28)|(0x03 << 26)|(0x03 << 24));
// Disable full up function
v_pIOPregs->rGPGUP |= ((0x01 << 15)|(0x01 << 14)|(0x01 << 13)|(0x01 << 12));
//
// Setup ADC register
//
// Down Int, YMON:0, nYPON:1, XMON:0;nXPON:1, Pullup:1, Auto Conv.,Waiting.
// v_pADCregs->rADCTSC = (0<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3);
// v_pADCregs->rADCTSC = (0<<8)|(1<<7)|(1<<6)|(0<<5)|(0<<4)|(0<<3)|(0<<2)|(3);
// v_pADCregs->rADCDLY = ADC_DELAY_TIME;//default value for delay.
// v_pADCregs->rADCCON = (1<<14)|(ADCPRS<<6)|(7<<3); //setup channel, ADCPRS, Touch Input
// v_pADCregs->rADCCON = (1<<14)|(ADCPRS<<6)|(2<<3); //setup channel, ADCPRS, Touch Input
// v_pADCregs->rADCCON = (1<<14)|(ADCPRS<<6)|(0<<3); //setup channel, ADCPRS, Touch Input
return ;
}
// **************************************************
// 申明:void TouchPanelPowerOff( void )
// 参数:
// 无
// 返回值:
// TRUE/FALSE (成功/失败)
// 功能描述:
// 关电操作/使Touch无法工作
// 引用:
// ************************************************
static void TouchPanelPowerOff( void )
{
}
/**************************************************
申明:BOOL TouchPddCreate( void )
参数:无
返回值:TRUE/FALSE 创建(成功/失败)
功能描述:初始化触摸屏设备层需要的资源
引用:
************************************************/
BOOL TouchPddCreate( void )
{
return TRUE;
}
/**************************************************
申明:void TouchPddDestroy( void )
参数:无
返回值:无
功能描述:释放触摸屏设备层分配的资源
引用:
************************************************/
void TouchPddDestroy( void )
{
INTR_Disable(SYSINTR_TOUCH);
}
/**************************************************
申明:BOOL TouchPddEnable( void )
参数:无
返回值:TRUE/FALSE (成功/失败)
功能描述:允许中断
引用:
************************************************/
#define DEBUG_TouchPddEnable 0
BOOL TouchPddEnable( void )
{
//DEBUGMSG(DEBUG_TouchPddEnable, (TEXT("TouchPddEnable entry.\r\n") ));
// Power on touch panel
TouchPanelPowerOn();
// Setup pen down interrupts, but leave ints disabled until InterruptEnable().
PddpSetupPenDownIntr(TRUE);
// int enable
v_pDriverGlobals->tch.status = 0;
// INTR_Done( idTouchChangedIrq );
Touch_Timer1_Setup( PEN_IDLE_MODE );
//DEBUGMSG(DEBUG_TouchPddEnable, (TEXT("TouchPddEnable leave.\r\n") ));
return( TRUE ); // we always succeed!!!!!!
}
/**************************************************
申明:void TouchPddDisable( void )
参数:无
返回值:无
功能描述:禁止中断
引用:
************************************************/
void TouchPddDisable( void )
{
TouchPanelPowerOff(); // Power down the device
}
/**************************************************
申明:void TouchPddClose( void )
参数:无
返回值:无
功能描述:
引用:
************************************************/
void TouchPddClose( void )
{
TouchPddDisable();
}
/**************************************************
申明:void TouchPddPowerHandle( BOOL bPowerOff )
参数:bPowerOff--(TRUE/FALSE)/(开/关)机
返回值:TRUE/FALSE 创建(成功/失败)
功能描述:处理触摸屏(开/关)机
引用:
************************************************/
void TouchPddPowerHandle( BOOL bPowerOff )
{
// Set flag so we know to avoid system calls
bInPowerHandler = TRUE;
if (bPowerOff) {
TouchPanelPowerOff();
}
else {
TouchPanelPowerOn();
PddpSetupPenDownIntr(TRUE);
}
bInPowerHandler = FALSE;
}
/**************************************************
申明:BOOL TouchPddGetPoint(int *pUnCalx, int *pUnCaly, DWORD *pFlag)
参数:*pUnCalx--返回未刻度的x坐标
*pUnCaly--返回未刻度的y坐标
*pFlag--当前笔的状态
返回值:TRUE/FALSE (成功/失败)
功能描述:获得未刻度的坐标和笔的状态
引用:
************************************************/
#define DEBUG_TouchPddGetPoint 1
VOID TouchPddGetPoint(int *pUncalX, int *pUncalY, DWORD *pTipStateFlags)
{
static int xPrev = 0;
static int yPrev = 0;
static int statePrev = 0;
static int nDownDelayTick = 0;
int x, y;
int mode = PEN_IDLE_MODE;
//DEBUGMSG(DEBUG_TouchPddGetPoint, (TEXT("TouchPddGetPoint: entry!.\r\n") ));
v_pADCregs->rADCTSC = (0<<8)|(0<<7)|(0<<6)|(0<<5)|(1<<4)|(1<<3)|(0<<2)|(0); //power to idle
usWait(100);
v_pADCregs->rADCCON &= ~(0x7<<3);
//pADCregs->rADCCON |= (0<<3) | (1<<0); //alex 16/09/2004
v_pADCregs->rADCCON |= (2<<3) | (1<<0);
while(!(0x8000&v_pADCregs->rADCCON));
v_pADCregs->rADCCON &= ~(0x7<<3);
//pADCregs->rADCCON |= (0<<3) | (1<<0); //alex 16/09/2004
v_pADCregs->rADCCON |= (2<<3) | (1<<0);
while(!(0x8000&v_pADCregs->rADCCON));
x = (0x3ff & v_pADCregs->rADCDAT0);
//DEBUGMSG(DEBUG_TouchPddGetPoint, (TEXT("+++++++ x=[%d] \r\n"), x));
if( x < MAX_ADVAL ) // up || mov pen
{ // up pen or invalid pen
//if(x < UP_TRIGGER)
{
if( statePrev == SAMPLE_DOWN )
{
*pTipStateFlags = SAMPLE_VALID;
*pUncalX = xPrev;
*pUncalY = yPrev;
statePrev = 0;
nDownDelayTick = DELAY_DOWN_TICK;
// mode = PEN_IDLE_MODE;
//DEBUGMSG(DEBUG_TouchPddGetPoint, (TEXT("x=%d, y=%d. up pen.\r\n"), *pUncalX, *pUncalY));
}
else
{
if( nDownDelayTick )
{
mode = SAMPLE_DOWN;
nDownDelayTick--;
}
*pTipStateFlags = SAMPLE_IGNORE;
v_pDriverGlobals->tch.status = 0;
}
}
}
else // down
{
int i;
unsigned short xx[4], yy[4];
aa:
v_pADCregs->rADCTSC =(0<<8)|(1<<7)|(0<<6)|(0<<5)|(1<<4)|(1<<3)|(0<<2)|(0); //power to Y channel
usWait(100);
for(i=0; i<3; i++){
v_pADCregs->rADCCON &= ~(0x7<<3); // Start Auto conversion
//v_pADCregs->rADCCON |= (0<<3) | (1<<0); //alex 16/09/2004
v_pADCregs->rADCCON |= (2<<3) | (1<<0);
while(v_pADCregs->rADCCON & 0x1); //check if Enable_start is low
while(!(0x8000&v_pADCregs->rADCCON)); // Check ECFLG
xx[i] = 0x3ff & v_pADCregs->rADCDAT0;
}
v_pADCregs->rADCTSC =(0<<8)|(0<<7)|(1<<6)|(1<<5)|(0<<4)|(1<<3)|(0<<2)|(0); //power to Y channel
usWait(100);
for(i=0; i<3; i++){
v_pADCregs->rADCCON &= ~(0x7<<3); // Start Auto conversion
//v_pADCregs->rADCCON |= (2<<3) | (1<<0); //alex 16/09/2004
v_pADCregs->rADCCON |= (0<<3) | (1<<0);
while(v_pADCregs->rADCCON & 0x1); //check if Enable_start is low
while(!(0x8000&v_pADCregs->rADCCON)); // Check ECFLG
yy[i] = 0x3ff & v_pADCregs->rADCDAT0;
}
xbuf[0] = xbuf[1] = xbuf[2] = xx[1];
ybuf[0] = ybuf[1] = ybuf[2] = yy[1];
//RETAILMSG(1, (TEXT("x[%d]=%d, y[%d]=%d \r\n"), 0, xbuf[0], 0, ybuf[0]));
/*for(i=0; i<3; i++){
RETAILMSG(1, (TEXT("x[%d]=%d, y[%d]=%d \r\n"), i, xx[i], i, yy[i]));
}*/
PddpTouchPanelEvaluateSamples( pTipStateFlags, &x, &y);
// v_pADCregs->rADCTSC=(1<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3);
v_pADCregs->rADCTSC =(0<<8)|(0<<7)|(1<<6)|(0<<5)|(1<<4)|(1<<3)|(0<<2)|(0); //power to idle
if (Touch_Pen_filtering(&x, &y)) // Valid touch pen
{
//RETAILMSG(JYLEE_TEST, (TEXT("valid touch pen\r\n")));
*pTipStateFlags = SAMPLE_VALID | SAMPLE_DOWN;
*pTipStateFlags &= ~SAMPLE_IGNORE;
}
else // Invalid touch pen
{
//RETAILMSG(1, (TEXT("invalid touch pen\r\n")));
*pTipStateFlags = SAMPLE_VALID;
*pTipStateFlags |= SAMPLE_IGNORE;
}
*pUncalX = xPrev = x;
*pUncalY = yPrev = y;
statePrev = SAMPLE_DOWN;
v_pDriverGlobals->tch.status = 1;
mode = PEN_DOWN_MODE;
}
// if( mode != -1 )
{
//DEBUGMSG(DEBUG_TouchPddGetPoint, (TEXT("set new mode(%d).\r\n"), mode ));
Touch_Timer1_Setup( mode );
}
//DEBUGMSG(DEBUG_TouchPddGetPoint, (TEXT("TouchPddGetPoint: leave!.\r\n") ));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -