bsptouch.cpp
来自「iMX21 Touch driver under WinCE5.0」· C++ 代码 · 共 582 行 · 第 1/2 页
CPP
582 行
dwX_Max = dwX_Min = dwX[1];
dwY_Max = dwY_Min = dwY[1];
*x = *y = 0;
// If we receive an x point less than MIN_VALID_PEN_X it is
// considered to be a pen up case.
// Discard first & last samples as they tends to differ quite
// signifcantly from the rest.
flag = 0;
for (i=1; i< (TOUCH_NUMBER_OF_SAMPLES - 1); i++) {
if(dwX[i] <= MIN_VALID_PEN_X){
flag = 1;
break;
}
//Calculate the X and Y coordinate use the samples
dwtmp = dwX[i];
if (dwX_Max < dwtmp)
dwX_Max = dwtmp;
if (dwX_Min > dwtmp)
dwX_Min = dwtmp;
*x += dwtmp;
dwtmp = dwY[i];
if (dwY_Max < dwtmp)
dwY_Max = dwtmp;
if (dwY_Min > dwtmp)
dwY_Min = dwtmp;
*y += dwtmp;
}
if (flag){
DEBUGMSG(ZONE_FUNCTION, (TEXT("flag-: (%d)\r\n"), flag));
StateFlags = TouchSampleValidFlag;
if (dwOldX != 0){
*x = dwOldX;
*y = dwOldY;
} else{
*x = 0;
*y = 0;
}
return StateFlags;
} else{
*x = *x / (TOUCH_NUMBER_OF_SAMPLES - 2);
*y = *y / (TOUCH_NUMBER_OF_SAMPLES - 2);
/*
* Check the delta between max x and min x, max y and min y
* IF one of the delta is too large (now we define the delta to 10)
* Invalid sample, set the sample state flag to TouchSampleIgnore
*/
if (((dwX_Max - dwX_Min) > DELTA_X_COORD_VARIANCE) ||
((dwY_Max - dwY_Min) > DELTA_Y_COORD_VARIANCE)){
DEBUGMSG(ZONE_FUNCTION, (TEXT("INVALID SAMPLE: X=%d Y=%d\r\n"), *x, *y));
StateFlags |= TouchSampleIgnore;
} else{
DEBUGMSG(ZONE_FUNCTION, (TEXT("SAMPLE: X=%d, Y=%d\r\n"), *x, *y));
dwOldX = *x;
dwOldY = *y;
StateFlags |= TouchSampleValidFlag;
}
}
DEBUGMSG(ZONE_FUNCTION, (TEXT("StateFlags(0x%08x)\r\n"), StateFlags));
return StateFlags;
}
//-----------------------------------------------------------------------------
//
// Function: BSPTouchTimerInit
//
// This function initializes the EPIT2 timer for use as the touch
// periodic timer.
//
// Parameters:
// None
//
// Returns:
// TRUE if successful, otherwise FALSE.
//
//-----------------------------------------------------------------------------
BOOL BSPTouchTimerInit(void)
{
// Reset timer
OUTREG32(&pTouchTimerStatic->TCTL, CSP_BITFMASK(GPT_TCTL_SWR));
// Wait for the software reset to complete
while (INREG32(&pTouchTimerStatic->TCTL) & CSP_BITFMASK(GPT_TCTL_SWR));
pTouchTimerStatic->TPRER = 0;
pTouchTimerStatic->TCMP = BSP_REF_32KHZ_FREQ / (CurSampleRateStatic+50);
pTouchTimerStatic->TCTL = CSP_BITFVAL(GPT_TCTL_TEN, GPT_TCTL_TEN_DISABLE) |
CSP_BITFVAL(GPT_TCTL_CLKSOURCE, GPT_TCTL_CLKSOURCE_32KCLK) |
CSP_BITFVAL(GPT_TCTL_COMPEN, GPT_TCTL_COMPEN_ENABLE) |
CSP_BITFVAL(GPT_TCTL_CAPTEN, GPT_TCTL_CAPTEN_DISABLE) |
CSP_BITFVAL(GPT_TCTL_CAP, GPT_TCTL_CAP_DISABLE) |
CSP_BITFVAL(GPT_TCTL_FRR, GPT_TCTL_FRR_RESTART) |
CSP_BITFVAL(GPT_TCTL_OM, GPT_TCTL_OM_ACTIVELOW) |
CSP_BITFVAL(GPT_TCTL_CC, GPT_TCTL_CC_ENABLE);
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: BSPTouchTimerEnable
//
// This function activates the touch timer for the specified
// periodic timer interrupt.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void BSPTouchTimerEnable(void)
{
pTouchTimerStatic->TSTAT = CSP_BITFMASK(GPT_TSTAT_COMP);
pTouchTimerStatic->TCTL |= (CSP_BITFMASK(GPT_TCTL_TEN) |
CSP_BITFMASK(GPT_TCTL_COMPEN));
}
//-----------------------------------------------------------------------------
//
// Function: BSPTouchTimerDisable
//
// DESCRIPTION:
// This function disables the touch timer and clears any pending
// timer interrupt.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void BSPTouchTimerDisable(void)
{
pTouchTimerStatic->TCTL &= ~(CSP_BITFMASK(GPT_TCTL_TEN) |
CSP_BITFMASK(GPT_TCTL_COMPEN));
pTouchTimerStatic->TSTAT = CSP_BITFMASK(GPT_TSTAT_COMP);
}
//-----------------------------------------------------------------------------
//
// Function: BSPTouchTimerIrqQuery
//
// DESCRIPTION:
// This function queries the touch timer interrupt status.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
BOOL BSPTouchTimerIrqQuery(void)
{
return ((pTouchTimerStatic->TSTAT & CSP_BITFMASK(GPT_TSTAT_COMP)) != 0);
}
//-----------------------------------------------------------------------------
//
// Function: BSPTouchPowerHandler
//
// DESCRIPTION:
// This function enable and disable the PEN_IRQ, the function
// also disable timer during power down
//
// Parameters:
// boff - TRUE : power down
// - FALSE : power up
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void BSPTouchPowerHandler(BOOL boff)
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("DdsiTouchPanelPowerHandler+:boff(%c)\r\n"), boff? 'T':'F'));
if (boff == TRUE){
// Just disable timer and interrupts
BSPTouchTimerDisable();
// Disable the Pen IRQ
DDKSetGpioInterruptState(pTouchGpio, GPIO_INTR_TOUCH_PORT, GPIO_INTR_TOUCH_PIN, TRUE, FALSE);
} else{
// Configure timer but keep it disabled
BSPTouchTimerInit();
// Enable the Pen IRQ
DDKSetGpioInterruptState(pTouchGpio, GPIO_INTR_TOUCH_PORT, GPIO_INTR_TOUCH_PIN, TRUE, TRUE);
}
return;
}
//------------------------------------------------------------------------------
//
// FUNCTION: BSPTouchIntrDisable
//
// DESCRIPTION: This function is used to disable the touch screen interrupt
// from AD7873 after pen up is detected.
//
// PARAMETERS:
// None
//
// RETURNS:
// None
//
//------------------------------------------------------------------------------
void BSPTouchIntrDisable(void)
{
// Note: This needs to be done after InterruptDone() so as to override
// the default setting.
DEBUGMSG(ZONE_FUNCTION, (TEXT("Disable AD7873 PENIRQ\r\n")));
DDKSetGpioInterruptState(pTouchGpio, GPIO_INTR_TOUCH_PORT,
GPIO_INTR_TOUCH_PIN, FALSE, FALSE);
}
//------------------------------------------------------------------------------
//
// FUNCTION: BSPTouchIntrEnable
//
// DESCRIPTION: This function is used to enable the touch screen interrupt
// from AD7873 after pen up is detected.
//
// PARAMETERS:
// None
//
// RETURNS:
// None
//
//------------------------------------------------------------------------------
void BSPTouchIntrEnable(void)
{
UINT32 RxBuf;
UINT32 cmd = TOUCH_CMD_INTR_ENABLE;
// Enable AD7873 PENIRQ
DEBUGMSG(ZONE_FUNCTION, (TEXT("Enable AD7873 PENIRQ\r\n")));
DDKSetGpioInterruptState(pTouchGpio, GPIO_INTR_TOUCH_PORT,
GPIO_INTR_TOUCH_PIN, FALSE, TRUE);
// Lock the cspi hardware resource
DDKCspiHwResourceLock(pTouchCspi, TRUE);
// Configure Cspi
DEBUGMSG(ZONE_FUNCTION, (TEXT("Configuring the cspi hardware\r\n")));
DDKCspiConfigure(pTouchCspi, &cspiConfigDataStatic);
// Select AD7873
DDKCspiChipSelect(pTouchCspi, TOUCH_CSPI_PORT);
DDKCspiExchange(pTouchCspi, &cmd, &RxBuf, 1);
// Release CSPI hardware resource
DDKCspiHwResourceLock(pTouchCspi, FALSE);
}
//------------------------------------------------------------------------------
//
// FUNCTION: BSPTouchTimerInterruptClear
//
// DESCRIPTION: This function is used to clear the touch timer interrupt status.
//
// PARAMETERS:
// None
//
// RETURNS:
// None
//
//------------------------------------------------------------------------------
void BSPTouchTimerInterruptClear(void)
{
pTouchTimerStatic->TSTAT = CSP_BITFMASK(GPT_TSTAT_COMP);
}
//------------------------------------------------------------------------------
// END OF FILE
//------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?