📄 s3c2410x_touch.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++
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:
Abstract:
Platform dependent TOUCH initialization functions
rev:
2002.4.27 : S3C2410 port (Hoyjoon Kim)
Notes:
--*/
#include <windows.h>
#include <types.h>
#include <memory.h>
#include <nkintr.h>
#include <tchddsi.h>
#include <nkintr.h>
#include <s3c2410x.h>
#define PUBLIC
#define PRIVATE static
// OS Timer 3 is used to sample points while the pen is down.
// Timer frequency is 1/2 * PCLK with 0 prescale value.
//
#define TIMER3_DIVIDER 2
#define TIMER3_PRESCALE 0
#define TSP_SAMPLE_NUM 4
#define TSP_SAMPLE_RATE_LOW 100
#define TSP_SAMPLE_RATE_HIGH 100
#define ADCPRS 200
#define TSP_MINX 85
#define TSP_MINY 105
#define TSP_MAXX 965
#define TSP_MAXY 980
#define TSP_CHANGE 15
#define TSP_INVALIDLIMIT 40
#define TSP_LCDX (LCD_XSIZE_TFT * 4)
#define TSP_LCDY (LCD_YSIZE_TFT * 4)
DWORD gIntrTouch = SYSINTR_NOP;
DWORD gIntrTouchChanged = SYSINTR_NOP;
// Default S3C2410x PCLK frequency. We try to obtain the actual value from
// the OAL (via an IOCTL) during initialization. FCLK is typically 203MHz
// and the typical PCLK divisor is 4.
//
UINT32 g_s3c2410_pclk = (203000000 / 4);
// Timer 3 clock frequency.
//
UINT32 g_timer3_freq = 0;
// Number of Timer 3 ticks in a pen-down sampling interval.
//
UINT32 g_timer3_sampleticks = 0;
extern "C" const int MIN_CAL_COUNT = 1;
PRIVATE INT TSP_CurRate = TSP_SAMPLE_RATE_HIGH;
PRIVATE volatile S3C2410X_IOPORT_REG * v_pIOPregs;
PRIVATE volatile S3C2410X_ADC_REG * v_pADCregs;
PRIVATE volatile S3C2410X_INTR_REG * v_pINTregs;
PRIVATE volatile S3C2410X_PWM_REG * v_pPWMregs;
PRIVATE BOOL bTSP_DownFlag;
VOID TSP_VirtualFree(VOID);
BOOL TSP_VirtualAlloc(VOID);
PRIVATE 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, 0, MEM_RELEASE);
reg = NULL;
}
}
return (reg);
}
PRIVATE BOOL
TSP_VirtualAlloc(VOID)
{
BOOL r = FALSE;
RETAILMSG(0,(TEXT("::: TSP_VirtualAlloc()\r\n")));
do
{
v_pIOPregs = (volatile S3C2410X_IOPORT_REG *)TSP_RegAlloc((PVOID)S3C2410X_BASE_REG_PA_IOPORT, sizeof(S3C2410X_IOPORT_REG));
if (v_pIOPregs == NULL)
{
ERRORMSG(1,(TEXT("For IOPreg: VirtualAlloc failed!\r\n")));
break;
}
v_pADCregs = (volatile S3C2410X_ADC_REG *)TSP_RegAlloc((PVOID)S3C2410X_BASE_REG_PA_ADC, sizeof(S3C2410X_ADC_REG));
if (v_pADCregs == NULL)
{
ERRORMSG(1,(TEXT("For ADCreg: VirtualAlloc failed!\r\n")));
break;
}
v_pINTregs = (volatile S3C2410X_INTR_REG *)TSP_RegAlloc((PVOID)S3C2410X_BASE_REG_PA_INTR, sizeof(S3C2410X_INTR_REG));
if (v_pADCregs == NULL)
{
ERRORMSG(1,(TEXT("For INTregs: VirtualAlloc failed!\r\n")));
break;
}
v_pPWMregs = (volatile S3C2410X_PWM_REG *)TSP_RegAlloc((PVOID)S3C2410X_BASE_REG_PA_PWM, sizeof(S3C2410X_PWM_REG));
if (v_pPWMregs == NULL)
{
ERRORMSG(1,(TEXT("For PWMregs: VirtualAlloc failed!\r\n")));
break;
}
r = TRUE;
} while (0);
if (!r)
{
TSP_VirtualFree();
RETAILMSG(0,(TEXT("::: TSP_VirtualAlloc() - Fail\r\n")));
}
else
{
RETAILMSG(0,(TEXT("::: TSP_VirtualAlloc() - Success\r\n")));
}
return (r);
}
PRIVATE void
TSP_VirtualFree(VOID)
{
RETAILMSG(0,(TEXT("::: TSP_VirtualFree()\r\n")));
if (v_pIOPregs)
{
VirtualFree((PVOID)v_pIOPregs, 0, MEM_RELEASE);
v_pIOPregs = NULL;
}
if (v_pADCregs)
{
VirtualFree((PVOID)v_pADCregs, 0, MEM_RELEASE);
v_pADCregs = NULL;
}
if (v_pINTregs)
{
VirtualFree((PVOID)v_pINTregs, 0, MEM_RELEASE);
v_pINTregs = NULL;
}
if (v_pPWMregs)
{
VirtualFree((PVOID)v_pPWMregs, 0, MEM_RELEASE);
v_pPWMregs = NULL;
}
}
PRIVATE VOID
TSP_SampleStart(VOID)
{
DWORD tmp;
tmp = v_pPWMregs->TCON & (~(0xf << 16));
v_pPWMregs->TCON = tmp | (2 << 16); /* update TCVNTB3, stop */
v_pPWMregs->TCON = tmp | (9 << 16); /* interval mode, start */
}
PRIVATE VOID
TSP_SampleStop(VOID)
{
v_pPWMregs->TCON &= ~(1 << 16); /* Timer3, stop */
}
PRIVATE VOID
TSP_PowerOn(VOID)
{
RETAILMSG(0,(TEXT("::: TSP_PowerOn()\r\n")));
/* Use TSXM, TSXP, TSYM, TSYP */
v_pIOPregs->GPGCON |= ((0x3 << 30) | (0x3 << 28) | (0x3 << 26) | (0x3 << 24));
v_pADCregs->ADCDLY = 50000;
v_pADCregs->ADCCON = (1 << 14) | /* A/D Converter Enable */
(ADCPRS << 6) | /* Prescaler Setting */
(0 << 3) | /* Analog Input Channel : 0 */
(0 << 2) | /* Normal Operation Mode */
(0 << 1) | /* Disable Read Start */
(0 << 0); /* No Operation */
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]) */
(0 << 3) | /* Pull Up Disable */
(0 << 2) | /* Normal ADC Conversion Mode */
(3 << 0); /* Waiting Interrupt */
v_pINTregs->INTSUBMSK &= ~(1<<IRQ_SUB_TC);
v_pPWMregs->TCFG1 &= ~(0xf << 12); /* Timer3's Divider Value */
v_pPWMregs->TCFG1 |= (0 << 12); /* 1/2 */
v_pPWMregs->TCNTB3 = g_timer3_sampleticks; /* Interrupt Frequency */
}
PRIVATE VOID
TSP_PowerOff(VOID)
{
RETAILMSG(0,(TEXT("::: TSP_PowerOff()\r\n")));
v_pINTregs->INTSUBMSK |= (1<<IRQ_SUB_TC);
}
PRIVATE BOOL
TSP_CalibrationPointGet(TPDC_CALIBRATION_POINT *pTCP)
{
INT32 cDisplayWidth = pTCP->cDisplayWidth;
INT32 cDisplayHeight = pTCP->cDisplayHeight;
int CalibrationRadiusX = cDisplayWidth / 20;
int CalibrationRadiusY = cDisplayHeight / 20;
switch (pTCP -> PointNumber)
{
case 0:
pTCP->CalibrationX = cDisplayWidth / 2;
pTCP->CalibrationY = cDisplayHeight / 2;
break;
case 1:
pTCP->CalibrationX = CalibrationRadiusX * 2;
pTCP->CalibrationY = CalibrationRadiusY * 2;
break;
case 2:
pTCP->CalibrationX = CalibrationRadiusX * 2;
pTCP->CalibrationY = cDisplayHeight - CalibrationRadiusY * 2;
break;
case 3:
pTCP->CalibrationX = cDisplayWidth - CalibrationRadiusX * 2;
pTCP->CalibrationY = cDisplayHeight - CalibrationRadiusY * 2;
break;
case 4:
pTCP->CalibrationX = cDisplayWidth - CalibrationRadiusX * 2;
pTCP->CalibrationY = CalibrationRadiusY * 2;
break;
default:
pTCP->CalibrationX = cDisplayWidth / 2;
pTCP->CalibrationY = cDisplayHeight / 2;
SetLastError(ERROR_INVALID_PARAMETER);
return (FALSE);
}
RETAILMSG(0, (TEXT("::: TSP_CalibrationPointGet()\r\n")));
RETAILMSG(0, (TEXT("cDisplayWidth : %4X\r\n"), cDisplayWidth ));
RETAILMSG(0, (TEXT("cDisplayHeight : %4X\r\n"), cDisplayHeight ));
RETAILMSG(0, (TEXT("CalibrationRadiusX : %4d\r\n"), CalibrationRadiusX));
RETAILMSG(0, (TEXT("CalibrationRadiusY : %4d\r\n"), CalibrationRadiusY));
RETAILMSG(0, (TEXT("pTCP -> PointNumber : %4d\r\n"), pTCP->PointNumber));
RETAILMSG(0, (TEXT("pTCP -> CalibrationX : %4d\r\n"), pTCP->CalibrationX));
RETAILMSG(0, (TEXT("pTCP -> CalibrationY : %4d\r\n"), pTCP->CalibrationY));
return (TRUE);
}
PRIVATE void
TSP_TransXY(INT *px, INT *py)
{
*px = (*px - TSP_MINX) * TSP_LCDX / (TSP_MAXX - TSP_MINX);
*py = (*py - TSP_MINY) * TSP_LCDY / (TSP_MAXY - TSP_MINY);
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;
}
PRIVATE BOOL
TSP_GetXY(INT *px, INT *py)
{
INT i;
INT xsum, ysum;
INT x, y;
INT dx, dy;
xsum = ysum = 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) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -