📄 keypad.c
字号:
/****************************************************************************/
void keypad_LED( KPLED_ID id, BOOL state )
{
switch( id )
{
case KPLED_POWER:
GPIO_SetPin( GIO_KPAD_LEDPOWER, state );
break;
case KPLED_LAMP:
GPIO_SetPin( GIO_KPAD_LEDLAMP, state );
break;
case KPLED_TEMP:
GPIO_SetPin( GIO_KPAD_LED_HOT, state );
break;
}
}
/****************************************************************************/
/* Set menu/function mode. */
/****************************************************************************/
void keypad_menuMode( BOOL isMenuMode )
{
if( isMenuMode )
menubit = SETMENU;
else
menubit = SETKPAD;
}
/****************************************************************************/
/* Keypad scan callback. */
/****************************************************************************/
int16 keypad_poll( uint16 tick )
{
UIREP keyReport;
if( KCODE_NIL != ( keyReport.key = keypad_scan()))
{
keyReport.mouse = FALSE;
dbmsg_ftrace( DBM_KEY, "keypad: key=%02x\r\n", keyReport.key );
guiKeycode( &keyReport, TRUE );
}
return KEYPAD_PERIOD / RTOS_MS_PER_TICK;
}
/****************************************************************************/
/* Keypad scanner. */
/* */
/* This function de-bounces key press/release operations and returns */
/* key-press codes. */
/* */
/* Only one code is returned per scan. If two keys are pressed or released */
/* at the same instant, the second code will be returned on the following */
/* scan. */
/* */
/* Returns no-change or ( key ID + open/close ) indication. */
/****************************************************************************/
KCODE_ENUM keypad_scan( void )
{
int16 i; /* key index */
uint08 scancode = 0; /* keypad scan code */
BOOL pinstate; /* GPIO pin state */
KCODE_ENUM retkey = KCODE_NIL; /* keycode return */
/****************************************************/
/* Generate keypad scan code. */
/****************************************************/
for( i = 0; i < scancount; i++ )
{
scancode <<= 1;
GPIO_GetPin( (GPIOPINS)keyScanVector[i], &pinstate );
if( !pinstate ) scancode++;
}
/****************************************************/
/* Reset scanner state machine if the new scan code */
/* is different from the prior scan. Then run the */
/* state machine. */
/****************************************************/
if( scancode != currentscan )
{
state = STATE_DEBOUNCE; /* go debounce a new code */
currentscan = scancode; /* update current scan code */
count = 0; /* reset scan counter */
}
switch( state )
{
case STATE_DEBOUNCE: /* debounce */
if( ++count >= DEBOUNCECOUNT )
{
if( decodeKey( scancode, &retkey ))
{
state = STATE_DELAY; /* next, delay for auto-repeat */
savekey = retkey; /* save for auto-repeat */
count = 0; /* reset scan counter */
}
else
state = STATE_IDLE; /* invalid keypress */
}
break;
case STATE_DELAY: /* delay for auto-repeat */
if( ++count >= DELAYCOUNT )
{
state = STATE_REPEAT; /* next, do auto-repeat */
retkey = savekey; /* resend last key */
count = 0; /* reset scan counter */
}
break;
case STATE_REPEAT: /* auto-repeat */
if( ++count >= REPEATCOUNT )
{
retkey = savekey; /* resend last key */
count = 0; /* reset scan counter */
}
break;
default:
state = STATE_IDLE; /* no-op */
break;
}
return retkey; /* return key event, if any */
}
/****************************************************************************/
/* Scan code decoder. */
/* */
/* Determine if the scan code is valid. If so, write the corresponding key */
/* code at the requested address. If not, write a NIL indication. */
/* */
/* Returns TRUE if the scan code is valid and if the key may be repeated. */
/****************************************************************************/
static BOOL decodeKey( uint08 scancode, KCODE_ENUM *retcode )
{
int16 i; /* index */
scancode |= menubit; /* OR the menu mode select bit */
for( i = 0 ; i < keycount; i++ ) /* scan key entries */
{
if( scancode == keyCode[i].scan ) /* if scan code found */
{
*retcode = keyCode[i].code; /* keycode */
return keyCode[i].repflag; /* auto-repeat flag */
}
}
*retcode = KCODE_NIL; /* scan code not found */
return FALSE; /* no auto-repeat */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -