update(demo): remove all old desc api
Signed-off-by: sakumisu <1203593632@qq.com>
This commit is contained in:
211
core/usbd_core.c
211
core/usbd_core.c
@@ -48,16 +48,10 @@ USB_NOCACHE_RAM_SECTION struct usbd_core_priv {
|
||||
uint32_t ep0_data_buf_len;
|
||||
/** Zero length packet flag of control transfer */
|
||||
bool zlp_flag;
|
||||
|
||||
/** Pointer to registered descriptors */
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
const struct usb_descriptor *descriptors;
|
||||
#else
|
||||
const uint8_t *descriptors;
|
||||
struct usb_msosv1_descriptor *msosv1_desc;
|
||||
struct usb_msosv2_descriptor *msosv2_desc;
|
||||
struct usb_bos_descriptor *bos_desc;
|
||||
struct usb_webusb_descriptor *webusb_url_desc;
|
||||
#endif
|
||||
|
||||
/* Buffer used for storing standard, class and vendor request data */
|
||||
USB_MEM_ALIGNX uint8_t req_data[USB_ALIGN_UP(CONFIG_USBDEV_REQUEST_BUFFER_LEN, CONFIG_USB_ALIGN_SIZE)];
|
||||
|
||||
@@ -69,9 +63,7 @@ USB_NOCACHE_RAM_SECTION struct usbd_core_priv {
|
||||
bool remote_wakeup_support;
|
||||
bool remote_wakeup_enabled;
|
||||
bool is_suspend;
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
uint8_t speed;
|
||||
#endif
|
||||
#ifdef CONFIG_USBDEV_TEST_MODE
|
||||
bool test_req;
|
||||
#endif
|
||||
@@ -180,7 +172,6 @@ static bool usbd_reset_endpoint(uint8_t busid, const struct usb_endpoint_descrip
|
||||
*
|
||||
* @return true if the descriptor was found, false otherwise
|
||||
*/
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
static bool usbd_get_descriptor(uint8_t busid, uint16_t type_index, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
uint8_t type = 0U;
|
||||
@@ -326,93 +317,6 @@ static bool usbd_get_descriptor(uint8_t busid, uint16_t type_index, uint8_t **da
|
||||
}
|
||||
return found;
|
||||
}
|
||||
#else
|
||||
static bool usbd_get_descriptor(uint8_t busid, uint16_t type_index, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
uint8_t type = 0U;
|
||||
uint8_t index = 0U;
|
||||
uint8_t *p = NULL;
|
||||
uint32_t cur_index = 0U;
|
||||
bool found = false;
|
||||
|
||||
type = HI_BYTE(type_index);
|
||||
index = LO_BYTE(type_index);
|
||||
|
||||
if ((type == USB_DESCRIPTOR_TYPE_STRING) && (index == USB_OSDESC_STRING_DESC_INDEX)) {
|
||||
if (!g_usbd_core[busid].msosv1_desc) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*data = (uint8_t *)g_usbd_core[busid].msosv1_desc->string;
|
||||
//memcpy(*data, (uint8_t *)g_usbd_core[busid].msosv1_desc->string, g_usbd_core[busid].msosv1_desc->string[0]);
|
||||
*len = g_usbd_core[busid].msosv1_desc->string[0];
|
||||
|
||||
return true;
|
||||
} else if (type == USB_DESCRIPTOR_TYPE_BINARY_OBJECT_STORE) {
|
||||
if (!g_usbd_core[busid].bos_desc) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*data = (uint8_t *)g_usbd_core[busid].bos_desc->string;
|
||||
//memcpy(*data, (uint8_t *)g_usbd_core[busid].bos_desc->string, g_usbd_core[busid].bos_desc->string_len);
|
||||
*len = g_usbd_core[busid].bos_desc->string_len;
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
* Invalid types of descriptors,
|
||||
* see USB Spec. Revision 2.0, 9.4.3 Get Descriptor
|
||||
*/
|
||||
else if ((type == USB_DESCRIPTOR_TYPE_INTERFACE) || (type == USB_DESCRIPTOR_TYPE_ENDPOINT) ||
|
||||
#ifndef CONFIG_USB_HS
|
||||
(type > USB_DESCRIPTOR_TYPE_ENDPOINT)) {
|
||||
#else
|
||||
(type > USB_DESCRIPTOR_TYPE_OTHER_SPEED)) {
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
p = (uint8_t *)g_usbd_core[busid].descriptors;
|
||||
|
||||
cur_index = 0U;
|
||||
|
||||
while (p[DESC_bLength] != 0U) {
|
||||
if (p[DESC_bDescriptorType] == type) {
|
||||
if (cur_index == index) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
cur_index++;
|
||||
}
|
||||
|
||||
/* skip to next descriptor */
|
||||
p += p[DESC_bLength];
|
||||
}
|
||||
|
||||
if (found) {
|
||||
if ((type == USB_DESCRIPTOR_TYPE_CONFIGURATION) || ((type == USB_DESCRIPTOR_TYPE_OTHER_SPEED))) {
|
||||
/* configuration or other speed descriptor is an
|
||||
* exception, length is at offset 2 and 3
|
||||
*/
|
||||
*len = (p[CONF_DESC_wTotalLength]) |
|
||||
(p[CONF_DESC_wTotalLength + 1] << 8);
|
||||
|
||||
g_usbd_core[busid].self_powered = (p[7] & USB_CONFIG_POWERED_MASK) ? true : false;
|
||||
g_usbd_core[busid].remote_wakeup_support = (p[7] & USB_CONFIG_REMOTE_WAKEUP) ? true : false;
|
||||
} else {
|
||||
/* normally length is at offset 0 */
|
||||
*len = p[DESC_bLength];
|
||||
}
|
||||
*data = p;
|
||||
//memcpy(*data, p, *len);
|
||||
} else {
|
||||
/* nothing found */
|
||||
USB_LOG_ERR("descriptor <type:0x%02x,index:0x%02x> not found!\r\n", type, index);
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief set USB configuration
|
||||
@@ -436,11 +340,8 @@ static bool usbd_set_configuration(uint8_t busid, uint8_t config_index, uint8_t
|
||||
uint32_t desc_len = 0;
|
||||
uint32_t current_desc_len = 0;
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
p = g_usbd_core[busid].descriptors->config_descriptor_callback(g_usbd_core[busid].speed);
|
||||
#else
|
||||
p = (uint8_t *)g_usbd_core[busid].descriptors;
|
||||
#endif
|
||||
|
||||
/* configure endpoints for this configuration/altsetting */
|
||||
while (p[DESC_bLength] != 0U) {
|
||||
switch (p[DESC_bDescriptorType]) {
|
||||
@@ -508,11 +409,8 @@ static bool usbd_set_interface(uint8_t busid, uint8_t iface, uint8_t alt_setting
|
||||
uint32_t desc_len = 0;
|
||||
uint32_t current_desc_len = 0;
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
p = g_usbd_core[busid].descriptors->config_descriptor_callback(g_usbd_core[busid].speed);
|
||||
#else
|
||||
p = (uint8_t *)g_usbd_core[busid].descriptors;
|
||||
#endif
|
||||
|
||||
USB_LOG_DBG("iface %u alt_setting %u\r\n", iface, alt_setting);
|
||||
|
||||
while (p[DESC_bLength] != 0U) {
|
||||
@@ -683,11 +581,7 @@ static bool usbd_std_interface_req_handler(uint8_t busid, struct usb_setup_packe
|
||||
uint32_t current_desc_len = 0;
|
||||
uint8_t cur_iface = 0xFF;
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
p = g_usbd_core[busid].descriptors->config_descriptor_callback(g_usbd_core[busid].speed);
|
||||
#else
|
||||
p = (uint8_t *)g_usbd_core[busid].descriptors;
|
||||
#endif
|
||||
|
||||
/* Only when device is configured, then interface requests can be valid. */
|
||||
if (!is_device_configured(busid)) {
|
||||
@@ -925,7 +819,7 @@ static int usbd_class_request_handler(uint8_t busid, struct usb_setup_packet *se
|
||||
static int usbd_vendor_request_handler(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
uint32_t desclen;
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
|
||||
if (g_usbd_core[busid].descriptors->msosv1_descriptor) {
|
||||
if (setup->bRequest == g_usbd_core[busid].descriptors->msosv1_descriptor->vendor_code) {
|
||||
switch (setup->wIndex) {
|
||||
@@ -982,61 +876,7 @@ static int usbd_vendor_request_handler(uint8_t busid, struct usb_setup_packet *s
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (g_usbd_core[busid].msosv1_desc) {
|
||||
if (setup->bRequest == g_usbd_core[busid].msosv1_desc->vendor_code) {
|
||||
switch (setup->wIndex) {
|
||||
case 0x04:
|
||||
*data = (uint8_t *)g_usbd_core[busid].msosv1_desc->compat_id;
|
||||
desclen = g_usbd_core[busid].msosv1_desc->compat_id[0] +
|
||||
(g_usbd_core[busid].msosv1_desc->compat_id[1] << 8) +
|
||||
(g_usbd_core[busid].msosv1_desc->compat_id[2] << 16) +
|
||||
(g_usbd_core[busid].msosv1_desc->compat_id[3] << 24);
|
||||
//memcpy(*data, g_usbd_core[busid].msosv1_desc->compat_id, desclen);
|
||||
*len = desclen;
|
||||
return 0;
|
||||
case 0x05:
|
||||
*data = (uint8_t *)g_usbd_core[busid].msosv1_desc->comp_id_property[setup->wValue];
|
||||
desclen = g_usbd_core[busid].msosv1_desc->comp_id_property[setup->wValue][0] +
|
||||
(g_usbd_core[busid].msosv1_desc->comp_id_property[setup->wValue][1] << 8) +
|
||||
(g_usbd_core[busid].msosv1_desc->comp_id_property[setup->wValue][2] << 16) +
|
||||
(g_usbd_core[busid].msosv1_desc->comp_id_property[setup->wValue][3] << 24);
|
||||
//memcpy(*data, g_usbd_core[busid].msosv1_desc->comp_id_property[setup->wValue], desclen);
|
||||
*len = desclen;
|
||||
return 0;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} else if (g_usbd_core[busid].msosv2_desc) {
|
||||
if (setup->bRequest == g_usbd_core[busid].msosv2_desc->vendor_code) {
|
||||
switch (setup->wIndex) {
|
||||
case WINUSB_REQUEST_GET_DESCRIPTOR_SET:
|
||||
*data = (uint8_t *)g_usbd_core[busid].msosv2_desc->compat_id;
|
||||
//memcpy(*data, g_usbd_core[busid].msosv2_desc->compat_id, g_usbd_core[busid].msosv2_desc->compat_id_len);
|
||||
*len = g_usbd_core[busid].msosv2_desc->compat_id_len;
|
||||
return 0;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (g_usbd_core[busid].webusb_url_desc) {
|
||||
if (setup->bRequest == g_usbd_core[busid].webusb_url_desc->vendor_code) {
|
||||
switch (setup->wIndex) {
|
||||
case WEBUSB_REQUEST_GET_URL:
|
||||
desclen = g_usbd_core[busid].webusb_url_desc->string_len;
|
||||
*data = (uint8_t *)g_usbd_core[busid].webusb_url_desc->string;
|
||||
//memcpy(*data, g_usbd_core[busid].webusb_url_desc->string, desclen);
|
||||
*len = desclen;
|
||||
return 0;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
for (uint8_t i = 0; i < g_usbd_core[busid].intf_offset; i++) {
|
||||
struct usbd_interface *intf = g_usbd_core[busid].intf[i];
|
||||
|
||||
@@ -1151,7 +991,6 @@ void usbd_event_reset_handler(uint8_t busid)
|
||||
g_usbd_core[busid].device_address = 0;
|
||||
g_usbd_core[busid].configuration = 0;
|
||||
g_usbd_core[busid].ep0_next_state = USBD_EP0_STATE_SETUP;
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
g_usbd_core[busid].speed = USB_SPEED_UNKNOWN;
|
||||
|
||||
USB_ASSERT_MSG(g_usbd_core[busid].descriptors->device_descriptor_callback != NULL,
|
||||
@@ -1159,9 +998,6 @@ void usbd_event_reset_handler(uint8_t busid)
|
||||
|
||||
struct usb_device_descriptor *device_desc = (struct usb_device_descriptor *)g_usbd_core[busid].descriptors->device_descriptor_callback(g_usbd_core[busid].speed);
|
||||
ep0.wMaxPacketSize = device_desc->bMaxPacketSize0;
|
||||
#else
|
||||
ep0.wMaxPacketSize = USB_CTRL_EP_MPS;
|
||||
#endif
|
||||
|
||||
ep0.bLength = 7;
|
||||
ep0.bDescriptorType = USB_DESCRIPTOR_TYPE_ENDPOINT;
|
||||
@@ -1377,7 +1213,6 @@ void usbd_event_ep_out_complete_handler(uint8_t busid, uint8_t ep, uint32_t nbyt
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
void usbd_desc_register(uint8_t busid, const struct usb_descriptor *desc)
|
||||
{
|
||||
memset(&g_usbd_core[busid], 0, sizeof(struct usbd_core_priv));
|
||||
@@ -1390,42 +1225,6 @@ void usbd_desc_register(uint8_t busid, const struct usb_descriptor *desc)
|
||||
g_usbd_core[busid].rx_msg[0].ep = 0x00;
|
||||
g_usbd_core[busid].rx_msg[0].cb = usbd_event_ep0_out_complete_handler;
|
||||
}
|
||||
#else
|
||||
void usbd_desc_register(uint8_t busid, const uint8_t *desc)
|
||||
{
|
||||
memset(&g_usbd_core[busid], 0, sizeof(struct usbd_core_priv));
|
||||
|
||||
g_usbd_core[busid].descriptors = desc;
|
||||
g_usbd_core[busid].intf_offset = 0;
|
||||
|
||||
g_usbd_core[busid].tx_msg[0].ep = 0x80;
|
||||
g_usbd_core[busid].tx_msg[0].cb = usbd_event_ep0_in_complete_handler;
|
||||
g_usbd_core[busid].rx_msg[0].ep = 0x00;
|
||||
g_usbd_core[busid].rx_msg[0].cb = usbd_event_ep0_out_complete_handler;
|
||||
}
|
||||
|
||||
/* Register MS OS Descriptors version 1 */
|
||||
void usbd_msosv1_desc_register(uint8_t busid, struct usb_msosv1_descriptor *desc)
|
||||
{
|
||||
g_usbd_core[busid].msosv1_desc = desc;
|
||||
}
|
||||
|
||||
/* Register MS OS Descriptors version 2 */
|
||||
void usbd_msosv2_desc_register(uint8_t busid, struct usb_msosv2_descriptor *desc)
|
||||
{
|
||||
g_usbd_core[busid].msosv2_desc = desc;
|
||||
}
|
||||
|
||||
void usbd_bos_desc_register(uint8_t busid, struct usb_bos_descriptor *desc)
|
||||
{
|
||||
g_usbd_core[busid].bos_desc = desc;
|
||||
}
|
||||
|
||||
void usbd_webusb_desc_register(uint8_t busid, struct usb_webusb_descriptor *desc)
|
||||
{
|
||||
g_usbd_core[busid].webusb_url_desc = desc;
|
||||
}
|
||||
#endif
|
||||
|
||||
void usbd_add_interface(uint8_t busid, struct usbd_interface *intf)
|
||||
{
|
||||
|
||||
@@ -96,15 +96,7 @@ extern struct usbd_bus g_usbdev_bus[];
|
||||
#error USBD_IRQHandler is obsolete, please call USBD_IRQHandler(xxx) in your irq
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
void usbd_desc_register(uint8_t busid, const struct usb_descriptor *desc);
|
||||
#else
|
||||
void usbd_desc_register(uint8_t busid, const uint8_t *desc);
|
||||
void usbd_msosv1_desc_register(uint8_t busid, struct usb_msosv1_descriptor *desc);
|
||||
void usbd_msosv2_desc_register(uint8_t busid, struct usb_msosv2_descriptor *desc);
|
||||
void usbd_bos_desc_register(uint8_t busid, struct usb_bos_descriptor *desc);
|
||||
void usbd_webusb_desc_register(uint8_t busid, struct usb_webusb_descriptor *desc);
|
||||
#endif
|
||||
|
||||
void usbd_add_interface(uint8_t busid, struct usbd_interface *intf);
|
||||
void usbd_add_endpoint(uint8_t busid, struct usbd_endpoint *ep);
|
||||
|
||||
Reference in New Issue
Block a user