?? kbd_task.c
字號(hào):
/*C**************************************************************************
* NAME: kbd_task.c
*----------------------------------------------------------------------------
* Copyright (c) 2002 Atmel.
*----------------------------------------------------------------------------
* RELEASE: snd1c-demo-hdd-0_2_0
* REVISION: 1.1
*----------------------------------------------------------------------------
* PURPOSE:
* This file contains the keyboard task and attached routines
*
* NOTES:
* Global Variables:
* - gl_key_press: bit in bdata space
* - gl_key_repeat: bit in bdata space
* - gl_key: byte in idata space
* - gl_kbd_tick: byte in data space
*
* keypad repeat behavior
* ---------------------------------------------------------------> t
* key_press ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
* <--- 1 --->< 2 >< 2 >< 2 >< 2 ><-2-><-2-><-2-><-2-><-2-><-2->
* <----------- 3 -------------->
* delays: 0: KBD_DEBOUNCE_TEMPO debounce time (not represented)
* 1: KBD_REP_START_TEMPO auto-repeat start time
* 2: KBD_REP_CONT_TEMPO auto-repeat time
* 3: KBD_REP_LONG_TEMPO long repeat start time
*****************************************************************************/
/*_____ I N C L U D E S ____________________________________________________*/
#include "config.h" /* system configuration */
#include "lib_demob\board.h" /* board definition */
#include "lib\kbd\kbd_drv.h" /* Keyboard driver definition */
#include "..\display\disp.h" /* display definition */
#include "kbd_task.h" /* Keyboard task definition */
/*_____ M A C R O S ________________________________________________________*/
/*_____ D E F I N I T I O N ________________________________________________*/
extern bdata bit gl_key_press; /* set to TRUE if a key is decoded */
extern bdata bit gl_key_repeat; /* set to TRUE during repeat start */
extern idata Byte gl_key; /* value of the key pressed */
extern data Byte gl_kbd_tick; /* keypad tick counter */
static Byte kbd_state; /* keyboard task state */
/*_____ D E C L A R A T I O N ______________________________________________*/
/*F**************************************************************************
* NAME: kbd_task_init
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Keyboard task initialisation
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void kbd_task_init (void)
{
gl_key_press = FALSE; /* no key pressed */
gl_key_repeat = FALSE; /* no repeat started */
gl_key = NO_KEY;
if (kbd_init() == ON) /* keyboard initialization */
kbd_state = KBD_IDLE;
else
print_kbd_lock();
kbd_state = KBD_LOCK;
}
/*F**************************************************************************
* NAME: kbd_task
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Keyboard task
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void kbd_task (void)
{
switch (kbd_state)
{
case KBD_LOCK:
if (!Kbd_key_locked())
{
print_kbd_unlock();
kbd_state = KBD_IDLE;
kbd_init();
}
break;
case KBD_IDLE:
if (Kbd_key_event())
{ /* key pressed */
gl_kbd_tick = KBD_DEBOUNCE_INIT; /* init debounce timer */
kbd_state = KBD_DEBOUNCE;
}
break;
case KBD_DEBOUNCE:
if (gl_kbd_tick > KBD_DEBOUNCE_TEMPO)
{
gl_key = kbd_decode(); /* read key pressed */
if (gl_key != NO_KEY) /* if real key pressed */
{
if (gl_key == KEY_LOCK)
{
print_kbd_lock();
kbd_state = KBD_LOCK;
}
else
{
gl_key_press = TRUE; /* signal to other tasks */
kbd_state = KBD_REP_START;
gl_key_repeat = TRUE;
gl_kbd_tick = KBD_REP_START_INIT; /* start repeat timer */
}
}
else
{
kbd_state = KBD_IDLE;
}
}
break;
case KBD_REP_START:
if (Kbd_key_event())
{ /* key pressed or released */
gl_kbd_tick = KBD_DEBOUNCE_INIT; /* init debounce timer */
kbd_state = KBD_DEBOUNCE;
gl_key_repeat = FALSE; /* end of repeat */
}
else
{
if (gl_kbd_tick > KBD_REP_START_TEMPO)
{
gl_key = kbd_decode(); /* read key pressed */
if (gl_key != NO_KEY) /* if real key pressed */
{
gl_key_press = TRUE; /* signal to other tasks */
gl_key |= KBD_REP_MASK; /* mark as repeated key */
kbd_state = KBD_REP_CONT;
gl_kbd_tick = KBD_REP_CONT_INIT;/* continue repeat timer */
}
else
{
gl_key_repeat = FALSE; /* end of repeat */
kbd_state = KBD_IDLE;
}
}
}
break;
case KBD_REP_CONT:
if (Kbd_key_event())
{ /* key pressed or released */
gl_key_repeat = FALSE; /* end of repeat */
gl_kbd_tick = KBD_DEBOUNCE_INIT; /* init debounce timer */
kbd_state = KBD_DEBOUNCE;
}
else
{
if (gl_kbd_tick > KBD_REP_CONT_TEMPO)
{
gl_key = kbd_decode(); /* read key pressed */
if (gl_key != NO_KEY) /* if real key pressed */
{
kbd_state++; /* for long repeat check */
gl_key_press = TRUE; /* signal to other tasks */
gl_key |= KBD_REP_MASK; /* mark as repeated key */
gl_kbd_tick = KBD_REP_CONT_INIT;/* continue repeat timer */
}
else
{
gl_key_repeat = FALSE; /* end of repeat */
kbd_state = KBD_IDLE;
}
}
}
break;
case KBD_REP_LONG:
if (Kbd_key_event())
{ /* key pressed or released */
gl_key_repeat = FALSE; /* end of repeat */
gl_kbd_tick = KBD_DEBOUNCE_INIT; /* init debounce timer */
kbd_state = KBD_DEBOUNCE;
}
else
{
if (gl_kbd_tick > KBD_REP_CONT_TEMPO)
{
gl_key = kbd_decode(); /* read key pressed */
if (gl_key != NO_KEY) /* if real key pressed */
{
gl_key_press = TRUE; /* signal to other tasks */
gl_key |= KBD_LREP_MASK; /* mark as repeated key */
gl_kbd_tick = KBD_REP_CONT_INIT;/* continue repeat timer */
}
else
{
gl_key_repeat = FALSE; /* end of repeat */
kbd_state = KBD_IDLE;
}
}
}
break;
default: /* long repeat state */
if (Kbd_key_event())
{ /* key pressed or released */
gl_key_repeat = FALSE; /* end of repeat */
gl_kbd_tick = KBD_DEBOUNCE_INIT; /* init debounce timer */
kbd_state = KBD_DEBOUNCE;
}
else
{
if (gl_kbd_tick > KBD_REP_CONT_TEMPO)
{
gl_key = kbd_decode(); /* read key pressed */
if (gl_key != NO_KEY) /* if real key pressed */
{
if (kbd_state == KBD_REP_LONG - 1)
{
gl_key |= KBD_LREP_MASK; /* mark as long repeated key */
}
else
{
gl_key |= KBD_REP_MASK; /* mark as repeated key */
}
kbd_state++; /* for long repeat check */
gl_key_press = TRUE; /* signal to other tasks */
gl_kbd_tick = KBD_REP_CONT_INIT;/* continue repeat timer */
}
else
{
gl_key_repeat = FALSE; /* end of repeat */
kbd_state = KBD_IDLE;
}
}
}
break;
}
}
/*F**************************************************************************
* NAME: kbd_set_stop
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Simulate STOP key press
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* Called from mode task before switching to download state
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void kbd_set_stop (void)
{
gl_key = KEY_STOP;
gl_key_press = TRUE;
if (kbd_state != KBD_LOCK)
kbd_state = KBD_IDLE;
}
/*F**************************************************************************
* NAME: kbd_stop_repeat
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Simulate STOP key press
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* Called from IHM task to stop
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void kbd_stop_repeat (void)
{
gl_key_repeat = FALSE; /* end of repeat */
kbd_state = KBD_IDLE;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -