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

📄 tsc2046touch.cpp

📁 TI TCS2046 Toutch PAD IC Driver for WindowsCE
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*************************************************************/
//
// Copyright (c) Texas Instruments 2005.  All rights reserved.
//
/**************************************************************
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.

Module Name:
		TSC2046Touch.CPP

Abstract:	
		This module contains TSC2046 Touch Screen Functions on
		the Ddsi layer.

Functions:
	DdsiTouchPanelAttach, 
	DdsiTouchPanelDetach, 
	DdsiTouchPanelEnable,
	DdsiTouchPanelDisable, 
	DdsiTouchPanelGetPoint,
    DdsiTouchPanelPowerHandler,
	DdsiTouchPanelGetDeviceCaps, 
    DdsiTouchPanelSetMode		
  
Revision History:
Rev 0.0		Original Release	WXF	9-30-2005

***************************************************************/
//--------------------------------------------------------------
// Include Files
//--------------------------------------------------------------
#include    <windows.h>
#include    <nkintr.h>
#include    <tchddsi.h>
#include	<TSC2046Touch.H>		// TSC2046 related headers
#include	<TSC2046SPI.H>
#include	<bsp.h>					// mainstone platform dependent 
#include    <HostTouch.H>			// host processor dependent 
#include	<HostSPIComm.H>			// host processor dependent

//---------------------------------------------------------------
// Global Variables.
//---------------------------------------------------------------

// The MDD expects these two variables to be defined here
DWORD gIntrTouch			= SYSINTR_TOUCH;
DWORD gIntrTouchChanged		= SYSINTR_TOUCH_CHANGED;

static  TOUCHPANEL_POINT_SAMPLES rgPointSamples;

// The MDD requires a minimum of MIN_CAL_COUNT consecutive samples before
// it will return a calibration coordinate to GWE.  This value is defined
// in the PDD so that each OEM can control the behaviour of the touch
// panel and still use the Microsoft supplied MDD.  Note that the extern "C"
// is required so that the variable name doesn't get decorated, and
// since we have an initializer the 'extern' is actually ignored and
// space is allocated.
extern "C" const int MIN_CAL_COUNT = 25;

//---------------------------------------------------------------
// Local Variables.
//---------------------------------------------------------------
static EXPECTED_INT_EVENT g_NextExpectedInterrupt = PEN_DOWN;
static BOOL TouchIrq = TRUE;

// lag to indicate whether we are in power handler routine, so
// we know to avoid system calls.
static BOOL InPowerHandler = FALSE;

//----------------------------------------------------------------
// Local function prototypes.
//----------------------------------------------------------------
////
//
// DDSI Implementation
//
// @doc EX_TOUCH_DDSI EXTERNAL DRIVERS DDSI TOUCH_PANEL
//
// @func LONG | DdsiTouchPanelAttach |
//        this function called when the MDD's DLL entry point gets a 
//        DLL_PROCESS_ATTACH message.
//
// This routine no longer does anything.  All functionallity has been moved
// from here into DdsiTouchPanelEnable to allow this code to be statically
// linked with GWE rather than existing as a DLL.  Technically, when built
// as a DLL we should keep an attach count and only allow touh.dll to be
// loaded once.  But, since we are loaded at boot time by GWE, there is
// no real concern about multiple loads (unless gwe has a bug!).
//
// @rdesc
// Always returns 0
//
// @comm
// Implemented in the PDD.
//
LONG DdsiTouchPanelAttach()
{
	RETAILMSG(1,(TEXT("Calling DdsiTouchPanelAttach()\r\n")));
    return(0); 
}

//
// DDSI Implementation
// @doc EX_TOUCH_DDSI EXTERNAL DRIVERS DDSI TOUCH_PANEL
// @func LONG | DdsiTouchPanelDetach |
//        this function called when the MDD's DLL entry point gets a 
//        DLL_PROCESS_DETACH message. See the descrition for attach.  
//        All functionallity has been moved into DdsiTouchPanelDisable.
// @rdesc
//		Always returns 0
// @comm
//		Implemented in the PDD.
//
LONG DdsiTouchPanelDetach()
{
	RETAILMSG(1,(TEXT("Calling DdsiTouchPanelDetach()\r\n")));
    return(0);
}

//
// DDSI Implementation
// @doc EX_TOUCH_DDSI EXTERNAL DRIVERS DDSI TOUCH_PANEL
// @func BOOL | DdsiTouchPanelEnable |
//        this function applies power to the touch panel and initializes it for
//        operation. 
// @rdesc
//		If the initializations failed, return 0.
// @comm
//		Implemented in the PDD.
//
BOOL DdsiTouchPanelEnable(void)
{
	RETAILMSG(1,(TEXT("Calling DdsiTouchPanelEnable()\r\n")));

    // Allocate touch panel resources (map registers, etc.)
    if (!HWAllocateTouchPanelResources()) { return(FALSE); }

    // Initialize SPI at Host
    if (!InitSPI(InPowerHandler)) { return(FALSE); }

	// Enable touch interrupt
	EnableTouchPanelIRQ();
	g_NextExpectedInterrupt=PEN_DOWN;
	
	RETAILMSG(1,(TEXT("END Calling DdsiTouchPanelEnable()\r\n")));
    return(TRUE);     
}

//
// DDSI Implementation
// @doc EX_TOUCH_DDSI EXTERNAL DRIVERS DDSI TOUCH_PANEL
// @func VOID | DdsiTouchPanelDisable |
//        this function disableds the touch screen devices to prevents generating 
//        any touch samples and powers down the touch panel device.
// @comm
//		Implemented in the PDD.
//
void DdsiTouchPanelDisable(void)
{
	RETAILMSG(1,(TEXT("Calling DdsiTouchPanelDisable()\r\n")));	

    // Clean up any PDD-allocated resources and deinit I2C interface
//	DeinitSPI(FALSE);
    HWDeallocateTouchPanelResources();

	RETAILMSG(1,(TEXT("END Calling DdsiTouchPanelDisable()\r\n")));	
	return;
}

//
// DDSI Implementation
// @doc EX_TOUCH_DDSI EXTERNAL DRIVERS DDSI TOUCH_PANEL
// @func void | DdsiTouchPanelGetPoint |
//		Returns the most recently acquired point and its associated tip state
//		information.
// @parm PDDSI_TOUCHPANEL_TIPSTATE | pTipState |
//		Pointer to where the tip state information will be returned.
// @parm PLONG | pUnCalX |
//		Pointer to where the x coordinate will be returned.
// @parm PLONG | pUnCalY |
//		Pointer to where the y coordinate will be returned.
// @comm
//		Implmented in the PDD.
//
VOID DdsiTouchPanelGetPoint(TOUCH_PANEL_SAMPLE_FLAGS *pTipStateFlags,
							INT *pUncalX,INT *pUncalY)
{
    static BOOL TouchIrq = TRUE;
    UINT32 InterruptType = SYSINTR_NOP;

//	RETAILMSG(1,(TEXT("Calling DdsiTouchPanelGetPoint()\r\n")));
	*pTipStateFlags = TouchSampleIgnore;
	if (TouchIrq)
	{
		// The pen was previously up - it just transitioned to down state.
		TouchIrq = FALSE;
		InterruptType   = SYSINTR_TOUCH;
	    *pTipStateFlags = PDDSampleTouchScreen(pUncalX, pUncalY);
		// The next expected interrupt will come from sampling timer 
		// (pen-up doesn't cause an interrupt).
		g_NextExpectedInterrupt = PEN_UP_OR_TIMER;
		RETAILMSG(1,(TEXT("GetPoint: pen from up to down ...\r\n")));	
	}
	else
	{
		// The timer irq ...
		// The pen could now be either up or down at this point 
		// - we need to check.
		InterruptType   = SYSINTR_TOUCH_CHANGED;
		// Read data if /PENIRQ is active so as to read 
		// the last data if avaliable
		*pTipStateFlags = PDDSampleTouchScreen(pUncalX, pUncalY);
	       // The next expected interrupt will come from sampling timer 
		// (pen-up doesn't cause an interrupt).
		g_NextExpectedInterrupt = PEN_UP_OR_TIMER;
		RETAILMSG(1,(TEXT("GetPoint: timer irq occured ...\r\n")));	
	}
	if (!HWGetTouchStatus())
	{
		TouchIrq = TRUE;
		// the pen isn't currently down, send the MDD a pen-up "event".
		*pTipStateFlags = TouchSampleValidFlag;   // but send pen up to mdd
		// The next expected interrupt will come from pen-down event.
		g_NextExpectedInterrupt = PEN_DOWN;
		RETAILMSG(1,(TEXT("GetPoint: pen is up ...\r\n")));	
	}
	RETAILMSG(1,(TEXT("TouchSampleFlag = %x\r\n"), *pTipStateFlags));
    // Make sure the next expected interrupt is configured and enabled.
    PrepareNextInterrupt(g_NextExpectedInterrupt);
    // Tell the OAL to clear and unmask interrupt just occurred.
    InterruptDone(InterruptType);
//	RETAILMSG(1,(TEXT("END Calling DdsiTouchPanelGetPoint()\r\n")));
}

//
// DDSI Implementation
// @func VOID | DdsiTouchPanelPowerHandler |
//	System power state notification.
// @parm BOOL | bOff | 
//		TRUE, the system is powering off; 
//		FALSE, the system is powering up.
// @comm
//		This routine is called in a kernel context and may not make any system
//		calls whatsoever.  It may read and write its own memory and that's about
//		it.  This routine is called by the MDD and also serves as an internal
//		helper routine for touch enable/disable.
// @devnote This routine will run in kernel context, and may not make
//		any system calls.  If you can any subroutines inside here, make sure
//		that they also follow this restriction.
//
void DdsiTouchPanelPowerHandler(BOOL bOff)
{
	RETAILMSG(1,(TEXT("Calling DdsiTouchPanelPowerHandler()\r\n")));

	InPowerHandler = TRUE;
	if (bOff)
	{      
		// Stop Touch function/interrupt and disable SPI 
		DeinitSPI(FALSE);
	}
	else
	{
   		// when waking up, re-initilize the TSC2046 itself.
		InitSPI(FALSE);
		
 		// Enable touch controller interrupt.
		EnableTouchPanelIRQ();
		g_NextExpectedInterrupt = PEN_DOWN;
	}
	InPowerHandler = FALSE;

⌨️ 快捷键说明

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