2 // Copyright (c) 2010, Peter Barrett
4 ** Permission to use, copy, modify, and/or distribute this software for
5 ** any purpose with or without fee is hereby granted, provided that the
6 ** above copyright notice and this permission notice appear in all copies.
8 ** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
9 ** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
10 ** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
11 ** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
12 ** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
13 ** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
14 ** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
23 #define CLEAR_FEATURE 1
26 #define GET_DESCRIPTOR 6
27 #define SET_DESCRIPTOR 7
28 #define GET_CONFIGURATION 8
29 #define SET_CONFIGURATION 9
30 #define GET_INTERFACE 10
31 #define SET_INTERFACE 11
35 #define REQUEST_HOSTTODEVICE 0x00
36 #define REQUEST_DEVICETOHOST 0x80
37 #define REQUEST_DIRECTION 0x80
39 #define REQUEST_STANDARD 0x00
40 #define REQUEST_CLASS 0x20
41 #define REQUEST_VENDOR 0x40
42 #define REQUEST_TYPE 0x60
44 #define REQUEST_DEVICE 0x00
45 #define REQUEST_INTERFACE 0x01
46 #define REQUEST_ENDPOINT 0x02
47 #define REQUEST_OTHER 0x03
48 #define REQUEST_RECIPIENT 0x03
50 #define REQUEST_DEVICETOHOST_CLASS_INTERFACE (REQUEST_DEVICETOHOST + REQUEST_CLASS + REQUEST_INTERFACE)
51 #define REQUEST_HOSTTODEVICE_CLASS_INTERFACE (REQUEST_HOSTTODEVICE + REQUEST_CLASS + REQUEST_INTERFACE)
55 #define CDC_SET_LINE_CODING 0x20
56 #define CDC_GET_LINE_CODING 0x21
57 #define CDC_SET_CONTROL_LINE_STATE 0x22
59 #define MSC_RESET 0xFF
60 #define MSC_GET_MAX_LUN 0xFE
62 #define HID_GET_REPORT 0x01
63 #define HID_GET_IDLE 0x02
64 #define HID_GET_PROTOCOL 0x03
65 #define HID_SET_REPORT 0x09
66 #define HID_SET_IDLE 0x0A
67 #define HID_SET_PROTOCOL 0x0B
71 #define USB_DEVICE_DESC_SIZE 18
72 #define USB_CONFIGUARTION_DESC_SIZE 9
73 #define USB_INTERFACE_DESC_SIZE 9
74 #define USB_ENDPOINT_DESC_SIZE 7
76 #define USB_DEVICE_DESCRIPTOR_TYPE 1
77 #define USB_CONFIGURATION_DESCRIPTOR_TYPE 2
78 #define USB_STRING_DESCRIPTOR_TYPE 3
79 #define USB_INTERFACE_DESCRIPTOR_TYPE 4
80 #define USB_ENDPOINT_DESCRIPTOR_TYPE 5
82 #define USB_DEVICE_CLASS_COMMUNICATIONS 0x02
83 #define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03
84 #define USB_DEVICE_CLASS_STORAGE 0x08
85 #define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF
87 #define USB_CONFIG_POWERED_MASK 0x40
88 #define USB_CONFIG_BUS_POWERED 0x80
89 #define USB_CONFIG_SELF_POWERED 0xC0
90 #define USB_CONFIG_REMOTE_WAKEUP 0x20
92 // bMaxPower in Configuration Descriptor
93 #define USB_CONFIG_POWER_MA(mA) ((mA)/2)
95 // bEndpointAddress in Endpoint Descriptor
96 #define USB_ENDPOINT_DIRECTION_MASK 0x80
97 #define USB_ENDPOINT_OUT(addr) ((addr) | 0x00)
98 #define USB_ENDPOINT_IN(addr) ((addr) | 0x80)
100 #define USB_ENDPOINT_TYPE_MASK 0x03
101 #define USB_ENDPOINT_TYPE_CONTROL 0x00
102 #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
103 #define USB_ENDPOINT_TYPE_BULK 0x02
104 #define USB_ENDPOINT_TYPE_INTERRUPT 0x03
106 #define TOBYTES(x) ((x) & 0xFF),(((x) >> 8) & 0xFF)
108 #define CDC_V1_10 0x0110
109 #define CDC_COMMUNICATION_INTERFACE_CLASS 0x02
111 #define CDC_CALL_MANAGEMENT 0x01
112 #define CDC_ABSTRACT_CONTROL_MODEL 0x02
113 #define CDC_HEADER 0x00
114 #define CDC_ABSTRACT_CONTROL_MANAGEMENT 0x02
115 #define CDC_UNION 0x06
116 #define CDC_CS_INTERFACE 0x24
117 #define CDC_CS_ENDPOINT 0x25
118 #define CDC_DATA_INTERFACE_CLASS 0x0A
120 #define MSC_SUBCLASS_SCSI 0x06
121 #define MSC_PROTOCOL_BULK_ONLY 0x50
123 #define HID_HID_DESCRIPTOR_TYPE 0x21
124 #define HID_REPORT_DESCRIPTOR_TYPE 0x22
125 #define HID_PHYSICAL_DESCRIPTOR_TYPE 0x23
131 u8 dtype; // 1 USB_DEVICE_DESCRIPTOR_TYPE
132 u16 usbVersion; // 0x200
136 u8 packetSize0; // Packet 0
139 u16 deviceVersion; // 0x100
143 u8 bNumConfigurations;
150 u16 clen; // total length
169 u8 interfaceSubClass;
172 } InterfaceDescriptor;
183 } EndpointDescriptor;
185 // Interface Association Descriptor
186 // Used to bind 2 interfaces together in CDC compostite device
199 // CDC CS interface descriptor
207 } CDCCSInterfaceDescriptor;
215 } CDCCSInterfaceDescriptor4;
224 } CMFunctionalDescriptor;
232 } ACMFunctionalDescriptor;
237 IADDescriptor iad; // Only needed on compound device
240 InterfaceDescriptor cif; //
241 CDCCSInterfaceDescriptor header;
242 CMFunctionalDescriptor callManagement; // Call Management
243 ACMFunctionalDescriptor controlManagement; // ACM
244 CDCCSInterfaceDescriptor functionalDescriptor; // CDC_UNION
245 EndpointDescriptor cifin;
248 InterfaceDescriptor dif;
249 EndpointDescriptor in;
250 EndpointDescriptor out;
255 InterfaceDescriptor msc;
256 EndpointDescriptor in;
257 EndpointDescriptor out;
265 u8 versionL; // 0x101
266 u8 versionH; // 0x101
268 u8 desctype; // 0x22 report
275 InterfaceDescriptor hid;
276 HIDDescDescriptor desc;
277 EndpointDescriptor in;
281 #define D_DEVICE(_class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs) \
282 { 18, 1, 0x200, _class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs }
284 #define D_CONFIG(_totalLength,_interfaces) \
285 { 9, 2, _totalLength,_interfaces, 1, 0, USB_CONFIG_BUS_POWERED, USB_CONFIG_POWER_MA(500) }
287 #define D_INTERFACE(_n,_numEndpoints,_class,_subClass,_protocol) \
288 { 9, 4, _n, 0, _numEndpoints, _class,_subClass, _protocol, 0 }
290 #define D_ENDPOINT(_addr,_attr,_packetSize, _interval) \
291 { 7, 5, _addr,_attr,_packetSize, _interval }
293 #define D_IAD(_firstInterface, _count, _class, _subClass, _protocol) \
294 { 8, 11, _firstInterface, _count, _class, _subClass, _protocol, 0 }
296 #define D_HIDREPORT(_descriptorLength) \
297 { 9, 0x21, 0x1, 0x1, 0, 1, 0x22, _descriptorLength, 0 }
299 #define D_CDCCS(_subtype,_d0,_d1) { 5, 0x24, _subtype, _d0, _d1 }
300 #define D_CDCCS4(_subtype,_d0) { 4, 0x24, _subtype, _d0 }