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

📄 touch.cpp.svn-base

📁 PXA270 平台 Windows Mobile 5。0 UCB1400 触摸屏驱动
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
//
// 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 ?1999,2000,2001 Intel Corp.  */
/*++

Module Name:  tchpdd.c

Abstract:  
 Intel XSC1 StrongARM  platform touch driver routines.

Notes:
 Created: July 22, 1997
 Modified January 17, 2002

--*/
//------------------------------------------------------------------------------
// Include Files
//------------------------------------------------------------------------------
#include <windows.h>
#include <nkintr.h>
#include <tchddsi.h>
#include <bsp.h>
#include "touch.h"
#include "aclink.h"
#include "ipm_drvCommon.h"

//------------------------------------------------------------------------------
// Defines
//------------------------------------------------------------------------------
#define REV_2A    0x2a0
#define REV_1B    0x2a

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

//------------------------------------------------------------------------------
// Local Variables
//------------------------------------------------------------------------------
static EXPECTED_INT_EVENT g_NextExpectedInterrupt = PEN_DOWN;
static UINT32 g_ResetCaps;
HANDLE					KeepAliveEvent;
HANDLE				    hSharedMap_init;
#define IPM_SHARED_FILENAME   (TEXT("IPMGlobalsFile"))
volatile IPM_GLOBALS  *v_pIPMGlobals = NULL;

DWORD gIntrTouch        = SYSINTR_TOUCH;
DWORD gIntrTouchChanged = SYSINTR_TOUCH_CHANGED;

static volatile BULVERDE_INTR_REG  *g_pICRegs   = NULL;
static volatile BULVERDE_OST_REG   *g_pOSTRegs  = NULL;
static volatile BULVERDE_GPIO_REG  *g_pGPIORegs = NULL;

HANDLE gTouchCtrlEvt[2];
const TCHAR szTchEnable[] = TEXT("TouchEnableEvent");
const TCHAR szTchDisable[] = TEXT("TouchDisableEvent");
int WINAPI TouchCtrlThread(void);
//------------------------------------------------------------------------------
// External Functions
//------------------------------------------------------------------------------
void IPM_TouchInit(void)
{
//	NKDbgPrintfW(TEXT("+Inside IPM Touch Init\r\n"));

	// 
	// An Event to signal IPM that there has been activity and immidiately leave its low power state.
	//
	KeepAliveEvent		= CreateEvent(NULL, FALSE, FALSE, KEEP_ALIVE_STR);

	//
	// Used to tell IPM which driver has timed out.
	//
	hSharedMap_init = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
									0, sizeof(IPM_GLOBALS), IPM_SHARED_FILENAME );

	// Get a valid process pointer to the buffer mapped above.
    v_pIPMGlobals = (volatile IPM_GLOBALS *)MapViewOfFile( hSharedMap_init, FILE_MAP_ALL_ACCESS, 0, 0, 0 );
}

void IPM_RegisterTouchActivity(void)
{
	v_pIPMGlobals->DeviceTimeOutTimes[DEVICE_TOUCH] =GetTickCount();

	//
	// Signal IPM of touch Activity only if need be
	//
//	NKDbgPrintfW(TEXT("IPM_RegisterTouchActivity\r\n"));
	if((v_pIPMGlobals->ProcessorState == PROC_STANDBY) || (v_pIPMGlobals->ProcessorState == THIRTEEN_M))
	{
		//NKDbgPrintfW(TEXT("touch alive!\r\n"));
		SetEvent(KeepAliveEvent);							
	}
}

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

BOOL DdsiTouchPanelEnable(void)
{

    // Allocate touch panel resources (map registers, etc.).
    //
    NKDbgPrintfW(TEXT("++ Touch Init...\r\n"));
	IPM_TouchInit();
    if (!AllocateTouchPanelResources())
    {
        return(FALSE);
    }

    // Initialize the AC97 link.
    //
    if (!InitializeACLink(FALSE, DEV_TOUCH))
    {
        return(FALSE);
    }

    //HACK: If the capabiliters reads 0x2a0 it's rev 2a, if its 0x2a then its rev 1b .
    ReadAC97(0, (UINT16 *)&g_ResetCaps, DEV_TOUCH);
    // Enable the touch controller.
    //
    DdsiTouchPanelPowerHandler(FALSE);
    
    gTouchCtrlEvt[0] = CreateEvent(NULL, FALSE, FALSE, szTchEnable);
    gTouchCtrlEvt[1] = CreateEvent(NULL, FALSE, FALSE, szTchDisable);    

    if(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) TouchCtrlThread, NULL, 0, NULL)==NULL)
      	return FALSE;
        	    
    return(TRUE);     
}


void DdsiTouchPanelDisable(void)
{

    // Clean up any PDD-allocated resources and deinitialize the AC link.
    //
    DeallocateTouchPanelResources();

    DeInitializeACLink(FALSE, DEV_TOUCH);

}


static BOOL AllocateTouchPanelResources(void)
{
    PHYSICAL_ADDRESS RegPA;

    if (g_pICRegs == NULL)
    {
        RegPA.QuadPart = BULVERDE_BASE_REG_PA_INTC;
        g_pICRegs = (volatile BULVERDE_INTR_REG *) MmMapIoSpace(RegPA, 0x400, FALSE);
    }

    if (g_pGPIORegs == NULL)
    {
        RegPA.QuadPart = BULVERDE_BASE_REG_PA_GPIO;
        g_pGPIORegs = (volatile BULVERDE_GPIO_REG *) MmMapIoSpace(RegPA, 0x400, FALSE);
    }

    if (g_pOSTRegs == NULL)
    {
        RegPA.QuadPart = BULVERDE_BASE_REG_PA_OST;
        g_pOSTRegs = (volatile BULVERDE_OST_REG *) MmMapIoSpace(RegPA, 0x400, FALSE);
    }

    if (!g_pOSTRegs  || !g_pGPIORegs || !g_pICRegs)
    {
        DEBUGMSG(1, (TEXT("ERROR: Failed to allocate touch panel resources (Error=%u).\r\n"), GetLastError()));
        DeallocateTouchPanelResources();
        return(FALSE);
    }
     UCB1X00_TOUCH_FUNCTION_0_SET;
     UCB1X00_TOUCH_DIRECTION_IN_SET;
     UCB1X00_TOUCH_RISING_EDGE_SET;
     UCB1X00_TOUCH_FALLING_EDGE_CLR;
 //    g_pICRegs->icmr|=XLLP_INTC_GPIOXX_2;
    return(TRUE);
}


static void DeallocateTouchPanelResources(void)
{
    if (g_pICRegs)
    {
        VirtualFree((void *)g_pICRegs, 0, MEM_RELEASE);
        g_pICRegs = NULL;
    }
    if (g_pOSTRegs)
    {
        VirtualFree((void *)g_pOSTRegs, 0, MEM_RELEASE);
        g_pOSTRegs = NULL;
    }
    if (g_pGPIORegs)
    {
        VirtualFree((void *)g_pGPIORegs, 0, MEM_RELEASE);
        g_pGPIORegs = NULL;
    }
}


void DdsiTouchPanelPowerHandler(BOOL PowerOff)
{    
    UINT16 TCR = 0;

    if (PowerOff)
    {               
    		UCB1X00_TOUCH_INT_SET;      
    		UCB1X00_TOUCH_RISING_EDGE_CLR ;
      // Disable interrupts.
        //
        WriteAC97(UCB_FE_IE, 0, DEV_TOUCH);

        // Unconfigure the AC97 controller.
        UnConfigureAC97Control();      
    }
    else
    {
         // Configure the AC97 controller.
        //
        ConfigureAC97Control();
        XllpOstDelayMicroSeconds((P_XLLP_OST_T) g_pOSTRegs, 1000);
        // At power-on, the first interrupt we expect is a pen-down interrupt.
        //
        g_NextExpectedInterrupt = PEN_DOWN;
        // Enable the touch controller interrupt.
        //
        EnableTouchInterrupt(); 
        UCB1X00_TOUCH_RISING_EDGE_SET;
    }
    
}


BOOL SetUCB1400TouchInterruptMode(void)
{
    UINT16 TCH_CR = 0;

    if (g_ResetCaps == REV_2A)
    {
        TCH_CR = (TSMY_GND | TSPY_GND | TSMX_POW | TSPX_POW);
    }
    else
    {
        TCH_CR = (TSMY_GND | TSPY_GND);
    }

    return(WriteAC97(UCB_TCH_CR, TCH_CR, DEV_TOUCH));
}


LONG DdsiTouchPanelAttach()
{
    return(0); 
}


LONG DdsiTouchPanelDetach()
{
    return(0);
}


static void EnableTouchTimerInterrupt(UINT32 TimeInterval)
{
    UINT32 TimerMatch;
    XLLP_OST_HANDLE_T    XllpOSTHandle;

    // Obtain pointers to OST and INTC registers.
    //
    XllpOSTHandle.pOSTRegs  = (XLLP_OST_T *)  g_pOSTRegs;
    XllpOSTHandle.pINTCRegs = (XLLP_INTC_T *) g_pICRegs;

    // XLLI initializes oier and rtsr to zeroes, so no further
    // initialization needs to be done.  Match timers and
    // alarms are disabled.
    //
    // Current usage of Match registers:
    //  M0 - Scheduler
    //  M1 - Touch Panel
    //  M2 - Profiler

    // Configure and arm the timer interrupt  to interrupt every specified system tick interval.
    //
    TimerMatch = (XllpOSTHandle.pOSTRegs->oscr0 + TimeInterval);
    XllpOstConfigureTimer (&XllpOSTHandle, MatchReg1, TimerMatch);

}


static void EnableTouchInterrupt(void)
{

    // Put the UCB1400 into touch interrupt mode.
    //
    SetUCB1400TouchInterruptMode();
    XllpOstDelayMicroSeconds((P_XLLP_OST_T) g_pOSTRegs, 1000);
    UCB1X00_TOUCH_INT_SET;
    UCB1X00_TOUCH_RISING_EDGE_SET;
    // Enable TSPX interrupt (active low).
    //
    WriteAC97(UCB_FE_IE, TSPX_INT, DEV_TOUCH);
}


BOOL PrepareNextInterrupt(void)
{

    if (g_NextExpectedInterrupt == PEN_DOWN)
    {
        // Enable the touch controller interrupt and configure it for a falling edge detection.
        EnableTouchInterrupt();
    }
    else
    {
        // Re/arm the sample timer.
        EnableTouchTimerInterrupt(TOUCH_TIMER_INCREMENT);
    }

    return(TRUE);
}


BOOL PenIsDown(void)
{
    UINT16 TCH_CR = 0;

    if (SetUCB1400TouchInterruptMode())

⌨️ 快捷键说明

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