📄 tchpdd.cpp
字号:
/*++
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) 1995-2000 Microsoft Corporation. All rights reserved.
Release Status:OS005-SW-70002-r0p0-00REL0
$Copyright:
----------------------------------------------------------------
This confidential and proprietary software may be used only as
authorised by a licensing agreement from ARM Limited
(C) COPYRIGHT 2004 ARM Limited
ALL RIGHTS RESERVED
The entire notice above must be reproduced on all authorised
copies and copies may only be made to the extent permitted
by a licensing agreement from ARM Limited.
----------------------------------------------------------------
File: TCHPDD.CPP,v
Revision: 1.2
----------------------------------------------------------------
$
Module Name:
tchpdd.cpp
Abstract:
This module contains the DDSI implementation and PDD support routines
for the touch panel for the ARM implementation.
Functions:
TouchDriverCalibrationPointGet
DdsiTouchPanelGetDeviceCaps
DdsiTouchPanelSetMode
DdsiTouchPanelEnable
DdsiTouchPanelDisable
DdsiTouchPanelAttach
DdsiTouchPanelDetach
DdsiTouchPanelGetPoint
DdsiTouchPanelPowerHandler
Notes:
If DBGPOINTS1 is defined during compilation, information about
raw point samples will be displayed.
Revision History:
x
John Lindquist (Intergraph) 7/2/95
Larry Morris (Rho) 9/22/95
Killian Murphy (Eclipse TG) 7/31/96 (for P2 platform)
--*/
#define HIVE
//#define DBGPOINTS1 1
#define DBGPOINTS1 0
#define TRACE_TIP_STATE
#include <windows.h>
#include <types.h>
#include <memory.h>
#include <nkintr.h>
#include <tchddsi.h>
#include <reg.h>
#include <tchpdd.h>
#include <nkintr.h>
#include <oalintr.h>
#include <ceddk.h>
#include <gpio.h>
#include <dma.h>
#include <pkfuncs.h>
#include <oalfuncs.h>
#include "OalIntr.h"
#include <platform.h>
#include <sp804.h> // Timers
#include "gpiodrv.h"
#include "wm9712.h"
//#include "ssp.h"
#ifndef HIVE
#include "..\TouchRegManage\TouchReg.h"
#endif
// Watermark info
const PTCHAR part_name = { TEXT("Touchscreen controller Device Driver ") };
const PTCHAR part_num = { TEXT("OS005-SW-70002-r0p0-00REL0") };
const TCHAR szevtUserInput[] = TEXT("UserInputEvent");
/* Timer definitions - note Timer 0 used by system, timer 1 used by Touchscreen*/
pstDualTimerRegs pTimer=NULL;
HANDLE g_evtSignal;
// Information for the MDD layer
unsigned long gIntrTouch = SYSINTR_TIMER2; // Our Timer interupt
unsigned long gIntrTouchChanged = SYSINTR_TOUCH; // Our TouchP interupt
// The TouchPanel event handle from the MDD layer, we are going to replace it with
// our own event handle that utilises our GPIO layer
extern "C" extern HANDLE hTouchPanelEvent;
// SSP Stuff
//HANDLE gSsp; // SSP Handle
GPIO_REGS GpioStruc;
PGPIO_REGS pGpioHead = (PGPIO_REGS)(&GpioStruc); // GPIO Handle
//PL022 SspStruc;
//PL022 * pSspHead = (PL022 *)(&SspStruc);
FILE *fp = NULL;
#define WAV_DEBUG
// Internal Structures used in the drivers
WCHAR gQuery[(NUMBER_SAMPLES_PER_POINT*REJECT_RATIO*2)];
static SAMPLE iPipe [PENUP_SAMPLE_REJECT];
#ifdef TRACE_TIP_STATE
BOOL PenIsUp = TRUE;
#endif
#define READPOINTTIMES 5
#define FLAGSEPARATOR 4
static void TouchPanelPowerOff();
static void TouchPanelPowerOn();
//static BYTE *g_AudioRegBase = NULL;// Pointer to memory mapped AACI regs.
UCHAR *g_AudioRegBase = NULL;
static int apAACI_ReadRegister(volatile int reg);
static int apAACI_WriteRegister(volatile int reg, int value);
//static int FinishAD(void);
void udelay(unsigned int msec);
// 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 = 20;
INT CurrentSampleRateSetting = 0; // Low sample rate setting
TOUCH_PANEL_SAMPLE_FLAGS SampleFlags;
static void
PddpTouchPanelDeallocateVm( VOID )
{
if (pTimer)
{
MmUnmapIoSpace (pTimer, sizeof (pstDualTimerRegs));
pTimer=NULL;
}
}
#define LOOP_TIME 10000
int loopcount;
#define WM9712_WRITE 1
#define WM9712_READ 0
typedef struct
{
USHORT reg;
USHORT data;
} PARA, *pPARA;
#if 0
/*++
@doc IN_TOUCH_DDSI INTERNAL DRIVERS PDD TOUCH_PANEL
@func VOID | PddpTouchPanelGetSamples |
Uses SSP Driver setup elsewhere to get touchscreen info from ADS
--*/
static
void
PddpTouchPanelGetSamples(
PTOUCHPANEL_POINT_SAMPLE pPointSamples //@PARM Pointer to where the samples will be stored.
)
{
int times;
// gQuery is the same as iReply in length but primed once in the INIT function
WCHAR iReplyX[sizeof(gQuery)/sizeof(WCHAR)];
WCHAR iReplyY[sizeof(gQuery)/sizeof(WCHAR)];
if(!g_AudioRegBase)return;
/*Use AC-link*/
//读x值
apAACI_WriteRegister(0x76, 0x9006); /*x 轴测量set 8k sample rate */
udelay(100); // wait charge of x axis
for (int i=0; i<REJECT_RATIO; i++)
{
times = 3*READPOINTTIMES;
while((apAACI_ReadRegister(0x76)&0x8000) && times--);
#if 1
if(times==0){
iReplyX[i] = 0;
if(fp)fprintf(fp, "6");
continue;
}
#endif
times = READPOINTTIMES;
while((!(iReplyX[i] = apAACI_ReadRegister(0x7a)&0x0fff)) && times--);
if(times==0){
iReplyX[i] = 0;
if(fp)fprintf(fp, "5");
continue;
}
}
//读y值
apAACI_WriteRegister(0x76, 0xa006); /* y轴测量 */
udelay(100); // wait charge of x axis
for (int i=0; i<REJECT_RATIO; i++)
{
times = 3*READPOINTTIMES;
while((apAACI_ReadRegister(0x76)&0x8000) && times--);
#if 1
if(times==0){
iReplyY[i] = 0;
continue;
}
#endif
times = READPOINTTIMES;
while((!(iReplyY[i] = apAACI_ReadRegister(0x7a)&0x0fff)) && times--);
if(times==0)
{
iReplyY[i] = 0;
}
}
//
// Due to the ADC Charge functions, discard most of the data
// Return 3 XY samples (which are then checked for consistancy)
//
for (unsigned long irg = 0; irg < NUMBER_SAMPLES_PER_POINT; irg++)
{
pPointSamples[ irg ].XSample = (iReplyX[irg+(REJECT_RATIO-NUMBER_SAMPLES_PER_POINT)]); //取最后几个点
pPointSamples[ irg ].YSample = (iReplyY[irg+(REJECT_RATIO-NUMBER_SAMPLES_PER_POINT)]); //取最后几个点
// DEBUGMSG(1, (TEXT("Touchscreen: PddpTouchPanelEvaluateSamples\r\n")));
}
}
#endif
/*++
@doc IN_TOUCH_DDSI INTERNAL DRIVERS PDD TOUCH_PANEL
@func VOID | PddpTouchPanelGetSamples |
Uses SSP Driver setup elsewhere to get touchscreen info from ADS
--*/
static
void
PddpTouchPanelGetSamples(
PTOUCHPANEL_POINT_SAMPLE pPointSamples //@PARM Pointer to where the samples will be stored.
)
{
int times;
// gQuery is the same as iReply in length but primed once in the INIT function
WCHAR iReplyX[sizeof(gQuery)/sizeof(WCHAR)];
WCHAR iReplyY[sizeof(gQuery)/sizeof(WCHAR)];
WCHAR temp;
if(!g_AudioRegBase)return;
for (int i=0; i<REJECT_RATIO; i++)
{
/*Use AC-link*/
//读x值
apAACI_WriteRegister(0x76, 0x9006);
times = READPOINTTIMES;
while((apAACI_ReadRegister(0x76)&0x8000) && times--);
if(times==0){
iReplyX[i] = 0;
continue;
}
times = READPOINTTIMES;
while((!(iReplyX[i] = apAACI_ReadRegister(0x7a)&0x0fff)) && times--);
if(times==0){
iReplyX[i] = 0;
continue;
}
//读y值
apAACI_WriteRegister(0x76, 0xa006);
times = READPOINTTIMES;
while((apAACI_ReadRegister(0x76)&0x8000) && times--);
if(times==0){
iReplyY[i] = 0;
continue;
}
times = READPOINTTIMES;
while((!(iReplyY[i] = apAACI_ReadRegister(0x7a)&0x0fff)) && times--);
if(times==0)iReplyY[i] = 0;
//RETAILMSG(1, (TEXT("iReplyX[%d] = %d, iReplyY[%d] = %d\r\n"), i, iReplyX[i], i, iReplyY[i]));
//yz_add_for_new_dev_tp_070705
temp = iReplyX[i];
iReplyX[i] = iReplyY[i];
//iReplyY[i] = temp;
iReplyY[i] = 0xfff - temp;
}
//
// Due to the ADC Charge functions, discard most of the data
// Return 3 XY samples (which are then checked for consistancy)
//
for (unsigned long irg = 0; irg < NUMBER_SAMPLES_PER_POINT; irg++)
{
pPointSamples[ irg ].XSample = (iReplyX[irg+(REJECT_RATIO-NUMBER_SAMPLES_PER_POINT)]); //取最后几个点
pPointSamples[ irg ].YSample = (iReplyY[irg+(REJECT_RATIO-NUMBER_SAMPLES_PER_POINT)]); //取最后几个点
DEBUGMSG(1, (TEXT("Touchscreen: PddpTouchPanelEvaluateSamples\r\n")));
}
}
static
BOOL
PddpTouchPanelPenDown()
{
// DEBUGMSG(1, (TEXT("Touchscreen: PddpTouchPanelPenDown\r\n")));
// static unsigned char first=1;
if (pGpioHead->Padding1[254] & 0x01) //// GPIO_BASE + 0x200
{
/* if(first){
udelay(15000);
first = 0;
}
DEBUGMSG( 1, (TEXT("PddpTouchPanelPenDown()- Pen DOWN\r\n")) );
*/ return TRUE;
}
else
{
// first = 1;
// DEBUGMSG( 1, (TEXT("PddpTouchPanelPenDown()- Pen UP\r\n")) );
return FALSE;
}
}
/*++
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;
static LONG dUncalX = 100;
static LONG dUncalY = 100;
TOUCHPANEL_POINT_SAMPLES rgPointSamples;
// DEBUGMSG(1, (TEXT("Touchscreen: PddpTouchPanelEvaluateSamples\r\n")));
//
// 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.
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -