00001 /* ---------------------------------------------------------------------------- */ 00002 /* Atmel Microcontroller Software Support */ 00003 /* SAM Software Package License */ 00004 /* ---------------------------------------------------------------------------- */ 00005 /* Copyright (c) 2015, Atmel Corporation */ 00006 /* */ 00007 /* All rights reserved. */ 00008 /* */ 00009 /* Redistribution and use in source and binary forms, with or without */ 00010 /* modification, are permitted provided that the following condition is met: */ 00011 /* */ 00012 /* - Redistributions of source code must retain the above copyright notice, */ 00013 /* this list of conditions and the disclaimer below. */ 00014 /* */ 00015 /* Atmel's name may not be used to endorse or promote products derived from */ 00016 /* this software without specific prior written permission. */ 00017 /* */ 00018 /* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */ 00019 /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ 00020 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */ 00021 /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */ 00022 /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 00023 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */ 00024 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ 00025 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */ 00026 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */ 00027 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 00028 /* ---------------------------------------------------------------------------- */ 00029 00030 /** \file 00031 * \section Purpose 00032 * 00033 * Definitions and methods for USB descriptor structures described by the 00034 * USB specification. 00035 * 00036 * \section Usage 00037 * 00038 */ 00039 00040 #ifndef _USBDESCRIPTORS_H_ 00041 #define _USBDESCRIPTORS_H_ 00042 /** \addtogroup usb_general 00043 * @{ 00044 * \addtogroup usb_descriptor USB Descriptors 00045 * @{ 00046 */ 00047 00048 /*--------------------------------------------------------------------------- 00049 * Headers 00050 *---------------------------------------------------------------------------*/ 00051 00052 /* These headers were introduced in C99 by working group 00053 * ISO/IEC JTC1/SC22/WG14. 00054 */ 00055 #include <stdint.h> 00056 00057 /*--------------------------------------------------------------------------- 00058 * Definitions 00059 *---------------------------------------------------------------------------*/ 00060 00061 /*--------- Generic Descriptors --------*/ 00062 00063 /** \addtogroup usb_desc_type USB Descriptor types 00064 * @{ 00065 * This section lists the codes of the usb descriptor types 00066 * - \ref USBGenericDescriptor_DEVICE 00067 * - \ref USBGenericDescriptor_CONFIGURATION 00068 * - \ref USBGenericDescriptor_STRING 00069 * - \ref USBGenericDescriptor_INTERFACE 00070 * - \ref USBGenericDescriptor_ENDPOINT 00071 * - \ref USBGenericDescriptor_DEVICEQUALIFIER 00072 * - \ref USBGenericDescriptor_OTHERSPEEDCONFIGURATION 00073 * - \ref USBGenericDescriptor_INTERFACEPOWER 00074 * - \ref USBGenericDescriptor_OTG 00075 * - \ref USBGenericDescriptor_DEBUG 00076 * - \ref USBGenericDescriptor_INTERFACEASSOCIATION 00077 */ 00078 /** Device descriptor type. */ 00079 #define USBGenericDescriptor_DEVICE 1 00080 /** Configuration descriptor type. */ 00081 #define USBGenericDescriptor_CONFIGURATION 2 00082 /** String descriptor type. */ 00083 #define USBGenericDescriptor_STRING 3 00084 /** Interface descriptor type. */ 00085 #define USBGenericDescriptor_INTERFACE 4 00086 /** Endpoint descriptor type. */ 00087 #define USBGenericDescriptor_ENDPOINT 5 00088 /** Device qualifier descriptor type. */ 00089 #define USBGenericDescriptor_DEVICEQUALIFIER 6 00090 /** Other speed configuration descriptor type. */ 00091 #define USBGenericDescriptor_OTHERSPEEDCONFIGURATION 7 00092 /** Interface power descriptor type. */ 00093 #define USBGenericDescriptor_INTERFACEPOWER 8 00094 /** On-The-Go descriptor type. */ 00095 #define USBGenericDescriptor_OTG 9 00096 /** Debug descriptor type. */ 00097 #define USBGenericDescriptor_DEBUG 10 00098 /** Interface association descriptor type. */ 00099 #define USBGenericDescriptor_INTERFACEASSOCIATION 11 00100 00101 #define USB_DT_BOS 0x0F 00102 00103 #define USBGenericDescriptor_DEVICE_CAPABILITY 0x10 00104 /** @}*/ 00105 00106 /** USB protocol port */ 00107 00108 #define USB_EP_TYPE_MASK 0x03 00109 #define USB_EP_ADDR_MASK 0x0f 00110 /** 00111 * \brief Endpoint transfer direction is IN 00112 */ 00113 #define USB_EP_DIR_IN 0x80 00114 00115 /** 00116 * \brief Endpoint transfer direction is OUT 00117 */ 00118 #define USB_EP_DIR_OUT 0x00 00119 00120 /** 00121 * \brief USB request data transfer direction (bmRequestType) 00122 */ 00123 #define USB_REQ_DIR_OUT (0<<7) //!< Host to device 00124 #define USB_REQ_DIR_IN (1<<7) //!< Device to host 00125 #define USB_REQ_DIR_MASK (1<<7) //!< Mask 00126 00127 /** 00128 * \brief USB request types (bmRequestType) 00129 */ 00130 #define USB_REQ_TYPE_STANDARD (0<<5) //!< Standard request 00131 #define USB_REQ_TYPE_CLASS (1<<5) //!< Class-specific request 00132 #define USB_REQ_TYPE_VENDOR (2<<5) //!< Vendor-specific request 00133 #define USB_REQ_TYPE_MASK (3<<5) //!< Mask 00134 00135 /** 00136 * \brief USB recipient codes (bmRequestType) 00137 */ 00138 #define USB_REQ_RECIP_DEVICE (0<<0) //!< Recipient device 00139 #define USB_REQ_RECIP_INTERFACE (1<<0) //!< Recipient interface 00140 #define USB_REQ_RECIP_ENDPOINT (2<<0) //!< Recipient endpoint 00141 #define USB_REQ_RECIP_OTHER (3<<0) //!< Recipient other 00142 #define USB_REQ_RECIP_MASK (0x1F) //!< Mask 00143 00144 /** 00145 * \brief Standard USB requests (bRequest) 00146 */ 00147 enum usb_reqid { 00148 USB_REQ_GET_STATUS = 0, 00149 USB_REQ_CLEAR_FEATURE = 1, 00150 USB_REQ_SET_FEATURE = 3, 00151 USB_REQ_SET_ADDRESS = 5, 00152 USB_REQ_GET_DESCRIPTOR = 6, 00153 USB_REQ_SET_DESCRIPTOR = 7, 00154 USB_REQ_GET_CONFIGURATION = 8, 00155 USB_REQ_SET_CONFIGURATION = 9, 00156 USB_REQ_GET_INTERFACE = 10, 00157 USB_REQ_SET_INTERFACE = 11, 00158 USB_REQ_SYNCH_FRAME = 12, 00159 }; 00160 00161 /** 00162 * \brief USB Device Capability types 00163 */ 00164 enum usb_capability_type { 00165 USB_DC_USB20_EXTENSION = 0x02, 00166 }; 00167 00168 /** 00169 * \brief USB Device Capability - USB 2.0 Extension 00170 * To fill bmAttributes field of usb_capa_ext_desc_t structure. 00171 */ 00172 enum usb_capability_extension_attr { 00173 USB_DC_EXT_LPM = 0x00000002, 00174 USB_DC_EXT_BESL = 0x00000004, 00175 USB_DC_EXT_BESL_BASELINE_VALID = 0x00000008, 00176 USB_DC_EXT_BESL_DEEP_VALID = 0x00000010, 00177 }; 00178 #define USB_DC_EXT_BESL_DEEP_OFFSET 8 00179 #define USB_DC_EXT_BESL_DEEP(besl) ((besl & 0xF) << USB_DC_EXT_BESL_DEEP_OFFSET) 00180 #define USB_DC_EXT_BESL_BASELINE_OFFSET 12 00181 #define USB_DC_EXT_BESL_BASELINE(besl) ((besl & 0xF) << USB_DC_EXT_BESL_BASELINE_OFFSET) 00182 00183 #define BESL_125_US 0 00184 #define BESL_150_US 1 00185 #define BESL_200_US 2 00186 #define BESL_300_US 3 00187 #define BESL_400_US 4 00188 #define BESL_500_US 5 00189 #define BESL_1000_US 6 00190 #define BESL_2000_US 7 00191 #define BESL_3000_US 8 00192 #define BESL_4000_US 9 00193 #define BESL_5000_US 10 00194 #define BESL_6000_US 11 00195 #define BESL_7000_US 12 00196 #define BESL_8000_US 13 00197 #define BESL_9000_US 14 00198 #define BESL_10000_US 15 00199 00200 /** Fields definition from a LPM TOKEN */ 00201 #define USB_LPM_ATTRIBUT_BLINKSTATE_MASK (0xF << 0) 00202 #define USB_LPM_ATTRIBUT_BESL_MASK (0xF << 4) 00203 #define USB_LPM_ATTRIBUT_REMOTEWAKE_MASK (1 << 8) 00204 #define USB_LPM_ATTRIBUT_BLINKSTATE(value) ((value & 0xF) << 0) 00205 #define USB_LPM_ATTRIBUT_BESL(value) ((value & 0xF) << 4) 00206 #define USB_LPM_ATTRIBUT_REMOTEWAKE(value) ((value & 1) << 8) 00207 #define USB_LPM_ATTRIBUT_BLINKSTATE_L1 USB_LPM_ATTRIBUT_BLINKSTATE(1) 00208 00209 00210 /******** END usb protocol *////////// 00211 /*--------- Device Descriptors --------*/ 00212 00213 /** \addtogroup usb_release_number USB release numbers 00214 * @{ 00215 * This section lists the codes of USB release numbers. 00216 * - \ref USBDeviceDescriptor_USB2_00 00217 */ 00218 00219 /** The device supports USB 2.00. */ 00220 #define USBDeviceDescriptor_USB2_00 0x0200 00221 00222 /** The device supports USB 2.01. */ 00223 #define USBDeviceDescriptor_USB2_01 0x0201 00224 /** @}*/ 00225 00226 00227 /*--------- Configuration Descriptors --------*/ 00228 00229 /** \addtogroup usb_attributes USB Device Attributes 00230 * @{ 00231 * This section lists the codes of the usb attributes. 00232 * - \ref USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP 00233 * - \ref USBConfigurationDescriptor_SELFPOWERED_NORWAKEUP 00234 * - \ref USBConfigurationDescriptor_BUSPOWERED_RWAKEUP 00235 * - \ref USBConfigurationDescriptor_SELFPOWERED_RWAKEUP 00236 * - \ref USBConfigurationDescriptor_POWER 00237 */ 00238 /** Device is bus-powered and not support remote wake-up. */ 00239 #define USBConfigurationDescriptor_BUSPOWERED_NORWAKEUP 0x80 00240 /** Device is self-powered and not support remote wake-up. */ 00241 #define USBConfigurationDescriptor_SELFPOWERED_NORWAKEUP 0xC0 00242 /** Device is bus-powered and supports remote wake-up. */ 00243 #define USBConfigurationDescriptor_BUSPOWERED_RWAKEUP 0xA0 00244 /** Device is self-powered and supports remote wake-up. */ 00245 #define USBConfigurationDescriptor_SELFPOWERED_RWAKEUP 0xE0 00246 /** Device is self-powered and supports remote wake-up. */ 00247 #define USBConfigurationDescriptor_REMOTE_WAKEUP 0x20 00248 /** Device is bus-powered and supports remote wake-up. */ 00249 /** Calculates the value of the power consumption field given the value in mA. 00250 * \param power The power consumption value in mA 00251 * \return The value that should be set to the field in descriptor 00252 */ 00253 #define USBConfigurationDescriptor_POWER(power) (power / 2) 00254 00255 #define USB_HOST_POWER_MAX 500 00256 /** @}*/ 00257 00258 /** 00259 * \brief Standard USB Interface status flags 00260 * 00261 */ 00262 enum usb_interface_status { 00263 USB_IFACE_STATUS_RESERVED = 0 00264 }; 00265 00266 /** 00267 * \brief Standard USB endpoint status flags 00268 * 00269 */ 00270 enum usb_endpoint_status { 00271 USB_EP_STATUS_HALTED = 1, 00272 }; 00273 00274 /** 00275 * \brief Standard USB endpoint feature/status flags 00276 */ 00277 enum usb_endpoint_feature { 00278 USB_EP_FEATURE_HALT = 0, 00279 }; 00280 00281 /** 00282 * \brief Standard USB device feature flags 00283 * 00284 * \note valid for SetFeature request. 00285 */ 00286 enum usb_device_feature { 00287 USB_DEV_FEATURE_REMOTE_WAKEUP = 1, //!< Remote wakeup enabled 00288 USB_DEV_FEATURE_TEST_MODE = 2, //!< USB test mode 00289 USB_DEV_FEATURE_OTG_B_HNP_ENABLE = 3, 00290 USB_DEV_FEATURE_OTG_A_HNP_SUPPORT = 4, 00291 USB_DEV_FEATURE_OTG_A_ALT_HNP_SUPPORT = 5 00292 }; 00293 00294 /*--------- Endpoint Descriptors --------*/ 00295 00296 /** \addtogroup usb_ep_define USB Endpoint definitions 00297 * @{ 00298 * This section lists definitions and macro for endpoint descriptors. 00299 * - \ref usb_ep_dir USB Endpoint directions 00300 * - \ref USBEndpointDescriptor_OUT 00301 * - \ref USBEndpointDescriptor_IN 00302 * 00303 * - \ref usb_ep_type USB Endpoint types 00304 * - \ref USBEndpointDescriptor_CONTROL 00305 * - \ref USBEndpointDescriptor_ISOCHRONOUS 00306 * - \ref USBEndpointDescriptor_BULK 00307 * - \ref USBEndpointDescriptor_INTERRUPT 00308 * 00309 * - \ref usb_ep_size USB Endpoint maximum sizes 00310 * - \ref USBEndpointDescriptor_MAXCTRLSIZE_FS 00311 * - \ref USBEndpointDescriptor_MAXCTRLSIZE_HS 00312 * - \ref USBEndpointDescriptor_MAXBULKSIZE_FS 00313 * - \ref USBEndpointDescriptor_MAXBULKSIZE_HS 00314 * - \ref USBEndpointDescriptor_MAXINTERRUPTSIZE_FS 00315 * - \ref USBEndpointDescriptor_MAXINTERRUPTSIZE_HS 00316 * - \ref USBEndpointDescriptor_MAXISOCHRONOUSSIZE_FS 00317 * - \ref USBEndpointDescriptor_MAXISOCHRONOUSSIZE_HS 00318 * 00319 * - \ref usb_ep_addr USB Endpoint address define 00320 * - \ref USBEndpointDescriptor_ADDRESS 00321 */ 00322 00323 /** \addtogroup usb_ep_dir USB Endpoint directions 00324 * @{ 00325 * This section lists definitions of USB endpoint directions. 00326 * - USBEndpointDescriptor_OUT 00327 * - USBEndpointDescriptor_IN 00328 */ 00329 /** Endpoint receives data from the host. */ 00330 #define USBEndpointDescriptor_OUT 0 00331 /** Endpoint sends data to the host. */ 00332 #define USBEndpointDescriptor_IN 1 00333 00334 /** 00335 * \brief Endpoint transfer direction is IN 00336 */ 00337 #define USB_EP_DIR_IN 0x80 00338 00339 /** 00340 * \brief Endpoint transfer direction is OUT 00341 */ 00342 #define USB_EP_DIR_OUT 0x00 00343 /** @}*/ 00344 00345 /** \addtogroup usb_ep_type USB Endpoint types 00346 * @{ 00347 * This section lists definitions of USB endpoint types. 00348 * - \ref USBEndpointDescriptor_CONTROL 00349 * - \ref USBEndpointDescriptor_ISOCHRONOUS 00350 * - \ref USBEndpointDescriptor_BULK 00351 * - \ref USBEndpointDescriptor_INTERRUPT 00352 */ 00353 /** Control endpoint type. */ 00354 #define USBEndpointDescriptor_CONTROL 0 00355 /** Isochronous endpoint type. */ 00356 #define USBEndpointDescriptor_ISOCHRONOUS 1 00357 /** Bulk endpoint type. */ 00358 #define USBEndpointDescriptor_BULK 2 00359 /** Interrupt endpoint type. */ 00360 #define USBEndpointDescriptor_INTERRUPT 3 00361 00362 00363 /** Synchronisation Type for Isochronous endpoint type. */ 00364 #define USBEndpointDescriptor_Asynchronous_ISOCHRONOUS (1<<2) 00365 #define USBEndpointDescriptor_Adaptive_ISOCHRONOUS (2<<2) 00366 #define USBEndpointDescriptor_Synchronous_ISOCHRONOUS (3<<2) 00367 00368 /** Usage Type for Isochronous endpoint type. */ 00369 #define USBEndpointDescriptor_Feedback_ISOCHRONOUS (1<<2) 00370 #define USBEndpointDescriptor_Explicit_Feedback_ISOCHRONOUS (2<<2) 00371 /** @}*/ 00372 00373 /** \addtogroup usb_ep_size USB Endpoint maximum sizes 00374 * @{ 00375 * This section lists definitions of USB endpoint maximum sizes. 00376 * - \ref USBEndpointDescriptor_MAXCTRLSIZE_FS 00377 * - \ref USBEndpointDescriptor_MAXCTRLSIZE_HS 00378 * - \ref USBEndpointDescriptor_MAXBULKSIZE_FS 00379 * - \ref USBEndpointDescriptor_MAXBULKSIZE_HS 00380 * - \ref USBEndpointDescriptor_MAXINTERRUPTSIZE_FS 00381 * - \ref USBEndpointDescriptor_MAXINTERRUPTSIZE_HS 00382 * - \ref USBEndpointDescriptor_MAXISOCHRONOUSSIZE_FS 00383 * - \ref USBEndpointDescriptor_MAXISOCHRONOUSSIZE_HS 00384 */ 00385 /** Maximum size for a full-speed control endpoint. */ 00386 #define USBEndpointDescriptor_MAXCTRLSIZE_FS 64 00387 /** Maximum size for a high-speed control endpoint. */ 00388 #define USBEndpointDescriptor_MAXCTRLSIZE_HS 64 00389 /** Maximum size for a full-speed bulk endpoint. */ 00390 #define USBEndpointDescriptor_MAXBULKSIZE_FS 64 00391 /** Maximum size for a high-speed bulk endpoint. */ 00392 #define USBEndpointDescriptor_MAXBULKSIZE_HS 512 00393 /** Maximum size for a full-speed interrupt endpoint. */ 00394 #define USBEndpointDescriptor_MAXINTERRUPTSIZE_FS 64 00395 /** Maximum size for a high-speed interrupt endpoint. */ 00396 #define USBEndpointDescriptor_MAXINTERRUPTSIZE_HS 1024 00397 /** Maximum size for a full-speed isochronous endpoint. */ 00398 #define USBEndpointDescriptor_MAXISOCHRONOUSSIZE_FS 1023 00399 /** Maximum size for a high-speed isochronous endpoint. */ 00400 #define USBEndpointDescriptor_MAXISOCHRONOUSSIZE_HS 1024 00401 /** @}*/ 00402 00403 /** \addtogroup usb_ep_addr USB Endpoint address define 00404 * @{ 00405 * This section lists macro for USB endpoint address definition. 00406 * - \ref USBEndpointDescriptor_ADDRESS 00407 */ 00408 /** 00409 * Calculates the address of an endpoint given its number and direction 00410 * \param direction USB endpoint direction definition 00411 * \param number USB endpoint number 00412 * \return The value used to set the endpoint descriptor based on input number 00413 * and direction 00414 */ 00415 #define USBEndpointDescriptor_ADDRESS(direction, number) \ 00416 (((direction & 0x01) << 7) | (number & 0xF)) 00417 /** @}*/ 00418 /** @}*/ 00419 00420 00421 /*--------- Generic Descriptors --------*/ 00422 00423 /** \addtogroup usb_string_descriptor USB String Descriptor Definitions 00424 * @{ 00425 * This section lists the codes and macros for USB string descriptor definition. 00426 * 00427 * \par Language IDs 00428 * - USBStringDescriptor_ENGLISH_US 00429 * 00430 * \par String Descriptor Length 00431 * - USBStringDescriptor_LENGTH 00432 * 00433 * \par ASCII to UNICODE conversion 00434 * - USBStringDescriptor_UNICODE 00435 */ 00436 /** Language ID for US English. */ 00437 #define USBStringDescriptor_ENGLISH_US 0x09, 0x04 00438 /** 00439 * Calculates the length of a string descriptor given the number of ascii 00440 * characters/language IDs in it. 00441 * \param length The ascii format string length. 00442 * \return The actual data length in bytes. 00443 */ 00444 #define USBStringDescriptor_LENGTH(length) ((length) * 2 + 2) 00445 /** 00446 * Converts an ascii character to its unicode representation. 00447 * \param ascii The ASCII character to convert 00448 * \return A 2-byte-array for the UNICODE based on given ASCII 00449 */ 00450 #define USBStringDescriptor_UNICODE(ascii) (ascii), 0 00451 /** @}*/ 00452 00453 00454 /*--------------------------------------------------------------------------- 00455 * Types 00456 *---------------------------------------------------------------------------*/ 00457 00458 /* 00459 * Function types 00460 */ 00461 00462 typedef uint32_t (*USBDescriptorParseFunction)(void *descriptor, void *parseArg); 00463 00464 00465 /* 00466 * Descriptor structs types 00467 */ 00468 #pragma pack(1) 00469 #if defined ( __CC_ARM ) /* Keil ¦̀Vision 4 */ 00470 #elif defined ( __ICCARM__ ) /* IAR Ewarm */ 00471 #define __attribute__(...) 00472 #define __packed__ packed 00473 #elif defined ( __GNUC__ ) /* GCC CS3 */ 00474 #define __packed__ aligned(1) 00475 #endif 00476 /** 00477 \typedef USBGenericDescriptor 00478 \brief Holds the few fields shared by all USB descriptors. 00479 */ 00480 typedef struct _USBGenericDescriptor { 00481 00482 /** Length of the descriptor in bytes. */ 00483 uint8_t bLength; 00484 /** Descriptor type. */ 00485 uint8_t bDescriptorType; 00486 00487 } __attribute__ ((__packed__)) USBGenericDescriptor; /* GCC */ 00488 00489 /** 00490 * \typedef USBDeviceDescriptor 00491 * \brief USB standard device descriptor structure. 00492 */ 00493 typedef struct _USBDeviceDescriptor { 00494 00495 /** Size of this descriptor in bytes. */ 00496 uint8_t bLength; 00497 /** Descriptor type (USBGenericDescriptor_DEVICE). */ 00498 uint8_t bDescriptorType; 00499 /** USB specification release number in BCD format. */ 00500 uint16_t bcdUSB; 00501 /** Device class code. */ 00502 uint8_t bDeviceClass; 00503 /** Device subclass code. */ 00504 uint8_t bDeviceSubClass; 00505 /** Device protocol code. */ 00506 uint8_t bDeviceProtocol; 00507 /** Maximum packet size of endpoint 0 (in bytes). */ 00508 uint8_t bMaxPacketSize0; 00509 /** Vendor ID. */ 00510 uint16_t idVendor; 00511 /** Product ID. */ 00512 uint16_t idProduct; 00513 /** Device release number in BCD format. */ 00514 uint16_t bcdDevice; 00515 /** Index of the manufacturer string descriptor. */ 00516 uint8_t iManufacturer; 00517 /** Index of the product string descriptor. */ 00518 uint8_t iProduct; 00519 /** Index of the serial number string descriptor. */ 00520 uint8_t iSerialNumber; 00521 /** Number of possible configurations for the device. */ 00522 uint8_t bNumConfigurations; 00523 00524 } __attribute__ ((__packed__)) USBDeviceDescriptor; /* GCC */ 00525 00526 /** 00527 * \typedef USBOtgDescriptor 00528 * \brief USB On-The-Go descriptor struct. 00529 */ 00530 typedef struct _USBOtgDescriptor { 00531 00532 /** Size of this descriptor in bytes. */ 00533 uint8_t bLength; 00534 /** Descriptor type (USBGenericDescriptor_OTG). */ 00535 uint8_t bDescriptorType; 00536 /** Attribute Fields D7?: Reserved D1: HNP support D0: SRP support */ 00537 uint8_t bmAttributes; 00538 00539 } __attribute__ ((__packed__)) USBOtgDescriptor; /* GCC */ 00540 00541 /** 00542 * \typedef USBDeviceQualifierDescriptor 00543 * \brief Alternate device descriptor indicating the capabilities of the device 00544 * in full-speed, if currently in high-speed; or in high-speed, if it is 00545 * currently in full-speed. Only relevant for devices supporting the 00546 * high-speed mode. 00547 */ 00548 typedef struct _USBDeviceQualifierDescriptor { 00549 00550 /** Size of the descriptor in bytes. */ 00551 uint8_t bLength; 00552 /** Descriptor type (USBDESC_DEVICE_QUALIFIER or "USB device types"). */ 00553 uint8_t bDescriptorType; 00554 /** USB specification release number (in BCD format). */ 00555 uint16_t bcdUSB; 00556 /** Device class code. */ 00557 uint8_t bDeviceClass; 00558 /** Device subclass code. */ 00559 uint8_t bDeviceSubClass; 00560 /** Device protocol code. */ 00561 uint8_t bDeviceProtocol; 00562 /** Maximum packet size of endpoint 0. */ 00563 uint8_t bMaxPacketSize0; 00564 /** Number of possible configurations for the device. */ 00565 uint8_t bNumConfigurations; 00566 /** Reserved. */ 00567 uint8_t bReserved; 00568 00569 } __attribute__ ((__packed__)) USBDeviceQualifierDescriptor; /* GCC */ 00570 00571 /** 00572 * \typedef USBConfigurationDescriptor 00573 * \brief USB standard configuration descriptor structure. 00574 */ 00575 typedef struct _USBConfigurationDescriptor { 00576 00577 /** Size of the descriptor in bytes. */ 00578 uint8_t bLength; 00579 /** Descriptor type 00580 (USBDESC_CONFIGURATION of \ref usb_desc_type USB Descriptor types). */ 00581 uint8_t bDescriptorType; 00582 /** Length of all descriptors returned along with this configuration 00583 descriptor. */ 00584 uint16_t wTotalLength; 00585 /** Number of interfaces in this configuration. */ 00586 uint8_t bNumInterfaces; 00587 /** Value for selecting this configuration. */ 00588 uint8_t bConfigurationValue; 00589 /** Index of the configuration string descriptor. */ 00590 uint8_t iConfiguration; 00591 /** Configuration characteristics. */ 00592 uint8_t bmAttributes; 00593 /** Maximum power consumption of the device when in this configuration. */ 00594 uint8_t bMaxPower; 00595 00596 } __attribute__ ((__packed__)) USBConfigurationDescriptor; /* GCC*/ 00597 00598 /** 00599 * \typedef USBDeviceBOSDescriptor 00600 * \brief USB Device BOS descriptor structure 00601 * 00602 * The BOS descriptor (Binary device Object Store) defines a root 00603 * descriptor that is similar to the configuration descriptor, and is 00604 * the base descriptor for accessing a family of related descriptors. 00605 * A host can read a BOS descriptor and learn from the wTotalLength field 00606 * the entire size of the device-level descriptor set, or it can read in 00607 * the entire BOS descriptor set of device capabilities. 00608 * The host accesses this descriptor using the GetDescriptor() request. 00609 * The descriptor type in the GetDescriptor() request is set to BOS. 00610 */ 00611 typedef struct _USBDeviceBOSDescriptor{ 00612 uint8_t bLength; 00613 uint8_t bDescriptorType; 00614 uint16_t wTotalLength; 00615 uint8_t bNumDeviceCaps; 00616 } __attribute__ ((__packed__)) USBDeviceBOSDescriptor; 00617 00618 00619 /** 00620 * \typedef USBDeviceBOSDescriptor 00621 * \brief USB Device Capabilities - USB 2.0 Extension Descriptor structure 00622 * 00623 * Defines the set of USB 1.1-specific device level capabilities. 00624 */ 00625 typedef struct _USBDeviceCapabilities{ 00626 uint8_t bLength; 00627 uint8_t bDescriptorType; 00628 uint8_t bDevCapabilityType; 00629 uint32_t bmAttributes; 00630 } __attribute__ ((__packed__)) USBDeviceCapabilities; 00631 00632 /** 00633 * \brief USB Device LPM Descriptor structure 00634 * 00635 * The BOS descriptor and capabilities descriptors for LPM. 00636 */ 00637 typedef struct _USB_DeviceLPMDescriptor{ 00638 USBDeviceBOSDescriptor bos; 00639 USBDeviceCapabilities capa_ext; 00640 }__attribute__ ((__packed__)) USB_DeviceLPMDescriptor; 00641 00642 /** 00643 * \typedef USBInterfaceAssociationDescriptor 00644 * \brief 00645 */ 00646 typedef struct _USBInterfaceAssociationDescriptor { 00647 00648 /** Size of the descriptor in bytes. */ 00649 uint8_t bLength; 00650 /** Descriptor type (USBGenericDescriptor_INTERFACE). */ 00651 uint8_t bDescriptorType; 00652 /** First Interface . */ 00653 uint8_t bFirstInterface; 00654 /** Interface Count. */ 00655 uint8_t bInterfaceCount; 00656 /** Function function code. */ 00657 uint8_t bFunctionClass; 00658 /** Function subclass code. */ 00659 uint8_t bFunctionSubClass; 00660 /** Function protocol code. */ 00661 uint8_t bFunctionProtocol; 00662 /** Index of the function string descriptor. */ 00663 uint8_t iFunction; 00664 } __attribute__ ((__packed__)) USBInterfaceAssociationDescriptor; /* GCC*/ 00665 00666 /** 00667 * \typedef USBInterfaceDescriptor 00668 * \brief USB standard interface descriptor structure. 00669 */ 00670 typedef struct _USBInterfaceDescriptor { 00671 00672 /** Size of the descriptor in bytes. */ 00673 uint8_t bLength; 00674 /** Descriptor type (USBGenericDescriptor_INTERFACE). */ 00675 uint8_t bDescriptorType; 00676 /** Number of the interface in its configuration. */ 00677 uint8_t bInterfaceNumber; 00678 /** Value to select this alternate interface setting. */ 00679 uint8_t bAlternateSetting; 00680 /** Number of endpoints used by the interface (excluding endpoint 0). */ 00681 uint8_t bNumEndpoints; 00682 /** Interface class code. */ 00683 uint8_t bInterfaceClass; 00684 /** Interface subclass code. */ 00685 uint8_t bInterfaceSubClass; 00686 /** Interface protocol code. */ 00687 uint8_t bInterfaceProtocol; 00688 /** Index of the interface string descriptor. */ 00689 uint8_t iInterface; 00690 00691 } __attribute__ ((__packed__)) USBInterfaceDescriptor; /* GCC */ 00692 00693 /** 00694 * \typedef USBEndpointDescriptor 00695 * \brief USB standard endpoint descriptor structure. 00696 */ 00697 typedef struct _USBEndpointDescriptor { 00698 00699 /** Size of the descriptor in bytes. */ 00700 uint8_t bLength; 00701 /** Descriptor type (\ref USBGenericDescriptor_ENDPOINT). */ 00702 uint8_t bDescriptorType; 00703 /** Address and direction of the endpoint. */ 00704 uint8_t bEndpointAddress; 00705 /** Endpoint type and additional characteristics 00706 (for isochronous endpoints). */ 00707 uint8_t bmAttributes; 00708 /** Maximum packet size (in bytes) of the endpoint. */ 00709 uint16_t wMaxPacketSize; 00710 /** Polling rate of the endpoint. */ 00711 uint8_t bInterval; 00712 00713 } __attribute__ ((__packed__)) USBEndpointDescriptor; /* GCC*/ 00714 00715 00716 /** 00717 * \brief A standard USB string descriptor structure 00718 */ 00719 typedef struct { 00720 uint8_t bLength; 00721 uint8_t bDescriptorType; 00722 }__attribute__ ((__packed__)) USBStringDescriptor; 00723 00724 typedef struct { 00725 USBStringDescriptor desc; 00726 uint16_t string[1]; 00727 } __attribute__ ((__packed__))USBStringLangIdDescriptor; 00728 00729 00730 #pragma pack() 00731 00732 /*--------------------------------------------------------------------------- 00733 * Exported Functions 00734 *---------------------------------------------------------------------------*/ 00735 00736 extern uint32_t USBGenericDescriptor_GetLength( 00737 const USBGenericDescriptor *descriptor); 00738 00739 extern uint8_t USBGenericDescriptor_GetType( 00740 const USBGenericDescriptor *descriptor); 00741 00742 extern USBGenericDescriptor *USBGenericDescriptor_GetNextDescriptor( 00743 const USBGenericDescriptor *descriptor); 00744 00745 extern USBGenericDescriptor *USBGenericDescriptor_Parse( 00746 const USBGenericDescriptor * descriptor, 00747 uint32_t totalLength, 00748 USBDescriptorParseFunction parseFunction, 00749 void * parseArg); 00750 00751 00752 extern uint32_t USBConfigurationDescriptor_GetTotalLength( 00753 const USBConfigurationDescriptor *configuration); 00754 00755 extern uint8_t USBConfigurationDescriptor_GetNumInterfaces( 00756 const USBConfigurationDescriptor *configuration); 00757 00758 extern uint8_t USBConfigurationDescriptor_IsSelfPowered( 00759 const USBConfigurationDescriptor *configuration); 00760 00761 extern void USBConfigurationDescriptor_Parse( 00762 const USBConfigurationDescriptor *configuration, 00763 USBInterfaceDescriptor **interfaces, 00764 USBEndpointDescriptor **endpoints, 00765 USBGenericDescriptor **others); 00766 00767 extern uint8_t USBEndpointDescriptor_GetNumber( 00768 const USBEndpointDescriptor *endpoint); 00769 00770 extern uint8_t USBEndpointDescriptor_GetDirection( 00771 const USBEndpointDescriptor *endpoint); 00772 00773 extern uint8_t USBEndpointDescriptor_GetType( 00774 const USBEndpointDescriptor *endpoint); 00775 00776 extern uint16_t USBEndpointDescriptor_GetMaxPacketSize( 00777 const USBEndpointDescriptor *endpoint); 00778 00779 extern uint8_t USBEndpointDescriptor_GetInterval( 00780 const USBEndpointDescriptor *endpoint); 00781 00782 00783 /** @}*/ 00784 /**@}*/ 00785 #endif /* #ifndef _USBDESCRIPTORS_H_ */ 00786