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