touchpdd.cpp

来自「i.mx27 soc for wince 6.0」· C++ 代码 · 共 525 行 · 第 1/2 页

CPP
525
字号
//------------------------------------------------------------------------------
//
//  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.
//
//------------------------------------------------------------------------------
//
//  Copyright (C) 2004, Motorola Inc. All Rights Reserved
//
//------------------------------------------------------------------------------
//
//  Copyright (C) 2004-2007, Freescale Semiconductor, Inc. All Rights Reserved.
//  THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
//  AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT
//
//------------------------------------------------------------------------------
//
//  File:  touchpdd.cpp
//
//  Provides the PDD code for the DDSI touch driver routines.
//
//-----------------------------------------------------------------------------

#include <windows.h>
#include <nkintr.h>
#include <tchddsi.h>
#include "touchpdd.h"


//-----------------------------------------------------------------------------
// External Functions
extern BOOL BSPTouchInit(DWORD dwIntervalMsec);
extern void BSPTouchDeinit(void);
extern TOUCH_PANEL_SAMPLE_FLAGS BSPTouchGetSample(INT *x, INT *y);
extern void BSPTouchSetSampleRate(DWORD dwIntervalMsec);
extern void BSPTouchPowerHandler(BOOL boff);
extern void BSPTouchTimerEnable(void);
/*extern void BSPTouchTimerDisable(void);
extern BOOL BSPTouchTimerIrqQuery(void);*/
extern void BSPCheckIRQ(void);
extern void BSPTouchADCDelay(void);


//-----------------------------------------------------------------------------
// External Variables
extern "C" HANDLE	hTouchPanelEvent;

//-----------------------------------------------------------------------------
// Defines


//-----------------------------------------------------------------------------
// Types


//-----------------------------------------------------------------------------
// Global Variables
DWORD gIntrTouch        = SYSINTR_NOP;
DWORD gIntrTouchChanged = SYSINTR_NOP; // Not used here.

INT gCurSampleRateSetting = 1;         // High sample rate setting.


//-----------------------------------------------------------------------------
// Local Variables
static DWORD gCurSampleRate    = TOUCH_SAMPLE_RATE_HIGH;
static DWORD gTouchPowerStatus = TouchPowerOn;


//-----------------------------------------------------------------------------
// Local Functions
static BOOL TouchDriverCalibrationPointGet(TPDC_CALIBRATION_POINT *lpOutput);


//-----------------------------------------------------------------------------
//
// Function: DdsiTouchPanelAttach
//
// This function executes when the MDD's DLL entry point gets a
// DLL_PROCESS_ATTACH message.
//
// Parameters:
//      None.
//
// Returns:
//      Returns zero (0).
//
//-----------------------------------------------------------------------------
LONG DdsiTouchPanelAttach(void)
{
    DEBUGMSG(ZONE_FUNCTION, (_T("DdsiTouchPanelAttach+\r\n")));
    return 0;
}


//-----------------------------------------------------------------------------
//
// Function: DdsiTouchPanelDetach
//
// This function executes when the MDD's DLL entry point gets a
// DLL_PROCESS_DETACH message.
//
// Parameters:
//      None.
//
// Returns:
//      Returns zero (0).
//
//-----------------------------------------------------------------------------
LONG DdsiTouchPanelDetach(void)
{
    DEBUGMSG(ZONE_FUNCTION, (_T("DdsiTouchPanelDetach+\r\n")));
    return 0;
}


//-----------------------------------------------------------------------------
//
// Function: DdsiTouchPanelEnable
//
// This function applies power to the touch screen device and initializes
// it for operation.
//
// Parameters:
//      None.
//
// Returns:
//      TRUE indicates success. FALSE indicates failure.
//
//-----------------------------------------------------------------------------
BOOL DdsiTouchPanelEnable(void)
{
    BOOL rc = TRUE;

    DEBUGMSG(ZONE_FUNCTION, (_T("DdsiTouchPanelEnable+\r\n")));

    // if we are already powered on, just return
    if (gTouchPowerStatus == TouchPowerOn)
    {
        goto cleanUp;
    }

    // Initialize BSP-specific settings
    if (!BSPTouchInit(1000/gCurSampleRate))
    {
        DEBUGMSG(ZONE_ERROR,
            (_T("DdsiTouchPanelEnable:  BSPTouchInit failed!\r\n")));
        rc = FALSE;
        goto cleanUp;
    }

    // Power on the touch device
    DdsiTouchPanelPowerHandler(FALSE);

cleanUp:
    if (!rc) BSPTouchDeinit();

    DEBUGMSG(ZONE_FUNCTION, (_T("DdsiTouchPanelEnable-\r\n")));

    return rc;
}


//-----------------------------------------------------------------------------
//
// Function: DdsiTouchPanelDisable
//
// This function disables the touch screen device. Disabling a touch
// screen prevents generation of any subsequent touch samples, and
// removes power from the screen's hardware. The exact steps necessary
// depend on the specific characteristics of the touch screen hardware.
//
// Parameters:
//      None.
//
// Returns:
//      None.
//
//-----------------------------------------------------------------------------
void DdsiTouchPanelDisable(void)
{
    DEBUGMSG(ZONE_FUNCTION, (_T("DdsiTouchPanelDisable+\r\n")));

    // If we are already off, just return
    if (gTouchPowerStatus == TouchPowerOff)
        return;

    // Power off
    DdsiTouchPanelPowerHandler(TRUE);

    // Deinitialize BSP-specific settings
    BSPTouchDeinit();

    DEBUGMSG(ZONE_FUNCTION, (_T("DdsiTouchPanelDisable-\r\n")));
    return;
}


//-----------------------------------------------------------------------------
//
// Function: DdsiTouchPanelGetDeviceCaps
//
// This function queries capabilities of the touch screen device.
//
// Parameters:
//      iIndex
//          [in] Capability to query.  The following capabilities can
//          be specifed:
//
//              TPDC_SAMPLE_RATE_ID - Returns the sample rate.
//
//              TPDC_CALIBRATION_POINT_ID - Returns the x and y
//              coordinates of the required calibration point. The index
//              of the calibration point is set in the PointNumber member
//              of lpOutput.
//
//              TPDC_CALIBRATION_POINT_COUNT_ID Returns the number of
//              calibration points used to calibrate the touch screen.
//
//      lpOutput
//          [out] Pointer to one or more memory locations to place the
//          queried information. The format of the memory referenced
//          depends on the setting of iIndex.
//
//  Returns:
//      TRUE if successful, FALSE otherwise.
//
//-----------------------------------------------------------------------------
BOOL DdsiTouchPanelGetDeviceCaps(INT iIndex, LPVOID lpOutput)
{
    TPDC_SAMPLE_RATE *ptrSR;
    TPDC_CALIBRATION_POINT *ptrCP;
    TPDC_CALIBRATION_POINT_COUNT *ptrCPC;

    DEBUGMSG(ZONE_FUNCTION, (_T("DdsiTouchPanelGetDeviceCaps+\r\n")));

    // Check for invalid parameter
    if (lpOutput == NULL)
        return FALSE;

    switch (iIndex)
    {
    // Get the sample rate
    case TPDC_SAMPLE_RATE_ID:
        ptrSR = (TPDC_SAMPLE_RATE*)lpOutput;
        ptrSR->SamplesPerSecondLow = TOUCH_SAMPLE_RATE_LOW;
        ptrSR->SamplesPerSecondHigh = TOUCH_SAMPLE_RATE_HIGH;
        ptrSR->CurrentSampleRateSetting = gCurSampleRateSetting;
        break;

    // Get the x and y coordinates of the required calibration point.
    case TPDC_CALIBRATION_POINT_ID:
        ptrCP = (TPDC_CALIBRATION_POINT*)lpOutput;
        return (TouchDriverCalibrationPointGet(ptrCP));

    // Get the number of calibration points used to calibrate the touch screen.
    case TPDC_CALIBRATION_POINT_COUNT_ID:

⌨️ 快捷键说明

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