📄 tchpdd.cpp
字号:
// when this function is called to protect access to the shared UCB registers.
//
BOOL
PddpSetupPenDownIntr(BOOL EnableIntr)
{
// USHORT intrMask;
// I don't know why we enable the interrupt here.
//
// Setup ADC register
//
// kang code
// Enable Prescaler,Prescaler,AIN5/7 fix,Normal,Disable read start,No operation
// Down,YM:GND,YP:AIN5,XM:Hi-z,XP:AIN7,XP pullup En,Normal,Waiting for interrupt mode
// kang code end
// 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=(1<<3)|(1<<2);
v_pADCregs->rADCDLY = ADC_DELAY_TIME;//default value for delay.
v_pADCregs->rADCCON = (1<<14)|(ADCPRS<<6)|(7<<3); //setup channel, ADCPRS, Touch Input
return TRUE;
}
//
// PddpDisableClearPenDownIntr(void)
//
// Tell the UCB to clear pen down interrupts
//
BOOL
PddpDisableClearPenDownIntr(void)
{
// Acquire semaphore to prevent contention with audio driver while accessing UCB regs
TCHAUD_SEM_LOCK();
// Clear bit 12 in UCB address 3 to disable interrupts on falling tspx (tspx_fal_int)
// Read data from UCB address 0x03
if (! ASIC_AND_REG(3, ~((USHORT)0x1000)))
goto error_return;
// Clear the pen down interrupt
// Write UCB address 4 bit 12 to a 0
if (! ASIC_WRITE_REG(4, 0))
goto error_return;
// Write UCB address 4 bit 12 to a 1, to clear tspx interrupts
if (! ASIC_WRITE_REG(4, 0x1000))
goto error_return;
TCHAUD_SEM_UNLOCK();
return TRUE;
error_return:
RETAILMSG(1,(TEXT("TchPdd: Error accessing UCB register!\r\n")));
TCHAUD_SEM_UNLOCK();
return FALSE;
}
//
// 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
)
{
INT32 cDisplayWidth = pTCP -> cDisplayWidth;
INT32 cDisplayHeight = pTCP -> cDisplayHeight;
int CalibrationRadiusX = cDisplayWidth/20;
int CalibrationRadiusY = cDisplayHeight/20;
switch (pTCP -> PointNumber)
{
case 0:
pTCP -> CalibrationX = cDisplayWidth/2;
pTCP -> CalibrationY = cDisplayHeight/2;
break;
case 1:
pTCP -> CalibrationX = CalibrationRadiusX*2;
pTCP -> CalibrationY = CalibrationRadiusY*2;
break;
case 2:
pTCP -> CalibrationX = CalibrationRadiusX*2;
pTCP -> CalibrationY = cDisplayHeight - CalibrationRadiusY*2;
break;
case 3:
pTCP -> CalibrationX = cDisplayWidth - CalibrationRadiusX*2;
pTCP -> CalibrationY = cDisplayHeight - CalibrationRadiusY*2;
break;
case 4:
pTCP -> CalibrationX = cDisplayWidth - CalibrationRadiusX*2;
pTCP -> CalibrationY = CalibrationRadiusY*2;
break;
default:
pTCP -> CalibrationX = cDisplayWidth/2;
pTCP -> CalibrationY = cDisplayHeight/2;
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
RETAILMSG(0,(TEXT("TouchDriverCalibrationPointGet\r\n")));
RETAILMSG(0,(TEXT("cDisplayWidth : %4X\r\n"),cDisplayWidth));
RETAILMSG(0,(TEXT("cDisplayHeight : %4X\r\n"),cDisplayHeight));
RETAILMSG(0,(TEXT("CalibrationRadiusX : %4d\r\n"),CalibrationRadiusX));
RETAILMSG(0,(TEXT("CalibrationRadiusY : %4d\r\n"),CalibrationRadiusY));
RETAILMSG(0,(TEXT("pTCP -> PointNumber : %4d\r\n"),pTCP -> PointNumber));
RETAILMSG(0,(TEXT("pTCP -> CalibrationX : %4d\r\n"),pTCP -> CalibrationX));
RETAILMSG(0,(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.
//
// @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
)
{
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
)
{
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 );
}
//
// @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.
//
BOOL
DdsiTouchPanelEnable(
VOID
)
{
BOOL Ret;
if(v_pIOPregs == NULL) {
v_pIOPregs = (volatile IOPreg *)
VirtualAlloc(0,sizeof(IOPreg),MEM_RESERVE, PAGE_NOACCESS);
if(v_pIOPregs == NULL) {
ERRORMSG(1,(TEXT("For IOPreg: VirtualAlloc failed!\r\n")));
return (FALSE);
}
else {
if(!VirtualCopy((PVOID)v_pIOPregs,(PVOID)(IOP_BASE),sizeof(IOPreg),
PAGE_READWRITE | PAGE_NOCACHE )) {
ERRORMSG(1,(TEXT("For pIOPregs: VirtualCopy failed!\r\n")));
PddpTouchPanelDeallocateVm();
return (FALSE);
}
}
}
if(v_pADCregs == NULL) {
v_pADCregs = (volatile ADCreg *)
VirtualAlloc(0,sizeof(ADCreg),MEM_RESERVE, PAGE_NOACCESS);
if(v_pADCregs == NULL) {
ERRORMSG(1,(TEXT("For ADCreg: VirtualAlloc failed!\r\n")));
return (FALSE);
}
else {
if(!VirtualCopy((PVOID)v_pADCregs,(PVOID)(ADC_BASE),sizeof(ADCreg),
PAGE_READWRITE | PAGE_NOCACHE )) {
ERRORMSG(1,(TEXT("For pADCregs: VirtualCopy failed!\r\n")));
PddpTouchPanelDeallocateVm();
return (FALSE);
}
}
}
if(v_pPWMregs == NULL) {
v_pPWMregs = (volatile PWMreg *)
VirtualAlloc(0,sizeof(PWMreg),MEM_RESERVE, PAGE_NOACCESS);
if(v_pPWMregs == NULL) {
ERRORMSG(1,(TEXT("For PWMreg: VirtualAlloc failed!\r\n")));
return (FALSE);
}
else {
if(!VirtualCopy((PVOID)v_pPWMregs,(PVOID)(PWM_BASE),sizeof(PWMreg),
PAGE_READWRITE | PAGE_NOCACHE )) {
ERRORMSG(1,(TEXT("For PWMreg: VirtualCopy failed!\r\n")));
return (FALSE);
}
}
}
if(v_pINTregs == NULL) {
v_pINTregs = (volatile INTreg *)
VirtualAlloc(0,sizeof(INTreg),MEM_RESERVE, PAGE_NOACCESS);
if(v_pINTregs == NULL) {
ERRORMSG(1,(TEXT("For INTreg: VirtualAlloc failed!\r\n")));
return (FALSE);
}
else {
if(!VirtualCopy((PVOID)v_pINTregs,(PVOID)(INT_BASE),sizeof(INTreg),
PAGE_READWRITE | PAGE_NOCACHE )) {
ERRORMSG(1,(TEXT("For INTreg: VirtualCopy failed!\r\n")));
return (FALSE);
}
}
}
//
// If the address space of the client process doesn't yet have the
// mapping to the pen dma area; map it. If the mapping fails
// we return FALSE
//
if ( v_pDriverGlobals == NULL )
{
v_pDriverGlobals =
(PDRIVER_GLOBALS)
VirtualAlloc( 0,
DRIVER_GLOBALS_PHYSICAL_MEMORY_SIZE,
MEM_RESERVE,
PAGE_NOACCESS
);
if ( v_pDriverGlobals == NULL )
{
DEBUGMSG( ZONE_ERROR, (TEXT( "TouchPanelEnable: VirtualAlloc failed!\r\n")) );
PddpTouchPanelDeallocateVm();
return ( FALSE );
}
Ret = VirtualCopy( (LPVOID)v_pDriverGlobals,
(LPVOID)DRIVER_GLOBALS_PHYSICAL_MEMORY_START,
DRIVER_GLOBALS_PHYSICAL_MEMORY_SIZE,
PAGE_READWRITE | PAGE_NOCACHE
);
if ( Ret == FALSE )
{
DEBUGMSG( ZONE_ERROR, (TEXT( "TouchPanelEnable: VirtualCopy failed!\r\n")) );
PddpTouchPanelDeallocateVm();
return ( FALSE );
}
}
// Set up mutex for access to shared registers
if ((v_hTchAudMutex = CreateMutex(NULL, FALSE, TCHAUD_MUTEX_NAME)) == NULL) {
DEBUGMSG(ZONE_ERROR, (TEXT("TouchPanelEnable: Error %u in CreateMutex\r\n"),
GetLastError()));
return ( FALSE );
}
// Power on touch panel
TouchPanelPowerOn();
// Setup pen down interrupts, but leave ints disabled until InterruptEnable().
TCHAUD_SEM_LOCK();
PddpSetupPenDownIntr(FALSE);
TCHAUD_SEM_UNLOCK();
return( TRUE ); // we always succeed!!!!!!
}
// @doc EX_TOUCH_DDSI EXTERNAL DRIVERS DDSI TOUCH_PANEL
//
// @func ULONG | DdsiTouchPanelDisable |
// Powers down the touch panel device.
//
// @comm
// Implemented in the PDD.
//
VOID
DdsiTouchPanelDisable(
VOID
)
{
//
// Check pointers in case the enable failed.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -