📄 ucb1400_touch.c
字号:
/******************************************************************************
**
** COPYRIGHT (C) 2000, 2001 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: UCB1400_touch.c
**
** PURPOSE: This is the TouchScreen driver code.
**
** LAST MODIFIED: $Modtime: 7/17/03 1:01p $
******************************************************************************/
/************* HEADER FILES *************/
#include "systypes.h"
#include "dm_errors.h"
#include "timedelays.h"
#define UCB1400_TOUCH_GLOBALS
#include "Ucb1400_Touch.h"
#include "Ucb1400.h"
#include "Ac97MixerRegsApi.h"
#include "XsAc97CtrlApi.h"
//#include "BoardControl.h"
//#include "XsPwm.h"
/************* LOCAL DEFINITIONS *************/
#define RETRIES 10
/************* GLOBAL VARIABLES *************/
UINT ucb1400rev = REVISIONUNKNOWN;
/************* GLOBAL FUNCTIONS *************/
/*
*******************************************************************************
*
* FUNCTION: TS_HWSetup
*
* DESCRIPTION: Setup the Touchscreen controller.
*
* INPUT PARAMETERS: None.
*
* RETURNS: ErrorT - Status.
*
* GLOBAL EFFECTS: None.
*
* ASSUMPTIONS: None.
*
* CALLS: None.
*
* CALLED BY: System.
*
* PROTOTYPE: ErrorT TS_HWSetup(void)
*
*******************************************************************************
*/
ErrorT TS_HWSetup(void)
{
ErrorT retVal;
UINT data;
// PostDisplayProgress(ERR_L_TS, 1, 0);
// Turn on the ADC
retVal = XsAc97CtrlWriteCodecReg (
XS_AC97CTRL_CM_ID_PRI_CODEC,
UCB_ADCCR,
UCB_ADCCR_AE
);
if (retVal != ERR_NONE) return retVal;
// PostDisplayProgress(ERR_L_TS, 1, 1);
// Get the contents of the reset register.
retVal = XsAc97CtrlReadCodecReg (
XS_AC97CTRL_CM_ID_PRI_CODEC,
UCB_RR,
&data
);
if (retVal != ERR_NONE) return retVal;
if (data == (UCB_RR_LOUDNESS | UCB_RR_20BITDAC | UCB_RR_20BITADC))
ucb1400rev = REVISION2A;
else
ucb1400rev = REVISION1B;
return (retVal);
}
/*
*******************************************************************************
*
* FUNCTION: TS_SWInit
*
* DESCRIPTION: Init the Touchscreen driver internal variables.
*
* INPUT PARAMETERS: None.
*
* RETURNS: Nothing.
*
* GLOBAL EFFECTS: None.
*
* ASSUMPTIONS: None.
*
* CALLS: None.
*
* CALLED BY: System.
*
* PROTOTYPE: void TS_SWInit(void)
*
*******************************************************************************
*/
void TS_SWInit(void)
{
// PostDisplayProgress(ERR_L_TS, 2, 0);
}
/*
*******************************************************************************
*
* FUNCTION: TS_GetPenStatus
*
* DESCRIPTION: Get the Penup/Pendown status.
*
* INPUT PARAMETERS: None.
*
* RETURNS: ErrorT - Status.
*
* GLOBAL EFFECTS: None.
*
* ASSUMPTIONS: None.
*
* CALLS: None.
*
* CALLED BY: System.
*
* PROTOTYPE: ErrorT TS_GetPenStatus(void)
*
*******************************************************************************
*/
ErrorT TS_GetPenStatus(void)
{
UINT data, retVal;
// PostDisplayProgress(ERR_L_TS, 4, 0);
// Watch the PENUP/PENDOWN State.
retVal = XsAc97CtrlWriteCodecReg (
XS_AC97CTRL_CM_ID_PRI_CODEC,
UCB_TSCR,
ucb1400rev==REVISION1B ?
UCB_TSCR_TSMY_GND | UCB_TSCR_TSPY_GND | UCB_TSCR_BIAS :
UCB_TSCR_TSMX_POW | UCB_TSCR_TSPX_POW | UCB_TSCR_TSMY_GND | UCB_TSCR_TSPY_GND
);
// PostDisplayProgress(ERR_L_TS, 4, 1);
if (retVal != ERR_NONE) return (retVal);
DM_WaitMs(3);
// PostDisplayProgress(ERR_L_TS, 4, 2);
// Read the PENUP/PENDOWN State.
retVal = XsAc97CtrlReadCodecReg (
XS_AC97CTRL_CM_ID_PRI_CODEC,
UCB_TSCR,
&data
);
// PostDisplayProgress(ERR_L_TS, 4, 3);
if (retVal != ERR_NONE) return (retVal);
if ((data & UCB_TSCR_PX) || (data & UCB_TSCR_MX)) {
// PostDisplayProgress(ERR_L_TS, 4, 4);
return (TS_PENUP);
}
// PostDisplayProgress(ERR_L_TS, 4, 5);
return (TS_PENDOWN);
}
/*
*******************************************************************************
*
* FUNCTION: TS_GetRaw
*
* DESCRIPTION: Get the raw Pen coordinates.
*
* INPUT PARAMETERS: UINT16 *x - Pointer for "X" coordinate return.
* UINT16 *y - Pointer for "Y" coordinate return.
*
* RETURNS: ErrorT - Status.
* UINT16 *x - "X" coordinate.
* UINT16 *y - "Y" coordinate.
*
* GLOBAL EFFECTS: None.
*
* ASSUMPTIONS: None.
*
* CALLS: None.
*
* CALLED BY: System.
*
* PROTOTYPE: ErrorT TS_GetRaw(UINT16 *x, UINT16 *y)
*
*******************************************************************************
*/
ErrorT TS_GetRaw(UINT16 *x, UINT16 *y)
{
ErrorT retVal;
UINT data, timeout;
//backlight off
// XsPwmWriteDuty(0, 0x0);
// PostDisplayProgress(ERR_L_TS, 3, 0);
retVal = XsAc97CtrlWriteCodecReg ( // Read the "X" coordinate.
XS_AC97CTRL_CM_ID_PRI_CODEC,
UCB_TSCR,
UCB_TSCR_BIAS | UCB_TSCR_POSMO | UCB_TSCR_TSPX_POW | UCB_TSCR_TSMX_GND
);
// PostDisplayProgress(ERR_L_TS, 3, 1);
if (retVal != ERR_NONE) return (retVal);
DM_WaitMs(3);
retVal = XsAc97CtrlWriteCodecReg ( // Start the conversion.
XS_AC97CTRL_CM_ID_PRI_CODEC,
UCB_ADCCR,
UCB_ADCCR_AE | UCB_ADCCR_AS | UCB_ADCCR_AI_TSMY
);
// PostDisplayProgress(ERR_L_TS, 3, 2);
if (retVal != ERR_NONE) return (retVal);
timeout = RETRIES;
do {
if (!(timeout--))
return ERRORCODEX(ERR_L_TS, 3, 3, ERR_T_TIMEOUT); // Touchscreen ADC never done!
DM_WaitUs(10);
retVal = XsAc97CtrlReadCodecReg ( // Get the result.
XS_AC97CTRL_CM_ID_PRI_CODEC,
UCB_ADCDR,
&data
);
if (retVal != ERR_NONE) return (retVal);
} while (!(data & UCB_ADCDR_ADV)); // Wait for done bit.
// PostDisplayProgress(ERR_L_TS, 3, 4);
*x = data & UCB_ADCDR_MASK;
retVal = XsAc97CtrlWriteCodecReg ( // Read the "Y" coordinate.
XS_AC97CTRL_CM_ID_PRI_CODEC,
UCB_TSCR,
UCB_TSCR_BIAS | UCB_TSCR_POSMO | UCB_TSCR_TSPY_POW | UCB_TSCR_TSMY_GND
);
// PostDisplayProgress(ERR_L_TS, 3, 5);
if (retVal != ERR_NONE) return (retVal);
DM_WaitMs(3);
retVal = XsAc97CtrlWriteCodecReg ( // Start the conversion.
XS_AC97CTRL_CM_ID_PRI_CODEC,
UCB_ADCCR,
UCB_ADCCR_AE | UCB_ADCCR_AS | UCB_ADCCR_AI_TSMX
);
// PostDisplayProgress(ERR_L_TS, 3, 6);
if (retVal != ERR_NONE) return (retVal);
timeout = RETRIES;
do {
if (!(timeout--))
return ERRORCODEX(ERR_L_TS, 3, 7, ERR_T_TIMEOUT); // Touchscreen ADC never done!
DM_WaitUs(10);
retVal = XsAc97CtrlReadCodecReg ( // Get the result.
XS_AC97CTRL_CM_ID_PRI_CODEC,
UCB_ADCDR,
&data
);
if (retVal != ERR_NONE) return (retVal);
} while (!(data & UCB_ADCDR_ADV)); // Wait for done bit.
// PostDisplayProgress(ERR_L_TS, 3, 8);
*y = data & UCB_ADCDR_MASK;
//backlight on
// XsPwmWriteDuty(0, 0x3FF);
return ERR_NONE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -