static const struct usb_device_config_descriptor usb_device_config_desc =
{
.config_descriptor =
{
.bLength = sizeof(struct usb_config_descriptor),
.bDescriptorType = USB_DTYPE_CONFIGURATION,
.wTotalLength = sizeof(struct usb_device_config_descriptor),
.bNumInterfaces = 3,
.bConfigurationValue = 1,
.iConfiguration = NO_DESCRIPTOR,
.bmAttributes = USB_CFG_ATTR_RESERVED | USB_CFG_ATTR_SELFPOWERED,
.bMaxPower = USB_CFG_POWER_MA(450)
},
.hid_iad_descriptor =
{
.bLength = sizeof(struct usb_iad_descriptor),
.bDescriptorType = USB_DTYPE_INTERFASEASSOC,
.bFirstInterface = 0,
.bInterfaceCount = 1,
.bFunctionClass = USB_CLASS_HID,
.bFunctionSubClass = USB_HID_SUBCLASS_NONBOOT,
.bFunctionProtocol = USB_HID_PROTO_NONBOOT,
.iFunction = 3
},
.hid_interface_descriptor =
{
.bLength = sizeof(struct usb_interface_descriptor),
.bDescriptorType = USB_DTYPE_INTERFACE,
.bInterfaceNumber = 0,
.bAlternateSetting = 0,
.bNumEndpoints = 2,
.bInterfaceClass = USB_CLASS_HID,
.bInterfaceSubClass = USB_HID_SUBCLASS_NONBOOT,
.bInterfaceProtocol = USB_HID_PROTO_NONBOOT,
.iInterface = 3
},
.hid_descriptor =
{
.bLength = sizeof(struct usb_hid_descriptor),
.bDescriptorType = USB_DTYPE_HID,
.bcdHID = VERSION_BCD(1, 1, 1),
.bCountryCode = USB_HID_COUNTRY_US,
.bNumDescriptors = 1,
.bDescriptorType0 = USB_DTYPE_HID_REPORT,
.wDescriptorLength0 = sizeof(usb_hid_report_descriptor)
},
.hid_ep_in_descriptor =
{
.bLength = sizeof(struct usb_endpoint_descriptor),
.bDescriptorType = USB_DTYPE_ENDPOINT,
.bEndpointAddress = USB_HID_IN_EP,
.bmAttributes = USB_EPTYPE_INTERRUPT,
.wMaxPacketSize = USB_PKT_SIZE,
.bInterval = 1
},
.hid_ep_out_descriptor =
{
.bLength = sizeof(struct usb_endpoint_descriptor),
.bDescriptorType = USB_DTYPE_ENDPOINT,
.bEndpointAddress = USB_HID_OUT_EP,
.bmAttributes = USB_EPTYPE_INTERRUPT,
.wMaxPacketSize = USB_PKT_SIZE,
.bInterval = 1
},
.cdc_iad_descriptor =
{
.bLength = sizeof(struct usb_iad_descriptor),
.bDescriptorType = USB_DTYPE_INTERFASEASSOC,
.bFirstInterface = 1,
.bInterfaceCount = 2,
.bFunctionClass = USB_CLASS_CDC,
.bFunctionSubClass = USB_CDC_SUBCLASS_ACM,
.bFunctionProtocol = USB_CDC_PROTO_V25TER,
.iFunction = 4
},
.cdc_ctrl_interface_descriptor =
{
.bLength = sizeof(struct usb_interface_descriptor),
.bDescriptorType = USB_DTYPE_INTERFACE,
.bInterfaceNumber = 1,
.bAlternateSetting = 0,
.bNumEndpoints = 1,
.bInterfaceClass = USB_CLASS_CDC,
.bInterfaceSubClass = USB_CDC_SUBCLASS_ACM,
.bInterfaceProtocol = USB_CDC_PROTO_V25TER,
.iInterface = 4
},
.cdc_header_descriptor =
{
.bFunctionLength = sizeof(struct usb_cdc_header_desc),
.bDescriptorType = USB_DTYPE_CS_INTERFACE,
.bDescriptorSubType = USB_DTYPE_CDC_HEADER,
.bcdCDC = VERSION_BCD(1,1,0)
},
.cdc_call_management_descriptor =
{
.bFunctionLength = sizeof(struct usb_cdc_call_mgmt_desc),
.bDescriptorType = USB_DTYPE_CS_INTERFACE,
.bDescriptorSubType = USB_DTYPE_CDC_CALL_MANAGEMENT,
.bmCapabilities = 0,
.bDataInterface = 2
},
.cdc_acm_descriptor =
{
.bFunctionLength = sizeof(struct usb_cdc_acm_desc),
.bDescriptorType = USB_DTYPE_CS_INTERFACE,
.bDescriptorSubType = USB_DTYPE_CDC_ACM,
.bmCapabilities = USB_CDC_CAP_LINE,
},
.cdc_union_descriptor =
{
.bFunctionLength = sizeof(struct usb_cdc_union_desc),
.bDescriptorType = USB_DTYPE_CS_INTERFACE,
.bDescriptorSubType = USB_DTYPE_CDC_UNION,
.bMasterInterface0 = 1,
.bSlaveInterface0 = 2,
},
.cdc_ep_ctrl_descriptor =
{
.bLength = sizeof(struct usb_endpoint_descriptor),
.bDescriptorType = USB_DTYPE_ENDPOINT,
.bEndpointAddress = USB_CDC_CTRL_EP,
.bmAttributes = USB_EPTYPE_INTERRUPT,
.wMaxPacketSize = USB_PKT_SIZE,
.bInterval = 1
},
.cdc_data_interface_descriptor =
{
.bLength = sizeof(struct usb_interface_descriptor),
.bDescriptorType = USB_DTYPE_INTERFACE,
.bInterfaceNumber = 2,
.bAlternateSetting = 0,
.bNumEndpoints = 2,
.bInterfaceClass = USB_CLASS_CDC_DATA,
.bInterfaceSubClass = USB_SUBCLASS_NONE,
.bInterfaceProtocol = USB_PROTO_NONE,
.iInterface = 4
},
.cdc_ep_data_rx_descriptor =
{
.bLength = sizeof(struct usb_endpoint_descriptor),
.bDescriptorType = USB_DTYPE_ENDPOINT,
.bEndpointAddress = USB_CDC_DATA_OUT_EP,
.bmAttributes = USB_EPTYPE_BULK,
.wMaxPacketSize = USB_PKT_SIZE,
.bInterval = 1
},
.cdc_ep_data_tx_descriptor =
{
.bLength = sizeof(struct usb_endpoint_descriptor),
.bDescriptorType = USB_DTYPE_ENDPOINT,
.bEndpointAddress = USB_CDC_DATA_IN_EP,
.bmAttributes = USB_EPTYPE_BULK,
.wMaxPacketSize = USB_PKT_SIZE,
.bInterval = 1
},
};
这个设备描述符通过 IAD 的方式复合了一个 HID 和一个 CDC 串口设备。CDC 本身因为使用了两个 Interface 因此需要 IAD,如果是譬如 HID 这种只需要一个 Interface 的通信协议的话可以不用 IAD。(这个设备其实我计划了 CDC+HID+MSC 的三路复合设备,就是希望 STM32F042K6 能放得下这点代码。)