]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.h
1. Add Partial Keystroke Support in UsbKb drivers. See the Uefi2.3.1a chapter 11.2
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbKbDxe / KeyBoard.h
CommitLineData
a7022cec 1/** @file\r
a7022cec 2 Function prototype for USB Keyboard Driver.\r
3\r
c1fd2767 4Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
cd5ebaa0 5This program and the accompanying materials\r
a7022cec 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#ifndef _EFI_KEYBOARD_H_\r
16#define _EFI_KEYBOARD_H_\r
17\r
18\r
19#include "EfiKey.h"\r
20\r
c41c3e55 21#define USB_KEYBOARD_KEY_COUNT 104\r
22\r
23#define USB_KEYBOARD_LANGUAGE_STR_LEN 5 // RFC4646 Language Code: "en-US"\r
24#define USB_KEYBOARD_DESCRIPTION_STR_LEN (16 + 1) // Description: "English Keyboard"\r
25\r
26#pragma pack (1)\r
27typedef struct {\r
28 //\r
29 // This 4-bytes total array length is required by PreparePackageList()\r
30 //\r
31 UINT32 Length;\r
32\r
33 //\r
34 // Keyboard Layout package definition\r
35 //\r
36 EFI_HII_PACKAGE_HEADER PackageHeader;\r
37 UINT16 LayoutCount;\r
38\r
39 //\r
40 // EFI_HII_KEYBOARD_LAYOUT\r
41 //\r
42 UINT16 LayoutLength;\r
43 EFI_GUID Guid;\r
44 UINT32 LayoutDescriptorStringOffset;\r
45 UINT8 DescriptorCount;\r
46 EFI_KEY_DESCRIPTOR KeyDescriptor[USB_KEYBOARD_KEY_COUNT];\r
47 UINT16 DescriptionCount;\r
48 CHAR16 Language[USB_KEYBOARD_LANGUAGE_STR_LEN];\r
49 CHAR16 Space;\r
50 CHAR16 DescriptionString[USB_KEYBOARD_DESCRIPTION_STR_LEN];\r
51} USB_KEYBOARD_LAYOUT_PACK_BIN;\r
52#pragma pack()\r
a7022cec 53/**\r
b4e73a63 54 Uses USB I/O to check whether the device is a USB keyboard device.\r
a7022cec 55\r
b4e73a63 56 @param UsbIo Pointer to a USB I/O protocol instance.\r
57\r
58 @retval TRUE Device is a USB keyboard device.\r
59 @retval FALSE Device is a not USB keyboard device.\r
a7022cec 60\r
61**/\r
62BOOLEAN\r
a7022cec 63IsUSBKeyboard (\r
64 IN EFI_USB_IO_PROTOCOL *UsbIo\r
65 );\r
66\r
67/**\r
b4e73a63 68 Initialize USB keyboard device and all private data structures.\r
a7022cec 69\r
70 @param UsbKeyboardDevice The USB_KB_DEV instance.\r
71\r
72 @retval EFI_SUCCESS Initialization is successful.\r
b4e73a63 73 @retval EFI_DEVICE_ERROR Keyboard initialization failed.\r
a7022cec 74\r
75**/\r
76EFI_STATUS\r
a7022cec 77InitUSBKeyboard (\r
b4e73a63 78 IN OUT USB_KB_DEV *UsbKeyboardDevice\r
a7022cec 79 );\r
80\r
81/**\r
b4e73a63 82 Initialize USB keyboard layout.\r
83\r
84 This function initializes Key Convertion Table for the USB keyboard device.\r
85 It first tries to retrieve layout from HII database. If failed and default\r
86 layout is enabled, then it just uses the default layout.\r
a7022cec 87\r
88 @param UsbKeyboardDevice The USB_KB_DEV instance.\r
89\r
b4e73a63 90 @retval EFI_SUCCESS Initialization succeeded.\r
91 @retval EFI_NOT_READY Keyboard layout cannot be retrieve from HII\r
92 database, and default layout is disabled.\r
93 @retval Other Fail to register event to EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID group.\r
a7022cec 94\r
95**/\r
96EFI_STATUS\r
a7022cec 97InitKeyboardLayout (\r
b4e73a63 98 OUT USB_KB_DEV *UsbKeyboardDevice\r
a7022cec 99 );\r
100\r
101/**\r
b4e73a63 102 Destroy resources for keyboard layout.\r
a7022cec 103\r
104 @param UsbKeyboardDevice The USB_KB_DEV instance.\r
105\r
106**/\r
107VOID\r
a7022cec 108ReleaseKeyboardLayoutResources (\r
b4e73a63 109 IN OUT USB_KB_DEV *UsbKeyboardDevice\r
a7022cec 110 );\r
111\r
112/**\r
b4e73a63 113 Handler function for USB keyboard's asynchronous interrupt transfer.\r
114\r
115 This function is the handler function for USB keyboard's asynchronous interrupt transfer\r
116 to manage the keyboard. It parses the USB keyboard input report, and inserts data to\r
117 keyboard buffer according to state of modifer keys and normal keys. Timer for repeat key\r
118 is also set accordingly.\r
a7022cec 119\r
120 @param Data A pointer to a buffer that is filled with key data which is\r
121 retrieved via asynchronous interrupt transfer.\r
122 @param DataLength Indicates the size of the data buffer.\r
123 @param Context Pointing to USB_KB_DEV instance.\r
124 @param Result Indicates the result of the asynchronous interrupt transfer.\r
125\r
b4e73a63 126 @retval EFI_SUCCESS Asynchronous interrupt transfer is handled successfully.\r
127 @retval EFI_DEVICE_ERROR Hardware error occurs.\r
a7022cec 128\r
129**/\r
130EFI_STATUS\r
131EFIAPI\r
132KeyboardHandler (\r
133 IN VOID *Data,\r
134 IN UINTN DataLength,\r
135 IN VOID *Context,\r
136 IN UINT32 Result\r
137 );\r
138\r
139/**\r
b4e73a63 140 Handler for Delayed Recovery event.\r
141\r
142 This function is the handler for Delayed Recovery event triggered\r
143 by timer.\r
144 After a device error occurs, the event would be triggered\r
145 with interval of EFI_USB_INTERRUPT_DELAY. EFI_USB_INTERRUPT_DELAY\r
146 is defined in USB standard for error handling.\r
a7022cec 147\r
148 @param Event The Delayed Recovery event.\r
149 @param Context Points to the USB_KB_DEV instance.\r
150\r
a7022cec 151**/\r
152VOID\r
153EFIAPI\r
154USBKeyboardRecoveryHandler (\r
155 IN EFI_EVENT Event,\r
156 IN VOID *Context\r
157 );\r
158\r
159/**\r
b4e73a63 160 Retrieves a USB keycode after parsing the raw data in keyboard buffer.\r
161\r
162 This function parses keyboard buffer. It updates state of modifier key for\r
163 USB_KB_DEV instancem, and returns keycode for output.\r
a7022cec 164\r
165 @param UsbKeyboardDevice The USB_KB_DEV instance.\r
b4e73a63 166 @param KeyCode Pointer to the USB keycode for output.\r
a7022cec 167\r
b4e73a63 168 @retval EFI_SUCCESS Keycode successfully parsed.\r
169 @retval EFI_NOT_READY Keyboard buffer is not ready for a valid keycode\r
a7022cec 170\r
171**/\r
172EFI_STATUS\r
a7022cec 173USBParseKey (\r
174 IN OUT USB_KB_DEV *UsbKeyboardDevice,\r
b4e73a63 175 OUT UINT8 *KeyCode\r
a7022cec 176 );\r
177\r
178/**\r
b4e73a63 179 Converts USB Keycode ranging from 0x4 to 0x65 to EFI_INPUT_KEY.\r
a7022cec 180\r
b4e73a63 181 @param UsbKeyboardDevice The USB_KB_DEV instance.\r
182 @param KeyCode Indicates the key code that will be interpreted.\r
c1fd2767 183 @param KeyData A pointer to a buffer that is filled in with\r
b4e73a63 184 the keystroke information for the key that\r
185 was pressed.\r
a7022cec 186\r
b4e73a63 187 @retval EFI_SUCCESS Success.\r
188 @retval EFI_INVALID_PARAMETER KeyCode is not in the range of 0x4 to 0x65.\r
189 @retval EFI_INVALID_PARAMETER Translated EFI_INPUT_KEY has zero for both ScanCode and UnicodeChar.\r
190 @retval EFI_NOT_READY KeyCode represents a dead key with EFI_NS_KEY_MODIFIER\r
81464cf1 191 @retval EFI_DEVICE_ERROR Keyboard layout is invalid.\r
a7022cec 192\r
193**/\r
194EFI_STATUS\r
5899f27e 195UsbKeyCodeToEfiInputKey (\r
a7022cec 196 IN USB_KB_DEV *UsbKeyboardDevice,\r
b4e73a63 197 IN UINT8 KeyCode,\r
c1fd2767 198 OUT EFI_KEY_DATA *KeyData\r
a7022cec 199 );\r
200\r
c1fd2767 201\r
a7022cec 202/**\r
c1fd2767 203 Create the queue.\r
a7022cec 204\r
c1fd2767
RN
205 @param Queue Points to the queue.\r
206 @param ItemSize Size of the single item.\r
a7022cec 207\r
a7022cec 208**/\r
5899f27e 209VOID\r
c1fd2767
RN
210InitQueue (\r
211 IN OUT USB_SIMPLE_QUEUE *Queue,\r
212 IN UINTN ItemSize\r
213 );\r
214\r
215/**\r
216 Destroy the queue\r
217\r
218 @param Queue Points to the queue.\r
219**/\r
220VOID\r
221DestroyQueue (\r
222 IN OUT USB_SIMPLE_QUEUE *Queue\r
a7022cec 223 );\r
224\r
c1fd2767 225\r
a7022cec 226/**\r
c1fd2767 227 Check whether the queue is empty.\r
a7022cec 228\r
c1fd2767 229 @param Queue Points to the queue.\r
a7022cec 230\r
c1fd2767
RN
231 @retval TRUE Queue is empty.\r
232 @retval FALSE Queue is not empty.\r
a7022cec 233\r
234**/\r
235BOOLEAN\r
c1fd2767
RN
236IsQueueEmpty (\r
237 IN USB_SIMPLE_QUEUE *Queue\r
a7022cec 238 );\r
239\r
c1fd2767 240\r
a7022cec 241/**\r
c1fd2767 242 Check whether the queue is full.\r
a7022cec 243\r
c1fd2767 244 @param Queue Points to the queue.\r
a7022cec 245\r
c1fd2767
RN
246 @retval TRUE Queue is full.\r
247 @retval FALSE Queue is not full.\r
a7022cec 248\r
249**/\r
250BOOLEAN\r
c1fd2767
RN
251IsQueueFull (\r
252 IN USB_SIMPLE_QUEUE *Queue\r
a7022cec 253 );\r
254\r
a7022cec 255\r
c1fd2767
RN
256/**\r
257 Enqueue the item to the queue.\r
a7022cec 258\r
c1fd2767
RN
259 @param Queue Points to the queue.\r
260 @param Item Points to the item to be enqueued.\r
261 @param ItemSize Size of the item.\r
a7022cec 262**/\r
5899f27e 263VOID\r
c1fd2767
RN
264Enqueue (\r
265 IN OUT USB_SIMPLE_QUEUE *Queue,\r
266 IN VOID *Item,\r
267 IN UINTN ItemSize\r
a7022cec 268 );\r
269\r
c1fd2767 270\r
a7022cec 271/**\r
c1fd2767 272 Dequeue a item from the queue.\r
a7022cec 273\r
c1fd2767
RN
274 @param Queue Points to the queue.\r
275 @param Item Receives the item.\r
276 @param ItemSize Size of the item.\r
a7022cec 277\r
c1fd2767
RN
278 @retval EFI_SUCCESS Item was successfully dequeued.\r
279 @retval EFI_DEVICE_ERROR The queue is empty.\r
a7022cec 280\r
281**/\r
282EFI_STATUS\r
c1fd2767
RN
283Dequeue (\r
284 IN OUT USB_SIMPLE_QUEUE *Queue,\r
285 OUT VOID *Item,\r
286 IN UINTN ItemSize\r
a7022cec 287 );\r
288\r
289/**\r
b4e73a63 290 Handler for Repeat Key event.\r
291\r
292 This function is the handler for Repeat Key event triggered\r
293 by timer.\r
294 After a repeatable key is pressed, the event would be triggered\r
295 with interval of USBKBD_REPEAT_DELAY. Once the event is triggered,\r
296 following trigger will come with interval of USBKBD_REPEAT_RATE.\r
a7022cec 297\r
298 @param Event The Repeat Key event.\r
299 @param Context Points to the USB_KB_DEV instance.\r
300\r
a7022cec 301**/\r
302VOID\r
303EFIAPI\r
304USBKeyboardRepeatHandler (\r
305 IN EFI_EVENT Event,\r
306 IN VOID *Context\r
307 );\r
308\r
309/**\r
b4e73a63 310 Sets USB keyboard LED state.\r
a7022cec 311\r
312 @param UsbKeyboardDevice The USB_KB_DEV instance.\r
313\r
a7022cec 314**/\r
5899f27e 315VOID\r
a7022cec 316SetKeyLED (\r
317 IN USB_KB_DEV *UsbKeyboardDevice\r
318 );\r
319\r
320#endif\r