6182|9

89

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

wince触摸屏驱动要让横坐标反向怎么改?急求~ [复制链接]

我用的是480*800的屏,现在想让触摸屏的(0,0)点的位置变成(800,0)点,纵坐标不变,只是横坐标反过来,请教怎么修改驱动~~~~急盼~~~谢谢大家了 ~~贴上驱动代码
/*++
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.
Copyright (c) 2002. Samsung Electronics, co. ltd  All rights reserved.

Module Name:

  tchpdd.cpp

Abstract:

  This module contains the DDSI implementation and PDD support routines
  for the touch panel for the P2 implementation.

Functions:

  TouchDriverCalibrationPointGet
  DdsiTouchPanelGetDeviceCaps
  DdsiTouchPanelSetMode
  DdsiTouchPanelEnable
  DdsiTouchPanelDisable
  DdsiTouchPanelAttach
  DdsiTouchPanelDetach
  DdsiTouchPanelGetPoint
  DdsiTouchPanelPowerHandler

Notes:


Revision History:


--*/

#define DBGPOINTS1 1
#define TRACE_TIP_STATE

#include   
#include       
#include   
#include   
#include   
#include   
#include   
#include   
//#include   

#include   
#include         "reg.h"

#define SYS_TIMER_PRESCALER        24
//#define SYS_TIMER_DIVIDER 4 // 2
//#define OEM_CLOCK_FREQ (S2440PCLK / (SYS_TIMER_PRESCALER+1) / SYS_TIMER_DIVIDER)

#define JYLEE_TEST 0
#define JYLEE_TEST1 0

//#define TFT240_320        1
//#define TFT640_480        4
//#define LCD_TYPE        TFT240_320
//#define LCD_TYPE        TFT640_480

#if ( LCD_TYPE == TFT640_480 )
        #define ADC_DELAY_TIME        65530
#else
        #define ADC_DELAY_TIME        40000        // yhkim
#endif

DWORD gIntrTouch = SYSINTR_TOUCH;
DWORD gIntrTouchChanged = SYSINTR_TOUCH_CHANGED;

#ifdef TRACE_TIP_STATE
BOOL PenIsUp = TRUE;
#endif

#if defined(MIPS) || defined(PPC821) || defined(PPC823) || defined(ARM) || defined(SH4)
#define PAGE_MASK 0x0fff
#define PAGE_SIZE 0x1000
volatile static PVOID pTmpRegs;
#endif

static void TouchPanelPowerOff();
static void TouchPanelPowerOn();
static BOOL Touch_Timer0_Setup(void) ;

static BOOL Touch_Pen_filtering(INT *px, INT *py);

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

INT                CurrentSampleRateSetting = 0;        //        Low sample rate setting

// @globalvar PTCHAUD_ASIC_REGISTERS | v_pTchAudAsicRegisters | Pointer to Asic regs

PTCHAUD_ASIC_REGISTERS              v_pTchAudAsicRegisters = NULL;

// @globalvar PTOUCHPANEL_POINT_SAMPLE | v_pPenSamples | Pointer to pen samples area
PDRIVER_GLOBALS      v_pDriverGlobals = NULL;

volatile static PVOID v_pCpuRegs = NULL;

TOUCH_PANEL_SAMPLE_FLAGS SampleFlags;

#ifdef CHECK_RATE
    UINT32        tmp_leds = 0x55;
#endif

// Mutex to prevent contention with audio while accessing shared registers
static HANDLE v_hTchAudMutex;

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


// Macros for aquiring semaphore for shared access to ASIC registers. If
// we are in the power handler routines, we don't need/want to aquire semaphore,
// since we are serialized at that point, and can't make any system calls.
#define TCHAUD_SEM_LOCK()  \
    if (!bInPowerHandler) { \
        DEBUGMSG(ZONE_TIPSTATE,(TEXT("TchPDD Getting semaphore...\r\n"))); \
        TchAudLock(v_hTchAudMutex, &(v_pDriverGlobals->tch.semaphore)); \
    }
#define TCHAUD_SEM_UNLOCK() \
    if (!bInPowerHandler) { \
        DEBUGMSG(ZONE_TIPSTATE,(TEXT("TchPDD Releasing semaphore...\r\n"))); \
        TchAudUnlock(v_hTchAudMutex, &(v_pDriverGlobals->tch.semaphore)); \
    }

// Macros for accessing registers on the touch audio ASIC.  The code for
// these functions is in drvlib so it can be shared between touch and audio.
#define ASIC_READ_REG(reg, pval) \
    TchAudReadReg(reg, pval, v_pTchAudAsicRegisters, bInPowerHandler)
#define ASIC_WRITE_REG(reg, val) \
    TchAudWriteReg(reg, val, v_pTchAudAsicRegisters, bInPowerHandler)
#define ASIC_AND_REG(reg, val) \
    TchAudAndReg(reg, val, v_pTchAudAsicRegisters, bInPowerHandler)
#define ASIC_OR_REG(reg, val) \
    TchAudOrReg(reg, val, v_pTchAudAsicRegisters, bInPowerHandler)


volatile IOPreg *v_pIOPregs;
volatile ADCreg *v_pADCregs;
volatile PWMreg *v_pPWMregs;
volatile INTreg *v_pINTregs;   

volatile unsigned short xbuf[10], ybuf[10];
static unsigned int touch_down = 1;

//#define ADCPRS  49        // 200Mhz
#define ADCPRS  49        // 200Mhz
//#define ADCPRS  65                // 532Mhz


static
void
PddpTouchPanelDeallocateVm(
    VOID
    )
{
    if(v_pIOPregs)
    {
        VirtualFree((void*)v_pIOPregs, sizeof(IOPreg), MEM_RELEASE);
        v_pIOPregs=NULL;
    }
    if(v_pADCregs)
    {   
        VirtualFree((void*)v_pADCregs, sizeof(ADCreg), MEM_RELEASE);
        v_pADCregs = NULL;
    }        
    if ( v_pDriverGlobals )
    {
        VirtualFree( v_pDriverGlobals,
                     DRIVER_GLOBALS_PHYSICAL_MEMORY_SIZE ,
                     MEM_RELEASE
                    );
        v_pDriverGlobals = NULL;
    }   
}

//
// PDD Internal Support Routines
//

/*++
    @doc IN_TOUCH_DDSI INTERNAL DRIVERS PDD TOUCH_PANEL

    @func VOID | PddpTouchPanelGetSamples |
    Copies from the pen dma area the most recent point sample into the location
    pointed to by pPointSamples.  During the copy the sample information is
    adjusted to be consistent with the 12 bit pen data format.
    Has the side effect of reinitializing ioPenPointer if we are near the
    end of the pen sample area.
--*/
static
void
PddpTouchPanelGetSamples(
    PTOUCHPANEL_POINT_SAMPLE pPointSamples //@PARM Pointer to where the samples will be stored.
    )
{
    // ULONG   devDrvPointer;
    ULONG   irg;

    //
    // Copy the samples to our buffer munging the data for the 12 bit
    //  pen data format.
    //

    for ( irg = 0; irg < NUMBER_SAMPLES_PER_POINT; irg++ )
    {
        pPointSamples[ irg ].XSample = xbuf[irg];
        pPointSamples[ irg ].YSample = ybuf[irg];
    }
}

/*++

Routine Description:

    Gathers the most recent sample and evaluates the sample returing
    the determined tip state and the `best guess' for the X and Y coordinates.

    Note: Determined empirically that the variance of the X coordinate of the
          first sample from all other samples is large enough that in order
          to keep the nominal variance small, we discard the first sample.

          Cases of a light touch that locks the ADC into
          seeing X and Y coordinate samples of 0x277 regardless of how the pen
          moves or presses have been seen. XXXXX


Arguments:

    pTipState   Pointer to where the tip state information will be returned.

    pUnCalX     Pointer to where the x coordinate will be returned.

    pUnCalY     Pointer to where the y coordinate will be returned.

Return Value:

    None.

Autodoc Information:

    @doc IN_TOUCH_DDI INTERNAL DRIVERS PDD TOUCH_PANEL

    @func VOID | PddpTouchPanelEvaluateSamples |
    Gathers the most recent sample and evaluates the sample returing
    the determined tip state and the `best guess' for the X and Y coordinates.

--*/
此帖出自WindowsCE论坛

最新回复

谢谢~~~没帮上什么忙呢~  详情 回复 发表于 2010-5-7 16:54
点赞 关注
 

回复
举报

82

帖子

0

TA的资源

一粒金砂(初级)

沙发
 
static
void
PddpTouchPanelEvaluateSamples(
    TOUCH_PANEL_SAMPLE_FLAGS        *pSampleFlags, //@PARM Pointer to where the tip state information will be returned.
    INT                                                        *pUncalX,      //@PARM Pointer to where the x coordinate will be returned.
        INT                                                        *pUncalY       //@PARM Pointer to where the y coordinate will be returned.

    )
{
    LONG    dlXDiff0;
    LONG    dlXDiff1;
    LONG    dlXDiff2;
    LONG    dlYDiff0;
    LONG    dlYDiff1;
    LONG    dlYDiff2;

    TOUCHPANEL_POINT_SAMPLES rgPointSamples;

    //
    // Get the sample.
    //

    PddpTouchPanelGetSamples( rgPointSamples );


    //
    // Calcuate the differences for the X samples and insure that
    // the resulting number is positive.
    //

    dlXDiff0 = rgPointSamples[ 0 ].XSample - rgPointSamples[ 1 ].XSample;
    dlXDiff1 = rgPointSamples[ 1 ].XSample - rgPointSamples[ 2 ].XSample;
    dlXDiff2 = rgPointSamples[ 2 ].XSample - rgPointSamples[ 0 ].XSample;
    dlXDiff0 = dlXDiff0 > 0  ? dlXDiff0 : -dlXDiff0;
    dlXDiff1 = dlXDiff1 > 0  ? dlXDiff1 : -dlXDiff1;
    dlXDiff2 = dlXDiff2 > 0  ? dlXDiff2 : -dlXDiff2;

    //
    // Calcuate the differences for the Y samples and insure that
    // the resulting number is positive.
    //

    dlYDiff0 = rgPointSamples[ 0 ].YSample - rgPointSamples[ 1 ].YSample;
    dlYDiff1 = rgPointSamples[ 1 ].YSample - rgPointSamples[ 2 ].YSample;
    dlYDiff2 = rgPointSamples[ 2 ].YSample - rgPointSamples[ 0 ].YSample;
    dlYDiff0 = dlYDiff0 > 0  ? dlYDiff0 : -dlYDiff0;
    dlYDiff1 = dlYDiff1 > 0  ? dlYDiff1 : -dlYDiff1;
    dlYDiff2 = dlYDiff2 > 0  ? dlYDiff2 : -dlYDiff2;

    //
    // The final X coordinate is the average of coordinates of
    // the two MIN of the differences.
    //

    if ( dlXDiff0 < dlXDiff1 )
    {
        if ( dlXDiff2 < dlXDiff0 )
        {

            *pUncalX = (ULONG)( ( ( rgPointSamples[ 0 ].XSample + rgPointSamples[ 2 ].XSample ) >> 1 ) );
        }
        else
        {

            *pUncalX = (ULONG)( ( ( rgPointSamples[ 0 ].XSample + rgPointSamples[ 1 ].XSample ) >> 1 ) );
        }
    }
    else if ( dlXDiff2 < dlXDiff1 )
    {

            *pUncalX = (ULONG)( ( ( rgPointSamples[ 0 ].XSample + rgPointSamples[ 2 ].XSample ) >> 1 ) );
    }
    else
    {

            *pUncalX = (ULONG)( ( ( rgPointSamples[ 1 ].XSample + rgPointSamples[ 2 ].XSample ) >> 1 ) );
    }

    //
    //
    // The final Y coordinate is the average of coordinates of
    // the two MIN of the differences.
    //

    if ( dlYDiff0 < dlYDiff1 )
    {
        if ( dlYDiff2 < dlYDiff0 )
        {

            *pUncalY = (ULONG)( ( ( rgPointSamples[ 0 ].YSample + rgPointSamples[ 2 ].YSample ) >> 1 ) );
        }
        else
        {

            *pUncalY = (ULONG)( ( ( rgPointSamples[ 0 ].YSample + rgPointSamples[ 1 ].YSample ) >> 1 ) );
        }
    }
    else if ( dlYDiff2 < dlYDiff1 )
    {

            *pUncalY = (ULONG)( ( ( rgPointSamples[ 0 ].YSample + rgPointSamples[ 2 ].YSample ) >> 1 ) );
    }
    else
    {

            *pUncalY = (ULONG)( ( ( rgPointSamples[ 1 ].YSample + rgPointSamples[ 2 ].YSample ) >> 1 ) );
    }

    //
    // Validate the coordinates and set the tip state accordingly.
    //

    if ( dlXDiff0 > DELTA_X_COORD_VARIANCE ||
         dlXDiff1 > DELTA_X_COORD_VARIANCE ||
         dlXDiff2 > DELTA_X_COORD_VARIANCE ||
         dlYDiff0 > DELTA_Y_COORD_VARIANCE ||
         dlYDiff1 > DELTA_Y_COORD_VARIANCE ||
         dlYDiff2 > DELTA_Y_COORD_VARIANCE )
    {

//#ifdef DBGPOINTS1
        DEBUGMSG( ZONE_SAMPLES, (TEXT("Sample 0: X 0x%x Y 0x%x\r\n"),
               rgPointSamples[ 0 ].XSample, rgPointSamples[ 0 ].YSample) );
        DEBUGMSG( ZONE_SAMPLES, (TEXT("Sample 1: X 0x%x Y 0x%x\r\n"),
               rgPointSamples[ 1 ].XSample, rgPointSamples[ 1 ].YSample) );
        DEBUGMSG( ZONE_SAMPLES, (TEXT("Sample 2: X 0x%x Y 0x%x\r\n"),
               rgPointSamples[ 2 ].XSample, rgPointSamples[ 2 ].YSample) );


        if ( dlXDiff0 > DELTA_X_COORD_VARIANCE )
            DEBUGMSG( ZONE_SAMPLES, (TEXT("XDiff0 too large 0x%x\r\n"), dlXDiff0) );
        if ( dlXDiff1 > DELTA_X_COORD_VARIANCE )
            DEBUGMSG( ZONE_SAMPLES, (TEXT("XDiff1 too large 0x%x\r\n"), dlXDiff1) );
        if ( dlXDiff2 > DELTA_X_COORD_VARIANCE )
            DEBUGMSG( ZONE_SAMPLES, (TEXT("XDiff2 too large 0x%x\r\n"), dlXDiff2) );

        if ( dlYDiff0 > DELTA_Y_COORD_VARIANCE )
            DEBUGMSG( ZONE_SAMPLES, (TEXT("YDiff0 too large 0x%x\r\n"), dlYDiff0) );
        if ( dlYDiff1 > DELTA_Y_COORD_VARIANCE )
            DEBUGMSG( ZONE_SAMPLES, (TEXT("YDiff1 too large 0x%x\r\n"), dlYDiff1) );
        if ( dlYDiff2 > DELTA_Y_COORD_VARIANCE )
            DEBUGMSG( ZONE_SAMPLES, (TEXT("YDiff2 too large 0x%x\r\n"), dlYDiff2) );

//#endif // DBGPOINTS1

    }
    else
    {
        //
        // Sample is valid. Set tip state accordingly.
        //
                *pSampleFlags = TouchSampleValidFlag | TouchSampleDownFlag;
    }

    DEBUGMSG( ZONE_SAMPLES, (TEXT("Filtered - SampleFlags: 0x%x X: 0x%x Y: 0x%x\r\n"),
           *pSampleFlags, *pUncalX, *pUncalY) );

}

//
// PddpSetupPenDownIntr()
//
// Set up the UCB to give pen down interrupts.  If EnableIntr flag is set, enable
// the interrupt, otherwise, leave it disabled.  Note: - Caller must hold semaphore
// when this function is called to protect access to the shared UCB registers.
//
BOOL
PddpSetupPenDownIntr(BOOL EnableIntr)
{
        // USHORT intrMask;

    // I don't know why we enable the interrupt here.
   
   
    //
    // Setup ADC register
    //

        // kang code
    // Enable Prescaler,Prescaler,AIN5/7 fix,Normal,Disable read start,No operation
    // Down,YM:GND,YP:AIN5,XM:Hi-z,XP:AIN7,XP pullup En,Normal,Waiting for interrupt mode
        // kang code end
    // Down Int, YMON:0, nYPON:1, XMON:0;nXPON:1, Pullup:1, Auto Conv.,Waiting.
    v_pADCregs->rADCTSC =(0<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3);
    //v_pADCregs->rADCTSC=(1<<3)|(1<<2);
    v_pADCregs->rADCDLY = ADC_DELAY_TIME;//default value for delay.   
    v_pADCregs->rADCCON        = (1<<14)|(ADCPRS<<6)|(7<<3);        //setup channel, ADCPRS, Touch Input

        return TRUE;

}

//
// PddpDisableClearPenDownIntr(void)
//
// Tell the UCB to clear pen down interrupts
//
BOOL
PddpDisableClearPenDownIntr(void)
{
    // Acquire semaphore to prevent contention with audio driver while accessing UCB regs
    TCHAUD_SEM_LOCK();

    // Clear bit 12 in UCB address 3 to disable interrupts on falling tspx (tspx_fal_int)
    // Read data from UCB address 0x03
    if (! ASIC_AND_REG(3, ~((USHORT)0x1000)))
        goto error_return;

    // Clear the pen down interrupt
    // Write UCB address 4 bit 12 to a 0
    if (! ASIC_WRITE_REG(4, 0))
        goto error_return;

    // Write UCB address 4 bit 12 to a 1, to clear tspx interrupts
    if (! ASIC_WRITE_REG(4, 0x1000))
        goto error_return;

    TCHAUD_SEM_UNLOCK();
    return TRUE;

error_return:
    RETAILMSG(1,(TEXT("TchPdd: Error accessing UCB register!\r\n")));
    TCHAUD_SEM_UNLOCK();
    return FALSE;
}

//
// DDSI Implementation
//


//        @DOC        EX_TOUCH_DDSI EXTERNAL DRIVERS TOUCH_DRIVER
/*        @FUNC   BOOL | TouchDriverCalibrationPointGet |

Gives a single calibration point.

        @XREF
               
               
               


        @COMM

This function is called to get a single calibration point, in screen
coordinates, when the input system is calibrating the touch driver.  The input system
will then draw a target on the screen for the user to press on.

The driver may use the cDisplayX and cDisplayY to compute a coordinate.
It does not need to remember this computed value internally since it will
be passed back when the input system has collected all of the points and
calls .

*/

extern "C"
BOOL
TouchDriverCalibrationPointGet(
        TPDC_CALIBRATION_POINT        *pTCP //@PARM pointer to returned calibration point
        )
{
   
        INT32        cDisplayWidth = pTCP -> cDisplayWidth;
        INT32        cDisplayHeight = pTCP -> cDisplayHeight;

        int        CalibrationRadiusX = cDisplayWidth/20;
        int        CalibrationRadiusY = cDisplayHeight/20;

        switch (pTCP -> PointNumber)
                {
                case        0:
                        pTCP -> CalibrationX = cDisplayWidth/2;
                        pTCP -> CalibrationY = cDisplayHeight/2;
                        break;

                case        1:
                        pTCP -> CalibrationX = CalibrationRadiusX*2;
                        pTCP -> CalibrationY = CalibrationRadiusY*2;
                        break;

                case        2:
                        pTCP -> CalibrationX = CalibrationRadiusX*2;
                        pTCP -> CalibrationY = cDisplayHeight - CalibrationRadiusY*2;
                        break;

                case        3:
                        pTCP -> CalibrationX = cDisplayWidth - CalibrationRadiusX*2;
                        pTCP -> CalibrationY = cDisplayHeight - CalibrationRadiusY*2;
                        break;

                case        4:
                        pTCP -> CalibrationX = cDisplayWidth - CalibrationRadiusX*2;
                        pTCP -> CalibrationY = CalibrationRadiusY*2;
                        break;

                default:
                        pTCP -> CalibrationX = cDisplayWidth/2;
                        pTCP -> CalibrationY = cDisplayHeight/2;
                        SetLastError(ERROR_INVALID_PARAMETER);
                        return FALSE;
                       

                }
        RETAILMSG(1,(TEXT("TouchDriverCalibrationPointGet\r\n")));
        RETAILMSG(1,(TEXT("cDisplayWidth : %4X\r\n"),cDisplayWidth));
        RETAILMSG(1,(TEXT("cDisplayHeight : %4X\r\n"),cDisplayHeight));
        RETAILMSG(1,(TEXT("CalibrationRadiusX : %4d\r\n"),CalibrationRadiusX));
        RETAILMSG(1,(TEXT("CalibrationRadiusY : %4d\r\n"),CalibrationRadiusY));
        RETAILMSG(1,(TEXT("pTCP -> PointNumber : %4d\r\n"),pTCP -> PointNumber));
        RETAILMSG(1,(TEXT("pTCP -> CalibrationX : %4d\r\n"),pTCP -> CalibrationX));
        RETAILMSG(1,(TEXT("pTCP -> CalibrationY : %4d\r\n"),pTCP -> CalibrationY));
        return TRUE;
}




此帖出自WindowsCE论坛
 
 
 

回复

80

帖子

0

TA的资源

一粒金砂(初级)

板凳
 
重新校准之后是不是就可以用了?
此帖出自WindowsCE论坛
 
 
 

回复

72

帖子

0

TA的资源

一粒金砂(初级)

4
 
extern "C"
BOOL
DdsiTouchPanelGetDeviceCaps(
        INT                iIndex,
    LPVOID  lpOutput
    )
{
        if ( lpOutput == NULL )
                {
                ERRORMSG(1, (__TEXT("TouchPanelGetDeviceCaps: invalid parameter.\r\n")));
                SetLastError(ERROR_INVALID_PARAMETER);
                DebugBreak();
                return FALSE;
                }

        switch        ( iIndex )
                {
                case TPDC_SAMPLE_RATE_ID:
                                {
                                TPDC_SAMPLE_RATE        *pTSR = (TPDC_SAMPLE_RATE*)lpOutput;

                                pTSR -> SamplesPerSecondLow = TOUCHPANEL_SAMPLE_RATE_LOW;
                                pTSR -> SamplesPerSecondHigh = TOUCHPANEL_SAMPLE_RATE_HIGH;
                                pTSR -> CurrentSampleRateSetting = CurrentSampleRateSetting;
                                }
                                break;

                case TPDC_CALIBRATION_POINT_COUNT_ID:
                                {
                                TPDC_CALIBRATION_POINT_COUNT *pTCPC = (TPDC_CALIBRATION_POINT_COUNT*)lpOutput;

                                pTCPC -> flags = 0;
                                pTCPC -> cCalibrationPoints = 5;
                                }
                                break;

                case TPDC_CALIBRATION_POINT_ID:
                                return(TouchDriverCalibrationPointGet((TPDC_CALIBRATION_POINT*)lpOutput));

                default:
                                ERRORMSG(1, (__TEXT("TouchPanelGetDeviceCaps: invalid parameter.\r\n")));
                                SetLastError(ERROR_INVALID_PARAMETER);
                                DebugBreak();
                                return FALSE;

                }

        return TRUE;
}

BOOL
DdsiTouchPanelSetMode(
        INT                iIndex,
    LPVOID  lpInput
    )
{
    BOOL  ReturnCode = FALSE;

    switch ( iIndex )
    {
        case TPSM_SAMPLERATE_LOW_ID:
        case TPSM_SAMPLERATE_HIGH_ID:
            SetLastError( ERROR_SUCCESS );
            ReturnCode = TRUE;
            break;

        default:
            SetLastError( ERROR_INVALID_PARAMETER );
            break;
    }


    return ( ReturnCode );
}


BOOL
DdsiTouchPanelEnable(
    VOID
    )
{
    BOOL    Ret;

    if(v_pIOPregs == NULL) {
            v_pIOPregs = (volatile IOPreg *)
                    VirtualAlloc(0,sizeof(IOPreg),MEM_RESERVE, PAGE_NOACCESS);
            if(v_pIOPregs == NULL) {
                    ERRORMSG(1,(TEXT("For IOPreg: VirtualAlloc failed!\r\n")));
                    return (FALSE);
            }
            else {
                    if(!VirtualCopy((PVOID)v_pIOPregs,(PVOID)(IOP_BASE),sizeof(IOPreg),
                            PAGE_READWRITE | PAGE_NOCACHE )) {
                            ERRORMSG(1,(TEXT("For pIOPregs: VirtualCopy failed!\r\n")));
                PddpTouchPanelDeallocateVm();
                            return (FALSE);
                    }
            }
        }
       

    if(v_pADCregs == NULL) {
            v_pADCregs = (volatile ADCreg *)
                    VirtualAlloc(0,sizeof(ADCreg),MEM_RESERVE, PAGE_NOACCESS);
            if(v_pADCregs == NULL) {
                    ERRORMSG(1,(TEXT("For ADCreg: VirtualAlloc failed!\r\n")));
                    return (FALSE);
            }
            else {
                    if(!VirtualCopy((PVOID)v_pADCregs,(PVOID)(ADC_BASE),sizeof(ADCreg),
                            PAGE_READWRITE | PAGE_NOCACHE )) {
                            ERRORMSG(1,(TEXT("For pADCregs: VirtualCopy failed!\r\n")));
                PddpTouchPanelDeallocateVm();
                            return (FALSE);
                    }
            }
        }

    if(v_pPWMregs == NULL) {
            v_pPWMregs = (volatile PWMreg *)
                    VirtualAlloc(0,sizeof(PWMreg),MEM_RESERVE, PAGE_NOACCESS);
            if(v_pPWMregs == NULL) {
                    ERRORMSG(1,(TEXT("For PWMreg: VirtualAlloc failed!\r\n")));
                    return (FALSE);
            }
            else {
                    if(!VirtualCopy((PVOID)v_pPWMregs,(PVOID)(PWM_BASE),sizeof(PWMreg),
                            PAGE_READWRITE | PAGE_NOCACHE )) {
                            ERRORMSG(1,(TEXT("For PWMreg: VirtualCopy failed!\r\n")));
                            return (FALSE);
                    }
            }
        }
       

    if(v_pINTregs == NULL) {
            v_pINTregs = (volatile INTreg *)
                    VirtualAlloc(0,sizeof(INTreg),MEM_RESERVE, PAGE_NOACCESS);
            if(v_pINTregs == NULL) {
                    ERRORMSG(1,(TEXT("For INTreg: VirtualAlloc failed!\r\n")));
                    return (FALSE);
            }
            else {
                    if(!VirtualCopy((PVOID)v_pINTregs,(PVOID)(INT_BASE),sizeof(INTreg),
                            PAGE_READWRITE | PAGE_NOCACHE )) {
                            ERRORMSG(1,(TEXT("For INTreg: VirtualCopy failed!\r\n")));
                            return (FALSE);
                    }
            }
        }


    if ( v_pDriverGlobals == NULL )
    {
        v_pDriverGlobals =
            (PDRIVER_GLOBALS)
                  VirtualAlloc( 0,
                                DRIVER_GLOBALS_PHYSICAL_MEMORY_SIZE,
                                MEM_RESERVE,
                                PAGE_NOACCESS
                              );
        if ( v_pDriverGlobals == NULL )
        {
            DEBUGMSG( ZONE_ERROR, (TEXT( "TouchPanelEnable: VirtualAlloc failed!\r\n")) );
            PddpTouchPanelDeallocateVm();
            return ( FALSE );
        }

        Ret = VirtualCopy( (LPVOID)v_pDriverGlobals,
                           (LPVOID)DRIVER_GLOBALS_PHYSICAL_MEMORY_START,
                           DRIVER_GLOBALS_PHYSICAL_MEMORY_SIZE,
                           PAGE_READWRITE | PAGE_NOCACHE
                           );

        if ( Ret == FALSE )
        {
            DEBUGMSG( ZONE_ERROR, (TEXT( "TouchPanelEnable: VirtualCopy failed!\r\n")) );
            PddpTouchPanelDeallocateVm();
            return ( FALSE );
        }
    }

    // Set up mutex for access to shared registers
    if ((v_hTchAudMutex = CreateMutex(NULL, FALSE, TCHAUD_MUTEX_NAME)) == NULL) {
        DEBUGMSG(ZONE_ERROR, (TEXT("TouchPanelEnable: Error %u in CreateMutex\r\n"),
                              GetLastError()));
        return ( FALSE );
    }


    // Power on touch panel
    TouchPanelPowerOn();





此帖出自WindowsCE论坛
 
 
 

回复

80

帖子

0

TA的资源

一粒金砂(初级)

5
 
   // Setup pen down interrupts, but leave ints disabled until InterruptEnable().
    TCHAUD_SEM_LOCK();
    PddpSetupPenDownIntr(FALSE);
    TCHAUD_SEM_UNLOCK();

    return( TRUE );     // we always succeed!!!!!!
}




VOID
DdsiTouchPanelDisable(
    VOID
    )
{
        if(v_pADCregs == NULL)
        return ;

    TouchPanelPowerOff();  
    PddpTouchPanelDeallocateVm();  }



LONG
DdsiTouchPanelAttach(
    VOID
    )
{
    return( 1 );
}



LONG
DdsiTouchPanelDetach(
    VOID
    )
{
    return ( 0 );
}

#define COODI_Y

#define TOUCH_MAX_X 1000 // 950
#define TOUCH_MIN_X 30 // 90
#define TOUCH_MAX_Y 980 // 960 // 910
#define TOUCH_MIN_Y 30 // 70 //50
#define TOUCH_X        800
#define TOUCH_Y        480

#define TOUCH_ERR        50

static int second = 0;

VOID Touch_CoordinateConversion(INT *px, INT *py)
{
        INT TmpX, TmpY;
        INT TmpX0, TmpY0;
       
        TmpX0 = *px; TmpY0 = *py;
       
        TmpX = (*px >= TOUCH_MAX_X) ? (TOUCH_MAX_X-1) : *px;
        TmpY = (*py >= TOUCH_MAX_Y) ? (TOUCH_MAX_Y-1) : *py;

       
    TmpX -= TOUCH_MIN_X;
    TmpY -= TOUCH_MIN_Y;

//#ifdef YC_2440_SUPPORT
#ifndef YC_2440_SUPPORT
        TmpX = (TmpX >= 0) ? TmpX : 0;
    TmpY = (TmpY >= 0) ? TmpY : 0;
#else
    TmpX = (TmpX) ? TmpX : 0;
    TmpY = (TmpY) ? TmpY : 0;
#endif
   
*px = ((TmpX * TOUCH_X) / (TOUCH_MAX_X-TOUCH_MIN_X))*4;
*py = ((TmpY * TOUCH_Y) / (TOUCH_MAX_Y-TOUCH_MIN_Y))*4;

//RETAILMSG(1, (TEXT("*px0== %d\r\n"), *px));
//#ifdef YC_2440_SUPPORT
#ifndef YC_2440_SUPPORT
#ifdef        INVERSE_X
        *px = TOUCH_X*4 - 1 - *px;
#endif
#ifdef        INVERSE_Y
        *py = TOUCH_Y*4 - 1 - *py;
#endif
#endif
RETAILMSG(1, (TEXT("*px0== %d\r\n"), *px));
RETAILMSG(1, (TEXT("*py0== %d\r\n"), *py));       
        return;
}


VOID
DdsiTouchPanelGetPoint(
        TOUCH_PANEL_SAMPLE_FLAGS        *pTipStateFlags,
        INT                                *pUncalX,
        INT                                *pUncalY
    )
{
        ULONG status;
        // USHORT ioAdcCntr;
        // USHORT intrMask;
        static int SampleCount = 0;
        static TOUCH_PANEL_SAMPLE_FLAGS PrevStateFlags = TouchSampleIgnore;
        static INT PrevX = 0;
        static INT PrevY = 0;
        TOUCH_PANEL_SAMPLE_FLAGS TmpStateFlags;
        INT TmpX = 0;
        INT TmpY = 0;
        int i;
   
    RETAILMSG(1, (TEXT(":::::::::::: DdsiTouchPanelGetPoint routine !!!\r\n")));

    // Read the status passed back by the HAL
    status = READ_REGISTER_ULONG( &(v_pDriverGlobals->tch.status) );

    if(status == TOUCH_PEN_UP) {
                v_pADCregs->rADCTSC = 0xD3;        // Set stylus down interrupt
                *pTipStateFlags = TouchSampleValidFlag;
                *pUncalX = PrevX;
                *pUncalY = PrevY;
                InterruptDone( gIntrTouchChanged );
       
                RETAILMSG(0, (TEXT("8 - (%d, %d) 0x%X\r\n"), *pUncalX, *pUncalY, *pTipStateFlags));
    }
    else if(status == TOUCH_PEN_DOWN){
                *pTipStateFlags = TouchSampleIgnore;
                *pUncalX = PrevX;
                *pUncalY = PrevY;
                Touch_Timer0_Setup();
                InterruptDone( gIntrTouchChanged );

                RETAILMSG(0, (TEXT("9 - (%d, %d) 0x%X\r\n"), *pUncalX, *pUncalY, *pTipStateFlags));
        }
        else {               
                if( (v_pADCregs->rADCDAT0 & 0x8000) || (v_pADCregs->rADCDAT1 & 0x8000) ){
                        v_pADCregs->rADCTSC = 0xD3;        // Set stylus down interrupt
                        *pTipStateFlags = TouchSampleValidFlag;
                        *pUncalX = PrevX;
                        *pUncalY = PrevY;
                        InterruptDone( gIntrTouchChanged );
                        RETAILMSG(0, (TEXT("91 - (%d, %d) 0x%X\r\n"), *pUncalX, *pUncalY, *pTipStateFlags));
                }
                else{                // charlie
                        //

                        for (i =0; i < 3; i++) {
                                // v_pADCregs->rADCTSC=(0<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(1<<3)|(1<<2)|(0);
                                v_pADCregs->rADCTSC=(1<<3)|(1<<2);
                                // Stylus Down,Don't care,Don't care,Don't care,Don't care,XP pullup Dis,Auto,No operation
                                v_pADCregs->rADCCON|=0x1;        // Start Auto conversion

                                while(v_pADCregs->rADCCON & 0x1);                //check if Enable_start is low
                                while(!(0x8000&v_pADCregs->rADCCON));        // Check ECFLG
//#ifdef YC_2440_SUPPORT
#ifndef YC_2440_SUPPORT
                                xbuf = 0x3ff & v_pADCregs->rADCDAT0;
                                ybuf = 0x3ff & v_pADCregs->rADCDAT1;
#else               
                                ybuf = 0x3ff - (0x3ff & v_pADCregs->rADCDAT0);
                                //xbuf = 0x3ff & v_pADCregs->rADCDAT1;
                                xbuf = 0x3ff-(0x3ff & v_pADCregs->rADCDAT1); //fhg
#endif
                        }       

                         PddpTouchPanelEvaluateSamples( &TmpStateFlags, &TmpX, &TmpY);
       
       
                        v_pADCregs->rADCTSC=(1<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3);
       
                        Touch_CoordinateConversion(&TmpX, &TmpY);   
                       
                       
                        if (Touch_Pen_filtering(&TmpX, &TmpY)) // Valid touch pen
                    {
                            //RETAILMSG(1, (TEXT("valid touch pen\r\n")));
                                *pTipStateFlags = TouchSampleValidFlag | TouchSampleDownFlag;                       
                                *pTipStateFlags &= ~TouchSampleIgnore;
                        }
                        else        // Invalid touch pen
                        {
                            //RETAILMSG(1, (TEXT("invalid touch pen\r\n")));
                                *pTipStateFlags = TouchSampleValidFlag;
                                *pTipStateFlags |= TouchSampleIgnore;                               
                        }               
                        *pUncalX = PrevX = TmpX;
                        *pUncalY = PrevY = TmpY;
       
                           InterruptDone( gIntrTouch );
                          
                           RETAILMSG(0, (TEXT("0 - (%d, %d) 0x%X\r\n"), *pUncalX, *pUncalY, *pTipStateFlags));

                }
        }

    return;

}

#define FILTER_LIMIT 25

static BOOL
Touch_Pen_filtering(INT *px, INT *py)
{
        BOOL RetVal = TRUE;
        // TRUE  : Valid pen sample
        // FALSE : Invalid pen sample
        static int count = 0;
        static INT x[2], y[2];
        INT TmpX, TmpY;
        INT dx, dy;
       

        count++;

        if (count > 2)
        { // apply filtering rule

                count = 2;
               
                // average between x,y[0] and *px,y
                TmpX = (x[0] + *px) / 2;
                TmpY = (y[0] + *py) / 2;
               
                // difference between x,y[1] and TmpX,Y
                dx = (x[1] > TmpX) ? (x[1] - TmpX) : (TmpX - x[1]);
                dy = (y[1] > TmpY) ? (y[1] - TmpY) : (TmpY - y[1]);
               
                if ((dx > FILTER_LIMIT) || (dy > FILTER_LIMIT)) {
                        // Invalid pen sample
                        *px = x[1];
                        *py = y[1]; // previous valid sample

                        RetVal = FALSE;
                        count = 0;
                }
                else               
                {                       
                        // Valid pen sample
                        x[0] = x[1]; y[0] = y[1];               
                        x[1] = *px; y[1] = *py; // reserve pen samples
                       
                        RetVal = TRUE;
                        //RETAILMSG(1, (TEXT("RetVal = TRUE\r\n")));
                }
               
        } else { // till 2 samples, no filtering rule
       
                x[0] = x[1]; y[0] = y[1];               
                x[1] = *px; y[1] = *py; // reserve pen samples
               
                RetVal = FALSE;        // <- TRUE jylee 2003.03.04
        }
       
        //if (RetVal==FALSE) {
        //}
        return RetVal;
}

void
DdsiTouchPanelPowerHandler(
        BOOL        bOff
        )
{
    // USHORT mask;

    // Set flag so we know to avoid system calls
    bInPowerHandler = TRUE;

    if (bOff) {
        TouchPanelPowerOff();
    }
    else {
        TouchPanelPowerOn();
        PddpSetupPenDownIntr(TRUE);
    }

    bInPowerHandler = FALSE;
}

static void
TouchPanelPowerOff()
{
    // Powering down, stop DMA and power off touch screen
    RETAILMSG(0,(TEXT("Touch Power Off\r\n")));
}


static void
TouchPanelPowerOn()
{
    DWORD tmp = 0;

   
    RETAILMSG(1,(TEXT("Touch Init\r\n")));


#ifdef YC_2440_SUPPORT
    // Clear GPG15, 14, 13, 12
    v_pIOPregs->rGPGCON &= ~((0x03 << 30)|(0x03 << 28)|(0x03 << 26)|(0x03 << 24));
    // Set GPG15 to use as nYPON, GPG14 to use as YMON, GPG13 to use as nXPON, GPG12 to use as XMON
    v_pIOPregs->rGPGCON |= ((0x01 << 30)|(0x01 << 28)|(0x01 << 26)|(0x01 << 24));
    // Disable full up function
    v_pIOPregs->rGPGUP |= ((0x01 << 15)|(0x01 << 14)|(0x01 << 13)|(0x01 << 12));
#endif
       v_pADCregs->rADCTSC = (0<<8)|(1<<7)|(1<<6)|(0<<5)|(1<<4)|(0<<3)|(0<<2)|(3);
    //v_pADCregs->rADCTSC=(1<<3)|(1<<2);
        v_pADCregs->rADCDLY = ADC_DELAY_TIME;//default value for delay.   
    v_pADCregs->rADCCON        = (1<<14)|(ADCPRS<<6)|(7<<3);        //setup channel, ADCPRS, Touch Input

        return ;
}


static BOOL Touch_Timer0_Setup(void) {
        unsigned int TmpTCON;

        v_pINTregs->rINTMSK |= BIT_TIMER1;     // Mask timer1 interrupt.
    v_pINTregs->rSRCPND = BIT_TIMER1;     // Clear pending bit
    v_pINTregs->rINTPND = BIT_TIMER1;

    //we operate our board with PCLK=203M/4 = 50750000Hz (50.75 Mhz)   
        v_pPWMregs->rTCFG0 &= ~(0xff);                /* Prescaler 1's Value                        */
    v_pPWMregs->rTCFG0 |= (PRESCALER); // prescaler value = 24 + 1
          v_pPWMregs->rTCFG1 &= ~(0xf<<4);
#if( SYS_TIMER_DIVIDER == 2 )
          v_pPWMregs->rTCFG1  |=  (0   << 4);                /* 1/2                                                        */
#elif ( SYS_TIMER_DIVIDER == 4 )
          v_pPWMregs->rTCFG1  |=  (1   << 4);                /* 1/4                                                        */
#elif ( SYS_TIMER_DIVIDER == 8 )
          v_pPWMregs->rTCFG1  |=  (2   << 4);                /* 1/8                                                        */
#elif ( SYS_TIMER_DIVIDER == 16 )
          v_pPWMregs->rTCFG1  |=  (3   << 4);                /* 1/16                                                        */
#endif
       
    v_pPWMregs->rTCNTB1 = (10 * (S2440PCLK / (PRESCALER+1) / SYS_TIMER_DIVIDER)) / 1000;                // 10msec, Charlie
                                                       
    v_pPWMregs->rTCMPB1 = 0;          

        TmpTCON = v_pPWMregs->rTCON;        // get TCON value to temp TCON register
        TmpTCON &= ~0xf00;                             // clear fields of Timer 1
        TmpTCON |= 0x200;                             // interval mode(auto reload), update TCVNTB4, stop
        v_pPWMregs->rTCON = TmpTCON;        // put the value to TCON register

        TmpTCON = v_pPWMregs->rTCON;        // get TCON value to temp TCON register
        TmpTCON &= ~0xf00;                             // clear fields of Timer 1
        TmpTCON |= 0x100;                             // interval mode, no operation, start for Timer 4
        v_pPWMregs->rTCON = TmpTCON;        // put the value to TCON register

    v_pINTregs->rINTMSK &= ~BIT_TIMER1;   

        return TRUE;   
}   
       
此帖出自WindowsCE论坛
 
 
 

回复

69

帖子

0

TA的资源

一粒金砂(初级)

6
 
引用 2 楼 kacyquan 的回复:
重新校准之后是不是就可以用了?

我需要改驱动。。因为开机就不进系统了没法校准~
此帖出自WindowsCE论坛
 
 
 

回复

68

帖子

0

TA的资源

一粒金砂(初级)

7
 
可以开机的时候打开校准画面,之后把CalibrationData的值,记下来。下次make的时候直接把这个值写到注册表里面就准了啊~
或者直接把触摸屏的X+和X-两跳线对调一下吧~
此帖出自WindowsCE论坛
 
 
 

回复

76

帖子

0

TA的资源

一粒金砂(初级)

8
 
引用 6 楼 kacyquan 的回复:
可以开机的时候打开校准画面,之后把CalibrationData的值,记下来。下次make的时候直接把这个值写到注册表里面就准了啊~
或者直接把触摸屏的X+和X-两跳线对调一下吧~

。。。不能换线。。。我们头不让换~~~
恩。。。谢谢了。。呵呵 我的问题解决了
改了驱动
此帖出自WindowsCE论坛
 
 
 

回复

76

帖子

0

TA的资源

一粒金砂(初级)

9
 
引用 6 楼 kacyquan 的回复:
可以开机的时候打开校准画面,之后把CalibrationData的值,记下来。下次make的时候直接把这个值写到注册表里面就准了啊~
或者直接把触摸屏的X+和X-两跳线对调一下吧~

分分给你~~·
此帖出自WindowsCE论坛
 
 
 

回复

63

帖子

0

TA的资源

一粒金砂(初级)

10
 
谢谢~~~没帮上什么忙呢~
此帖出自WindowsCE论坛
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/9 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表