📄 tchpdd.cpp
字号:
// @rdesc
// If the function succeeds, the return value is TRUE; otherwise, it is FALSE.
//
// @comm
// Implemented in the PDD.
//
//****************************************************************************
BOOL DdsiTouchPanelEnable()
{
DEBUGMSG(ZONE_INIT || ZONE_PDD,(TEXT("DdsiTouchPanelEnable\r\n")));
BOOL bReturnValue = TRUE;
HKEY hKey;
//
// Program the Setup register.
//
*TOUCH_TSSETUP = gulSetup =
TSSETUP_NSMP_32 | TSSETUP_DEV_64 |
((128<<TSSETUP_SDLY_SHIFT) & TSSETUP_SDLY_MASK) |
((128<<TSSETUP_DLY_SHIFT) & TSSETUP_DLY_MASK);
//
// Initialize the second program setup register to zero.
//
*TOUCH_TSSETUP2 = TSSETUP2_DEFAULT;
//
// Set the touch settings.
//
*TOUCH_TSSWLOCK = 0xAA;
*TOUCH_TSDIRECT = SWITCH_DISCHARGE;
//
// Set the rest of the touch settings.
//
*TOUCH_TSSWLOCK = 0xAA;
*TOUCH_XSAMPLE = SWITCH_Z1;
*TOUCH_TSSWLOCK = 0xAA;
*TOUCH_YSAMPLE = SWITCH_Z2;
*TOUCH_TSSWLOCK = 0xAA;
*TOUCH_TSDETECT = SWITCH_DETECT;
*TOUCH_TSSWLOCK = 0xAA;
*TOUCH_DISCARGE = SWITCH_DISCHARGE;
// X,YMin set to 0x40 = have to drag that many pixels for a new irq.
// X,YMax set to 0x40 = 1024 pixels is the maximum movement within the
// time scan limit.
//
*TOUCH_TSMAXMIN = ((50 <<TSMAXMIN_XMIN_SHIFT) & TSMAXMIN_XMIN_MASK) |
((50 <<TSMAXMIN_YMIN_SHIFT) & TSMAXMIN_YMIN_MASK) |
((0xFF<<TSMAXMIN_XMAX_SHIFT) & TSMAXMIN_XMAX_MASK) |
((0xFF<<TSMAXMIN_YMAX_SHIFT) & TSMAXMIN_YMAX_MASK);
//
// Callibrate the DDK stall counter.
//
CalibrateStallCounter();
//
// Change the touch screen to interrupt mode.
//
TouchInterruptMode();
RegOpenKeyEx
(
HKEY_LOCAL_MACHINE,
TEXT("\\HARDWARE\\DEVICEMAP\\TOUCH"),
0,
0,
&hKey
);
//
// Read in the registry values.
//
gulMinInvPressure = ReadRegistryValue(hKey, REG_VALUE_MIN_INV_PRESSURE, 0x1500);
gulMaxInvPressure = ReadRegistryValue(hKey, REG_VALUE_MAX_INV_PRESSURE, 0x5000);
gulMaxChange = ReadRegistryValue(hKey, REG_VALUE_MAX_CHANGE, 0x120);
//
// Close the registry key value.
//
RegCloseKey( hKey);
//
// Create an event for sub 1 Millisecond times.
//
ghTimer2Event = CreateEvent(NULL,FALSE, FALSE, NULL);
if(!ghTimer2Event)
{
bReturnValue = FALSE;
}
//
// Allocate timer2.
//
if(bReturnValue)
{
bReturnValue = InterruptInitialize(SYSINTR_TIMER2, ghTimer2Event, NULL, 0);
}
return(bReturnValue);
}
//****************************************************************************
// @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()
{
DEBUGMSG(ZONE_INIT|| ZONE_PDD,(TEXT("DdsiTouchPanelDisable\r\n")));
InterruptDisable( SYSINTR_TIMER2) ;
TouchPollingMode( );
}
//****************************************************************************
//
// @doc EX_TOUCH_DDSI EXTERNAL DRIVERS DDSI TOUCH_PANEL
//
// @func LONG | DdsiTouchPanelAttach |
// This routine no longer does anything. All functionallity has been moved
// from here into DdsiTouchPanelEnable to allow this code to be statically
// linked with GWE rather than existing as a DLL. Technically, when built
// as a DLL we should keep an attach count and only allow touh.dll to be
// loaded once. But, since we are loaded at boot time by GWE, there is
// no real concern about multiple loads (unless gwe has a bug!).
//
// @rdesc
// Always returns 0
//
// @comm
// Implemented in the PDD.
//
//****************************************************************************
LONG DdsiTouchPanelAttach()
{
DEBUGMSG(ZONE_INIT|| ZONE_PDD,(TEXT("DdsiTouchPanelAttach\r\n")));
return(1);
}
//****************************************************************************
//
// @doc EX_TOUCH_DDSI EXTERNAL DRIVERS DDSI TOUCH_PANEL
//
// @func LONG | DdsiTouchPanelDetach |
// See the descrition for attach. All functionallity has been moved into
// DdsiTouchPanelDisable.
//
// @rdesc
// The updated global counter. If the initializations failed, the returned
// count is 0.
//
// @comm
// Implemented in the PDD.
//
//****************************************************************************
LONG DdsiTouchPanelDetach()
{
DEBUGMSG(ZONE_INIT|| ZONE_PDD,(TEXT("DdsiTouchPanelDetach\r\n")));
return(0);
}
//****************************************************************************
//
// @doc EX_TOUCH_DDSI EXTERNAL DRIVERS DDSI TOUCH_PANEL
//
// @func void | DdsiTouchPanelGetPoint |
// Returns the most recently acquired point and its associated tip state
// information.
//
// @parm PDDSI_TOUCHPANEL_TIPSTATE | pTipState |
// Pointer to where the tip state information will be returned.
// @parm PLONG | pUnCalX |
// Pointer to where the x coordinate will be returned.
// @parm PLONG | pUnCalY |
// Pointer to where the y coordinate will be returned.
//
// @comm
// Implmented in the PDD.
//
// Currently the scenario is that we configure the TSPX interrupt for a pen down. On a
// pen down interrupt we start a timer which will interrupt the driver almost 100 times
// a second. At the end of servicing each interrupt we query the status of the pen and
// change the state accordingly.
//****************************************************************************
VOID DdsiTouchPanelGetPoint(TOUCH_PANEL_SAMPLE_FLAGS *pTipStateFlags,INT *pUncalX,INT *pUncalY)
{
//DEBUGMSG(ZONE_POINT || ZONE_PDD,(TEXT("DdsiTouchPanelGetPoint\r\n")));
// static BOOL bPreviousDown = FALSE;
BOOL bPreviousDown = (*pTipStateFlags & TouchSamplePreviousDownFlag);
TouchStruct sTouch;
BOOL bIsTouch;
BOOL bCurrentInterruptMode = gbInterruptMode;
ULONG ulXDiff, ulYDiff;
static ULONG ulUpCount = 0;
ULONG ulInvPressure;
//
// Change to Polling mode.
//
if(gbInterruptMode)
{
TouchPollingMode();
}
//
// Read the touch values and calculate the current pressure.
//
GetTouchValues(&sTouch);
ulInvPressure = CalculateInvPressure(&sTouch);
//
// Check to see if the point is valid. If the resistance is below
// the minimum resistance then the point is probably valid.
//
if( ulInvPressure< gulMinInvPressure)
{
if(bPreviousDown )
{
//
// If the difference between samples is too great, ignore the sample.
//
ulXDiff = abs(gulLastX - sTouch.ulX);
ulYDiff = abs(gulLastY - sTouch.ulY);
if (ulXDiff <gulMaxChange && ulYDiff <gulMaxChange)
{
*pTipStateFlags = TouchSampleValidFlag | TouchSampleDownFlag;
}
else
{
*pTipStateFlags = TouchSampleValidFlag | TouchSampleIgnore;
}
}
else
{
*pTipStateFlags = TouchSampleValidFlag | TouchSampleDownFlag;
}
*pUncalX = sTouch.ulX;
*pUncalY = sTouch.ulY;
gulLastX = sTouch.ulX;
gulLastY = sTouch.ulY;
ulUpCount = 0;
}
//
// If the Resistance is less than the MaxInvPressure but greater than
// the MinInvPressure, disregard the point because it may be
// errouneous.
//
//
else if(ulInvPressure< gulMaxInvPressure)
{
*pTipStateFlags = TouchSampleValidFlag | TouchSampleIgnore;
}
//
// The absence of the down flag means that the user picked up the pen.
//
else if(bPreviousDown)
{
ulUpCount++;
if(ulUpCount<2)
{
*pTipStateFlags = TouchSampleValidFlag | TouchSampleIgnore;
}
else
{
*pTipStateFlags = TouchSampleValidFlag;
TouchInterruptMode();
//
// Set the done interrupt flag.
//
InterruptDone(gIntrTouch);
}
}
//
// Pen was previously up so ignore the sample.
//
else
{
*pTipStateFlags = TouchSampleValidFlag | TouchSampleIgnore;
//
// Go back to Interrupt mode.
//
TouchInterruptMode();
//
// Set the done interrupt flag.
//
InterruptDone(gIntrTouch);
}
}
//****************************************************************************
//
// @func VOID | DdsiTouchPanelPowerHandler |
// System power state notification.
//
// @parm BOOL | bOff | TRUE, the system is powering off; FALSE, the system is powering up.
//
// @comm
// This routine is called in a kernel context and may not make any system
// calls whatsoever. It may read and write its own memory and that's about
// it. This routine is called by the MDD and also serves as an internal
// helper routine for touch enable/disable.
//
// @devnote This routine will run in kernel context, and may not make
// any system calls. If you can any subroutines inside here, make sure
// that they also follow this restriction.
//
//****************************************************************************
void DdsiTouchPanelPowerHandler(BOOL bOff)
{
(bOff);
}
BOOL TouchPanelInitializeCursor()
{
return TRUE;
}
//****************************************************************************
// GetTouchValues
//****************************************************************************
// Gets the X, Y, Z1 and Z2 values from the touch sceen. Z1 and Z2 allow
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -