tchpdd.cpp
来自「S3C24A0的完整BSP包,对开发此芯片的开发者很有用.」· C++ 代码 · 共 1,273 行 · 第 1/3 页
CPP
1,273 行
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Copyright (c) 2002. Samsung Electronics, co. ltd All rights reserved.
Module Name:
tchpdd.cpp
Abstract:
This module contains the DDSI implementation and PDD support routines
for the touch panel for the P2 implementation.
Functions:
TouchDriverCalibrationPointGet
DdsiTouchPanelGetDeviceCaps
DdsiTouchPanelSetMode
DdsiTouchPanelEnable
DdsiTouchPanelDisable
DdsiTouchPanelAttach
DdsiTouchPanelDetach
DdsiTouchPanelGetPoint
DdsiTouchPanelPowerHandler
Notes:
Touch Screen Device Driver for S3C24A0
jaeyong2.lee@samsung.com
Revision History:
2003/07/03 start
--*/
#define DBGPOINTS1 1
#define TRACE_TIP_STATE
#include <windows.h>
#include <types.h>
#include <memory.h>
#include <nkintr.h>
#include <tchddsi.h>
#include <tchpdd.h>
#include <drv_glob.h>
//#include <bsp.h>
#define TOUCH_TIMER_PRESCALER SYS_TIMER_PRESCALER
#define TOUCH_TIMER_DIVIDER SYS_TIMER_DIVIDER
#define ADCPRS 49
#define JYLEE_TEST1 0
#define TCHPDD_TEST 0
#define TFT240_320 1
#define TFT640_480 4
#define S3C24A0A 1
#define LCD_TYPE TFT240_320 //TFT640_480
#if ( LCD_TYPE == TFT640_480 )
#define ADC_DELAY_TIME 5000
#else
#define ADC_DELAY_TIME 600//1000
#endif
DWORD gIntrTouch = SYSINTR_NOP;
DWORD gIntrTouchChanged = SYSINTR_NOP;
#ifdef TRACE_TIP_STATE
BOOL PenIsUp = TRUE;
#endif
#if defined(MIPS) || defined(PPC821) || defined(PPC823) || defined(ARM) || defined(SH4)
#define PAGE_MASK 0x0fff
#define PAGE_SIZE 0x1000
volatile static PVOID pTmpRegs;
#endif
//Static variables
//
static BOOL bInPowerHandler = FALSE; // Global Flag to indicate in power routine for avoiding system calls
static unsigned int touch_down = 1;
// Static Functions
//
static void TouchPanelPowerOff();
static void TouchPanelPowerOn();
static BOOL Touch_Timer0_Setup(void) ;
static BOOL Touch_Pen_filtering(INT *px, INT *py);
// The MDD requires a minimum of MIN_CAL_COUNT consecutive samples before
// it will return a calibration coordinate to GWE. This value is defined
// in the PDD so that each OEM can control the behaviour of the touch
// panel and still use the Microsoft supplied MDD. Note that the extern "C"
// is required so that the variable name doesn't get decorated, and
// since we have an initializer the 'extern' is actually ignored and
// space is allocated.
extern "C" const int MIN_CAL_COUNT = 40;
INT CurrentSampleRateSetting = 0; // Low sample rate setting
TOUCH_PANEL_SAMPLE_FLAGS SampleFlags;
volatile unsigned short xbuf[10], ybuf[10];
#ifdef CHECK_RATE
UINT32 tmp_leds = 0x55;
#endif
PDRIVER_GLOBALS v_pDriverGlobals = NULL;
volatile S3C24A0_ADC_REG *v_pADCregs;
volatile S3C24A0_PWM_REG *v_pPWMregs;
volatile S3C24A0_INTR_REG *v_pINTregs;
PVOID TSP_RegAlloc(PVOID addr, INT sz)
{
PVOID reg;
reg = (PVOID)VirtualAlloc(0, sz, MEM_RESERVE, PAGE_NOACCESS);
if (reg)
{
if (!VirtualCopy(reg, (PVOID)((UINT32)addr >> 8), sz, PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE ))
{
VirtualFree(reg, sz, MEM_RELEASE);
reg = NULL;
}
}
return reg;
}
/*++
Routine Description:
Deallocates the virtual memory reserved for the Touch/Audio Asic registers,
and the pen samples dma area.
Arguments:
None.
Return Value:
None.
Autodoc Information:
@doc IN_TOUCH_DDSI INTERNAL DRIVERS PDD TOUCH_PANEL
@func VOID | PddpTouchPanelDeallocateVm |
Deallocates the virtual memory reserved for the Touch/Audio Asic registers,
and the pen samples dma area.
--*/
static
void
PddpTouchPanelDeallocateVm(
VOID
)
{
if(v_pADCregs)
{
VirtualFree((void*)v_pADCregs, sizeof(S3C24A0_ADC_REG), MEM_RELEASE);
v_pADCregs = NULL;
}
if(v_pPWMregs)
{
VirtualFree((void*)v_pPWMregs, sizeof(S3C24A0_PWM_REG), MEM_RELEASE);
v_pPWMregs = NULL;
}
if(v_pINTregs)
{
VirtualFree((void*)v_pINTregs, sizeof(S3C24A0_INTR_REG), MEM_RELEASE);
v_pINTregs = NULL;
}
if ( v_pDriverGlobals )
{
VirtualFree( v_pDriverGlobals,
DRIVER_GLOBALS_PHYSICAL_MEMORY_SIZE ,
MEM_RELEASE
);
v_pDriverGlobals = NULL;
}
}
//
// PDD Internal Support Routines
//
/*++
@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 devDrvPointer;
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;
TOUCHPANEL_POINT_SAMPLES rgPointSamples;
//
// Get the sample.
//
PddpTouchPanelGetSamples( rgPointSamples );
//
// Calcuate the differences for the X samples and insure that
// the resulting number is positive.
//
dlXDiff0 = rgPointSamples[ 0 ].XSample - rgPointSamples[ 1 ].XSample;
dlXDiff1 = rgPointSamples[ 1 ].XSample - rgPointSamples[ 2 ].XSample;
dlXDiff2 = rgPointSamples[ 2 ].XSample - rgPointSamples[ 0 ].XSample;
dlXDiff0 = dlXDiff0 > 0 ? dlXDiff0 : -dlXDiff0;
dlXDiff1 = dlXDiff1 > 0 ? dlXDiff1 : -dlXDiff1;
dlXDiff2 = dlXDiff2 > 0 ? dlXDiff2 : -dlXDiff2;
//
// Calcuate the differences for the Y samples and insure that
// the resulting number is positive.
//
dlYDiff0 = rgPointSamples[ 0 ].YSample - rgPointSamples[ 1 ].YSample;
dlYDiff1 = rgPointSamples[ 1 ].YSample - rgPointSamples[ 2 ].YSample;
dlYDiff2 = rgPointSamples[ 2 ].YSample - rgPointSamples[ 0 ].YSample;
dlYDiff0 = dlYDiff0 > 0 ? dlYDiff0 : -dlYDiff0;
dlYDiff1 = dlYDiff1 > 0 ? dlYDiff1 : -dlYDiff1;
dlYDiff2 = dlYDiff2 > 0 ? dlYDiff2 : -dlYDiff2;
//
// The final X coordinate is the average of coordinates of
// the two MIN of the differences.
//
if ( dlXDiff0 < dlXDiff1 )
{
if ( dlXDiff2 < dlXDiff0 )
{
*pUncalX = (ULONG)( ( ( rgPointSamples[ 0 ].XSample + rgPointSamples[ 2 ].XSample ) >> 1 ) );
}
else
{
*pUncalX = (ULONG)( ( ( rgPointSamples[ 0 ].XSample + rgPointSamples[ 1 ].XSample ) >> 1 ) );
}
}
else if ( dlXDiff2 < dlXDiff1 )
{
*pUncalX = (ULONG)( ( ( rgPointSamples[ 0 ].XSample + rgPointSamples[ 2 ].XSample ) >> 1 ) );
}
else
{
*pUncalX = (ULONG)( ( ( rgPointSamples[ 1 ].XSample + rgPointSamples[ 2 ].XSample ) >> 1 ) );
}
//
//
// The final Y coordinate is the average of coordinates of
// the two MIN of the differences.
//
if ( dlYDiff0 < dlYDiff1 )
{
if ( dlYDiff2 < dlYDiff0 )
{
*pUncalY = (ULONG)( ( ( rgPointSamples[ 0 ].YSample + rgPointSamples[ 2 ].YSample ) >> 1 ) );
}
else
{
*pUncalY = (ULONG)( ( ( rgPointSamples[ 0 ].YSample + rgPointSamples[ 1 ].YSample ) >> 1 ) );
}
}
else if ( dlYDiff2 < dlYDiff1 )
{
*pUncalY = (ULONG)( ( ( rgPointSamples[ 0 ].YSample + rgPointSamples[ 2 ].YSample ) >> 1 ) );
}
else
{
*pUncalY = (ULONG)( ( ( rgPointSamples[ 1 ].YSample + rgPointSamples[ 2 ].YSample ) >> 1 ) );
}
//
// Validate the coordinates and set the tip state accordingly.
//
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( ZONE_SAMPLES, (TEXT("Sample 0: X 0x%x Y 0x%x\r\n"),
rgPointSamples[ 0 ].XSample, rgPointSamples[ 0 ].YSample) );
DEBUGMSG( ZONE_SAMPLES, (TEXT("Sample 1: X 0x%x Y 0x%x\r\n"),
rgPointSamples[ 1 ].XSample, rgPointSamples[ 1 ].YSample) );
DEBUGMSG( ZONE_SAMPLES, (TEXT("Sample 2: X 0x%x Y 0x%x\r\n"),
rgPointSamples[ 2 ].XSample, rgPointSamples[ 2 ].YSample) );
if ( dlXDiff0 > DELTA_X_COORD_VARIANCE )
DEBUGMSG( ZONE_SAMPLES, (TEXT("XDiff0 too large 0x%x\r\n"), dlXDiff0) );
if ( dlXDiff1 > DELTA_X_COORD_VARIANCE )
DEBUGMSG( ZONE_SAMPLES, (TEXT("XDiff1 too large 0x%x\r\n"), dlXDiff1) );
if ( dlXDiff2 > DELTA_X_COORD_VARIANCE )
DEBUGMSG( ZONE_SAMPLES, (TEXT("XDiff2 too large 0x%x\r\n"), dlXDiff2) );
if ( dlYDiff0 > DELTA_Y_COORD_VARIANCE )
DEBUGMSG( ZONE_SAMPLES, (TEXT("YDiff0 too large 0x%x\r\n"), dlYDiff0) );
if ( dlYDiff1 > DELTA_Y_COORD_VARIANCE )
DEBUGMSG( ZONE_SAMPLES, (TEXT("YDiff1 too large 0x%x\r\n"), dlYDiff1) );
if ( dlYDiff2 > DELTA_Y_COORD_VARIANCE )
DEBUGMSG( ZONE_SAMPLES, (TEXT("YDiff2 too large 0x%x\r\n"), dlYDiff2) );
//#endif // DBGPOINTS1
}
else
{
//
// Sample is valid. Set tip state accordingly.
//
*pSampleFlags = TouchSampleValidFlag | TouchSampleDownFlag;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?