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

📄 pws570_7843.lib

📁 rabbit 3000的触摸屏驱动程序
💻 LIB
📖 第 1 页 / 共 2 页
字号:
/* START LIBRARY DESCRIPTION *********************************************
TS_R4096.LIB
	Copyright (c) 2002, Z-World.

DESCRIPTION: Touchscreen low-level driver.

END DESCRIPTION **********************************************************/

/*** BeginHeader */
#ifndef __PWS570_7843_LIB
#define __PWS570_7843_LIB
/*** EndHeader */

/*** BeginHeader  */
#define BTNRELEASE 0x80000000L
/*** EndHeader */


/*** BeginHeader TsCalib, _adcCalibTS*/
int TsCalib(int x1, int y1, int x2, int y2);

typedef struct
{
	int x_offset;
	int y_offset;
	float x_gainfactor;
	float y_gainfactor;
}tc_cal;

#define CALIB_TS    (4096*GetIDBlockSize()-0x400)
extern tc_cal _adcCalibTS;

#ifndef TSCAL_MINIMUM
#define TSCAL_MINIMUM 600
#endif
#ifndef TSCAL_MAXIMUM
#define TSCAL_MAXIMUM 3200
#endif
/*** EndHeader */

tc_cal _adcCalibTS;

/* START FUNCTION DESCRIPTION ********************************************
TsCalib                       <PWS570_7843.LIB>

SYNTAX:			int TsCalib(int x1, int y1, int x2, int y2);

DESCRIPTION:	Calibrates the touchscreen as a linear function using
               the two sets of x,y coordinate's provided. Gainfactor
               and offset constants are calculated and placed into
               global table _adcCalibTS. This function is non-reentrant.

PARAMETER1:		X-coordinate of upper-left hand corner of touchscreen.
PARAMETER2:		Y-coordinate of upper-left hand corner of touchscreen.
PARAMETER1:		X-coordinate of lower-right hand corner of touchscreen.
PARAMETER2:		Y-coordinate of lower-right hand corner of touchscreen.

RETURN VALUE:	0, if sucessful.
					-1, if not able to make calibration constants.

SEE ALSO:		TsCalibEERd, TsCalibEEWr, TsXYvector, brdInit,

END DESCRIPTION **********************************************************/

nodebug
int TsCalib(int x1, int y1, int x2, int y2)
{
	if(x1 > TSCAL_MINIMUM ||  y1 > TSCAL_MINIMUM)
		return -1;
	if(x2 < TSCAL_MAXIMUM || y2 < TSCAL_MAXIMUM)
		return -1;
	_adcCalibTS.x_offset = x1;
	_adcCalibTS.y_offset = y1;

	_adcCalibTS.x_gainfactor = (float)LCD_XS/(float)(x2-x1);
	_adcCalibTS.y_gainfactor = (float)LCD_YS/(float)(y2-y1);

	return 0;
}


/*** BeginHeader TsCalibEERd */
int TsCalibEERd( void );
/*** EndHeader */

/* START FUNCTION DESCRIPTION ********************************************
TsCalibEERd                   <PWS570_7843.LIB>

SYNTAX:			int TsCalibEERd( void );

DESCRIPTION:	Reads the calibration constants, gainfactor and offset,
               from simulated eeprom in flash, located at the top 1K
               of the reserved UserBlock memory area. This function is
               non-reentrant.

               See the user manual for the size of the UserBlock area.

PARAMETER1:		None.

RETURN VALUE:	 0, If successful.
					-1, invalid address or range.

SEE ALSO:		TsCalib, TsCalibEEWr, TsXYvector, brdInit

END DESCRIPTION **********************************************************/

nodebug
int TsCalibEERd( void )

{
	auto int	status;

	// read calibration constants from flash
	status = readUserBlock(&_adcCalibTS, CALIB_TS, sizeof(_adcCalibTS));
	return(status);
}

/*** BeginHeader TsCalibEEWr */
int TsCalibEEWr( void );
/*** EndHeader */

/* START FUNCTION DESCRIPTION ********************************************
TsCalibEEWr                   <PWS570_7843.LIB>

SYNTAX:			TsCalibEEWr( void );

DESCRIPTION:	Writes the calibration constants, gainfactor and offset,
					to simulated eeprom in flash, located at the top 1K of
					the reserved UserBlock memory area. This function is non-
               reentrant.

               See the user manual for the size of the UserBlock area.

PARAMETER1:		None.

RETURN VALUE:	 0, successful write to simulated eeprom.
					-1, invalid address or range.

SEE ALSO:		TsCalib, TsCalibEERd, TsXYvector, brdInit

END DESCRIPTION **********************************************************/

nodebug
int TsCalibEEWr( void )
{
	auto int	status;

	// write calibration constants to flash
	status = writeUserBlock(CALIB_TS, &_adcCalibTS, sizeof(_adcCalibTS));
	return(status);
}


/*** Beginheader _adcTouchScreen */
useix int _adcTouchScreen( int cmd );
/*** endheader */

/* START _FUNCTION DESCRIPTION ********************************************
_adcTouchScreen		<PWS570_7843.LIB>

SYNTAX:	      int _adcTouchScreen( int cmd );

DESCRIPTION:  	Low-level driver to read the x,y coordinate's of the
               touchscreen. This function is non-reentrant.

PARAMETER1:    The cmd byte to be send to the ADS7870 touchscreen ADC
               converter chip. Please refer to the Burr-Brown ADS7870
               data sheet for complete details.

RETURN VALUE:	Value = 0 - 4095

END DESCRIPTION **********************************************************/

nodebug
useix int _adcTouchScreen( int cmd )
{
#asm
	;---------------------------------------------------------------------
	;	Send CMD to the touchscreen ADC to get the x,y coordinate's.
	;---------------------------------------------------------------------
	ld    de, PDDR
	ld    a, (PDDRShadow)
	res   3,a
	ioi	ld (de),a				;Un-assert Chip Select on ADC  		;
	ld    (PDDRShadow),a			;Update shadow register

	push  ip							; save off IP state
	ipset	1							; set interrupt priority to level 1
	ld		b,8
	ld    l,(ix+cmd)
.cmdcontinue:
	ld    de, PEDR
	ld    a, (PEDRShadow)
	res	3,a						;set CLK bit low    PE3_SK
	ioi	ld (de),a				;CLK SDI data bit into AD
	ld    (PEDRShadow),a

	ld		a,l
	and   a,0x80
	cp    a,0x80
	jr		nz,.cmdbitlow

.cmdbithigh:
	ld    a,(PEDRShadow)
	set   1,a
	ioi   ld (de),a
	ld    (PEDRShadow),a
	jr    .cmdCLK

.cmdbitlow:
	ld    a,(PEDRShadow)
	res   1,a
	ioi   ld (de),a
	ld    (PEDRShadow),a

.cmdCLK:
	ld    de, PEDR
	ld    a, (PEDRShadow)
	set	3,a						;set CLK bit High
	ioi	ld (de),a				;CLK SDI data bit into AD
	ld    (PEDRShadow),a
	sla   l
	djnz	.cmdcontinue
	pop	ip
	WAIT_50usX(1);


	;---------------------------------------------------------------------
	;	Get the x,y coordinate's from the touchscreen ADC.
	;---------------------------------------------------------------------
	ld		de,PEDR
	ld    a,(PEDRShadow)
	res	1,a
	ioi	ld (de),a
	ld		b,12
	ld		iy,0x0000
	push  ip							; save off IP state
	ipset	1							; set interrupt priority to level 1

.rd_touchscreen:
	ld    de, PEDR
	ld    a, (PEDRShadow)
	res	3,a						;set CLK bit low
	ioi	ld (de),a				;CLK SDI data bit into AD
	ld    (PEDRShadow),a
	ld    de, PBDR
	ioi   ld a,(de)
	and   a,0x20
	rra
	rra
	rra
	rra
	rra
	ld    d,0
	ld    e,a
	ld    hl,iy
	or		hl,de
	ex		de,hl
	rl		de
	ex		de,hl
	ld    iy,hl
	ld    de,PEDR
	ld    a,(PEDRShadow)
	set	3,a						;set CLK bit high
	ioi	ld (de),a				;CLK SDI data bit into AD
	ld    (PEDRShadow),a
	djnz	.rd_touchscreen

	;---------------------------------------------------------------------
	;	Un-assert chip select and preset the CLK line low, for the next
	;  conversion cycle.
	;---------------------------------------------------------------------
	ld    de, PDDR
	ld    a, (PDDRShadow)
	set   3,a
	ioi	ld (de),a				;Un-assert Chip Select on ADC
	ld    (PDDRShadow),a			;Update shadow register
	ld    de, PEDR
	ld    a, (PEDRShadow)
	res	3,a						;set CLK bit low
	ioi	ld (de),a				;CLK SDI data bit into AD
	ld    (PEDRShadow),a
	ld		hl,iy
	pop	ip
#endasm
}

/*** Beginheader TsXYvector */
void TsXYvector(int *xkey, int *ykey, int mode);
#define RAW_MODE 0
#define CAL_MODE 1
/*** endheader */

/* START FUNCTION DESCRIPTION ********************************************
TsXYvector			<PWS570_7843.LIB>

SYNTAX:	      void TsXYvector(int *xkey, int *ykey, int mode);

DESCRIPTION:  	Reads the current x, y coordinate's of the touchscreen.
               This function is non-reentrant.

PARAMETER1:    Pointer to the X-coordinate value.
PARAMETER2:    Pointer to the Y-coordinate value.
PARAMETER3:    Mode of operation:
					0 (RAW_MODE) = Return touchscreen x, y coordinate's raw
					               data value.
					1 (CAL_MODE) = Return touchscreen x, y coordinate's as
					               normalized data values to match the LCD
					               display resolution.
RETURN VALUE:	None.

SEE ALSO:		TsActive, TsScanState, TsXYBuffer, brdInit

END DESCRIPTION **********************************************************/

nodebug
void TsXYvector(int *xkey, int *ykey, int mode)
{

	#GLOBAL_INIT {__brdInitFlag = FALSE;}

	if(!__brdInitFlag)
	{
		// The brdInit function hasn't been executed as of yet
		exception(-ERR_BADPARAMETER);
		exit(-ERR_BADPARAMETER);
	}

	*xkey = _adcTouchScreen(0xD0);
	*xkey = 0x0fff & *xkey;

	*ykey = _adcTouchScreen(0x90);
	*ykey = 0x0fff & *ykey;

	 if(mode == CAL_MODE)
	{
		*xkey -= _adcCalibTS.x_offset;
		*ykey -= _adcCalibTS.y_offset;

		*xkey =  (int) (*xkey*_adcCalibTS.x_gainfactor);
		*ykey =  (int) (*ykey*_adcCalibTS.y_gainfactor);
		if(*xkey < 0)
			*xkey = 0;
		if(*ykey < 0)
			*ykey = 0;

		if(*ykey > LCD_YS)
			*ykey = LCD_YS;

⌨️ 快捷键说明

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