/** @file\r
-\r
Helper functions for USB Keyboard Driver.\r
\r
Copyright (c) 2004 - 2008, Intel Corporation\r
**/\r
\r
#include "KeyBoard.h"\r
-#include <Library/UefiUsbLib.h>\r
\r
//\r
// Static English keyboard layout\r
{ MOD_WIN_R, 0xe7 }, // 11100111 \r
};\r
\r
-\r
/**\r
Initialize KeyConvertionTable by using default keyboard layout.\r
\r
@param UsbKeyboardDevice The USB_KB_DEV instance.\r
- @retval None.\r
\r
**/\r
VOID\r
}\r
}\r
\r
-\r
/**\r
Uses USB I/O to check whether the device is a USB Keyboard device.\r
\r
@param UsbIo Points to a USB I/O protocol instance.\r
- @retval None\r
\r
**/\r
BOOLEAN\r
/**\r
Get current keyboard layout from HII database.\r
\r
- @retval Pointer to EFI_HII_KEYBOARD_LAYOUT.\r
+ @return Pointer to EFI_HII_KEYBOARD_LAYOUT.\r
\r
**/\r
EFI_HII_KEYBOARD_LAYOUT *\r
@param ScanCode USB scan code.\r
\r
@return The Key descriptor in KeyConvertionTable.\r
+ NULL means not found.\r
\r
**/\r
EFI_KEY_DESCRIPTOR *\r
@param UsbKeyboardDevice The USB_KB_DEV instance.\r
@param KeyDescriptor Key descriptor.\r
\r
- @retval NULL Key list is empty.\r
- @return Other The Non-Spacing key.\r
+ @return The Non-Spacing key corresponding to KeyDescriptor\r
+ NULL means not found.\r
\r
**/\r
USB_NS_KEY *\r
}\r
\r
//\r
- // Allocate resource for KeyConvertionTable\r
+ // Re-allocate resource for KeyConvertionTable\r
//\r
ReleaseKeyboardLayoutResources (UsbKeyboardDevice);\r
UsbKeyboardDevice->KeyConvertionTable = AllocateZeroPool ((USB_KEYCODE_MAX_MAKE + 8) * sizeof (EFI_KEY_DESCRIPTOR));\r
ASSERT (UsbKeyboardDevice->KeyConvertionTable != NULL);\r
\r
+ //\r
+ // Traverse the list of key descriptors following the header of EFI_HII_KEYBOARD_LAYOUT\r
+ //\r
KeyDescriptor = (EFI_KEY_DESCRIPTOR *) (((UINT8 *) KeyboardLayout) + sizeof (EFI_HII_KEYBOARD_LAYOUT));\r
for (Index = 0; Index < KeyboardLayout->DescriptorCount; Index++) {\r
//\r
CopyMem (&TempKey, KeyDescriptor, sizeof (EFI_KEY_DESCRIPTOR));\r
\r
//\r
- // Fill the key into KeyConvertionTable (which use USB Scan Code as index)\r
+ // Fill the key into KeyConvertionTable, whose index is calculated from USB scan code.\r
//\r
ScanCode = UsbScanCodeConvertionTable [(UINT8) (TempKey.Key)];\r
TableEntry = GetKeyDescriptor (UsbKeyboardDevice, ScanCode);\r
\r
if (TempKey.Modifier == EFI_NS_KEY_MODIFIER) {\r
//\r
- // Non-spacing key\r
+ // For non-spacing key, create the list with a non-spacing key followed by physical keys.\r
//\r
UsbNsKey = AllocatePool (sizeof (USB_NS_KEY));\r
ASSERT (UsbNsKey != NULL);\r
UsbKeyboardDevice->KeyboardLayoutEvent = NULL;\r
\r
//\r
- // Register SET_KEYBOARD_LAYOUT_EVENT notification\r
+ // Register event to EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID group,\r
+ // which will be triggered by EFI_HII_DATABASE_PROTOCOL.SetKeyboardLayout.\r
//\r
Status = gBS->CreateEventEx (\r
EVT_NOTIFY_SIGNAL,\r
return Status;\r
}\r
\r
- //\r
- // Try to get current keyboard layout from HII database\r
- //\r
KeyboardLayout = GetCurrentKeyboardLayout ();\r
if (KeyboardLayout != NULL) {\r
//\r
- // Force to initialize the keyboard layout\r
+ // If current keyboard layout is successfully retrieved from HII database,\r
+ // force to initialize the keyboard layout.\r
//\r
gBS->SignalEvent (UsbKeyboardDevice->KeyboardLayoutEvent);\r
} else {\r
if (FeaturePcdGet (PcdDisableDefaultKeyboardLayoutInUsbKbDriver)) {\r
- return EFI_NOT_READY;\r
- } else {\r
-\r
//\r
- // Fail to get keyboard layout from HII database,\r
- // use default keyboard layout\r
+ // If no keyboard layout can be retrieved from HII database, and default layout\r
+ // is disabled, then return EFI_NOT_READY.\r
//\r
- LoadDefaultKeyboardLayout (UsbKeyboardDevice);\r
+ return EFI_NOT_READY;\r
}\r
+ //\r
+ // If no keyboard layout can be retrieved from HII database, and default layout\r
+ // is enabled, then load the default keyboard layout.\r
+ //\r
+ LoadDefaultKeyboardLayout (UsbKeyboardDevice);\r
}\r
\r
return EFI_SUCCESS;\r
EFI_STATUS Status;\r
UINT32 TransferResult;\r
\r
- KbdReportStatusCode (\r
- UsbKeyboardDevice->DevicePath,\r
+ REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
EFI_PROGRESS_CODE,\r
- PcdGet32 (PcdStatusCodeValueKeyboardSelfTest)\r
+ PcdGet32 (PcdStatusCodeValueKeyboardSelfTest),\r
+ UsbKeyboardDevice->DevicePath\r
);\r
\r
InitUSBKeyBuffer (&(UsbKeyboardDevice->KeyboardBuffer));\r
// Uses default configuration to configure the USB Keyboard device.\r
//\r
Status = UsbSetConfiguration (\r
- UsbKeyboardDevice->UsbIo,\r
- (UINT16) ConfigValue,\r
- &TransferResult\r
- );\r
+ UsbKeyboardDevice->UsbIo,\r
+ (UINT16) ConfigValue,\r
+ &TransferResult\r
+ );\r
if (EFI_ERROR (Status)) {\r
//\r
// If configuration could not be set here, it means\r
// the keyboard interface has some errors and could\r
// not be initialized\r
//\r
- KbdReportStatusCode (\r
- UsbKeyboardDevice->DevicePath,\r
+ REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
- PcdGet32 (PcdStatusCodeValueKeyboardInterfaceError)\r
+ PcdGet32 (PcdStatusCodeValueKeyboardInterfaceError),\r
+ UsbKeyboardDevice->DevicePath\r
);\r
\r
return EFI_DEVICE_ERROR;\r
&Protocol\r
);\r
//\r
- // Sets boot protocol for the USB Keyboard.\r
+ // Set boot protocol for the USB Keyboard.\r
// This driver only supports boot protocol.\r
- // !!BugBug: How about the device that does not support boot protocol?\r
+ // The device that does not support boot protocol is not supported.\r
//\r
if (Protocol != BOOT_PROTOCOL) {\r
UsbSetProtocolRequest (\r
BOOT_PROTOCOL\r
);\r
}\r
- //\r
- // the duration is indefinite, so the endpoint will inhibit reporting forever,\r
- // and only reporting when a change is detected in the report data.\r
- //\r
\r
//\r
- // idle value for all report ID\r
+ // ReportId is zero, which means the idle rate applies to all input reports.\r
//\r
ReportId = 0;\r
//\r
- // idle forever until there is a key pressed and released.\r
+ // Duration is zero, which means the duration is indefinite.\r
+ // so the endpoint will inhibit reporting forever,\r
+ // and only reporting when a change is detected in the report data.\r
//\r
Duration = 0;\r
UsbSetIdleRequest (\r
//\r
if (UsbKeyboardDevice->RepeatTimer != NULL) {\r
gBS->CloseEvent (UsbKeyboardDevice->RepeatTimer);\r
- UsbKeyboardDevice->RepeatTimer = 0;\r
+ UsbKeyboardDevice->RepeatTimer = NULL;\r
}\r
\r
Status = gBS->CreateEvent (\r
\r
if (UsbKeyboardDevice->DelayedRecoveryEvent != NULL) {\r
gBS->CloseEvent (UsbKeyboardDevice->DelayedRecoveryEvent);\r
- UsbKeyboardDevice->DelayedRecoveryEvent = 0;\r
+ UsbKeyboardDevice->DelayedRecoveryEvent = NULL;\r
}\r
\r
Status = gBS->CreateEvent (\r
UINT32 UsbStatus;\r
EFI_KEY_DESCRIPTOR *KeyDescriptor;\r
\r
- ASSERT (Context);\r
+ ASSERT (Context != NULL);\r
\r
NewRepeatKey = 0;\r
UsbKeyboardDevice = (USB_KB_DEV *) Context;\r
//\r
// Some errors happen during the process\r
//\r
- KbdReportStatusCode (\r
- UsbKeyboardDevice->DevicePath,\r
+ REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
- PcdGet32 (PcdStatusCodeValueKeyboardInputError)\r
+ PcdGet32 (PcdStatusCodeValueKeyboardInputError),\r
+ UsbKeyboardDevice->DevicePath\r
);\r
\r
//\r
\r
//\r
// Delete & Submit this interrupt again\r
+ // Handler of DelayedRecoveryEvent triggered by timer will re-submit the interrupt. \r
//\r
-\r
UsbIo->UsbAsyncInterruptTransfer (\r
- UsbIo,\r
- UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress,\r
- FALSE,\r
- 0,\r
- 0,\r
- NULL,\r
- NULL\r
- );\r
-\r
+ UsbIo,\r
+ UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress,\r
+ FALSE,\r
+ 0,\r
+ 0,\r
+ NULL,\r
+ NULL\r
+ );\r
+ //\r
+ // EFI_USB_INTERRUPT_DELAY is defined in USB standard for error handling\r
+ //\r
gBS->SetTimer (\r
- UsbKeyboardDevice->DelayedRecoveryEvent,\r
- TimerRelative,\r
- EFI_USB_INTERRUPT_DELAY\r
- );\r
+ UsbKeyboardDevice->DelayedRecoveryEvent,\r
+ TimerRelative,\r
+ EFI_USB_INTERRUPT_DELAY\r
+ );\r
\r
return EFI_DEVICE_ERROR;\r
}\r
\r
+ //\r
+ // If no error and no data, just return EFI_SUCCESS.\r
+ //\r
if (DataLength == 0 || Data == NULL) {\r
return EFI_SUCCESS;\r
}\r
\r
+ //\r
+ // Following code checks current keyboard input report against old key code buffer.\r
+ // According to USB HID Firmware Specification, the report consists of 8 bytes.\r
+ // Byte 0 is map of Modifier keys.\r
+ // Byte 1 is reserved.\r
+ // Bytes 2 to 7 are keycodes.\r
+ //\r
CurKeyCodeBuffer = (UINT8 *) Data;\r
OldKeyCodeBuffer = UsbKeyboardDevice->LastKeyCodeArray;\r
\r
//\r
- // checks for new key stroke.\r
- // if no new key got, return immediately.\r
+ // Checks for new key stroke.\r
//\r
for (Index = 0; Index < 8; Index++) {\r
if (OldKeyCodeBuffer[Index] != CurKeyCodeBuffer[Index]) {\r
}\r
}\r
\r
+ //\r
+ // If no new key, return EFI_SUCCESS immediately.\r
+ //\r
if (Index == 8) {\r
return EFI_SUCCESS;\r
}\r
\r
//\r
- // Parse the modifier key\r
+ // Parse the modifier key, which is the first byte of keyboard input report.\r
//\r
CurModifierMap = CurKeyCodeBuffer[0];\r
OldModifierMap = OldKeyCodeBuffer[0];\r
\r
//\r
- // handle modifier key's pressing or releasing situation.\r
+ // Handle modifier key's pressing or releasing situation.\r
//\r
for (Index = 0; Index < 8; Index++) {\r
\r
if ((CurModifierMap & KB_Mod[Index].Mask) != (OldModifierMap & KB_Mod[Index].Mask)) {\r
//\r
- // if current modifier key is up, then\r
+ // If current modifier key is up, then\r
// CurModifierMap & KB_Mod[Index].Mask = 0;\r
- // otherwize it is a non-zero value.\r
+ // otherwise it is a non-zero value.\r
// Inserts the pressed modifier key into key buffer.\r
//\r
Down = (UINT8) (CurModifierMap & KB_Mod[Index].Mask);\r
}\r
\r
//\r
- // handle normal key's releasing situation\r
+ // Handle normal key's releasing situation\r
+ // Bytes 2 to 7 are normal keycodes\r
//\r
KeyRelease = FALSE;\r
for (Index = 2; Index < 8; Index++) {\r
if (!USBKBD_VALID_KEYCODE (OldKeyCodeBuffer[Index])) {\r
continue;\r
}\r
-\r
+ //\r
+ // For any key in old keycode buffer, if it is not in current keycode buffer,\r
+ // then it is released. Otherwise, it is not released.\r
+ //\r
KeyRelease = TRUE;\r
for (Index2 = 2; Index2 < 8; Index2++) {\r
\r
0\r
);\r
//\r
- // the original reapeat key is released.\r
+ // The original repeat key is released.\r
//\r
if (OldKeyCodeBuffer[Index] == UsbKeyboardDevice->RepeatKey) {\r
UsbKeyboardDevice->RepeatKey = 0;\r
}\r
\r
//\r
- // original repeat key is released, cancel the repeat timer\r
+ // If original repeat key is released, cancel the repeat timer\r
//\r
if (UsbKeyboardDevice->RepeatKey == 0) {\r
gBS->SetTimer (\r
- UsbKeyboardDevice->RepeatTimer,\r
- TimerCancel,\r
- USBKBD_REPEAT_RATE\r
- );\r
+ UsbKeyboardDevice->RepeatTimer,\r
+ TimerCancel,\r
+ USBKBD_REPEAT_RATE\r
+ );\r
}\r
\r
//\r
- // handle normal key's pressing situation\r
+ // Handle normal key's pressing situation\r
//\r
KeyPress = FALSE;\r
for (Index = 2; Index < 8; Index++) {\r
if (!USBKBD_VALID_KEYCODE (CurKeyCodeBuffer[Index])) {\r
continue;\r
}\r
-\r
+ //\r
+ // For any key in current keycode buffer, if it is not in old keycode buffer,\r
+ // then it is pressed. Otherwise, it is not pressed.\r
+ //\r
KeyPress = TRUE;\r
for (Index2 = 2; Index2 < 8; Index2++) {\r
\r
\r
if (KeyPress) {\r
InsertKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), CurKeyCodeBuffer[Index], 1);\r
+\r
//\r
- // NumLock pressed or CapsLock pressed\r
+ // Handle repeat key\r
//\r
KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, CurKeyCodeBuffer[Index]);\r
if (KeyDescriptor->Modifier == EFI_NUM_LOCK_MODIFIER || KeyDescriptor->Modifier == EFI_CAPS_LOCK_MODIFIER) {\r
+ //\r
+ // For NumLock or CapsLock pressed, there is no need to handle repeat key for them.\r
+ //\r
UsbKeyboardDevice->RepeatKey = 0;\r
} else {\r
- NewRepeatKey = CurKeyCodeBuffer[Index];\r
//\r
- // do not repeat the original repeated key\r
+ // Prepare new repeat key, and clear the original one.\r
//\r
+ NewRepeatKey = CurKeyCodeBuffer[Index];\r
UsbKeyboardDevice->RepeatKey = 0;\r
}\r
}\r
}\r
\r
//\r
- // pre-process KeyboardBuffer, pop out the ctrl,alt,del key in sequence\r
+ // Pre-process KeyboardBuffer. Pop out the Ctrl, Alt, Del key in sequence\r
// and judge whether it will invoke reset event.\r
//\r
- SavedTail = UsbKeyboardDevice->KeyboardBuffer.bTail;\r
- Index = UsbKeyboardDevice->KeyboardBuffer.bHead;\r
+ SavedTail = UsbKeyboardDevice->KeyboardBuffer.BufferTail;\r
+ Index = UsbKeyboardDevice->KeyboardBuffer.BufferHead;\r
while (Index != SavedTail) {\r
RemoveKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), &UsbKey);\r
\r
break;\r
\r
//\r
- // Del Key Code\r
+ // For Del Key, check if Ctrl + Alt + Del occurs for reset.\r
//\r
case EFI_DELETE_MODIFIER:\r
if (UsbKey.Down != 0) {\r
}\r
\r
//\r
- // insert the key back to the buffer.\r
+ // Insert the key back to the buffer,\r
// so the key sequence will not be destroyed.\r
//\r
InsertKeyCode (\r
UsbKey.KeyCode,\r
UsbKey.Down\r
);\r
- Index = UsbKeyboardDevice->KeyboardBuffer.bHead;\r
+ Index = UsbKeyboardDevice->KeyboardBuffer.BufferHead;\r
\r
}\r
//\r
//\r
if (NewRepeatKey != 0) {\r
//\r
- // sets trigger time to "Repeat Delay Time",\r
+ // Sets trigger time to "Repeat Delay Time",\r
// to trigger the repeat timer when the key is hold long\r
// enough time.\r
//\r
\r
while (!IsUSBKeyboardBufferEmpty (&UsbKeyboardDevice->KeyboardBuffer)) {\r
//\r
- // pops one raw data off.\r
+ // Pops one raw data off.\r
//\r
RemoveKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), &UsbKey);\r
\r
KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, UsbKey.KeyCode);\r
if (UsbKey.Down == 0) {\r
+ //\r
+ // Key is released.\r
+ //\r
switch (KeyDescriptor->Modifier) {\r
\r
//\r
case EFI_NUM_LOCK_MODIFIER:\r
UsbKeyboardDevice->NumLockOn ^= 1;\r
//\r
- // Turn on the NumLock light on KB\r
+ // Set the NumLock light on keyboard\r
//\r
SetKeyLED (UsbKeyboardDevice);\r
continue;\r
case EFI_CAPS_LOCK_MODIFIER:\r
UsbKeyboardDevice->CapsOn ^= 1;\r
//\r
- // Turn on the CapsLock light on KB\r
+ // Set the CapsLock light on keyboard\r
//\r
SetKeyLED (UsbKeyboardDevice);\r
continue;\r
case EFI_SCROLL_LOCK_MODIFIER:\r
UsbKeyboardDevice->ScrollOn ^= 1;\r
//\r
- // Turn on the ScrollLock light on KB\r
+ // Set the ScrollLock light on keyboard\r
//\r
SetKeyLED (UsbKeyboardDevice);\r
continue;\r
break;\r
\r
//\r
- // F11,F12,PrintScreen,Pause/Break\r
- // could not be retrieved via SimpleTxtInEx protocol\r
+ // F11, F12, PrintScreen, Pause/Break\r
+ // could not be retrieved via SimpleTextInEx protocol\r
//\r
case EFI_FUNCTION_KEY_ELEVEN_MODIFIER:\r
case EFI_FUNCTION_KEY_TWELVE_MODIFIER:\r
case EFI_PAUSE_MODIFIER:\r
case EFI_BREAK_MODIFIER:\r
//\r
- // fall through\r
+ // Fall through\r
//\r
continue;\r
break;\r
}\r
\r
//\r
- // When encountered Del Key...\r
+ // When encountering Ctrl + Alt + Del, then warm reset.\r
//\r
if (KeyDescriptor->Modifier == EFI_DELETE_MODIFIER) {\r
if ((UsbKeyboardDevice->CtrlOn != 0) && (UsbKeyboardDevice->AltOn != 0)) {\r
\r
\r
/**\r
- Converts USB Keyboard code to EFI Scan Code.\r
+ Converts USB Keyboard code to EFI_INPUT_KEY.\r
\r
@param UsbKeyboardDevice The USB_KB_DEV instance.\r
@param KeyChar Indicates the key code that will be interpreted.\r
**/\r
EFI_STATUS\r
EFIAPI\r
-USBKeyCodeToEFIScanCode (\r
+UsbKeyCodeToEfiInputKey (\r
IN USB_KB_DEV *UsbKeyboardDevice,\r
IN UINT8 KeyChar,\r
OUT EFI_INPUT_KEY *Key\r
}\r
\r
//\r
- // valid USB Key Code starts from 4\r
+ // Valid USB Key Code starts from 4, so it's safe to minus 4.\r
//\r
Index = (UINT8) (KeyChar - 4);\r
\r
\r
KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, KeyChar);\r
\r
- //\r
- // Check for Non-spacing key\r
- //\r
if (KeyDescriptor->Modifier == EFI_NS_KEY_MODIFIER) {\r
+ //\r
+ // If this is a dead key with EFI_NS_KEY_MODIFIER, then record it and return.\r
+ //\r
UsbKeyboardDevice->CurrentNsKey = FindUsbNsKey (UsbKeyboardDevice, KeyDescriptor);\r
return EFI_NOT_READY;\r
}\r
\r
- //\r
- // Check whether this keystroke follows a Non-spacing key\r
- //\r
if (UsbKeyboardDevice->CurrentNsKey != NULL) {\r
+ //\r
+ // If this keystroke follows a non-spacing key, then find the descriptor for corresponding\r
+ // physical key.\r
+ //\r
KeyDescriptor = FindPhysicalKey (UsbKeyboardDevice->CurrentNsKey, KeyDescriptor);\r
UsbKeyboardDevice->CurrentNsKey = NULL;\r
}\r
Key->ScanCode = EfiScanCodeConvertionTable[KeyDescriptor->Modifier];\r
Key->UnicodeChar = KeyDescriptor->Unicode;\r
\r
- if (KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_STANDARD_SHIFT) {\r
+ if ((KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_STANDARD_SHIFT)!= 0) {\r
if (UsbKeyboardDevice->ShiftOn != 0) {\r
Key->UnicodeChar = KeyDescriptor->ShiftedUnicode;\r
\r
// Need not return associated shift state if a class of printable characters that\r
// are normally adjusted by shift modifiers. e.g. Shift Key + 'f' key = 'F'\r
//\r
- if (KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_CAPS_LOCK) {\r
+ if ((KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_CAPS_LOCK) != 0) {\r
UsbKeyboardDevice->LeftShiftOn = 0;\r
UsbKeyboardDevice->RightShiftOn = 0;\r
}\r
}\r
}\r
\r
- if (KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_CAPS_LOCK) {\r
+ if ((KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_CAPS_LOCK) != 0) {\r
if (UsbKeyboardDevice->CapsOn != 0) {\r
\r
if (Key->UnicodeChar == KeyDescriptor->Unicode) {\r
}\r
\r
//\r
- // Translate the CTRL-Alpha characters to their corresponding control value (ctrl-a = 0x0001 through ctrl-Z = 0x001A)\r
+ // Translate the CTRL-Alpha characters to their corresponding control value\r
+ // (ctrl-a = 0x0001 through ctrl-Z = 0x001A)\r
//\r
if (UsbKeyboardDevice->CtrlOn != 0) {\r
if (Key->UnicodeChar >= 'a' && Key->UnicodeChar <= 'z') {\r
}\r
\r
if (KeyDescriptor->AffectedAttribute & EFI_AFFECTED_BY_NUM_LOCK) {\r
-\r
+ //\r
+ // For key affected by NumLock, if NumLock is on and Shift is not pressed, then it means\r
+ // normal key, instead of original control key. So the ScanCode should be cleaned.\r
+ // Otherwise, it means control key, so preserve the EFI Scan Code and clear the unicode keycode.\r
+ //\r
if ((UsbKeyboardDevice->NumLockOn != 0) && (UsbKeyboardDevice->ShiftOn == 0)) {\r
-\r
Key->ScanCode = SCAN_NULL;\r
-\r
} else {\r
Key->UnicodeChar = 0x00;\r
}\r
Key->UnicodeChar = 0x00;\r
}\r
\r
+ //\r
+ // Not valid for key without both unicode key code and EFI Scan Code.\r
+ //\r
if (Key->UnicodeChar == 0 && Key->ScanCode == SCAN_NULL) {\r
return EFI_NOT_READY;\r
}\r
\r
@param KeyboardBuffer Points to the USB Keyboard Buffer.\r
\r
- @retval EFI_SUCCESS Init key buffer successfully.\r
-\r
**/\r
-EFI_STATUS\r
+VOID\r
EFIAPI\r
InitUSBKeyBuffer (\r
IN OUT USB_KB_BUFFER *KeyboardBuffer\r
{\r
ZeroMem (KeyboardBuffer, sizeof (USB_KB_BUFFER));\r
\r
- KeyboardBuffer->bHead = KeyboardBuffer->bTail;\r
-\r
- return EFI_SUCCESS;\r
+ KeyboardBuffer->BufferHead = KeyboardBuffer->BufferTail;\r
}\r
\r
\r
//\r
// meet FIFO empty condition\r
//\r
- return (BOOLEAN) (KeyboardBuffer->bHead == KeyboardBuffer->bTail);\r
+ return (BOOLEAN) (KeyboardBuffer->BufferHead == KeyboardBuffer->BufferTail);\r
}\r
\r
\r
IN USB_KB_BUFFER *KeyboardBuffer\r
)\r
{\r
- return (BOOLEAN)(((KeyboardBuffer->bTail + 1) % (MAX_KEY_ALLOWED + 1)) ==\r
- KeyboardBuffer->bHead);\r
+ return (BOOLEAN)(((KeyboardBuffer->BufferTail + 1) % (MAX_KEY_ALLOWED + 1)) == KeyboardBuffer->BufferHead);\r
}\r
\r
\r
@param Key Key code\r
@param Down Special key\r
\r
- @retval EFI_SUCCESS Success\r
-\r
**/\r
-EFI_STATUS\r
+VOID\r
EFIAPI\r
InsertKeyCode (\r
IN OUT USB_KB_BUFFER *KeyboardBuffer,\r
RemoveKeyCode (KeyboardBuffer, &UsbKey);\r
}\r
\r
- KeyboardBuffer->buffer[KeyboardBuffer->bTail].KeyCode = Key;\r
- KeyboardBuffer->buffer[KeyboardBuffer->bTail].Down = Down;\r
+ KeyboardBuffer->Buffer[KeyboardBuffer->BufferTail].KeyCode = Key;\r
+ KeyboardBuffer->Buffer[KeyboardBuffer->BufferTail].Down = Down;\r
\r
//\r
- // adjust the tail pointer of the FIFO keyboard buffer.\r
+ // Adjust the tail pointer of the FIFO keyboard buffer.\r
//\r
- KeyboardBuffer->bTail = (UINT8) ((KeyboardBuffer->bTail + 1) % (MAX_KEY_ALLOWED + 1));\r
-\r
- return EFI_SUCCESS;\r
+ KeyboardBuffer->BufferTail = (UINT8) ((KeyboardBuffer->BufferTail + 1) % (MAX_KEY_ALLOWED + 1));\r
}\r
\r
\r
@param KeyboardBuffer Points to the USB Keyboard Buffer.\r
@param UsbKey Points to the buffer that contains a usb key code.\r
\r
- @retval EFI_SUCCESS Success\r
- @retval EFI_DEVICE_ERROR Hardware Error\r
+ @retval EFI_SUCCESS Key code Successfully poped from keyboard buffer.\r
+ @retval EFI_DEVICE_ERROR Keyboard buffer is empty.\r
\r
**/\r
EFI_STATUS\r
return EFI_DEVICE_ERROR;\r
}\r
\r
- UsbKey->KeyCode = KeyboardBuffer->buffer[KeyboardBuffer->bHead].KeyCode;\r
- UsbKey->Down = KeyboardBuffer->buffer[KeyboardBuffer->bHead].Down;\r
+ UsbKey->KeyCode = KeyboardBuffer->Buffer[KeyboardBuffer->BufferHead].KeyCode;\r
+ UsbKey->Down = KeyboardBuffer->Buffer[KeyboardBuffer->BufferHead].Down;\r
\r
//\r
- // adjust the head pointer of the FIFO keyboard buffer.\r
+ // Adjust the head pointer of the FIFO keyboard buffer.\r
//\r
- KeyboardBuffer->bHead = (UINT8) ((KeyboardBuffer->bHead + 1) % (MAX_KEY_ALLOWED + 1));\r
+ KeyboardBuffer->BufferHead = (UINT8) ((KeyboardBuffer->BufferHead + 1) % (MAX_KEY_ALLOWED + 1));\r
\r
return EFI_SUCCESS;\r
}\r
\r
@param UsbKeyboardDevice The USB_KB_DEV instance.\r
\r
- @retval EFI_SUCCESS Success\r
-\r
**/\r
-EFI_STATUS\r
+VOID\r
EFIAPI\r
SetKeyLED (\r
IN USB_KB_DEV *UsbKeyboardDevice\r
\r
ReportId = 0;\r
//\r
- // call Set Report Request to lighten the LED.\r
+ // Call Set_Report Request to lighten the LED.\r
//\r
UsbSetReportRequest (\r
UsbKeyboardDevice->UsbIo,\r
1,\r
(UINT8 *) &Led\r
);\r
-\r
- return EFI_SUCCESS;\r
}\r
\r
\r
@param Event The Repeat Key event.\r
@param Context Points to the USB_KB_DEV instance.\r
\r
-\r
**/\r
VOID\r
EFIAPI\r
);\r
\r
//\r
- // set repeate rate for repeat key generation.\r
+ // Set repeate rate for next repeat key generation.\r
//\r
gBS->SetTimer (\r
- UsbKeyboardDevice->RepeatTimer,\r
- TimerRelative,\r
- USBKBD_REPEAT_RATE\r
- );\r
-\r
+ UsbKeyboardDevice->RepeatTimer,\r
+ TimerRelative,\r
+ USBKBD_REPEAT_RATE\r
+ );\r
}\r
}\r
\r
@param Event The Delayed Recovery event.\r
@param Context Points to the USB_KB_DEV instance.\r
\r
-\r
**/\r
VOID\r
EFIAPI\r
\r
PacketSize = (UINT8) (UsbKeyboardDevice->IntEndpointDescriptor.MaxPacketSize);\r
\r
+ //\r
+ // Re-submit Asynchronous Interrupt Transfer for recovery.\r
+ //\r
UsbIo->UsbAsyncInterruptTransfer (\r
- UsbIo,\r
- UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress,\r
- TRUE,\r
- UsbKeyboardDevice->IntEndpointDescriptor.Interval,\r
- PacketSize,\r
- KeyboardHandler,\r
- UsbKeyboardDevice\r
- );\r
+ UsbIo,\r
+ UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress,\r
+ TRUE,\r
+ UsbKeyboardDevice->IntEndpointDescriptor.Interval,\r
+ PacketSize,\r
+ KeyboardHandler,\r
+ UsbKeyboardDevice\r
+ );\r
}\r