接上:
extern "C" BOOL DdsiTouchPanelGetDeviceCaps(INT iIndex,LPVOID lpOutput)
{
if (lpOutput == NULL)
{
ERRORMSG(1,(__TEXT("TouchPanelGetDeviceCaps: invalid parameter.\r\n")));
SetLastError(ERROR_INVALID_PARAMETER);
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 = 90;
}
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);
return FALSE;
}
return TRUE;
}
BOOL DdsiTouchPanelSetMode(INT iIndex,LPVOID lpInput)
{
BOOL ReturnCode = FALSE;
RETAILMSG(1,(TEXT("DdsiTouchPanelSetMode(0x%x)\r\n"),iIndex));
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);
}
BOOL AllocTouchPanelRegs()
{
if (v_pICReg == NULL)
{
v_pICReg = (XLLP_INTC_T *) VirtualAllocCopy(0x400, (PVOID)INTC_BASE_U_VIRTUAL);
if (v_pICReg)
{
if (v_pOSTReg == NULL)
{
v_pOSTReg = (XLLP_OST_T *) VirtualAllocCopy(0x400, (PVOID)OST_BASE_U_VIRTUAL);
}
}
}
if (!v_pOSTReg || !v_pICReg )
{
PddpTouchPanelDeallocateVm();
RETAILMSG(1,(TEXT("DdsiTouchPanelEnable(): Error %u\r\n"),GetLastError()));
return (FALSE);
}
return(TRUE);
}
BOOL DdsiTouchPanelEnable()
{
if(AllocTouchPanelRegs())
InitAcLink();
else
return(FALSE);
if ( g_hEventIdle == NULL )
{
g_hEventIdle = CreateEvent(0,FALSE,FALSE,L"_IdleListen_Event_");
}
return Init_Touch_Reg();
}
VOID DdsiTouchPanelDisable()
{
//RETAILMSG(1,(TEXT("DdsiTouchPanelDisable()\r\n")));
PddpTouchPanelDeallocateVm();
DeInitAcLink();
}
LONG DdsiTouchPanelAttach()
{
return(1);
}
LONG DdsiTouchPanelDetach()
{
return(0);
}
BOOL penIsDown()
{
USHORT adcData;
ReadAC97 (0x7A, &adcData);
if(adcData & WM97_DATA_PENDOWN)
return TRUE; // pen down
else
return FALSE; // pen up
}
TOUCH_PANEL_SAMPLE_FLAGS SampleTouchScreen(INT *x,INT *y)
{
unsigned int i;
TOUCH_PANEL_SAMPLE_FLAGS TmpStateFlags;
TOUCHPANEL_POINT_SAMPLES rgPointSamples;
INT TmpX = 0x0FFF;
INT TmpY = 0x0FFF;
for(i=0;i
{
rgPointSamples.XSample = getTouchCoordinate(WM97_ADC_X);
rgPointSamples.YSample = getTouchCoordinate(WM97_ADC_Y);
}
TmpStateFlags = TouchSampleDownFlag;
if (evaluateSample(rgPointSamples[0].XSample,rgPointSamples[1].XSample,rgPointSamples[2].XSample,
DELTA_X_COORD_VARIANCE,&TmpX) == TouchSampleIgnore)
{
TmpStateFlags |= TouchSampleIgnore;
RETAILMSG(1,(TEXT("Invalid X sample\r\n")));
}
else
{
TmpStateFlags |= evaluateSample(rgPointSamples[0].YSample,rgPointSamples[1].YSample,rgPointSamples[2].YSample,
DELTA_Y_COORD_VARIANCE,&TmpY);
}
*y=TmpY;
*x=TmpX;
RETAILMSG(1,(TEXT("Filtered - SampleFlags: 0x%x X: 0x%x Y: 0x%x\r\n"),TmpStateFlags,TmpX,TmpY));
return(TmpStateFlags);
}
VOID DdsiTouchPanelGetPoint(TOUCH_PANEL_SAMPLE_FLAGS *pTipStateFlags,INT *pUncalX,INT *pUncalY)
{
static unsigned int TouchIrq=1;
unsigned InterruptType=SYSINTR_TOUCH;
*pTipStateFlags = TouchSampleIgnore;
if(TouchIrq) // handle pen down irq
{
// add by jiyq, 2008-6-26, for listen idle
if ( g_hEventIdle != NULL )
{
SetEvent(g_hEventIdle);
}
TouchIrq = 0;
InterruptType=SYSINTR_TOUCH;
*pTipStateFlags=SampleTouchScreen(pUncalX,pUncalY);
nextExpectedInterrupt=PEN_UP_OR_TIMER;
}
else // handle timer irq
{
InterruptType=SYSINTR_TOUCH_CHANGED;
*pTipStateFlags=SampleTouchScreen(pUncalX,pUncalY);
nextExpectedInterrupt=PEN_UP_OR_TIMER;
}
if (!penIsDown() && (nextExpectedInterrupt==PEN_UP_OR_TIMER))
{
TouchIrq = 1;
*pTipStateFlags = TouchSampleValidFlag; // send pen up to mdd
nextExpectedInterrupt = PEN_DOWN;
}
PddpEnablePenInterrupt(nextExpectedInterrupt);
InterruptDone(InterruptType);
RETAILMSG(1,(TEXT("x= %x y= %x F=%x\r\n"),*pUncalX,*pUncalY,*pTipStateFlags));
}
BOOL Init_Touch_Reg(void)
{
USHORT tmp;
ReadAC97 (0x7C, &tmp);
if (tmp != 0x574D)
{
RETAILMSG(1,(TEXT("No Found WM97xx Codec\r\n")));
return FALSE;
}
ReadAC97 (0x7E, &tmp);
if (tmp == 0x4C12)
RETAILMSG(1,(TEXT("Found WM9712 Codec\r\n")));
else
{
RETAILMSG(1,(TEXT("Not Found WM9712\r\n")));
return FALSE;
}
ReadAC97 (0x4C, &tmp); //Set GPIO3 for PENDOWN
WriteAC97(0x4C, tmp & ~0x08);
ReadAC97 (0x56, &tmp); //Set GPIO3 for PENDOWN
WriteAC97(0x56, tmp & ~0x08);
ReadAC97 (0x78, &tmp);
tmp |= 0xC000; //set ADC running mode
tmp &= ~0x1000; //set 4-wire touchscreen
WriteAC97(0x78, tmp);
return TRUE;
}
void DdsiTouchPanelPowerHandler(BOOL bOff)
{
AC97PowerHandler(bOff);
if (bOff)
{
// InterruptDone(SYSINTR_TOUCH);
// InterruptDone(SYSINTR_TOUCH_CHANGED);
}
else
{
// nextExpectedInterrupt=PEN_DOWN;
// InterruptDone(SYSINTR_TOUCH);
}
}