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

📄 touch.cpp

📁 PXA270平台下WINCE6.0的触摸屏控制驱动
💻 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.
//
/* 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"

//------------------------------------------------------------------------------
// 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;

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;

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

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

BOOL DdsiTouchPanelEnable(void)
{

    // Allocate touch panel resources (map registers, etc.).
    //
    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);

    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);
    }

    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)
    {
        // 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();
    }
}


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);

    // 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())
    {
        XllpOstDelayMicroSeconds((P_XLLP_OST_T) g_pOSTRegs, 250);
        ReadAC97(UCB_TCH_CR, &TCH_CR, DEV_TOUCH);
    }

    return((TCH_CR & TSPX_LOW) ? FALSE : TRUE);
}


void DdsiTouchPanelGetPoint(TOUCH_PANEL_SAMPLE_FLAGS *pTipStateFlags, INT *pUncalX, INT *pUncalY)
{
    static BOOL TouchIrq = TRUE;
    UINT32 InterruptType = SYSINTR_NOP;

    if (!pTipStateFlags || !pUncalX || !pUncalY)
    {
        DEBUGMSG(TRUE, (TEXT("ERROR: DdsiTouchPanelGetPoint: Invalid parameter(s).\r\n")));
        return;
    }

⌨️ 快捷键说明

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