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