📄 s3c2410x_touch.cpp
字号:
if (*px < 0) *px = 0;
if (*px >= TSP_LCDX) *px = TSP_LCDX - 1;
if (*py < 0) *py = 0;
if (*py >= TSP_LCDY) *py = TSP_LCDY - 1;
RETAILMSG(1, (TEXT("after change px : %d\r\n"), *px));
RETAILMSG(1, (TEXT("after change py : %d\r\n"), *py));
}
PRIVATE BOOL
TSP_GetXY(INT *px, INT *py)
{
INT i;
INT x, y;
DWORD a = 0, b = 0;
for (i = 0; i < TSP_SAMPLE_NUM; i++)
{
v_pADCregs->ADCTSC = (0 << 8) | /* UD_Sen */
(1 << 7) | /* YMON 1 (YM = GND) */
(1 << 6) | /* nYPON 1 (YP Connected AIN[n]) */
(0 << 5) | /* XMON 0 (XM = Z) */
(1 << 4) | /* nXPON 1 (XP = AIN[7]) */
(1 << 3) | /* Pull Up Enable */
(1 << 2) | /* Auto ADC Conversion Mode */
(0 << 0); /* No Operation Mode */
v_pADCregs->ADCCON |= (1 << 0); /* Start Auto conversion */
while (v_pADCregs->ADCCON & 0x1); /* check if Enable_start is low */
while (!(v_pADCregs->ADCCON & (1 << 15))); /* Check ECFLG */
y = (0x3ff & v_pADCregs->ADCDAT0); /* modified for MagicARM2410 */
x = (0x3ff & v_pADCregs->ADCDAT1);
xbuf[i] = x;
ybuf[i] = y;
//RETAILMSG(1, (TEXT("last (x,y) = (%d, %d)\r\n"), x, y));
//Sleep(1);
}
v_pADCregs->ADCTSC = (1 << 8) | /* UD_Sen */
(1 << 7) | /* YMON 1 (YM = GND) */
(1 << 6) | /* nYPON 1 (YP Connected AIN[n]) */
(0 << 5) | /* XMON 0 (XM = Z) */
(1 << 4) | /* nXPON 1 (XP = AIN[7]) */
(0 << 3) | /* Pull Up Disable */
(0 << 2) | /* Normal ADC Conversion Mode */
(3 << 0); /* Waiting Interrupt */
return TRUE;
}
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
PUBLIC BOOL
DdsiTouchPanelGetDeviceCaps(INT iIndex, LPVOID lpOutput)
{
RETAILMSG(0, (TEXT("::: DdsiTouchPanelGetDeviceCaps\r\n")));
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;
RETAILMSG(0, (TEXT("TouchPanelGetDeviceCaps::TPDC_SAMPLE_RATE_ID\r\n")));
pTSR->SamplesPerSecondLow = TSP_SAMPLE_RATE_LOW;
pTSR->SamplesPerSecondHigh = TSP_SAMPLE_RATE_HIGH;
pTSR->CurrentSampleRateSetting = TSP_CurRate;
}
break;
case TPDC_CALIBRATION_POINT_COUNT_ID:
{
TPDC_CALIBRATION_POINT_COUNT *pTCPC = (TPDC_CALIBRATION_POINT_COUNT*)lpOutput;
RETAILMSG(0, (TEXT("TouchPanelGetDeviceCaps::TPDC_CALIBRATION_POINT_COUNT_ID\r\n")));
pTCPC->flags = 0;
pTCPC->cCalibrationPoints = 5;
}
break;
case TPDC_CALIBRATION_POINT_ID:
RETAILMSG(0, (TEXT("TouchPanelGetDeviceCaps::TPDC_CALIBRATION_POINT_ID\r\n")));
return(TSP_CalibrationPointGet((TPDC_CALIBRATION_POINT*)lpOutput));
default:
ERRORMSG(1, (__TEXT("TouchPanelGetDeviceCaps: invalid parameter.\r\n")));
SetLastError(ERROR_INVALID_PARAMETER);
DebugBreak();
return (FALSE);
}
return (TRUE);
}
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
PUBLIC BOOL
DdsiTouchPanelSetMode(INT iIndex, LPVOID lpInput)
{
BOOL ReturnCode = FALSE;
RETAILMSG(0, (TEXT("::: DdsiTouchPanelSetMode()\r\n")));
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 );
}
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
PUBLIC BOOL
DdsiTouchPanelEnable(VOID)
{
BOOL r;
UINT32 Irq;
PROCESSOR_INFO procInfo;
RETAILMSG(0, (TEXT("::: DdsiTouchPanelEnable()\r\n")));
r = TSP_VirtualAlloc();
// Obtain sysintr values from the OAL for the touch and touch changed interrupts.
//
Irq = IRQ_ADC;
if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &Irq, sizeof(UINT32), &gIntrTouch, sizeof(UINT32), NULL))
{
RETAILMSG(1, (TEXT("ERROR: Failed to request the touch sysintr.\r\n")));
gIntrTouch = SYSINTR_UNDEFINED;
return(FALSE);
}
Irq = IRQ_TIMER3;
if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &Irq, sizeof(UINT32), &gIntrTouchChanged, sizeof(UINT32), NULL))
{
RETAILMSG(1, (TEXT("ERROR: Failed to request the touch changed sysintr.\r\n")));
gIntrTouchChanged = SYSINTR_UNDEFINED;
return(FALSE);
}
// Get the processor's pclk frequency.
//
if (!KernelIoControl(IOCTL_PROCESSOR_INFORMATION, NULL, 0, &procInfo, sizeof(PROCESSOR_INFO), NULL))
{
DEBUGMSG(1, (TEXT("WARNING: Touch driver failed to obtain processor frequency - using default value(%d Hz).\r\n"), g_s3c2410_pclk));
}
else
{
g_s3c2410_pclk = procInfo.dwClockSpeed;
DEBUGMSG(1, (TEXT("INFO: Touch driver using processor frequency reported by the OAL (%d Hz).\r\n"), g_s3c2410_pclk));
}
// Compute the OS timer frequency and number of pen-down sampling ticks.
//
g_timer3_freq = (g_s3c2410_pclk / TIMER3_DIVIDER);
g_timer3_sampleticks = (g_timer3_freq / TSP_SAMPLE_RATE_LOW);
if (r)
{
TSP_PowerOn();
}
return (r);
}
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
PUBLIC VOID
DdsiTouchPanelDisable(VOID)
{
RETAILMSG(0, (TEXT("::: DdsiTouchPanelDisable()\r\n")));
if (v_pADCregs)
{
TSP_PowerOff();
TSP_VirtualFree();
}
}
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
LONG
DdsiTouchPanelAttach(VOID)
{
return(0);
}
LONG
DdsiTouchPanelDetach(VOID)
{
return(0);
}
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
PUBLIC VOID
DdsiTouchPanelPowerHandler(BOOL bOff)
{
RETAILMSG(0, (TEXT("::: DdsiTouchPanelPowerHandler()\r\n")));
if (bOff)
{
TSP_PowerOff();
}
else
{
TSP_PowerOn();
}
}
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
#define NUMBER_SAMPLES_PER_POINT 3
//
// Digitizer related definitions.
//
//
// @doc INTERNAL DRIVERS PDD TOUCH_PANEL
// @const ULONG | DELTA_X_COORD_VARIANCE |
// Maximum allowed variance in the X coordinate samples.
//
#define DELTA_X_COORD_VARIANCE 0x8
//
// @doc INTERNAL DRIVERS PDD TOUCH_PANEL
// @const ULONG | DELTA_Y_COORD_VARIANCE |
// Maximum allowed variance in the X coordinate samples.
//
#define DELTA_Y_COORD_VARIANCE 0x10
typedef struct
{
USHORT XSample; //@field X Coordinate.
USHORT YSample; //@field Y Coordinate.
} TOUCHPANEL_POINT_SAMPLE, *PTOUCHPANEL_POINT_SAMPLE;
typedef TOUCHPANEL_POINT_SAMPLE TOUCHPANEL_POINT_SAMPLES[ NUMBER_SAMPLES_PER_POINT ];
/*++
@doc IN_TOUCH_DDSI INTERNAL DRIVERS PDD TOUCH_PANEL
@func VOID | PddpTouchPanelGetSamples |
Copies from the pen dma area the most recent point sample into the location
pointed to by pPointSamples. During the copy the sample information is
adjusted to be consistent with the 12 bit pen data format.
Has the side effect of reinitializing ioPenPointer if we are near the
end of the pen sample area.
--*/
static
void
PddpTouchPanelGetSamples(
PTOUCHPANEL_POINT_SAMPLE pPointSamples //@PARM Pointer to where the samples will be stored.
)
{
ULONG irg;
//
// Copy the samples to our buffer munging the data for the 12 bit
// pen data format.
//
for ( irg = 0; irg < NUMBER_SAMPLES_PER_POINT; irg++ )
{
pPointSamples[ irg ].XSample = xbuf[irg];
pPointSamples[ irg ].YSample = ybuf[irg];
}
}
/*++
Routine Description:
Gathers the most recent sample and evaluates the sample returing
the determined tip state and the `best guess' for the X and Y coordinates.
Note: Determined empirically that the variance of the X coordinate of the
first sample from all other samples is large enough that in order
to keep the nominal variance small, we discard the first sample.
Cases of a light touch that locks the ADC into
seeing X and Y coordinate samples of 0x277 regardless of how the pen
moves or presses have been seen. XXXXX
Arguments:
pTipState Pointer to where the tip state information will be returned.
pUnCalX Pointer to where the x coordinate will be returned.
pUnCalY Pointer to where the y coordinate will be returned.
Return Value:
None.
Autodoc Information:
@doc IN_TOUCH_DDI INTERNAL DRIVERS PDD TOUCH_PANEL
@func VOID | PddpTouchPanelEvaluateSamples |
Gathers the most recent sample and evaluates the sample returing
the determined tip state and the `best guess' for the X and Y coordinates.
--*/
static
void
PddpTouchPanelEvaluateSamples(
TOUCH_PANEL_SAMPLE_FLAGS *pSampleFlags, //@PARM Pointer to where the tip state information will be returned.
INT *pUncalX, //@PARM Pointer to where the x coordinate will be returned.
INT *pUncalY //@PARM Pointer to where the y coordinate will be returned.
)
{
LONG dlXDiff0;
LONG dlXDiff1;
LONG dlXDiff2;
LONG dlYDiff0;
LONG dlYDiff1;
LONG dlYDiff2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -