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

📄 keyboard.c

📁 AT91RM9200的完整启动代码:包括loader, boot及U-boot三部分均已编译通过!欢迎下载使用!
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************                   SciTech OS Portability Manager Library**  ========================================================================**    The contents of this file are subject to the SciTech MGL Public*    License Version 1.0 (the "License"); you may not use this file*    except in compliance with the License. You may obtain a copy of*    the License at http://www.scitechsoft.com/mgl-license.txt**    Software distributed under the License is distributed on an*    "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or*    implied. See the License for the specific language governing*    rights and limitations under the License.**    The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.**    The Initial Developer of the Original Code is SciTech Software, Inc.*    All Rights Reserved.**  ========================================================================** Language:     ANSI C* Environment:  Any** Description:  Direct keyboard event handling module. This module contains*               code to process raw scan code information, convert it to*               virtual scan codes and do code page translation to ASCII*               for different international keyboard layouts.*****************************************************************************//*---------------------------- Implementation -----------------------------*//****************************************************************************PARAMETERS:scanCode    - Keyboard scan code to translatetable       - Code page table to searchcount       - Number of entries in the code page tableREMARKS:This function translates the scan codes from keyboard scan codes to ASCIIcodes using a binary search on the code page table.****************************************************************************/static uchar translateScan(    uchar scanCode,    codepage_entry_t *table,    int count){    codepage_entry_t    *test;    int                 n,pivot,val;    for (n = count; n > 0; ) {        pivot = n >> 1;        test = table + pivot;        val = scanCode - test->scanCode;        if (val < 0)            n = pivot;        else if (val == 0)            return test->asciiCode;        else {            table = test + 1;            n -= pivot + 1;            }        }    return 0;}/****************************************************************************REMARKS:This macro/function is used to converts the scan codes reported by thekeyboard to our event libraries normalised format. We only have one scancode for the 'A' key, and use shift modifiers to determine if it is aCtrl-F1, Alt-F1 etc. The raw scan codes from the keyboard work this way,but the OS gives us 'cooked' scan codes, we have to translate them backto the raw format.{secret}****************************************************************************/void _EVT_maskKeyCode(    event_t *evt){    int ascii,scan = EVT_scanCode(evt->message);    evt->message &= ~0xFF;    if (evt->modifiers & EVT_NUMLOCK) {        if ((ascii = translateScan(scan,EVT.codePage->numPad,EVT.codePage->numPadLen)) != 0) {            evt->message |= ascii;            return;            }        }    if (evt->modifiers & EVT_CTRLSTATE) {        evt->message |= translateScan(scan,EVT.codePage->ctrl,EVT.codePage->ctrlLen);        return;        }    if (evt->modifiers & EVT_CAPSLOCK) {        if (evt->modifiers & EVT_SHIFTKEY) {            if ((ascii = translateScan(scan,EVT.codePage->shiftCaps,EVT.codePage->shiftCapsLen)) != 0) {                evt->message |= ascii;                return;                }            }        else {            if ((ascii = translateScan(scan,EVT.codePage->caps,EVT.codePage->capsLen)) != 0) {                evt->message |= ascii;                return;                }            }        }    if (evt->modifiers & EVT_SHIFTKEY) {        if ((ascii = translateScan(scan,EVT.codePage->shift,EVT.codePage->shiftLen)) != 0) {            evt->message |= ascii;            return;            }        }    evt->message |= translateScan(scan,EVT.codePage->normal,EVT.codePage->normalLen);}/****************************************************************************REMARKS:Returns true if the key with the specified scan code is being held down.****************************************************************************/static ibool _EVT_isKeyDown(    uchar scanCode){    if (scanCode > 0x7F)        return false;    else        return EVT.keyTable[scanCode] != 0;}/****************************************************************************PARAMETERS:what        - Event codemessage     - Event message (ASCII code and scan code)REMARKS:Adds a new keyboard event to the event queue. This routine is called fromwithin the keyboard interrupt subroutine!NOTE:   Interrupts are OFF when this routine is called by the keyboard ISR,        and we leave them OFF the entire time.****************************************************************************/static void addKeyEvent(    uint what,    uint message){    event_t evt;    if (EVT.count < EVENTQSIZE) {        /* Save information in event record */        evt.when = _EVT_getTicks();        evt.what = what;        evt.message = message | 0x10000UL;        evt.where_x = 0;        evt.where_y = 0;        evt.relative_x = 0;        evt.relative_y = 0;        evt.modifiers = EVT.keyModifiers;        if (evt.what == EVT_KEYREPEAT) {            if (EVT.oldKey != -1)                EVT.evtq[EVT.oldKey].message += 0x10000UL;            else {                EVT.oldKey = EVT.freeHead;                addEvent(&evt);         /* Add to tail of event queue   */                }            }        else {#ifdef __QNX__            _EVT_maskKeyCode(&evt);#endif            addEvent(&evt);             /* Add to tail of event queue   */            }        EVT.oldMove = -1;        }}/****************************************************************************REMARKS:This function waits for the keyboard controller to set the ready-for-writebit.****************************************************************************/static int kbWaitForWriteReady(void){    int timeout = 8192;    while ((timeout > 0) && (PM_inpb(0x64) & 0x02))        timeout--;    return (timeout > 0);}/****************************************************************************REMARKS:This function waits for the keyboard controller to set the ready-for-readbit.****************************************************************************/static int kbWaitForReadReady(void){    int timeout = 8192;    while ((timeout > 0) && (!(PM_inpb(0x64) & 0x01)))        timeout--;    return (timeout > 0);}/****************************************************************************PARAMETERS:data    - Data to send to the keyboardREMARKS:This function sends a data byte to the keyboard controller.****************************************************************************/static int kbSendData(    uchar data){    int resends = 4;    int timeout, temp;    do {        if (!kbWaitForWriteReady())            return 0;        PM_outpb(0x60,data);        timeout = 8192;        while (--timeout > 0) {            if (!kbWaitForReadReady())                return 0;            temp = PM_inpb(0x60);            if (temp == 0xFA)

⌨️ 快捷键说明

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