tchpdd.cpp

来自「S3C24A0的完整BSP包,对开发此芯片的开发者很有用.」· C++ 代码 · 共 1,273 行 · 第 1/3 页

CPP
1,273
字号
    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
    //
    v_pADCregs->ADCTSC = 0xd3;	// YM:GND,YP:AIN5,XM:Hi-z,XP:AIN7,XP pullup En,Normal,Waiting for interrupt mode
    v_pADCregs->ADCDLY = ADC_DELAY_TIME;	//default value for delay.    
    v_pADCregs->ADCCON = (1<<14)|(ADCPRS<<6)|(0<<3)|(0<<2)|(0<<1)|0;	

	return TRUE;

}

//
// PddpDisableClearPenDownIntr(void)
//
// Tell the UCB to clear pen down interrupts
//
BOOL
PddpDisableClearPenDownIntr(void)
{
    return TRUE;
}

//
// DDSI Implementation
//


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

Gives a single calibration point.

	@XREF
		<l TouchPanelReadCalibrationPoint.TouchPanelReadCalibrationPoint>
		<l TouchPanelSetCalibration.TouchPanelSetCalibration>
		<l TouchPanelReadCalibrationAbort.TouchPanelReadCalibrationAbort>


	@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 <l TouchPanelSetCalibration.TouchPanelSetCalibration>.

*/

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(JYLEE_TEST1,(TEXT("TouchDriverCalibrationPointGet\r\n")));
	RETAILMSG(JYLEE_TEST1,(TEXT("cDisplayWidth : %4X\r\n"),cDisplayWidth));
	RETAILMSG(JYLEE_TEST1,(TEXT("cDisplayHeight : %4X\r\n"),cDisplayHeight));
	RETAILMSG(JYLEE_TEST1,(TEXT("CalibrationRadiusX : %4d\r\n"),CalibrationRadiusX));
	RETAILMSG(JYLEE_TEST1,(TEXT("CalibrationRadiusY : %4d\r\n"),CalibrationRadiusY));
	RETAILMSG(JYLEE_TEST1,(TEXT("pTCP -> PointNumber : %4d\r\n"),pTCP -> PointNumber));
	RETAILMSG(JYLEE_TEST1,(TEXT("pTCP -> CalibrationX : %4d\r\n"),pTCP -> CalibrationX));
	RETAILMSG(JYLEE_TEST1,(TEXT("pTCP -> CalibrationY : %4d\r\n"),pTCP -> CalibrationY));
	return TRUE;
}




// @doc EX_TOUCH_DDSI EXTERNAL DRIVERS DDSI TOUCH_PANEL
//
// @func ULONG | DdsiTouchPanelGetDeviceCaps |
//
// Queries capabilities about the physical touch panel device.
//
// @parm ULONG | iIndex |
//
// Specifies the capability to query. They are one of the following:
//
// @flag TPDC_SAMPLERATE_ID |
// The sample rate.
// @flag TPDC_CALIBRATIONPOINTS_ID |
// The X and Y coordinates used for calibration.
// @flag TPDC_CALIBRATIONDATA_ID |
// The X and Y coordinates used for calibration mapping.
//
// @parm LPVOID | lpOutput |
// Points to the memory location(s) where the queried information
// will be placed. The format of the memory referenced depends on
// the setting of iIndex. If 0, returns the number of words
// required for the output data.
//
// @rdesc
// The return values is set to the amount of information supplied and depends
// on the setting of the iIndex argument.
//
// @comm
// Implemented in the PDD.
//

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



//
// @doc EX_TOUCH_DDSI EXTERNAL DRIVERS DDSI TOUCH_PANEL
//
// @func BOOL | DdsiTouchPanelSetMode |
// Sets information about the physical touch panel device.
//
// @parm ULONG | iIndex |
// Specifies the mode to set. They are one of the following:
//
// @flag TPSM_SAMPLERATE_HIGH_ID |
// Sets the sample rate to the high rate.
// @flag TPSM_SAMPLERATE_LOW_ID |
// Sets the sample rate to the low rate.
//
// @parm LPVOID | lpInput |
// Points to the memory location(s) where the update information
// resides. The format of the memory referenced depends on the
// Points to the memory location(s) where the queried information
// will be placed.
//
// @rdesc
// If the function succeeds the return value is TRUE, otherwise, it is FALSE.
//
// @comm
// Implemented in the PDD.
//

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

//
// @doc EX_TOUCH_DDSI EXTERNAL DRIVERS DDSI TOUCH_PANEL
//
// @func BOOL | DdsiTouchPanelEnable |
// Powers up and initializes the touch panel hardware for operation.
//
// @rdesc
// If the function succeeds, the return value is TRUE; otherwise, it is FALSE.
//
// @comm
// Implemented in the PDD.
//

BOOL
DdsiTouchPanelEnable(
    VOID
    )
{
    BOOL    Ret;
	UINT32 Irq;
	BOOL b = FALSE;

	RETAILMSG(TCHPDD_TEST,(_T("TOUCHP::DdsiTouchPannelEnable\r\n")));

    if(v_pADCregs == NULL) {
		//(volatile S3C2410X_IOPORT_REG *)TSP_RegAlloc((PVOID)S3C2410X_BASE_REG_PA_IOPORT, sizeof(S3C2410X_IOPORT_REG));
		v_pADCregs = (volatile S3C24A0_ADC_REG *)TSP_RegAlloc((PVOID)S3C24A0_BASE_REG_PA_ADC, sizeof(S3C24A0_ADC_REG));
    	if(v_pADCregs == NULL) {
	    	ERRORMSG(1,(TEXT("For S3C24A0_ADC_REG: VirtualAlloc failed!\r\n")));
		    return (FALSE);
	    }
	}

    if(v_pPWMregs == NULL) {
    	v_pPWMregs = (volatile S3C24A0_PWM_REG *)TSP_RegAlloc((PVOID)S3C24A0_BASE_REG_PA_PWM, sizeof(S3C24A0_PWM_REG));
    	if(v_pPWMregs == NULL) {
	    	ERRORMSG(1,(TEXT("For S3C24A0_PWM_REG: VirtualAlloc failed!\r\n")));
		    return (FALSE);
	    }
	}	

    if(v_pINTregs == NULL) {
		v_pINTregs = (volatile S3C24A0_INTR_REG *)TSP_RegAlloc((PVOID)S3C24A0_BASE_REG_PA_INTR, sizeof(S3C24A0_INTR_REG)); 
		if(v_pINTregs == NULL) {
			ERRORMSG(1,(TEXT("For S3C24A0_INTR_REG: VirtualAlloc failed!\r\n")));
			return (FALSE);
		}
	}
    //
    // If the address space of the client process doesn't yet have the
    //  mapping to the pen dma area; map it.  If the mapping fails
    //  we 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 );
        }
    }

    // Power on touch panel
    TouchPanelPowerOn();

	// 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), &gIntrTouchChanged, sizeof(UINT32), NULL))
    {
        RETAILMSG(1, (TEXT("ERROR: Failed to request the touch changed sysintr.\r\n")));
        gIntrTouch = SYSINTR_UNDEFINED;
        return(FALSE);
    }
    Irq = IRQ_TIMER1;
    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")));
        gIntrTouchChanged = SYSINTR_UNDEFINED;
        return(FALSE);
    }
	RETAILMSG(1, (TEXT("Touch sysintr.%d\r\n"), gIntrTouch));
	RETAILMSG(1, (TEXT("Touch_change sysintr.%d\r\n"), gIntrTouchChanged));

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

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



// @doc EX_TOUCH_DDSI EXTERNAL DRIVERS DDSI TOUCH_PANEL
//
// @func ULONG | DdsiTouchPanelDisable |
// Powers down the touch panel device.
//
// @comm
// Implemented in the PDD.
//

VOID
DdsiTouchPanelDisable(
    VOID
    )
{

	RETAILMSG(TCHPDD_TEST,(_T("TOUCHP::DdsiTouchPanelDisable\r\n")));

    //
    // Check pointers in case the enable failed.
    //
    if(v_pADCregs == NULL) 
        return ;

    TouchPanelPowerOff();  // Power down the device

    PddpTouchPanelDeallocateVm();  // free up any resources
}

//
// @doc EX_TOUCH_DDSI EXTERNAL DRIVERS DDSI TOUCH_PANEL
//
// @func LONG | DdsiTouchPanelAttach |
// This routine no longer does anything.  All functionallity has been moved
// from here into DdsiTouchPanelEnable to allow this code to be statically
// linked with GWE rather than existing as a DLL.  Technically, when built
// as a DLL we should keep an attach count and only allow touh.dll to be
// loaded once.  But, since we are loaded at boot time by GWE, there is
// no real concern about multiple loads (unless gwe has a bug!).
//
// @rdesc
// Always returns 0
//
// @comm

⌨️ 快捷键说明

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