⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kbd_support.c

📁 开放源码实时操作系统源码.
💻 C
📖 第 1 页 / 共 2 页
字号:
//==========================================================================
//
//        kbd_support.c
//
//        Cirrus Logic EDB7xxx eval board ASCII keyboard support functions
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s):     gthomas
// Contributors:  gthomas
// Date:          1999-05-15
// Description:   Functions used to support ASCII keyboard
//####DESCRIPTIONEND####

static char kbd_server_stack[STACK_SIZE];
static cyg_thread kbd_server_thread_data;
static cyg_handle_t kbd_server_thread_handle;

static cyg_interrupt kbd_interrupt;
static cyg_handle_t  kbd_interrupt_handle;

static cyg_mbox      kbd_events_mbox;
static cyg_handle_t  kbd_events_mbox_handle;
static cyg_sem_t     kbd_sem;

static cyg_uint8 col_state[8];
static cyg_uint8 ext_state[8];

static void
kbd_delay(void)
{
    volatile int i;
    for (i = 0;  i < 250;  i++) ;
}

static void
kbd_scan(void)
{
    int i;
    cyg_uint8 port_data, ext_data;
    // Turn off drive (de-select) all columns
    *(volatile cyg_uint32 *)SYSCON1 = (*(volatile cyg_uint32 *)SYSCON1 & ~SYSCON1_KBD_CTL) |
        SYSCON1_KBD_LOW;
    for (i = 0;  i < 8;  i++) {
        // Select column 'i'
        *(volatile cyg_uint32 *)SYSCON1 = (*(volatile cyg_uint32 *)SYSCON1 & ~SYSCON1_KBD_CTL) |
            SYSCON1_KBD_COL(i);
        // Small pause to let the wires charge up :-)
        kbd_delay();
        // Grab the data
        col_state[i] = port_data = *(volatile cyg_uint8 *)PADR;
        ext_state[i] = ext_data = *(volatile cyg_uint8 *)KBD_PORT;
        // De-Select column 'i'
        *(volatile cyg_uint32 *)SYSCON1 = (*(volatile cyg_uint32 *)SYSCON1 & ~SYSCON1_KBD_CTL) |
            SYSCON1_KBD_TRISTATE;
        // Allow line to go slack
        kbd_delay();
    }
    // Turn on drive (select) all columns - necessary to see interrupts
    *(volatile cyg_uint32 *)SYSCON1 = (*(volatile cyg_uint32 *)SYSCON1 & ~SYSCON1_KBD_CTL) |
        SYSCON1_KBD_HIGH;
}

static cyg_uint8     kbd_state[128];      // Known state of each key
static cyg_uint8     kbd_new_state[128];  // Current state of each key

// Row #1
#define KBD_Escape     0x00
#define KBD_F1         0x01
#define KBD_F2         0x02
#define KBD_F3         0x03
#define KBD_F4         0x04
#define KBD_F5         0x05
#define KBD_F6         0x06
#define KBD_F7         0x07
#define KBD_F8         0x08
#define KBD_F9         0x09
#define KBD_F10        0x0A
#define KBD_NumLock    0x0B
#define KBD_SysReq     0x0C
#define KBD_ScrlLock   0x0D
#define KBD_Break      0x0E
// Row #2
#define KBD_1          0x10
#define KBD_2          0x11
#define KBD_3          0x12
#define KBD_4          0x13
#define KBD_5          0x14
#define KBD_6          0x15
#define KBD_7          0x16
#define KBD_8          0x17
#define KBD_9          0x18
#define KBD_0          0x19
#define KBD_Hyphen     0x1A
#define KBD_Equals     0x1B
#define KBD_BackSpace  0x1C
#define KBD_Home       0x1D
// Row #3
#define KBD_Tab        0x20
#define KBD_Q          0x21
#define KBD_W          0x22
#define KBD_E          0x23
#define KBD_R          0x24
#define KBD_T          0x25
#define KBD_Y          0x26
#define KBD_U          0x27
#define KBD_I          0x28
#define KBD_O          0x29
#define KBD_P          0x2A
#define KBD_LeftBrkt   0x2B
#define KBD_RightBrkt  0x2C
#define KBD_BackSlash  0x2D
#define KBD_PageUp     0x2E
// Row #4
#define KBD_CapsLock   0x30
#define KBD_A          0x31
#define KBD_S          0x32
#define KBD_D          0x33
#define KBD_F          0x34
#define KBD_G          0x35
#define KBD_H          0x36
#define KBD_J          0x37
#define KBD_K          0x38
#define KBD_L          0x39
#define KBD_SemiColon  0x3A
#define KBD_Quote      0x3B
#define KBD_Enter      0x3C
#define KBD_PageDown   0x3D
// Row #5
#define KBD_LeftShift  0x40
#define KBD_Z          0x41
#define KBD_X          0x42
#define KBD_C          0x43
#define KBD_V          0x44
#define KBD_B          0x45
#define KBD_N          0x46
#define KBD_M          0x47
#define KBD_Comma      0x48
#define KBD_Period     0x49
#define KBD_Slash      0x4A
#define KBD_RightShift 0x4B
#define KBD_UpArrow    0x4C
#define KBD_End        0x4D
// Row #6
#define KBD_Ctrl       0x50
#define KBD_Function   0x51
#define KBD_LeftAlt    0x52
#define KBD_Accent     0x53
#define KBD_Space      0x54
#define KBD_RightAlt   0x55
#define KBD_Ins        0x56
#define KBD_Del        0x57
#define KBD_LeftArrow  0x58
#define KBD_DownArrow  0x59
#define KBD_RightArrow 0x5A

#define KBD_Press      0x80  // Event has this bit when the key is pressed
#define KBD_Empty      0xFF

// Map column, bit -> keycode
static cyg_uint32    kbd_map[8][16] = {
    // Column #0
    {KBD_Escape,    KBD_1,          KBD_Tab,        KBD_CapsLock,
     KBD_BackSlash, KBD_Space,      KBD_LeftArrow,  KBD_UpArrow,
     KBD_DownArrow, KBD_RightArrow, KBD_LeftShift,  KBD_Ctrl, 
     KBD_Function,  KBD_LeftAlt,    KBD_RightAlt,   KBD_RightShift },
    // Column #1
    {KBD_F5,        KBD_6,          KBD_T,          KBD_G,  
     KBD_B,         KBD_Slash,      KBD_SemiColon,  KBD_P,  
     KBD_Hyphen,    KBD_F10,        KBD_Empty,      KBD_Empty,
     KBD_Empty,     KBD_Empty,      KBD_Empty,      KBD_Empty     },
    // Column #2
    {KBD_F4,        KBD_5,          KBD_R,          KBD_F,  
     KBD_V,         KBD_Del,        KBD_Quote,      KBD_LeftBrkt,  
     KBD_Equals,    KBD_NumLock,    KBD_Empty,      KBD_Empty,
     KBD_Empty,     KBD_Empty,      KBD_Empty,      KBD_Empty },
    // Column #3
    {KBD_F3,        KBD_4,          KBD_E,          KBD_D,  
     KBD_C,         KBD_Ins,        KBD_Empty,      KBD_RightBrkt,  
     KBD_BackSpace, KBD_SysReq,     KBD_Empty,      KBD_Empty,
     KBD_Empty,     KBD_Empty,      KBD_Empty,      KBD_Empty },
    // Column #4
    {KBD_F2,        KBD_3,          KBD_W,          KBD_S,  
     KBD_X,         KBD_Empty,      KBD_Enter,      KBD_Empty,
     KBD_Empty,     KBD_ScrlLock,   KBD_Empty,      KBD_Empty,
     KBD_Empty,     KBD_Empty,      KBD_Empty,      KBD_Empty },
    // Column #5
    {KBD_F1,        KBD_2,          KBD_Q,          KBD_A,  
     KBD_Z,         KBD_End,        KBD_PageDown,   KBD_PageUp,
     KBD_Home,      KBD_Break,      KBD_Empty,      KBD_Empty,
     KBD_Empty,     KBD_Empty,      KBD_Empty,      KBD_Empty },
    // Column #6
    {KBD_F6,        KBD_7,          KBD_Y,          KBD_H,  
     KBD_N,         KBD_Period,     KBD_L,          KBD_O,  
     KBD_0,         KBD_F9,         KBD_Empty,      KBD_Empty,
     KBD_Empty,     KBD_Empty,      KBD_Empty,      KBD_Empty },
    // Column #7
    {KBD_F7,        KBD_8,          KBD_U,          KBD_J,  
     KBD_M,         KBD_Comma,      KBD_K,          KBD_I,  
     KBD_9,         KBD_F8,         KBD_Empty,      KBD_Empty,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -