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