3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Common Dxe Libarary for USB
19 Add Constants & structure definitions for Usb HID
25 #ifndef _USB_DXE_LIB_H
26 #define _USB_DXE_LIB_H
28 #include <Protocol/UsbIo.h>
30 // define the timeout time as 3ms
32 #define TIMEOUT_VALUE 3 * 1000
35 // HID constants definition, see HID rev1.0
38 // HID report item format
40 #define HID_ITEM_FORMAT_SHORT 0
41 #define HID_ITEM_FORMAT_LONG 1
44 // Special tag indicating long items
46 #define HID_ITEM_TAG_LONG 15
49 // HID report descriptor item type (prefix bit 2,3)
51 #define HID_ITEM_TYPE_MAIN 0
52 #define HID_ITEM_TYPE_GLOBAL 1
53 #define HID_ITEM_TYPE_LOCAL 2
54 #define HID_ITEM_TYPE_RESERVED 3
57 // HID report descriptor main item tags
59 #define HID_MAIN_ITEM_TAG_INPUT 8
60 #define HID_MAIN_ITEM_TAG_OUTPUT 9
61 #define HID_MAIN_ITEM_TAG_FEATURE 11
62 #define HID_MAIN_ITEM_TAG_BEGIN_COLLECTION 10
63 #define HID_MAIN_ITEM_TAG_END_COLLECTION 12
66 // HID report descriptor main item contents
68 #define HID_MAIN_ITEM_CONSTANT 0x001
69 #define HID_MAIN_ITEM_VARIABLE 0x002
70 #define HID_MAIN_ITEM_RELATIVE 0x004
71 #define HID_MAIN_ITEM_WRAP 0x008
72 #define HID_MAIN_ITEM_NONLINEAR 0x010
73 #define HID_MAIN_ITEM_NO_PREFERRED 0x020
74 #define HID_MAIN_ITEM_NULL_STATE 0x040
75 #define HID_MAIN_ITEM_VOLATILE 0x080
76 #define HID_MAIN_ITEM_BUFFERED_BYTE 0x100
79 // HID report descriptor collection item types
81 #define HID_COLLECTION_PHYSICAL 0
82 #define HID_COLLECTION_APPLICATION 1
83 #define HID_COLLECTION_LOGICAL 2
86 // HID report descriptor global item tags
88 #define HID_GLOBAL_ITEM_TAG_USAGE_PAGE 0
89 #define HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM 1
90 #define HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM 2
91 #define HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM 3
92 #define HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM 4
93 #define HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT 5
94 #define HID_GLOBAL_ITEM_TAG_UNIT 6
95 #define HID_GLOBAL_ITEM_TAG_REPORT_SIZE 7
96 #define HID_GLOBAL_ITEM_TAG_REPORT_ID 8
97 #define HID_GLOBAL_ITEM_TAG_REPORT_COUNT 9
98 #define HID_GLOBAL_ITEM_TAG_PUSH 10
99 #define HID_GLOBAL_ITEM_TAG_POP 11
102 // HID report descriptor local item tags
104 #define HID_LOCAL_ITEM_TAG_USAGE 0
105 #define HID_LOCAL_ITEM_TAG_USAGE_MINIMUM 1
106 #define HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM 2
107 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_INDEX 3
108 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MINIMUM 4
109 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MAXIMUM 5
110 #define HID_LOCAL_ITEM_TAG_STRING_INDEX 7
111 #define HID_LOCAL_ITEM_TAG_STRING_MINIMUM 8
112 #define HID_LOCAL_ITEM_TAG_STRING_MAXIMUM 9
113 #define HID_LOCAL_ITEM_TAG_DELIMITER 10
118 #define HID_USAGE_PAGE 0xffff0000
120 #define HID_UP_GENDESK 0x00010000
121 #define HID_UP_KEYBOARD 0x00070000
122 #define HID_UP_LED 0x00080000
123 #define HID_UP_BUTTON 0x00090000
124 #define HID_UP_CONSUMER 0x000c0000
125 #define HID_UP_DIGITIZER 0x000d0000
126 #define HID_UP_PID 0x000f0000
128 #define HID_USAGE 0x0000ffff
130 #define HID_GD_POINTER 0x00010001
131 #define HID_GD_MOUSE 0x00010002
132 #define HID_GD_JOYSTICK 0x00010004
133 #define HID_GD_GAMEPAD 0x00010005
134 #define HID_GD_HATSWITCH 0x00010039
139 #define HID_INPUT_REPORT 1
140 #define HID_OUTPUT_REPORT 2
141 #define HID_FEATURE_REPORT 3
144 // HID device quirks.
146 #define HID_QUIRK_INVERT 0x01
147 #define HID_QUIRK_NOTOUCH 0x02
150 // HID class protocol request
152 #define EFI_USB_GET_REPORT_REQUEST 0x01
153 #define EFI_USB_GET_IDLE_REQUEST 0x02
154 #define EFI_USB_GET_PROTOCOL_REQUEST 0x03
155 #define EFI_USB_SET_REPORT_REQUEST 0x09
156 #define EFI_USB_SET_IDLE_REQUEST 0x0a
157 #define EFI_USB_SET_PROTOCOL_REQUEST 0x0b
161 // Descriptor header for Report/Physical Descriptors
163 typedef struct hid_class_descriptor
{
164 UINT8 DescriptorType
;
165 UINT16 DescriptorLength
;
166 } EFI_USB_HID_CLASS_DESCRIPTOR
;
168 typedef struct hid_descriptor
{
170 UINT8 DescriptorType
;
173 UINT8 NumDescriptors
;
174 EFI_USB_HID_CLASS_DESCRIPTOR HidClassDesc
[1];
175 } EFI_USB_HID_DESCRIPTOR
;
180 UsbGetHidDescriptor (
181 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
182 IN UINT8 InterfaceNum
,
183 OUT EFI_USB_HID_DESCRIPTOR
*HidDescriptor
187 UsbGetReportDescriptor (
188 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
189 IN UINT8 InterfaceNum
,
190 IN UINT16 DescriptorSize
,
191 OUT UINT8
*DescriptorBuffer
195 UsbGetProtocolRequest (
196 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
202 UsbSetProtocolRequest (
203 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
210 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
218 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
225 UsbSetReportRequest (
226 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
235 UsbGetReportRequest (
236 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
245 // Get Device Descriptor
249 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
252 IN UINT16 DescriptorLength
,
253 OUT VOID
*Descriptor
,
258 // Set Device Descriptor
262 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
265 IN UINT16 DescriptorLength
,
271 // Get device Interface
274 UsbGetDeviceInterface (
275 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
277 OUT UINT8
*AltSetting
,
282 // Set device interface
285 UsbSetDeviceInterface (
286 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
287 IN UINT16 InterfaceNo
,
288 IN UINT16 AltSetting
,
293 // Get device configuration
296 UsbGetDeviceConfiguration (
297 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
298 OUT UINT8
*ConfigValue
,
303 // Set device configuration
306 UsbSetDeviceConfiguration (
307 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
313 // Set Device Feature
316 UsbSetDeviceFeature (
317 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
318 IN EFI_USB_RECIPIENT Recipient
,
325 // Clear Device Feature
328 UsbClearDeviceFeature (
329 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
330 IN EFI_USB_RECIPIENT Recipient
,
341 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
342 IN EFI_USB_RECIPIENT Recipient
,
344 OUT UINT16
*DevStatus
,
349 // The following APIs are not basic library, but they are common used.
356 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
365 // Clear endpoint stall
368 UsbClearEndpointHalt (
369 IN EFI_USB_IO_PROTOCOL
*UsbIo
,