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

📄 bsptouch.cpp

📁 Microsoft WinCE 6.0 BSP FINAL release source code for use with the i.MX27ADS TO2 WCE600_FINAL_MX27_S
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//------------------------------------------------------------------------------
//
//  Copyright (C) 2004-2005, Motorola Inc. All Rights Reserved
//
//------------------------------------------------------------------------------
//
//  Copyright (C) 2005-2006,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:  bsptouch.cpp
//
//  Provides the implementation for BSP-specific touch support.
//
//------------------------------------------------------------------------------
#include <windows.h>
#include <tchddsi.h>
#include "bsp.h"
#include "pmic_ioctl.h"
#include "pmic_lla.h"
#include "pmic_adc.h"
#include "gpt.h"

#include "regs.h"
#include "regs_adc.h"

//-----------------------------------------------------------------------------
// External Functions

//-----------------------------------------------------------------------------
// External Variables
extern "C" const int MIN_CAL_COUNT = 20;

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

// Maximum allowed variance in the X coordinate samples.
#define DELTA_X_COORD_VARIANCE          24

// Maximum allowed variance in the X coordinate samples.
#define DELTA_Y_COORD_VARIANCE          24


#define TOUCHCLKSRC_FREQ            BSP_CLK_CKIL_FREQ       // clock source is CKIL
#define TOUCHPRESCALAR_VAL          0x000               // divide by 1

#define ABS(x)  ((x) >= 0 ? (x) : (-(x)))

// GPT Granularity is in usec
#define TOUCH_DELAY_GPT_ONE_MS 1000
#define TOUCH_DELAY(x) ((x) * TOUCH_DELAY_GPT_ONE_MS)

#define GPT_EVENT_NAME	L"ADCScanInterval"

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

// Global Variables
HANDLE	hGpt;
HANDLE	hGptTimer;

// Local Variables


static HANDLE hPMI;
static TCHAR *gEventNamePri = TEXT("EVENT_TS_PRI");
static TCHAR *gEventNameAlt = TEXT("EVENT_TS_ALT");
// Named event for interrupt registration
static TCHAR *gTouchEventName;


//-----------------------------------------------------------------------------
// Local Functions

//-----------------------------------------------------------------------------
//
// Function: PmicTouchDeinit
//
// This function uninitializes the PMIC touch controller.
//
// Parameters:
//      None.
//
// Returns:
//      None.
//
//-----------------------------------------------------------------------------
static void PmicTouchDeinit(void)
{

    DEBUGMSG(ZONE_FUNCTION, (TEXT("-%s()\r\n"), __WFUNCTION__));

    // Deregister for PMIC pen down interrupts.
    if (PmicInterruptDeregister(PMIC_MC13783_INT_TSI) != PMIC_SUCCESS)
    {
        ERRORMSG(TRUE, (_T("PmicTouchDeinit:  PmicInterruptDeregister failed\r\n")));
    }

    // Disable PMIC touch interrupt
    // Set to inactive mode
    if (PmicADCTouchStandby(false) != PMIC_SUCCESS)
    {
        ERRORMSG(TRUE, (_T("PmicTouchDeinit:  PmicTouchStandby failed\r\n")));
    }

    DEBUGMSG(ZONE_FUNCTION, (TEXT("-%s()\r\n"), __WFUNCTION__));
}


//------------------------------------------------------------------------------
//
// Function: PmicTouchInit
//
// This function initializes the PMIC touch controller.
//
// Parameters:
//      None.
//
// Returns:
//      Status.
//
//------------------------------------------------------------------------------
static PMIC_STATUS PmicTouchInit(void)
{
    PMIC_STATUS rc = PMIC_ERROR;

    DEBUGMSG(ZONE_FUNCTION, (TEXT("+%s()\r\n"), __WFUNCTION__));

    // Register for PMIC pen down interrupts.  Event name must match one given
    // to event created in MDD for IST signaling.
    if (PmicInterruptRegister(PMIC_MC13783_INT_TSI, gTouchEventName)
        != PMIC_SUCCESS)
    {
        ERRORMSG(TRUE, (_T("PmicTouchInit:  PmicInterruptRegister failed\r\n")));
        goto cleanUp;
    }

    // Put PMIC touch ADC into standby (required for pen down interrupt)
    if (PmicADCTouchStandby(true) != PMIC_SUCCESS)
    {
        ERRORMSG(TRUE, (_T("PmicTouchInit:  PmicTouchStandby failed\r\n")));
        goto cleanUp;
    }

    // Make sure pen down interrupt are unmasked
    if (PmicInterruptHandlingComplete(PMIC_MC13783_INT_TSI) != PMIC_SUCCESS)
    {
        ERRORMSG(TRUE, (_T("PmicTouchInit:  PmicInterruptHandlingComplete failed\r\n")));
        goto cleanUp;
    }

    rc = PMIC_SUCCESS;

cleanUp:
    if (rc != PMIC_SUCCESS) PmicTouchDeinit();

    DEBUGMSG(ZONE_FUNCTION, (TEXT("-%s()\r\n"), __WFUNCTION__));

    return rc;
}

//-----------------------------------------------------------------------------
//
// Function: BSPTouchSetSampleRate
//
// This function configures the rate for acquiring touch samples by
// configuring the periodic interval of the GPT2 timer.
//
// Parameters:
//      dwIntervalMsec
//          [in] Specifies the interval in msec to be used for generating
//          a periodic timer interrupt.  This interval sets the sample
//          rate of the touch driver.
//
// Returns:
//      None
//
//-----------------------------------------------------------------------------
void BSPTouchSetSampleRate(DWORD dwIntervalMsec)
{
	GPT_TIMER_SET_PKT gptTimerDelayPkt;

    DEBUGMSG(ZONE_FUNCTION, (TEXT("+%s()\r\n"), __WFUNCTION__));

	gptTimerDelayPkt.timerMode = timerModePeriodic;
    gptTimerDelayPkt.period = TOUCH_DELAY(dwIntervalMsec);

	GptSetTimer(hGpt, &gptTimerDelayPkt);

    DEBUGMSG(ZONE_FUNCTION, (TEXT("-%s()\r\n"), __WFUNCTION__));
}


//-----------------------------------------------------------------------------
//
// Function: BSPTouchTimerInit
//
// This function initializes the GPT2 timer for use as the touch
// periodic timer.
//
// Parameters:
//      dwIntervalMsec
//          [in] Specifies the interval in msec to be used for generating
//          a periodic timer interrupt.  This interval sets the sample
//          rate of the touch driver.
//
// Returns:
//      TRUE if successful, otherwise FALSE.
//
//-----------------------------------------------------------------------------

static BOOL BSPTouchTimerInit(DWORD dwIntervalMsec)
{
    GPT_TIMER_SET_PKT gptTimerDelayPkt;

	DEBUGMSG(ZONE_FUNCTION, (TEXT("+%s()\r\n"), __WFUNCTION__));

	hGpt = GptOpenHandle(2);

	if ((hGpt == NULL) || (hGpt == INVALID_HANDLE_VALUE))
	{
		ERRORMSG(TRUE, (_T("BSPTouchTimerInit: GPT Handle creation failed\r\n")));
		return FALSE;
	}

	hGptTimer = GptCreateTimerEvent(hGpt, GPT_EVENT_NAME);

	if (hGptTimer == NULL)
	{
		ERRORMSG(TRUE, (_T("BSPTouchTimerInit: GPT Event creation failed\r\n")));
		return FALSE;
	}
	gptTimerDelayPkt.timerMode = timerModePeriodic;
    gptTimerDelayPkt.period = TOUCH_DELAY(dwIntervalMsec);
    gptTimerDelayPkt.periodType = MICROSEC;


	GptSetTimer(hGpt, &gptTimerDelayPkt);

    DEBUGMSG(ZONE_FUNCTION, (TEXT("-%s()\r\n"), __WFUNCTION__));

    return TRUE;
}

//-----------------------------------------------------------------------------
//
// Function: BSPTouchTimerDeInit
//
// This function de-initializes the GPT timer 2.
//
// Parameters:
//      None.
//
// Returns:
//      TRUE if successful, otherwise FALSE.
//
//-----------------------------------------------------------------------------

static void BSPTouchTimerDeInit(void)
{
	GptStop(hGpt);

//	if (GptReleaseTimerEvent(hGpt, GPT_EVENT_NAME) == FALSE)
//	{
//		ERRORMSG(TRUE, (_T("BSPTouchTimerDeInit: GPT Release Event failed\r\n")));
//	}

	if (GptCloseHandle(hGpt) == FALSE)
	{
		ERRORMSG(TRUE, (_T("BSPTouchTimerDeInit: GPT Close handle failed\r\n")));
	}

	return;
}

//-----------------------------------------------------------------------------
//
// Function: BSPTouchADCDelay
//
// DESCRIPTION:
//      This function blocks on the GPT timer 2 till the timer elapses.
//
// Parameters:
//      None.
//
// Returns:
//      None.
//
//-----------------------------------------------------------------------------

void BSPTouchADCDelay(void)
{

	GptStart(hGpt);

	if (WaitForSingleObject(hGptTimer, INFINITE) == WAIT_OBJECT_0)
	{
		GptStop(hGpt);
	}

	return;
}

//-----------------------------------------------------------------------------
//
// Function: BSPTouchDeinit
//
// Deinitializes the BSP-specific interfaces and data structures for
// touch support
//
// Parameters:
//      None.
//
// Returns:
//      None.
//
//-----------------------------------------------------------------------------
void BSPTouchDeinit(void)
{
    DEBUGMSG(ZONE_FUNCTION, (TEXT("-%s()\r\n"), __WFUNCTION__));

	// deinitialize the GPT timer 2
	BSPTouchTimerDeInit();

    // Deinitialize PMIC touch interface
    PmicTouchDeinit();

    DEBUGMSG(ZONE_FUNCTION, (TEXT("-%s()\r\n"), __WFUNCTION__));

	return;
}


//-----------------------------------------------------------------------------
//
// Function: BSPTouchAttach
//
// The function performs BSP-specific attachment allocations and assignments.
//

⌨️ 快捷键说明

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