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