1 /*********************************************************************** 2 * $Id:: mw_usbd.h 575 2012-11-20 01:35:56Z usb10131 $ 3 * 4 * Project: USB device ROM Stack 5 * 6 * Description: 7 * USB Definitions. 8 * 9 *********************************************************************** 10 * Copyright(C) 2011, NXP Semiconductor 11 * All rights reserved. 12 * 13 * Software that is described herein is for illustrative purposes only 14 * which provides customers with programming information regarding the 15 * products. This software is supplied "AS IS" without any warranties. 16 * NXP Semiconductors assumes no responsibility or liability for the 17 * use of the software, conveys no license or title under any patent, 18 * copyright, or mask work right to the product. NXP Semiconductors 19 * reserves the right to make changes in the software without 20 * notification. NXP Semiconductors also make no representation or 21 * warranty that such application will be suitable for the specified 22 * use without further testing or modification. 23 **********************************************************************/ 24 25 #ifndef __USBD_H__ 26 #define __USBD_H__ 27 28 /** \file 29 * \brief Common definitions and declarations for the USB stack. 30 * 31 * Common definitions and declarations for the USB stack. 32 * \addtogroup USBD_Core 33 * @{ 34 */ 35 36 #include "lpc_types.h" 37 38 #if defined(__GNUC__) 39 /* As per http://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html#Attribute-Syntax, 40 6.29 Attributes Syntax 41 "An attribute specifier list may appear as part of a struct, union or 42 enum specifier. It may go either immediately after the struct, union 43 or enum keyword, or after the closing brace. The former syntax is 44 preferred. Where attribute specifiers follow the closing brace, they 45 are considered to relate to the structure, union or enumerated type 46 defined, not to any enclosing declaration the type specifier appears 47 in, and the type defined is not complete until after the attribute 48 specifiers." 49 So use POST_PACK immediately after struct keyword 50 */ 51 #define PRE_PACK 52 #define POST_PACK __attribute__((__packed__)) 53 #define ALIGNED(n) __attribute__((aligned (n))) 54 55 #elif defined(__arm) 56 #define PRE_PACK __packed 57 #define POST_PACK 58 #define ALIGNED(n) __align(n) 59 60 #elif defined(__ICCARM__) 61 #define PRE_PACK __packed 62 #define POST_PACK 63 #define PRAGMA_ALIGN_4096 _Pragma("data_alignment=4096") 64 #define PRAGMA_ALIGN_2048 _Pragma("data_alignment=2048") 65 #define PRAGMA_ALIGN_256 _Pragma("data_alignment=256") 66 #define PRAGMA_ALIGN_128 _Pragma("data_alignment=128") 67 #define PRAGMA_ALIGN_64 _Pragma("data_alignment=64") 68 #define PRAGMA_ALIGN_48 _Pragma("data_alignment=48") 69 #define PRAGMA_ALIGN_32 _Pragma("data_alignment=32") 70 #define PRAGMA_ALIGN_4 _Pragma("data_alignment=4") 71 #define ALIGNED(n) PRAGMA_ALIGN_##n 72 73 #pragma diag_suppress=Pe021 74 #endif 75 76 /** Structure to pack lower and upper byte to form 16 bit word. */ 77 PRE_PACK struct POST_PACK _WB_T 78 { 79 uint8_t L; /**< lower byte */ 80 uint8_t H; /**< upper byte */ 81 }; 82 /** Structure to pack lower and upper byte to form 16 bit word.*/ 83 typedef struct _WB_T WB_T; 84 85 /** Union of \ref _WB_T struct and 16 bit word.*/ 86 PRE_PACK union POST_PACK __WORD_BYTE 87 { 88 uint16_t W; /**< data member to do 16 bit access */ 89 WB_T WB; /**< data member to do 8 bit access */ 90 } ; 91 /** Union of \ref _WB_T struct and 16 bit word.*/ 92 typedef union __WORD_BYTE WORD_BYTE; 93 94 /** bmRequestType.Dir defines 95 * @{ 96 */ 97 /** Request from host to device */ 98 #define REQUEST_HOST_TO_DEVICE 0 99 /** Request from device to host */ 100 #define REQUEST_DEVICE_TO_HOST 1 101 /** @} */ 102 103 /** bmRequestType.Type defines 104 * @{ 105 */ 106 /** Standard Request */ 107 #define REQUEST_STANDARD 0 108 /** Class Request */ 109 #define REQUEST_CLASS 1 110 /** Vendor Request */ 111 #define REQUEST_VENDOR 2 112 /** Reserved Request */ 113 #define REQUEST_RESERVED 3 114 /** @} */ 115 116 /** bmRequestType.Recipient defines 117 * @{ 118 */ 119 /** Request to device */ 120 #define REQUEST_TO_DEVICE 0 121 /** Request to interface */ 122 #define REQUEST_TO_INTERFACE 1 123 /** Request to endpoint */ 124 #define REQUEST_TO_ENDPOINT 2 125 /** Request to other */ 126 #define REQUEST_TO_OTHER 3 127 /** @} */ 128 129 /** Structure to define 8 bit USB request.*/ 130 PRE_PACK struct POST_PACK _BM_T 131 { 132 uint8_t Recipient : 5; /**< Recipient type. */ 133 uint8_t Type : 2; /**< Request type. */ 134 uint8_t Dir : 1; /**< Direction type. */ 135 }; 136 /** Structure to define 8 bit USB request.*/ 137 typedef struct _BM_T BM_T; 138 139 /** Union of \ref _BM_T struct and 8 bit byte.*/ 140 PRE_PACK union POST_PACK _REQUEST_TYPE 141 { 142 uint8_t B; /**< byte wide access memeber */ 143 BM_T BM; /**< bitfield structure access memeber */ 144 } ; 145 /** Union of \ref _BM_T struct and 8 bit byte.*/ 146 typedef union _REQUEST_TYPE REQUEST_TYPE; 147 148 /** USB Standard Request Codes 149 * @{ 150 */ 151 /** GET_STATUS request */ 152 #define USB_REQUEST_GET_STATUS 0 153 /** CLEAR_FEATURE request */ 154 #define USB_REQUEST_CLEAR_FEATURE 1 155 /** SET_FEATURE request */ 156 #define USB_REQUEST_SET_FEATURE 3 157 /** SET_ADDRESS request */ 158 #define USB_REQUEST_SET_ADDRESS 5 159 /** GET_DESCRIPTOR request */ 160 #define USB_REQUEST_GET_DESCRIPTOR 6 161 /** SET_DESCRIPTOR request */ 162 #define USB_REQUEST_SET_DESCRIPTOR 7 163 /** GET_CONFIGURATION request */ 164 #define USB_REQUEST_GET_CONFIGURATION 8 165 /** SET_CONFIGURATION request */ 166 #define USB_REQUEST_SET_CONFIGURATION 9 167 /** GET_INTERFACE request */ 168 #define USB_REQUEST_GET_INTERFACE 10 169 /** SET_INTERFACE request */ 170 #define USB_REQUEST_SET_INTERFACE 11 171 /** SYNC_FRAME request */ 172 #define USB_REQUEST_SYNC_FRAME 12 173 /** @} */ 174 175 /** USB GET_STATUS Bit Values 176 * @{ 177 */ 178 /** SELF_POWERED status*/ 179 #define USB_GETSTATUS_SELF_POWERED 0x01 180 /** REMOTE_WAKEUP capable status*/ 181 #define USB_GETSTATUS_REMOTE_WAKEUP 0x02 182 /** ENDPOINT_STALL status*/ 183 #define USB_GETSTATUS_ENDPOINT_STALL 0x01 184 /** @} */ 185 186 /** USB Standard Feature selectors 187 * @{ 188 */ 189 /** ENDPOINT_STALL feature*/ 190 #define USB_FEATURE_ENDPOINT_STALL 0 191 /** REMOTE_WAKEUP feature*/ 192 #define USB_FEATURE_REMOTE_WAKEUP 1 193 /** TEST_MODE feature*/ 194 #define USB_FEATURE_TEST_MODE 2 195 /** @} */ 196 197 /** USB Default Control Pipe Setup Packet*/ 198 PRE_PACK struct POST_PACK _USB_SETUP_PACKET 199 { 200 REQUEST_TYPE bmRequestType; /**< This bitmapped field identifies the characteristics 201 of the specific request. \sa _BM_T. 202 */ 203 uint8_t bRequest; /**< This field specifies the particular request. The 204 Type bits in the bmRequestType field modify the meaning 205 of this field. \sa USBD_REQUEST. 206 */ 207 WORD_BYTE wValue; /**< Used to pass a parameter to the device, specific 208 to the request. 209 */ 210 WORD_BYTE wIndex; /**< Used to pass a parameter to the device, specific 211 to the request. The wIndex field is often used in 212 requests to specify an endpoint or an interface. 213 */ 214 uint16_t wLength; /**< This field specifies the length of the data 215 transferred during the second phase of the control 216 transfer. 217 */ 218 } ; 219 /** USB Default Control Pipe Setup Packet*/ 220 typedef struct _USB_SETUP_PACKET USB_SETUP_PACKET; 221 222 223 /** USB Descriptor Types 224 * @{ 225 */ 226 /** Device descriptor type */ 227 #define USB_DEVICE_DESCRIPTOR_TYPE 1 228 /** Configuration descriptor type */ 229 #define USB_CONFIGURATION_DESCRIPTOR_TYPE 2 230 /** String descriptor type */ 231 #define USB_STRING_DESCRIPTOR_TYPE 3 232 /** Interface descriptor type */ 233 #define USB_INTERFACE_DESCRIPTOR_TYPE 4 234 /** Endpoint descriptor type */ 235 #define USB_ENDPOINT_DESCRIPTOR_TYPE 5 236 /** Device qualifier descriptor type */ 237 #define USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE 6 238 /** Other speed configuration descriptor type */ 239 #define USB_OTHER_SPEED_CONFIG_DESCRIPTOR_TYPE 7 240 /** Interface power descriptor type */ 241 #define USB_INTERFACE_POWER_DESCRIPTOR_TYPE 8 242 /** OTG descriptor type */ 243 #define USB_OTG_DESCRIPTOR_TYPE 9 244 /** Debug descriptor type */ 245 #define USB_DEBUG_DESCRIPTOR_TYPE 10 246 /** Interface association descriptor type */ 247 #define USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE 11 248 /** @} */ 249 250 /** USB Device Classes 251 * @{ 252 */ 253 /** Reserved device class */ 254 #define USB_DEVICE_CLASS_RESERVED 0x00 255 /** Audio device class */ 256 #define USB_DEVICE_CLASS_AUDIO 0x01 257 /** Communications device class */ 258 #define USB_DEVICE_CLASS_COMMUNICATIONS 0x02 259 /** Human interface device class */ 260 #define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03 261 /** monitor device class */ 262 #define USB_DEVICE_CLASS_MONITOR 0x04 263 /** physical interface device class */ 264 #define USB_DEVICE_CLASS_PHYSICAL_INTERFACE 0x05 265 /** power device class */ 266 #define USB_DEVICE_CLASS_POWER 0x06 267 /** Printer device class */ 268 #define USB_DEVICE_CLASS_PRINTER 0x07 269 /** Storage device class */ 270 #define USB_DEVICE_CLASS_STORAGE 0x08 271 /** Hub device class */ 272 #define USB_DEVICE_CLASS_HUB 0x09 273 /** miscellaneous device class */ 274 #define USB_DEVICE_CLASS_MISCELLANEOUS 0xEF 275 /** Application device class */ 276 #define USB_DEVICE_CLASS_APP 0xFE 277 /** Vendor specific device class */ 278 #define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF 279 /** @} */ 280 281 /** bmAttributes in Configuration Descriptor 282 * @{ 283 */ 284 /** Power field mask */ 285 #define USB_CONFIG_POWERED_MASK 0x40 286 /** Bus powered */ 287 #define USB_CONFIG_BUS_POWERED 0x80 288 /** Self powered */ 289 #define USB_CONFIG_SELF_POWERED 0xC0 290 /** remote wakeup */ 291 #define USB_CONFIG_REMOTE_WAKEUP 0x20 292 /** @} */ 293 294 /** bMaxPower in Configuration Descriptor */ 295 #define USB_CONFIG_POWER_MA(mA) ((mA)/2) 296 297 /** bEndpointAddress in Endpoint Descriptor 298 * @{ 299 */ 300 /** Endopint address mask */ 301 #define USB_ENDPOINT_DIRECTION_MASK 0x80 302 /** Macro to convert OUT endopint number to endpoint address value. */ 303 #define USB_ENDPOINT_OUT(addr) ((addr) | 0x00) 304 /** Macro to convert IN endopint number to endpoint address value. */ 305 #define USB_ENDPOINT_IN(addr) ((addr) | 0x80) 306 /** @} */ 307 308 /** bmAttributes in Endpoint Descriptor 309 * @{ 310 */ 311 /** Endopint type mask */ 312 #define USB_ENDPOINT_TYPE_MASK 0x03 313 /** Control Endopint type */ 314 #define USB_ENDPOINT_TYPE_CONTROL 0x00 315 /** isochronous Endopint type */ 316 #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01 317 /** bulk Endopint type */ 318 #define USB_ENDPOINT_TYPE_BULK 0x02 319 /** interrupt Endopint type */ 320 #define USB_ENDPOINT_TYPE_INTERRUPT 0x03 321 /** Endopint sync type mask */ 322 #define USB_ENDPOINT_SYNC_MASK 0x0C 323 /** no synchronization Endopint */ 324 #define USB_ENDPOINT_SYNC_NO_SYNCHRONIZATION 0x00 325 /** Asynchronous sync Endopint */ 326 #define USB_ENDPOINT_SYNC_ASYNCHRONOUS 0x04 327 /** Adaptive sync Endopint */ 328 #define USB_ENDPOINT_SYNC_ADAPTIVE 0x08 329 /** Synchronous sync Endopint */ 330 #define USB_ENDPOINT_SYNC_SYNCHRONOUS 0x0C 331 /** Endopint usage type mask */ 332 #define USB_ENDPOINT_USAGE_MASK 0x30 333 /** Endopint data usage type */ 334 #define USB_ENDPOINT_USAGE_DATA 0x00 335 /** Endopint feedback usage type */ 336 #define USB_ENDPOINT_USAGE_FEEDBACK 0x10 337 /** Endopint implicit feedback usage type */ 338 #define USB_ENDPOINT_USAGE_IMPLICIT_FEEDBACK 0x20 339 /** Endopint reserved usage type */ 340 #define USB_ENDPOINT_USAGE_RESERVED 0x30 341 /** @} */ 342 343 /** Control endopint EP0's maximum packet size in high-speed mode.*/ 344 #define USB_ENDPOINT_0_HS_MAXP 64 345 /** Control endopint EP0's maximum packet size in low-speed mode.*/ 346 #define USB_ENDPOINT_0_LS_MAXP 8 347 /** Bulk endopint's maximum packet size in high-speed mode.*/ 348 #define USB_ENDPOINT_BULK_HS_MAXP 512 349 350 /** USB Standard Device Descriptor */ 351 PRE_PACK struct POST_PACK _USB_DEVICE_DESCRIPTOR 352 { 353 uint8_t bLength; /**< Size of this descriptor in bytes. */ 354 uint8_t bDescriptorType; /**< DEVICE Descriptor Type. */ 355 uint16_t bcdUSB; /**< BUSB Specification Release Number in 356 Binary-Coded Decimal (i.e., 2.10 is 210H). 357 This field identifies the release of the USB 358 Specification with which the device and its 359 descriptors are compliant. 360 */ 361 uint8_t bDeviceClass; /**< Class code (assigned by the USB-IF). 362 If this field is reset to zero, each interface 363 within a configuration specifies its own 364 class information and the various 365 interfaces operate independently.\n 366 If this field is set to a value between 1 and 367 FEH, the device supports different class 368 specifications on different interfaces and 369 the interfaces may not operate 370 independently. This value identifies the 371 class definition used for the aggregate 372 interfaces. \n 373 If this field is set to FFH, the device class 374 is vendor-specific. 375 */ 376 uint8_t bDeviceSubClass; /**< Subclass code (assigned by the USB-IF). 377 These codes are qualified by the value of 378 the bDeviceClass field. \n 379 If the bDeviceClass field is reset to zero, 380 this field must also be reset to zero. \n 381 If the bDeviceClass field is not set to FFH, 382 all values are reserved for assignment by 383 the USB-IF. 384 */ 385 uint8_t bDeviceProtocol; /**< Protocol code (assigned by the USB-IF). 386 These codes are qualified by the value of 387 the bDeviceClass and the 388 bDeviceSubClass fields. If a device 389 supports class-specific protocols on a 390 device basis as opposed to an interface 391 basis, this code identifies the protocols 392 that the device uses as defined by the 393 specification of the device class. \n 394 If this field is reset to zero, the device 395 does not use class-specific protocols on a 396 device basis. However, it may use classspecific 397 protocols on an interface basis. \n 398 If this field is set to FFH, the device uses a 399 vendor-specific protocol on a device basis. 400 */ 401 uint8_t bMaxPacketSize0; /**< Maximum packet size for endpoint zero 402 (only 8, 16, 32, or 64 are valid). For HS devices 403 is fixed to 64. 404 */ 405 406 uint16_t idVendor; /**< Vendor ID (assigned by the USB-IF). */ 407 uint16_t idProduct; /**< Product ID (assigned by the manufacturer). */ 408 uint16_t bcdDevice; /**< Device release number in binary-coded decimal. */ 409 uint8_t iManufacturer; /**< Index of string descriptor describing manufacturer. */ 410 uint8_t iProduct; /**< Index of string descriptor describing product. */ 411 uint8_t iSerialNumber; /**< Index of string descriptor describing the device�s 412 serial number. 413 */ 414 uint8_t bNumConfigurations; /**< Number of possible configurations. */ 415 } ; 416 /** USB Standard Device Descriptor */ 417 typedef struct _USB_DEVICE_DESCRIPTOR USB_DEVICE_DESCRIPTOR; 418 419 /** USB 2.0 Device Qualifier Descriptor */ 420 PRE_PACK struct POST_PACK _USB_DEVICE_QUALIFIER_DESCRIPTOR 421 { 422 uint8_t bLength; /**< Size of descriptor */ 423 uint8_t bDescriptorType; /**< Device Qualifier Type */ 424 uint16_t bcdUSB; /**< USB specification version number (e.g., 0200H for V2.00) */ 425 uint8_t bDeviceClass; /**< Class Code */ 426 uint8_t bDeviceSubClass; /**< SubClass Code */ 427 uint8_t bDeviceProtocol; /**< Protocol Code */ 428 uint8_t bMaxPacketSize0; /**< Maximum packet size for other speed */ 429 uint8_t bNumConfigurations; /**< Number of Other-speed Configurations */ 430 uint8_t bReserved; /**< Reserved for future use, must be zero */ 431 } ; 432 /** USB 2.0 Device Qualifier Descriptor */ 433 typedef struct _USB_DEVICE_QUALIFIER_DESCRIPTOR USB_DEVICE_QUALIFIER_DESCRIPTOR; 434 435 /** USB Standard Configuration Descriptor */ 436 PRE_PACK struct POST_PACK _USB_CONFIGURATION_DESCRIPTOR 437 { 438 uint8_t bLength; /**< Size of this descriptor in bytes */ 439 uint8_t bDescriptorType; /**< CONFIGURATION Descriptor Type*/ 440 uint16_t wTotalLength; /**< Total length of data returned for this 441 configuration. Includes the combined length 442 of all descriptors (configuration, interface, 443 endpoint, and class- or vendor-specific) 444 returned for this configuration.*/ 445 uint8_t bNumInterfaces; /**< Number of interfaces supported by this configuration*/ 446 uint8_t bConfigurationValue; /**< Value to use as an argument to the 447 SetConfiguration() request to select this 448 configuration. */ 449 uint8_t iConfiguration; /**< Index of string descriptor describing this 450 configuration*/ 451 uint8_t bmAttributes; /**< Configuration characteristics \n 452 D7: Reserved (set to one)\n 453 D6: Self-powered \n 454 D5: Remote Wakeup \n 455 D4...0: Reserved (reset to zero) \n 456 D7 is reserved and must be set to one for 457 historical reasons. \n 458 A device configuration that uses power from 459 the bus and a local source reports a non-zero 460 value in bMaxPower to indicate the amount of 461 bus power required and sets D6. The actual 462 power source at runtime may be determined 463 using the GetStatus(DEVICE) request (see 464 USB 2.0 spec Section 9.4.5). \n 465 If a device configuration supports remote 466 wakeup, D5 is set to one.*/ 467 uint8_t bMaxPower; /**< Maximum power consumption of the USB 468 device from the bus in this specific 469 configuration when the device is fully 470 operational. Expressed in 2 mA units 471 (i.e., 50 = 100 mA). \n 472 Note: A device configuration reports whether 473 the configuration is bus-powered or selfpowered. 474 Device status reports whether the 475 device is currently self-powered. If a device is 476 disconnected from its external power source, it 477 updates device status to indicate that it is no 478 longer self-powered. \n 479 A device may not increase its power draw 480 from the bus, when it loses its external power 481 source, beyond the amount reported by its 482 configuration. \n 483 If a device can continue to operate when 484 disconnected from its external power source, it 485 continues to do so. If the device cannot 486 continue to operate, it fails operations it can 487 no longer support. The USB System Software 488 may determine the cause of the failure by 489 checking the status and noting the loss of the 490 device�s power source.*/ 491 } ; 492 /** USB Standard Configuration Descriptor */ 493 typedef struct _USB_CONFIGURATION_DESCRIPTOR USB_CONFIGURATION_DESCRIPTOR; 494 495 /** USB Standard Interface Association Descriptor */ 496 PRE_PACK struct POST_PACK _USB_IAD_DESCRIPTOR 497 { 498 uint8_t bLength; /**< Size of this descriptor in bytes*/ 499 uint8_t bDescriptorType; /**< INTERFACE ASSOCIATION Descriptor Type*/ 500 uint8_t bFirstInterface; /**< Interface number of the first interface that is 501 associated with this function.*/ 502 uint8_t bInterfaceCount; /**< Number of contiguous interfaces that are 503 associated with this function. */ 504 uint8_t bFunctionClass; /**< Class code (assigned by USB-IF). \n 505 A value of zero is not allowed in this descriptor. 506 If this field is FFH, the function class is vendorspecific. 507 All other values are reserved for assignment by 508 the USB-IF.*/ 509 uint8_t bFunctionSubClass; /**< Subclass code (assigned by USB-IF). \n 510 If the bFunctionClass field is not set to FFH all 511 values are reserved for assignment by the USBIF.*/ 512 uint8_t bFunctionProtocol; /**< Protocol code (assigned by the USB). \n 513 These codes are qualified by the values of the 514 bFunctionClass and bFunctionSubClass fields.*/ 515 uint8_t iFunction; /**< Index of string descriptor describing this function.*/ 516 } ; 517 /** USB Standard Interface Association Descriptor */ 518 typedef struct _USB_IAD_DESCRIPTOR USB_IAD_DESCRIPTOR; 519 520 /** USB Standard Interface Descriptor */ 521 PRE_PACK struct POST_PACK _USB_INTERFACE_DESCRIPTOR 522 { 523 uint8_t bLength; /**< Size of this descriptor in bytes*/ 524 uint8_t bDescriptorType; /**< INTERFACE Descriptor Type*/ 525 uint8_t bInterfaceNumber; /**< Number of this interface. Zero-based 526 value identifying the index in the array of 527 concurrent interfaces supported by this 528 configuration.*/ 529 uint8_t bAlternateSetting; /**< Value used to select this alternate setting 530 for the interface identified in the prior field*/ 531 uint8_t bNumEndpoints; /**< Number of endpoints used by this 532 interface (excluding endpoint zero). If this 533 value is zero, this interface only uses the 534 Default Control Pipe.*/ 535 uint8_t bInterfaceClass; /**< Class code (assigned by the USB-IF). \n 536 A value of zero is reserved for future 537 standardization. \n 538 If this field is set to FFH, the interface 539 class is vendor-specific. \n 540 All other values are reserved for 541 assignment by the USB-IF.*/ 542 uint8_t bInterfaceSubClass; /**< Subclass code (assigned by the USB-IF). \n 543 These codes are qualified by the value of 544 the bInterfaceClass field. \n 545 If the bInterfaceClass field is reset to zero, 546 this field must also be reset to zero. \n 547 If the bInterfaceClass field is not set to 548 FFH, all values are reserved for 549 assignment by the USB-IF.*/ 550 uint8_t bInterfaceProtocol; /**< Protocol code (assigned by the USB). \n 551 These codes are qualified by the value of 552 the bInterfaceClass and the 553 bInterfaceSubClass fields. If an interface 554 supports class-specific requests, this code 555 identifies the protocols that the device 556 uses as defined by the specification of the 557 device class. \n 558 If this field is reset to zero, the device 559 does not use a class-specific protocol on 560 this interface. \n 561 If this field is set to FFH, the device uses 562 a vendor-specific protocol for this 563 interface.*/ 564 uint8_t iInterface; /**< Index of string descriptor describing this interface*/ 565 } ; 566 /** USB Standard Interface Descriptor */ 567 typedef struct _USB_INTERFACE_DESCRIPTOR USB_INTERFACE_DESCRIPTOR; 568 569 /** USB Standard Endpoint Descriptor */ 570 PRE_PACK struct POST_PACK _USB_ENDPOINT_DESCRIPTOR 571 { 572 uint8_t bLength; /**< Size of this descriptor in bytes*/ 573 uint8_t bDescriptorType; /**< ENDPOINT Descriptor Type*/ 574 uint8_t bEndpointAddress; /**< The address of the endpoint on the USB device 575 described by this descriptor. The address is 576 encoded as follows: \n 577 Bit 3...0: The endpoint number \n 578 Bit 6...4: Reserved, reset to zero \n 579 Bit 7: Direction, ignored for control endpoints 580 0 = OUT endpoint 581 1 = IN endpoint. \n \sa USBD_ENDPOINT_ADR_Type*/ 582 uint8_t bmAttributes; /**< This field describes the endpoint�s attributes when it is 583 configured using the bConfigurationValue. \n 584 Bits 1..0: Transfer Type 585 \li 00 = Control 586 \li 01 = Isochronous 587 \li 10 = Bulk 588 \li 11 = Interrupt \n 589 If not an isochronous endpoint, bits 5..2 are reserved 590 and must be set to zero. If isochronous, they are 591 defined as follows: \n 592 Bits 3..2: Synchronization Type 593 \li 00 = No Synchronization 594 \li 01 = Asynchronous 595 \li 10 = Adaptive 596 \li 11 = Synchronous \n 597 Bits 5..4: Usage Type 598 \li 00 = Data endpoint 599 \li 01 = Feedback endpoint 600 \li 10 = Implicit feedback Data endpoint 601 \li 11 = Reserved \n 602 Refer to Chapter 5 of USB 2.0 specification for more information. \n 603 All other bits are reserved and must be reset to zero. 604 Reserved bits must be ignored by the host. 605 \n \sa USBD_EP_ATTR_Type*/ 606 uint16_t wMaxPacketSize; /**< Maximum packet size this endpoint is capable of 607 sending or receiving when this configuration is 608 selected. \n 609 For isochronous endpoints, this value is used to 610 reserve the bus time in the schedule, required for the 611 per-(micro)frame data payloads. The pipe may, on an 612 ongoing basis, actually use less bandwidth than that 613 reserved. The device reports, if necessary, the actual 614 bandwidth used via its normal, non-USB defined 615 mechanisms. \n 616 For all endpoints, bits 10..0 specify the maximum 617 packet size (in bytes). \n 618 For high-speed isochronous and interrupt endpoints: \n 619 Bits 12..11 specify the number of additional transaction 620 opportunities per microframe: \n 621 \li 00 = None (1 transaction per microframe) 622 \li 01 = 1 additional (2 per microframe) 623 \li 10 = 2 additional (3 per microframe) 624 \li 11 = Reserved \n 625 Bits 15..13 are reserved and must be set to zero.*/ 626 uint8_t bInterval; /**< Interval for polling endpoint for data transfers. 627 Expressed in frames or microframes depending on the 628 device operating speed (i.e., either 1 millisecond or 629 125 �s units). 630 \li For full-/high-speed isochronous endpoints, this value 631 must be in the range from 1 to 16. The bInterval value 632 is used as the exponent for a \f$ 2^(bInterval-1) \f$ value; e.g., a 633 bInterval of 4 means a period of 8 (\f$ 2^(4-1) \f$). 634 \li For full-/low-speed interrupt endpoints, the value of 635 this field may be from 1 to 255. 636 \li For high-speed interrupt endpoints, the bInterval value 637 is used as the exponent for a \f$ 2^(bInterval-1) \f$ value; e.g., a 638 bInterval of 4 means a period of 8 (\f$ 2^(4-1) \f$) . This value 639 must be from 1 to 16. 640 \li For high-speed bulk/control OUT endpoints, the 641 bInterval must specify the maximum NAK rate of the 642 endpoint. A value of 0 indicates the endpoint never 643 NAKs. Other values indicate at most 1 NAK each 644 bInterval number of microframes. This value must be 645 in the range from 0 to 255. \n 646 Refer to Chapter 5 of USB 2.0 specification for more information. 647 */ 648 } ; 649 /** USB Standard Endpoint Descriptor */ 650 typedef struct _USB_ENDPOINT_DESCRIPTOR USB_ENDPOINT_DESCRIPTOR; 651 652 /** USB String Descriptor */ 653 PRE_PACK struct POST_PACK _USB_STRING_DESCRIPTOR 654 { 655 uint8_t bLength; /**< Size of this descriptor in bytes*/ 656 uint8_t bDescriptorType; /**< STRING Descriptor Type*/ 657 uint16_t bString/*[]*/; /**< UNICODE encoded string */ 658 } ; 659 /** USB String Descriptor */ 660 typedef struct _USB_STRING_DESCRIPTOR USB_STRING_DESCRIPTOR; 661 662 /** USB Common Descriptor */ 663 PRE_PACK struct POST_PACK _USB_COMMON_DESCRIPTOR 664 { 665 uint8_t bLength; /**< Size of this descriptor in bytes*/ 666 uint8_t bDescriptorType; /**< Descriptor Type*/ 667 } ; 668 /** USB Common Descriptor */ 669 typedef struct _USB_COMMON_DESCRIPTOR USB_COMMON_DESCRIPTOR; 670 671 /** USB Other Speed Configuration */ 672 PRE_PACK struct POST_PACK _USB_OTHER_SPEED_CONFIGURATION 673 { 674 uint8_t bLength; /**< Size of descriptor*/ 675 uint8_t bDescriptorType; /**< Other_speed_Configuration Type*/ 676 uint16_t wTotalLength; /**< Total length of data returned*/ 677 uint8_t bNumInterfaces; /**< Number of interfaces supported by this speed configuration*/ 678 uint8_t bConfigurationValue; /**< Value to use to select configuration*/ 679 uint8_t IConfiguration; /**< Index of string descriptor*/ 680 uint8_t bmAttributes; /**< Same as Configuration descriptor*/ 681 uint8_t bMaxPower; /**< Same as Configuration descriptor*/ 682 } ; 683 /** USB Other Speed Configuration */ 684 typedef struct _USB_OTHER_SPEED_CONFIGURATION USB_OTHER_SPEED_CONFIGURATION; 685 686 /** \ingroup USBD_Core 687 * USB device stack/module handle. 688 */ 689 typedef void* USBD_HANDLE_T; 690 691 #define WBVAL(x) ((x) & 0xFF),(((x) >> 8) & 0xFF) 692 #define B3VAL(x) ((x) & 0xFF),(((x) >> 8) & 0xFF),(((x) >> 16) & 0xFF) 693 694 #define USB_DEVICE_DESC_SIZE (sizeof(USB_DEVICE_DESCRIPTOR)) 695 #define USB_CONFIGURATION_DESC_SIZE (sizeof(USB_CONFIGURATION_DESCRIPTOR)) 696 #define USB_INTERFACE_DESC_SIZE (sizeof(USB_INTERFACE_DESCRIPTOR)) 697 #define USB_INTERFACE_ASSOC_DESC_SIZE (sizeof(USB_IAD_DESCRIPTOR)) 698 #define USB_ENDPOINT_DESC_SIZE (sizeof(USB_ENDPOINT_DESCRIPTOR)) 699 #define USB_DEVICE_QUALI_SIZE (sizeof(USB_DEVICE_QUALIFIER_DESCRIPTOR)) 700 #define USB_OTHER_SPEED_CONF_SIZE (sizeof(USB_OTHER_SPEED_CONFIGURATION)) 701 702 /** @}*/ 703 704 #endif /* __USBD_H__ */ 705