2008-07-23 08:29:46 +02:00
|
|
|
/** @file
|
|
|
|
Function prototype for USB Keyboard Driver.
|
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>
|
2010-04-24 11:49:11 +02:00
|
|
|
This program and the accompanying materials
|
2008-07-23 08:29:46 +02:00
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#ifndef _EFI_KEYBOARD_H_
|
|
|
|
#define _EFI_KEYBOARD_H_
|
|
|
|
|
|
|
|
|
|
|
|
#include "EfiKey.h"
|
|
|
|
|
2009-04-10 06:28:13 +02:00
|
|
|
#define USB_KEYBOARD_LAYOUT_PACKAGE_GUID \
|
|
|
|
{ \
|
|
|
|
0xc0f3b43, 0x44de, 0x4907, { 0xb4, 0x78, 0x22, 0x5f, 0x6f, 0x62, 0x89, 0xdc } \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define USB_KEYBOARD_LAYOUT_KEY_GUID \
|
|
|
|
{ \
|
|
|
|
0x3a4d7a7c, 0x18a, 0x4b42, { 0x81, 0xb3, 0xdc, 0x10, 0xe3, 0xb5, 0x91, 0xbd } \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define USB_KEYBOARD_KEY_COUNT 104
|
|
|
|
|
|
|
|
#define USB_KEYBOARD_LANGUAGE_STR_LEN 5 // RFC4646 Language Code: "en-US"
|
|
|
|
#define USB_KEYBOARD_DESCRIPTION_STR_LEN (16 + 1) // Description: "English Keyboard"
|
|
|
|
|
|
|
|
#pragma pack (1)
|
|
|
|
typedef struct {
|
|
|
|
//
|
|
|
|
// This 4-bytes total array length is required by PreparePackageList()
|
|
|
|
//
|
|
|
|
UINT32 Length;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Keyboard Layout package definition
|
|
|
|
//
|
|
|
|
EFI_HII_PACKAGE_HEADER PackageHeader;
|
|
|
|
UINT16 LayoutCount;
|
|
|
|
|
|
|
|
//
|
|
|
|
// EFI_HII_KEYBOARD_LAYOUT
|
|
|
|
//
|
|
|
|
UINT16 LayoutLength;
|
|
|
|
EFI_GUID Guid;
|
|
|
|
UINT32 LayoutDescriptorStringOffset;
|
|
|
|
UINT8 DescriptorCount;
|
|
|
|
EFI_KEY_DESCRIPTOR KeyDescriptor[USB_KEYBOARD_KEY_COUNT];
|
|
|
|
UINT16 DescriptionCount;
|
|
|
|
CHAR16 Language[USB_KEYBOARD_LANGUAGE_STR_LEN];
|
|
|
|
CHAR16 Space;
|
|
|
|
CHAR16 DescriptionString[USB_KEYBOARD_DESCRIPTION_STR_LEN];
|
|
|
|
} USB_KEYBOARD_LAYOUT_PACK_BIN;
|
|
|
|
#pragma pack()
|
2008-07-23 08:29:46 +02:00
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Uses USB I/O to check whether the device is a USB keyboard device.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@param UsbIo Pointer to a USB I/O protocol instance.
|
|
|
|
|
|
|
|
@retval TRUE Device is a USB keyboard device.
|
|
|
|
@retval FALSE Device is a not USB keyboard device.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
BOOLEAN
|
|
|
|
IsUSBKeyboard (
|
|
|
|
IN EFI_USB_IO_PROTOCOL *UsbIo
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Initialize USB keyboard device and all private data structures.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
@param UsbKeyboardDevice The USB_KB_DEV instance.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS Initialization is successful.
|
2008-12-15 08:17:47 +01:00
|
|
|
@retval EFI_DEVICE_ERROR Keyboard initialization failed.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
InitUSBKeyboard (
|
2008-12-15 08:17:47 +01:00
|
|
|
IN OUT USB_KB_DEV *UsbKeyboardDevice
|
2008-07-23 08:29:46 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Initialize USB keyboard layout.
|
|
|
|
|
|
|
|
This function initializes Key Convertion Table for the USB keyboard device.
|
|
|
|
It first tries to retrieve layout from HII database. If failed and default
|
|
|
|
layout is enabled, then it just uses the default layout.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
@param UsbKeyboardDevice The USB_KB_DEV instance.
|
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@retval EFI_SUCCESS Initialization succeeded.
|
|
|
|
@retval EFI_NOT_READY Keyboard layout cannot be retrieve from HII
|
|
|
|
database, and default layout is disabled.
|
|
|
|
@retval Other Fail to register event to EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID group.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
InitKeyboardLayout (
|
2008-12-15 08:17:47 +01:00
|
|
|
OUT USB_KB_DEV *UsbKeyboardDevice
|
2008-07-23 08:29:46 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Destroy resources for keyboard layout.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
@param UsbKeyboardDevice The USB_KB_DEV instance.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
ReleaseKeyboardLayoutResources (
|
2008-12-15 08:17:47 +01:00
|
|
|
IN OUT USB_KB_DEV *UsbKeyboardDevice
|
2008-07-23 08:29:46 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Handler function for USB keyboard's asynchronous interrupt transfer.
|
|
|
|
|
|
|
|
This function is the handler function for USB keyboard's asynchronous interrupt transfer
|
|
|
|
to manage the keyboard. It parses the USB keyboard input report, and inserts data to
|
|
|
|
keyboard buffer according to state of modifer keys and normal keys. Timer for repeat key
|
|
|
|
is also set accordingly.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
@param Data A pointer to a buffer that is filled with key data which is
|
|
|
|
retrieved via asynchronous interrupt transfer.
|
|
|
|
@param DataLength Indicates the size of the data buffer.
|
|
|
|
@param Context Pointing to USB_KB_DEV instance.
|
|
|
|
@param Result Indicates the result of the asynchronous interrupt transfer.
|
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@retval EFI_SUCCESS Asynchronous interrupt transfer is handled successfully.
|
|
|
|
@retval EFI_DEVICE_ERROR Hardware error occurs.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
KeyboardHandler (
|
|
|
|
IN VOID *Data,
|
|
|
|
IN UINTN DataLength,
|
|
|
|
IN VOID *Context,
|
|
|
|
IN UINT32 Result
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Handler for Delayed Recovery event.
|
|
|
|
|
|
|
|
This function is the handler for Delayed Recovery event triggered
|
|
|
|
by timer.
|
|
|
|
After a device error occurs, the event would be triggered
|
|
|
|
with interval of EFI_USB_INTERRUPT_DELAY. EFI_USB_INTERRUPT_DELAY
|
|
|
|
is defined in USB standard for error handling.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
@param Event The Delayed Recovery event.
|
|
|
|
@param Context Points to the USB_KB_DEV instance.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
USBKeyboardRecoveryHandler (
|
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *Context
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Retrieves a USB keycode after parsing the raw data in keyboard buffer.
|
|
|
|
|
|
|
|
This function parses keyboard buffer. It updates state of modifier key for
|
|
|
|
USB_KB_DEV instancem, and returns keycode for output.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
@param UsbKeyboardDevice The USB_KB_DEV instance.
|
2008-12-15 08:17:47 +01:00
|
|
|
@param KeyCode Pointer to the USB keycode for output.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@retval EFI_SUCCESS Keycode successfully parsed.
|
|
|
|
@retval EFI_NOT_READY Keyboard buffer is not ready for a valid keycode
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
USBParseKey (
|
|
|
|
IN OUT USB_KB_DEV *UsbKeyboardDevice,
|
2008-12-15 08:17:47 +01:00
|
|
|
OUT UINT8 *KeyCode
|
2008-07-23 08:29:46 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Converts USB Keycode ranging from 0x4 to 0x65 to EFI_INPUT_KEY.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@param UsbKeyboardDevice The USB_KB_DEV instance.
|
|
|
|
@param KeyCode Indicates the key code that will be interpreted.
|
2011-04-19 08:52:20 +02:00
|
|
|
@param KeyData A pointer to a buffer that is filled in with
|
2008-12-15 08:17:47 +01:00
|
|
|
the keystroke information for the key that
|
|
|
|
was pressed.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2008-12-15 08:17:47 +01:00
|
|
|
@retval EFI_SUCCESS Success.
|
|
|
|
@retval EFI_INVALID_PARAMETER KeyCode is not in the range of 0x4 to 0x65.
|
|
|
|
@retval EFI_INVALID_PARAMETER Translated EFI_INPUT_KEY has zero for both ScanCode and UnicodeChar.
|
|
|
|
@retval EFI_NOT_READY KeyCode represents a dead key with EFI_NS_KEY_MODIFIER
|
2009-01-13 09:29:55 +01:00
|
|
|
@retval EFI_DEVICE_ERROR Keyboard layout is invalid.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
2008-12-05 10:19:10 +01:00
|
|
|
UsbKeyCodeToEfiInputKey (
|
2008-07-23 08:29:46 +02:00
|
|
|
IN USB_KB_DEV *UsbKeyboardDevice,
|
2008-12-15 08:17:47 +01:00
|
|
|
IN UINT8 KeyCode,
|
2011-04-19 08:52:20 +02:00
|
|
|
OUT EFI_KEY_DATA *KeyData
|
2008-07-23 08:29:46 +02:00
|
|
|
);
|
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
/**
|
2011-04-19 08:52:20 +02:00
|
|
|
Create the queue.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
@param Queue Points to the queue.
|
|
|
|
@param ItemSize Size of the single item.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
**/
|
2008-12-05 10:19:10 +01:00
|
|
|
VOID
|
2011-04-19 08:52:20 +02:00
|
|
|
InitQueue (
|
|
|
|
IN OUT USB_SIMPLE_QUEUE *Queue,
|
|
|
|
IN UINTN ItemSize
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destroy the queue
|
|
|
|
|
|
|
|
@param Queue Points to the queue.
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
DestroyQueue (
|
|
|
|
IN OUT USB_SIMPLE_QUEUE *Queue
|
2008-07-23 08:29:46 +02:00
|
|
|
);
|
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
/**
|
2011-04-19 08:52:20 +02:00
|
|
|
Check whether the queue is empty.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
@param Queue Points to the queue.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
@retval TRUE Queue is empty.
|
|
|
|
@retval FALSE Queue is not empty.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
BOOLEAN
|
2011-04-19 08:52:20 +02:00
|
|
|
IsQueueEmpty (
|
|
|
|
IN USB_SIMPLE_QUEUE *Queue
|
2008-07-23 08:29:46 +02:00
|
|
|
);
|
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
/**
|
2011-04-19 08:52:20 +02:00
|
|
|
Check whether the queue is full.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
@param Queue Points to the queue.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
@retval TRUE Queue is full.
|
|
|
|
@retval FALSE Queue is not full.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
BOOLEAN
|
2011-04-19 08:52:20 +02:00
|
|
|
IsQueueFull (
|
|
|
|
IN USB_SIMPLE_QUEUE *Queue
|
2008-07-23 08:29:46 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
/**
|
|
|
|
Enqueue the item to the queue.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
@param Queue Points to the queue.
|
|
|
|
@param Item Points to the item to be enqueued.
|
|
|
|
@param ItemSize Size of the item.
|
2008-07-23 08:29:46 +02:00
|
|
|
**/
|
2008-12-05 10:19:10 +01:00
|
|
|
VOID
|
2011-04-19 08:52:20 +02:00
|
|
|
Enqueue (
|
|
|
|
IN OUT USB_SIMPLE_QUEUE *Queue,
|
|
|
|
IN VOID *Item,
|
|
|
|
IN UINTN ItemSize
|
2008-07-23 08:29:46 +02:00
|
|
|
);
|
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
|
2008-07-23 08:29:46 +02:00
|
|
|
/**
|
2011-04-19 08:52:20 +02:00
|
|
|
Dequeue a item from the queue.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
@param Queue Points to the queue.
|
|
|
|
@param Item Receives the item.
|
|
|
|
@param ItemSize Size of the item.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
2011-04-19 08:52:20 +02:00
|
|
|
@retval EFI_SUCCESS Item was successfully dequeued.
|
|
|
|
@retval EFI_DEVICE_ERROR The queue is empty.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
2011-04-19 08:52:20 +02:00
|
|
|
Dequeue (
|
|
|
|
IN OUT USB_SIMPLE_QUEUE *Queue,
|
|
|
|
OUT VOID *Item,
|
|
|
|
IN UINTN ItemSize
|
2008-07-23 08:29:46 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Handler for Repeat Key event.
|
|
|
|
|
|
|
|
This function is the handler for Repeat Key event triggered
|
|
|
|
by timer.
|
|
|
|
After a repeatable key is pressed, the event would be triggered
|
|
|
|
with interval of USBKBD_REPEAT_DELAY. Once the event is triggered,
|
|
|
|
following trigger will come with interval of USBKBD_REPEAT_RATE.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
@param Event The Repeat Key event.
|
|
|
|
@param Context Points to the USB_KB_DEV instance.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
USBKeyboardRepeatHandler (
|
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *Context
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
2008-12-15 08:17:47 +01:00
|
|
|
Sets USB keyboard LED state.
|
2008-07-23 08:29:46 +02:00
|
|
|
|
|
|
|
@param UsbKeyboardDevice The USB_KB_DEV instance.
|
|
|
|
|
|
|
|
**/
|
2008-12-05 10:19:10 +01:00
|
|
|
VOID
|
2008-07-23 08:29:46 +02:00
|
|
|
SetKeyLED (
|
|
|
|
IN USB_KB_DEV *UsbKeyboardDevice
|
|
|
|
);
|
|
|
|
|
|
|
|
#endif
|