USBCore.h
Go to the documentation of this file.
1 
2 // Copyright (c) 2010, Peter Barrett
3 /*
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.
7 **
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
15 ** SOFTWARE.
16 */
17 
18 #ifndef __USBCORE_H__
19 #define __USBCORE_H__
20 
21 #include "USBAPI.h"
22 
23 // Standard requests
24 #define GET_STATUS 0
25 #define CLEAR_FEATURE 1
26 #define SET_FEATURE 3
27 #define SET_ADDRESS 5
28 #define GET_DESCRIPTOR 6
29 #define SET_DESCRIPTOR 7
30 #define GET_CONFIGURATION 8
31 #define SET_CONFIGURATION 9
32 #define GET_INTERFACE 10
33 #define SET_INTERFACE 11
34 
35 
36 // bmRequestType
37 #define REQUEST_HOSTTODEVICE 0x00
38 #define REQUEST_DEVICETOHOST 0x80
39 #define REQUEST_DIRECTION 0x80
40 
41 #define REQUEST_STANDARD 0x00
42 #define REQUEST_CLASS 0x20
43 #define REQUEST_VENDOR 0x40
44 #define REQUEST_TYPE 0x60
45 
46 #define REQUEST_DEVICE 0x00
47 #define REQUEST_INTERFACE 0x01
48 #define REQUEST_ENDPOINT 0x02
49 #define REQUEST_OTHER 0x03
50 #define REQUEST_RECIPIENT 0x03
51 
52 #define REQUEST_DEVICETOHOST_CLASS_INTERFACE (REQUEST_DEVICETOHOST | REQUEST_CLASS | REQUEST_INTERFACE)
53 #define REQUEST_HOSTTODEVICE_CLASS_INTERFACE (REQUEST_HOSTTODEVICE | REQUEST_CLASS | REQUEST_INTERFACE)
54 #define REQUEST_DEVICETOHOST_STANDARD_INTERFACE (REQUEST_DEVICETOHOST | REQUEST_STANDARD | REQUEST_INTERFACE)
55 
56 // Class requests
57 
58 #define CDC_SET_LINE_CODING 0x20
59 #define CDC_GET_LINE_CODING 0x21
60 #define CDC_SET_CONTROL_LINE_STATE 0x22
61 #define CDC_SEND_BREAK 0x23
62 
63 #define MSC_RESET 0xFF
64 #define MSC_GET_MAX_LUN 0xFE
65 
66 // Descriptors
67 
68 #define USB_DEVICE_DESC_SIZE 18
69 #define USB_CONFIGUARTION_DESC_SIZE 9
70 #define USB_INTERFACE_DESC_SIZE 9
71 #define USB_ENDPOINT_DESC_SIZE 7
72 
73 #define USB_DEVICE_DESCRIPTOR_TYPE 1
74 #define USB_CONFIGURATION_DESCRIPTOR_TYPE 2
75 #define USB_STRING_DESCRIPTOR_TYPE 3
76 #define USB_INTERFACE_DESCRIPTOR_TYPE 4
77 #define USB_ENDPOINT_DESCRIPTOR_TYPE 5
78 
79 // usb_20.pdf Table 9.6 Standard Feature Selectors
80 #define DEVICE_REMOTE_WAKEUP 1
81 #define ENDPOINT_HALT 2
82 #define TEST_MODE 3
83 
84 // usb_20.pdf Figure 9-4. Information Returned by a GetStatus() Request to a Device
85 #define FEATURE_SELFPOWERED_ENABLED (1 << 0)
86 #define FEATURE_REMOTE_WAKEUP_ENABLED (1 << 1)
87 
88 #define USB_DEVICE_CLASS_COMMUNICATIONS 0x02
89 #define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03
90 #define USB_DEVICE_CLASS_STORAGE 0x08
91 #define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF
92 
93 #define USB_CONFIG_POWERED_MASK 0x40
94 #define USB_CONFIG_BUS_POWERED 0x80
95 #define USB_CONFIG_SELF_POWERED 0xC0
96 #define USB_CONFIG_REMOTE_WAKEUP 0x20
97 
98 // bMaxPower in Configuration Descriptor
99 #define USB_CONFIG_POWER_MA(mA) ((mA)/2)
100 
101 // bEndpointAddress in Endpoint Descriptor
102 #define USB_ENDPOINT_DIRECTION_MASK 0x80
103 #define USB_ENDPOINT_OUT(addr) (lowByte((addr) | 0x00))
104 #define USB_ENDPOINT_IN(addr) (lowByte((addr) | 0x80))
105 
106 #define USB_ENDPOINT_TYPE_MASK 0x03
107 #define USB_ENDPOINT_TYPE_CONTROL 0x00
108 #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
109 #define USB_ENDPOINT_TYPE_BULK 0x02
110 #define USB_ENDPOINT_TYPE_INTERRUPT 0x03
111 
112 #define TOBYTES(x) ((x) & 0xFF),(((x) >> 8) & 0xFF)
113 
114 #define CDC_V1_10 0x0110
115 #define CDC_COMMUNICATION_INTERFACE_CLASS 0x02
116 
117 #define CDC_CALL_MANAGEMENT 0x01
118 #define CDC_ABSTRACT_CONTROL_MODEL 0x02
119 #define CDC_HEADER 0x00
120 #define CDC_ABSTRACT_CONTROL_MANAGEMENT 0x02
121 #define CDC_UNION 0x06
122 #define CDC_CS_INTERFACE 0x24
123 #define CDC_CS_ENDPOINT 0x25
124 #define CDC_DATA_INTERFACE_CLASS 0x0A
125 
126 #define MSC_SUBCLASS_SCSI 0x06
127 #define MSC_PROTOCOL_BULK_ONLY 0x50
128 
129 #ifndef USB_VERSION
130 #define USB_VERSION 0x200
131 #endif
132 
133 // Device
134 typedef struct {
135  u8 len; // 18
136  u8 dtype; // 1 USB_DEVICE_DESCRIPTOR_TYPE
137  u16 usbVersion; // 0x200 or 0x210
141  u8 packetSize0; // Packet 0
144  u16 deviceVersion; // 0x100
150 
151 // Config
152 typedef struct {
153  u8 len; // 9
154  u8 dtype; // 2
155  u16 clen; // total length
162 
163 // String
164 
165 // Interface
166 typedef struct
167 {
168  u8 len; // 9
169  u8 dtype; // 4
178 
179 // Endpoint
180 typedef struct
181 {
182  u8 len; // 7
183  u8 dtype; // 5
189 
190 // Interface Association Descriptor
191 // Used to bind 2 interfaces together in CDC compostite device
192 typedef struct
193 {
194  u8 len; // 8
195  u8 dtype; // 11
202 } IADDescriptor;
203 
204 // CDC CS interface descriptor
205 typedef struct
206 {
207  u8 len; // 5
208  u8 dtype; // 0x24
213 
214 typedef struct
215 {
216  u8 len; // 4
217  u8 dtype; // 0x24
221 
222 typedef struct
223 {
225  u8 dtype; // 0x24
226  u8 subtype; // 1
230 
231 typedef struct
232 {
234  u8 dtype; // 0x24
235  u8 subtype; // 1
238 
239 typedef struct
240 {
241  // IAD
242  IADDescriptor iad; // Only needed on compound device
243 
244  // Control
251 
252  // Data
256 } CDCDescriptor;
257 
258 typedef struct
259 {
263 } MSCDescriptor;
264 
265 
266 #define D_DEVICE(_class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs) \
267  { 18, 1, USB_VERSION, _class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs }
268 
269 #define D_CONFIG(_totalLength,_interfaces) \
270  { 9, 2, _totalLength,_interfaces, 1, 0, USB_CONFIG_BUS_POWERED | USB_CONFIG_REMOTE_WAKEUP, USB_CONFIG_POWER_MA(500) }
271 
272 #define D_INTERFACE(_n,_numEndpoints,_class,_subClass,_protocol) \
273  { 9, 4, _n, 0, _numEndpoints, _class,_subClass, _protocol, 0 }
274 
275 #define D_ENDPOINT(_addr,_attr,_packetSize, _interval) \
276  { 7, 5, _addr,_attr,_packetSize, _interval }
277 
278 #define D_IAD(_firstInterface, _count, _class, _subClass, _protocol) \
279  { 8, 11, _firstInterface, _count, _class, _subClass, _protocol, 0 }
280 
281 #define D_CDCCS(_subtype,_d0,_d1) { 5, 0x24, _subtype, _d0, _d1 }
282 #define D_CDCCS4(_subtype,_d0) { 4, 0x24, _subtype, _d0 }
283 
284 // Bootloader related fields
285 // Old Caterina bootloader places the MAGIC key into unsafe RAM locations (it can be rewritten
286 // by the running sketch before to actual reboot).
287 // Newer bootloaders, recognizable by the LUFA "signature" at the end of the flash, can handle both
288 // the usafe and the safe location. Check once (in USBCore.cpp) if the bootloader in new, then set the global
289 // _updatedLUFAbootloader variable to true/false and place the magic key consequently
290 #ifndef MAGIC_KEY
291 #define MAGIC_KEY 0x7777
292 #endif
293 
294 #ifndef MAGIC_KEY_POS
295 #define MAGIC_KEY_POS 0x0800
296 #endif
297 
298 #ifndef NEW_LUFA_SIGNATURE
299 #define NEW_LUFA_SIGNATURE 0xDCFB
300 #endif
301 
302 #endif
InterfaceDescriptor dif
Definition: USBCore.h:253
CDCCSInterfaceDescriptor functionalDescriptor
Definition: USBCore.h:249
unsigned short u16
Definition: USBAPI.h:30
EndpointDescriptor in
Definition: USBCore.h:254
u8 functionProtocol
Definition: USBCore.h:200
EndpointDescriptor out
Definition: USBCore.h:262
u8 funtionSubClass
Definition: USBCore.h:199
CMFunctionalDescriptor callManagement
Definition: USBCore.h:247
IADDescriptor iad
Definition: USBCore.h:242
EndpointDescriptor out
Definition: USBCore.h:255
ACMFunctionalDescriptor controlManagement
Definition: USBCore.h:248
EndpointDescriptor cifin
Definition: USBCore.h:250
unsigned char u8
Definition: USBAPI.h:29
u8 interfaceCount
Definition: USBCore.h:197
u8 functionClass
Definition: USBCore.h:198
InterfaceDescriptor cif
Definition: USBCore.h:245
EndpointDescriptor in
Definition: USBCore.h:261
CDCCSInterfaceDescriptor header
Definition: USBCore.h:246
u8 firstInterface
Definition: USBCore.h:196
InterfaceDescriptor msc
Definition: USBCore.h:260
u8 bNumConfigurations
Definition: USBCore.h:148


arduino_daq
Author(s):
autogenerated on Mon Jun 10 2019 12:46:03