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

📄 touch.cpp

📁 PXA270 MainstoneII平台下完整触摸屏驱动源码
💻 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

// WM9712_CODEC
#define WM9712_CODEC                                1   

//------------------------------------------------------------------------------
// 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)
{

#if WM9712_CODEC     // For WM9712

	CPLD_BCR_TJ   psCPLDBcr0;
	UINT16 adcControl1 = 0;
	UINT16 adcControl2 = 0;
	DEBUGMSG(DEBUG_FUNC, (TEXT("+DdsiTouchPanelPowerHandler\r\n")));
	if( PowerOff )
	{
        // Unconfigure the AC97 controller.
        UnConfigureAC97Control();
	}
	else
	{
		DEBUGMSG(DEBUG_FUNC, (TEXT("Touch Power ON\r\n")));
		// Power ON WM9712
		CPLD_RegMap(&psCPLDBcr0, BCR0_REG, TURE);
		SetCPLDBcrReg(&psCPLDBcr0, AUDIO_PWR_ON, BCR_BIT_SET, TRUE);
	}

	// Initialize the AC97 link.
    //
    if (!InitializeACLink(FALSE, DEV_TOUCH))
    {
        DEBUGMSG(DEBUG_ERROR, (TEXT("-DdsiTouchPanelPowerHandler, InitializeACLink Fail !\r\n")));
		return(FALSE);
    }

	Ac97WarmReset();

	// Configure the AC97 controller.
	//
	ConfigureAC97Control();

	// Config WM9712 Codec for TouchPanel part    set 76h
	adcControl1 = WM9712_DC1_COO | WM9712_DC1_DEL;
	WriteAC97Raw(WM9712_DIGITISER_CONTROL1, adcControl1, DEV_TOUCH);
	
	//Set PULL-UP resistor for Pen detection bits in register 78h
	adcControl2 = WM9712_DC2_PRP | WM9712_DC2_WAIT | WM9712_DC2_RPU;
	WriteAC97Raw(WM9712_DIGITISER_CONTROL2, adcControl2, DEV_TOUCH);

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

#else

// UCB1x00 CODEC defines
	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();
    }

#endif   //WM9712_CODEC

	DEBUGMSG(DEBUG_FUNC, (TEXT("-DdsiTouchPanelPowerHandler !\r\n")));
}


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

	// For WM9712 Codec
	DEBUGMSG(DEBUG_FUNC, (TEXT("+EnableTouchInterrupt !\r\n")));

	UINT16 gpioPinConfig = 0;
	// Set up GPIO3 on WM9712 to be Pendown signal
	ReadAC97Raw(WM9712_GPIO_PIN_CONFIG, (unsigned short *)&gpioPinConfig, DEV_TOUCH);
	gpioPinConfig &= ~PENDOWN_GPIO; // Set 4Ch, bit 3 to 0 to output PENDOWN signal
	WriteAC97Raw(WM9712_GPIO_PIN_CONFIG, gpioPinConfig, DEV_TOUCH);


	ReadAC97Raw(WM9712_GPIO_PIN_SHARING, (unsigned short *)&gpioPinConfig, DEV_TOUCH);
	gpioPinConfig &= ~PENDOWN_GPIO; // Set 56h, bit 3 to select PENDOWN output
	WriteAC97Raw(WM9712_GPIO_PIN_SHARING, gpioPinConfig, DEV_TOUCH);

	DEBUGMSG(DEBUG_FUNC, (TEXT("-EnableTouchInterrupt !\r\n")));
}


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

	// For WM9712 Codec
	DEBUGMSG(DEBUG_FUNC, (TEXT("+PenIsDown\r\n")));

	UNINT16 adcDataReg;
	ReadAC97Raw(WM9712_DIGITISER_DATA, (unsigned short *)&adcDataReg, DEV_TOUCH);
	if (adcDataReg & WM9712_DATA_PENDOWN)
	{
		return(TRUE);
	}
	else
	{
		return(FALSE);
	}
	DEBUGMSG(DEBUG_FUNC, (TEXT("-PenIsDown\r\n")));
}

⌨️ 快捷键说明

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