📄 pws570_7843.lib
字号:
if(*xkey > LCD_XS)
*xkey = LCD_XS;
}
}
/*** BeginHeader TsActive */
int TsActive( void );
/*** EndHeader */
/* START FUNCTION DESCRIPTION ********************************************
TsActive <PWS570_7843.LIB>
SYNTAX: int TsActive( void );
DESCRIPTION: This function returns the status of the touchscreen. This
function is non-reentrant.
PARAMETER: None.
RETURN VALUE: 0 = Touchscreen not being pressed.
1 = Touchscreen being pressed.
SEE ALSO: TsXYvector, TsScanState, TsXYBuffer, brdInit
END DESCRIPTION **********************************************************/
nodebug
int TsActive( void )
{
#asm
ld de,PBDR
ioi ld a,(de)
bit 4,a
jr Z, .set1
ld l,0
jr .end
.set1:
ld l,1
.end:
ld h,0x00
#endasm
}
/*** BeginHeader TsScanState, btnpressed */
void TsScanState( void );
#ifndef TS_ASSERT
#define TS_ASSERT 50
#endif
#ifndef TS_RELEASE
#define TS_RELEASE 50
#endif
#ifndef TS_RECHECK
#define TS_RECHECK 2
#endif
#ifndef TS_PREVENTRACE
#define TS_PREVENTRACE 200
#endif
extern int btnpressed;
/*** EndHeader */
int btnpressed;
/* START FUNCTION DESCRIPTION ********************************************
TsScanState <PWS570_7843.LIB>
SYNTAX: void TsScanState( void )
DESCRIPTION: This function processes the current state of the touch
screen, the results then can be read with the TsXYBuffer
function, which will return one of the following:
1. Current x,y location of where the touchscreen is
being pressed.
2. Value indicating that the touchscreen was released.
3. Value of -1 to indicate no activity has occurred.
This function is non-reentrant.
Note: When this function is called the information
should processed before calling this function
again otherwise the snapshot of touchscreen
information will be lost.
PARAMETER: None.
RETURN VALUE: None.
SEE ALSO: TsXYvector, TsActive, TsXYBuffer, brdInit
END DESCRIPTION **********************************************************/
nodebug
void TsScanState( void )
{
static int StatusByte;
static unsigned long debounce_period;
static int ScanState;
static int TS_StartLow;
#GLOBAL_INIT{TS_StartLow = FALSE;}
#GLOBAL_INIT{ScanState = 0;}
#GLOBAL_INIT{__brdInitFlag = FALSE;}
#GLOBAL_INIT{btnpressed = 0;}
if(!__brdInitFlag)
{
// The brdInit function hasn't been executed as of yet
exception(-ERR_BADPARAMETER);
exit(-ERR_BADPARAMETER);
}
// brdInit function will set the flag active to meet ADC power-on delay
if(__InitTSpower)
{
while(!((long) (MS_TIMER-__anaPWRDelay) >= 0 ));
_adcTouchScreen(0xD0);
_adcTouchScreen(0x90);
__InitTSpower = 0;
}
switch(ScanState)
{
case 0:
if(!(StatusByte = TsActive()))
{
TS_StartLow = TRUE;
}
if (TS_StartLow && StatusByte && !btnpressed)
{
ScanState = 1;
debounce_period = MS_TIMER + TS_ASSERT;
}
else if(!StatusByte && btnpressed)
{
ScanState = 3;
}
break;
case 1:
if((long) (MS_TIMER-debounce_period) >= 0 )
{
ScanState = 2;
}
break;
case 2:
if(_TsChangeState(!BTNRELEASE))
{
ScanState = 0;
if(btnpressed)
TS_StartLow = FALSE;
}
break;
case 3:
_TsChangeState(BTNRELEASE);
debounce_period = MS_TIMER + TS_RELEASE;
ScanState = 4;
TS_StartLow = TRUE;
break;
case 4:
if((long) (MS_TIMER-debounce_period) >= 0 )
{
ScanState = 0;
}
break;
default:
ScanState = 0;
TS_StartLow = FALSE;
break;
}
}
/*** BeginHeader _TsChangeState, btnSnapshot */
int _TsChangeState( long btnState );
extern int btnSnapshot;
/*** EndHeader */
int btnSnapshot;
/* START _FUNCTION DESCRIPTION ********************************************
_TsChangeState <PWS570_7843.LIB>
SYNTAX: int _TsChangeState(long btnState);
DESCRIPTION: Support function for the TsScanState function to read the
touchscreen.
PARAMETER: Value to indicate what state the TsScanState function
is processing.
RETURN VALUE: 0 = State machine not finished.
1 = State machine finished.
END DESCRIPTION **********************************************************/
nodebug
int _TsChangeState( long btnState ) {
auto char valid, executionDone;
static int xkey1, ykey1, xkey2, ykey2;
static unsigned long debounce_period;
static int ts_counter;
static int state;
#GLOBAL_INIT{btnSnapshot = 0;
state = 0;
ts_counter = 0;}
executionDone = TRUE;
BtnOneKeyBuf = -1;
if(btnState == BTNRELEASE)
{
BtnOneKeyBuf = BTNRELEASE;
btnpressed = 0;
btnSnapshot = 1;
state = 0;
executionDone = TRUE;
}
else
{
switch(state)
{
case 0:
if(TsActive())
{
TsXYvector(&xkey1, &ykey1, CAL_MODE);
debounce_period = MS_TIMER + TS_RECHECK;
state = 1;
executionDone = FALSE;
}
break;
case 1:
if((long) (MS_TIMER-debounce_period) >= 0 )
{
executionDone = FALSE;
state = 2;
}
break;
case 2:
if(TsActive())
{
TsXYvector(&xkey2, &ykey2, CAL_MODE);
if(xkey2 >= (xkey1 - 10) && xkey2 <= (xkey1 + 10) &&
ykey2 >= (ykey1 - 10) && ykey2 <= (ykey1 + 10))
{
ts_counter++;
if(ts_counter > 10)
{
xkey1 = (xkey1+xkey2)/2;
ykey1 = (ykey1+ykey2)/2;
BtnOneKeyBuf = ((long)xkey1<<16) | ykey1;
btnpressed = 1;
btnSnapshot = 1;
ts_counter = 0;
state = 0;
executionDone = TRUE;
}
else
{
debounce_period = MS_TIMER + TS_RECHECK;
executionDone = FALSE;
}
}
else
{
executionDone = TRUE;
ts_counter = 0;
state = 0;
}
}
else
{
executionDone = TRUE;
ts_counter = 0;
state = 0;
}
break;
default:
executionDone = TRUE;
ts_counter = 0;
state = 0;
break;
}
}
return(executionDone);
}
/*** BeginHeader TsXYBuffer, BtnOneKeyBuf */
long TsXYBuffer( void );
extern long BtnOneKeyBuf;
/*** EndHeader */
long BtnOneKeyBuf;
/* START FUNCTION DESCRIPTION ********************************************
TsXYBuffer <PWS570_7843.LIB>
SYNTAX: long TsXYBuffer( void );
DESCRIPTION: This function returns either the x,y coordinate's or the
touchscreen BTN_RELEASE status code which was processed
by the TsScanState function. This function is non-
reentrant.
PARAMETERS: None.
RETURN VALUE: - Current x,y location of where the touchscreen is
being pressed. The X-coordinate is returned in the
MSB, and Y-coordinate is returned in the LSB of the
long integer value.
- BTNRELEASE (0x80000000L) indicating the touchscreen
was released.
- Value of -1 to indicate no activity has occurred.
SEE ALSO: TsXYvector, TsActive, TsScanState, brdInit
END DESCRIPTION **********************************************************/
nodebug
long TsXYBuffer( void )
{
auto long tmp;
#GLOBAL_INIT{BtnOneKeyBuf = -1;}
tmp = BtnOneKeyBuf;
BtnOneKeyBuf = -1;
return tmp;
}
/*** BeginHeader */
#endif
/*** EndHeader */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -