add usb hs support,add bos and msosv2 descriptor register

This commit is contained in:
sakumisu
2021-09-28 10:51:20 +08:00
parent 051d127cdc
commit 0672902d62
13 changed files with 474 additions and 220 deletions

View File

@@ -17,7 +17,14 @@ int audio_class_request_handler(struct usb_setup_packet *setup, uint8_t **data,
memcpy(&audio_control_info.mute, *data, *len);
} else if (setup->wValueH == AUDIO_FU_CONTROL_VOLUME) {
memcpy(&audio_control_info.vol_current, *data, *len);
USBD_LOG_DBG("vol:0x%x\r\n", audio_control_info.vol_current);
uint32_t vol;
if (audio_control_info.vol_current == 0) {
vol = 100;
} else {
vol = (audio_control_info.vol_current - 0xDB00 + 1) * 100 / (0xFFFF - 0xDB00);
}
usbd_audio_set_volume(vol);
USBD_LOG_WRN("vol:%d\r\n", vol);
}
}
@@ -78,7 +85,9 @@ void audio_notify_handler(uint8_t event, void *arg)
break;
}
}
__weak void usbd_audio_set_volume(uint8_t vol)
{
}
void usbd_audio_add_interface(usbd_class_t *class, usbd_interface_t *intf)
{
static usbd_class_t *last_class = NULL;

View File

@@ -269,7 +269,7 @@ struct usbd_audio_control_info {
void usbd_audio_add_interface(usbd_class_t *class, usbd_interface_t *intf);
void usbd_audio_set_interface_callback(uint8_t value);
void usbd_audio_set_volume(uint8_t vol);
#ifdef __cplusplus
}
#endif

View File

@@ -295,71 +295,139 @@ struct cdc_ecm_descriptor {
/*Length of template descriptor: 66 bytes*/
#define CDC_ACM_DESCRIPTOR_LEN (8 + 9 + 5 + 5 + 4 + 5 + 7 + 9 + 7 + 7)
// clang-format off
#ifndef CONFIG_USB_HS
#define CDC_ACM_DESCRIPTOR_INIT(bFirstInterface, int_ep, out_ep, in_ep, str_idx) \
/* Interface Associate */ \
0x08, /* bLength */ \
USB_DESCRIPTOR_TYPE_INTERFACE_ASSOCIATION, /* bDescriptorType */ \
bFirstInterface, /* bFirstInterface */ \
0x02, /* bInterfaceCount */ \
USB_DEVICE_CLASS_CDC, /* bFunctionClass */ \
CDC_ABSTRACT_CONTROL_MODEL, /* bFunctionSubClass */ \
CDC_COMMON_PROTOCOL_AT_COMMANDS, /* bFunctionProtocol */ \
0x00, /* iFunction */ /* CDC Control Interface */ \
0x09, /* bLength */ \
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
bFirstInterface, /* bInterfaceNumber */ \
0x00, /* bAlternateSetting */ \
0x01, /* bNumEndpoints */ \
USB_DEVICE_CLASS_CDC, /* bInterfaceClass */ \
CDC_ABSTRACT_CONTROL_MODEL, /* bInterfaceSubClass */ \
CDC_COMMON_PROTOCOL_AT_COMMANDS, /* bInterfaceProtocol */ \
str_idx, /* iInterface */ /* CDC Header */ \
0x05, /* bLength */ \
CDC_CS_INTERFACE, /* bDescriptorType */ \
CDC_FUNC_DESC_HEADER, /* bDescriptorSubtype */ \
WBVAL(CDC_V1_10), /* bcdCDC */ /* CDC Call */ \
0x05, /* bLength */ \
CDC_CS_INTERFACE, /* bDescriptorType */ \
CDC_FUNC_DESC_CALL_MANAGEMENT, /* bDescriptorSubtype */ \
bFirstInterface, /* bmCapabilities */ \
(uint8_t)(bFirstInterface + 1), /* bDataInterface */ /* CDC ACM: support line request */ \
0x04, /* bLength */ \
CDC_CS_INTERFACE, /* bDescriptorType */ \
CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT, /* bDescriptorSubtype */ \
0x02, /* bmCapabilities */ /* CDC Union */ \
0x05, /* bLength */ \
CDC_CS_INTERFACE, /* bDescriptorType */ \
CDC_FUNC_DESC_UNION, /* bDescriptorSubtype */ \
bFirstInterface, /* bMasterInterface */ \
(uint8_t)(bFirstInterface + 1), /* bSlaveInterface0 */ /* Endpoint Notification */ \
0x07, /* bLength */ \
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \
int_ep, /* bEndpointAddress */ \
0x03, /* bmAttributes */ \
0x40, 0x00, /* wMaxPacketSize */ \
0x01, /* bInterval */ /* CDC Data Interface */ \
0x09, /* bLength */ \
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
(uint8_t)(bFirstInterface + 1), /* bInterfaceNumber */ \
0x00, /* bAlternateSetting */ \
0x02, /* bNumEndpoints */ \
CDC_DATA_INTERFACE_CLASS, /* bInterfaceClass */ \
0x00, /* bInterfaceSubClass */ \
0x00, /* bInterfaceProtocol */ \
0x00, /* iInterface */ /* Endpoint Out */ \
0x07, /* bLength */ \
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \
out_ep, /* bEndpointAddress */ \
0x02, /* bmAttributes */ \
0x40, 0x00, /* wMaxPacketSize */ \
0x01, /* bInterval */ /* Endpoint In */ \
0x07, /* bLength */ \
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \
in_ep, /* bEndpointAddress */ \
0x02, /* bmAttributes */ \
0x40, 0x00, /* wMaxPacketSize */ \
0x01 /* bInterval */
0x08, /* bLength */ \
USB_DESCRIPTOR_TYPE_INTERFACE_ASSOCIATION, /* bDescriptorType */ \
bFirstInterface, /* bFirstInterface */ \
0x02, /* bInterfaceCount */ \
USB_DEVICE_CLASS_CDC, /* bFunctionClass */ \
CDC_ABSTRACT_CONTROL_MODEL, /* bFunctionSubClass */ \
CDC_COMMON_PROTOCOL_AT_COMMANDS, /* bFunctionProtocol */ \
0x00, /* iFunction */ /* CDC Control Interface */ \
0x09, /* bLength */ \
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
bFirstInterface, /* bInterfaceNumber */ \
0x00, /* bAlternateSetting */ \
0x01, /* bNumEndpoints */ \
USB_DEVICE_CLASS_CDC, /* bInterfaceClass */ \
CDC_ABSTRACT_CONTROL_MODEL, /* bInterfaceSubClass */ \
CDC_COMMON_PROTOCOL_AT_COMMANDS, /* bInterfaceProtocol */ \
str_idx, /* iInterface */ /* CDC Header */ \
0x05, /* bLength */ \
CDC_CS_INTERFACE, /* bDescriptorType */ \
CDC_FUNC_DESC_HEADER, /* bDescriptorSubtype */ \
WBVAL(CDC_V1_10), /* bcdCDC */ /* CDC Call */ \
0x05, /* bLength */ \
CDC_CS_INTERFACE, /* bDescriptorType */ \
CDC_FUNC_DESC_CALL_MANAGEMENT, /* bDescriptorSubtype */ \
bFirstInterface, /* bmCapabilities */ \
(uint8_t)(bFirstInterface + 1), /* bDataInterface */ /* CDC ACM: support line request */ \
0x04, /* bLength */ \
CDC_CS_INTERFACE, /* bDescriptorType */ \
CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT, /* bDescriptorSubtype */ \
0x02, /* bmCapabilities */ /* CDC Union */ \
0x05, /* bLength */ \
CDC_CS_INTERFACE, /* bDescriptorType */ \
CDC_FUNC_DESC_UNION, /* bDescriptorSubtype */ \
bFirstInterface, /* bMasterInterface */ \
(uint8_t)(bFirstInterface + 1), /* bSlaveInterface0 */ /* Endpoint Notification */ \
0x07, /* bLength */ \
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \
int_ep, /* bEndpointAddress */ \
0x03, /* bmAttributes */ \
0x40, 0x00, /* wMaxPacketSize */ \
0x01, /* bInterval */ /* CDC Data Interface */ \
0x09, /* bLength */ \
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
(uint8_t)(bFirstInterface + 1), /* bInterfaceNumber */ \
0x00, /* bAlternateSetting */ \
0x02, /* bNumEndpoints */ \
CDC_DATA_INTERFACE_CLASS, /* bInterfaceClass */ \
0x00, /* bInterfaceSubClass */ \
0x00, /* bInterfaceProtocol */ \
0x00, /* iInterface */ /* Endpoint Out */ \
0x07, /* bLength */ \
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \
out_ep, /* bEndpointAddress */ \
0x02, /* bmAttributes */ \
0x40, 0x00, /* wMaxPacketSize */ \
0x01, /* bInterval */ /* Endpoint In */ \
0x07, /* bLength */ \
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \
in_ep, /* bEndpointAddress */ \
0x02, /* bmAttributes */ \
0x40, 0x00, /* wMaxPacketSize */ \
0x01 /* bInterval */
#else
#define CDC_ACM_DESCRIPTOR_INIT(bFirstInterface, int_ep, out_ep, in_ep, str_idx) \
/* Interface Associate */ \
0x08, /* bLength */ \
USB_DESCRIPTOR_TYPE_INTERFACE_ASSOCIATION, /* bDescriptorType */ \
bFirstInterface, /* bFirstInterface */ \
0x02, /* bInterfaceCount */ \
USB_DEVICE_CLASS_CDC, /* bFunctionClass */ \
CDC_ABSTRACT_CONTROL_MODEL, /* bFunctionSubClass */ \
CDC_COMMON_PROTOCOL_AT_COMMANDS, /* bFunctionProtocol */ \
0x00, /* iFunction */ /* CDC Control Interface */ \
0x09, /* bLength */ \
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
bFirstInterface, /* bInterfaceNumber */ \
0x00, /* bAlternateSetting */ \
0x01, /* bNumEndpoints */ \
USB_DEVICE_CLASS_CDC, /* bInterfaceClass */ \
CDC_ABSTRACT_CONTROL_MODEL, /* bInterfaceSubClass */ \
CDC_COMMON_PROTOCOL_AT_COMMANDS, /* bInterfaceProtocol */ \
str_idx, /* iInterface */ /* CDC Header */ \
0x05, /* bLength */ \
CDC_CS_INTERFACE, /* bDescriptorType */ \
CDC_FUNC_DESC_HEADER, /* bDescriptorSubtype */ \
WBVAL(CDC_V1_10), /* bcdCDC */ /* CDC Call */ \
0x05, /* bLength */ \
CDC_CS_INTERFACE, /* bDescriptorType */ \
CDC_FUNC_DESC_CALL_MANAGEMENT, /* bDescriptorSubtype */ \
bFirstInterface, /* bmCapabilities */ \
(uint8_t)(bFirstInterface + 1), /* bDataInterface */ /* CDC ACM: support line request */ \
0x04, /* bLength */ \
CDC_CS_INTERFACE, /* bDescriptorType */ \
CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT, /* bDescriptorSubtype */ \
0x02, /* bmCapabilities */ /* CDC Union */ \
0x05, /* bLength */ \
CDC_CS_INTERFACE, /* bDescriptorType */ \
CDC_FUNC_DESC_UNION, /* bDescriptorSubtype */ \
bFirstInterface, /* bMasterInterface */ \
(uint8_t)(bFirstInterface + 1), /* bSlaveInterface0 */ /* Endpoint Notification */ \
0x07, /* bLength */ \
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \
int_ep, /* bEndpointAddress */ \
0x03, /* bmAttributes */ \
0x02, 0x00, /* wMaxPacketSize */ \
0x01, /* bInterval */ /* CDC Data Interface */ \
0x09, /* bLength */ \
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
(uint8_t)(bFirstInterface + 1), /* bInterfaceNumber */ \
0x00, /* bAlternateSetting */ \
0x02, /* bNumEndpoints */ \
CDC_DATA_INTERFACE_CLASS, /* bInterfaceClass */ \
0x00, /* bInterfaceSubClass */ \
0x00, /* bInterfaceProtocol */ \
0x00, /* iInterface */ /* Endpoint Out */ \
0x07, /* bLength */ \
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \
out_ep, /* bEndpointAddress */ \
0x02, /* bmAttributes */ \
0x02, 0x00, /* wMaxPacketSize */ \
0x01, /* bInterval */ /* Endpoint In */ \
0x07, /* bLength */ \
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \
in_ep, /* bEndpointAddress */ \
0x02, /* bmAttributes */ \
0x02, 0x00, /* wMaxPacketSize */ \
0x01 /* bInterval */
#endif
// clang-format on
void usbd_cdc_add_acm_interface(usbd_class_t *class, usbd_interface_t *intf);

View File

@@ -30,11 +30,19 @@ struct usbd_hid_cfg_private {
const uint8_t *hid_descriptor;
const uint8_t *hid_report_descriptor;
uint32_t hid_report_descriptor_len;
uint32_t protocol;
uint32_t idle_state;
uint8_t current_intf_num;
uint8_t hid_state;
uint8_t report;
uint8_t current_intf_num;
uint8_t idle_state;
uint8_t protocol;
uint8_t (*get_report_callback)(uint8_t report_id, uint8_t report_type);
void (*set_report_callback)(uint8_t report_id, uint8_t report_type, uint8_t *report, uint8_t report_len);
uint8_t (*get_idle_callback)(uint8_t report_id);
void (*set_idle_callback)(uint8_t report_id, uint8_t duration);
void (*set_protocol_callback)(uint8_t protocol);
uint8_t (*get_protocol_callback)(void);
usb_slist_t list;
} usbd_hid_cfg[4];
@@ -47,6 +55,7 @@ static void usbd_hid_reset(void)
{
struct usbd_hid_cfg_private *hid_intf = usb_slist_entry(i, struct usbd_hid_cfg_private, list);
hid_intf->hid_state = HID_STATE_IDLE;
hid_intf->report = 0;
hid_intf->idle_state = 0;
hid_intf->protocol = 0;
}
@@ -131,24 +140,42 @@ int hid_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, ui
switch (setup->bRequest) {
case HID_REQUEST_GET_REPORT:
if (current_hid_intf->get_report_callback)
current_hid_intf->report = current_hid_intf->get_report_callback(setup->wValueL, setup->wValueH); /*report id ,report type*/
*data = (uint8_t *)&current_hid_intf->report;
*len = 1;
break;
case HID_REQUEST_GET_IDLE:
if (current_hid_intf->get_idle_callback)
current_hid_intf->idle_state = current_hid_intf->get_idle_callback(setup->wValueL);
*data = (uint8_t *)&current_hid_intf->idle_state;
*len = 1;
break;
case HID_REQUEST_GET_PROTOCOL:
if (current_hid_intf->get_protocol_callback)
current_hid_intf->protocol = current_hid_intf->get_protocol_callback();
*data = (uint8_t *)&current_hid_intf->protocol;
*len = 1;
break;
case HID_REQUEST_SET_REPORT:
if (current_hid_intf->set_report_callback)
current_hid_intf->set_report_callback(setup->wValueL, setup->wValueH, *data, *len); /*report id ,report type,report,report len*/
current_hid_intf->report = **data;
break;
case HID_REQUEST_SET_IDLE:
current_hid_intf->idle_state = setup->wValueH;
if (current_hid_intf->set_idle_callback)
current_hid_intf->set_idle_callback(setup->wValueL, setup->wIndexH); /*report id ,duration*/
current_hid_intf->idle_state = setup->wIndexH;
break;
case HID_REQUEST_SET_PROTOCOL:
if (current_hid_intf->set_protocol_callback)
current_hid_intf->set_protocol_callback(setup->wValueL); /*protocol*/
current_hid_intf->protocol = setup->wValueL;
break;
@@ -205,6 +232,38 @@ void usbd_hid_report_descriptor_register(uint8_t intf_num, const uint8_t *desc,
}
}
}
// clang-format off
void usbd_hid_set_request_callback( uint8_t intf_num,
uint8_t (*get_report_callback)(uint8_t report_id, uint8_t report_type),
void (*set_report_callback)(uint8_t report_id, uint8_t report_type, uint8_t *report, uint8_t report_len),
uint8_t (*get_idle_callback)(uint8_t report_id),
void (*set_idle_callback)(uint8_t report_id, uint8_t duration),
void (*set_protocol_callback)(uint8_t protocol),
uint8_t (*get_protocol_callback)(void))
// clang-format on
{
usb_slist_t *i;
usb_slist_for_each(i, &usbd_hid_class_head)
{
struct usbd_hid_cfg_private *hid_intf = usb_slist_entry(i, struct usbd_hid_cfg_private, list);
if (hid_intf->current_intf_num == intf_num) {
if (get_report_callback)
hid_intf->get_report_callback = get_report_callback;
if (set_report_callback)
hid_intf->set_report_callback = set_report_callback;
if (get_idle_callback)
hid_intf->get_idle_callback = get_idle_callback;
if (set_idle_callback)
hid_intf->set_idle_callback = set_idle_callback;
if (set_protocol_callback)
hid_intf->set_protocol_callback = set_protocol_callback;
if (get_protocol_callback)
hid_intf->get_protocol_callback = get_protocol_callback;
return;
}
}
}
void usbd_hid_add_interface(usbd_class_t *class, usbd_interface_t *intf)
{

View File

@@ -12,6 +12,13 @@
extern "C" {
#endif
/* HID Protocol Codes */
#define HID_PROTOCOL_NONE 0x00
#define HID_PROTOCOL_BOOT 0x00
#define HID_PROTOCOL_KEYBOARD 0x01
#define HID_PROTOCOL_REPORT 0x01
#define HID_PROTOCOL_MOUSE 0x02
/* HID Class Descriptor Types */
#define HID_DESCRIPTOR_TYPE_HID 0x21
#define HID_DESCRIPTOR_TYPE_HID_REPORT 0x22
@@ -25,6 +32,11 @@ extern "C" {
#define HID_REQUEST_SET_IDLE 0x0A
#define HID_REQUEST_SET_PROTOCOL 0x0B
/* HID Report Types */
#define HID_REPORT_INPUT 0x01
#define HID_REPORT_OUTPUT 0x02
#define HID_REPORT_FEATURE 0x03
/* HID Report Definitions */
struct usb_hid_class_subdescriptor {
uint8_t bDescriptorType;
@@ -122,10 +134,6 @@ struct usb_hid_descriptor {
#define COLLECTION_PHYSICAL 0x00
#define COLLECTION_APPLICATION 0x01
/* Protocols */
#define HID_PROTOCOL_BOOT 0x00
#define HID_PROTOCOL_REPORT 0x01
/* Example HID report descriptors */
/**
* @brief Simple HID mouse report descriptor for n button mouse.
@@ -336,7 +344,15 @@ void usbd_hid_report_descriptor_register(uint8_t intf_num, const uint8_t *desc,
void usbd_hid_add_interface(usbd_class_t *class, usbd_interface_t *intf);
void usbd_hid_reset_state(void);
void usbd_hid_send_report(uint8_t ep, uint8_t *data, uint8_t len);
// clang-format off
void usbd_hid_set_request_callback( uint8_t intf_num,
uint8_t (*get_report_callback)(uint8_t report_id, uint8_t report_type),
void (*set_report_callback)(uint8_t report_id, uint8_t report_type, uint8_t *report, uint8_t report_len),
uint8_t (*get_idle_callback)(uint8_t report_id),
void (*set_idle_callback)(uint8_t report_id, uint8_t duration),
void (*set_protocol_callback)(uint8_t protocol),
uint8_t (*get_protocol_callback)(void));
// clang-format on
#ifdef __cplusplus
}
#endif

View File

@@ -25,8 +25,11 @@
#include "usbd_msc.h"
/* max USB packet size */
#ifndef CONFIG_USB_HS
#define MASS_STORAGE_BULK_EP_MPS 64
#define MASS_STORAGE_BLOCK_SIZE 512
#else
#define MASS_STORAGE_BULK_EP_MPS 512
#endif
#define MSD_OUT_EP_IDX 0
#define MSD_IN_EP_IDX 1
@@ -60,7 +63,7 @@ struct usbd_msc_cfg_private {
uint32_t scsi_blk_addr;
uint32_t scsi_blk_len;
uint8_t block_buffer[MASS_STORAGE_BLOCK_SIZE];
uint8_t *block_buffer;
} usbd_msc_cfg;
@@ -76,6 +79,11 @@ static void usbd_msc_reset(void)
usbd_msc_cfg.scsi_blk_len = 0U;
usbd_msc_get_cap(0, &usbd_msc_cfg.scsi_blk_nbr, &usbd_msc_cfg.scsi_blk_size);
usbd_msc_cfg.max_lun_count = 0;
if (usbd_msc_cfg.block_buffer) {
free(usbd_msc_cfg.block_buffer);
}
usbd_msc_cfg.block_buffer = malloc(usbd_msc_cfg.scsi_blk_size * sizeof(uint8_t));
}
/**
@@ -138,7 +146,6 @@ static bool usbd_msc_datain_check(void)
{
if (!usbd_msc_cfg.cbw.DataLength) {
USBD_LOG_WRN("Zero length in CBW");
//SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB);
usbd_msc_cfg.csw.Status = CSW_STATUS_PHASE_ERROR;
usbd_msc_send_csw();
return false;
@@ -164,7 +171,7 @@ static bool usbd_msc_send_to_host(uint8_t *buffer, uint16_t size)
}
if (usbd_ep_write(mass_ep_data[MSD_IN_EP_IDX].ep_addr, buffer, size, NULL)) {
USBD_LOG_ERR("USB write failed");
USBD_LOG_ERR("USB write failed\r\n");
return false;
}
@@ -478,11 +485,10 @@ static bool usbd_msc_read_write_process(void)
{
/* Logical Block Address of First Block */
uint32_t lba;
uint32_t len = 0;
uint32_t blk_num = 0;
if (!usbd_msc_cfg.cbw.DataLength) {
USBD_LOG_WRN("Zero length in CBW\r\n");
//SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB);
usbd_msc_cfg.csw.Status = CSW_STATUS_PHASE_ERROR;
usbd_msc_send_csw();
return false;
@@ -498,22 +504,22 @@ static bool usbd_msc_read_write_process(void)
case SCSI_READ10:
case SCSI_WRITE10:
case SCSI_VERIFY10:
len = GET_BE16(&usbd_msc_cfg.cbw.CB[7]);
blk_num = GET_BE16(&usbd_msc_cfg.cbw.CB[7]);
break;
case SCSI_READ12:
case SCSI_WRITE12:
len = GET_BE32(&usbd_msc_cfg.cbw.CB[6]);
blk_num = GET_BE32(&usbd_msc_cfg.cbw.CB[6]);
break;
default:
break;
}
USBD_LOG_DBG("len (block) : 0x%x\r\n", len);
usbd_msc_cfg.scsi_blk_len = len * usbd_msc_cfg.scsi_blk_size;
USBD_LOG_DBG("num (block) : 0x%x\r\n", blk_num);
usbd_msc_cfg.scsi_blk_len = blk_num * usbd_msc_cfg.scsi_blk_size;
if ((lba + len) > usbd_msc_cfg.scsi_blk_nbr) {
if ((lba + blk_num) > usbd_msc_cfg.scsi_blk_nbr) {
USBD_LOG_ERR("LBA out of range\r\n");
usbd_msc_cfg.csw.Status = CSW_STATUS_CMD_FAILED;
usbd_msc_send_csw();

View File

@@ -64,30 +64,57 @@ struct CSW {
/*Length of template descriptor: 23 bytes*/
#define MSC_DESCRIPTOR_LEN (9 + 7 + 7)
#define MSC_DESCRIPTOR_INIT(bFirstInterface, out_ep, in_ep, str_idx) \
// clang-format off
#ifndef SUPPORT_USB_HS
#define MSC_DESCRIPTOR_INIT(bFirstInterface, out_ep, in_ep,str_idx) \
/* Interface */ \
0x09, /* bLength */ \
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
bFirstInterface, /* bInterfaceNumber */ \
0x00, /* bAlternateSetting */ \
0x02, /* bNumEndpoints */ \
USB_DEVICE_CLASS_MASS_STORAGE, /* bInterfaceClass */ \
MSC_SUBCLASS_SCSI, /* bInterfaceSubClass */ \
MSC_PROTOCOL_BULK_ONLY, /* bInterfaceProtocol */ \
str_idx, /* iInterface */ /* Endpoint Out */ \
0x07, /* bLength */ \
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \
out_ep, /* bEndpointAddress */ \
0x02, /* bmAttributes */ \
0x40, 0x00, /* wMaxPacketSize */ \
0x01, /* bInterval */ /* Endpoint In */ \
0x07, /* bLength */ \
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \
in_ep, /* bEndpointAddress */ \
0x02, /* bmAttributes */ \
0x40, 0x00, /* wMaxPacketSize */ \
0x01 /* bInterval */
0x09, /* bLength */ \
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
bFirstInterface, /* bInterfaceNumber */ \
0x00, /* bAlternateSetting */ \
0x02, /* bNumEndpoints */ \
USB_DEVICE_CLASS_MASS_STORAGE, /* bInterfaceClass */ \
MSC_SUBCLASS_SCSI, /* bInterfaceSubClass */ \
MSC_PROTOCOL_BULK_ONLY, /* bInterfaceProtocol */ \
str_idx, /* iInterface */ /* Endpoint Out */ \
0x07, /* bLength */ \
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \
out_ep, /* bEndpointAddress */ \
0x02, /* bmAttributes */ \
0x40, 0x00, /* wMaxPacketSize */ \
0x01, /* bInterval */ /* Endpoint In */ \
0x07, /* bLength */ \
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \
in_ep, /* bEndpointAddress */ \
0x02, /* bmAttributes */ \
0x40, 0x00, /* wMaxPacketSize */ \
0x01 /* bInterval */
#else
#define MSC_DESCRIPTOR_INIT(bFirstInterface, out_ep, in_ep,str_idx) \
/* Interface */ \
0x09, /* bLength */ \
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
bFirstInterface, /* bInterfaceNumber */ \
0x00, /* bAlternateSetting */ \
0x02, /* bNumEndpoints */ \
USB_DEVICE_CLASS_MASS_STORAGE, /* bInterfaceClass */ \
MSC_SUBCLASS_SCSI, /* bInterfaceSubClass */ \
MSC_PROTOCOL_BULK_ONLY, /* bInterfaceProtocol */ \
str_idx, /* iInterface */ /* Endpoint Out */ \
0x07, /* bLength */ \
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \
out_ep, /* bEndpointAddress */ \
0x02, /* bmAttributes */ \
0x02, 0x00, /* wMaxPacketSize */ \
0x01, /* bInterval */ /* Endpoint In */ \
0x07, /* bLength */ \
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \
in_ep, /* bEndpointAddress */ \
0x02, /* bmAttributes */ \
0x02, 0x00, /* wMaxPacketSize */ \
0x01 /* bInterval */
#endif
// clang-format on
void usbd_msc_class_init(uint8_t out_ep, uint8_t in_ep);
void usbd_msc_get_cap(uint8_t lun, uint32_t *block_num, uint16_t *block_size);

View File

@@ -19,19 +19,4 @@
#define WEBUSB_CONFIGURATION_SUBSET_HEADER_SIZE 4
#define WEBUSB_FUNCTION_SUBSET_HEADER_SIZE 3
/* BOS Capability webusb */
struct usb_bos_webusb_platform_capability_descriptor {
struct usb_bos_capability_descriptor webusb_platform;
uint16_t bcdVersion;
uint8_t bVendorCode;
uint8_t iLandingPage;
} __packed;
struct webusb_url_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bScheme;
char URL[];
} __packed;
#endif

View File

@@ -23,13 +23,4 @@
#define WINUSB_PROP_DATA_TYPE_REG_SZ 0x01
#define WINUSB_PROP_DATA_TYPE_REG_MULTI_SZ 0x07
/* WinUSB Microsoft OS 2.0 descriptor Platform Capability Descriptor */
struct usb_bos_winusb_platform_capability_descriptor {
struct usb_bos_capability_descriptor winusb_platform;
uint32_t dwWindowsVersion;
uint16_t wMSOSDescriptorSetTotalLength;
uint8_t bMS_VendorCode;
uint8_t bAltEnumCode;
} __packed;
#endif