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

📄 xllp_touch.c

📁 Xcale270Bsp包,wince平台
💻 C
字号:
/******************************************************************************
**
**  COPYRIGHT (C) 2001, 2002 Intel Corporation.
**
**  This software as well as the software described in it is furnished under
**  license and may only be used or copied in accordance with the terms of the
**  license. The information in this file is furnished for informational use
**  only, is subject to change without notice, and should not be construed as
**  a commitment by Intel Corporation. Intel Corporation assumes no
**  responsibility or liability for any errors or inaccuracies that may appear
**  in this document or any software that may be provided in association with
**  this document. 
**  Except as permitted by such license, no part of this document may be 
**  reproduced, stored in a retrieval system, or transmitted in any form or by
**  any means without the express written consent of Intel Corporation. 
**
**  FILENAME:       xllp_touch.c
**
**  PURPOSE: contains all primitive functions for Bulverde/Mainstone/UCB1400 basic
**             touch screen operations   
******************************************************************************/

#include "xllp_touch.h"

/******************************************************************************
XDP_DOC_HDR_END

  Function Name: XllpAc97SetupTouch(P_XLLP_AC97_T pAC97Reg)

  Description: Put UCB1400 codec into pen interrupt mode
			  				
  Global Registers Modified: Touch screen control register of UCB1400 codec

  Input Arguments: P_XLLP_AC97_T, P_XLLP_OST_T, XLLP_UINT16_T
     
  Output Arguments:
     None
  
  return:
	XLLP_TRUE
	XLLP_FALSE

XLLP_DOC_HDR_END
*******************************************************************************/
XLLP_BOOL_T XllpAc97SetupTouch(P_XLLP_AC97_T pAC97Reg, P_XLLP_OST_T pOstRegs, XLLP_UINT16_T rev)
{
    XLLP_AC97_ERROR_T err;
    XLLP_UINT16_T value;
    
    if (0x02A0 == rev)
    {
        value = XLLP_AC97_U14_TSCR_TSMY_GND | XLLP_AC97_U14_TSCR_TSPY_GND | 
                XLLP_AC97_U14_TSCR_TSPX_POW | XLLP_AC97_U14_TSCR_TSMX_POW;
    }
    else
    {
	    value = XLLP_AC97_U14_TSCR_TSMY_GND | XLLP_AC97_U14_TSCR_TSPY_GND;
	}

    //Put UCB1400 into pen interrupt mode
    err = XllpAc97Write(XLLP_AC97_CR_U14_TS_CTRL, value, pAC97Reg, pOstRegs, XLLP_AC97_RW_TIMEOUT_DEF, 
                XLLP_TOUCH_CODEC_ID);     
    if (XLLP_AC97_NO_ERROR != err)
    {
        return XLLP_FALSE;
    }
    return XLLP_TRUE;
}

/******************************************************************************
XDP_DOC_HDR_END

  Function Name: XLLP_BOOL_T XllpAc97DisablePenDownInterrupt(P_XLLP_AC97_T pAC97Reg, P_XLLP_OST_T pOstRegs)

  Description: Disable pen down interrupt in codec
			  				
  Global Registers Modified: Negative interrupt enable register of UCB1400 codec

  Input Arguments: P_XLLP_AC97_T, P_XLLP_OST_T
     
  Output Arguments:
     None
  
  return:
	XLLP_TRUE
	XLLP_FALSE

XLLP_DOC_HDR_END
*******************************************************************************/
XLLP_BOOL_T XllpAc97DisablePenDownInterrupt(P_XLLP_AC97_T pAC97Reg, P_XLLP_OST_T pOstRegs)
{
    XLLP_AC97_ERROR_T err;
    XLLP_UINT16_T value;
    
    //read current mask
	err = XllpAc97Read(XLLP_AC97_CR_U14_NEG_INT_ENAB, &value, pAC97Reg, pOstRegs, XLLP_AC97_RW_TIMEOUT_DEF, 
                XLLP_TOUCH_CODEC_ID);
	if (XLLP_AC97_NO_ERROR != err)
	{
		return XLLP_FALSE;
	}
	
	value &= ~(XLLP_AC97_U14_NIER_TMXN | XLLP_AC97_U14_NIER_TPXN);
	err = XllpAc97Write(XLLP_AC97_CR_U14_NEG_INT_ENAB, value, pAC97Reg, pOstRegs, XLLP_AC97_RW_TIMEOUT_DEF, 
                XLLP_TOUCH_CODEC_ID);
	if (XLLP_AC97_NO_ERROR != err)
	{
		return XLLP_FALSE;
	}
	return XLLP_TRUE;
}

/******************************************************************************
XDP_DOC_HDR_END

  Function Name: XLLP_BOOL_T XllpAc97EnablePenDownInterrupt(P_XLLP_AC97_T pAC97Reg, P_XLLP_OST_T pOstRegs)

  Description: Enable pen down interrupt in codec
			  				
  Global Registers Modified: Negative interrupt enable register of UCB1400 codec

  Input Arguments: P_XLLP_AC97_T, P_XLLP_OST_T
     
  Output Arguments:
     None
  
  return:
	XLLP_TRUE
	XLLP_FALSE

XLLP_DOC_HDR_END
*******************************************************************************/
XLLP_BOOL_T XllpAc97EnablePenDownInterrupt(P_XLLP_AC97_T pAC97Reg, P_XLLP_OST_T pOstRegs)
{
    XLLP_AC97_ERROR_T err;
    XLLP_UINT16_T value;
    
    //read current mask
	err = XllpAc97Read(XLLP_AC97_CR_U14_NEG_INT_ENAB, &value, pAC97Reg, pOstRegs, XLLP_AC97_RW_TIMEOUT_DEF, 
                XLLP_TOUCH_CODEC_ID);
	if (XLLP_AC97_NO_ERROR != err)
	{
		return XLLP_FALSE;
	}
	
	value |= (XLLP_AC97_U14_NIER_TMXN | XLLP_AC97_U14_NIER_TPXN);
	err = XllpAc97Write(XLLP_AC97_CR_U14_NEG_INT_ENAB, value, pAC97Reg, pOstRegs, XLLP_AC97_RW_TIMEOUT_DEF, 
                XLLP_TOUCH_CODEC_ID);
	if (XLLP_AC97_NO_ERROR != err)
	{
		return XLLP_FALSE;
	}
	return XLLP_TRUE;
}

/******************************************************************************
XDP_DOC_HDR_END

  Function Name: XllpAc97GetPenIntStatus(P_XLLP_AC97_T pAC97Reg, P_XLLP_OST_T pOstRegs, XLLP_BOOL_T *pIntStatus)

  Description: Get the status of pen down interrupt
			  				
  Global Registers Modified: None

  Input Arguments: P_XLLP_AC97_T, 
     
  Output Arguments: XLLP_BOOL_T *
  
  return:
	XLLP_TRUE
	XLLP_FALSE

XLLP_DOC_HDR_END
*******************************************************************************/
XLLP_BOOL_T XllpAc97GetPenIntStatus(P_XLLP_AC97_T pAC97Reg, P_XLLP_OST_T pOstRegs, XLLP_BOOL_T *pIntStatus)
{
    XLLP_AC97_ERROR_T err;
    XLLP_UINT16_T value;
    
	err = XllpAc97Read(XLLP_AC97_CR_U14_INT_CLR_STAT, &value, pAC97Reg, pOstRegs, XLLP_AC97_RW_TIMEOUT_DEF, 
                XLLP_TOUCH_CODEC_ID);
	if (XLLP_AC97_NO_ERROR != err)
	{
		return XLLP_FALSE;
	}

    if (value & (XLLP_AC97_U14_ICSR_TSMX | XLLP_AC97_U14_ICSR_TSPX))
    {
        *pIntStatus = XLLP_TRUE;
    }
    else
    {
        *pIntStatus = XLLP_FALSE;
    }
    return XLLP_TRUE;
}

/******************************************************************************
XDP_DOC_HDR_END

  Function Name: XLLP_BOOL_T XllpAc97ClearPenIntStatus(P_XLLP_AC97_T pAC97Reg, P_XLLP_OST_T pOstRegs)

  Description: Clear the status of pen down interrupt
			  				
  Global Registers Modified: Interrupt clear status register of UCB1400 codec

  Input Arguments: P_XLLP_AC97_T, P_XLLP_OST_T
     
  Output Arguments
            NONE
  
  return:
	XLLP_TRUE
	XLLP_FALSE

XLLP_DOC_HDR_END
*******************************************************************************/
XLLP_BOOL_T XllpAc97ClearPenIntStatus(P_XLLP_AC97_T pAC97Reg, P_XLLP_OST_T pOstRegs)
{
    XLLP_AC97_ERROR_T err;
    XLLP_UINT16_T value;
    
    value = XLLP_AC97_U14_ICSR_TSMX | XLLP_AC97_U14_ICSR_TSPX;
	err = XllpAc97Write(XLLP_AC97_CR_U14_INT_CLR_STAT, value, pAC97Reg, pOstRegs, XLLP_AC97_RW_TIMEOUT_DEF, 
                XLLP_TOUCH_CODEC_ID);
	if (XLLP_AC97_NO_ERROR != err)
	{
		return XLLP_FALSE;
	}

    return XLLP_TRUE;
}

/******************************************************************************
XDP_DOC_HDR_END

  Function Name: XLLP_BOOL_T XllpAc97IsPenUp(P_XLLP_AC97_T pAC97Reg, P_XLLP_OST_T pOstRegs, P_XLLP_BOOL_T *pPenUp)

  Description: Get the status of pen (down or up)
			  				
  Global Registers Modified: NONE

  Input Arguments: P_XLLP_AC97_T, P_XLLP_OST_T
     
  Output Arguments: XLLP_BOOL_T *
            
  
  return:
	XLLP_TRUE
	XLLP_FALSE

XLLP_DOC_HDR_END
*******************************************************************************/
XLLP_BOOL_T XllpAc97IsPenUp(P_XLLP_AC97_T pAC97Reg, P_XLLP_OST_T pOstRegs, XLLP_BOOL_T *pPenUp)
{
    XLLP_AC97_ERROR_T err;
    XLLP_UINT16_T value;

	err = XllpAc97Read(XLLP_AC97_CR_U14_TS_CTRL, &value, pAC97Reg, pOstRegs, XLLP_AC97_RW_TIMEOUT_DEF, 
                XLLP_TOUCH_CODEC_ID);
	if (XLLP_AC97_NO_ERROR != err)
	{
		return XLLP_FALSE;
	}
	
    value &= (XLLP_AC97_U14_TSCR_PX | XLLP_AC97_U14_TSCR_MX);
	if ((XLLP_AC97_U14_TSCR_PX | XLLP_AC97_U14_TSCR_MX) == value)
	{
		*pPenUp = XLLP_TRUE;
	}
	else
	{
		*pPenUp = XLLP_FALSE;
	}

	return XLLP_TRUE;
}
        
/******************************************************************************
XDP_DOC_HDR_END

  Function Name: XLLP_BOOL_T XllpAc97EnableADC(P_XLLP_AC97_T pAC97Reg, P_XLLP_OST_T pOstRegs)

  Description: Enable the 10-bit ADC of UCB1400 codec
			  				
  Global Registers Modified: ADC control register of UCB1400 codec

  Input Arguments: P_XLLP_AC97_T, P_XLLP_OST_T
     
  Output Arguments
            NONE
            
  
  return:
	XLLP_TRUE
	XLLP_FALSE

XLLP_DOC_HDR_END
*******************************************************************************/
XLLP_BOOL_T XllpAc97EnableADC(P_XLLP_AC97_T pAC97Reg, P_XLLP_OST_T pOstRegs)
{
    XLLP_AC97_ERROR_T err;
    XLLP_UINT16_T value;
    
	value = XLLP_AC97_U14_ADCCR_AE;
	err = XllpAc97Write(XLLP_AC97_CR_U14_ADC_CTRL, value, pAC97Reg, pOstRegs, XLLP_AC97_RW_TIMEOUT_DEF, 
                XLLP_TOUCH_CODEC_ID);
	if (XLLP_AC97_NO_ERROR != err)
	{
		return XLLP_FALSE;
	}
	return XLLP_TRUE;
}

/******************************************************************************
XDP_DOC_HDR_END

  Function Name: XLLP_BOOL_T XllpAc97DisableADC(P_XLLP_AC97_T pAC97Reg, P_XLLP_OST_T pOstRegs)

  Description: Disable the 10-bit ADC of UCB1400 codec
			  				
  Global Registers Modified: ADC control register of UCB1400 codec

  Input Arguments: P_XLLP_AC97_T, P_XLLP_OST_T
     
  Output Arguments
            NONE
            
  
  return:
	XLLP_TRUE
	XLLP_FALSE

XLLP_DOC_HDR_END
*******************************************************************************/
XLLP_BOOL_T XllpAc97DisableADC(P_XLLP_AC97_T pAC97Reg, P_XLLP_OST_T pOstRegs)
{
    XLLP_AC97_ERROR_T err;
    XLLP_UINT16_T value;
    
	value = 0;
	err = XllpAc97Write(XLLP_AC97_CR_U14_ADC_CTRL, value, pAC97Reg, pOstRegs, XLLP_AC97_RW_TIMEOUT_DEF, 
                XLLP_TOUCH_CODEC_ID);
	if (XLLP_AC97_NO_ERROR != err)
	{
		return XLLP_FALSE;
	}
	return XLLP_TRUE;
}

/******************************************************************************
XDP_DOC_HDR_END

  Function Name: XLLP_BOOL_T XllpAc97SampleADC(P_XLLP_AC97_T pAC97Reg, P_XLLP_OST_T pOstRegs, XLLP_AC97_ADC_TYPE type,
            P_XLLP_UINT16_T pValue, XLLP_INT32_T timeOutUs)

  Description: Start the ADC and get the result
			  				
  Global Registers Modified: ADC control register of UCB1400 codec

  Input Arguments: P_XLLP_AC97_T, P_XLLP_OST_T, XLLP_AC97_ADC_TYPE, XLLP_INT32_T
     
  Output Arguments: P_XLLP_UINT16_T
            
  
  return:
	XLLP_TRUE
	XLLP_FALSE

XLLP_DOC_HDR_END
*******************************************************************************/
XLLP_BOOL_T XllpAc97SampleADC(P_XLLP_AC97_T pAC97Reg, P_XLLP_OST_T pOstRegs, XLLP_AC97_ADC_TYPE type,
            P_XLLP_UINT16_T pValue, XLLP_INT32_T timeOutUs)
{
    XLLP_AC97_ERROR_T err;
    XLLP_UINT16_T value;
    
	//Sample ADC
	if (XLLP_AC97_TOUCH_X == type)
	{
	    value = XLLP_AC97_U14_ADCCR_AE | XLLP_AC97_U14_ADCCR_AS | XLLP_AC97_U14_ADCCR_AI_TSMX;	        
	}
	else if (XLLP_AC97_TOUCH_Y == type)
	{
	    value = XLLP_AC97_U14_ADCCR_AE | XLLP_AC97_U14_ADCCR_AS | XLLP_AC97_U14_ADCCR_AI_TSMY;	        
    }
    else if (XLLP_AC97_BATTERY == type)
    {
	    value = XLLP_AC97_U14_ADCCR_AE | XLLP_AC97_U14_ADCCR_AS | XLLP_AC97_U14_ADCCR_AI_AD0;	        
    }
    else
    {//not supported
        return XLLP_FALSE;
    }

	err = XllpAc97Write(XLLP_AC97_CR_U14_ADC_CTRL, value, pAC97Reg, pOstRegs, XLLP_AC97_RW_TIMEOUT_DEF, 
                XLLP_TOUCH_CODEC_ID);
	if (XLLP_AC97_NO_ERROR != err)
	{
		return XLLP_FALSE;
	}
	
    while (1)
    {
		XllpOstDelayMicroSeconds(pOstRegs, 40);
		
		err = XllpAc97Read(XLLP_AC97_CR_U14_ADC_DATA, &value, pAC97Reg, pOstRegs, XLLP_AC97_RW_TIMEOUT_DEF, 
                    XLLP_TOUCH_CODEC_ID);
	    if (XLLP_AC97_NO_ERROR != err)
	    {
		    return XLLP_FALSE;
	    }
        if (value & XLLP_AC97_U14_ADCDR_ADV) 
        {//done
            break;
        }        
		XllpOstDelayMicroSeconds(pOstRegs, 1);
        timeOutUs --;
        if (timeOutUs <= 0)
        {
            return XLLP_FALSE;
        }
    }

    *pValue = value & XLLP_AC97_U14_ADCDR_MASK;
    return XLLP_TRUE;
}

/******************************************************************************
XDP_DOC_HDR_END

  Function Name: XLLP_BOOL_T XllpAc97GetPenPosition(P_XLLP_AC97_T pAC97Reg, P_XLLP_OST_T pOstRegs, 
            P_XLLP_UINT16_T pValueX, P_XLLP_UINT16_T pValueY, XLLP_INT32_T timeOutUs, XLLP_UINT16_T rev)

  Description: Get the pen position
			  				
  Global Registers Modified: ADC control register of UCB1400 codec and touch control 
                                register of UCB1400 codec

  Input Arguments: P_XLLP_AC97_T, P_XLLP_OST_T, XLLP_INT32_T
     
  Output Arguments: P_XLLP_UINT16_T, P_XLLP_UINT16_T
            
  
  return:
	XLLP_TRUE
	XLLP_FALSE

XLLP_DOC_HDR_END
*******************************************************************************/
XLLP_BOOL_T XllpAc97GetPenPosition(P_XLLP_AC97_T pAC97Reg, P_XLLP_OST_T pOstRegs, 
            P_XLLP_UINT16_T pValueX, P_XLLP_UINT16_T pValueY, XLLP_INT32_T timeOutUs, XLLP_UINT16_T rev)
{
    XLLP_AC97_ERROR_T err;
    XLLP_UINT16_T value;
    XLLP_BOOL_T result;

    //Set into X-measure mode
	value = XLLP_AC97_U14_TSCR_BIAS | XLLP_AC97_U14_TSCR_POSMO 
	        | XLLP_AC97_U14_TSCR_TSMY_POW | XLLP_AC97_U14_TSCR_TSPY_GND;
	err = XllpAc97Write(XLLP_AC97_CR_U14_TS_CTRL, value, pAC97Reg, pOstRegs, XLLP_AC97_RW_TIMEOUT_DEF, 
                XLLP_TOUCH_CODEC_ID);
	if (XLLP_AC97_NO_ERROR != err)
	{
		return XLLP_FALSE;
	}
	
	XllpOstDelayMicroSeconds(pOstRegs, 80);
	
	//Sample ADC
	result = XllpAc97SampleADC(pAC97Reg, pOstRegs, XLLP_AC97_TOUCH_X, pValueX, timeOutUs);
	if (XLLP_FALSE == result)
	{
	    return XLLP_FALSE;
	}
	
	//Set into Y-measure mode
	value = XLLP_AC97_U14_TSCR_BIAS | XLLP_AC97_U14_TSCR_POSMO 
	        | XLLP_AC97_U14_TSCR_TSMX_POW | XLLP_AC97_U14_TSCR_TSPX_GND;
	err = XllpAc97Write(XLLP_AC97_CR_U14_TS_CTRL, value, pAC97Reg, pOstRegs, XLLP_AC97_RW_TIMEOUT_DEF, 
                XLLP_TOUCH_CODEC_ID);
	if (XLLP_AC97_NO_ERROR != err)
	{
		return XLLP_FALSE;
	}
	
	XllpOstDelayMicroSeconds(pOstRegs, 80);
    
	//Sample ADC
	result = XllpAc97SampleADC(pAC97Reg, pOstRegs, XLLP_AC97_TOUCH_Y, pValueY, timeOutUs);
	if (XLLP_FALSE == result)
	{
	    return XLLP_FALSE;
	}
    
    //Set back to interrupt mode
    result = XllpAc97SetupTouch(pAC97Reg, pOstRegs, rev);
    return result;    
}

⌨️ 快捷键说明

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