1 #ifndef _IUSB_H_
2 
3 /* Standard USB protocol defines */
4 
5 /*
6  * Copyright 2013 Graeme W. Gill
7  * All rights reserved.
8  *
9  * This material is licenced under the GNU GENERAL PUBLIC LICENSE Version 2 or later :-
10  * see the License2.txt file for licencing details.
11  */
12 
13 #ifdef __cplusplus
14 	extern "C" {
15 #endif
16 
17 /* Device and/or Interface Class codes */
18 #define IUSB_CLASS_PER_INTERFACE     0x00    /* for DeviceClass */
19 #define IUSB_CLASS_AUDIO             0x01
20 #define IUSB_CLASS_COMM              0x02
21 #define IUSB_CLASS_HID               0x03
22 #define IUSB_CLASS_PHYSICAL          0x05
23 #define IUSB_CLASS_STILL_IMAGE       0x06
24 #define IUSB_CLASS_PRINTER           0x07
25 #define IUSB_CLASS_MASS_STORAGE      0x08
26 #define IUSB_CLASS_HUB               0x09
27 #define IUSB_CLASS_CDC_DATA          0x0a
28 #define IUSB_CLASS_SMART_CARD        0x0b
29 #define IUSB_CLASS_CONT_SECURITY     0x0d
30 #define IUSB_CLASS_VIDEO             0x0e
31 #define IUSB_CLASS_DIAGNOSTIC        0xdc
32 #define IUSB_CLASS_WIRELESS          0xe0
33 #define IUSB_CLASS_MISC              0xef
34 #define IUSB_CLASS_APP_SPEC          0xfe
35 #define IUSB_CLASS_VENDOR_SPEC       0xff
36 
37 
38 /* Standard Descriptor types */
39 #define IUSB_DESC_TYPE_DEVICE                0x01
40 #define IUSB_DESC_TYPE_CONFIG                0x02
41 #define IUSB_DESC_TYPE_STRING                0x03
42 #define IUSB_DESC_TYPE_INTERFACE             0x04
43 #define IUSB_DESC_TYPE_ENDPOINT              0x05
44 #define IUSB_DESC_TYPE_DEVICE_QUALIFIER      0x06
45 #define IUSB_DESC_TYPE_OTHER_SPEED_CONFIG    0x07
46 #define IUSB_DESC_TYPE_INTERFACE_POWER       0x08
47 #define IUSB_DESC_TYPE_OTG                   0x09
48 #define IUSB_DESC_TYPE_DEBUG                 0x0a
49 #define IUSB_DESC_TYPE_INTERFACE_ASSOCIATION 0x0b
50 
51 /* Descriptor sizes per descriptor type */
52 #define IUSB_DESC_TYPE_DEVICE_SIZE           18
53 #define IUSB_DESC_TYPE_CONFIG_SIZE           9
54 #define IUSB_DESC_TYPE_INTERFACE_SIZE        9
55 #define IUSB_DESC_TYPE_ENDPOINT_SIZE         7
56 
57 /* Endpoint descriptor bEndpointAddress */
58 #define IUSB_ENDPOINT_NUM_MASK         0x0f
59 #define IUSB_ENDPOINT_DIR_MASK         0x80
60 #define IUSB_ENDPOINT_DIR_SHIFT        7
61 #define IUSB_ENDPOINT_IN               0x80
62 #define IUSB_ENDPOINT_OUT              0x00
63 
64 /* Endpoint descriptor bmAttributes */
65 #define IUSB_ENDPOINT_TYPE_MASK        0x03
66 #define IUSB_ENDPOINT_TYPE_CONTROL     0x00
67 #define IUSB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
68 #define IUSB_ENDPOINT_TYPE_BULK        0x02
69 #define IUSB_ENDPOINT_TYPE_INTERRUPT   0x03
70 
71 #define IUSB_ENDPOINT_SYNC_MASK        0x0c
72 #define IUSB_ENDPOINT_SYNC_NONE        0x00
73 #define IUSB_ENDPOINT_SYNC_ASYNC       0x04
74 #define IUSB_ENDPOINT_SYNC_ADPT        0x08
75 #define IUSB_ENDPOINT_SYNC_SYNC        0x0c
76 
77 #define IUSB_ENDPOINT_USAGE_MASK       0x30
78 #define IUSB_ENDPOINT_USAGE_DATA       0x00
79 #define IUSB_ENDPOINT_USAGE_FEED       0x10
80 #define IUSB_ENDPOINT_USAGE_IMPL_FEED  0x20
81 
82 /* Endpoint descriptor wMaxPacketSize */
83 #define IUSB_ENDPOINT_MAX_PKTSZ_MASK   0x03ff
84 #define IUSB_ENDPOINT_MAX_XACTS_MASK   0x0c00
85 #define IUSB_ENDPOINT_MAX_XACTS_SHIFT  11
86 
87 /* OTG descriptor bmAttributes */
88 #define IUSB_OTG_SRP                   0x00
89 #define IUSB_OTG_HNP                   0x01
90 
91 /* Control request */
92 #define IUSB_REQ_HEADER_SIZE           8
93 
94 /* Request bmRequestType */
95 #define IUSB_REQ_HOST_TO_DEV           0x00
96 #define IUSB_REQ_DEV_TO_HOST           0x80
97 #define IUSB_REQ_DIR_MASK              0x80
98 
99 #define IUSB_REQ_TYPE_SHIFT           5
100 #define IUSB_REQ_TYPE_STANDARD        (0x00 << IUSB_REQ_TYPE_SHIFT)
101 #define IUSB_REQ_TYPE_CLASS           (0x01 << IUSB_REQ_TYPE_SHIFT)
102 #define IUSB_REQ_TYPE_VENDOR          (0x02 << IUSB_REQ_TYPE_SHIFT)
103 #define IUSB_REQ_TYPE_RESERVED        (0x03 << IUSB_REQ_TYPE_SHIFT)
104 #define IUSB_REQ_TYPE_MASK            (0x03 << IUSB_REQ_TYPE_SHIFT)
105 
106 #define IUSB_REQ_RECIP_DEVICE          0x00
107 #define IUSB_REQ_RECIP_INTERFACE       0x01
108 #define IUSB_REQ_RECIP_ENDPOINT        0x02
109 #define IUSB_REQ_RECIP_OTHER           0x03
110 #define IUSB_REQ_RECIP_MASK            0x1f
111 
112 /* Standard bRequest values */
113 #define IUSB_REQ_GET_STATUS            0x00
114 #define IUSB_REQ_CLEAR_FEATURE         0x01
115 #define IUSB_REQ_SET_FEATURE           0x03
116 #define IUSB_REQ_SET_ADDRESS           0x05
117 #define IUSB_REQ_GET_DESCRIPTOR        0x06
118 #define IUSB_REQ_SET_DESCRIPTOR        0x07
119 #define IUSB_REQ_GET_CONFIGURATION     0x08
120 #define IUSB_REQ_SET_CONFIGURATION     0x09
121 #define IUSB_REQ_GET_INTERFACE         0x0a
122 #define IUSB_REQ_SET_INTERFACE         0x0b
123 #define IUSB_REQ_SYNCH_FRAME           0x0c
124 
125 /* Feature selector */
126 #define IUSB_FEATURE_EP_HALT              0
127 #define IUSB_FEATURE_DEV_REMOTE_WAKEUP    1
128 
129 /* REQ_GET_STATUS return values */
130 #define IUSB_DEVICE_STATUS_SELFPWR        0x0001
131 #define IUSB_DEVICE_STATUS_REMOTE_WAKEUP  0x0002
132 #define IUSB_ENDPOINT_STATUS_HALT         0x0001
133 
134 #ifdef __cplusplus
135 	}
136 #endif
137 
138 #define _IUSB_H_
139 #endif /* _IUSB_H_ */
140