]> git.sur5r.net Git - armstart-ibdap/blob - inc/usbd/usbd.h
initial commit
[armstart-ibdap] / inc / usbd / usbd.h
1 /***********************************************************************\r
2 * $Id:: mw_usbd.h 575 2012-11-20 01:35:56Z usb10131                           $\r
3 *\r
4 * Project: USB device ROM Stack\r
5 *\r
6 * Description:\r
7 *     USB Definitions.\r
8 *\r
9 ***********************************************************************\r
10 *   Copyright(C) 2011, NXP Semiconductor\r
11 *   All rights reserved.\r
12 *\r
13 * Software that is described herein is for illustrative purposes only\r
14 * which provides customers with programming information regarding the\r
15 * products. This software is supplied "AS IS" without any warranties.\r
16 * NXP Semiconductors assumes no responsibility or liability for the\r
17 * use of the software, conveys no license or title under any patent,\r
18 * copyright, or mask work right to the product. NXP Semiconductors\r
19 * reserves the right to make changes in the software without\r
20 * notification. NXP Semiconductors also make no representation or\r
21 * warranty that such application will be suitable for the specified\r
22 * use without further testing or modification.\r
23 **********************************************************************/\r
24 \r
25 #ifndef __USBD_H__\r
26 #define __USBD_H__\r
27 \r
28 /** \file\r
29  *  \brief Common definitions and declarations for the USB stack.\r
30  *\r
31  *  Common definitions and declarations for the USB stack.\r
32  *  \addtogroup USBD_Core \r
33  *  @{\r
34  */\r
35 \r
36 #include "lpc_types.h"\r
37 \r
38 #if defined(__GNUC__)\r
39 /* As per http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html#Attribute-Syntax,\r
40 6.29 Attributes Syntax\r
41 "An attribute specifier list may appear as part of a struct, union or\r
42 enum specifier. It may go either immediately after the struct, union\r
43 or enum keyword, or after the closing brace. The former syntax is\r
44 preferred. Where attribute specifiers follow the closing brace, they\r
45 are considered to relate to the structure, union or enumerated type\r
46 defined, not to any enclosing declaration the type specifier appears\r
47 in, and the type defined is not complete until after the attribute\r
48 specifiers."\r
49 So use POST_PACK immediately after struct keyword\r
50 */\r
51 #define PRE_PACK\r
52 #define POST_PACK       __attribute__((__packed__))\r
53 #define ALIGNED(n)      __attribute__((aligned (n)))\r
54 \r
55 #elif defined(__arm)\r
56 #define PRE_PACK        __packed\r
57 #define POST_PACK\r
58 #define ALIGNED(n)      __align(n)\r
59 \r
60 #elif defined(__ICCARM__)\r
61 #define PRE_PACK                __packed\r
62 #define POST_PACK\r
63 #define PRAGMA_ALIGN_4096       _Pragma("data_alignment=4096")\r
64 #define PRAGMA_ALIGN_2048       _Pragma("data_alignment=2048")\r
65 #define PRAGMA_ALIGN_256        _Pragma("data_alignment=256")\r
66 #define PRAGMA_ALIGN_128        _Pragma("data_alignment=128")\r
67 #define PRAGMA_ALIGN_64         _Pragma("data_alignment=64")\r
68 #define PRAGMA_ALIGN_48         _Pragma("data_alignment=48")\r
69 #define PRAGMA_ALIGN_32         _Pragma("data_alignment=32")\r
70 #define PRAGMA_ALIGN_4          _Pragma("data_alignment=4")\r
71 #define ALIGNED(n)              PRAGMA_ALIGN_##n\r
72 \r
73 #pragma diag_suppress=Pe021\r
74 #endif\r
75 \r
76 /** Structure to pack lower and upper byte to form 16 bit word. */\r
77 PRE_PACK struct POST_PACK _WB_T\r
78 {\r
79   uint8_t L; /**< lower byte */\r
80   uint8_t H; /**< upper byte */\r
81 };\r
82 /** Structure to pack lower and upper byte to form 16 bit word.*/\r
83 typedef struct _WB_T WB_T;\r
84 \r
85 /** Union of \ref _WB_T struct and 16 bit word.*/\r
86 PRE_PACK union POST_PACK __WORD_BYTE\r
87 {\r
88   uint16_t W; /**< data member to do 16 bit access */\r
89   WB_T WB; /**< data member to do 8 bit access */\r
90 } ;\r
91 /** Union of \ref _WB_T struct and 16 bit word.*/\r
92 typedef union __WORD_BYTE WORD_BYTE;\r
93 \r
94 /** bmRequestType.Dir defines \r
95  * @{ \r
96  */\r
97 /** Request from host to device */\r
98 #define REQUEST_HOST_TO_DEVICE     0\r
99 /** Request from device to host */\r
100 #define REQUEST_DEVICE_TO_HOST     1\r
101 /** @} */\r
102 \r
103 /** bmRequestType.Type defines  \r
104  * @{ \r
105  */\r
106 /** Standard Request */\r
107 #define REQUEST_STANDARD           0\r
108 /** Class Request */\r
109 #define REQUEST_CLASS              1\r
110 /** Vendor Request */\r
111 #define REQUEST_VENDOR             2\r
112 /** Reserved Request */\r
113 #define REQUEST_RESERVED           3\r
114 /** @} */\r
115 \r
116 /** bmRequestType.Recipient defines  \r
117  * @{ \r
118  */\r
119 /** Request to device */\r
120 #define REQUEST_TO_DEVICE          0\r
121 /** Request to interface */\r
122 #define REQUEST_TO_INTERFACE       1\r
123 /** Request to endpoint */\r
124 #define REQUEST_TO_ENDPOINT        2\r
125 /** Request to other */\r
126 #define REQUEST_TO_OTHER           3\r
127 /** @} */\r
128 \r
129 /** Structure to define 8 bit USB request.*/\r
130 PRE_PACK struct POST_PACK _BM_T\r
131 {\r
132   uint8_t Recipient :  5; /**< Recipient type. */\r
133   uint8_t Type      :  2; /**< Request type.  */\r
134   uint8_t Dir       :  1; /**< Direction type. */\r
135 };\r
136 /** Structure to define 8 bit USB request.*/\r
137 typedef struct _BM_T BM_T;\r
138 \r
139 /** Union of \ref _BM_T struct and 8 bit byte.*/\r
140 PRE_PACK union POST_PACK _REQUEST_TYPE\r
141 {\r
142   uint8_t B; /**< byte wide access memeber */\r
143   BM_T BM;   /**< bitfield structure access memeber */\r
144 } ;\r
145 /** Union of \ref _BM_T struct and 8 bit byte.*/\r
146 typedef union _REQUEST_TYPE REQUEST_TYPE;\r
147 \r
148 /** USB Standard Request Codes \r
149  * @{ \r
150  */\r
151 /** GET_STATUS request */\r
152 #define USB_REQUEST_GET_STATUS                 0\r
153 /** CLEAR_FEATURE request */\r
154 #define USB_REQUEST_CLEAR_FEATURE              1\r
155 /** SET_FEATURE request */\r
156 #define USB_REQUEST_SET_FEATURE                3\r
157 /** SET_ADDRESS request */\r
158 #define USB_REQUEST_SET_ADDRESS                5\r
159 /** GET_DESCRIPTOR request */\r
160 #define USB_REQUEST_GET_DESCRIPTOR             6\r
161 /** SET_DESCRIPTOR request */\r
162 #define USB_REQUEST_SET_DESCRIPTOR             7\r
163 /** GET_CONFIGURATION request */\r
164 #define USB_REQUEST_GET_CONFIGURATION          8\r
165 /** SET_CONFIGURATION request */\r
166 #define USB_REQUEST_SET_CONFIGURATION          9\r
167 /** GET_INTERFACE request */\r
168 #define USB_REQUEST_GET_INTERFACE              10\r
169 /** SET_INTERFACE request */\r
170 #define USB_REQUEST_SET_INTERFACE              11\r
171 /** SYNC_FRAME request */\r
172 #define USB_REQUEST_SYNC_FRAME                 12\r
173 /** @} */\r
174 \r
175 /** USB GET_STATUS Bit Values \r
176  * @{ \r
177  */\r
178 /** SELF_POWERED status*/\r
179 #define USB_GETSTATUS_SELF_POWERED             0x01\r
180 /** REMOTE_WAKEUP capable status*/\r
181 #define USB_GETSTATUS_REMOTE_WAKEUP            0x02\r
182 /** ENDPOINT_STALL status*/\r
183 #define USB_GETSTATUS_ENDPOINT_STALL           0x01\r
184 /** @} */\r
185 \r
186 /** USB Standard Feature selectors \r
187  * @{ \r
188  */\r
189 /** ENDPOINT_STALL feature*/\r
190 #define USB_FEATURE_ENDPOINT_STALL             0\r
191 /** REMOTE_WAKEUP feature*/\r
192 #define USB_FEATURE_REMOTE_WAKEUP              1\r
193 /** TEST_MODE feature*/\r
194 #define USB_FEATURE_TEST_MODE                  2\r
195 /** @} */\r
196 \r
197 /** USB Default Control Pipe Setup Packet*/\r
198 PRE_PACK struct POST_PACK _USB_SETUP_PACKET\r
199 {\r
200   REQUEST_TYPE bmRequestType; /**< This bitmapped field identifies the characteristics\r
201                               of the specific request. \sa _BM_T.\r
202                               */\r
203   uint8_t      bRequest; /**< This field specifies the particular request. The \r
204                          Type bits in the bmRequestType field modify the meaning \r
205                          of this field. \sa USBD_REQUEST.\r
206                          */\r
207   WORD_BYTE    wValue; /**< Used to pass a parameter to the device, specific\r
208                         to the request.\r
209                         */\r
210   WORD_BYTE    wIndex; /**< Used to pass a parameter to the device, specific\r
211                         to the request. The wIndex field is often used in \r
212                         requests to specify an endpoint or an interface.\r
213                         */\r
214   uint16_t     wLength; /**< This field specifies the length of the data \r
215                         transferred during the second phase of the control \r
216                         transfer.\r
217                         */\r
218 } ;\r
219 /** USB Default Control Pipe Setup Packet*/\r
220 typedef struct _USB_SETUP_PACKET USB_SETUP_PACKET;\r
221 \r
222 \r
223 /** USB Descriptor Types \r
224  * @{ \r
225  */\r
226 /** Device descriptor type  */\r
227 #define USB_DEVICE_DESCRIPTOR_TYPE             1\r
228 /** Configuration descriptor type  */\r
229 #define USB_CONFIGURATION_DESCRIPTOR_TYPE      2\r
230 /** String descriptor type  */\r
231 #define USB_STRING_DESCRIPTOR_TYPE             3\r
232 /** Interface descriptor type  */\r
233 #define USB_INTERFACE_DESCRIPTOR_TYPE          4\r
234 /** Endpoint descriptor type  */\r
235 #define USB_ENDPOINT_DESCRIPTOR_TYPE           5\r
236 /** Device qualifier descriptor type  */\r
237 #define USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE   6\r
238 /** Other speed configuration descriptor type  */\r
239 #define USB_OTHER_SPEED_CONFIG_DESCRIPTOR_TYPE 7\r
240 /** Interface power descriptor type  */\r
241 #define USB_INTERFACE_POWER_DESCRIPTOR_TYPE    8\r
242 /** OTG descriptor type  */\r
243 #define USB_OTG_DESCRIPTOR_TYPE                     9\r
244 /** Debug descriptor type  */\r
245 #define USB_DEBUG_DESCRIPTOR_TYPE                  10\r
246 /** Interface association descriptor type  */\r
247 #define USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE  11\r
248 /** @} */\r
249 \r
250 /** USB Device Classes \r
251  * @{ \r
252  */\r
253 /** Reserved device class  */\r
254 #define USB_DEVICE_CLASS_RESERVED              0x00\r
255 /** Audio device class  */\r
256 #define USB_DEVICE_CLASS_AUDIO                 0x01\r
257 /** Communications device class  */\r
258 #define USB_DEVICE_CLASS_COMMUNICATIONS        0x02\r
259 /** Human interface device class  */\r
260 #define USB_DEVICE_CLASS_HUMAN_INTERFACE       0x03\r
261 /** monitor device class  */\r
262 #define USB_DEVICE_CLASS_MONITOR               0x04\r
263 /** physical interface device class  */\r
264 #define USB_DEVICE_CLASS_PHYSICAL_INTERFACE    0x05\r
265 /** power device class  */\r
266 #define USB_DEVICE_CLASS_POWER                 0x06\r
267 /** Printer device class  */\r
268 #define USB_DEVICE_CLASS_PRINTER               0x07\r
269 /** Storage device class  */\r
270 #define USB_DEVICE_CLASS_STORAGE               0x08\r
271 /** Hub device class  */\r
272 #define USB_DEVICE_CLASS_HUB                   0x09\r
273 /** miscellaneous device class  */\r
274 #define USB_DEVICE_CLASS_MISCELLANEOUS         0xEF\r
275 /** Application device class  */\r
276 #define USB_DEVICE_CLASS_APP                   0xFE\r
277 /** Vendor specific device class  */\r
278 #define USB_DEVICE_CLASS_VENDOR_SPECIFIC       0xFF\r
279 /** @} */\r
280 \r
281 /** bmAttributes in Configuration Descriptor \r
282  * @{ \r
283  */\r
284 /** Power field mask */\r
285 #define USB_CONFIG_POWERED_MASK                0x40\r
286 /** Bus powered */\r
287 #define USB_CONFIG_BUS_POWERED                 0x80\r
288 /** Self powered */\r
289 #define USB_CONFIG_SELF_POWERED                0xC0\r
290 /** remote wakeup */\r
291 #define USB_CONFIG_REMOTE_WAKEUP               0x20\r
292 /** @} */\r
293 \r
294 /** bMaxPower in Configuration Descriptor */\r
295 #define USB_CONFIG_POWER_MA(mA)                ((mA)/2)\r
296 \r
297 /** bEndpointAddress in Endpoint Descriptor \r
298  * @{ \r
299  */\r
300 /** Endopint address mask */\r
301 #define USB_ENDPOINT_DIRECTION_MASK            0x80\r
302 /** Macro to convert OUT endopint number to endpoint address value. */\r
303 #define USB_ENDPOINT_OUT(addr)                 ((addr) | 0x00)\r
304 /** Macro to convert IN endopint number to endpoint address value. */\r
305 #define USB_ENDPOINT_IN(addr)                  ((addr) | 0x80)\r
306 /** @} */\r
307 \r
308 /** bmAttributes in Endpoint Descriptor \r
309  * @{ \r
310  */\r
311 /** Endopint type mask */\r
312 #define USB_ENDPOINT_TYPE_MASK                 0x03\r
313 /** Control Endopint type */\r
314 #define USB_ENDPOINT_TYPE_CONTROL              0x00\r
315 /** isochronous Endopint type */\r
316 #define USB_ENDPOINT_TYPE_ISOCHRONOUS          0x01\r
317 /** bulk Endopint type */\r
318 #define USB_ENDPOINT_TYPE_BULK                 0x02\r
319 /** interrupt Endopint type */\r
320 #define USB_ENDPOINT_TYPE_INTERRUPT            0x03\r
321 /** Endopint sync type mask */\r
322 #define USB_ENDPOINT_SYNC_MASK                 0x0C\r
323 /** no synchronization Endopint */\r
324 #define USB_ENDPOINT_SYNC_NO_SYNCHRONIZATION   0x00\r
325 /** Asynchronous sync Endopint */\r
326 #define USB_ENDPOINT_SYNC_ASYNCHRONOUS         0x04\r
327 /** Adaptive sync Endopint */\r
328 #define USB_ENDPOINT_SYNC_ADAPTIVE             0x08\r
329 /** Synchronous sync Endopint */\r
330 #define USB_ENDPOINT_SYNC_SYNCHRONOUS          0x0C\r
331 /** Endopint usage type mask */\r
332 #define USB_ENDPOINT_USAGE_MASK                0x30\r
333 /** Endopint data usage type  */\r
334 #define USB_ENDPOINT_USAGE_DATA                0x00\r
335 /** Endopint feedback usage type  */\r
336 #define USB_ENDPOINT_USAGE_FEEDBACK            0x10\r
337 /** Endopint implicit feedback usage type  */\r
338 #define USB_ENDPOINT_USAGE_IMPLICIT_FEEDBACK   0x20\r
339 /** Endopint reserved usage type  */\r
340 #define USB_ENDPOINT_USAGE_RESERVED            0x30\r
341 /** @} */\r
342 \r
343 /** Control endopint EP0's maximum packet size in high-speed mode.*/\r
344 #define USB_ENDPOINT_0_HS_MAXP                 64\r
345 /** Control endopint EP0's maximum packet size in low-speed mode.*/\r
346 #define USB_ENDPOINT_0_LS_MAXP                 8\r
347 /** Bulk endopint's maximum packet size in high-speed mode.*/\r
348 #define USB_ENDPOINT_BULK_HS_MAXP              512\r
349 \r
350 /** USB Standard Device Descriptor */\r
351 PRE_PACK struct POST_PACK _USB_DEVICE_DESCRIPTOR\r
352 {\r
353   uint8_t  bLength;     /**< Size of this descriptor in bytes. */\r
354   uint8_t  bDescriptorType; /**< DEVICE Descriptor Type. */\r
355   uint16_t bcdUSB; /**< BUSB Specification Release Number in\r
356                     Binary-Coded Decimal (i.e., 2.10 is 210H).\r
357                     This field identifies the release of the USB\r
358                     Specification with which the device and its\r
359                     descriptors are compliant.\r
360                    */\r
361   uint8_t  bDeviceClass; /**< Class code (assigned by the USB-IF).\r
362                           If this field is reset to zero, each interface\r
363                           within a configuration specifies its own\r
364                           class information and the various\r
365                           interfaces operate independently.\n\r
366                           If this field is set to a value between 1 and\r
367                           FEH, the device supports different class\r
368                           specifications on different interfaces and\r
369                           the interfaces may not operate\r
370                           independently. This value identifies the\r
371                           class definition used for the aggregate\r
372                           interfaces. \n\r
373                           If this field is set to FFH, the device class\r
374                           is vendor-specific.\r
375                           */\r
376   uint8_t  bDeviceSubClass; /**< Subclass code (assigned by the USB-IF).\r
377                             These codes are qualified by the value of\r
378                             the bDeviceClass field. \n\r
379                             If the bDeviceClass field is reset to zero,\r
380                             this field must also be reset to zero. \n\r
381                             If the bDeviceClass field is not set to FFH,\r
382                             all values are reserved for assignment by\r
383                             the USB-IF. \r
384                             */\r
385   uint8_t  bDeviceProtocol; /**< Protocol code (assigned by the USB-IF).\r
386                             These codes are qualified by the value of\r
387                             the bDeviceClass and the\r
388                             bDeviceSubClass fields. If a device\r
389                             supports class-specific protocols on a\r
390                             device basis as opposed to an interface\r
391                             basis, this code identifies the protocols\r
392                             that the device uses as defined by the\r
393                             specification of the device class. \n\r
394                             If this field is reset to zero, the device\r
395                             does not use class-specific protocols on a\r
396                             device basis. However, it may use classspecific\r
397                             protocols on an interface basis. \n\r
398                             If this field is set to FFH, the device uses a\r
399                             vendor-specific protocol on a device basis. \r
400                             */\r
401   uint8_t  bMaxPacketSize0; /**< Maximum packet size for endpoint zero\r
402                             (only 8, 16, 32, or 64 are valid). For HS devices\r
403                             is fixed to 64.\r
404                             */\r
405 \r
406   uint16_t idVendor; /**< Vendor ID (assigned by the USB-IF). */\r
407   uint16_t idProduct; /**< Product ID (assigned by the manufacturer). */\r
408   uint16_t bcdDevice; /**< Device release number in binary-coded decimal. */\r
409   uint8_t  iManufacturer; /**< Index of string descriptor describing manufacturer. */\r
410   uint8_t  iProduct; /**< Index of string descriptor describing product. */\r
411   uint8_t  iSerialNumber; /**< Index of string descriptor describing the device\92\r
412                           serial number.\r
413                           */\r
414   uint8_t  bNumConfigurations; /**< Number of possible configurations. */\r
415 } ;\r
416 /** USB Standard Device Descriptor */\r
417 typedef struct _USB_DEVICE_DESCRIPTOR USB_DEVICE_DESCRIPTOR;\r
418 \r
419 /** USB 2.0 Device Qualifier Descriptor */\r
420 PRE_PACK struct POST_PACK _USB_DEVICE_QUALIFIER_DESCRIPTOR\r
421 {\r
422   uint8_t  bLength; /**< Size of descriptor */\r
423   uint8_t  bDescriptorType; /**< Device Qualifier Type */\r
424   uint16_t bcdUSB; /**< USB specification version number (e.g., 0200H for V2.00) */\r
425   uint8_t  bDeviceClass; /**< Class Code */\r
426   uint8_t  bDeviceSubClass; /**< SubClass Code */\r
427   uint8_t  bDeviceProtocol; /**< Protocol Code */\r
428   uint8_t  bMaxPacketSize0; /**< Maximum packet size for other speed */\r
429   uint8_t  bNumConfigurations; /**< Number of Other-speed Configurations */\r
430   uint8_t  bReserved; /**< Reserved for future use, must be zero */\r
431 } ;\r
432 /** USB 2.0 Device Qualifier Descriptor */\r
433 typedef struct _USB_DEVICE_QUALIFIER_DESCRIPTOR USB_DEVICE_QUALIFIER_DESCRIPTOR;\r
434 \r
435 /** USB Standard Configuration Descriptor */\r
436 PRE_PACK struct POST_PACK _USB_CONFIGURATION_DESCRIPTOR\r
437 {\r
438   uint8_t  bLength; /**< Size of this descriptor in bytes */\r
439   uint8_t  bDescriptorType; /**< CONFIGURATION Descriptor Type*/\r
440   uint16_t wTotalLength; /**< Total length of data returned for this\r
441                           configuration. Includes the combined length\r
442                           of all descriptors (configuration, interface,\r
443                           endpoint, and class- or vendor-specific)\r
444                           returned for this configuration.*/\r
445   uint8_t  bNumInterfaces; /**< Number of interfaces supported by this configuration*/\r
446   uint8_t  bConfigurationValue; /**< Value to use as an argument to the\r
447                                 SetConfiguration() request to select this \r
448                                 configuration. */\r
449   uint8_t  iConfiguration; /**< Index of string descriptor describing this\r
450                             configuration*/\r
451   uint8_t  bmAttributes; /**< Configuration characteristics \n\r
452                           D7: Reserved (set to one)\n\r
453                           D6: Self-powered \n\r
454                           D5: Remote Wakeup \n\r
455                           D4...0: Reserved (reset to zero) \n\r
456                           D7 is reserved and must be set to one for\r
457                           historical reasons. \n\r
458                           A device configuration that uses power from\r
459                           the bus and a local source reports a non-zero\r
460                           value in bMaxPower to indicate the amount of\r
461                           bus power required and sets D6. The actual\r
462                           power source at runtime may be determined\r
463                           using the GetStatus(DEVICE) request (see\r
464                           USB 2.0 spec Section 9.4.5). \n\r
465                           If a device configuration supports remote\r
466                           wakeup, D5 is set to one.*/\r
467   uint8_t  bMaxPower; /**< Maximum power consumption of the USB\r
468                       device from the bus in this specific\r
469                       configuration when the device is fully\r
470                       operational. Expressed in 2 mA units\r
471                       (i.e., 50 = 100 mA). \n\r
472                       Note: A device configuration reports whether\r
473                       the configuration is bus-powered or selfpowered.\r
474                       Device status reports whether the\r
475                       device is currently self-powered. If a device is\r
476                       disconnected from its external power source, it\r
477                       updates device status to indicate that it is no\r
478                       longer self-powered. \n\r
479                       A device may not increase its power draw\r
480                       from the bus, when it loses its external power\r
481                       source, beyond the amount reported by its\r
482                       configuration. \n\r
483                       If a device can continue to operate when\r
484                       disconnected from its external power source, it\r
485                       continues to do so. If the device cannot\r
486                       continue to operate, it fails operations it can\r
487                       no longer support. The USB System Software\r
488                       may determine the cause of the failure by\r
489                       checking the status and noting the loss of the\r
490                       device\92s power source.*/\r
491 } ;\r
492 /** USB Standard Configuration Descriptor */\r
493 typedef struct _USB_CONFIGURATION_DESCRIPTOR USB_CONFIGURATION_DESCRIPTOR;\r
494 \r
495 /** USB Standard Interface Association Descriptor */\r
496 PRE_PACK struct POST_PACK _USB_IAD_DESCRIPTOR\r
497 {\r
498   uint8_t  bLength; /**< Size of this descriptor in bytes*/\r
499   uint8_t  bDescriptorType; /**< INTERFACE ASSOCIATION Descriptor Type*/\r
500   uint8_t  bFirstInterface; /**< Interface number of the first interface that is\r
501                             associated with this function.*/\r
502   uint8_t  bInterfaceCount; /**< Number of contiguous interfaces that are\r
503                             associated with this function. */\r
504   uint8_t  bFunctionClass; /**< Class code (assigned by USB-IF). \n\r
505                             A value of zero is not allowed in this descriptor.\r
506                             If this field is FFH, the function class is vendorspecific.\r
507                             All other values are reserved for assignment by\r
508                             the USB-IF.*/\r
509   uint8_t  bFunctionSubClass; /**< Subclass code (assigned by USB-IF). \n\r
510                             If the bFunctionClass field is not set to FFH all\r
511                             values are reserved for assignment by the USBIF.*/\r
512   uint8_t  bFunctionProtocol; /**< Protocol code (assigned by the USB). \n\r
513                                 These codes are qualified by the values of the\r
514                                 bFunctionClass and bFunctionSubClass fields.*/\r
515   uint8_t  iFunction; /**< Index of string descriptor describing this function.*/\r
516 } ;\r
517 /** USB Standard Interface Association Descriptor */\r
518 typedef struct _USB_IAD_DESCRIPTOR USB_IAD_DESCRIPTOR;\r
519 \r
520 /** USB Standard Interface Descriptor */\r
521 PRE_PACK struct POST_PACK _USB_INTERFACE_DESCRIPTOR\r
522 {\r
523   uint8_t  bLength; /**< Size of this descriptor in bytes*/\r
524   uint8_t  bDescriptorType; /**< INTERFACE Descriptor Type*/\r
525   uint8_t  bInterfaceNumber; /**< Number of this interface. Zero-based\r
526                               value identifying the index in the array of\r
527                               concurrent interfaces supported by this\r
528                               configuration.*/\r
529   uint8_t  bAlternateSetting; /**< Value used to select this alternate setting\r
530                               for the interface identified in the prior field*/\r
531   uint8_t  bNumEndpoints; /**< Number of endpoints used by this\r
532                           interface (excluding endpoint zero). If this\r
533                           value is zero, this interface only uses the\r
534                           Default Control Pipe.*/\r
535   uint8_t  bInterfaceClass; /**< Class code (assigned by the USB-IF). \n\r
536                             A value of zero is reserved for future\r
537                             standardization. \n\r
538                             If this field is set to FFH, the interface\r
539                             class is vendor-specific. \n\r
540                             All other values are reserved for\r
541                             assignment by the USB-IF.*/\r
542   uint8_t  bInterfaceSubClass; /**< Subclass code (assigned by the USB-IF). \n\r
543                               These codes are qualified by the value of\r
544                               the bInterfaceClass field. \n\r
545                               If the bInterfaceClass field is reset to zero,\r
546                               this field must also be reset to zero. \n\r
547                               If the bInterfaceClass field is not set to\r
548                               FFH, all values are reserved for\r
549                               assignment by the USB-IF.*/\r
550   uint8_t  bInterfaceProtocol; /**< Protocol code (assigned by the USB). \n\r
551                                 These codes are qualified by the value of\r
552                                 the bInterfaceClass and the\r
553                                 bInterfaceSubClass fields. If an interface\r
554                                 supports class-specific requests, this code\r
555                                 identifies the protocols that the device\r
556                                 uses as defined by the specification of the\r
557                                 device class. \n\r
558                                 If this field is reset to zero, the device\r
559                                 does not use a class-specific protocol on\r
560                                 this interface. \n\r
561                                 If this field is set to FFH, the device uses\r
562                                 a vendor-specific protocol for this\r
563                                 interface.*/\r
564   uint8_t  iInterface; /**< Index of string descriptor describing this interface*/\r
565 } ;\r
566 /** USB Standard Interface Descriptor */\r
567 typedef struct _USB_INTERFACE_DESCRIPTOR USB_INTERFACE_DESCRIPTOR;\r
568 \r
569 /** USB Standard Endpoint Descriptor */\r
570 PRE_PACK struct POST_PACK _USB_ENDPOINT_DESCRIPTOR\r
571 {\r
572   uint8_t  bLength; /**< Size of this descriptor in bytes*/\r
573   uint8_t  bDescriptorType; /**< ENDPOINT Descriptor Type*/\r
574   uint8_t  bEndpointAddress; /**< The address of the endpoint on the USB device\r
575                             described by this descriptor. The address is\r
576                             encoded as follows: \n\r
577                             Bit 3...0: The endpoint number \n\r
578                             Bit 6...4: Reserved, reset to zero \n\r
579                             Bit 7: Direction, ignored for control endpoints\r
580                             0 = OUT endpoint\r
581                             1 = IN endpoint.  \n \sa USBD_ENDPOINT_ADR_Type*/\r
582   uint8_t  bmAttributes; /**< This field describes the endpoint\92s attributes when it is\r
583                           configured using the bConfigurationValue. \n\r
584                           Bits 1..0: Transfer Type\r
585                           \li 00 = Control\r
586                           \li 01 = Isochronous\r
587                           \li 10 = Bulk\r
588                           \li 11 = Interrupt  \n\r
589                           If not an isochronous endpoint, bits 5..2 are reserved\r
590                           and must be set to zero. If isochronous, they are\r
591                           defined as follows: \n\r
592                           Bits 3..2: Synchronization Type\r
593                           \li 00 = No Synchronization\r
594                           \li 01 = Asynchronous\r
595                           \li 10 = Adaptive\r
596                           \li 11 = Synchronous \n\r
597                           Bits 5..4: Usage Type\r
598                           \li 00 = Data endpoint\r
599                           \li 01 = Feedback endpoint\r
600                           \li 10 = Implicit feedback Data endpoint\r
601                           \li 11 = Reserved \n\r
602                           Refer to Chapter 5 of USB 2.0 specification for more information. \n\r
603                           All other bits are reserved and must be reset to zero.\r
604                           Reserved bits must be ignored by the host.\r
605                          \n \sa USBD_EP_ATTR_Type*/\r
606   uint16_t wMaxPacketSize; /**< Maximum packet size this endpoint is capable of\r
607                           sending or receiving when this configuration is\r
608                           selected. \n\r
609                           For isochronous endpoints, this value is used to\r
610                           reserve the bus time in the schedule, required for the\r
611                           per-(micro)frame data payloads. The pipe may, on an\r
612                           ongoing basis, actually use less bandwidth than that\r
613                           reserved. The device reports, if necessary, the actual\r
614                           bandwidth used via its normal, non-USB defined\r
615                           mechanisms. \n\r
616                           For all endpoints, bits 10..0 specify the maximum\r
617                           packet size (in bytes). \n\r
618                           For high-speed isochronous and interrupt endpoints: \n\r
619                           Bits 12..11 specify the number of additional transaction\r
620                           opportunities per microframe: \n\r
621                           \li 00 = None (1 transaction per microframe)\r
622                           \li 01 = 1 additional (2 per microframe)\r
623                           \li 10 = 2 additional (3 per microframe)\r
624                           \li 11 = Reserved \n\r
625                           Bits 15..13 are reserved and must be set to zero.*/\r
626   uint8_t  bInterval; /**< Interval for polling endpoint for data transfers.\r
627                       Expressed in frames or microframes depending on the\r
628                       device operating speed (i.e., either 1 millisecond or\r
629                       125 µs units). \r
630                       \li For full-/high-speed isochronous endpoints, this value\r
631                       must be in the range from 1 to 16. The bInterval value\r
632                       is used as the exponent for a \f$ 2^(bInterval-1) \f$ value; e.g., a\r
633                       bInterval of 4 means a period of 8 (\f$ 2^(4-1) \f$). \r
634                       \li For full-/low-speed interrupt endpoints, the value of\r
635                       this field may be from 1 to 255.\r
636                       \li For high-speed interrupt endpoints, the bInterval value\r
637                       is used as the exponent for a \f$ 2^(bInterval-1) \f$ value; e.g., a\r
638                       bInterval of 4 means a period of 8 (\f$ 2^(4-1) \f$) . This value\r
639                       must be from 1 to 16.\r
640                       \li For high-speed bulk/control OUT endpoints, the\r
641                       bInterval must specify the maximum NAK rate of the\r
642                       endpoint. A value of 0 indicates the endpoint never\r
643                       NAKs. Other values indicate at most 1 NAK each\r
644                       bInterval number of microframes. This value must be\r
645                       in the range from 0 to 255. \n\r
646                       Refer to Chapter 5 of USB 2.0 specification for more information.\r
647                       */\r
648 } ;\r
649 /** USB Standard Endpoint Descriptor */\r
650 typedef struct _USB_ENDPOINT_DESCRIPTOR USB_ENDPOINT_DESCRIPTOR;\r
651 \r
652 /** USB String Descriptor */\r
653 PRE_PACK struct POST_PACK _USB_STRING_DESCRIPTOR\r
654 {\r
655   uint8_t  bLength; /**< Size of this descriptor in bytes*/\r
656   uint8_t  bDescriptorType; /**< STRING Descriptor Type*/\r
657   uint16_t bString/*[]*/; /**< UNICODE encoded string */\r
658 }  ;\r
659 /** USB String Descriptor */\r
660 typedef struct _USB_STRING_DESCRIPTOR USB_STRING_DESCRIPTOR;\r
661 \r
662 /** USB Common Descriptor */\r
663 PRE_PACK struct POST_PACK _USB_COMMON_DESCRIPTOR\r
664 {\r
665   uint8_t  bLength; /**< Size of this descriptor in bytes*/\r
666   uint8_t  bDescriptorType; /**< Descriptor Type*/\r
667 } ;\r
668 /** USB Common Descriptor */\r
669 typedef struct _USB_COMMON_DESCRIPTOR USB_COMMON_DESCRIPTOR;\r
670 \r
671 /** USB Other Speed Configuration */\r
672 PRE_PACK struct POST_PACK _USB_OTHER_SPEED_CONFIGURATION\r
673 {\r
674   uint8_t  bLength; /**< Size of descriptor*/\r
675   uint8_t  bDescriptorType; /**< Other_speed_Configuration Type*/\r
676   uint16_t wTotalLength; /**< Total length of data returned*/\r
677   uint8_t  bNumInterfaces; /**< Number of interfaces supported by this speed configuration*/\r
678   uint8_t  bConfigurationValue; /**< Value to use to select configuration*/\r
679   uint8_t  IConfiguration; /**< Index of string descriptor*/\r
680   uint8_t  bmAttributes; /**< Same as Configuration descriptor*/\r
681   uint8_t  bMaxPower; /**< Same as Configuration descriptor*/\r
682 } ;\r
683 /** USB Other Speed Configuration */\r
684 typedef struct _USB_OTHER_SPEED_CONFIGURATION USB_OTHER_SPEED_CONFIGURATION;\r
685 \r
686 /** \ingroup USBD_Core \r
687  * USB device stack/module handle. \r
688  */\r
689 typedef void* USBD_HANDLE_T;\r
690 \r
691 #define WBVAL(x) ((x) & 0xFF),(((x) >> 8) & 0xFF)\r
692 #define B3VAL(x) ((x) & 0xFF),(((x) >> 8) & 0xFF),(((x) >> 16) & 0xFF)\r
693 \r
694 #define USB_DEVICE_DESC_SIZE        (sizeof(USB_DEVICE_DESCRIPTOR))\r
695 #define USB_CONFIGURATION_DESC_SIZE (sizeof(USB_CONFIGURATION_DESCRIPTOR))\r
696 #define USB_INTERFACE_DESC_SIZE     (sizeof(USB_INTERFACE_DESCRIPTOR))\r
697 #define USB_INTERFACE_ASSOC_DESC_SIZE   (sizeof(USB_IAD_DESCRIPTOR))\r
698 #define USB_ENDPOINT_DESC_SIZE      (sizeof(USB_ENDPOINT_DESCRIPTOR))\r
699 #define USB_DEVICE_QUALI_SIZE       (sizeof(USB_DEVICE_QUALIFIER_DESCRIPTOR))\r
700 #define USB_OTHER_SPEED_CONF_SIZE   (sizeof(USB_OTHER_SPEED_CONFIGURATION))\r
701 \r
702 /** @}*/\r
703 \r
704 #endif  /* __USBD_H__ */\r