2 Common Dxe Libarary for USB
3 Add Constants & structure definitions for Usb HID
5 Copyright (c) 2006, Intel Corporation<BR>
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #ifndef __USB_DXE_LIB_H__
18 #define __USB_DXE_LIB_H__
20 #include <Protocol/UsbIo.h>
22 // define the timeout time as 3ms
24 #define TIMEOUT_VALUE 3 * 1000
27 // HID constants definition, see HID rev1.0
30 // HID report item format
32 #define HID_ITEM_FORMAT_SHORT 0
33 #define HID_ITEM_FORMAT_LONG 1
36 // Special tag indicating long items
38 #define HID_ITEM_TAG_LONG 15
41 // HID report descriptor item type (prefix bit 2,3)
43 #define HID_ITEM_TYPE_MAIN 0
44 #define HID_ITEM_TYPE_GLOBAL 1
45 #define HID_ITEM_TYPE_LOCAL 2
46 #define HID_ITEM_TYPE_RESERVED 3
49 // HID report descriptor main item tags
51 #define HID_MAIN_ITEM_TAG_INPUT 8
52 #define HID_MAIN_ITEM_TAG_OUTPUT 9
53 #define HID_MAIN_ITEM_TAG_FEATURE 11
54 #define HID_MAIN_ITEM_TAG_BEGIN_COLLECTION 10
55 #define HID_MAIN_ITEM_TAG_END_COLLECTION 12
58 // HID report descriptor main item contents
60 #define HID_MAIN_ITEM_CONSTANT 0x001
61 #define HID_MAIN_ITEM_VARIABLE 0x002
62 #define HID_MAIN_ITEM_RELATIVE 0x004
63 #define HID_MAIN_ITEM_WRAP 0x008
64 #define HID_MAIN_ITEM_NONLINEAR 0x010
65 #define HID_MAIN_ITEM_NO_PREFERRED 0x020
66 #define HID_MAIN_ITEM_NULL_STATE 0x040
67 #define HID_MAIN_ITEM_VOLATILE 0x080
68 #define HID_MAIN_ITEM_BUFFERED_BYTE 0x100
71 // HID report descriptor collection item types
73 #define HID_COLLECTION_PHYSICAL 0
74 #define HID_COLLECTION_APPLICATION 1
75 #define HID_COLLECTION_LOGICAL 2
78 // HID report descriptor global item tags
80 #define HID_GLOBAL_ITEM_TAG_USAGE_PAGE 0
81 #define HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM 1
82 #define HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM 2
83 #define HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM 3
84 #define HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM 4
85 #define HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT 5
86 #define HID_GLOBAL_ITEM_TAG_UNIT 6
87 #define HID_GLOBAL_ITEM_TAG_REPORT_SIZE 7
88 #define HID_GLOBAL_ITEM_TAG_REPORT_ID 8
89 #define HID_GLOBAL_ITEM_TAG_REPORT_COUNT 9
90 #define HID_GLOBAL_ITEM_TAG_PUSH 10
91 #define HID_GLOBAL_ITEM_TAG_POP 11
94 // HID report descriptor local item tags
96 #define HID_LOCAL_ITEM_TAG_USAGE 0
97 #define HID_LOCAL_ITEM_TAG_USAGE_MINIMUM 1
98 #define HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM 2
99 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_INDEX 3
100 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MINIMUM 4
101 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MAXIMUM 5
102 #define HID_LOCAL_ITEM_TAG_STRING_INDEX 7
103 #define HID_LOCAL_ITEM_TAG_STRING_MINIMUM 8
104 #define HID_LOCAL_ITEM_TAG_STRING_MAXIMUM 9
105 #define HID_LOCAL_ITEM_TAG_DELIMITER 10
110 #define HID_USAGE_PAGE 0xffff0000
112 #define HID_UP_GENDESK 0x00010000
113 #define HID_UP_KEYBOARD 0x00070000
114 #define HID_UP_LED 0x00080000
115 #define HID_UP_BUTTON 0x00090000
116 #define HID_UP_CONSUMER 0x000c0000
117 #define HID_UP_DIGITIZER 0x000d0000
118 #define HID_UP_PID 0x000f0000
120 #define HID_USAGE 0x0000ffff
122 #define HID_GD_POINTER 0x00010001
123 #define HID_GD_MOUSE 0x00010002
124 #define HID_GD_JOYSTICK 0x00010004
125 #define HID_GD_GAMEPAD 0x00010005
126 #define HID_GD_HATSWITCH 0x00010039
131 #define HID_INPUT_REPORT 1
132 #define HID_OUTPUT_REPORT 2
133 #define HID_FEATURE_REPORT 3
136 // HID device quirks.
138 #define HID_QUIRK_INVERT 0x01
139 #define HID_QUIRK_NOTOUCH 0x02
142 // HID class protocol request
144 #define EFI_USB_GET_REPORT_REQUEST 0x01
145 #define EFI_USB_GET_IDLE_REQUEST 0x02
146 #define EFI_USB_GET_PROTOCOL_REQUEST 0x03
147 #define EFI_USB_SET_REPORT_REQUEST 0x09
148 #define EFI_USB_SET_IDLE_REQUEST 0x0a
149 #define EFI_USB_SET_PROTOCOL_REQUEST 0x0b
153 // Descriptor header for Report/Physical Descriptors
155 typedef struct hid_class_descriptor
{
156 UINT8 DescriptorType
;
157 UINT16 DescriptorLength
;
158 } EFI_USB_HID_CLASS_DESCRIPTOR
;
160 typedef struct hid_descriptor
{
162 UINT8 DescriptorType
;
165 UINT8 NumDescriptors
;
166 EFI_USB_HID_CLASS_DESCRIPTOR HidClassDesc
[1];
167 } EFI_USB_HID_DESCRIPTOR
;
172 UsbGetHidDescriptor (
173 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
174 IN UINT8 InterfaceNum
,
175 OUT EFI_USB_HID_DESCRIPTOR
*HidDescriptor
179 UsbGetReportDescriptor (
180 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
181 IN UINT8 InterfaceNum
,
182 IN UINT16 DescriptorSize
,
183 OUT UINT8
*DescriptorBuffer
187 UsbGetProtocolRequest (
188 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
194 UsbSetProtocolRequest (
195 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
202 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
210 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
217 UsbSetReportRequest (
218 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
227 UsbGetReportRequest (
228 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
237 // Get Device Descriptor
241 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
244 IN UINT16 DescriptorLength
,
245 OUT VOID
*Descriptor
,
250 // Set Device Descriptor
254 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
257 IN UINT16 DescriptorLength
,
263 // Get device Interface
266 UsbGetDeviceInterface (
267 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
269 OUT UINT8
*AltSetting
,
274 // Set device interface
277 UsbSetDeviceInterface (
278 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
279 IN UINT16 InterfaceNo
,
280 IN UINT16 AltSetting
,
285 // Get device configuration
288 UsbGetDeviceConfiguration (
289 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
290 OUT UINT8
*ConfigValue
,
295 // Set device configuration
298 UsbSetDeviceConfiguration (
299 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
305 // Set Device Feature
308 UsbSetDeviceFeature (
309 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
310 IN EFI_USB_RECIPIENT Recipient
,
317 // Clear Device Feature
320 UsbClearDeviceFeature (
321 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
322 IN EFI_USB_RECIPIENT Recipient
,
333 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
334 IN EFI_USB_RECIPIENT Recipient
,
336 OUT UINT16
*DevStatus
,
341 // The following APIs are not basic library, but they are common used.
348 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
357 // Clear endpoint stall
360 UsbClearEndpointHalt (
361 IN EFI_USB_IO_PROTOCOL
*UsbIo
,