ps2keybd.cpp

来自「WinCE 3.0 BSP, 包含Inter SA1110, Intel_815」· C++ 代码 · 共 252 行

CPP
252
字号
/* -*-C-*-
 *
 * $Revision: 1.1 $
 *   $Author: kwelton $
 *     $Date: 2000/04/12 00:50:42 $
 *
 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
 * ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 *
 * Copyright (c) 1995-1998  Microsoft Corporation
 * Copyright (c) 2000 ARM Limited
 * All Rights Reserved
 */

#include <windows.h>
#include <ceddk.h>
#include <nkintr.h>
#include <rio.h>

#include <keybddr.h>
#include <keybdpdd.h>

#include "ps2port.hpp"
#include "ps2mouse.hpp"
#include "ps2keybd.hpp"


// Scan code consts
static const UINT8 scE0Extended = 0xe0;
static const UINT8 scE1Extended = 0xe1;
static const UINT8 scKeyUpMask  = 0x80;

//      There is really only one physical keyboard supported by the system.
Ps2Keybd *v_pp2k;

static KEY_STATE_FLAGS v_KeyStateToggled;

/**********************************************************************/

void WINAPI KeybdPdd_PowerHandler(BOOL bOff)
{
    return;
}

BOOL WINAPI KeybdPdd_InitializeDriverEx(PFN_KEYBD_EVENT_CALLBACK_EX pfnKeybdEventCallbackEx)
{
    return TRUE;
}

int WINAPI KeybdPdd_GetEventEx(UINT32 VKeyBuf[16],
                               UINT32 ScanCodeBuf[16],
                               KEY_STATE_FLAGS KeyStateFlagsBuf[16])
{
    UINT8 ui8ScanCode;
    INT cEvents = 0;
    KEY_STATE_FLAGS KeyStateFlags;

    static  UINT32  scInProgress;
    static  UINT32  scPrevious;

    v_pp2k->m_pp2p->KeybdDataRead(&ui8ScanCode);

#if 0
    RETAILMSG(1,(TEXT("scInProgress: %08x  ui8ScanCode: %08x\r\n"),
                 scInProgress, ui8ScanCode));
#endif /* 0/1 */

    if (ui8ScanCode == scE0Extended)
        scInProgress = 0xe000;
    else if (ui8ScanCode == scE1Extended)
        scInProgress = 0xe10000;
    else if (scInProgress == 0xe10000)
    {
        ui8ScanCode &= ~scKeyUpMask;
        scInProgress |= ui8ScanCode << 8;
    }
    else
    {
        scInProgress |= ui8ScanCode;

        if (scInProgress == scPrevious)
        {
            // mdd handles auto-repeat so ignore auto-repeats from keybd
        }
        else
        {
            // Not a repeated key.  This is the real thing.
            scPrevious = scInProgress;

            if (ui8ScanCode & scKeyUpMask)
            {
                KeyStateFlags = 0;
                scInProgress &= ~scKeyUpMask;
            }
            else
                KeyStateFlags = KeyStateDownFlag;

            cEvents = ScanCodeToVKeyEx(scInProgress, KeyStateFlags,
                                       VKeyBuf, ScanCodeBuf,
                                       KeyStateFlagsBuf);
        }
        scInProgress = 0;
    }

    return(cEvents);
}

void WINAPI KeybdPdd_ToggleKeyNotification(KEY_STATE_FLAGS KeyStateFlags)
{
    unsigned int fLights;

    v_KeyStateToggled = KeyStateFlags;

    fLights = 0;

    if (KeyStateFlags & KeyShiftCapitalFlag)
        fLights |= 0x04;

    if (KeyStateFlags & KeyShiftNumLockFlag)
        fLights |= 0x2;

    v_pp2k->m_pp2p->KeyboardLights(fLights);

    return;
}


KEY_STATE_FLAGS WINAPI KeybdPdd_KeyStateToggled(void)
{
    return v_KeyStateToggled;
}

BOOL KeybdIstLoop(HANDLE  hevIntrKeybd, BYTE bSYSINTR);


BOOL Ps2Keybd::IsrThreadProc(void)
{
    BYTE        bIRQ, bSYSINTR;
    DWORD       dwRet;

    m_hevInterrupt = CreateEvent(NULL, FALSE, FALSE, NULL);
    if (m_hevInterrupt == NULL)
        goto leave;

    bIRQ = (BYTE) RIO_IRQ_KEYBOARD;

    KernelIoControl(IOCTL_HAL_TRANSLATE_IRQ, (LPVOID)&bIRQ, sizeof(bIRQ),
                    (LPVOID)&bSYSINTR, sizeof(bSYSINTR), &dwRet);

    if (!InterruptInitialize(bSYSINTR, m_hevInterrupt, NULL, 0))
        goto leave;

    m_pp2p->KeybdInterruptEnable();

    KeybdIstLoop(m_hevInterrupt, bSYSINTR);

  leave:
    return 0;
}

/*
 * GetISTPriority
 *
 * Read the thread priority to use for the keyboard IST or return the default
 */
DWORD GetISTPriority(void)
{
    HKEY hKey;
    DWORD dwVal;
    DWORD dwLen;
    DWORD dwType;
    DWORD dwRet;

    /*
     * 20000411 KWelton
     *
     * DEFAULT_KEYBD_IST_PRIORITY seems not to be defined anywhere
     * in the Harp HAL 0.1 code drop. Other code seems to use the
     * highest priority for their driver, so we'll default to the
     * same value
     */
#ifdef OldCode
    dwVal = DEFAULT_KEYBD_IST_PRIORITY;
#else /* OldCode */
    dwVal = THREAD_PRIORITY_HIGHEST;
#endif /* OldCode */

    dwRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, KEYBOARD_DRIVER_KEY,
                         0, 0, &hKey);

    if (dwRet == ERROR_SUCCESS)
    {
        dwLen = sizeof(DWORD);
        RegQueryValueEx(hKey, TEXT("Priority"), NULL, &dwType,
                        (PUCHAR)&dwVal, &dwLen);
        RegCloseKey(hKey);
    }

    return dwVal;
}

DWORD Ps2KeybdIsrThread(Ps2Keybd *pp2k)
{
    /*
     * 20000411 KWelton
     *
     * Does this really mean to call CeSetThreadPriority()? WinCE 2.12
     * certainly doesn't seem to like it
     */
#ifdef OldCode
    CeSetThreadPriority(GetCurrentThread(), GetISTPriority());
#else
    SetThreadPriority(GetCurrentThread(), GetISTPriority());
#endif

    pp2k->IsrThreadProc();

    return 0;
}

BOOL Ps2Keybd::IsrThreadStart(void)
{
    HANDLE  hthrd;

    hthrd = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Ps2KeybdIsrThread,
                         this, 0, NULL);

    // Since we don't need the handle, close it now.
    CloseHandle(hthrd);

    return TRUE;
}

BOOL Ps2Keybd::Initialize(Ps2Port *pp2p)
{
    m_pp2p = pp2p;

    if (!m_pp2p->KeyboardInterfaceTest())
    {
        ASSERT(0);
        return FALSE;
    }

    v_pp2k->m_pp2p->KeyboardLights(0);

    return TRUE;
}

/* EOF ps2keybd.cpp */

⌨️ 快捷键说明

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