Add descriptor class, subclass and protocol constants to the class drivers, modify...
[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.fourwalledcubicle.com
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 /** Can be masked with an endpoint address for a \ref USB_Descriptor_Endpoint_t endpoint descriptor's
123 * EndpointAddress value to indicate to the host that the endpoint is of the IN direction (i.e, from
124 * device to host).
125 */
126 #define ENDPOINT_DESCRIPTOR_DIR_IN 0x80
127
128 /** Can be masked with an endpoint address for a \ref USB_Descriptor_Endpoint_t endpoint descriptor's
129 * EndpointAddress value to indicate to the host that the endpoint is of the OUT direction (i.e, from
130 * host to device).
131 */
132 #define ENDPOINT_DESCRIPTOR_DIR_OUT 0x00
133
134 /** Can be masked with other configuration descriptor attributes for a \ref USB_Descriptor_Configuration_Header_t
135 * descriptor's ConfigAttributes value to indicate that the specified configuration can draw its power
136 * from the host's VBUS line.
137 */
138 #define USB_CONFIG_ATTR_BUSPOWERED 0x80
139
140 /** Can be masked with other configuration descriptor attributes for a \ref USB_Descriptor_Configuration_Header_t
141 * descriptor's ConfigAttributes value to indicate that the specified configuration can draw its power
142 * from the device's own power source.
143 */
144 #define USB_CONFIG_ATTR_SELFPOWERED 0x40
145
146 /** Can be masked with other configuration descriptor attributes for a \ref USB_Descriptor_Configuration_Header_t
147 * descriptor's ConfigAttributes value to indicate that the specified configuration supports the
148 * remote wakeup feature of the USB standard, allowing a suspended USB device to wake up the host upon
149 * request.
150 */
151 #define USB_CONFIG_ATTR_REMOTEWAKEUP 0x20
152
153 /** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
154 * Attributes value to indicate that the specified endpoint is not synchronized.
155 *
156 * \see The USB specification for more details on the possible Endpoint attributes.
157 */
158 #define ENDPOINT_ATTR_NO_SYNC (0 << 2)
159
160 /** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
161 * Attributes value to indicate that the specified endpoint is asynchronous.
162 *
163 * \see The USB specification for more details on the possible Endpoint attributes.
164 */
165 #define ENDPOINT_ATTR_ASYNC (1 << 2)
166
167 /** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
168 * Attributes value to indicate that the specified endpoint is adaptive.
169 *
170 * \see The USB specification for more details on the possible Endpoint attributes.
171 */
172 #define ENDPOINT_ATTR_ADAPTIVE (2 << 2)
173
174 /** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
175 * Attributes value to indicate that the specified endpoint is synchronized.
176 *
177 * \see The USB specification for more details on the possible Endpoint attributes.
178 */
179 #define ENDPOINT_ATTR_SYNC (3 << 2)
180
181 /** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
182 * Attributes value to indicate that the specified endpoint is used for data transfers.
183 *
184 * \see The USB specification for more details on the possible Endpoint usage attributes.
185 */
186 #define ENDPOINT_USAGE_DATA (0 << 4)
187
188 /** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
189 * Attributes value to indicate that the specified endpoint is used for feedback.
190 *
191 * \see The USB specification for more details on the possible Endpoint usage attributes.
192 */
193 #define ENDPOINT_USAGE_FEEDBACK (1 << 4)
194
195 /** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
196 * Attributes value to indicate that the specified endpoint is used for implicit feedback.
197 *
198 * \see The USB specification for more details on the possible Endpoint usage attributes.
199 */
200 #define ENDPOINT_USAGE_IMPLICIT_FEEDBACK (2 << 4)
201
202 /* Enums: */
203 /** Enum for the possible standard descriptor types, as given in each descriptor's header. */
204 enum USB_DescriptorTypes_t
205 {
206 DTYPE_Device = 0x01, /**< Indicates that the descriptor is a device descriptor. */
207 DTYPE_Configuration = 0x02, /**< Indicates that the descriptor is a configuration descriptor. */
208 DTYPE_String = 0x03, /**< Indicates that the descriptor is a string descriptor. */
209 DTYPE_Interface = 0x04, /**< Indicates that the descriptor is an interface descriptor. */
210 DTYPE_Endpoint = 0x05, /**< Indicates that the descriptor is an endpoint descriptor. */
211 DTYPE_DeviceQualifier = 0x06, /**< Indicates that the descriptor is a device qualifier descriptor. */
212 DTYPE_Other = 0x07, /**< Indicates that the descriptor is of other type. */
213 DTYPE_InterfacePower = 0x08, /**< Indicates that the descriptor is an interface power descriptor. */
214 DTYPE_InterfaceAssociation = 0x0B, /**< Indicates that the descriptor is an interface association descriptor. */
215 DTYPE_CSInterface = 0x24, /**< Indicates that the descriptor is a class specific interface descriptor. */
216 DTYPE_CSEndpoint = 0x25, /**< Indicates that the descriptor is a class specific endpoint descriptor. */
217 };
218
219 /** Enum for possible Class, Subclass and Protocol values of device and interface descriptors. */
220 enum USB_Descriptor_ClassSubclassProtocol_t
221 {
222 USB_CSCP_NoDeviceClass = 0x00, /**< Descriptor Class value indicating that the device does not belong
223 * to a particular class at the device level.
224 */
225 USB_CSCP_NoDeviceSubclass = 0x00, /**< Descriptor Subclass value indicating that the device does not belong
226 * to a particular subclass at the device level.
227 */
228 USB_CSCP_NoDeviceProtocol = 0x00, /**< Descriptor Protocol value indicating that the device does not belong
229 * to a particular protocol at the device level.
230 */
231 USB_CSCP_VendorSpecificClass = 0xFF, /**< Descriptor Class value indicating that the device/interface belongs
232 * to a vendor specific class.
233 */
234 USB_CSCP_VendorSpecificSubclass = 0xFF, /**< Descriptor Subclass value indicating that the device/interface belongs
235 * to a vendor specific subclass.
236 */
237 USB_CSCP_VendorSpecificProtocol = 0xFF, /**< Descriptor Protocol value indicating that the device/interface belongs
238 * to a vendor specific protocol.
239 */
240 USB_CSCP_IADDeviceClass = 0xEF, /**< Descriptor Class value indicating that the device belongs to the
241 * Interface Association Descriptor class.
242 */
243 USB_CSCP_IADDeviceSubclass = 0x02, /**< Descriptor Subclass value indicating that the device belongs to the
244 * Interface Association Descriptor subclass.
245 */
246 USB_CSCP_IADDeviceProtocol = 0x01, /**< Descriptor Protocol value indicating that the device belongs to the
247 * Interface Association Descriptor protocol.
248 */
249 };
250
251 /* Type Defines: */
252 /** \brief Standard USB Descriptor Header (LUFA naming conventions).
253 *
254 * Type define for all descriptors' standard header, indicating the descriptor's length and type. This structure
255 * uses LUFA-specific element names to make each element's purpose clearer.
256 *
257 * \see \ref USB_StdDescriptor_Header_t for the version of this type with standard element names.
258 */
259 typedef struct
260 {
261 uint8_t Size; /**< Size of the descriptor, in bytes. */
262 uint8_t Type; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
263 * given by the specific class.
264 */
265 } USB_Descriptor_Header_t;
266
267 /** \brief Standard USB Descriptor Header (USB-IF naming conventions).
268 *
269 * Type define for all descriptors' standard header, indicating the descriptor's length and type. This structure
270 * uses the relevant standard's given element names to ensure compatibility with the standard.
271 *
272 * \see \ref USB_Descriptor_Header_t for the version of this type with non-standard LUFA specific element names.
273 */
274 typedef struct
275 {
276 uint8_t bLength; /**< Size of the descriptor, in bytes. */
277 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
278 * given by the specific class.
279 */
280 } USB_StdDescriptor_Header_t;
281
282 /** \brief Standard USB Device Descriptor (LUFA naming conventions).
283 *
284 * Type define for a standard Device Descriptor. This structure uses LUFA-specific element names to make each
285 * element's purpose clearer.
286 *
287 * \see \ref USB_StdDescriptor_Device_t for the version of this type with standard element names.
288 */
289 typedef struct
290 {
291 USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
292
293 uint16_t USBSpecification; /**< BCD of the supported USB specification. */
294 uint8_t Class; /**< USB device class. */
295 uint8_t SubClass; /**< USB device subclass. */
296 uint8_t Protocol; /**< USB device protocol. */
297
298 uint8_t Endpoint0Size; /**< Size of the control (address 0) endpoint's bank in bytes. */
299
300 uint16_t VendorID; /**< Vendor ID for the USB product. */
301 uint16_t ProductID; /**< Unique product ID for the USB product. */
302 uint16_t ReleaseNumber; /**< Product release (version) number. */
303
304 uint8_t ManufacturerStrIndex; /**< String index for the manufacturer's name. The
305 * host will request this string via a separate
306 * control request for the string descriptor.
307 *
308 * \note If no string supplied, use \ref NO_DESCRIPTOR.
309 */
310 uint8_t ProductStrIndex; /**< String index for the product name/details.
311 *
312 * \see ManufacturerStrIndex structure entry.
313 */
314 uint8_t SerialNumStrIndex; /**< String index for the product's globally unique hexadecimal
315 * serial number, in uppercase Unicode ASCII.
316 *
317 * \note On some AVR models, there is an embedded serial number
318 * in the chip which can be used for the device serial number.
319 * To use this serial number, set this to USE_INTERNAL_SERIAL.
320 * On unsupported devices, this will evaluate to 0 and will cause
321 * the host to generate a pseudo-unique value for the device upon
322 * insertion.
323 *
324 * \see ManufacturerStrIndex structure entry.
325 */
326 uint8_t NumberOfConfigurations; /**< Total number of configurations supported by
327 * the device.
328 */
329 } USB_Descriptor_Device_t;
330
331 /** \brief Standard USB Device Descriptor (USB-IF naming conventions).
332 *
333 * Type define for a standard Device Descriptor. This structure uses the relevant standard's given element names
334 * to ensure compatibility with the standard.
335 *
336 * \see \ref USB_Descriptor_Device_t for the version of this type with non-standard LUFA specific element names.
337 */
338 typedef struct
339 {
340 uint8_t bLength; /**< Size of the descriptor, in bytes. */
341 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
342 * given by the specific class.
343 */
344 uint16_t bcdUSB; /**< BCD of the supported USB specification. */
345 uint8_t bDeviceClass; /**< USB device class. */
346 uint8_t bDeviceSubClass; /**< USB device subclass. */
347 uint8_t bDeviceProtocol; /**< USB device protocol. */
348 uint8_t bMaxPacketSize0; /**< Size of the control (address 0) endpoint's bank in bytes. */
349 uint16_t idVendor; /**< Vendor ID for the USB product. */
350 uint16_t idProduct; /**< Unique product ID for the USB product. */
351 uint16_t bcdDevice; /**< Product release (version) number. */
352 uint8_t iManufacturer; /**< String index for the manufacturer's name. The
353 * host will request this string via a separate
354 * control request for the string descriptor.
355 *
356 * \note If no string supplied, use \ref NO_DESCRIPTOR.
357 */
358 uint8_t iProduct; /**< String index for the product name/details.
359 *
360 * \see ManufacturerStrIndex structure entry.
361 */
362 uint8_t iSerialNumber; /**< String index for the product's globally unique hexadecimal
363 * serial number, in uppercase Unicode ASCII.
364 *
365 * \note On some AVR models, there is an embedded serial number
366 * in the chip which can be used for the device serial number.
367 * To use this serial number, set this to USE_INTERNAL_SERIAL.
368 * On unsupported devices, this will evaluate to 0 and will cause
369 * the host to generate a pseudo-unique value for the device upon
370 * insertion.
371 *
372 * \see ManufacturerStrIndex structure entry.
373 */
374 uint8_t bNumConfigurations; /**< Total number of configurations supported by
375 * the device.
376 */
377 } USB_StdDescriptor_Device_t;
378
379 /** \brief Standard USB Configuration Descriptor (LUFA naming conventions).
380 *
381 * Type define for a standard Configuration Descriptor header. This structure uses LUFA-specific element names
382 * to make each element's purpose clearer.
383 *
384 * \see \ref USB_StdDescriptor_Configuration_Header_t for the version of this type with standard element names.
385 */
386 typedef struct
387 {
388 USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
389
390 uint16_t TotalConfigurationSize; /**< Size of the configuration descriptor header,
391 * and all sub descriptors inside the configuration.
392 */
393 uint8_t TotalInterfaces; /**< Total number of interfaces in the configuration. */
394
395 uint8_t ConfigurationNumber; /**< Configuration index of the current configuration. */
396 uint8_t ConfigurationStrIndex; /**< Index of a string descriptor describing the configuration. */
397
398 uint8_t ConfigAttributes; /**< Configuration attributes, comprised of a mask of zero or
399 * more USB_CONFIG_ATTR_* masks.
400 */
401
402 uint8_t MaxPowerConsumption; /**< Maximum power consumption of the device while in the
403 * current configuration, calculated by the \ref USB_CONFIG_POWER_MA()
404 * macro.
405 */
406 } USB_Descriptor_Configuration_Header_t;
407
408 /** \brief Standard USB Configuration Descriptor (USB-IF naming conventions).
409 *
410 * Type define for a standard Configuration Descriptor header. This structure uses the relevant standard's given element names
411 * to ensure compatibility with the standard.
412 *
413 * \see \ref USB_Descriptor_Device_t for the version of this type with non-standard LUFA specific element names.
414 */
415 typedef struct
416 {
417 uint8_t bLength; /**< Size of the descriptor, in bytes. */
418 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
419 * given by the specific class.
420 */
421 uint16_t wTotalLength; /**< Size of the configuration descriptor header,
422 * and all sub descriptors inside the configuration.
423 */
424 uint8_t bNumInterfaces; /**< Total number of interfaces in the configuration. */
425 uint8_t bConfigurationValue; /**< Configuration index of the current configuration. */
426 uint8_t iConfiguration; /**< Index of a string descriptor describing the configuration. */
427 uint8_t bmAttributes; /**< Configuration attributes, comprised of a mask of zero or
428 * more USB_CONFIG_ATTR_* masks.
429 */
430 uint8_t bMaxPower; /**< Maximum power consumption of the device while in the
431 * current configuration, calculated by the \ref USB_CONFIG_POWER_MA()
432 * macro.
433 */
434 } USB_StdDescriptor_Configuration_Header_t;
435
436 /** \brief Standard USB Interface Descriptor (LUFA naming conventions).
437 *
438 * Type define for a standard Interface Descriptor. This structure uses LUFA-specific element names
439 * to make each element's purpose clearer.
440 *
441 * \see \ref USB_StdDescriptor_Interface_t for the version of this type with standard element names.
442 */
443 typedef struct
444 {
445 USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
446
447 uint8_t InterfaceNumber; /**< Index of the interface in the current configuration. */
448 uint8_t AlternateSetting; /**< Alternate setting for the interface number. The same
449 * interface number can have multiple alternate settings
450 * with different endpoint configurations, which can be
451 * selected by the host.
452 */
453 uint8_t TotalEndpoints; /**< Total number of endpoints in the interface. */
454
455 uint8_t Class; /**< Interface class ID. */
456 uint8_t SubClass; /**< Interface subclass ID. */
457 uint8_t Protocol; /**< Interface protocol ID. */
458
459 uint8_t InterfaceStrIndex; /**< Index of the string descriptor describing the interface. */
460 } USB_Descriptor_Interface_t;
461
462 /** \brief Standard USB Interface Descriptor (USB-IF naming conventions).
463 *
464 * Type define for a standard Interface Descriptor. This structure uses the relevant standard's given element names
465 * to ensure compatibility with the standard.
466 *
467 * \see \ref USB_Descriptor_Interface_t for the version of this type with non-standard LUFA specific element names.
468 */
469 typedef struct
470 {
471 uint8_t bLength; /**< Size of the descriptor, in bytes. */
472 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
473 * given by the specific class.
474 */
475 uint8_t bInterfaceNumber; /**< Index of the interface in the current configuration. */
476 uint8_t bAlternateSetting; /**< Alternate setting for the interface number. The same
477 * interface number can have multiple alternate settings
478 * with different endpoint configurations, which can be
479 * selected by the host.
480 */
481 uint8_t bNumEndpoints; /**< Total number of endpoints in the interface. */
482 uint8_t bInterfaceClass; /**< Interface class ID. */
483 uint8_t bInterfaceSubClass; /**< Interface subclass ID. */
484 uint8_t bInterfaceProtocol; /**< Interface protocol ID. */
485 uint8_t iInterface; /**< Index of the string descriptor describing the
486 * interface.
487 */
488 } USB_StdDescriptor_Interface_t;
489
490 /** \brief Standard USB Interface Association Descriptor (LUFA naming conventions).
491 *
492 * Type define for a standard Interface Association Descriptor. This structure uses LUFA-specific element names
493 * to make each element's purpose clearer.
494 *
495 * This descriptor has been added as a supplement to the USB2.0 standard, in the ECN located at
496 * <a>http://www.usb.org/developers/docs/InterfaceAssociationDescriptor_ecn.pdf</a>. It allows composite
497 * devices with multiple interfaces related to the same function to have the multiple interfaces bound
498 * together at the point of enumeration, loading one generic driver for all the interfaces in the single
499 * function. Read the ECN for more information.
500 *
501 * \see \ref USB_StdDescriptor_Interface_Association_t for the version of this type with standard element names.
502 */
503 typedef struct
504 {
505 USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
506
507 uint8_t FirstInterfaceIndex; /**< Index of the first associated interface. */
508 uint8_t TotalInterfaces; /**< Total number of associated interfaces. */
509
510 uint8_t Class; /**< Interface class ID. */
511 uint8_t SubClass; /**< Interface subclass ID. */
512 uint8_t Protocol; /**< Interface protocol ID. */
513
514 uint8_t IADStrIndex; /**< Index of the string descriptor describing the
515 * interface association.
516 */
517 } USB_Descriptor_Interface_Association_t;
518
519 /** \brief Standard USB Interface Association Descriptor (USB-IF naming conventions).
520 *
521 * Type define for a standard Interface Association Descriptor. This structure uses the relevant standard's given
522 * element names to ensure compatibility with the standard.
523 *
524 * This descriptor has been added as a supplement to the USB2.0 standard, in the ECN located at
525 * <a>http://www.usb.org/developers/docs/InterfaceAssociationDescriptor_ecn.pdf</a>. It allows composite
526 * devices with multiple interfaces related to the same function to have the multiple interfaces bound
527 * together at the point of enumeration, loading one generic driver for all the interfaces in the single
528 * function. Read the ECN for more information.
529 *
530 * \see \ref USB_Descriptor_Interface_Association_t for the version of this type with non-standard LUFA specific
531 * element names.
532 */
533 typedef struct
534 {
535 uint8_t bLength; /**< Size of the descriptor, in bytes. */
536 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
537 * given by the specific class.
538 */
539 uint8_t bFirstInterface; /**< Index of the first associated interface. */
540 uint8_t bInterfaceCount; /**< Total number of associated interfaces. */
541 uint8_t bFunctionClass; /**< Interface class ID. */
542 uint8_t bFunctionSubClass; /**< Interface subclass ID. */
543 uint8_t bFunctionProtocol; /**< Interface protocol ID. */
544 uint8_t iFunction; /**< Index of the string descriptor describing the
545 * interface association.
546 */
547 } USB_StdDescriptor_Interface_Association_t;
548
549 /** \brief Standard USB Endpoint Descriptor (LUFA naming conventions).
550 *
551 * Type define for a standard Endpoint Descriptor. This structure uses LUFA-specific element names
552 * to make each element's purpose clearer.
553 *
554 * \see \ref USB_StdDescriptor_Endpoint_t for the version of this type with standard element names.
555 */
556 typedef struct
557 {
558 USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
559
560 uint8_t EndpointAddress; /**< Logical address of the endpoint within the device for the current
561 * configuration, including direction mask.
562 */
563 uint8_t Attributes; /**< Endpoint attributes, comprised of a mask of the endpoint type (EP_TYPE_*)
564 * and attributes (ENDPOINT_ATTR_*) masks.
565 */
566 uint16_t EndpointSize; /**< Size of the endpoint bank, in bytes. This indicates the maximum packet
567 * size that the endpoint can receive at a time.
568 */
569 uint8_t PollingIntervalMS; /**< Polling interval in milliseconds for the endpoint if it is an INTERRUPT
570 * or ISOCHRONOUS type.
571 */
572 } USB_Descriptor_Endpoint_t;
573
574 /** \brief Standard USB Endpoint Descriptor (USB-IF naming conventions).
575 *
576 * Type define for a standard Endpoint Descriptor. This structure uses the relevant standard's given
577 * element names to ensure compatibility with the standard.
578 *
579 * \see \ref USB_Descriptor_Endpoint_t for the version of this type with non-standard LUFA specific
580 * element names.
581 */
582 typedef struct
583 {
584 uint8_t bLength; /**< Size of the descriptor, in bytes. */
585 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a
586 * value given by the specific class.
587 */
588 uint8_t bEndpointAddress; /**< Logical address of the endpoint within the device for the current
589 * configuration, including direction mask.
590 */
591 uint8_t bmAttributes; /**< Endpoint attributes, comprised of a mask of the endpoint type (EP_TYPE_*)
592 * and attributes (ENDPOINT_ATTR_*) masks.
593 */
594 uint16_t wMaxPacketSize; /**< Size of the endpoint bank, in bytes. This indicates the maximum packet size
595 * that the endpoint can receive at a time.
596 */
597 uint8_t bInterval; /**< Polling interval in milliseconds for the endpoint if it is an INTERRUPT or
598 * ISOCHRONOUS type.
599 */
600 } USB_StdDescriptor_Endpoint_t;
601
602 /** \brief Standard USB String Descriptor (LUFA naming conventions).
603 *
604 * Type define for a standard string descriptor. Unlike other standard descriptors, the length
605 * of the descriptor for placement in the descriptor header must be determined by the \ref USB_STRING_LEN()
606 * macro rather than by the size of the descriptor structure, as the length is not fixed.
607 *
608 * This structure should also be used for string index 0, which contains the supported language IDs for
609 * the device as an array.
610 *
611 * This structure uses LUFA-specific element names to make each element's purpose clearer.
612 *
613 * \see \ref USB_StdDescriptor_String_t for the version of this type with standard element names.
614 */
615 typedef struct
616 {
617 USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
618
619 wchar_t UnicodeString[]; /**< String data, as unicode characters (alternatively,
620 * string language IDs). If normal ASCII characters are
621 * to be used, they must be added as an array of characters
622 * rather than a normal C string so that they are widened to
623 * Unicode size.
624 *
625 * Under GCC, strings prefixed with the "L" character (before
626 * the opening string quotation mark) are considered to be
627 * Unicode strings, and may be used instead of an explicit
628 * array of ASCII characters.
629 */
630 } USB_Descriptor_String_t;
631
632 /** \brief Standard USB String Descriptor (USB-IF naming conventions).
633 *
634 * Type define for a standard string descriptor. Unlike other standard descriptors, the length
635 * of the descriptor for placement in the descriptor header must be determined by the \ref USB_STRING_LEN()
636 * macro rather than by the size of the descriptor structure, as the length is not fixed.
637 *
638 * This structure should also be used for string index 0, which contains the supported language IDs for
639 * the device as an array.
640 *
641 * This structure uses the relevant standard's given element names to ensure compatibility with the standard.
642 *
643 * \see \ref USB_Descriptor_String_t for the version of this type with with non-standard LUFA specific
644 * element names.
645 */
646 typedef struct
647 {
648 uint8_t bLength; /**< Size of the descriptor, in bytes. */
649 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t
650 * or a value given by the specific class.
651 */
652 int16_t bString[]; /**< String data, as unicode characters (alternatively, string language IDs).
653 * If normal ASCII characters are to be used, they must be added as an array
654 * of characters rather than a normal C string so that they are widened to
655 * Unicode size.
656 *
657 * Under GCC, strings prefixed with the "L" character (before the opening string
658 * quotation mark) are considered to be Unicode strings, and may be used instead
659 * of an explicit array of ASCII characters.
660 */
661 } USB_StdDescriptor_String_t;
662
663 /* Private Interface - For use in library only: */
664 #if !defined(__DOXYGEN__)
665 /* Macros: */
666 #define VERSION_TENS(x) (int)((x) / 10)
667 #define VERSION_ONES(x) (int)((x) - (10 * VERSION_TENS(x)))
668 #define VERSION_TENTHS(x) (int)(((x) - (int)(x)) * 10)
669 #define VERSION_HUNDREDTHS(x) (int)((((x) - (int)(x)) * 100) - (10 * VERSION_TENTHS(x)))
670 #endif
671
672 /* Disable C linkage for C++ Compilers: */
673 #if defined(__cplusplus)
674 }
675 #endif
676
677 #endif
678
679 /** @} */
680