BIOS下的键盘驱动

#include <Library/DebugLib.h>

#include <Protocol/UsbIo.h>
#include <Library/UefiLib.h>

#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>

#include <Protocol/SimplePointer.h>
#include <Protocol/DevicePath.h>
#include <Library/ReportStatusCodeLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiBootServicesTableLib.h>

#include <string.h>

//#include <IndustryStandard/Usb.h>
//#include <Library/UefiUsbLib.h>
//#include <stdio.h>
//#include <stdlib.h>

extern EFI_BOOT_SERVICES *gBS;

#define  NUM0            0x30
#define  NUM1            0x31
#define  NUM2            0x32
#define  NUM3            0x33
#define  NUM4            0x34
#define  NUM5            0x35
#define  NUM6            0x36
#define  NUM7            0x37
#define  NUM8            0x38
#define  NUM9            0x39

typedef enum _KeyCode
{
    KC_NUM0 = 0x00,
    KC_NUM1 = 0x01,
    KC_NUM2 = 0x02,
    KC_NUM3 = 0x03,
    KC_NUM4 = 0x04,
    KC_NUM5 = 0x05,
    KC_NUM6 = 0x06,
    KC_NUM7 = 0x07,
    KC_NUM8 = 0x08,
    KC_NUM9 = 0x09,
    KC_UNKNOW = 0xA0
} KeyCode;

KeyCode HIDkeyboard_getCode()
{
    KeyCode code;
    EFI_STATUS Status;
    EFI_EVENT myEvent[2];
    UINTN index = 0;

    Status = gBS->CreateEvent(
                EVT_TIMER,
                TPL_CALLBACK,
                (EFI_EVENT_NOTIFY)NULL,
                (VOID*)NULL,
                &myEvent[0]
            );

    Status = gBS->SetTimer(
                myEvent[0],
            TimerRelative,
            10*1000*1000
            );

    myEvent[1] = gST->ConIn->WaitForKey;

    Status = gBS->WaitForEvent(2, myEvent, &index);
    Status = gBS->SetTimer(myEvent[0],TimerCancel,10*1000*1000);

    if(index == 0)
    {
        code = KC_UNKNOW;
    }
    else if(index == 1)
    {
        EFI_INPUT_KEY Key;
        Status = gST->ConIn->ReadKeyStroke(gST->ConIn, &Key);

        if (EFI_ERROR(Status))
        {
            Print(L"key board is not support\n");
            return -1;
        }
        INTN currentKey = Key.UnicodeChar;
        switch (currentKey)
        {
        case NUM0:
            code = KC_NUM0;
            break;
        case NUM1:
            code = KC_NUM1;
            break;
        case NUM2:
            code = KC_NUM2;
            break;
        case NUM3:
            code = KC_NUM3;
            break;
        case NUM4:
            code = KC_NUM4;
            break;
        case NUM5:
            code = KC_NUM5;
            break;
        case NUM6:
            code = KC_NUM6;
            break;
        case NUM7:
            code = KC_NUM7;
            break;
        case NUM8:
            code = KC_NUM8;
            break;
        case NUM9:
            code = KC_NUM9;
            break;
        default:
            code = KC_UNKNOW;
            break;
        }
    }
    Status = gBS->SetTimer(
                myEvent[0],
            TimerRelative,
            10*1000*1000
            );

    return code;
}

INTN EFIAPI ShellAppMain(IN UINTN Argc, IN CHAR16 **Argv)
{

    while(1)
    {
        KeyCode code = HIDkeyboard_getCode();


    }

    return EFI_SUCCESS;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值