/*++
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:
Revision History:
--*/
#define DBGPOINTS1 1
#define TRACE_TIP_STATE
#include <windows.h>
#include <types.h>
#include <memory.h>
#include <nkintr.h>
#include <oalintr.h>
#include <tchddsi.h>
#include <tchpdd.h>
#include <drv_glob.h>
//#include <p2debug.h>
#include <S2440.H>
#include "reg.h"
#define SYS_TIMER_PRESCALER PRESCALER
//#define SYS_TIMER_DIVIDER 4 // 2
//#define OEM_CLOCK_FREQ (S2440PCLK / (SYS_TIMER_PRESCALER+1) / SYS_TIMER_DIVIDER)
#define JYLEE_TEST 0
#define JYLEE_TEST1 0
/*for backlight set**/
HANDLE g_evtTSignal;
extern const TCHAR szevtUserInput[] = TEXT("UserInputEvent");
#define ADCMutex 1
#if ADCMutex
static HANDLE ghMutex;
#define BATTERY_FILE_MUTEX TEXT("KeyValue File Mutex") //
#define MUTEX_TIMEOUT 5000
#endif
#define TFT480_272 1
#ifdef LCD_TYPE
#undef LCD_TYPE
#define LCD_TYPE TFT480_272
#endif
//#define TFT240_320 1
//#define TFT640_480 4
//#define LCD_TYPE TFT240_320
//#define LCD_TYPE TFT640_480
#if ( LCD_TYPE == TFT640_480 )
#define ADC_DELAY_TIME 65530
#else
#define ADC_DELAY_TIME 65535//40000 modified by fam 20080709// yhkim
#endif
DWORD gIntrTouch = SYSINTR_TOUCH;
DWORD gIntrTouchChanged = SYSINTR_TOUCH_CHANGED;
#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 void TouchPanelPowerOff();
static void TouchPanelPowerOn();
static BOOL Touch_Timer0_Setup(void) ;
static BOOL Touch_Pen_filtering(INT *px, INT *py);
static void Ave_Touch_Point(INT *px, INT *py , INT *pf);
// 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
// @globalvar PTCHAUD_ASIC_REGISTERS | v_pTchAudAsicRegisters | Pointer to Asic regs
PTCHAUD_ASIC_REGISTERS v_pTchAudAsicRegisters = NULL;
// @globalvar PTOUCHPANEL_POINT_SAMPLE | v_pPenSamples | Pointer to pen samples area
PDRIVER_GLOBALS v_pDriverGlobals = NULL;
volatile static PVOID v_pCpuRegs = NULL;
TOUCH_PANEL_SAMPLE_FLAGS SampleFlags;
#ifdef CHECK_RATE
UINT32 tmp_leds = 0x55;
#endif
// Mutex to prevent contention with audio while accessing shared registers
static HANDLE v_hTchAudMutex;
// Global flag to indicate whether we are in power handler routine, so
// we know to avoid system calls.
static BOOL bInPowerHandler = FALSE;
// Macros for aquiring semaphore for shared access to ASIC registers. If
// we are in the power handler routines, we don't need/want to aquire semaphore,
// since we are serialized at that point, and can't make any system calls.
#define TCHAUD_SEM_LOCK() \
if (!bInPowerHandler) { \
DEBUGMSG(ZONE_TIPSTATE,(TEXT("TchPDD Getting semaphore...\r\n"))); \
TchAudLock(v_hTchAudMutex, &(v_pDriverGlobals->tch.semaphore)); \
}
#define TCHAUD_SEM_UNLOCK() \
if (!bInPowerHandler) { \
DEBUGMSG(ZONE_TIPSTATE,(TEXT("TchPDD Releasing semaphore...\r\n"))); \
TchAudUnlock(v_hTchAudMutex, &(v_pDriverGlobals->tch.semaphore)); \
}
// Macros for accessing registers on the touch audio ASIC. The code for
// these functions is in drvlib so it can be shared between touch and audio.
#define ASIC_READ_REG(reg, pval) \
TchAudReadReg(reg, pval, v_pTchAudAsicRegisters, bInPowerHandler)
#define ASIC_WRITE_REG(reg, val) \
TchAudWriteReg(reg, val, v_pTchAudAsicRegisters, bInPowerHandler)
#define ASIC_AND_REG(reg, val) \
TchAudAndReg(reg, val, v_pTchAudAsicRegisters, bInPowerHandler)
#define ASIC_OR_REG(reg, val) \
TchAudOrReg(reg, val, v_pTchAudAsicRegisters, bInPowerHandler)
volatile IOPreg *v_pIOPregs;
volatile ADCreg *v_pADCregs;
volatile PWMreg *v_pPWMregs;
volatile INTreg *v_pINTregs;
volatile unsigned short xbuf[10], ybuf[10];
static unsigned int touch_down = 1;
//#define ADCPRS 49 // 200Mhz
#define ADCPRS 49 // 200Mhz
//#define ADCPRS 65 // 532Mhz
/*++
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_pIOPregs)
{
VirtualFree((void*)v_pIOPregs, sizeof(IOPreg), MEM_RELEASE);
v_pIOPregs=NULL;
}
if(v_pADCregs)
{
VirtualFree((void*)v_pADCregs, sizeof(ADCreg), MEM_RELEASE);
v_pADCregs = 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