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

📄 s3c2410x_touch.cpp

📁 SMDK2410_ZY_V11.rar
💻 CPP
📖 第 1 页 / 共 3 页
字号:

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

}


//#define TOUCH_MAX_X    920
//#define TOUCH_MIN_X    30
//#define TOUCH_MAX_Y    960
//#define TOUCH_MIN_Y    60

#define TOUCH_X	640
#define TOUCH_Y	480


VOID Touch_CoordinateConversion(INT *px, INT *py)
{
	INT TmpX, TmpY;

	TmpX = (*px >= TOUCH_MAX_X) ? (TOUCH_MAX_X) : *px;
	TmpY = (*py >= TOUCH_MAX_Y) ? (TOUCH_MAX_Y) : *py;
	
	TmpX -= TOUCH_MIN_X;
    TmpY -= TOUCH_MIN_Y;
    
	if (TmpX < 0) TmpX = 0;
	if (TmpY < 0) TmpY = 0;
   
	*px = ((TmpX * TOUCH_X) / (TOUCH_MAX_X-TOUCH_MIN_X))*4;
	*py = ((TmpY * TOUCH_Y) / (TOUCH_MAX_Y-TOUCH_MIN_Y))*4;

#if 0	
	RETAILMSG(1, (TEXT("first *px,y = (%d, %d)\r\n"), TmpX0, TmpY0));
	RETAILMSG(1, (TEXT("TOUCH_MAX_X : %d\r\n"), TOUCH_MAX_X));
	RETAILMSG(1, (TEXT("TOUCH_MAX_Y : %d\r\n"), TOUCH_MAX_Y));
	RETAILMSG(1, (TEXT("TOUCH_MIN_X : %d\r\n"), TOUCH_MIN_X));
	RETAILMSG(1, (TEXT("TOUCH_MIN_Y : %d\r\n"), TOUCH_MIN_Y));
	RETAILMSG(1, (TEXT("TOUCH_X     : %d\r\n"), TOUCH_X));
	RETAILMSG(1, (TEXT("TOUCH_Y     : %d\r\n"), TOUCH_Y));	
	RETAILMSG(1, (TEXT("last  *px,y = (%d, %d)\r\n"), *px, *py));	
#endif
	
	return;
}




static int count = 0;
static INT x[2], y[2];

static BOOL Touch_Pen_filtering(INT *px, INT *py)
{
	BOOL RetVal = TRUE;
	// TRUE  : Valid pen sample
	// FALSE : Invalid pen sample
	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;
		}
		
	} 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 
	}
	
	return RetVal;
}



PUBLIC VOID
DdsiTouchPanelGetPoint(TOUCH_PANEL_SAMPLE_FLAGS * pTipStateFlags,
                       INT  * pUncalX,
                       INT  * pUncalY)
{
    static INT x, y;
    INT TmpX = 0;
    INT TmpY = 0;
    static INT PrevX = 0;
    static INT PrevY = 0;
	TOUCH_PANEL_SAMPLE_FLAGS TmpStateFlags;

    if (v_pINTregs->SUBSRCPND & (1<<IRQ_SUB_TC))        /* SYSINTR_TOUCH Interrupt Case				*/
    {
        *pTipStateFlags = TouchSampleValidFlag;

        if ( (v_pADCregs->ADCDAT0 & (1 << 15)) |
             (v_pADCregs->ADCDAT1 & (1 << 15)) )
        {
            bTSP_DownFlag = FALSE;

            DEBUGMSG(ZONE_TIPSTATE, (TEXT("up\r\n")));

            v_pADCregs->ADCTSC &= 0xff;

			*pTipStateFlags = TouchSampleValidFlag;
			*pUncalX = PrevX;
			*pUncalY = PrevY;

            TSP_SampleStop();

            /* At this point SYSINTR_TOUCH_CHANGED (timer3) interrupt could also be pending (and masked).
               Since we do not care about the timer3 interrupt after calling TSP_SampleStop, signal it Done.
               If we do not signal done and it was indeed pending and masked, IRQ_TIMER3 will not be unmasked
               and won't fire again unless unmasked */
            if (v_pINTregs->SRCPND & (1<<IRQ_TIMER3))
                InterruptDone(gIntrTouchChanged);
        }
        else
        {
            bTSP_DownFlag = TRUE;

            if (!TSP_GetXY(&x, &y))
                *pTipStateFlags = TouchSampleIgnore;

            DEBUGMSG(ZONE_TIPSTATE, (TEXT("down %x %x\r\n"), x, y));
            TSP_SampleStart();
        }

        v_pINTregs->SUBSRCPND  =  (1<<IRQ_SUB_TC);
        v_pINTregs->INTSUBMSK &= ~(1<<IRQ_SUB_TC);

        InterruptDone(gIntrTouch);
    }
    else        /* SYSINTR_TOUCH_CHANGED Interrupt Case		*/
    {
		if ( (v_pADCregs->ADCDAT0 & (1 << 15)) |
             (v_pADCregs->ADCDAT1 & (1 << 15)) )
        {
            bTSP_DownFlag = FALSE;

            DEBUGMSG(ZONE_TIPSTATE, (TEXT("up\r\n")));

            v_pADCregs->ADCTSC &= 0xff;
			*pTipStateFlags = TouchSampleValidFlag;
			*pUncalX = PrevX;
			*pUncalY = PrevY;

            TSP_SampleStop();

            /* At this point SYSINTR_TOUCH_CHANGED (timer3) interrupt could also be pending (and masked).
               Since we do not care about the timer3 interrupt after calling TSP_SampleStop, signal it Done.
               If we do not signal done and it was indeed pending and masked, IRQ_TIMER3 will not be unmasked
               and won't fire again unless unmasked */
            if (v_pINTregs->SRCPND & (1<<IRQ_TIMER3))
                InterruptDone(gIntrTouchChanged);

			return;
        }

        if (bTSP_DownFlag)
        {
            INT  tx, ty;
 
            if (!TSP_GetXY(&tx, &ty))
                *pTipStateFlags = TouchSampleIgnore;
            else
            {
	 			PddpTouchPanelEvaluateSamples( &TmpStateFlags, &TmpX, &TmpY);
				Touch_CoordinateConversion(&TmpX, &TmpY);    
				
				if (Touch_Pen_filtering(&TmpX, &TmpY)) // Valid touch pen
				{
					*pTipStateFlags = TouchSampleValidFlag | TouchSampleDownFlag;			
					*pTipStateFlags &= ~TouchSampleIgnore;

					*pUncalX = PrevX = TmpX;
					*pUncalY = PrevY = TmpY;
				}
				else	// Invalid touch pen 
				{
					*pTipStateFlags = TouchSampleDownFlag;
					*pTipStateFlags |= TouchSampleIgnore;	
				}		
            }
        }
        else
        {
            *pTipStateFlags = TouchSampleIgnore;

            TSP_SampleStop();
        }

        InterruptDone(gIntrTouchChanged);
    }
}

⌨️ 快捷键说明

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