⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lpc32xx_touch.cpp

📁 NXP LPC3000系列 wince BSP包
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
// FILENAME: touch_core.cpp
//
// DESCRIPTION:
//   Implementation of the WinCE touch screen PDD.
//
// Functions:
//
//  TouchDriverCalibrationPointGet
//  DdsiTouchPanelGetDeviceCaps
//  DdsiTouchPanelSetMode
//  DdsiTouchPanelEnable
//  DdsiTouchPanelDisable
//  DdsiTouchPanelAttach
//  DdsiTouchPanelDetach
//  DdsiTouchPanelGetPoint
//  DdsiTouchPanelPowerHandler
//
////////////////////////////////////////////////////////////////////////////////


//------------------------------------------------------------------------------
// Public
//
#include <windows.h>
#include <types.h>
#include <nkintr.h>
#include <creg.hxx>
#include <tchddsi.h>
#include <ceddk.h>

//------------------------------------------------------------------------------
// Platform
//
#include "lpc32xx_touch.h"
#include "bsp.h"

//------------------------------------------------------------------------------
// Debug Zones (only for retail)
// DGPARAM is already defined in tcc_mdd
// only use this to get debug messages in retail mode
//#define DEBUG

#ifndef SHIP_BUILD
#ifdef DEBUG
#define ZONE_INFO           DEBUGZONE(4)

#else
#undef  ZONE_ERROR
#undef  ZONE_WARN
#undef  ZONE_FUNCTION
#undef  ZONE_INIT
#undef  ZONE_INFO

#define ZONE_ERROR          DEBUGZONE(0)
#define ZONE_WARN           DEBUGZONE(1)
#define ZONE_FUNCTION       DEBUGZONE(2)
#define ZONE_INIT           DEBUGZONE(3)
#define ZONE_INFO           DEBUGZONE(4)

DBGPARAM dpCurSettings = 
    {
    L"Touch Screen", 
        {
        L"Errors",      
        L"Warnings", 
        L"Function",    
        L"Init",
        L"Info",        
        L"Undefined",   
        L"Undefined",   
        L"Undefined",
        L"Undefined",   
        L"Undefined",   
        L"Undefined",   
        L"Undefined",
        L"Undefined",       
        L"Undefined",   
        L"Undefined",   
        L"Undefined"      
        },
        0x0013  // Errors, Warnings, Info
    };

#undef  DEBUGMSG
#define DEBUGMSG RETAILMSG

#endif
#endif

//------------------------------------------------------------------------------
// local data structures
//
typedef struct
{
    LONG                  nProcessAttached;
    int                   nSampleRate;        // Sample rate
	LPC3250_ADCTSC_REGS_T *pTSCREGs;          // Pointer to touch registers
	BOOL predownflag;
} TOUCH_INSTANCE;

//------------------------------------------------------------------------------
//  Device registry parameters
static WCHAR const* s_szRegistryPath = L"\\HARDWARE\\DEVICEMAP\\TOUCH";

//------------------------------------------------------------------------------
// global variables
//
static TOUCH_INSTANCE s_TouchPad =
{
    0xFFFFFFFF,    
    DEFAULT_SAMPLE_RATE,
    NULL,
	FALSE
};

// Referenced in MDD. TS controller only asserts SYSINTR_TOUCH.
//
DWORD gIntrTouchChanged = SYSINTR_NOP;   // Not used here.
DWORD gIntrTouch        = SYSINTR_NOP;

static int srates[2] = {TOUCHPANEL_SAMPLE_RATE_LOW, TOUCHPANEL_SAMPLE_RATE_HIGH};

// We control the MDD thread wait timeout to force a penup state when no more
// touchscreen events are present
extern "C" DWORD gdwTouchIstTimeout;

// The MDD requires a minimum of MIN_CAL_COUNT consecutive samples before
// it will return a calibration coordinate to GWE.
extern "C" int MIN_CAL_COUNT = 10;

//------------------------------------------------------------------------------
//
//  TouchDriverCalibrationPointGet
//
//  Get calibration data for touch apoint
//
extern "C" BOOL TouchDriverCalibrationPointGet(TPDC_CALIBRATION_POINT *pTCP)
{
    BOOL rc = FALSE;

    INT32 cDisplayWidth  = pTCP->cDisplayWidth;
    INT32 cDisplayHeight = pTCP->cDisplayHeight;

    int CalibrationRadiusX = cDisplayWidth / 20;
    int CalibrationRadiusY = cDisplayHeight / 20;

    DEBUGMSG(ZONE_FUNCTION, (TEXT("TouchDriverCalibrationPointGet+\r\n")));    
    
    // Check which of the 5 calibration point is requested.
    switch ( pTCP->PointNumber )
        {
        case 0:
            pTCP->CalibrationX = cDisplayWidth / 2;
            pTCP->CalibrationY = cDisplayHeight / 2;
            rc = TRUE;
            break;

        case 1:
            pTCP->CalibrationX = CalibrationRadiusX * 2;
            pTCP->CalibrationY = CalibrationRadiusY * 2;
            rc = TRUE;
            break;

        case 2:
            pTCP->CalibrationX = CalibrationRadiusX * 2;
            pTCP->CalibrationY = cDisplayHeight - ( CalibrationRadiusY * 2 );
            rc = TRUE;
            break;

        case 3:
            pTCP->CalibrationX = cDisplayWidth - ( CalibrationRadiusX * 2 );
            pTCP->CalibrationY = cDisplayHeight - ( CalibrationRadiusY * 2 );
            rc = TRUE;
            break;

        case 4:
            pTCP->CalibrationX = cDisplayWidth - ( CalibrationRadiusX * 2 );
            pTCP->CalibrationY = CalibrationRadiusY * 2;
            rc = TRUE;
            break;

        default:
            pTCP->CalibrationX = cDisplayWidth / 2;
            pTCP->CalibrationY = cDisplayHeight / 2;
            SetLastError( ERROR_INVALID_PARAMETER );
            break;
    }

    DEBUGMSG(ZONE_INFO, (TEXT("cDisplayWidth        : %4X\r\n"), cDisplayWidth     ));
    DEBUGMSG(ZONE_INFO, (TEXT("cDisplayHeight       : %4X\r\n"), cDisplayHeight    ));
    DEBUGMSG(ZONE_INFO, (TEXT("CalibrationRadiusX   : %4d\r\n"), CalibrationRadiusX));
    DEBUGMSG(ZONE_INFO, (TEXT("CalibrationRadiusY   : %4d\r\n"), CalibrationRadiusY));
    DEBUGMSG(ZONE_INFO, (TEXT("pTCP -> PointNumber  : %4d\r\n"), pTCP->PointNumber));
    DEBUGMSG(ZONE_INFO, (TEXT("pTCP -> CalibrationX : %4d\r\n"), pTCP->CalibrationX));
    DEBUGMSG(ZONE_INFO, (TEXT("pTCP -> CalibrationY : %4d\r\n"), pTCP->CalibrationY));

    DEBUGMSG(ZONE_FUNCTION, (TEXT("TouchDriverCalibrationPointGet-\r\n")));    
    return ( rc );
}

//------------------------------------------------------------------------------
//
//  DdsiTouchPanelGetDeviceCaps
//
//  Get touch panel capabilities
//
extern "C" BOOL DdsiTouchPanelGetDeviceCaps(INT iIndex, LPVOID lpOutput)
{
    DEBUGMSG(ZONE_FUNCTION, (TEXT("DdsiTouchPanelGetDeviceCaps+\r\n")));
 
    BOOL rc = FALSE;
    TPDC_SAMPLE_RATE *pTSR = (TPDC_SAMPLE_RATE*) lpOutput;
    TPDC_CALIBRATION_POINT_COUNT *pTCPC = (TPDC_CALIBRATION_POINT_COUNT*) lpOutput;

	if (pTSR == NULL)
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("TouchPanelGetDeviceCaps: Invalid parameter.\r\n")));
        SetLastError( ERROR_INVALID_PARAMETER );
    }
    else
    {
        // Check which of the device capabilities are requested.
        switch (iIndex)
        {
            // Return the sample rate.
            case TPDC_SAMPLE_RATE_ID:

                pTSR->SamplesPerSecondLow      = TOUCHPANEL_SAMPLE_RATE_LOW;
                pTSR->SamplesPerSecondHigh     = TOUCHPANEL_SAMPLE_RATE_HIGH;
				pTSR->CurrentSampleRateSetting = s_TouchPad.nSampleRate;
                rc = TRUE;
                break;

            // Return the number of calibration points used to calibrate the touch screen.
            case TPDC_CALIBRATION_POINT_COUNT_ID:
                pTCPC->flags              = 0;
                pTCPC->cCalibrationPoints = 5;
                rc = TRUE;
                break;

            // Return the x and y coordinates of the requested calibration point.
            // The index of the calibration point is set in lpOutput->PointNumber.
            case TPDC_CALIBRATION_POINT_ID:
                rc = TouchDriverCalibrationPointGet((TPDC_CALIBRATION_POINT*)lpOutput);
                break;

            default:
                RETAILMSG(ZONE_ERROR, 
                    (TEXT("TouchPanelGetDeviceCaps: Invalid parameter.\r\n")));
                SetLastError(ERROR_INVALID_PARAMETER);
                break;
        }
    }

	DEBUGMSG(ZONE_FUNCTION, (TEXT("DdsiTouchPanelGetDeviceCaps-\r\n")));

    return rc;
}

//------------------------------------------------------------------------------
//  DdsiTouchPanelSetMode
//
//    Sets the low or high sample rate
//
BOOL DdsiTouchPanelSetMode(INT iIndex, LPVOID lpInput)
{
    BOOL rc = FALSE;

    DEBUGMSG(ZONE_FUNCTION, (TEXT("DdsiTouchPanelSetMode+\r\n")));
    
    switch (iIndex)
    {
        case TPSM_SAMPLERATE_LOW_ID:
			s_TouchPad.nSampleRate = 0;
			lpc32xx_update_samplerate();
            SetLastError(ERROR_SUCCESS);
            rc = TRUE;
			break;

		case TPSM_SAMPLERATE_HIGH_ID:
			s_TouchPad.nSampleRate = 1;
			lpc32xx_update_samplerate();
            SetLastError(ERROR_SUCCESS);
            rc = TRUE;
            break;

        default:
            RETAILMSG(ZONE_ERROR, (TEXT("DdsiTouchPanelSetMode: Invalid parameter.\r\n")));
            SetLastError(ERROR_INVALID_PARAMETER);
            break;
    }

    DEBUGMSG(ZONE_FUNCTION, (TEXT("DdsiTouchPanelSetMode-\r\n")));

    return rc;
}

//------------------------------------------------------------------------------
//
//  DdsiTouchPanelEnable
//
//  Enable the touchscreen
//
BOOL DdsiTouchPanelEnable()
{
	DWORD irqt = OAL_INTR_IRQ_TS;

	DEBUGMSG(ZONE_FUNCTION, (TEXT("DdsiTouchPanelEnable+\r\n")));
    
    HKEY hkTouch = NULL;
    DWORD dwStatus, dwType, dwSize, samplerate = 0xFF, tmp32;
    BOOL rc = FALSE;

	// Open the registry key and read our configuration
    dwStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, s_szRegistryPath, 0, 0, &hkTouch);
    if (dwStatus != ERROR_SUCCESS) {
        RETAILMSG(ZONE_ERROR, (_T("DdsiTouchPanelEnable: Error opening registry!\r\n")));
    }
	else
	{
		// Get sample rate (in Hz)
        dwSize = sizeof(samplerate);
	    dwType = REG_DWORD;
        dwStatus = RegQueryValueEx(hkTouch, _T("Samplerate"), NULL, &dwType, 
            (LPBYTE) &samplerate, &dwSize);
	    if (dwStatus != ERROR_SUCCESS) {
	        DEBUGMSG(ZONE_WARN, (_T("DdsiTouchPanelEnable: No sample rate type "
				_T("found, using default!\r\n"))));
			samplerate = DEFAULT_SAMPLE_RATE;
	    }

		// Get Maximum calibration error
        dwSize = sizeof(tmp32);
	    dwType = REG_DWORD;
        dwStatus = RegQueryValueEx(hkTouch, _T("MaxCalError"), NULL, &dwType, 
            (LPBYTE) &tmp32, &dwSize);
	    if (dwStatus != ERROR_SUCCESS) {
	        DEBUGMSG(ZONE_WARN, (_T("DdsiTouchPanelEnable: No maximum calibration "
				_T("value found, using default!\r\n"))));
			MIN_CAL_COUNT = DEFAULT_TOUCHPANEL_MAX_CALERROR;
	    }
		else
		{
			MIN_CAL_COUNT = (int) tmp32;
		}
	}
	
	// Close the registry key
    if (hkTouch != NULL) {
        RegCloseKey(hkTouch);
    }

	// Check high or low sample rate setting
	if (samplerate > 1)
	{
		DEBUGMSG(ZONE_WARN, (_T("DdsiTouchPanelEnable: Sample rate invalid, using default\r\n")));
		samplerate = DEFAULT_SAMPLE_RATE;
	}

	DEBUGMSG(ZONE_INFO, (_T("DdsiTouchPanelEnable: Using sample rate %d Hz\r\n"),
		srates[samplerate]));
	s_TouchPad.nSampleRate = samplerate;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -