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

📄 s3c2410x_touch.cpp

📁 从Sam sung2410 Wince bsp上修改过的touch driver.可以在碰触到lcd画面时,在板子上作出LED灯变化.给初阶学者学习用的,
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                                (1      <<  4) |        /* nXPON 1 (XP = AIN[7])				*/
                                (1      <<  3) |        /* Pull Up Enable						*/
                                (1      <<  2) |        /* Auto ADC Conversion Mode				*/
                                (0      <<  0);         /* No Operation Mode					*/

        v_pADCregs->ADCCON |= (1 << 0);             /* Start Auto conversion				*/

        while (v_pADCregs->ADCCON & 0x1);               /* check if Enable_start is low			*/
        while (!(v_pADCregs->ADCCON & (1 << 15)));      /* Check ECFLG							*/

        x = (0x3ff & v_pADCregs->ADCDAT1);
        y = 0x3ff - (0x3ff & v_pADCregs->ADCDAT0);

        xsum += x;
        ysum += y;
    }


    *px = xsum / TSP_SAMPLE_NUM;
    *py = ysum / TSP_SAMPLE_NUM;

    v_pADCregs->ADCTSC =    (1      <<  8) |            /* UD_Sen								*/
                            (1      <<  7) |            /* YMON  1 (YM = GND)					*/
                            (1      <<  6) |            /* nYPON 1 (YP Connected AIN[n])		*/
                            (0      <<  5) |            /* XMON  0 (XM = Z)						*/
                            (1      <<  4) |            /* nXPON 1 (XP = AIN[7])				*/
                            (0      <<  3) |            /* Pull Up Disable						*/
                            (0      <<  2) |            /* Normal ADC Conversion Mode			*/
                            (3      <<  0);             /* Waiting Interrupt					*/

    dx = (*px > x) ? (*px - x) : (x - *px);
    dy = (*py > y) ? (*py - y) : (y - *py);

    return((dx > TSP_INVALIDLIMIT || dy > TSP_INVALIDLIMIT) ? FALSE : TRUE);
}

/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */

PUBLIC BOOL
DdsiTouchPanelGetDeviceCaps(INT iIndex, LPVOID  lpOutput)
{
    RETAILMSG(0, (TEXT("::: DdsiTouchPanelGetDeviceCaps\r\n")));

    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;
            RETAILMSG(0, (TEXT("TouchPanelGetDeviceCaps::TPDC_SAMPLE_RATE_ID\r\n")));

            pTSR->SamplesPerSecondLow      = TSP_SAMPLE_RATE_LOW;
            pTSR->SamplesPerSecondHigh     = TSP_SAMPLE_RATE_HIGH;
            pTSR->CurrentSampleRateSetting = TSP_CurRate;
        }
        break;

    case TPDC_CALIBRATION_POINT_COUNT_ID:
        {
            TPDC_CALIBRATION_POINT_COUNT *pTCPC = (TPDC_CALIBRATION_POINT_COUNT*)lpOutput;
            RETAILMSG(0, (TEXT("TouchPanelGetDeviceCaps::TPDC_CALIBRATION_POINT_COUNT_ID\r\n")));

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

    case TPDC_CALIBRATION_POINT_ID:
        RETAILMSG(0, (TEXT("TouchPanelGetDeviceCaps::TPDC_CALIBRATION_POINT_ID\r\n")));
        return(TSP_CalibrationPointGet((TPDC_CALIBRATION_POINT*)lpOutput));

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

    }

    return (TRUE);
}

/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
PUBLIC BOOL
DdsiTouchPanelSetMode(INT iIndex, LPVOID  lpInput)
{
    BOOL  ReturnCode = FALSE;

    RETAILMSG(0, (TEXT("::: DdsiTouchPanelSetMode()\r\n")));

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

/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */

PUBLIC BOOL
DdsiTouchPanelEnable(VOID)
{
    BOOL r;
    UINT32 Irq;
    PROCESSOR_INFO procInfo;

    RETAILMSG(0, (TEXT("::: DdsiTouchPanelEnable()\r\n")));

    r = TSP_VirtualAlloc();

    // Obtain sysintr values from the OAL for the touch and touch changed interrupts.
    //
    Irq = IRQ_ADC;
    if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &Irq, sizeof(UINT32), &gIntrTouch, sizeof(UINT32), NULL))
    {
        RETAILMSG(1, (TEXT("ERROR: Failed to request the touch sysintr.\r\n")));
        gIntrTouch = SYSINTR_UNDEFINED;
        return(FALSE);
    }
    Irq = IRQ_TIMER3;
    if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &Irq, sizeof(UINT32), &gIntrTouchChanged, sizeof(UINT32), NULL))
    {
        RETAILMSG(1, (TEXT("ERROR: Failed to request the touch changed sysintr.\r\n")));
        gIntrTouchChanged = SYSINTR_UNDEFINED;
        return(FALSE);
    }

    // Get the processor's pclk frequency.
    //
    if (!KernelIoControl(IOCTL_PROCESSOR_INFORMATION, NULL, 0, &procInfo, sizeof(PROCESSOR_INFO), NULL))
    {
        DEBUGMSG(1, (TEXT("WARNING: Touch driver failed to obtain processor frequency - using default value(%d Hz).\r\n"), g_s3c2410_pclk));
    }
    else
    {
        g_s3c2410_pclk = procInfo.dwClockSpeed;
        DEBUGMSG(1, (TEXT("INFO: Touch driver using processor frequency reported by the OAL (%d Hz).\r\n"), g_s3c2410_pclk));
    }

    // Compute the OS timer frequency and number of pen-down sampling ticks.
    //
    g_timer3_freq        = (g_s3c2410_pclk / TIMER3_DIVIDER);
    g_timer3_sampleticks = (g_timer3_freq / TSP_SAMPLE_RATE_LOW);

    if (r)
    {
        TSP_PowerOn();
    }

    return (r);
}



/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */

PUBLIC VOID
DdsiTouchPanelDisable(VOID)
{
    RETAILMSG(0, (TEXT("::: DdsiTouchPanelDisable()\r\n")));
    if (v_pADCregs)
    {
        TSP_PowerOff();
        TSP_VirtualFree();
    }
}

/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */

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


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


/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
PUBLIC VOID
DdsiTouchPanelPowerHandler(BOOL bOff)
{
    RETAILMSG(0, (TEXT("::: DdsiTouchPanelPowerHandler()\r\n")));
    if (bOff)
    {
        TSP_PowerOff();
    }
    else
    {
        TSP_PowerOn();
    }
}


/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */



PUBLIC VOID
DdsiTouchPanelGetPoint(TOUCH_PANEL_SAMPLE_FLAGS * pTipStateFlags,
                       INT  * pUncalX,
                       INT  * pUncalY)
{
    static INT x, y;

    //DEBUGMSG(1, (TEXT("::: DdsiTouchPanelGetPoint()\r\n")));

    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;

            *pUncalX = x;
            *pUncalY = y;

            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;

            TSP_TransXY(&x, &y);

            *pUncalX = x;
            *pUncalY = y;

            *pTipStateFlags |= TouchSampleDownFlag;

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

        if (bTSP_DownFlag)
        {
            INT  tx, ty;
            INT  dx, dy;

            if (!TSP_GetXY(&tx, &ty))
                *pTipStateFlags = TouchSampleIgnore;
            else
            {
                TSP_TransXY(&tx, &ty);
// insert by mostek@dstcorp.com
#define X_ERRV	0x3bf
#define Y_ERRV	0x4ff

// Subsequent info: If the ADC provides a bad reading, this catches it and
// skips over it. Instead, it should be fixed at the source
// so as not to provide a bad reading.

                if ((tx == X_ERRV) || (ty == Y_ERRV))
                {
                    tx = x;
                    ty = y;
                }
// =================== mostek
                dx = (tx > x) ? (tx - x) : (x - tx);
                dy = (ty > y) ? (ty - y) : (y - ty);

                if (dx > TSP_CHANGE || dy > TSP_CHANGE)
                {
                    *pUncalX = x = tx;
                    *pUncalY = y = ty;

                    DEBUGMSG(ZONE_TIPSTATE, (TEXT("down-c-v %x %x\r\n"), x, y));

                    *pTipStateFlags = TouchSampleValidFlag | TouchSampleDownFlag;
                }
                else
                {
                    *pUncalX = x;
                    *pUncalY = y;

                    DEBUGMSG(ZONE_TIPSTATE, (TEXT("down-c %x %x\r\n"), x, y));

                    *pTipStateFlags = TouchSampleIgnore;
                }
            }
        }
        else
        {
            *pTipStateFlags = TouchSampleIgnore;

            TSP_SampleStop();
        }

        InterruptDone(gIntrTouchChanged);
    }
}

⌨️ 快捷键说明

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