我的学习之旅keyboard.h和keyboard.c

来源:互联网 发布:94红磡 知乎 编辑:程序博客网 时间:2024/05/05 18:59
/*按下alt之后的key与ascii的映射表  */static unsigned char g_key2ascii_alt_map_table[] = {    0, 0, 0, '@', 0, '$', 0, 0, '{', '[', ']', '}', '\\', 0, 0, 0, 0, 0, 0, 0,    0, 0, 0, 0, 0, 0, 0, '~', 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,    0, 0, 0, 0, '|', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};static unsigned char g_number_table[] = {    '7', '8', '9', ' ', '4', '5', '6', ' ', '1', '2', '3', '0'};static unsigned int g_current_mode = 0;static unsigned char g_caps_led_status = 0;int self_func(unsigned char scan_code){    unsigned char *key_map = &g_key2ascii_normal_map_table[0];    unsigned char ch;    unsigned short length = sizeof(g_key2ascii_normal_map_table);    tty_struct_t *tty;    int i;        /*只处理非键盘键的0~9数字,a~z字母,shift键和Capslock键,       回车键和回退键,其他默认返回       只支持按下键后又放开,不支持持续按键   */    if( g_current_mode & SHIFT_MODE ) {        if( !(g_current_mode & CAPS_MODE ) ) {            key_map = &g_key2ascii_shift_map_table[0];            length = sizeof(g_key2ascii_shift_map_table);         }    }    else if ( g_current_mode & CAPS_MODE ) {        key_map = &g_key2ascii_shift_map_table[0];        length = sizeof(g_key2ascii_shift_map_table);    }    if( scan_code >= length )        return 0;        ch = key_map[scan_code & 0xff];    /*只支持字母、数字和空格*/    if( ( ch <= 'Z' && ch >= 'A' ) || ( ch <= 'z' && ch >= 'a' ) ||( ch <= '9' && ch >= '0' ) ||ch == 127  || ch == 10 || ch == ' ') {                /*入console队列并打印*/                tty_write(get_tty(CONSOLE_ID), (char *)&ch, 1 );        if( g_ttx_task ) {            tty = get_tty(g_ttx_task->tty_channel_id);            //printk("tty:%x\n",(unsigned int)tty);        if( !tty )            return 0;        /*处理后入read_q供任务读取并处理*/                if (((tty->read_q.tail-tty->read_q.head-1)&(TTY_BUF_SIZE-1))) {            put_char_into_queue(tty, ch);            //printk("put %d into read_q with [%d>>%d]\n", ch, tty->read_q.head, tty->read_q.tail);            wmb();            return 0;            }        }    }    return 0;}
0 0