added IAD descriptor

This commit is contained in:
hathach 2012-12-03 18:43:35 +07:00
parent 21012d42a2
commit 6ea85a569a
4 changed files with 61 additions and 48 deletions

View File

@ -65,22 +65,6 @@ typedef PRE_PACK struct POST_PACK _USB_STR_DESCRIPTOR
#define USB_DEVICE_SUBCLASS_IAD 0x02
#define USB_DEVICE_PROTOCOL_IAD 0x01
// USB Interface Association Descriptor
typedef PRE_PACK struct POST_PACK _USB_INTERFACE_ASSOCIATION_DESCRIPTOR
{
uint8_t bLength; /**< Size of descriptor*/
uint8_t bDescriptorType; /**< Other_speed_Configuration Type*/
uint8_t bFirstInterface; /**< Index of the first associated interface. */
uint8_t bInterfaceCount; /**< Total number of associated interfaces. */
uint8_t bFunctionClass; /**< Interface class ID. */
uint8_t bFunctionSubClass; /**< Interface subclass ID. */
uint8_t bFunctionProtocol; /**< Interface protocol ID. */
uint8_t iFunction; /**< Index of the string descriptor describing the interface association. */
} USB_INTERFACE_ASSOCIATION_DESCRIPTOR;
///////////////////////////////////////////////////////////////////////
// Interface Assosication Descriptor if device is CDC + other class
#define IAD_DESC_REQUIRED ( defined(CFG_CLASS_CDC) && (TUSB_CLASS_HID) )

View File

@ -1525,7 +1525,7 @@ INCLUDE_FILE_PATTERNS =
# undefined via #undef or recursively expanded use the := operator
# instead of the = operator.
PREDEFINED = __attribute__(x)= __attribute__((x))= ATTR_ALIGNED(x)= ATTR_PREPACKED= ATTR_PACKED=
PREDEFINED = __attribute__(x)= __attribute__((x))= ATTR_ALIGNED(x)= ATTR_PREPACKED= ATTR_PACKED=
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
# this tag can be used to specify a list of macro names that should be expanded.

View File

@ -54,24 +54,8 @@
#include "common/common.h"
/// USB Descriptor Types (section 9.4 table 9-5)
typedef enum {
DEVICE_TYPE=1,
CONFIGURATIONT_TYPE,
STRING_TYPE,
INTERFACE_TYPE,
ENDPOINT_TYPE,
DEVICE_QUALIFIER_TYPE,
OTHER_SPEED_CONFIGURATION_TYPE,
INTERFACE_POWER_TYPE
}USB_DescriptorType_t;
//typedef enum {
//
//};
/// USB Standard Device Descriptor (section 9.6.1, table 9-8)
typedef ATTR_PREPACKED struct {
typedef ATTR_PREPACKED struct ATTR_PACKED {
uint8_t bLength ; ///< Size of this descriptor in bytes.
uint8_t bDescriptorType ; ///< DEVICE Descriptor Type.
uint16_t bcdUSB ; ///< BUSB Specification Release Number in Binary-Coded Decimal (i.e., 2.10 is 210H). This field identifies the release of the USB Specification with which the device and its descriptors are compliant.
@ -88,10 +72,10 @@ typedef ATTR_PREPACKED struct {
uint8_t iProduct ; ///< Index of string descriptor describing product.
uint8_t iSerialNumber ; ///< Index of string descriptor describing the device's serial number.
uint8_t bNumConfigurations ; ///< Number of possible configurations.
} ATTR_PACKED USB_Descriptor_Device_t;
} USB_Descriptor_Device_t;
/// USB Standard Configuration Descriptor (section 9.6.1 table 9-10) */
typedef ATTR_PREPACKED struct {
typedef ATTR_PREPACKED struct ATTR_PACKED {
uint8_t bLength ; ///< Size of this descriptor in bytes
uint8_t bDescriptorType ; ///< CONFIGURATION Descriptor Type
uint16_t wTotalLength ; ///< Total length of data returned for this configuration. Includes the combined length of all descriptors (configuration, interface, endpoint, and class- or vendor-specific) returned for this configuration.
@ -100,10 +84,10 @@ typedef ATTR_PREPACKED struct {
uint8_t iConfiguration ; ///< Index of string descriptor describing this configuration
uint8_t bmAttributes ; ///< Configuration characteristics \n D7: Reserved (set to one)\n D6: Self-powered \n D5: Remote Wakeup \n D4...0: Reserved (reset to zero) \n D7 is reserved and must be set to one for historical reasons. \n A device configuration that uses power from the bus and a local source reports a non-zero value in bMaxPower to indicate the amount of bus power required and sets D6. The actual power source at runtime may be determined using the GetStatus(DEVICE) request (see USB 2.0 spec Section 9.4.5). \n If a device configuration supports remote wakeup, D5 is set to one.
uint8_t bMaxPower ; ///< Maximum power consumption of the USB device from the bus in this specific configuration when the device is fully operational. Expressed in 2 mA units (i.e., 50 = 100 mA).
} ATTR_PACKED USB_Descriptor_Configuration_t;
} USB_Descriptor_Configuration_t;
/// USB Standard Interface Descriptor (section 9.6.1 table 9-12)
typedef ATTR_PREPACKED struct {
typedef ATTR_PREPACKED struct ATTR_PACKED {
uint8_t bLength; ///< Size of this descriptor in bytes
uint8_t bDescriptorType; ///< INTERFACE Descriptor Type
uint8_t bInterfaceNumber; ///< Number of this interface. Zero-based value identifying the index in the array of concurrent interfaces supported by this configuration.
@ -113,20 +97,20 @@ typedef ATTR_PREPACKED struct {
uint8_t bInterfaceSubClass; ///< Subclass code (assigned by the USB-IF). \n These codes are qualified by the value of the bInterfaceClass field. \li If the bInterfaceClass field is reset to zero, this field must also be reset to zero. \li If the bInterfaceClass field is not set to FFH, all values are reserved for assignment by the USB-IF.
uint8_t bInterfaceProtocol; ///< Protocol code (assigned by the USB). \n These codes are qualified by the value of the bInterfaceClass and the bInterfaceSubClass fields. If an interface supports class-specific requests, this code identifies the protocols that the device uses as defined by the specification of the device class. \li If this field is reset to zero, the device does not use a class-specific protocol on this interface. \li If this field is set to FFH, the device uses a vendor-specific protocol for this interface.
uint8_t iInterface; ///< Index of string descriptor describing this interface
}ATTR_PACKED USB_Descriptor_Interface_t ;
}USB_Descriptor_Interface_t ;
/// USB Standard Endpoint Descriptor (section 9.6.1 table 9-13)
typedef ATTR_PREPACKED struct {
typedef ATTR_PREPACKED struct ATTR_PACKED {
uint8_t bLength ; ///< Size of this descriptor in bytes
uint8_t bDescriptorType ; ///< ENDPOINT Descriptor Type
uint8_t bEndpointAddress ; ///< The address of the endpoint on the USB device described by this descriptor. The address is encoded as follows: \n Bit 3...0: The endpoint number \n Bit 6...4: Reserved, reset to zero \n Bit 7: Direction, ignored for control endpoints 0 = OUT endpoint 1 = IN endpoint.
uint8_t bmAttributes ; ///< This field describes the endpoint's attributes when it is configured using the bConfigurationValue. \n Bits 1..0: Transfer Type \n- 00 = Control \n- 01 = Isochronous \n- 10 = Bulk \n- 11 = Interrupt \n If not an isochronous endpoint, bits 5..2 are reserved and must be set to zero. If isochronous, they are defined as follows: \n Bits 3..2: Synchronization Type \n- 00 = No Synchronization \n- 01 = Asynchronous \n- 10 = Adaptive \n- 11 = Synchronous \n Bits 5..4: Usage Type \n- 00 = Data endpoint \n- 01 = Feedback endpoint \n- 10 = Implicit feedback Data endpoint \n- 11 = Reserved \n Refer to Chapter 5 of USB 2.0 specification for more information. \n All other bits are reserved and must be reset to zero. Reserved bits must be ignored by the host.
uint16_t wMaxPacketSize ; ///< Maximum packet size this endpoint is capable of sending or receiving when this configuration is selected. \n For isochronous endpoints, this value is used to reserve the bus time in the schedule, required for the per-(micro)frame data payloads. The pipe may, on an ongoing basis, actually use less bandwidth than that reserved. The device reports, if necessary, the actual bandwidth used via its normal, non-USB defined mechanisms. \n For all endpoints, bits 10..0 specify the maximum packet size (in bytes). \n For high-speed isochronous and interrupt endpoints: \n Bits 12..11 specify the number of additional transaction opportunities per microframe: \n- 00 = None (1 transaction per microframe) \n- 01 = 1 additional (2 per microframe) \n- 10 = 2 additional (3 per microframe) \n- 11 = Reserved \n Bits 15..13 are reserved and must be set to zero.
uint8_t bInterval ; ///< Interval for polling endpoint for data transfers. Expressed in frames or microframes depending on the device operating speed (i.e., either 1 millisecond or 125 us units). \n- For full-/high-speed isochronous endpoints, this value must be in the range from 1 to 16. The bInterval value is used as the exponent for a \f$ 2^(bInterval-1) \f$ value; e.g., a bInterval of 4 means a period of 8 (\f$ 2^(4-1) \f$). \n- For full-/low-speed interrupt endpoints, the value of this field may be from 1 to 255. \n- For high-speed interrupt endpoints, the bInterval value is used as the exponent for a \f$ 2^(bInterval-1) \f$ value; e.g., a bInterval of 4 means a period of 8 (\f$ 2^(4-1) \f$) . This value must be from 1 to 16. \n- For high-speed bulk/control OUT endpoints, the bInterval must specify the maximum NAK rate of the endpoint. A value of 0 indicates the endpoint never NAKs. Other values indicate at most 1 NAK each bInterval number of microframes. This value must be in the range from 0 to 255. \n Refer to Chapter 5 of USB 2.0 specification for more information.
} ATTR_PACKED USB_Descriptor_Endpoint_t;
} USB_Descriptor_Endpoint_t;
/// USB Other Speed Configuration Descriptor (section 9.6.1 table 9-11)
typedef ATTR_PREPACKED struct {
typedef ATTR_PREPACKED struct ATTR_PACKED {
uint8_t bLength ; ///< Size of descriptor
uint8_t bDescriptorType ; ///< Other_speed_Configuration Type
uint16_t wTotalLength ; ///< Total length of data returned
@ -135,10 +119,10 @@ typedef ATTR_PREPACKED struct {
uint8_t IConfiguration ; ///< Index of string descriptor
uint8_t bmAttributes ; ///< Same as Configuration descriptor
uint8_t bMaxPower ; ///< Same as Configuration descriptor
} ATTR_PACKED USB_Descriptor_OtherSpeed_t;
} USB_Descriptor_OtherSpeed_t;
/// USB Device Qualifier Descriptor (section 9.6.1 table 9-9)
typedef ATTR_PREPACKED struct {
typedef ATTR_PREPACKED struct ATTR_PACKED {
uint8_t bLength ; ///< Size of descriptor
uint8_t bDescriptorType ; ///< Device Qualifier Type
uint16_t bcdUSB ; ///< USB specification version number (e.g., 0200H for V2.00)
@ -148,7 +132,23 @@ typedef ATTR_PREPACKED struct {
uint8_t bMaxPacketSize0 ; ///< Maximum packet size for other speed
uint8_t bNumConfigurations ; ///< Number of Other-speed Configurations
uint8_t bReserved ; ///< Reserved for future use, must be zero
} ATTR_PACKED USB_Descriptor_DeviceQualifier_t;
} USB_Descriptor_DeviceQualifier_t;
/// USB Interface Association Descriptor (IAD ECN)
typedef ATTR_PREPACKED struct ATTR_PACKED
{
uint8_t bLength; ///< Size of descriptor
uint8_t bDescriptorType; ///< Other_speed_Configuration Type
uint8_t bFirstInterface; ///< Index of the first associated interface.
uint8_t bInterfaceCount; ///< Total number of associated interfaces.
uint8_t bFunctionClass; ///< Interface class ID.
uint8_t bFunctionSubClass; ///< Interface subclass ID.
uint8_t bFunctionProtocol; ///< Interface protocol ID.
uint8_t iFunction; ///< Index of the string descriptor describing the interface association.
} USB_Descriptor_InterfaceAssociation_t;
#ifdef __cplusplus

View File

@ -58,7 +58,7 @@ typedef enum {
FULL_SPEED =0,
LOWS_PEED,
HIGH_SPEED
}TUSB_Speed_t;
}USB_Speed_t;
/// defined base on USB Specs Endpoint's bmAttributes
typedef enum {
@ -66,16 +66,45 @@ typedef enum {
ISOCHRONOUS_TYPE,
BULK_TYPE,
INTERRUPT_TYPE
}TUSB_TransferType_t;
}USB_TransferType_t;
/// TBD
typedef enum {
SETUP_TOKEN,
IN_TOKEN,
OUT_TOKEN
}TUSB_PID_t;
}USB_PID_t;
/// USB Descriptor Types (section 9.4 table 9-5)
typedef enum {
DEVICE_DESC=1 , ///< 1
CONFIGURATIONT_DESC , ///< 2
STRING_DESC , ///< 3
INTERFACE_DESC , ///< 4
ENDPOINT_DESC , ///< 5
DEVICE_QUALIFIER_DESC , ///< 6
OTHER_SPEED_CONFIGURATION_DESC , ///< 7
INTERFACE_POWER_DESC , ///< 8
OTG_DESC , ///< 9
DEBUG_DESCRIPTOR , ///< 10
INTERFACE_ASSOCIATION_DESC ///< 11
}USB_DescriptorType_t;
typedef enum {
REQUEST_GET_STATUS =0 , ///< 0
REQUEST_CLEAR_FEATURE , ///< 1
REQUEST_RESERVED , ///< 2
REQUEST_SET_FEATURE , ///< 3
REQUEST_RESERVED2 , ///< 4
REQUEST_SET_ADDRESS , ///< 5
REQUEST_GET_DESCRIPTOR , ///< 6
REQUEST_SET_DESCRIPTOR , ///< 7
REQUEST_GET_CONFIGURATION , ///< 8
REQUEST_SET_CONFIGURATION , ///< 9
REQUEST_GET_INTERFACE , ///< 10
REQUEST_SET_INTERFACE , ///< 11
REQUEST_SYNCH_FRAME ///< 12
}USB_RequestCode_t;
#ifdef __cplusplus
}