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