Documentation improvements - put driver example code into its own section, fix incorr...
[pub/USBasp.git] / LUFA / Drivers / USB / HighLevel / StdDescriptors.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2010.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 /** \file
32 * \brief USB standard descriptor definitions.
33 *
34 * This file contains structures and macros for the easy creation of standard USB descriptors in USB device projects.
35 *
36 * \note This file should not be included directly. It is automatically included as needed by the USB driver
37 * dispatch header located in LUFA/Drivers/USB/USB.h.
38 */
39
40 /** \ingroup Group_USB
41 * @defgroup Group_Descriptors USB Descriptors
42 *
43 * Standard USB device descriptor defines and retrieval routines, for USB devices. This module contains
44 * structures and macros for the easy creation of standard USB descriptors in USB device projects.
45 *
46 * @{
47 */
48
49 #ifndef __USBDESCRIPTORS_H__
50 #define __USBDESCRIPTORS_H__
51
52 /* Includes: */
53 #include <avr/pgmspace.h>
54 #include <stdbool.h>
55 #include <stdint.h>
56 #include <stddef.h>
57
58 #include "../../../Common/Common.h"
59 #include "USBMode.h"
60 #include "Events.h"
61
62 #if defined(USB_CAN_BE_DEVICE)
63 #include "../LowLevel/Device.h"
64 #endif
65
66 /* Enable C linkage for C++ Compilers: */
67 #if defined(__cplusplus)
68 extern "C" {
69 #endif
70
71 /* Preprocessor Checks: */
72 #if !defined(__INCLUDE_FROM_USB_DRIVER)
73 #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
74 #endif
75
76 /* Public Interface - May be used in end-application: */
77 /* Macros: */
78 /** Indicates that a given descriptor does not exist in the device. This can be used inside descriptors
79 * for string descriptor indexes, or may be use as a return value for GetDescriptor when the specified
80 * descriptor does not exist.
81 */
82 #define NO_DESCRIPTOR 0
83
84 #if (!defined(NO_INTERNAL_SERIAL) && \
85 (defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1287__) || \
86 defined(__AVR_ATmega32U6__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) || \
87 defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega8U2__)))
88 /** String descriptor index for the device's unique serial number string descriptor within the device.
89 * This unique serial number is used by the host to associate resources to the device (such as drivers or COM port
90 * number allocations) to a device regardless of the port it is plugged in to on the host. Some USB AVRs contain
91 * a unique serial number internally, and setting the device descriptors serial number string index to this value
92 * will cause it to use the internal serial number.
93 *
94 * On unsupported devices, this will evaluate to NO_DESCRIPTOR and so will force the host to create a pseudo-serial
95 * number for the device.
96 */
97 #define USE_INTERNAL_SERIAL 0xDC
98 #else
99 #define USE_INTERNAL_SERIAL NO_DESCRIPTOR
100 #endif
101
102 /** Macro to calculate the power value for the configuration descriptor, from a given number of milliamperes. */
103 #define USB_CONFIG_POWER_MA(mA) ((mA) >> 1)
104
105 /** Macro to calculate the Unicode length of a string with a given number of Unicode characters.
106 * Should be used in string descriptor's headers for giving the string descriptor's byte length.
107 */
108 #define USB_STRING_LEN(str) (sizeof(USB_Descriptor_Header_t) + ((str) << 1))
109
110 /** Macro to encode a given four digit floating point version number (e.g. 01.23) into Binary Coded
111 * Decimal format for descriptor fields requiring BCD encoding, such as the USB version number in the
112 * standard device descriptor.
113 */
114 #define VERSION_BCD(x) ((((VERSION_TENS(x) << 4) | VERSION_ONES(x)) << 8) | \
115 ((VERSION_TENTHS(x) << 4) | VERSION_HUNDREDTHS(x)))
116
117 /** String language ID for the English language. Should be used in \ref USB_Descriptor_String_t descriptors
118 * to indicate that the English language is supported by the device in its string descriptors.
119 */
120 #define LANGUAGE_ID_ENG 0x0409
121
122 /** \name Endpoint Address Direction Masks */
123 //@{
124 /** Can be masked with an endpoint address for a \ref USB_Descriptor_Endpoint_t endpoint descriptor's
125 * EndpointAddress value to indicate to the host that the endpoint is of the IN direction (i.e, from
126 * device to host).
127 */
128 #define ENDPOINT_DESCRIPTOR_DIR_IN 0x80
129
130 /** Can be masked with an endpoint address for a \ref USB_Descriptor_Endpoint_t endpoint descriptor's
131 * EndpointAddress value to indicate to the host that the endpoint is of the OUT direction (i.e, from
132 * host to device).
133 */
134 #define ENDPOINT_DESCRIPTOR_DIR_OUT 0x00
135 //@}
136
137 /** \name USB Configuration Descriptor Attribute Masks */
138 //@{
139 /** Can be masked with other configuration descriptor attributes for a \ref USB_Descriptor_Configuration_Header_t
140 * descriptor's ConfigAttributes value to indicate that the specified configuration can draw its power
141 * from the host's VBUS line.
142 */
143 #define USB_CONFIG_ATTR_BUSPOWERED 0x80
144
145 /** Can be masked with other configuration descriptor attributes for a \ref USB_Descriptor_Configuration_Header_t
146 * descriptor's ConfigAttributes value to indicate that the specified configuration can draw its power
147 * from the device's own power source.
148 */
149 #define USB_CONFIG_ATTR_SELFPOWERED 0x40
150
151 /** Can be masked with other configuration descriptor attributes for a \ref USB_Descriptor_Configuration_Header_t
152 * descriptor's ConfigAttributes value to indicate that the specified configuration supports the
153 * remote wakeup feature of the USB standard, allowing a suspended USB device to wake up the host upon
154 * request.
155 */
156 #define USB_CONFIG_ATTR_REMOTEWAKEUP 0x20
157 //@}
158
159 /** \name Endpoint Descriptor Attribute Masks */
160 //@{
161 /** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
162 * Attributes value to indicate that the specified endpoint is not synchronized.
163 *
164 * \see The USB specification for more details on the possible Endpoint attributes.
165 */
166 #define ENDPOINT_ATTR_NO_SYNC (0 << 2)
167
168 /** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
169 * Attributes value to indicate that the specified endpoint is asynchronous.
170 *
171 * \see The USB specification for more details on the possible Endpoint attributes.
172 */
173 #define ENDPOINT_ATTR_ASYNC (1 << 2)
174
175 /** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
176 * Attributes value to indicate that the specified endpoint is adaptive.
177 *
178 * \see The USB specification for more details on the possible Endpoint attributes.
179 */
180 #define ENDPOINT_ATTR_ADAPTIVE (2 << 2)
181
182 /** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
183 * Attributes value to indicate that the specified endpoint is synchronized.
184 *
185 * \see The USB specification for more details on the possible Endpoint attributes.
186 */
187 #define ENDPOINT_ATTR_SYNC (3 << 2)
188 //@}
189
190 /** \name Endpoint Descriptor Usage Masks */
191 //@{
192 /** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
193 * Attributes value to indicate that the specified endpoint is used for data transfers.
194 *
195 * \see The USB specification for more details on the possible Endpoint usage attributes.
196 */
197 #define ENDPOINT_USAGE_DATA (0 << 4)
198
199 /** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
200 * Attributes value to indicate that the specified endpoint is used for feedback.
201 *
202 * \see The USB specification for more details on the possible Endpoint usage attributes.
203 */
204 #define ENDPOINT_USAGE_FEEDBACK (1 << 4)
205
206 /** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
207 * Attributes value to indicate that the specified endpoint is used for implicit feedback.
208 *
209 * \see The USB specification for more details on the possible Endpoint usage attributes.
210 */
211 #define ENDPOINT_USAGE_IMPLICIT_FEEDBACK (2 << 4)
212 //@}
213
214 /* Enums: */
215 /** Enum for the possible standard descriptor types, as given in each descriptor's header. */
216 enum USB_DescriptorTypes_t
217 {
218 DTYPE_Device = 0x01, /**< Indicates that the descriptor is a device descriptor. */
219 DTYPE_Configuration = 0x02, /**< Indicates that the descriptor is a configuration descriptor. */
220 DTYPE_String = 0x03, /**< Indicates that the descriptor is a string descriptor. */
221 DTYPE_Interface = 0x04, /**< Indicates that the descriptor is an interface descriptor. */
222 DTYPE_Endpoint = 0x05, /**< Indicates that the descriptor is an endpoint descriptor. */
223 DTYPE_DeviceQualifier = 0x06, /**< Indicates that the descriptor is a device qualifier descriptor. */
224 DTYPE_Other = 0x07, /**< Indicates that the descriptor is of other type. */
225 DTYPE_InterfacePower = 0x08, /**< Indicates that the descriptor is an interface power descriptor. */
226 DTYPE_InterfaceAssociation = 0x0B, /**< Indicates that the descriptor is an interface association descriptor. */
227 DTYPE_CSInterface = 0x24, /**< Indicates that the descriptor is a class specific interface descriptor. */
228 DTYPE_CSEndpoint = 0x25, /**< Indicates that the descriptor is a class specific endpoint descriptor. */
229 };
230
231 /** Enum for possible Class, Subclass and Protocol values of device and interface descriptors. */
232 enum USB_Descriptor_ClassSubclassProtocol_t
233 {
234 USB_CSCP_NoDeviceClass = 0x00, /**< Descriptor Class value indicating that the device does not belong
235 * to a particular class at the device level.
236 */
237 USB_CSCP_NoDeviceSubclass = 0x00, /**< Descriptor Subclass value indicating that the device does not belong
238 * to a particular subclass at the device level.
239 */
240 USB_CSCP_NoDeviceProtocol = 0x00, /**< Descriptor Protocol value indicating that the device does not belong
241 * to a particular protocol at the device level.
242 */
243 USB_CSCP_VendorSpecificClass = 0xFF, /**< Descriptor Class value indicating that the device/interface belongs
244 * to a vendor specific class.
245 */
246 USB_CSCP_VendorSpecificSubclass = 0xFF, /**< Descriptor Subclass value indicating that the device/interface belongs
247 * to a vendor specific subclass.
248 */
249 USB_CSCP_VendorSpecificProtocol = 0xFF, /**< Descriptor Protocol value indicating that the device/interface belongs
250 * to a vendor specific protocol.
251 */
252 USB_CSCP_IADDeviceClass = 0xEF, /**< Descriptor Class value indicating that the device belongs to the
253 * Interface Association Descriptor class.
254 */
255 USB_CSCP_IADDeviceSubclass = 0x02, /**< Descriptor Subclass value indicating that the device belongs to the
256 * Interface Association Descriptor subclass.
257 */
258 USB_CSCP_IADDeviceProtocol = 0x01, /**< Descriptor Protocol value indicating that the device belongs to the
259 * Interface Association Descriptor protocol.
260 */
261 };
262
263 /* Type Defines: */
264 /** \brief Standard USB Descriptor Header (LUFA naming conventions).
265 *
266 * Type define for all descriptors' standard header, indicating the descriptor's length and type. This structure
267 * uses LUFA-specific element names to make each element's purpose clearer.
268 *
269 * \see \ref USB_StdDescriptor_Header_t for the version of this type with standard element names.
270 */
271 typedef struct
272 {
273 uint8_t Size; /**< Size of the descriptor, in bytes. */
274 uint8_t Type; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
275 * given by the specific class.
276 */
277 } USB_Descriptor_Header_t;
278
279 /** \brief Standard USB Descriptor Header (USB-IF naming conventions).
280 *
281 * Type define for all descriptors' standard header, indicating the descriptor's length and type. This structure
282 * uses the relevant standard's given element names to ensure compatibility with the standard.
283 *
284 * \see \ref USB_Descriptor_Header_t for the version of this type with non-standard LUFA specific element names.
285 */
286 typedef struct
287 {
288 uint8_t bLength; /**< Size of the descriptor, in bytes. */
289 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
290 * given by the specific class.
291 */
292 } USB_StdDescriptor_Header_t;
293
294 /** \brief Standard USB Device Descriptor (LUFA naming conventions).
295 *
296 * Type define for a standard Device Descriptor. This structure uses LUFA-specific element names to make each
297 * element's purpose clearer.
298 *
299 * \see \ref USB_StdDescriptor_Device_t for the version of this type with standard element names.
300 */
301 typedef struct
302 {
303 USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
304
305 uint16_t USBSpecification; /**< BCD of the supported USB specification. */
306 uint8_t Class; /**< USB device class. */
307 uint8_t SubClass; /**< USB device subclass. */
308 uint8_t Protocol; /**< USB device protocol. */
309
310 uint8_t Endpoint0Size; /**< Size of the control (address 0) endpoint's bank in bytes. */
311
312 uint16_t VendorID; /**< Vendor ID for the USB product. */
313 uint16_t ProductID; /**< Unique product ID for the USB product. */
314 uint16_t ReleaseNumber; /**< Product release (version) number. */
315
316 uint8_t ManufacturerStrIndex; /**< String index for the manufacturer's name. The
317 * host will request this string via a separate
318 * control request for the string descriptor.
319 *
320 * \note If no string supplied, use \ref NO_DESCRIPTOR.
321 */
322 uint8_t ProductStrIndex; /**< String index for the product name/details.
323 *
324 * \see ManufacturerStrIndex structure entry.
325 */
326 uint8_t SerialNumStrIndex; /**< String index for the product's globally unique hexadecimal
327 * serial number, in uppercase Unicode ASCII.
328 *
329 * \note On some AVR models, there is an embedded serial number
330 * in the chip which can be used for the device serial number.
331 * To use this serial number, set this to USE_INTERNAL_SERIAL.
332 * On unsupported devices, this will evaluate to 0 and will cause
333 * the host to generate a pseudo-unique value for the device upon
334 * insertion.
335 *
336 * \see ManufacturerStrIndex structure entry.
337 */
338 uint8_t NumberOfConfigurations; /**< Total number of configurations supported by
339 * the device.
340 */
341 } USB_Descriptor_Device_t;
342
343 /** \brief Standard USB Device Descriptor (USB-IF naming conventions).
344 *
345 * Type define for a standard Device Descriptor. This structure uses the relevant standard's given element names
346 * to ensure compatibility with the standard.
347 *
348 * \see \ref USB_Descriptor_Device_t for the version of this type with non-standard LUFA specific element names.
349 */
350 typedef struct
351 {
352 uint8_t bLength; /**< Size of the descriptor, in bytes. */
353 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
354 * given by the specific class.
355 */
356 uint16_t bcdUSB; /**< BCD of the supported USB specification. */
357 uint8_t bDeviceClass; /**< USB device class. */
358 uint8_t bDeviceSubClass; /**< USB device subclass. */
359 uint8_t bDeviceProtocol; /**< USB device protocol. */
360 uint8_t bMaxPacketSize0; /**< Size of the control (address 0) endpoint's bank in bytes. */
361 uint16_t idVendor; /**< Vendor ID for the USB product. */
362 uint16_t idProduct; /**< Unique product ID for the USB product. */
363 uint16_t bcdDevice; /**< Product release (version) number. */
364 uint8_t iManufacturer; /**< String index for the manufacturer's name. The
365 * host will request this string via a separate
366 * control request for the string descriptor.
367 *
368 * \note If no string supplied, use \ref NO_DESCRIPTOR.
369 */
370 uint8_t iProduct; /**< String index for the product name/details.
371 *
372 * \see ManufacturerStrIndex structure entry.
373 */
374 uint8_t iSerialNumber; /**< String index for the product's globally unique hexadecimal
375 * serial number, in uppercase Unicode ASCII.
376 *
377 * \note On some AVR models, there is an embedded serial number
378 * in the chip which can be used for the device serial number.
379 * To use this serial number, set this to USE_INTERNAL_SERIAL.
380 * On unsupported devices, this will evaluate to 0 and will cause
381 * the host to generate a pseudo-unique value for the device upon
382 * insertion.
383 *
384 * \see ManufacturerStrIndex structure entry.
385 */
386 uint8_t bNumConfigurations; /**< Total number of configurations supported by
387 * the device.
388 */
389 } USB_StdDescriptor_Device_t;
390
391 /** \brief Standard USB Configuration Descriptor (LUFA naming conventions).
392 *
393 * Type define for a standard Configuration Descriptor header. This structure uses LUFA-specific element names
394 * to make each element's purpose clearer.
395 *
396 * \see \ref USB_StdDescriptor_Configuration_Header_t for the version of this type with standard element names.
397 */
398 typedef struct
399 {
400 USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
401
402 uint16_t TotalConfigurationSize; /**< Size of the configuration descriptor header,
403 * and all sub descriptors inside the configuration.
404 */
405 uint8_t TotalInterfaces; /**< Total number of interfaces in the configuration. */
406
407 uint8_t ConfigurationNumber; /**< Configuration index of the current configuration. */
408 uint8_t ConfigurationStrIndex; /**< Index of a string descriptor describing the configuration. */
409
410 uint8_t ConfigAttributes; /**< Configuration attributes, comprised of a mask of zero or
411 * more USB_CONFIG_ATTR_* masks.
412 */
413
414 uint8_t MaxPowerConsumption; /**< Maximum power consumption of the device while in the
415 * current configuration, calculated by the \ref USB_CONFIG_POWER_MA()
416 * macro.
417 */
418 } USB_Descriptor_Configuration_Header_t;
419
420 /** \brief Standard USB Configuration Descriptor (USB-IF naming conventions).
421 *
422 * Type define for a standard Configuration Descriptor header. This structure uses the relevant standard's given element names
423 * to ensure compatibility with the standard.
424 *
425 * \see \ref USB_Descriptor_Device_t for the version of this type with non-standard LUFA specific element names.
426 */
427 typedef struct
428 {
429 uint8_t bLength; /**< Size of the descriptor, in bytes. */
430 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
431 * given by the specific class.
432 */
433 uint16_t wTotalLength; /**< Size of the configuration descriptor header,
434 * and all sub descriptors inside the configuration.
435 */
436 uint8_t bNumInterfaces; /**< Total number of interfaces in the configuration. */
437 uint8_t bConfigurationValue; /**< Configuration index of the current configuration. */
438 uint8_t iConfiguration; /**< Index of a string descriptor describing the configuration. */
439 uint8_t bmAttributes; /**< Configuration attributes, comprised of a mask of zero or
440 * more USB_CONFIG_ATTR_* masks.
441 */
442 uint8_t bMaxPower; /**< Maximum power consumption of the device while in the
443 * current configuration, calculated by the \ref USB_CONFIG_POWER_MA()
444 * macro.
445 */
446 } USB_StdDescriptor_Configuration_Header_t;
447
448 /** \brief Standard USB Interface Descriptor (LUFA naming conventions).
449 *
450 * Type define for a standard Interface Descriptor. This structure uses LUFA-specific element names
451 * to make each element's purpose clearer.
452 *
453 * \see \ref USB_StdDescriptor_Interface_t for the version of this type with standard element names.
454 */
455 typedef struct
456 {
457 USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
458
459 uint8_t InterfaceNumber; /**< Index of the interface in the current configuration. */
460 uint8_t AlternateSetting; /**< Alternate setting for the interface number. The same
461 * interface number can have multiple alternate settings
462 * with different endpoint configurations, which can be
463 * selected by the host.
464 */
465 uint8_t TotalEndpoints; /**< Total number of endpoints in the interface. */
466
467 uint8_t Class; /**< Interface class ID. */
468 uint8_t SubClass; /**< Interface subclass ID. */
469 uint8_t Protocol; /**< Interface protocol ID. */
470
471 uint8_t InterfaceStrIndex; /**< Index of the string descriptor describing the interface. */
472 } USB_Descriptor_Interface_t;
473
474 /** \brief Standard USB Interface Descriptor (USB-IF naming conventions).
475 *
476 * Type define for a standard Interface Descriptor. This structure uses the relevant standard's given element names
477 * to ensure compatibility with the standard.
478 *
479 * \see \ref USB_Descriptor_Interface_t for the version of this type with non-standard LUFA specific element names.
480 */
481 typedef struct
482 {
483 uint8_t bLength; /**< Size of the descriptor, in bytes. */
484 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
485 * given by the specific class.
486 */
487 uint8_t bInterfaceNumber; /**< Index of the interface in the current configuration. */
488 uint8_t bAlternateSetting; /**< Alternate setting for the interface number. The same
489 * interface number can have multiple alternate settings
490 * with different endpoint configurations, which can be
491 * selected by the host.
492 */
493 uint8_t bNumEndpoints; /**< Total number of endpoints in the interface. */
494 uint8_t bInterfaceClass; /**< Interface class ID. */
495 uint8_t bInterfaceSubClass; /**< Interface subclass ID. */
496 uint8_t bInterfaceProtocol; /**< Interface protocol ID. */
497 uint8_t iInterface; /**< Index of the string descriptor describing the
498 * interface.
499 */
500 } USB_StdDescriptor_Interface_t;
501
502 /** \brief Standard USB Interface Association Descriptor (LUFA naming conventions).
503 *
504 * Type define for a standard Interface Association Descriptor. This structure uses LUFA-specific element names
505 * to make each element's purpose clearer.
506 *
507 * This descriptor has been added as a supplement to the USB2.0 standard, in the ECN located at
508 * <a>http://www.usb.org/developers/docs/InterfaceAssociationDescriptor_ecn.pdf</a>. It allows composite
509 * devices with multiple interfaces related to the same function to have the multiple interfaces bound
510 * together at the point of enumeration, loading one generic driver for all the interfaces in the single
511 * function. Read the ECN for more information.
512 *
513 * \see \ref USB_StdDescriptor_Interface_Association_t for the version of this type with standard element names.
514 */
515 typedef struct
516 {
517 USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
518
519 uint8_t FirstInterfaceIndex; /**< Index of the first associated interface. */
520 uint8_t TotalInterfaces; /**< Total number of associated interfaces. */
521
522 uint8_t Class; /**< Interface class ID. */
523 uint8_t SubClass; /**< Interface subclass ID. */
524 uint8_t Protocol; /**< Interface protocol ID. */
525
526 uint8_t IADStrIndex; /**< Index of the string descriptor describing the
527 * interface association.
528 */
529 } USB_Descriptor_Interface_Association_t;
530
531 /** \brief Standard USB Interface Association Descriptor (USB-IF naming conventions).
532 *
533 * Type define for a standard Interface Association Descriptor. This structure uses the relevant standard's given
534 * element names to ensure compatibility with the standard.
535 *
536 * This descriptor has been added as a supplement to the USB2.0 standard, in the ECN located at
537 * <a>http://www.usb.org/developers/docs/InterfaceAssociationDescriptor_ecn.pdf</a>. It allows composite
538 * devices with multiple interfaces related to the same function to have the multiple interfaces bound
539 * together at the point of enumeration, loading one generic driver for all the interfaces in the single
540 * function. Read the ECN for more information.
541 *
542 * \see \ref USB_Descriptor_Interface_Association_t for the version of this type with non-standard LUFA specific
543 * element names.
544 */
545 typedef struct
546 {
547 uint8_t bLength; /**< Size of the descriptor, in bytes. */
548 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
549 * given by the specific class.
550 */
551 uint8_t bFirstInterface; /**< Index of the first associated interface. */
552 uint8_t bInterfaceCount; /**< Total number of associated interfaces. */
553 uint8_t bFunctionClass; /**< Interface class ID. */
554 uint8_t bFunctionSubClass; /**< Interface subclass ID. */
555 uint8_t bFunctionProtocol; /**< Interface protocol ID. */
556 uint8_t iFunction; /**< Index of the string descriptor describing the
557 * interface association.
558 */
559 } USB_StdDescriptor_Interface_Association_t;
560
561 /** \brief Standard USB Endpoint Descriptor (LUFA naming conventions).
562 *
563 * Type define for a standard Endpoint Descriptor. This structure uses LUFA-specific element names
564 * to make each element's purpose clearer.
565 *
566 * \see \ref USB_StdDescriptor_Endpoint_t for the version of this type with standard element names.
567 */
568 typedef struct
569 {
570 USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
571
572 uint8_t EndpointAddress; /**< Logical address of the endpoint within the device for the current
573 * configuration, including direction mask.
574 */
575 uint8_t Attributes; /**< Endpoint attributes, comprised of a mask of the endpoint type (EP_TYPE_*)
576 * and attributes (ENDPOINT_ATTR_*) masks.
577 */
578 uint16_t EndpointSize; /**< Size of the endpoint bank, in bytes. This indicates the maximum packet
579 * size that the endpoint can receive at a time.
580 */
581 uint8_t PollingIntervalMS; /**< Polling interval in milliseconds for the endpoint if it is an INTERRUPT
582 * or ISOCHRONOUS type.
583 */
584 } USB_Descriptor_Endpoint_t;
585
586 /** \brief Standard USB Endpoint Descriptor (USB-IF naming conventions).
587 *
588 * Type define for a standard Endpoint Descriptor. This structure uses the relevant standard's given
589 * element names to ensure compatibility with the standard.
590 *
591 * \see \ref USB_Descriptor_Endpoint_t for the version of this type with non-standard LUFA specific
592 * element names.
593 */
594 typedef struct
595 {
596 uint8_t bLength; /**< Size of the descriptor, in bytes. */
597 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a
598 * value given by the specific class.
599 */
600 uint8_t bEndpointAddress; /**< Logical address of the endpoint within the device for the current
601 * configuration, including direction mask.
602 */
603 uint8_t bmAttributes; /**< Endpoint attributes, comprised of a mask of the endpoint type (EP_TYPE_*)
604 * and attributes (ENDPOINT_ATTR_*) masks.
605 */
606 uint16_t wMaxPacketSize; /**< Size of the endpoint bank, in bytes. This indicates the maximum packet size
607 * that the endpoint can receive at a time.
608 */
609 uint8_t bInterval; /**< Polling interval in milliseconds for the endpoint if it is an INTERRUPT or
610 * ISOCHRONOUS type.
611 */
612 } USB_StdDescriptor_Endpoint_t;
613
614 /** \brief Standard USB String Descriptor (LUFA naming conventions).
615 *
616 * Type define for a standard string descriptor. Unlike other standard descriptors, the length
617 * of the descriptor for placement in the descriptor header must be determined by the \ref USB_STRING_LEN()
618 * macro rather than by the size of the descriptor structure, as the length is not fixed.
619 *
620 * This structure should also be used for string index 0, which contains the supported language IDs for
621 * the device as an array.
622 *
623 * This structure uses LUFA-specific element names to make each element's purpose clearer.
624 *
625 * \see \ref USB_StdDescriptor_String_t for the version of this type with standard element names.
626 */
627 typedef struct
628 {
629 USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
630
631 wchar_t UnicodeString[]; /**< String data, as unicode characters (alternatively,
632 * string language IDs). If normal ASCII characters are
633 * to be used, they must be added as an array of characters
634 * rather than a normal C string so that they are widened to
635 * Unicode size.
636 *
637 * Under GCC, strings prefixed with the "L" character (before
638 * the opening string quotation mark) are considered to be
639 * Unicode strings, and may be used instead of an explicit
640 * array of ASCII characters.
641 */
642 } USB_Descriptor_String_t;
643
644 /** \brief Standard USB String Descriptor (USB-IF naming conventions).
645 *
646 * Type define for a standard string descriptor. Unlike other standard descriptors, the length
647 * of the descriptor for placement in the descriptor header must be determined by the \ref USB_STRING_LEN()
648 * macro rather than by the size of the descriptor structure, as the length is not fixed.
649 *
650 * This structure should also be used for string index 0, which contains the supported language IDs for
651 * the device as an array.
652 *
653 * This structure uses the relevant standard's given element names to ensure compatibility with the standard.
654 *
655 * \see \ref USB_Descriptor_String_t for the version of this type with with non-standard LUFA specific
656 * element names.
657 */
658 typedef struct
659 {
660 uint8_t bLength; /**< Size of the descriptor, in bytes. */
661 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t
662 * or a value given by the specific class.
663 */
664 int16_t bString[]; /**< String data, as unicode characters (alternatively, string language IDs).
665 * If normal ASCII characters are to be used, they must be added as an array
666 * of characters rather than a normal C string so that they are widened to
667 * Unicode size.
668 *
669 * Under GCC, strings prefixed with the "L" character (before the opening string
670 * quotation mark) are considered to be Unicode strings, and may be used instead
671 * of an explicit array of ASCII characters.
672 */
673 } USB_StdDescriptor_String_t;
674
675 /* Private Interface - For use in library only: */
676 #if !defined(__DOXYGEN__)
677 /* Macros: */
678 #define VERSION_TENS(x) (int)((x) / 10)
679 #define VERSION_ONES(x) (int)((x) - (10 * VERSION_TENS(x)))
680 #define VERSION_TENTHS(x) (int)(((x) - (int)(x)) * 10)
681 #define VERSION_HUNDREDTHS(x) (int)((((x) - (int)(x)) * 100) - (10 * VERSION_TENTHS(x)))
682 #endif
683
684 /* Disable C linkage for C++ Compilers: */
685 #if defined(__cplusplus)
686 }
687 #endif
688
689 #endif
690
691 /** @} */
692