/*_____ I N C L U D E S ____________________________________________________*/ #include "config.h" /* lib configuration header */ #include "include/kbd_drv.h" /* Keyboard driver definition */ /*_____ 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 ______________________________________________*/ static void kbd_set_prio (Byte); /*F************************************************************************** * NAME: kbd_init *---------------------------------------------------------------------------- * PARAMS: * * return: *---------------------------------------------------------------------------- * PURPOSE: * Keyboard initialisation function *---------------------------------------------------------------------------- * EXAMPLE: *---------------------------------------------------------------------------- * NOTE: *---------------------------------------------------------------------------- * REQUIREMENTS: * ram/xram: * cycle: * stack: * code: *****************************************************************************/ Byte kbd_init (void) { kbd_set_prio(KBD_PRIO); KBSTA = KBSTA; /* clear pending interrupt */ P_KBD |= MSK_COL; /* all columns inactive */ KBCON = KB_STD; /* detect 1 to 0 transition */ P_KBD &= MSK_STD; /* 0 on all columns */ return ON; /* Keyboard not locked */ } /*F************************************************************************** * NAME: kbd_set_prio *---------------------------------------------------------------------------- * PARAMS: * * return: *---------------------------------------------------------------------------- * PURPOSE: * Set the keyboard interface priority interrupt *---------------------------------------------------------------------------- * EXAMPLE: *---------------------------------------------------------------------------- * NOTE: *---------------------------------------------------------------------------- * REQUIREMENTS: * ram/xram: * cycle: * stack: * code: *****************************************************************************/ 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; } } /*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; P_KBD |= MSK_COL; /* all columns inactive */ /* COL3 = 0; COL3 test (always 0) */ key = (P_KBD & MSK_PKB); if (key != NK_COL3) { KBCON |= (KBSTA << 4); /*detect 0 to 1 transition */ P_KBD &= MSK_STD; /* 0 on all columns */ KBSTA = KBSTA; /* clear pending interrupt */ return (key); } COL2 = 0; /* COL2 test */ key = (P_KBD & MSK_PKB); if (key != NK_COL2) { KBCON |= (KBSTA << 4); /*detect 0 to 1 transition */ P_KBD &= MSK_STD; /* 0 on all columns */ KBSTA = KBSTA; /* clear pending interrupt */ return (key); } COL1 = 0; /* COL1 test */ key = (P_KBD & MSK_PKB); if (key != NK_COL1) { KBCON |= (KBSTA << 4); /*detect 0 to 1 transition */ P_KBD &= MSK_STD; /* 0 on all columns */ KBSTA = KBSTA; /* clear pending interrupt */ return (key); } COL0 = 0; /* COL0 test */ key = (P_KBD & MSK_PKB); if (key != NK_COL0) { KBCON |= (KBSTA << 4); /*detect 0 to 1 transition */ KBSTA = KBSTA; /* clear pending interrupt */ return (key); } KBCON = KB_STD; /* detect 1 to 0 transition */ P_KBD &= MSK_STD; /* 0 on all columns */ KBSTA = KBSTA; /* clear pending interrupt */ return NO_KEY; }