1. Add Partial Keystroke Support in UsbKb drivers. See the Uefi2.3.1a chapter 11.2

Signed-off-by: qianouyang
Reviewed-by: niruiyu vanjeff



git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12494 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qianouyang 2011-09-30 07:28:16 +00:00
parent e791cf4449
commit 3765794ca3
3 changed files with 130 additions and 84 deletions

View File

@ -676,14 +676,25 @@ USBKeyboardReadKeyStroke (
UsbKeyboardDevice = USB_KB_DEV_FROM_THIS (This);
//
// Considering if the partial keystroke is enabled, there maybe a partial
// keystroke in the queue, so here skip the partial keystroke and get the
// next key from the queue
//
while (1) {
Status = USBKeyboardReadKeyStrokeWorker (UsbKeyboardDevice, &KeyData);
if (EFI_ERROR (Status)) {
return Status;
}
//
// SimpleTextIn Protocol doesn't support partial keystroke;
//
if (KeyData.Key.ScanCode == CHAR_NULL && KeyData.Key.UnicodeChar == SCAN_NULL) {
continue;
}
CopyMem (Key, &KeyData.Key, sizeof (EFI_INPUT_KEY));
return EFI_SUCCESS;
}
}
@ -703,15 +714,42 @@ USBKeyboardWaitForKey (
)
{
USB_KB_DEV *UsbKeyboardDevice;
EFI_KEY_DATA KeyData;
EFI_TPL OldTpl;
UsbKeyboardDevice = (USB_KB_DEV *) Context;
if (!IsQueueEmpty (&UsbKeyboardDevice->EfiKeyQueue)) {
//
// Enter critical section
//
OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
//
// WaitforKey doesn't suppor the partial key.
// Considering if the partial keystroke is enabled, there maybe a partial
// keystroke in the queue, so here skip the partial keystroke and get the
// next key from the queue
//
while (!IsQueueEmpty (&UsbKeyboardDevice->EfiKeyQueue)) {
//
// If there is pending key, signal the event.
//
gBS->SignalEvent (Event);
CopyMem (
&KeyData,
UsbKeyboardDevice->EfiKeyQueue.Buffer[UsbKeyboardDevice->EfiKeyQueue.Head],
sizeof (EFI_KEY_DATA)
);
if (KeyData.Key.ScanCode == SCAN_NULL && KeyData.Key.UnicodeChar == CHAR_NULL) {
Dequeue (&UsbKeyboardDevice->EfiKeyQueue, &KeyData, sizeof (EFI_KEY_DATA));
continue;
}
gBS->SignalEvent (Event);
break;
}
//
// Leave critical section and return
//
gBS->RestoreTPL (OldTpl);
}
/**
@ -867,6 +905,9 @@ USBKeyboardResetEx (
return EFI_DEVICE_ERROR;
}
UsbKeyboardDevice->KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID;
UsbKeyboardDevice->KeyState.KeyToggleState = EFI_TOGGLE_STATE_VALID;
return EFI_SUCCESS;
}
@ -933,7 +974,8 @@ USBKeyboardSetState (
UsbKeyboardDevice = TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS (This);
if ((*KeyToggleState & EFI_TOGGLE_STATE_VALID) != EFI_TOGGLE_STATE_VALID) {
if (((UsbKeyboardDevice->KeyState.KeyToggleState & EFI_TOGGLE_STATE_VALID) != EFI_TOGGLE_STATE_VALID) ||
((*KeyToggleState & EFI_TOGGLE_STATE_VALID) != EFI_TOGGLE_STATE_VALID)) {
return EFI_UNSUPPORTED;
}
@ -944,6 +986,7 @@ USBKeyboardSetState (
UsbKeyboardDevice->ScrollOn = FALSE;
UsbKeyboardDevice->NumLockOn = FALSE;
UsbKeyboardDevice->CapsOn = FALSE;
UsbKeyboardDevice->IsSupportPartialKey = FALSE;
if ((*KeyToggleState & EFI_SCROLL_LOCK_ACTIVE) == EFI_SCROLL_LOCK_ACTIVE) {
UsbKeyboardDevice->ScrollOn = TRUE;
@ -954,9 +997,14 @@ USBKeyboardSetState (
if ((*KeyToggleState & EFI_CAPS_LOCK_ACTIVE) == EFI_CAPS_LOCK_ACTIVE) {
UsbKeyboardDevice->CapsOn = TRUE;
}
if ((*KeyToggleState & EFI_KEY_STATE_EXPOSED) == EFI_KEY_STATE_EXPOSED) {
UsbKeyboardDevice->IsSupportPartialKey = TRUE;
}
SetKeyLED (UsbKeyboardDevice);
UsbKeyboardDevice->KeyState.KeyToggleState = *KeyToggleState;
return EFI_SUCCESS;
}

View File

@ -142,6 +142,10 @@ typedef struct {
BOOLEAN MenuKeyOn;
BOOLEAN SysReqOn;
BOOLEAN AltGrOn;
BOOLEAN IsSupportPartialKey;
EFI_KEY_STATE KeyState;
//
// Notification function list
//

View File

@ -296,10 +296,17 @@ UINT8 ModifierValueToEfiScanCodeConvertionTable[] = {
SCAN_F10, // EFI_FUNCTION_KEY_TEN_MODIFIER
SCAN_F11, // EFI_FUNCTION_KEY_ELEVEN_MODIFIER
SCAN_F12, // EFI_FUNCTION_KEY_TWELVE_MODIFIER
//
// For Partial Keystroke support
//
SCAN_NULL, // EFI_PRINT_MODIFIER
SCAN_NULL, // EFI_SYS_REQUEST_MODIFIER
SCAN_NULL, // EFI_SCROLL_LOCK_MODIFIER
SCAN_PAUSE // EFI_PAUSE_MODIFIER
SCAN_PAUSE, // EFI_PAUSE_MODIFIER
SCAN_NULL, // EFI_BREAK_MODIFIER
SCAN_NULL, // EFI_LEFT_LOGO_MODIFIER
SCAN_NULL, // EFI_RIGHT_LOGO_MODIFER
SCAN_NULL, // EFI_MENU_MODIFER
};
/**
@ -1382,12 +1389,10 @@ USBParseKey (
case EFI_LEFT_CONTROL_MODIFIER:
UsbKeyboardDevice->LeftCtrlOn = TRUE;
UsbKeyboardDevice->CtrlOn = TRUE;
continue;
break;
case EFI_RIGHT_CONTROL_MODIFIER:
UsbKeyboardDevice->RightCtrlOn = TRUE;
UsbKeyboardDevice->CtrlOn = TRUE;
continue;
break;
//
@ -1396,12 +1401,10 @@ USBParseKey (
case EFI_LEFT_SHIFT_MODIFIER:
UsbKeyboardDevice->LeftShiftOn = TRUE;
UsbKeyboardDevice->ShiftOn = TRUE;
continue;
break;
case EFI_RIGHT_SHIFT_MODIFIER:
UsbKeyboardDevice->RightShiftOn = TRUE;
UsbKeyboardDevice->ShiftOn = TRUE;
continue;
break;
//
@ -1410,12 +1413,10 @@ USBParseKey (
case EFI_LEFT_ALT_MODIFIER:
UsbKeyboardDevice->LeftAltOn = TRUE;
UsbKeyboardDevice->AltOn = TRUE;
continue;
break;
case EFI_RIGHT_ALT_MODIFIER:
UsbKeyboardDevice->RightAltOn = TRUE;
UsbKeyboardDevice->AltOn = TRUE;
continue;
break;
//
@ -1445,7 +1446,6 @@ USBParseKey (
case EFI_PRINT_MODIFIER:
case EFI_SYS_REQUEST_MODIFIER:
UsbKeyboardDevice->SysReqOn = TRUE;
continue;
break;
//
@ -1461,7 +1461,6 @@ USBParseKey (
//
UsbKeyboardDevice->NumLockOn = (BOOLEAN) (!(UsbKeyboardDevice->NumLockOn));
SetKeyLED (UsbKeyboardDevice);
continue;
break;
case EFI_CAPS_LOCK_MODIFIER:
@ -1470,7 +1469,6 @@ USBParseKey (
//
UsbKeyboardDevice->CapsOn = (BOOLEAN) (!(UsbKeyboardDevice->CapsOn));
SetKeyLED (UsbKeyboardDevice);
continue;
break;
case EFI_SCROLL_LOCK_MODIFIER:
@ -1479,7 +1477,6 @@ USBParseKey (
//
UsbKeyboardDevice->ScrollOn = (BOOLEAN) (!(UsbKeyboardDevice->ScrollOn));
SetKeyLED (UsbKeyboardDevice);
continue;
break;
default:
@ -1532,15 +1529,8 @@ UsbKeyCodeToEfiInputKey (
KEYBOARD_CONSOLE_IN_EX_NOTIFY *CurrentNotify;
//
// KeyCode must in the range of 0x4 to 0x65
// KeyCode must in the range of [0x4, 0x65] or [0xe0, 0xe7].
//
if (!USBKBD_VALID_KEYCODE (KeyCode)) {
return EFI_INVALID_PARAMETER;
}
if ((KeyCode - 4) >= NUMBER_OF_VALID_NON_MODIFIER_USB_KEYCODE) {
return EFI_INVALID_PARAMETER;
}
KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, KeyCode);
ASSERT (KeyDescriptor != NULL);
@ -1618,7 +1608,7 @@ UsbKeyCodeToEfiInputKey (
if ((UsbKeyboardDevice->NumLockOn) && (!(UsbKeyboardDevice->ShiftOn))) {
KeyData->Key.ScanCode = SCAN_NULL;
} else {
KeyData->Key.UnicodeChar = 0x00;
KeyData->Key.UnicodeChar = CHAR_NULL;
}
}
@ -1627,15 +1617,17 @@ UsbKeyCodeToEfiInputKey (
//
if (KeyData->Key.UnicodeChar == 0x1B && KeyData->Key.ScanCode == SCAN_NULL) {
KeyData->Key.ScanCode = SCAN_ESC;
KeyData->Key.UnicodeChar = 0x00;
KeyData->Key.UnicodeChar = CHAR_NULL;
}
//
// Not valid for key without both unicode key code and EFI Scan Code.
//
if (KeyData->Key.UnicodeChar == 0 && KeyData->Key.ScanCode == SCAN_NULL) {
if (!UsbKeyboardDevice->IsSupportPartialKey) {
return EFI_NOT_READY;
}
}
//
// Save Shift/Toggle state
@ -1683,7 +1675,9 @@ UsbKeyCodeToEfiInputKey (
if (UsbKeyboardDevice->CapsOn) {
KeyData->KeyState.KeyToggleState |= EFI_CAPS_LOCK_ACTIVE;
}
if (UsbKeyboardDevice->IsSupportPartialKey) {
KeyData->KeyState.KeyToggleState |= EFI_KEY_STATE_EXPOSED;
}
//
// Invoke notification functions if the key is registered.
//