X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/f3ec62b5c689d9c66b07a57df76ca83881ce3fe3..c029d72b9497ebf554c9d05ec58d48d7534b8a2f:/LUFA/Drivers/USB/Core/StdDescriptors.h diff --git a/LUFA/Drivers/USB/Core/StdDescriptors.h b/LUFA/Drivers/USB/Core/StdDescriptors.h index 8599f47aa..e3d925502 100644 --- a/LUFA/Drivers/USB/Core/StdDescriptors.h +++ b/LUFA/Drivers/USB/Core/StdDescriptors.h @@ -76,19 +76,29 @@ */ #define NO_DESCRIPTOR 0 - /** Macro to calculate the power value for the configuration descriptor, from a given number of milliamperes. */ + /** Macro to calculate the power value for the configuration descriptor, from a given number of milliamperes. + * + * \param[in] mA Maximum number of milliamps the device consumes when the given configuration is selected. + */ #define USB_CONFIG_POWER_MA(mA) ((mA) >> 1) /** Macro to calculate the Unicode length of a string with a given number of Unicode characters. * Should be used in string descriptor's headers for giving the string descriptor's byte length. + * + * \param[in] UnicodeChars Number of Unicode characters in the string text. */ - #define USB_STRING_LEN(str) (sizeof(USB_Descriptor_Header_t) + ((str) << 1)) + #define USB_STRING_LEN(UnicodeChars) (sizeof(USB_Descriptor_Header_t) + ((UnicodeChars) << 1)) /** Macro to encode a given four digit floating point version number (e.g. 01.23) into Binary Coded * Decimal format for descriptor fields requiring BCD encoding, such as the USB version number in the * standard device descriptor. + * + * \note This value is automatically converted into Little Endian, suitable for direct use inside device + * descriptors on all architectures without endianness conversion macros. + * + * \param[in] x Version number to encode as a 16-bit little-endian number, as a floating point number. */ - #define VERSION_BCD(x) ((((VERSION_TENS(x) << 4) | VERSION_ONES(x)) << 8) | \ + #define VERSION_BCD(x) CPU_TO_LE16((((VERSION_TENS(x) << 4) | VERSION_ONES(x)) << 8) | \ ((VERSION_TENTHS(x) << 4) | VERSION_HUNDREDTHS(x))) /** String language ID for the English language. Should be used in \ref USB_Descriptor_String_t descriptors @@ -244,6 +254,8 @@ * uses LUFA-specific element names to make each element's purpose clearer. * * \see \ref USB_StdDescriptor_Header_t for the version of this type with standard element names. + * + * \note Regardless of CPU architecture, these values should be stored as little endian. */ typedef struct { @@ -251,7 +263,7 @@ uint8_t Type; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value * given by the specific class. */ - } USB_Descriptor_Header_t; + } ATTR_PACKED USB_Descriptor_Header_t; /** \brief Standard USB Descriptor Header (USB-IF naming conventions). * @@ -259,6 +271,8 @@ * uses the relevant standard's given element names to ensure compatibility with the standard. * * \see \ref USB_Descriptor_Header_t for the version of this type with non-standard LUFA specific element names. + * + * \note Regardless of CPU architecture, these values should be stored as little endian. */ typedef struct { @@ -266,7 +280,7 @@ uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value * given by the specific class. */ - } USB_StdDescriptor_Header_t; + } ATTR_PACKED USB_StdDescriptor_Header_t; /** \brief Standard USB Device Descriptor (LUFA naming conventions). * @@ -274,6 +288,8 @@ * element's purpose clearer. * * \see \ref USB_StdDescriptor_Device_t for the version of this type with standard element names. + * + * \note Regardless of CPU architecture, these values should be stored as little endian. */ typedef struct { @@ -315,7 +331,7 @@ uint8_t NumberOfConfigurations; /**< Total number of configurations supported by * the device. */ - } USB_Descriptor_Device_t; + } ATTR_PACKED USB_Descriptor_Device_t; /** \brief Standard USB Device Descriptor (USB-IF naming conventions). * @@ -323,6 +339,8 @@ * to ensure compatibility with the standard. * * \see \ref USB_Descriptor_Device_t for the version of this type with non-standard LUFA specific element names. + * + * \note Regardless of CPU architecture, these values should be stored as little endian. */ typedef struct { @@ -363,7 +381,7 @@ uint8_t bNumConfigurations; /**< Total number of configurations supported by * the device. */ - } USB_StdDescriptor_Device_t; + } ATTR_PACKED USB_StdDescriptor_Device_t; /** \brief Standard USB Configuration Descriptor (LUFA naming conventions). * @@ -371,6 +389,8 @@ * to make each element's purpose clearer. * * \see \ref USB_StdDescriptor_Configuration_Header_t for the version of this type with standard element names. + * + * \note Regardless of CPU architecture, these values should be stored as little endian. */ typedef struct { @@ -392,7 +412,7 @@ * current configuration, calculated by the \ref USB_CONFIG_POWER_MA() * macro. */ - } USB_Descriptor_Configuration_Header_t; + } ATTR_PACKED USB_Descriptor_Configuration_Header_t; /** \brief Standard USB Configuration Descriptor (USB-IF naming conventions). * @@ -400,6 +420,8 @@ * to ensure compatibility with the standard. * * \see \ref USB_Descriptor_Device_t for the version of this type with non-standard LUFA specific element names. + * + * \note Regardless of CPU architecture, these values should be stored as little endian. */ typedef struct { @@ -420,7 +442,7 @@ * current configuration, calculated by the \ref USB_CONFIG_POWER_MA() * macro. */ - } USB_StdDescriptor_Configuration_Header_t; + } ATTR_PACKED USB_StdDescriptor_Configuration_Header_t; /** \brief Standard USB Interface Descriptor (LUFA naming conventions). * @@ -428,6 +450,8 @@ * to make each element's purpose clearer. * * \see \ref USB_StdDescriptor_Interface_t for the version of this type with standard element names. + * + * \note Regardless of CPU architecture, these values should be stored as little endian. */ typedef struct { @@ -446,7 +470,7 @@ uint8_t Protocol; /**< Interface protocol ID. */ uint8_t InterfaceStrIndex; /**< Index of the string descriptor describing the interface. */ - } USB_Descriptor_Interface_t; + } ATTR_PACKED USB_Descriptor_Interface_t; /** \brief Standard USB Interface Descriptor (USB-IF naming conventions). * @@ -454,6 +478,8 @@ * to ensure compatibility with the standard. * * \see \ref USB_Descriptor_Interface_t for the version of this type with non-standard LUFA specific element names. + * + * \note Regardless of CPU architecture, these values should be stored as little endian. */ typedef struct { @@ -474,7 +500,7 @@ uint8_t iInterface; /**< Index of the string descriptor describing the * interface. */ - } USB_StdDescriptor_Interface_t; + } ATTR_PACKED USB_StdDescriptor_Interface_t; /** \brief Standard USB Interface Association Descriptor (LUFA naming conventions). * @@ -488,6 +514,8 @@ * function. Read the ECN for more information. * * \see \ref USB_StdDescriptor_Interface_Association_t for the version of this type with standard element names. + * + * \note Regardless of CPU architecture, these values should be stored as little endian. */ typedef struct { @@ -503,7 +531,7 @@ uint8_t IADStrIndex; /**< Index of the string descriptor describing the * interface association. */ - } USB_Descriptor_Interface_Association_t; + } ATTR_PACKED USB_Descriptor_Interface_Association_t; /** \brief Standard USB Interface Association Descriptor (USB-IF naming conventions). * @@ -518,6 +546,8 @@ * * \see \ref USB_Descriptor_Interface_Association_t for the version of this type with non-standard LUFA specific * element names. + * + * \note Regardless of CPU architecture, these values should be stored as little endian. */ typedef struct { @@ -533,7 +563,7 @@ uint8_t iFunction; /**< Index of the string descriptor describing the * interface association. */ - } USB_StdDescriptor_Interface_Association_t; + } ATTR_PACKED USB_StdDescriptor_Interface_Association_t; /** \brief Standard USB Endpoint Descriptor (LUFA naming conventions). * @@ -541,6 +571,8 @@ * to make each element's purpose clearer. * * \see \ref USB_StdDescriptor_Endpoint_t for the version of this type with standard element names. + * + * \note Regardless of CPU architecture, these values should be stored as little endian. */ typedef struct { @@ -558,7 +590,7 @@ uint8_t PollingIntervalMS; /**< Polling interval in milliseconds for the endpoint if it is an INTERRUPT * or ISOCHRONOUS type. */ - } USB_Descriptor_Endpoint_t; + } ATTR_PACKED USB_Descriptor_Endpoint_t; /** \brief Standard USB Endpoint Descriptor (USB-IF naming conventions). * @@ -567,6 +599,8 @@ * * \see \ref USB_Descriptor_Endpoint_t for the version of this type with non-standard LUFA specific * element names. + * + * \note Regardless of CPU architecture, these values should be stored as little endian. */ typedef struct { @@ -586,7 +620,7 @@ uint8_t bInterval; /**< Polling interval in milliseconds for the endpoint if it is an INTERRUPT or * ISOCHRONOUS type. */ - } USB_StdDescriptor_Endpoint_t; + } ATTR_PACKED USB_StdDescriptor_Endpoint_t; /** \brief Standard USB String Descriptor (LUFA naming conventions). * @@ -600,23 +634,29 @@ * This structure uses LUFA-specific element names to make each element's purpose clearer. * * \see \ref USB_StdDescriptor_String_t for the version of this type with standard element names. + * + * \note Regardless of CPU architecture, these values should be stored as little endian. */ typedef struct { USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */ - wchar_t UnicodeString[]; /**< String data, as unicode characters (alternatively, - * string language IDs). If normal ASCII characters are - * to be used, they must be added as an array of characters - * rather than a normal C string so that they are widened to - * Unicode size. - * - * Under GCC, strings prefixed with the "L" character (before - * the opening string quotation mark) are considered to be - * Unicode strings, and may be used instead of an explicit - * array of ASCII characters. - */ - } USB_Descriptor_String_t; + #if (ARCH == ARCH_AVR8) + wchar_t UnicodeString[]; + #else + uint16_t UnicodeString[]; /**< String data, as unicode characters (alternatively, + * string language IDs). If normal ASCII characters are + * to be used, they must be added as an array of characters + * rather than a normal C string so that they are widened to + * Unicode size. + * + * Under GCC, strings prefixed with the "L" character (before + * the opening string quotation mark) are considered to be + * Unicode strings, and may be used instead of an explicit + * array of ASCII characters. + */ + #endif + } ATTR_PACKED USB_Descriptor_String_t; /** \brief Standard USB String Descriptor (USB-IF naming conventions). * @@ -631,6 +671,8 @@ * * \see \ref USB_Descriptor_String_t for the version of this type with with non-standard LUFA specific * element names. + * + * \note Regardless of CPU architecture, these values should be stored as little endian. */ typedef struct { @@ -638,16 +680,16 @@ uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t * or a value given by the specific class. */ - int16_t bString[]; /**< String data, as unicode characters (alternatively, string language IDs). - * If normal ASCII characters are to be used, they must be added as an array - * of characters rather than a normal C string so that they are widened to - * Unicode size. - * - * Under GCC, strings prefixed with the "L" character (before the opening string - * quotation mark) are considered to be Unicode strings, and may be used instead - * of an explicit array of ASCII characters. - */ - } USB_StdDescriptor_String_t; + uint16_t bString[]; /**< String data, as unicode characters (alternatively, string language IDs). + * If normal ASCII characters are to be used, they must be added as an array + * of characters rather than a normal C string so that they are widened to + * Unicode size. + * + * Under GCC, strings prefixed with the "L" character (before the opening string + * quotation mark) are considered to be Unicode strings, and may be used instead + * of an explicit array of ASCII characters. + */ + } ATTR_PACKED USB_StdDescriptor_String_t; /* Private Interface - For use in library only: */ #if !defined(__DOXYGEN__)