📄 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 DBGPOINTS1 1
#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 "ssp.h"
// Watermark info
const PTCHAR part_name = { TEXT("Touchscreen controller Device Driver ") };
const PTCHAR part_num = { TEXT("OS005-SW-70002-r0p0-00REL0") };
/* Timer definitions - note Timer 0 used by system, timer 1 used by Touchscreen*/
pstDualTimerRegs pTimer=NULL;
// 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);
// 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
static void TouchPanelPowerOff();
static void TouchPanelPowerOn();
// 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;
void SSP_WriteWord(WCHAR num)
{
// DEBUGMSG(1, (_T("SSP_WriteWord\r\n")));
loopcount = LOOP_TIME;
while((pSspHead->SSPSR & 0x02) == 0 && --loopcount);
if (loopcount < LOOP_TIME - 100)
DEBUGMSG(1, (_T("SSP_WriteWord - loopcount 1:%d\r\n"), loopcount));
pSspHead->SSPDR = num;
// DEBUGMSG(1, (_T("SSP_WriteWord - Write\r\n")));
loopcount = LOOP_TIME;
while((pSspHead->SSPSR & 0x10) && --loopcount);
if (loopcount < LOOP_TIME - 100)
DEBUGMSG(1, (_T("SSP_WriteWord - loopcount 2:%d\r\n"), loopcount));
return;
}
void SSP_ReadWord(WCHAR * pnum)
{
// DEBUGMSG(1, (_T("SSP_ReadWord\r\n")));
loopcount = LOOP_TIME;
while((pSspHead->SSPSR & 0x04) == 0 && --loopcount);
if (loopcount < LOOP_TIME - 100)
DEBUGMSG(1, (_T("SSP_ReadWord - loopcount 1:%d\r\n"), loopcount));
*pnum = (WCHAR)(pSspHead->SSPDR);
// DEBUGMSG(1, (_T("SSP_ReadWord - Read\r\n")));
loopcount = LOOP_TIME;
while((pSspHead->SSPSR & 0x10) && --loopcount);
if (loopcount < LOOP_TIME - 100)
DEBUGMSG(1, (_T("SSP_ReadWord - loopcount 2:%d\r\n"), loopcount));
return;
}
/*++
@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.
)
{
// unsigned long iDump;
// gQuery is the same as iReply in length but primed once in the INIT function
WCHAR iReply[sizeof(gQuery)/sizeof(WCHAR)];
DEBUGMSG(1, (TEXT("Touchscreen: PddpTouchPanelGetSamples\r\n")));
pSspHead->SSPCR1 |= apSSP_ENABLE;
for (int i=0; i<sizeof(gQuery)/sizeof(WCHAR); i++)
{
#if 1
SSP_WriteWord(gQuery[i]);
SSP_ReadWord(&(iReply[i]));
#else
iReply[i] = 0x40;
#endif
}
pSspHead->SSPCR1 &= ~apSSP_ENABLE;
// WriteFile(gSsp, &gQuery, sizeof(gQuery), &iDump, NULL); // Write Query then
// Sleep(10);
// ReadFile(gSsp, &iReply, sizeof(iReply), &iDump, NULL); // Read reply, this function will block until all data is read
// Sleep(10);
//
// 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+=1)
{
pPointSamples[ irg ].XSample = (iReply[irg+(NUMBER_SAMPLES_PER_POINT*3)]);
pPointSamples[ irg ].YSample = (iReply[irg+(NUMBER_SAMPLES_PER_POINT*7)]);
}
}
static
BOOL
PddpTouchPanelPenDown()
{
DEBUGMSG(1, (TEXT("Touchscreen: PddpTouchPanelPenDown\r\n")));
/*
OEM_IOCTL_GPIO gpio;
int value;
gpio.num = 6; gpio.pin = 7; gpio.code = GPIO_Read;
value = 0; gpio.value = &value;
KernelIoControl(HAL_IOCTL_GPIO , &gpio , sizeof(OEM_IOCTL_GPIO) , 0 , 0 , 0 );
if (value)
{
DEBUGMSG( 1, (TEXT("PddpTouchPanelPenDown()- Pen UP\r\n")) );
return FALSE;
}
else
{
DEBUGMSG( 1, (TEXT("PddpTouchPanelPenDown()- Pen DOWN\r\n")) );
return TRUE;
}
*/
if (pGpioHead->Padding1[0x7F] & 0x80) //// GPIO_BASE + 0x200
{
DEBUGMSG( 1, (TEXT("PddpTouchPanelPenDown()- Pen UP\r\n")) );
return FALSE;
}
else
{
DEBUGMSG( 1, (TEXT("PddpTouchPanelPenDown()- Pen DOWN\r\n")) );
return TRUE;
}
}
/*++
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;
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 )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -