📄 key_drv.c
字号:
/*C**************************************************************************
* NAME: kbd_drv.c
*----------------------------------------------------------------------------
* Copyright (c) 2003 Atmel.
*----------------------------------------------------------------------------
* RELEASE: snd1c-refd-nf-4_0_3
* REVISION: 1.10
*----------------------------------------------------------------------------
* PURPOSE:
* This file contains the keypad driver routines
*
* NOTES:
* Driver Configuration:
* - KBD_EXIT_PD in config.h define as:
* TRUE: to allow exit of power down by keyboard
* FALSE: to disallow exit of power down by keyboard
* - LOCK_ROW in config.h
* - KEY_LOCK in config.h
* Global Variables:
* - gl_kbd_lock in bdata space
*****************************************************************************/
/*_____ I N C L U D E S ____________________________________________________*/
#include "config.h" /* lib configuration header */
#include "key_drv.h" /* Keyboard driver definition */
#include "modules\song\song_drv.h"
#include "lib_mcu\lcd\lcd_drv.h"
#include "lib_mcu\ide\ideio.h"
#include "modules\mass\usb_task.h"
#include "modules\file\fat.h"
/*_____ M A C R O S ________________________________________________________*/
/*_____ D E F I N I T I O N ________________________________________________*/
/*_____ D E C L A R A T I O N ______________________________________________*/
extern bdata bit gl_key_press; /* TRUE when a key is decoded */
extern idata Byte gl_key; /* value of the key pressed */
extern idata Byte system_mode;
idata keytemp;
extern idata Byte play_pause;
extern idata Byte bass_nobass;
extern Byte song_sound;
idata Byte key_mode;
static void kbd_set_prio (Byte);
static void kbd_install (void);
/*F**************************************************************************
* NAME: kbd_init
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Keyboard initialisation function
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
* ram/xram:
* cycle:
* stack:
* code:
*****************************************************************************/
void kbd_init (void)
{
#if KBD_EXIT_PD
Kbd_enable_pd_exit(); /* enable keyboard Power-Down exit */
kbd_set_prio(KBD_PRIO);
#endif
kbd_install();
}
/*F**************************************************************************
* NAME: kbd_install
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Keyboard IT and columns mask init
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
* ram/xram:
* cycle:
* stack:
* code:
*****************************************************************************/
void kbd_install (void)
{
KBSTA = KBSTA; /* dummy read for clearing pending interrupt */
#if KBD_EXIT_PD
Kbd_enable_int(); /* enable or re-enable the kbd interrupt */
Kbd_unmask_int();
Kbd_low_int();
#endif
}
/*F**************************************************************************
* NAME: kbd_set_prio
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Set the keyboard interface priority interrupt
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
* ram/xram:
* cycle:
* stack:
* code:
*****************************************************************************/
#if KBD_EXIT_PD
void kbd_set_prio (Byte priority)
{
if ((priority == 1) || (priority == 3)) /* set LSB priority bit */
{
IPL1 |= MSK_EKB;
}
if ((priority == 2) || (priority == 3)) /* set MSB priority bit */
{
IPH1 |= MSK_EKB;
}
}
#endif
/*F**************************************************************************
* NAME: kbd_decode
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
* Decoded key pressed
*----------------------------------------------------------------------------
* PURPOSE:
* Decode the key that generated an IT
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
* ram/xram:
* cycle:
* stack:
* code:
*****************************************************************************/
Byte kbd_decode (void)
{
Byte key;
switch (keytemp & 0x0f)
{
case KEY_0:
gl_key_press = TRUE;
key = KEY_0;
kbd_install();
return (key);
case KEY_1:
gl_key_press = TRUE;
key = KEY_1;
kbd_install();
return (key);
case KEY_2:
gl_key_press = TRUE;
key = KEY_2;
kbd_install();
return (key);
case KEY_3:
gl_key_press = TRUE;
key = KEY_3;
kbd_install();
return (key);
default :
gl_key_press = FALSE;
key = NO_KEY;
kbd_install();
return(key);
}
}
void Keydelay(Uint32 time)
{
Uint32 i;
for(i = 0; i < time; i++);
}
void key_task(void)
{
gl_key = NO_KEY;
switch(system_mode)
{
case MP3_STATUS:
{
switch(key_mode)
{
case MP3_PLAY_MODE:
if (kbd_decode() == KEY_0) {
key_mode = MP3_VOL_MODE;
song_sound = SND_VOLUME;
lcdcls(0x90);
print_sound_level();
}
else if (kbd_decode() == KEY_1) gl_key = KEY_PREV;
else if (kbd_decode() == KEY_2) gl_key = KEY_NEXT;
else if (kbd_decode() == KEY_3)
{
Keydelay(0x0fff);
play_pause = ~play_pause;
if (play_pause) gl_key = KEY_PLAY;
else gl_key = KEY_PAUSE;
}
break;
case MP3_VOL_MODE:
if (kbd_decode() == KEY_0) {
key_mode = MP3_BASS_MODE;
song_sound = SND_BASS;
lcdcls(0x90);
print_sound_level();
}
else if (kbd_decode() == KEY_1) gl_key = KEY_DEC;
else if (kbd_decode() == KEY_2) gl_key = KEY_INC;
break;
case MP3_BASS_MODE:
if (kbd_decode() == KEY_0) {
key_mode = MP3_MED_MODE;
song_sound = SND_MEDIUM;
lcdcls(0x90);
print_sound_level();
}
else if (kbd_decode() == KEY_1) gl_key = KEY_DEC;
else if (kbd_decode() == KEY_2) gl_key = KEY_INC;
else if (kbd_decode() == KEY_3)
{
Keydelay(0x0fff);
bass_nobass = ~bass_nobass;
if (bass_nobass) {
MP3CON |= MSK_MPBBST;
printch(0x97,"B ");
gl_key = KEY_BASS;
}
else {
MP3CON &= (~MSK_MPBBST);
printch(0x97,"N ");
gl_key = KEY_NOBASS;
}
}
break;
case MP3_MED_MODE:
if (kbd_decode() == KEY_0) {
key_mode = MP3_TRE_MODE;
song_sound = SND_TREBLE;
lcdcls(0x90);
print_sound_level();
}
else if (kbd_decode() == KEY_1) gl_key = KEY_DEC;
else if (kbd_decode() == KEY_2) gl_key = KEY_INC;
break;
case MP3_TRE_MODE:
if (kbd_decode() == KEY_0) {
key_mode = MP3_OTHER_MODE;
lcdcls(0x90);
//printch(0x90,"进入USB按KEY3 ");
}
else if (kbd_decode() == KEY_1) gl_key = KEY_DEC;
else if (kbd_decode() == KEY_2) gl_key = KEY_INC;
break;
case MP3_OTHER_MODE:
if (kbd_decode() == KEY_0) {
key_mode = MP3_PLAY_MODE;
song_sound = SND_NONDIS;
lcdcls(0x90);
print_sound_level();
}
else if (kbd_decode() == KEY_1) gl_key = KEY_PARENT;
else if (kbd_decode() == KEY_2) gl_key = KEY_REPEAT;
else if (kbd_decode() == KEY_3) {
}
//gl_key = KEY_STOP;
break;
default : break;
}
}
break;
case REC_STATUS:
{break;}
default : break;
}
keytemp = 0x00;
}
/*F**************************************************************************
* NAME: kbd_int
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
* Keyboard interrupt function
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
* This isr is called when a key is pressed to get out power-down Interrupt
* is re-enable in the install routine
*----------------------------------------------------------------------------
* REQUIREMENTS:
* ram/xram:
* cycle:
* stack:
* code:
*****************************************************************************/
#if KBD_EXIT_PD
Interrupt(kbd_int (void), IRQ_KBD)
{
keytemp = KBSTA;
Kbd_disable_int(); /* disable interrupt */
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -