|
28 | 28 | #include "usbd_ioreq.h" |
29 | 29 | #include "usbd_cdc_msc_hid.h" |
30 | 30 |
|
| 31 | +#define MSC_TEMPLATE_CONFIG_DESC_SIZE (32) |
31 | 32 | #define CDC_TEMPLATE_CONFIG_DESC_SIZE (67) |
32 | 33 | #define CDC_MSC_TEMPLATE_CONFIG_DESC_SIZE (98) |
33 | 34 | #define CDC_HID_TEMPLATE_CONFIG_DESC_SIZE (107) |
@@ -89,6 +90,54 @@ __ALIGN_BEGIN static uint8_t USBD_CDC_MSC_HID_DeviceQualifierDesc[USB_LEN_DEV_QU |
89 | 90 | }; |
90 | 91 | */ |
91 | 92 |
|
| 93 | +// USB MSC device Configuration Descriptor |
| 94 | +static const uint8_t msc_template_config_desc[MSC_TEMPLATE_CONFIG_DESC_SIZE] = { |
| 95 | + //-------------------------------------------------------------------------- |
| 96 | + // Configuration Descriptor |
| 97 | + 0x09, // bLength: Configuration Descriptor size |
| 98 | + USB_DESC_TYPE_CONFIGURATION, // bDescriptorType: Configuration |
| 99 | + LOBYTE(MSC_TEMPLATE_CONFIG_DESC_SIZE), // wTotalLength: no of returned bytes |
| 100 | + HIBYTE(MSC_TEMPLATE_CONFIG_DESC_SIZE), |
| 101 | + 0x01, // bNumInterfaces: 1 interfaces |
| 102 | + 0x01, // bConfigurationValue: Configuration value |
| 103 | + 0x00, // iConfiguration: Index of string descriptor describing the configuration |
| 104 | + 0x80, // bmAttributes: bus powered; 0xc0 for self powered |
| 105 | + 0xfa, // bMaxPower: in units of 2mA |
| 106 | + |
| 107 | + //========================================================================== |
| 108 | + // MSC only has 1 interface so doesn't need an IAD |
| 109 | + |
| 110 | + //-------------------------------------------------------------------------- |
| 111 | + // Interface Descriptor |
| 112 | + 0x09, // bLength: Interface Descriptor size |
| 113 | + USB_DESC_TYPE_INTERFACE, // bDescriptorType: interface descriptor |
| 114 | + MSC_IFACE_NUM_WITH_CDC, // bInterfaceNumber: Number of Interface |
| 115 | + 0x00, // bAlternateSetting: Alternate setting |
| 116 | + 0x02, // bNumEndpoints |
| 117 | + 0x08, // bInterfaceClass: MSC Class |
| 118 | + 0x06, // bInterfaceSubClass : SCSI transparent |
| 119 | + 0x50, // nInterfaceProtocol |
| 120 | + 0x00, // iInterface: |
| 121 | + |
| 122 | + // Endpoint IN descriptor |
| 123 | + 0x07, // bLength: Endpoint descriptor length |
| 124 | + USB_DESC_TYPE_ENDPOINT, // bDescriptorType: Endpoint descriptor type |
| 125 | + MSC_IN_EP, // bEndpointAddress: IN, address 3 |
| 126 | + 0x02, // bmAttributes: Bulk endpoint type |
| 127 | + LOBYTE(MSC_MAX_PACKET), // wMaxPacketSize |
| 128 | + HIBYTE(MSC_MAX_PACKET), |
| 129 | + 0x00, // bInterval: ignore for Bulk transfer |
| 130 | + |
| 131 | + // Endpoint OUT descriptor |
| 132 | + 0x07, // bLength: Endpoint descriptor length |
| 133 | + USB_DESC_TYPE_ENDPOINT, // bDescriptorType: Endpoint descriptor type |
| 134 | + MSC_OUT_EP, // bEndpointAddress: OUT, address 3 |
| 135 | + 0x02, // bmAttributes: Bulk endpoint type |
| 136 | + LOBYTE(MSC_MAX_PACKET), // wMaxPacketSize |
| 137 | + HIBYTE(MSC_MAX_PACKET), |
| 138 | + 0x00, // bInterval: ignore for Bulk transfer |
| 139 | +}; |
| 140 | + |
92 | 141 | // USB CDC MSC device Configuration Descriptor |
93 | 142 | static const uint8_t cdc_msc_template_config_desc[CDC_MSC_TEMPLATE_CONFIG_DESC_SIZE] = { |
94 | 143 | //-------------------------------------------------------------------------- |
@@ -554,6 +603,11 @@ int USBD_SelectMode(usbd_cdc_msc_hid_state_t *usbd, uint32_t mode, USBD_HID_Mode |
554 | 603 |
|
555 | 604 | // construct config desc |
556 | 605 | switch (usbd->usbd_mode) { |
| 606 | + case USBD_MODE_MSC: |
| 607 | + usbd->usbd_config_desc_size = sizeof(msc_template_config_desc); |
| 608 | + memcpy(usbd->usbd_config_desc, msc_template_config_desc, sizeof(msc_template_config_desc)); |
| 609 | + break; |
| 610 | + |
557 | 611 | case USBD_MODE_CDC_MSC: |
558 | 612 | usbd->usbd_config_desc_size = sizeof(cdc_msc_template_config_desc); |
559 | 613 | memcpy(usbd->usbd_config_desc, cdc_msc_template_config_desc, sizeof(cdc_msc_template_config_desc)); |
|
0 commit comments