📄 s3c2443_touch.cpp.old2
字号:
//
// 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) 2005. Samsung Electronics, co. ltd All rights reserved.
Module Name:
Abstract:
Platform dependent TOUCH initialization functions
rev:
2004.4.27 : S3C2440 port (Hoyjoon Kim)
2005.05.23 : Magneto porting revision (junkim)
2006.06.29 : S3C2443 port(JJG)
Notes:
--*/
#include <windows.h>
#include <types.h>
#include <memory.h>
#include <nkintr.h>
#include <tchddsi.h>
#include <nkintr.h>
#include <s3c2443.h>
#include <bsp_cfg.h>
#define PUBLIC
#define PRIVATE static
#define TSP_SAMPLE_RATE_LOW 50
#define TSP_SAMPLE_RATE_HIGH 100
#define TSP_SAMPLETICK_LOW (102*1000/ TSP_SAMPLE_RATE_LOW - 1) //(100 * 1000 / TSP_SAMPLE_RATE_LOW)
#define TSP_SAMPLETICK_HIGH (102*1000/ TSP_SAMPLE_RATE_HIGH - 1) // 1020 = PCLK/PRESCALE(=250)/DIV3(=2)/1000(1SEC)*(1000/100) //(100 * 1000 / TSP_SAMPLE_RATE_HIGH)
#define ADCPRS 49 // 200
#define TS_DBGON 0
#define TSP_MINX 71 //105 //85
#define TSP_MINY 78 //70 //105
#define TSP_MAXX 942 //910 //965
#define TSP_MAXY 928 // 940 //980
#define TSP_CHANGE 15
#define TSP_INVALIDLIMIT 40
#define TSP_LCDX (LCD_XSIZE_TFT * 4)
#define TSP_LCDY (LCD_YSIZE_TFT * 4)
#define TSP_SAMPLE_NUM 4
#ifndef OAL_INTR_FORCE_STATIC
#define OAL_INTR_FORCE_STATIC (1 << 2)
#endif
DWORD gIntrTouch = SYSINTR_NOP;
DWORD gIntrTouchChanged = SYSINTR_NOP;
extern "C" const int MIN_CAL_COUNT = 1;
PRIVATE INT TSP_CurRate = 1;
static BOOL Touch_Pen_Filtering(INT *px, INT *py);
PRIVATE volatile S3C2443_IOPORT_REG * v_pIOPregs;
PRIVATE volatile S3C2443_ADC_REG * v_pADCregs;
PRIVATE volatile S3C2443_INTR_REG * v_pINTregs;
PRIVATE volatile S3C2443_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 S3C2443_IOPORT_REG *)TSP_RegAlloc((PVOID)S3C2443_BASE_REG_PA_IOPORT, sizeof(S3C2443_IOPORT_REG));
if (v_pIOPregs == NULL)
{
ERRORMSG(1,(TEXT("For IOPreg: VirtualAlloc failed!\r\n")));
break;
}
v_pADCregs = (volatile S3C2443_ADC_REG *)TSP_RegAlloc((PVOID)S3C2443_BASE_REG_PA_ADC, sizeof(S3C2443_ADC_REG));
if (v_pADCregs == NULL)
{
ERRORMSG(1,(TEXT("For ADCreg: VirtualAlloc failed!\r\n")));
break;
}
v_pINTregs = (volatile S3C2443_INTR_REG *)TSP_RegAlloc((PVOID)S3C2443_BASE_REG_PA_INTR, sizeof(S3C2443_INTR_REG));
if (v_pADCregs == NULL)
{
ERRORMSG(1,(TEXT("For INTregs: VirtualAlloc failed!\r\n")));
break;
}
v_pPWMregs = (volatile S3C2443_PWM_REG *)TSP_RegAlloc((PVOID)S3C2443_BASE_REG_PA_PWM, sizeof(S3C2443_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 */
// v_pPWMregs->TCON = tmp | (1 << 16); /* one-shot mode, start */
}
PRIVATE VOID
TSP_SampleStop(VOID)
{
v_pPWMregs->TCON &= ~(1 << 16); /* Timer3, stop */
}
PRIVATE VOID
TSP_PowerOn(VOID)
{
RETAILMSG(TS_DBGON,(TEXT("::: TSP_PowerOn()\r\n")));
RETAILMSG(TS_DBGON,(TEXT("Touch::ADCPRS=%d\r\n"),ADCPRS));
v_pADCregs->ADCDLY = 40000;
v_pADCregs->ADCCON = (1<<14) | (ADCPRS<< 6) | (7<<3);
v_pADCregs->ADCTSC = (0<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3);
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 = TSP_SAMPLETICK_HIGH; /* Interrupt Frequency */
// v_pPWMregs->TCMPB3 = 0; /**/
}
PRIVATE VOID
TSP_PowerOff(VOID)
{
RETAILMSG(TS_DBGON,(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(TS_DBGON, (TEXT("::: TSP_CalibrationPointGet()\r\n")));
RETAILMSG(TS_DBGON, (TEXT("cDisplayWidth : %4d\r\n"), cDisplayWidth ));
RETAILMSG(TS_DBGON, (TEXT("cDisplayHeight : %4d\r\n"), cDisplayHeight ));
RETAILMSG(TS_DBGON, (TEXT("CalibrationRadiusX : %4d\r\n"), CalibrationRadiusX));
RETAILMSG(TS_DBGON, (TEXT("CalibrationRadiusY : %4d\r\n"), CalibrationRadiusY));
RETAILMSG(TS_DBGON, (TEXT("pTCP -> PointNumber : %4d\r\n"), pTCP->PointNumber));
RETAILMSG(TS_DBGON, (TEXT("pTCP -> CalibrationX : %4d\r\n"), pTCP->CalibrationX));
RETAILMSG(TS_DBGON, (TEXT("pTCP -> CalibrationY : %4d\r\n"), pTCP->CalibrationY));
return TRUE;
}
PRIVATE void
TSP_TransXY(INT *px, INT *py)
{
INT TmpX, TmpY;
TmpX = (*px >= TSP_MAXX) ? (TSP_MAXX) : *px;
TmpY = (*py >= TSP_MAXY) ? (TSP_MAXY) : *py;
TmpX -= TSP_MINX;
TmpY -= TSP_MINY;
if(TmpX <= 0)
TmpX=0;
if(TmpY <=0)
TmpY=0;
*px = TmpX * TSP_LCDX / (TSP_MAXX - TSP_MINX);
*py = (/*LCD_YSIZE_TFT - */(TmpY * LCD_YSIZE_TFT) / (TSP_MAXY - TSP_MINY))*4;
*px = (*px >= TSP_LCDX) ? TSP_LCDX -1 : *px;
*py = (*py >= TSP_LCDY) ? TSP_LCDY -1 : *py;
RETAILMSG(TS_DBGON,(TEXT("TSP_TransXY: *px=%d, *py=%d\r\n"),*px,*py));
}
PRIVATE BOOL
TSP_GetXY(INT *px, INT *py)
{
INT i,j,k;
INT xsum, ysum, temp;
INT x[TSP_SAMPLE_NUM], y[TSP_SAMPLE_NUM];
INT dx, dy;
temp = 0 ;
xsum = ysum = 0;
for (i = 0; i < TSP_SAMPLE_NUM; i++)
{
v_pADCregs->ADCTSC = (0<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(1<<3)|(1<<2)|(0);
v_pADCregs->ADCCON |= (1 << 0); /* Start Auto conversion */
while (v_pADCregs->ADCCON & 0x1); /* check if Enable_start is low */
while (!(v_pADCregs->ADCCON & (1 << 15))); /* Check ECFLG */
y[i] = (0x3ff & v_pADCregs->ADCDAT1);
x[i] = (0x3ff & v_pADCregs->ADCDAT0);
}
for (j = 0; j < TSP_SAMPLE_NUM -1; ++j)
{
for (k = j+1; k < TSP_SAMPLE_NUM; ++k)
{
if(x[j]>x[k])
{
temp = x[j];
x[j]=x[k];
x[k]=temp;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -