13#ifndef __USB_COMMON_H__
14#define __USB_COMMON_H__
22#define RT_DEBUG_USB 0x00
23#define USB_DYNAMIC 0x00
25#define USB_CLASS_DEVICE 0x00
26#define USB_CLASS_AUDIO 0x01
27#define USB_CLASS_CDC 0x02
28#define USB_CLASS_HID 0x03
29#define USB_CLASS_PHYSICAL 0x05
30#define USB_CLASS_IMAGE 0x06
31#define USB_CLASS_PRINTER 0x07
32#define USB_CLASS_MASS_STORAGE 0x08
33#define USB_CLASS_HUB 0x09
34#define USB_CLASS_CDC_DATA 0x0a
35#define USB_CLASS_SMART_CARD 0x0b
36#define USB_CLASS_SECURITY 0x0d
37#define USB_CLASS_VIDEO 0x0e
38#define USB_CLASS_HEALTHCARE 0x0f
39#define USB_CLASS_DIAG_DEVICE 0xdc
40#define USB_CLASS_WIRELESS 0xe0
41#define USB_CLASS_MISC 0xef
42#define USB_CLASS_APP_SPECIFIC 0xfe
43#define USB_CLASS_VEND_SPECIFIC 0xff
45#define USB_DESC_TYPE_DEVICE 0x01
46#define USB_DESC_TYPE_CONFIGURATION 0x02
47#define USB_DESC_TYPE_STRING 0x03
48#define USB_DESC_TYPE_INTERFACE 0x04
49#define USB_DESC_TYPE_ENDPOINT 0x05
50#define USB_DESC_TYPE_DEVICEQUALIFIER 0x06
51#define USB_DESC_TYPE_OTHERSPEED 0x07
52#define USB_DESC_TYPE_IAD 0x0b
53#define USB_DESC_TYPE_HID 0x21
54#define USB_DESC_TYPE_REPORT 0x22
55#define USB_DESC_TYPE_PHYSICAL 0x23
56#define USB_DESC_TYPE_HUB 0x29
58#define USB_DESC_LENGTH_DEVICE 0x12
59#define USB_DESC_LENGTH_CONFIG 0x9
60#define USB_DESC_LENGTH_IAD 0x8
61#define USB_DESC_LENGTH_STRING 0x4
62#define USB_DESC_LENGTH_INTERFACE 0x9
63#define USB_DESC_LENGTH_ENDPOINT 0x7
65#define USB_REQ_TYPE_STANDARD 0x00
66#define USB_REQ_TYPE_CLASS 0x20
67#define USB_REQ_TYPE_VENDOR 0x40
68#define USB_REQ_TYPE_MASK 0x60
70#define USB_REQ_TYPE_DIR_OUT 0x00
71#define USB_REQ_TYPE_DIR_IN 0x80
73#define USB_REQ_TYPE_DEVICE 0x00
74#define USB_REQ_TYPE_INTERFACE 0x01
75#define USB_REQ_TYPE_ENDPOINT 0x02
76#define USB_REQ_TYPE_OTHER 0x03
77#define USB_REQ_TYPE_RECIPIENT_MASK 0x1f
79#define USB_FEATURE_ENDPOINT_HALT 0x00
80#define USB_FEATURE_DEV_REMOTE_WAKEUP 0x01
81#define USB_FEATURE_TEST_MODE 0x02
83#define USB_REQ_GET_STATUS 0x00
84#define USB_REQ_CLEAR_FEATURE 0x01
85#define USB_REQ_SET_FEATURE 0x03
86#define USB_REQ_SET_ADDRESS 0x05
87#define USB_REQ_GET_DESCRIPTOR 0x06
88#define USB_REQ_SET_DESCRIPTOR 0x07
89#define USB_REQ_GET_CONFIGURATION 0x08
90#define USB_REQ_SET_CONFIGURATION 0x09
91#define USB_REQ_GET_INTERFACE 0x0A
92#define USB_REQ_SET_INTERFACE 0x0B
93#define USB_REQ_SYNCH_FRAME 0x0C
94#define USB_REQ_SET_ENCRYPTION 0x0D
95#define USB_REQ_GET_ENCRYPTION 0x0E
96#define USB_REQ_RPIPE_ABORT 0x0E
97#define USB_REQ_SET_HANDSHAKE 0x0F
98#define USB_REQ_RPIPE_RESET 0x0F
99#define USB_REQ_GET_HANDSHAKE 0x10
100#define USB_REQ_SET_CONNECTION 0x11
101#define USB_REQ_SET_SECURITY_DATA 0x12
102#define USB_REQ_GET_SECURITY_DATA 0x13
103#define USB_REQ_SET_WUSB_DATA 0x14
104#define USB_REQ_LOOPBACK_DATA_WRITE 0x15
105#define USB_REQ_LOOPBACK_DATA_READ 0x16
106#define USB_REQ_SET_INTERFACE_DS 0x17
108#define USB_STRING_LANGID_INDEX 0x00
109#define USB_STRING_MANU_INDEX 0x01
110#define USB_STRING_PRODUCT_INDEX 0x02
111#define USB_STRING_SERIAL_INDEX 0x03
112#define USB_STRING_CONFIG_INDEX 0x04
113#define USB_STRING_INTERFACE_INDEX 0x05
114#define USB_STRING_OS_INDEX 0x06
115#define USB_STRING_MAX 0xff
117#define USB_STRING_OS "MSFT100A"
119#define USB_PID_OUT 0x01
120#define USB_PID_ACK 0x02
121#define USB_PID_DATA0 0x03
122#define USB_PID_SOF 0x05
123#define USB_PID_IN 0x09
124#define USB_PID_NACK 0x0A
125#define USB_PID_DATA1 0x0B
126#define USB_PID_PRE 0x0C
127#define USB_PID_SETUP 0x0D
128#define USB_PID_STALL 0x0E
130#define USB_EP_DESC_OUT 0x00
131#define USB_EP_DESC_IN 0x80
132#define USB_EP_DESC_NUM_MASK 0x0f
134#define USB_EP_ATTR_CONTROL 0x00
135#define USB_EP_ATTR_ISOC 0x01
136#define USB_EP_ATTR_BULK 0x02
137#define USB_EP_ATTR_INT 0x03
138#define USB_EP_ATTR_TYPE_MASK 0x03
140#define USB_EPNO_MASK 0x7f
141#define USB_DIR_OUT 0x00
142#define USB_DIR_IN 0x80
143#define USB_DIR_INOUT 0x40
144#define USB_DIR_MASK 0x80
146#define ID_UNASSIGNED 0
149#define RH_GET_PORT_STATUS 0
150#define RH_SET_PORT_STATUS 1
151#define RH_CLEAR_PORT_FEATURE 2
152#define RH_SET_PORT_FEATURE 3
154#define USB_BUS_POWERED 0
155#define USB_SELF_POWERED 1
156#define USB_REMOTE_WAKEUP 1
162#define PORT_FEAT_CONNECTION 0
163#define PORT_FEAT_ENABLE 1
164#define PORT_FEAT_SUSPEND 2
165#define PORT_FEAT_OVER_CURRENT 3
166#define PORT_FEAT_RESET 4
167#define PORT_FEAT_POWER 8
168#define PORT_FEAT_LOWSPEED 9
169#define PORT_FEAT_HIGHSPEED 10
170#define PORT_FEAT_C_CONNECTION 16
171#define PORT_FEAT_C_ENABLE 17
172#define PORT_FEAT_C_SUSPEND 18
173#define PORT_FEAT_C_OVER_CURRENT 19
174#define PORT_FEAT_C_RESET 20
185#define PORT_CCS 0x00000001UL
186#define PORT_PES 0x00000002UL
187#define PORT_PSS 0x00000004UL
188#define PORT_POCI 0x00000008UL
189#define PORT_PRS 0x00000010UL
190#define PORT_PPS 0x00000100UL
191#define PORT_LSDA 0x00000200UL
192#define PORT_CCSC 0x00010000UL
193#define PORT_PESC 0x00020000UL
194#define PORT_PSSC 0x00040000UL
195#define PORT_POCIC 0x00080000UL
196#define PORT_PRSC 0x00100000UL
201#define HUB_STATUS_LOCAL_POWER 0x0001
202#define HUB_STATUS_OVERCURRENT 0x0002
204#define HUB_CHANGE_LOCAL_POWER 0x0001
205#define HUB_CHANGE_OVERCURRENT 0x0002
207#define USB_EP_ATTR(attr) (attr & USB_EP_ATTR_TYPE_MASK)
208#define USB_EP_DESC_NUM(addr) (addr & USB_EP_DESC_NUM_MASK)
209#define USB_EP_DIR(addr) ((addr & USB_DIR_MASK)>>7)
211#define HID_REPORT_ID_KEYBOARD1 1
212#define HID_REPORT_ID_KEYBOARD2 2
213#define HID_REPORT_ID_KEYBOARD3 3
214#define HID_REPORT_ID_KEYBOARD4 7
215#define HID_REPORT_ID_MEDIA 4
216#define HID_REPORT_ID_GENERAL 5
217#define HID_REPORT_ID_MOUSE 6
222#ifndef USB_TIMEOUT_BASIC
223#define USB_TIMEOUT_BASIC (RT_TICK_PER_SECOND)
225#ifndef USB_TIMEOUT_LONG
226#define USB_TIMEOUT_LONG (RT_TICK_PER_SECOND * 5)
228#ifndef USB_DEBOUNCE_TIME
229#define USB_DEBOUNCE_TIME (RT_TICK_PER_SECOND / 5)
233 ((((x) & 0xff000000) >> 24) | \
234 (((x) & 0x00ff0000) >> 8) | \
235 (((x) & 0x0000ff00) << 8) | \
236 (((x) & 0x000000ff) << 24))
239 (((rt_uint16_t)(*((rt_uint8_t *)(x)))) + \
240 (((rt_uint16_t)(*(((rt_uint8_t *)(x)) + 1))) << 8))
420#define USB_OS_PROPERTY_TYPE_REG_SZ 0x01UL
421#define USB_OS_PROPERTY_TYPE_REG_EXPAND_SZ 0x02UL
422#define USB_OS_PROPERTY_TYPE_REG_BINARY 0x03UL
423#define USB_OS_PROPERTY_TYPE_REG_DWORD_LITTLE_ENDIAN 0x04UL
424#define USB_OS_PROPERTY_TYPE_REG_DWORD_BIG_ENDIAN 0x05UL
425#define USB_OS_PROPERTY_TYPE_REG_LINK 0x06UL
426#define USB_OS_PROPERTY_TYPE_REG_MULTI_SZ 0x07UL
428#define USB_OS_PROPERTY_DESC(PropertyDataType,PropertyName,PropertyData) \
430 .dwSize = sizeof(struct usb_os_proerty)-sizeof(const char *)*2\
431 +sizeof(PropertyName)*2+sizeof(PropertyData)*2,\
432 .dwPropertyDataType = PropertyDataType,\
433 .wPropertyNameLength = sizeof(PropertyName)*2,\
434 .bPropertyName = PropertyName,\
435 .dwPropertyDataLength = sizeof(PropertyData)*2,\
436 .bPropertyData = PropertyData\
440#ifndef HID_SUB_DESCRIPTOR_MAX
441#define HID_SUB_DESCRIPTOR_MAX 1
479#define MIN(a, b) (a < b ? a : b)
482#define MAX(a, b) (a > b ? a : b)
488#define USBREQ_GET_MAX_LUN 0xfe
489#define USBREQ_MASS_STORAGE_RESET 0xff
491#define SIZEOF_CSW 0x0d
492#define SIZEOF_CBW 0x1f
493#define SIZEOF_INQUIRY_CMD 0x24
494#define SIZEOF_MODE_SENSE_6 0x4
495#define SIZEOF_READ_CAPACITIES 0xc
496#define SIZEOF_READ_CAPACITY 0x8
497#define SIZEOF_REQUEST_SENSE 0x12
499#define CBWFLAGS_DIR_M 0x80
500#define CBWFLAGS_DIR_IN 0x80
501#define CBWFLAGS_DIR_OUT 0x00
503#define SCSI_TEST_UNIT_READY 0x00
504#define SCSI_REQUEST_SENSE 0x03
505#define SCSI_INQUIRY_CMD 0x12
506#define SCSI_ALLOW_REMOVAL 0x1e
507#define SCSI_MODE_SENSE_6 0x1a
508#define SCSI_START_STOP 0x1b
509#define SCSI_READ_CAPACITIES 0x23
510#define SCSI_READ_CAPACITY 0x25
511#define SCSI_READ_10 0x28
512#define SCSI_WRITE_10 0x2a
513#define SCSI_VERIFY_10 0x2f
515#define CBW_SIGNATURE 0x43425355
516#define CSW_SIGNATURE 0x53425355
517#define CBW_TAG_VALUE 0x12345678
564#ifndef RT_USBD_THREAD_STACK_SZ
565#define RT_USBD_THREAD_STACK_SZ 512
569#ifndef RT_USBD_THREAD_PRIO
570#define RT_USBD_THREAD_PRIO 8
unsigned short rt_uint16_t
struct rt_list_node rt_list_t
rt_uint8_t bConfigurationValue
rt_uint8_t iConfiguration
rt_uint8_t bNumInterfaces
rt_uint8_t bNumConfigurations
rt_uint8_t bDeviceSubClass
rt_uint8_t bDeviceProtocol
rt_uint8_t bMaxPacketSize0
rt_uint8_t bEndpointAddress
rt_uint16_t wMaxPacketSize
rt_uint8_t bNumDescriptors
struct uhid_descriptor::hid_descriptor_list Descriptor[HID_SUB_DESCRIPTOR_MAX]
rt_uint16_t characteristics
rt_uint8_t bInterfaceCount
rt_uint8_t bFunctionSubClass
rt_uint8_t bFirstInterface
rt_uint8_t bDescriptorType
rt_uint8_t bFunctionClass
rt_uint8_t bFunctionProtocol
rt_uint8_t bInterfaceSubClass
rt_uint8_t bInterfaceProtocol
rt_uint8_t bInterfaceNumber
rt_uint8_t bInterfaceClass
rt_uint8_t bAlternateSetting
struct usb_os_header_comp_id_descriptor head_desc
rt_uint8_t bFirstInterfaceNumber
rt_uint8_t compatibleID[8]
rt_uint8_t subCompatibleID[8]
rt_uint32_t dwPropertyDataType
const char * bPropertyData
rt_uint32_t dwPropertyDataLength
const char * bPropertyName
rt_uint16_t wPropertyNameLength
rt_uint8_t bDescriptorType
rt_uint8_t bDeviceSubClass
rt_uint8_t bMaxPacketSize0
rt_uint8_t bDeviceProtocol
rt_uint8_t bNumConfigurations
void HID_Report_Received(hid_report_t report)
#define HID_SUB_DESCRIPTOR_MAX
struct uhub_descriptor * uhub_desc_t
struct uiad_descriptor * uiad_desc_t
struct usb_os_comp_id_descriptor * usb_os_comp_id_desc_t
struct usb_os_proerty * usb_os_proerty_t
struct uinterface_descriptor * uintf_desc_t
struct udevice_descriptor * udev_desc_t
struct ustorage_csw * ustorage_csw_t
struct usb_os_header_comp_id_descriptor * usb_os_header_desc_t
void(* func_callback)(void *context)
struct usb_os_header_comp_id_descriptor __attribute__
struct uendpoint_descriptor * uep_desc_t
struct uhid_descriptor * uhid_desc_t
struct uconfig_descriptor * ucfg_desc_t
struct ustorage_cbw * ustorage_cbw_t
struct usb_os_property_header * usb_os_property_header_t
@ USB_STATE_UNAUTHENTICATED
struct usb_os_function_comp_id_descriptor * usb_os_func_comp_id_desc_t
struct usb_descriptor * udesc_t
struct hid_report * hid_report_t
struct ustring_descriptor * ustr_desc_t