📄 tchpdd.cpp
字号:
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( 1, (TEXT("Sample 0: X 0x%x Y 0x%x\r\n"),
rgPointSamples[ 0 ].XSample, rgPointSamples[ 0 ].YSample) );
DEBUGMSG( 1, (TEXT("Sample 1: X 0x%x Y 0x%x\r\n"),
rgPointSamples[ 1 ].XSample, rgPointSamples[ 1 ].YSample) );
DEBUGMSG( 1, (TEXT("Sample 2: X 0x%x Y 0x%x\r\n"),
rgPointSamples[ 2 ].XSample, rgPointSamples[ 2 ].YSample) );
if ( dlXDiff0 > DELTA_X_COORD_VARIANCE )
DEBUGMSG( 1, (TEXT("XDiff0 too large 0x%x\r\n"), dlXDiff0) );
if ( dlXDiff1 > DELTA_X_COORD_VARIANCE )
DEBUGMSG( 1, (TEXT("XDiff1 too large 0x%x\r\n"), dlXDiff1) );
if ( dlXDiff2 > DELTA_X_COORD_VARIANCE )
DEBUGMSG( 1, (TEXT("XDiff2 too large 0x%x\r\n"), dlXDiff2) );
if ( dlYDiff0 > DELTA_Y_COORD_VARIANCE )
DEBUGMSG( 1, (TEXT("YDiff0 too large 0x%x\r\n"), dlYDiff0) );
if ( dlYDiff1 > DELTA_Y_COORD_VARIANCE )
DEBUGMSG( 1, (TEXT("YDiff1 too large 0x%x\r\n"), dlYDiff1) );
if ( dlYDiff2 > DELTA_Y_COORD_VARIANCE )
DEBUGMSG( 1, (TEXT("YDiff2 too large 0x%x\r\n"), dlYDiff2) );
#endif // DBGPOINTS1
}
else
{
//
// Sample is valid. Set tip state accordingly.
//
*pSampleFlags = TouchSampleValidFlag | TouchSampleDownFlag;
}
//RETAILMSG( 1, (TEXT("Filtered - SampleFlags: 0x%x X: %4d Y: %4d\r\n"), *pSampleFlags, *pUncalX, *pUncalY) );
// if(*pUncalX<=130 || *pUncalX>4000 || *pUncalY<=130 || *pUncalY>4000){
if(*pUncalX<10 || *pUncalY<10){
// RETAILMSG( 0, (TEXT("Filtered - Sample X: %4d Y: %4d %4d %4d\r\n"),
// *pUncalX, *pUncalY,dUncalX,dUncalY) );
*pUncalX = 0;
*pUncalY = 0;
}else{
dUncalX = *pUncalX;
dUncalY = *pUncalY ;
}
#if 0
DEBUGMSG( 1, (TEXT("Filtered - Sample X: %4d Y: %4d\r\n"),
*pUncalX, *pUncalY) );
#endif
}
//
// PddpSetupPenDownIntr()
//
BOOL
PddpSetupPenDownIntr(BOOL EnableIntr)
{
DEBUGMSG(1, (TEXT("Touchscreen: PddpSetupPenDownIntr\r\n")));
// RETAILMSG(1, (TEXT("Touchscreen: PddpSetupPenDownIntr\r\n")));
/*
OEM_IOCTL_GPIO gpio;
int value;
gpio.num = 6; gpio.pin = 7; gpio.code = GPIO_IntType;
value = 0x02; gpio.value = &value;
KernelIoControl(HAL_IOCTL_GPIO , &gpio , sizeof(OEM_IOCTL_GPIO) , 0 , 0 , 0 );
gpio.num = 6; gpio.pin = 7; gpio.code = GPIO_IntEnable;
value = EnableIntr?1:0; gpio.value = &value;
KernelIoControl(HAL_IOCTL_GPIO , &gpio , sizeof(OEM_IOCTL_GPIO) , 0 , 0 , 0 );
if (EnableIntr)
{
unsigned long iDump;
WCHAR reg = INT_REQUEST;
WriteFile(gSsp, ®, sizeof(reg), &iDump, NULL); // Write Query then
}
*/
pGpioHead->dwGPIOIS &= (~0x01);
pGpioHead->dwGPIOIBE &= (~0x01);
// pGpioHead->dwGPIOIEV &= ~0x80; //下降沿
pGpioHead->dwGPIOIEV |= 0x01; //上升沿
if (EnableIntr)
{
pGpioHead->dwGPIOIC |= 0x01;
pGpioHead->dwGPIOIE |= 0x01;
}
else
{
pGpioHead->dwGPIOIE &= ~0x01;
pGpioHead->dwGPIOIC |= 0x01;
}
return TRUE;
}
//
// PddpDisableClearPenDownIntr(void)
//
inline BOOL
PddpDisableClearPenDownIntr(void)
{
DEBUGMSG(1, (TEXT("Touchscreen: PddpDisableClearPenDownIntr\r\n")));
pGpioHead->dwGPIOIC |= 0x01;
// this function is unused as events are automatic
return TRUE;
}
//
// DDSI Implementation
//
// @DOC EX_TOUCH_DDSI EXTERNAL DRIVERS TOUCH_DRIVER
/* @FUNC BOOL | TouchDriverCalibrationPointGet |
Gives a single calibration point.
@XREF
<l TouchPanelReadCalibrationPoint.TouchPanelReadCalibrationPoint>
<l TouchPanelSetCalibration.TouchPanelSetCalibration>
<l TouchPanelReadCalibrationAbort.TouchPanelReadCalibrationAbort>
@COMM
This function is called to get a single calibration point, in screen
coordinates, when the input system is calibrating the touch driver. The input system
will then draw a target on the screen for the user to press on.
The driver may use the cDisplayX and cDisplayY to compute a coordinate.
It does not need to remember this computed value internally since it will
be passed back when the input system has collected all of the points and
calls <l TouchPanelSetCalibration.TouchPanelSetCalibration>.
*/
extern "C"
BOOL
TouchDriverCalibrationPointGet(
TPDC_CALIBRATION_POINT *pTCP //@PARM pointer to returned calibration point
)
{
// RETAILMSG(1, (TEXT("Touchscreen: TouchDriverCalibrationPointGet(0x%x)\r\n"), pTCP -> PointNumber));
INT32 cDisplayWidth = pTCP -> cDisplayWidth;
INT32 cDisplayHeight = pTCP -> cDisplayHeight;
// int CalibrationRadiusX = cDisplayWidth/20;
int CalibrationRadiusX = cDisplayWidth/30; //16
int CalibrationRadiusY = cDisplayHeight/30; //9
// int CalibrationRadiusX = cDisplayWidth/40;
// int CalibrationRadiusY = cDisplayHeight/17;
switch (pTCP -> PointNumber)
{
case 0: //center
pTCP -> CalibrationX = cDisplayWidth/2;
pTCP -> CalibrationY = cDisplayHeight/2;
break;
case 1:
pTCP -> CalibrationX = CalibrationRadiusX*FLAGSEPARATOR;
pTCP -> CalibrationY = CalibrationRadiusY*FLAGSEPARATOR;
break;
case 2:
pTCP -> CalibrationX = CalibrationRadiusX*FLAGSEPARATOR;
pTCP -> CalibrationY = cDisplayHeight - CalibrationRadiusY*FLAGSEPARATOR;
break;
case 3:
pTCP -> CalibrationX = cDisplayWidth - CalibrationRadiusX*FLAGSEPARATOR;
pTCP -> CalibrationY = cDisplayHeight - CalibrationRadiusY*FLAGSEPARATOR;
break;
case 4:
pTCP -> CalibrationX = cDisplayWidth - CalibrationRadiusX*FLAGSEPARATOR;
pTCP -> CalibrationY = CalibrationRadiusY*FLAGSEPARATOR;
break;
default:
pTCP -> CalibrationX = cDisplayWidth/2;
pTCP -> CalibrationY = cDisplayHeight/2;
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
DEBUGMSG(1,(TEXT("cDisplayWidth : %4X\r\n"),cDisplayWidth));
DEBUGMSG(1,(TEXT("cDisplayHeight : %4X\r\n"),cDisplayHeight));
DEBUGMSG(1,(TEXT("CalibrationRadiusX : %4d\r\n"),CalibrationRadiusX));
DEBUGMSG(1,(TEXT("CalibrationRadiusY : %4d\r\n"),CalibrationRadiusY));
DEBUGMSG(1,(TEXT("pTCP -> PointNumber : %4d\r\n"),pTCP -> PointNumber));
DEBUGMSG(1,(TEXT("pTCP -> CalibrationX : %4d\r\n"),pTCP -> CalibrationX));
DEBUGMSG(1,(TEXT("pTCP -> CalibrationY : %4d\r\n"),pTCP -> CalibrationY));
return TRUE;
}
// @doc EX_TOUCH_DDSI EXTERNAL DRIVERS DDSI TOUCH_PANEL
//
// @func ULONG | DdsiTouchPanelGetDeviceCaps |
//
// Queries capabilities about the physical touch panel device.
//FLAGSEPARATOR
// @parm ULONG | iIndex |
//
// Specifies the capability to query. They are one of the following:
//
// @flag TPDC_SAMPLERATE_ID |
// The sample rate.
// @flag TPDC_CALIBRATIONPOINTS_ID |
// The X and Y coordinates used for calibration.
// @flag TPDC_CALIBRATIONDATA_ID |
// The X and Y coordinates used for calibration mapping.
//
// @parm LPVOID | lpOutput |
// Points to the memory location(s) where the queried information
// will be placed. The format of the memory referenced depends on
// the setting of iIndex. If 0, returns the number of words
// required for the output data.
//
// @rdesc
// The return values is set to the amount of information supplied and depends
// on the setting of the iIndex argument.
//
// @comm
// Implemented in the PDD.
//
extern "C"
BOOL
DdsiTouchPanelGetDeviceCaps(
INT iIndex,
LPVOID lpOutput
)
{
DEBUGMSG(1, (TEXT("Touchscreen: DdsiTouchPanelGetDeviceCaps(0x%x)\r\n"), iIndex));
if ( lpOutput == NULL )
{
ERRORMSG(1, (__TEXT("TouchPanelGetDeviceCaps: invalid parameter.\r\n")));
SetLastError(ERROR_INVALID_PARAMETER);
DebugBreak();
return FALSE;
}
switch ( iIndex )
{
case TPDC_SAMPLE_RATE_ID:
{
TPDC_SAMPLE_RATE *pTSR = (TPDC_SAMPLE_RATE*)lpOutput;
pTSR -> SamplesPerSecondLow = TOUCHPANEL_SAMPLE_RATE_LOW;
pTSR -> SamplesPerSecondHigh = TOUCHPANEL_SAMPLE_RATE_HIGH;
pTSR -> CurrentSampleRateSetting = CurrentSampleRateSetting;
}
break;
case TPDC_CALIBRATION_POINT_COUNT_ID:
{
TPDC_CALIBRATION_POINT_COUNT *pTCPC = (TPDC_CALIBRATION_POINT_COUNT*)lpOutput;
pTCPC -> flags = 0;
pTCPC -> cCalibrationPoints = 5;
}
break;
case TPDC_CALIBRATION_POINT_ID:
return(TouchDriverCalibrationPointGet((TPDC_CALIBRATION_POINT*)lpOutput));
default:
ERRORMSG(1, (__TEXT("TouchPanelGetDeviceCaps: invalid parameter.\r\n")));
SetLastError(ERROR_INVALID_PARAMETER);
DebugBreak();
return FALSE;
}
return TRUE;
}
//
// @doc EX_TOUCH_DDSI EXTERNAL DRIVERS DDSI TOUCH_PANEL
//
// @func BOOL | DdsiTouchPanelSetMode |
// Sets information about the physical touch panel device.
//
// @parm ULONG | iIndex |
// Specifies the mode to set. They are one of the following:
//
// @flag TPSM_SAMPLERATE_HIGH_ID |
// Sets the sample rate to the high rate.
// @flag TPSM_SAMPLERATE_LOW_ID |
// Sets the sample rate to the low rate.
//
// @parm LPVOID | lpInput |
// Points to the memory location(s) where the update information
// resides. The format of the memory referenced depends on the
// Points to the memory location(s) where the queried information
// will be placed.
//
// @rdesc
// If the function succeeds the return value is TRUE, otherwise, it is FALSE.
//
// @comm
// Implemented in the PDD.
//
BOOL
DdsiTouchPanelSetMode(
INT iIndex,
LPVOID lpInput
)
{
DEBUGMSG(1, (TEXT("Touchscreen: DdsiTouchPanelSetMode(0x%x)\r\n"), iIndex));
BOOL ReturnCode = FALSE;
switch ( iIndex )
{
case TPSM_SAMPLERATE_LOW_ID:
case TPSM_SAMPLERATE_HIGH_ID:
SetLastError( ERROR_SUCCESS );
ReturnCode = TRUE;
break;
default:
SetLastError( ERROR_INVALID_PARAMETER );
break;
}
return ( ReturnCode );
}
HANDLE hd_9712 = NULL;
HANDLE hMutex = NULL;
#define ENTERMUTEX //WaitForSingleObject(hMutex, INFINITE)
#define RELEASEMUTEX //ReleaseMutex(hMutex)
//
// @doc EX_TOUCH_DDSI EXTERNAL DRIVERS DDSI TOUCH_PANEL
//
// @func BOOL | DdsiTouchPanelEnable |
// Powers up and initializes the touch panel hardware for operation.
//
// @rdesc
// If the function succeeds, the return value is TRUE; otherwise, it is FALSE.
//
// @comm
// Implemented in the PDD.
//
#define TOUCH_SET_4C 5
static BOOL firstFlag =1 ;
BOOL
DdsiTouchPanelEnable(
VOID
)
{
unsigned int data;
DEBUGMSG( TRUE, (TEXT("DdsiTouchPanelEnable\r\n")) );
DEBUGMSG( TRUE, (TEXT("MODULE NAME: %s 1.2\r\n"),part_name) );
DEBUGMSG( TRUE, (TEXT("MODULE VERSION: %s\r\n"),part_num) );
RETAILMSG( 1, (TEXT("Touch Panel Enable\r\n")));
//
// Mapping is required for Timer2
//
PHYSICAL_ADDRESS PhysicalAddress;
PhysicalAddress.HighPart = 0;
PhysicalAddress.LowPart = PHYS_CT2_BASE;
pTimer= (pstDualTimerRegs)MmMapIoSpace(PhysicalAddress, (ULONG)sizeof(stDualTimerRegs),0);
//
// Setup global data
//
#ifdef WAV_DEBUG
#if 0
if(fp == NULL)
{
fp = fopen("\\NandFlash\\touchp.txt", "a+");
}
if(fp)fflush(fp);
#endif
#if 0
if(fp == NULL)
{
fp = fopen("\\touchp.txt", "a+");
fprintf(fp, "damn\n");
}
if(fp)fflush(fp);
#endif
if(hd_9712 == NULL)
{
hd_9712 = CreateFile(L"PWR1:",
GENERIC_READ | GENERIC_WRITE,
0, // comm devices must be opened w/exclusive-access
NULL, // no security attrs
OPEN_EXISTING, // comm devices must use OPEN_EXISTING
FILE_ATTRIBUTE_NORMAL, // overlapped I/O
NULL // hTemplate must be NULL for comm devices
);
}
#endif
for ( unsigned long irg = 0; irg <= (NUMBER_SAMPLES_PER_POINT*REJECT_RATIO); irg+=1 )
{
gQuery[irg] =X_REQUEST;
gQuery[irg+ (NUMBER_SAMPLES_PER_POINT*REJECT_RATIO)] =Y_REQUEST;
}
for (irg=0;irg<PENUP_SAMPLE_REJECT;irg++)
{
iPipe[irg].Flags=TouchSampleIgnore;
}
DEBUGMSG(1, (TEXT("DdsiTouchPanelEnable - TIMER : %2x%2x%2x%2x size:0x%x \r\n"),
pTimer->TimerPeriphID3, pTimer->TimerPeriphID2,
pTimer->TimerPeriphID1, pTimer->TimerPeriphID0, sizeof( stDualTimerRegs) ) );
pTimer->Timer0.Control = 0;
pTimer->Timer0.InterruptClear = 1;
pTimer->Timer0.Control = TimerControlIntEnable | TimerControlPeriodic | TimerControlSize32 | TimerControlOneShot;
pTimer->Timer0.Load = OEM_COUNT_1MS * MS_BETWEEN_READINGS;
// Power on touch panel
TouchPanelPowerOn();
g_evtSignal = CreateEvent(NULL, FALSE, FALSE, szevtUserInput);
/*
// Init SSP control structure.
pSspHead = (PL022 *)(&SspStruc);
PhysicalAddress.HighPart = 0;
PhysicalAddress.LowPart = PHYS_SSP_BASE; //PHYS_SSP_BASE
pSspHead = (PL022 *)MmMapIoSpace( PhysicalAddress, sizeof(PL022), FALSE);
if(pSspHead== NULL)
{
DEBUGMSG(1, (TEXT("GIO_Init: Error SSP MmMapIoSpace failed\r\n")));
return FALSE;
}
else
DEBUGMSG(1, (TEXT("GIO_Init: SSP MmMapIoSpace 0x%x\r\n"), pSspHead));
pSspHead->SSPCR0 = 0x0F27; //*(SSP_BASE + 0x00) = 0x0F27; // SCR[7:0] = f, NS mode, 8-bits/ts
pSspHead->SSPIMSC = 0x0000; //*(SSP_BASE + 0x14) = 0x0000; // interrupt is mask
pSspHead->SSPCPSR = 0x0014; //*(SSP_BASE + 0x10) = 0x0014; // pre-scale : CPSDVSR=20
pSspHead->SSPDMACR = 0x0000; //*(SSP_BASE + 0x24) = 0x0000; // disable Tx&Rx DMA
pSspHead->SSPCR1 = 0x0000; //*(SSP_BASE + 0x04) = 0x0000; // disable SSP
*/
//初始化AACI控制器
PhysicalAddress.HighPart = 0;
PhysicalAddress.LowPart = AACI_BASE;
g_AudioRegBase = (UCHAR *)MmMapIoSpace(PhysicalAddress, AACI_HWREGS_SIZE, FALSE);
if( !g_AudioRegBase )
{
RETAILMSG(1, (TEXT("PDD_TouchPanel: Map AACI hardware registers failed")));
}
if(firstFlag == 1)
{
#ifndef WAV_DEBUG
//配置pendown模式
data = apAACI_ReadRegister(0x4c);
data&=(~0x0008);
apAACI_WriteRegister(0x4c, data);
firstFlag = 0;
#else
if(hd_9712 != INVALID_HANDLE_VALUE)
DeviceIoControl(hd_9712, TOUCH_SET_4C, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
}
// data = apAACI_ReadRegister(0x4c);
// RETAILMSG(1, (TEXT("WMSet0x4c: 0x%.4x\r\n"), data));
data = apAACI_ReadRegister(0x56);
data&=(~0x0008);
apAACI_WriteRegister(0x56, data);
// data = apAACI_ReadRegister(0x56);
// RETAILMSG(1, (TEXT("WMSet0x56: 0x%.4x\r\n"), data));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -