|
|
@@ -1,6 +1,4 @@
|
|
|
/*
|
|
|
- * Copyright (C) 2006 Bertrik Sikken (bertrik@sikken.nl)
|
|
|
- * Copyright (c) 2016 Intel Corporation
|
|
|
* Copyright (c) 2022, sakumisu
|
|
|
*
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
@@ -63,9 +61,11 @@ USB_NOCACHE_RAM_SECTION struct usbd_core_priv {
|
|
|
|
|
|
struct usbd_tx_rx_msg tx_msg[USB_EP_IN_NUM];
|
|
|
struct usbd_tx_rx_msg rx_msg[USB_EP_OUT_NUM];
|
|
|
-} g_usbd_core;
|
|
|
|
|
|
-static void usbd_class_event_notify_handler(uint8_t event, void *arg);
|
|
|
+ void (*event_handler)(uint8_t event);
|
|
|
+} g_usbd_core[CONFIG_USBDEV_MAX_BUS];
|
|
|
+
|
|
|
+static void usbd_class_event_notify_handler(uint8_t busid, uint8_t event, void *arg);
|
|
|
|
|
|
static void usbd_print_setup(struct usb_setup_packet *setup)
|
|
|
{
|
|
|
@@ -78,9 +78,9 @@ static void usbd_print_setup(struct usb_setup_packet *setup)
|
|
|
setup->wLength);
|
|
|
}
|
|
|
|
|
|
-static bool is_device_configured(void)
|
|
|
+static bool is_device_configured(uint8_t busid)
|
|
|
{
|
|
|
- return (g_usbd_core.configuration != 0);
|
|
|
+ return (g_usbd_core[busid].configuration != 0);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -93,14 +93,14 @@ static bool is_device_configured(void)
|
|
|
*
|
|
|
* @return true if successfully configured and enabled
|
|
|
*/
|
|
|
-static bool usbd_set_endpoint(const struct usb_endpoint_descriptor *ep)
|
|
|
+static bool usbd_set_endpoint(uint8_t busid, const struct usb_endpoint_descriptor *ep)
|
|
|
{
|
|
|
USB_LOG_INFO("Open ep:0x%02x type:%u mps:%u\r\n",
|
|
|
ep->bEndpointAddress,
|
|
|
USB_GET_ENDPOINT_TYPE(ep->bmAttributes),
|
|
|
USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize));
|
|
|
|
|
|
- return usbd_ep_open(ep) == 0 ? true : false;
|
|
|
+ return usbd_ep_open(busid, ep) == 0 ? true : false;
|
|
|
}
|
|
|
/**
|
|
|
* @brief Disable endpoint for transferring data
|
|
|
@@ -112,13 +112,13 @@ static bool usbd_set_endpoint(const struct usb_endpoint_descriptor *ep)
|
|
|
*
|
|
|
* @return true if successfully deconfigured and disabled
|
|
|
*/
|
|
|
-static bool usbd_reset_endpoint(const struct usb_endpoint_descriptor *ep)
|
|
|
+static bool usbd_reset_endpoint(uint8_t busid, const struct usb_endpoint_descriptor *ep)
|
|
|
{
|
|
|
USB_LOG_INFO("Close ep:0x%02x type:%u\r\n",
|
|
|
ep->bEndpointAddress,
|
|
|
USB_GET_ENDPOINT_TYPE(ep->bmAttributes));
|
|
|
|
|
|
- return usbd_ep_close(ep->bEndpointAddress) == 0 ? true : false;
|
|
|
+ return usbd_ep_close(busid, ep->bEndpointAddress) == 0 ? true : false;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -134,7 +134,7 @@ static bool usbd_reset_endpoint(const struct usb_endpoint_descriptor *ep)
|
|
|
* @return true if the descriptor was found, false otherwise
|
|
|
*/
|
|
|
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
|
|
-static bool usbd_get_descriptor(uint16_t type_index, uint8_t **data, uint32_t *len)
|
|
|
+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;
|
|
|
@@ -147,7 +147,7 @@ static bool usbd_get_descriptor(uint16_t type_index, uint8_t **data, uint32_t *l
|
|
|
|
|
|
switch (type) {
|
|
|
case USB_DESCRIPTOR_TYPE_DEVICE:
|
|
|
- desc = g_usbd_core.descriptors->device_descriptor_callback(g_usbd_core.speed);
|
|
|
+ desc = g_usbd_core[busid].descriptors->device_descriptor_callback(g_usbd_core[busid].speed);
|
|
|
if (desc == NULL) {
|
|
|
found = false;
|
|
|
break;
|
|
|
@@ -155,7 +155,7 @@ static bool usbd_get_descriptor(uint16_t type_index, uint8_t **data, uint32_t *l
|
|
|
desc_len = desc[0];
|
|
|
break;
|
|
|
case USB_DESCRIPTOR_TYPE_CONFIGURATION:
|
|
|
- desc = g_usbd_core.descriptors->config_descriptor_callback(g_usbd_core.speed);
|
|
|
+ desc = g_usbd_core[busid].descriptors->config_descriptor_callback(g_usbd_core[busid].speed);
|
|
|
if (desc == NULL) {
|
|
|
found = false;
|
|
|
break;
|
|
|
@@ -166,15 +166,15 @@ static bool usbd_get_descriptor(uint16_t type_index, uint8_t **data, uint32_t *l
|
|
|
if (index == USB_OSDESC_STRING_DESC_INDEX) {
|
|
|
USB_LOG_INFO("read MS OS 2.0 descriptor string\r\n");
|
|
|
|
|
|
- if (!g_usbd_core.descriptors->msosv1_descriptor) {
|
|
|
+ if (!g_usbd_core[busid].descriptors->msosv1_descriptor) {
|
|
|
found = false;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- desc = (uint8_t *)g_usbd_core.descriptors->msosv1_descriptor->string;
|
|
|
- desc_len = g_usbd_core.descriptors->msosv1_descriptor->string[0];
|
|
|
+ desc = (uint8_t *)g_usbd_core[busid].descriptors->msosv1_descriptor->string;
|
|
|
+ desc_len = g_usbd_core[busid].descriptors->msosv1_descriptor->string[0];
|
|
|
} else {
|
|
|
- desc = g_usbd_core.descriptors->string_descriptor_callback(g_usbd_core.speed, index);
|
|
|
+ desc = g_usbd_core[busid].descriptors->string_descriptor_callback(g_usbd_core[busid].speed, index);
|
|
|
if (desc == NULL) {
|
|
|
found = false;
|
|
|
break;
|
|
|
@@ -183,7 +183,7 @@ static bool usbd_get_descriptor(uint16_t type_index, uint8_t **data, uint32_t *l
|
|
|
}
|
|
|
break;
|
|
|
case USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER:
|
|
|
- desc = g_usbd_core.descriptors->device_quality_descriptor_callback(g_usbd_core.speed);
|
|
|
+ desc = g_usbd_core[busid].descriptors->device_quality_descriptor_callback(g_usbd_core[busid].speed);
|
|
|
if (desc == NULL) {
|
|
|
found = false;
|
|
|
break;
|
|
|
@@ -191,7 +191,7 @@ static bool usbd_get_descriptor(uint16_t type_index, uint8_t **data, uint32_t *l
|
|
|
desc_len = desc[0];
|
|
|
break;
|
|
|
case USB_DESCRIPTOR_TYPE_OTHER_SPEED:
|
|
|
- desc = g_usbd_core.descriptors->other_speed_descriptor_callback(g_usbd_core.speed);
|
|
|
+ desc = g_usbd_core[busid].descriptors->other_speed_descriptor_callback(g_usbd_core[busid].speed);
|
|
|
if (desc == NULL) {
|
|
|
found = false;
|
|
|
break;
|
|
|
@@ -202,13 +202,13 @@ static bool usbd_get_descriptor(uint16_t type_index, uint8_t **data, uint32_t *l
|
|
|
case USB_DESCRIPTOR_TYPE_BINARY_OBJECT_STORE:
|
|
|
USB_LOG_INFO("read BOS descriptor string\r\n");
|
|
|
|
|
|
- if (!g_usbd_core.descriptors->bos_descriptor) {
|
|
|
+ if (!g_usbd_core[busid].descriptors->bos_descriptor) {
|
|
|
found = false;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- desc = (uint8_t *)g_usbd_core.descriptors->bos_descriptor->string;
|
|
|
- desc_len = g_usbd_core.descriptors->bos_descriptor->string_len;
|
|
|
+ desc = (uint8_t *)g_usbd_core[busid].descriptors->bos_descriptor->string;
|
|
|
+ desc_len = g_usbd_core[busid].descriptors->bos_descriptor->string_len;
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
@@ -227,7 +227,7 @@ static bool usbd_get_descriptor(uint16_t type_index, uint8_t **data, uint32_t *l
|
|
|
return found;
|
|
|
}
|
|
|
#else
|
|
|
-static bool usbd_get_descriptor(uint16_t type_index, uint8_t **data, uint32_t *len)
|
|
|
+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;
|
|
|
@@ -241,25 +241,25 @@ static bool usbd_get_descriptor(uint16_t type_index, uint8_t **data, uint32_t *l
|
|
|
if ((type == USB_DESCRIPTOR_TYPE_STRING) && (index == USB_OSDESC_STRING_DESC_INDEX)) {
|
|
|
USB_LOG_INFO("read MS OS 2.0 descriptor string\r\n");
|
|
|
|
|
|
- if (!g_usbd_core.msosv1_desc) {
|
|
|
+ if (!g_usbd_core[busid].msosv1_desc) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- //*data = (uint8_t *)g_usbd_core.msosv1_desc->string;
|
|
|
- memcpy(*data, (uint8_t *)g_usbd_core.msosv1_desc->string, g_usbd_core.msosv1_desc->string[0]);
|
|
|
- *len = g_usbd_core.msosv1_desc->string[0];
|
|
|
+ //*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) {
|
|
|
USB_LOG_INFO("read BOS descriptor string\r\n");
|
|
|
|
|
|
- if (!g_usbd_core.bos_desc) {
|
|
|
+ if (!g_usbd_core[busid].bos_desc) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- //*data = g_usbd_core.bos_desc->string;
|
|
|
- memcpy(*data, (uint8_t *)g_usbd_core.bos_desc->string, g_usbd_core.bos_desc->string_len);
|
|
|
- *len = g_usbd_core.bos_desc->string_len;
|
|
|
+ //*data = 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;
|
|
|
}
|
|
|
/*
|
|
|
@@ -275,7 +275,7 @@ static bool usbd_get_descriptor(uint16_t type_index, uint8_t **data, uint32_t *l
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- p = (uint8_t *)g_usbd_core.descriptors;
|
|
|
+ p = (uint8_t *)g_usbd_core[busid].descriptors;
|
|
|
|
|
|
cur_index = 0U;
|
|
|
|
|
|
@@ -326,7 +326,7 @@ static bool usbd_get_descriptor(uint16_t type_index, uint8_t **data, uint32_t *l
|
|
|
*
|
|
|
* @return true if successfully configured false if error or unconfigured
|
|
|
*/
|
|
|
-static bool usbd_set_configuration(uint8_t config_index, uint8_t alt_setting)
|
|
|
+static bool usbd_set_configuration(uint8_t busid, uint8_t config_index, uint8_t alt_setting)
|
|
|
{
|
|
|
uint8_t cur_alt_setting = 0xFF;
|
|
|
uint8_t cur_config = 0xFF;
|
|
|
@@ -336,9 +336,9 @@ static bool usbd_set_configuration(uint8_t config_index, uint8_t alt_setting)
|
|
|
uint32_t current_desc_len = 0;
|
|
|
|
|
|
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
|
|
- p = g_usbd_core.descriptors->config_descriptor_callback(g_usbd_core.speed);
|
|
|
+ p = g_usbd_core[busid].descriptors->config_descriptor_callback(g_usbd_core[busid].speed);
|
|
|
#else
|
|
|
- p = (uint8_t *)g_usbd_core.descriptors;
|
|
|
+ p = (uint8_t *)g_usbd_core[busid].descriptors;
|
|
|
#endif
|
|
|
/* configure endpoints for this configuration/altsetting */
|
|
|
while (p[DESC_bLength] != 0U) {
|
|
|
@@ -369,7 +369,7 @@ static bool usbd_set_configuration(uint8_t config_index, uint8_t alt_setting)
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- found = usbd_set_endpoint((struct usb_endpoint_descriptor *)p);
|
|
|
+ found = usbd_set_endpoint(busid, (struct usb_endpoint_descriptor *)p);
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
@@ -395,7 +395,7 @@ static bool usbd_set_configuration(uint8_t config_index, uint8_t alt_setting)
|
|
|
*
|
|
|
* @return true if successfully configured false if error or unconfigured
|
|
|
*/
|
|
|
-static bool usbd_set_interface(uint8_t iface, uint8_t alt_setting)
|
|
|
+static bool usbd_set_interface(uint8_t busid, uint8_t iface, uint8_t alt_setting)
|
|
|
{
|
|
|
const uint8_t *if_desc = NULL;
|
|
|
struct usb_endpoint_descriptor *ep_desc;
|
|
|
@@ -407,9 +407,9 @@ static bool usbd_set_interface(uint8_t iface, uint8_t alt_setting)
|
|
|
uint32_t current_desc_len = 0;
|
|
|
|
|
|
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
|
|
- p = g_usbd_core.descriptors->config_descriptor_callback(g_usbd_core.speed);
|
|
|
+ p = g_usbd_core[busid].descriptors->config_descriptor_callback(g_usbd_core[busid].speed);
|
|
|
#else
|
|
|
- p = (uint8_t *)g_usbd_core.descriptors;
|
|
|
+ p = (uint8_t *)g_usbd_core[busid].descriptors;
|
|
|
#endif
|
|
|
USB_LOG_DBG("iface %u alt_setting %u\r\n", iface, alt_setting);
|
|
|
|
|
|
@@ -441,9 +441,9 @@ static bool usbd_set_interface(uint8_t iface, uint8_t alt_setting)
|
|
|
ep_desc = (struct usb_endpoint_descriptor *)p;
|
|
|
|
|
|
if (cur_alt_setting != alt_setting) {
|
|
|
- ret = usbd_reset_endpoint(ep_desc);
|
|
|
+ ret = usbd_reset_endpoint(busid, ep_desc);
|
|
|
} else {
|
|
|
- ret = usbd_set_endpoint(ep_desc);
|
|
|
+ ret = usbd_set_endpoint(busid, ep_desc);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -461,7 +461,7 @@ static bool usbd_set_interface(uint8_t iface, uint8_t alt_setting)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- usbd_class_event_notify_handler(USBD_EVENT_SET_INTERFACE, (void *)if_desc);
|
|
|
+ usbd_class_event_notify_handler(busid, USBD_EVENT_SET_INTERFACE, (void *)if_desc);
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
|
@@ -475,7 +475,7 @@ static bool usbd_set_interface(uint8_t iface, uint8_t alt_setting)
|
|
|
*
|
|
|
* @return true if the request was handled successfully
|
|
|
*/
|
|
|
-static bool usbd_std_device_req_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
|
|
+static bool usbd_std_device_req_handler(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
|
|
{
|
|
|
uint16_t value = setup->wValue;
|
|
|
bool ret = true;
|
|
|
@@ -493,26 +493,26 @@ static bool usbd_std_device_req_handler(struct usb_setup_packet *setup, uint8_t
|
|
|
case USB_REQUEST_SET_FEATURE:
|
|
|
if (value == USB_FEATURE_REMOTE_WAKEUP) {
|
|
|
if (setup->bRequest == USB_REQUEST_SET_FEATURE) {
|
|
|
- usbd_event_handler(USBD_EVENT_SET_REMOTE_WAKEUP);
|
|
|
+ g_usbd_core[busid].event_handler(USBD_EVENT_SET_REMOTE_WAKEUP);
|
|
|
} else {
|
|
|
- usbd_event_handler(USBD_EVENT_CLR_REMOTE_WAKEUP);
|
|
|
+ g_usbd_core[busid].event_handler(USBD_EVENT_CLR_REMOTE_WAKEUP);
|
|
|
}
|
|
|
} else if (value == USB_FEATURE_TEST_MODE) {
|
|
|
#ifdef CONFIG_USBDEV_TEST_MODE
|
|
|
- g_usbd_core.test_mode = true;
|
|
|
- usbd_execute_test_mode(setup);
|
|
|
+ g_usbd_core[busid].test_mode = true;
|
|
|
+ usbd_execute_test_mode(busid, setup);
|
|
|
#endif
|
|
|
}
|
|
|
*len = 0;
|
|
|
break;
|
|
|
|
|
|
case USB_REQUEST_SET_ADDRESS:
|
|
|
- usbd_set_address(value);
|
|
|
+ usbd_set_address(busid, value);
|
|
|
*len = 0;
|
|
|
break;
|
|
|
|
|
|
case USB_REQUEST_GET_DESCRIPTOR:
|
|
|
- ret = usbd_get_descriptor(value, data, len);
|
|
|
+ ret = usbd_get_descriptor(busid, value, data, len);
|
|
|
break;
|
|
|
|
|
|
case USB_REQUEST_SET_DESCRIPTOR:
|
|
|
@@ -520,19 +520,19 @@ static bool usbd_std_device_req_handler(struct usb_setup_packet *setup, uint8_t
|
|
|
break;
|
|
|
|
|
|
case USB_REQUEST_GET_CONFIGURATION:
|
|
|
- *data = (uint8_t *)&g_usbd_core.configuration;
|
|
|
+ *data = (uint8_t *)&g_usbd_core[busid].configuration;
|
|
|
*len = 1;
|
|
|
break;
|
|
|
|
|
|
case USB_REQUEST_SET_CONFIGURATION:
|
|
|
value &= 0xFF;
|
|
|
|
|
|
- if (!usbd_set_configuration(value, 0)) {
|
|
|
+ if (!usbd_set_configuration(busid, value, 0)) {
|
|
|
ret = false;
|
|
|
} else {
|
|
|
- g_usbd_core.configuration = value;
|
|
|
- usbd_class_event_notify_handler(USBD_EVENT_CONFIGURED, NULL);
|
|
|
- usbd_event_handler(USBD_EVENT_CONFIGURED);
|
|
|
+ g_usbd_core[busid].configuration = value;
|
|
|
+ usbd_class_event_notify_handler(busid, USBD_EVENT_CONFIGURED, NULL);
|
|
|
+ g_usbd_core[busid].event_handler(USBD_EVENT_CONFIGURED);
|
|
|
}
|
|
|
*len = 0;
|
|
|
break;
|
|
|
@@ -559,15 +559,14 @@ static bool usbd_std_device_req_handler(struct usb_setup_packet *setup, uint8_t
|
|
|
*
|
|
|
* @return true if the request was handled successfully
|
|
|
*/
|
|
|
-static bool usbd_std_interface_req_handler(struct usb_setup_packet *setup,
|
|
|
- uint8_t **data, uint32_t *len)
|
|
|
+static bool usbd_std_interface_req_handler(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
|
|
{
|
|
|
uint8_t type = HI_BYTE(setup->wValue);
|
|
|
uint8_t intf_num = LO_BYTE(setup->wIndex);
|
|
|
bool ret = true;
|
|
|
|
|
|
/* Only when device is configured, then interface requests can be valid. */
|
|
|
- if (!is_device_configured()) {
|
|
|
+ if (!is_device_configured(busid)) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -582,8 +581,8 @@ static bool usbd_std_interface_req_handler(struct usb_setup_packet *setup,
|
|
|
if (type == 0x22) { /* HID_DESCRIPTOR_TYPE_HID_REPORT */
|
|
|
USB_LOG_INFO("read hid report descriptor\r\n");
|
|
|
|
|
|
- for (uint8_t i = 0; i < g_usbd_core.intf_offset; i++) {
|
|
|
- struct usbd_interface *intf = g_usbd_core.intf[i];
|
|
|
+ for (uint8_t i = 0; i < g_usbd_core[busid].intf_offset; i++) {
|
|
|
+ struct usbd_interface *intf = g_usbd_core[busid].intf[i];
|
|
|
|
|
|
if (intf && (intf->intf_num == intf_num)) {
|
|
|
//*data = (uint8_t *)intf->hid_report_descriptor;
|
|
|
@@ -605,7 +604,7 @@ static bool usbd_std_interface_req_handler(struct usb_setup_packet *setup,
|
|
|
break;
|
|
|
|
|
|
case USB_REQUEST_SET_INTERFACE:
|
|
|
- usbd_set_interface(setup->wIndex, setup->wValue);
|
|
|
+ usbd_set_interface(busid, setup->wIndex, setup->wValue);
|
|
|
*len = 0;
|
|
|
break;
|
|
|
|
|
|
@@ -626,13 +625,13 @@ static bool usbd_std_interface_req_handler(struct usb_setup_packet *setup,
|
|
|
*
|
|
|
* @return true if the request was handled successfully
|
|
|
*/
|
|
|
-static bool usbd_std_endpoint_req_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
|
|
+static bool usbd_std_endpoint_req_handler(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
|
|
{
|
|
|
uint8_t ep = (uint8_t)setup->wIndex;
|
|
|
bool ret = true;
|
|
|
|
|
|
/* Only when device is configured, then endpoint requests can be valid. */
|
|
|
- if (!is_device_configured()) {
|
|
|
+ if (!is_device_configured(busid)) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -646,7 +645,7 @@ static bool usbd_std_endpoint_req_handler(struct usb_setup_packet *setup, uint8_
|
|
|
if (setup->wValue == USB_FEATURE_ENDPOINT_HALT) {
|
|
|
USB_LOG_ERR("ep:%02x clear halt\r\n", ep);
|
|
|
|
|
|
- usbd_ep_clear_stall(ep);
|
|
|
+ usbd_ep_clear_stall(busid, ep);
|
|
|
break;
|
|
|
} else {
|
|
|
ret = false;
|
|
|
@@ -657,7 +656,7 @@ static bool usbd_std_endpoint_req_handler(struct usb_setup_packet *setup, uint8_
|
|
|
if (setup->wValue == USB_FEATURE_ENDPOINT_HALT) {
|
|
|
USB_LOG_ERR("ep:%02x set halt\r\n", ep);
|
|
|
|
|
|
- usbd_ep_set_stall(ep);
|
|
|
+ usbd_ep_set_stall(busid, ep);
|
|
|
} else {
|
|
|
ret = false;
|
|
|
}
|
|
|
@@ -684,27 +683,27 @@ static bool usbd_std_endpoint_req_handler(struct usb_setup_packet *setup, uint8_
|
|
|
*
|
|
|
* @return true if the request was handled successfully
|
|
|
*/
|
|
|
-static int usbd_standard_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
|
|
+static int usbd_standard_request_handler(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
|
|
{
|
|
|
int rc = 0;
|
|
|
|
|
|
switch (setup->bmRequestType & USB_REQUEST_RECIPIENT_MASK) {
|
|
|
case USB_REQUEST_RECIPIENT_DEVICE:
|
|
|
- if (usbd_std_device_req_handler(setup, data, len) == false) {
|
|
|
+ if (usbd_std_device_req_handler(busid, setup, data, len) == false) {
|
|
|
rc = -1;
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case USB_REQUEST_RECIPIENT_INTERFACE:
|
|
|
- if (usbd_std_interface_req_handler(setup, data, len) == false) {
|
|
|
+ if (usbd_std_interface_req_handler(busid, setup, data, len) == false) {
|
|
|
rc = -1;
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case USB_REQUEST_RECIPIENT_ENDPOINT:
|
|
|
- if (usbd_std_endpoint_req_handler(setup, data, len) == false) {
|
|
|
+ if (usbd_std_endpoint_req_handler(busid, setup, data, len) == false) {
|
|
|
rc = -1;
|
|
|
}
|
|
|
|
|
|
@@ -729,22 +728,22 @@ static int usbd_standard_request_handler(struct usb_setup_packet *setup, uint8_t
|
|
|
*
|
|
|
* @return true if the request was handled successfully
|
|
|
*/
|
|
|
-static int usbd_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
|
|
+static int usbd_class_request_handler(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
|
|
{
|
|
|
if ((setup->bmRequestType & USB_REQUEST_RECIPIENT_MASK) == USB_REQUEST_RECIPIENT_INTERFACE) {
|
|
|
- for (uint8_t i = 0; i < g_usbd_core.intf_offset; i++) {
|
|
|
- struct usbd_interface *intf = g_usbd_core.intf[i];
|
|
|
+ for (uint8_t i = 0; i < g_usbd_core[busid].intf_offset; i++) {
|
|
|
+ struct usbd_interface *intf = g_usbd_core[busid].intf[i];
|
|
|
|
|
|
if (intf && intf->class_interface_handler && (intf->intf_num == (setup->wIndex & 0xFF))) {
|
|
|
- return intf->class_interface_handler(setup, data, len);
|
|
|
+ return intf->class_interface_handler(busid, setup, data, len);
|
|
|
}
|
|
|
}
|
|
|
} else if ((setup->bmRequestType & USB_REQUEST_RECIPIENT_MASK) == USB_REQUEST_RECIPIENT_ENDPOINT) {
|
|
|
- for (uint8_t i = 0; i < g_usbd_core.intf_offset; i++) {
|
|
|
- struct usbd_interface *intf = g_usbd_core.intf[i];
|
|
|
+ for (uint8_t i = 0; i < g_usbd_core[busid].intf_offset; i++) {
|
|
|
+ struct usbd_interface *intf = g_usbd_core[busid].intf[i];
|
|
|
|
|
|
if (intf && intf->class_endpoint_handler) {
|
|
|
- return intf->class_endpoint_handler(setup, data, len);
|
|
|
+ return intf->class_endpoint_handler(busid, setup, data, len);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -762,33 +761,33 @@ static int usbd_class_request_handler(struct usb_setup_packet *setup, uint8_t **
|
|
|
*
|
|
|
* @return true if the request was handled successfully
|
|
|
*/
|
|
|
-static int usbd_vendor_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
|
|
+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.descriptors->msosv1_descriptor) {
|
|
|
- if (setup->bRequest == g_usbd_core.descriptors->msosv1_descriptor->vendor_code) {
|
|
|
+ if (g_usbd_core[busid].descriptors->msosv1_descriptor) {
|
|
|
+ if (setup->bRequest == g_usbd_core[busid].descriptors->msosv1_descriptor->vendor_code) {
|
|
|
switch (setup->wIndex) {
|
|
|
case 0x04:
|
|
|
USB_LOG_INFO("get Compat ID\r\n");
|
|
|
- desclen = g_usbd_core.descriptors->msosv1_descriptor->compat_id[0] +
|
|
|
- (g_usbd_core.descriptors->msosv1_descriptor->compat_id[1] << 8) +
|
|
|
- (g_usbd_core.descriptors->msosv1_descriptor->compat_id[2] << 16) +
|
|
|
- (g_usbd_core.descriptors->msosv1_descriptor->compat_id[3] << 24);
|
|
|
+ desclen = g_usbd_core[busid].descriptors->msosv1_descriptor->compat_id[0] +
|
|
|
+ (g_usbd_core[busid].descriptors->msosv1_descriptor->compat_id[1] << 8) +
|
|
|
+ (g_usbd_core[busid].descriptors->msosv1_descriptor->compat_id[2] << 16) +
|
|
|
+ (g_usbd_core[busid].descriptors->msosv1_descriptor->compat_id[3] << 24);
|
|
|
|
|
|
- //*data = (uint8_t *)g_usbd_core.descriptors->msosv1_descriptor->compat_id;
|
|
|
- memcpy(*data, g_usbd_core.descriptors->msosv1_descriptor->compat_id, desclen);
|
|
|
+ //*data = (uint8_t *)g_usbd_core[busid].descriptors->msosv1_descriptor->compat_id;
|
|
|
+ memcpy(*data, g_usbd_core[busid].descriptors->msosv1_descriptor->compat_id, desclen);
|
|
|
*len = desclen;
|
|
|
return 0;
|
|
|
case 0x05:
|
|
|
USB_LOG_INFO("get Compat id properties\r\n");
|
|
|
- desclen = g_usbd_core.descriptors->msosv1_descriptor->comp_id_property[setup->wValue][0] +
|
|
|
- (g_usbd_core.descriptors->msosv1_descriptor->comp_id_property[setup->wValue][1] << 8) +
|
|
|
- (g_usbd_core.descriptors->msosv1_descriptor->comp_id_property[setup->wValue][2] << 16) +
|
|
|
- (g_usbd_core.descriptors->msosv1_descriptor->comp_id_property[setup->wValue][3] << 24);
|
|
|
+ desclen = g_usbd_core[busid].descriptors->msosv1_descriptor->comp_id_property[setup->wValue][0] +
|
|
|
+ (g_usbd_core[busid].descriptors->msosv1_descriptor->comp_id_property[setup->wValue][1] << 8) +
|
|
|
+ (g_usbd_core[busid].descriptors->msosv1_descriptor->comp_id_property[setup->wValue][2] << 16) +
|
|
|
+ (g_usbd_core[busid].descriptors->msosv1_descriptor->comp_id_property[setup->wValue][3] << 24);
|
|
|
|
|
|
- //*data = (uint8_t *)g_usbd_core.descriptors->msosv1_descriptor->comp_id_property[setup->wValue];
|
|
|
- memcpy(*data, g_usbd_core.descriptors->msosv1_descriptor->comp_id_property[setup->wValue], desclen);
|
|
|
+ //*data = (uint8_t *)g_usbd_core[busid].descriptors->msosv1_descriptor->comp_id_property[setup->wValue];
|
|
|
+ memcpy(*data, g_usbd_core[busid].descriptors->msosv1_descriptor->comp_id_property[setup->wValue], desclen);
|
|
|
*len = desclen;
|
|
|
return 0;
|
|
|
default:
|
|
|
@@ -796,31 +795,31 @@ static int usbd_vendor_request_handler(struct usb_setup_packet *setup, uint8_t *
|
|
|
return -1;
|
|
|
}
|
|
|
}
|
|
|
- } else if (g_usbd_core.descriptors->msosv2_descriptor) {
|
|
|
- if (setup->bRequest == g_usbd_core.descriptors->msosv2_descriptor->vendor_code) {
|
|
|
+ } else if (g_usbd_core[busid].descriptors->msosv2_descriptor) {
|
|
|
+ if (setup->bRequest == g_usbd_core[busid].descriptors->msosv2_descriptor->vendor_code) {
|
|
|
switch (setup->wIndex) {
|
|
|
case WINUSB_REQUEST_GET_DESCRIPTOR_SET:
|
|
|
USB_LOG_INFO("GET MS OS 2.0 Descriptor\r\n");
|
|
|
|
|
|
- desclen = g_usbd_core.descriptors->msosv2_descriptor->compat_id_len;
|
|
|
- //*data = (uint8_t *)g_usbd_core.descriptors->msosv2_descriptor->compat_id;
|
|
|
- memcpy(*data, g_usbd_core.descriptors->msosv2_descriptor->compat_id, desclen);
|
|
|
- *len = g_usbd_core.descriptors->msosv2_descriptor->compat_id_len;
|
|
|
+ desclen = g_usbd_core[busid].descriptors->msosv2_descriptor->compat_id_len;
|
|
|
+ //*data = (uint8_t *)g_usbd_core[busid].descriptors->msosv2_descriptor->compat_id;
|
|
|
+ memcpy(*data, g_usbd_core[busid].descriptors->msosv2_descriptor->compat_id, desclen);
|
|
|
+ *len = g_usbd_core[busid].descriptors->msosv2_descriptor->compat_id_len;
|
|
|
return 0;
|
|
|
default:
|
|
|
USB_LOG_ERR("unknown vendor code\r\n");
|
|
|
return -1;
|
|
|
}
|
|
|
}
|
|
|
- } else if (g_usbd_core.descriptors->webusb_url_descriptor) {
|
|
|
- if (setup->bRequest == g_usbd_core.descriptors->webusb_url_descriptor->vendor_code) {
|
|
|
+ } else if (g_usbd_core[busid].descriptors->webusb_url_descriptor) {
|
|
|
+ if (setup->bRequest == g_usbd_core[busid].descriptors->webusb_url_descriptor->vendor_code) {
|
|
|
switch (setup->wIndex) {
|
|
|
case WINUSB_REQUEST_GET_DESCRIPTOR_SET:
|
|
|
USB_LOG_INFO("GET Webusb url Descriptor\r\n");
|
|
|
|
|
|
- desclen = g_usbd_core.descriptors->webusb_url_descriptor->string_len;
|
|
|
- //*data = (uint8_t *)g_usbd_core.descriptors->webusb_url_descriptor->string;
|
|
|
- memcpy(*data, g_usbd_core.descriptors->webusb_url_descriptor->string, desclen);
|
|
|
+ desclen = g_usbd_core[busid].descriptors->webusb_url_descriptor->string_len;
|
|
|
+ //*data = (uint8_t *)g_usbd_core[busid].descriptors->webusb_url_descriptor->string;
|
|
|
+ memcpy(*data, g_usbd_core[busid].descriptors->webusb_url_descriptor->string, desclen);
|
|
|
*len = desclen;
|
|
|
return 0;
|
|
|
default:
|
|
|
@@ -830,27 +829,27 @@ static int usbd_vendor_request_handler(struct usb_setup_packet *setup, uint8_t *
|
|
|
}
|
|
|
}
|
|
|
#else
|
|
|
- if (g_usbd_core.msosv1_desc) {
|
|
|
- if (setup->bRequest == g_usbd_core.msosv1_desc->vendor_code) {
|
|
|
+ if (g_usbd_core[busid].msosv1_desc) {
|
|
|
+ if (setup->bRequest == g_usbd_core[busid].msosv1_desc->vendor_code) {
|
|
|
switch (setup->wIndex) {
|
|
|
case 0x04:
|
|
|
USB_LOG_INFO("get Compat ID\r\n");
|
|
|
//*data = (uint8_t *)msosv1_desc->compat_id;
|
|
|
- desclen = g_usbd_core.msosv1_desc->compat_id[0] +
|
|
|
- (g_usbd_core.msosv1_desc->compat_id[1] << 8) +
|
|
|
- (g_usbd_core.msosv1_desc->compat_id[2] << 16) +
|
|
|
- (g_usbd_core.msosv1_desc->compat_id[3] << 24);
|
|
|
- memcpy(*data, g_usbd_core.msosv1_desc->compat_id, desclen);
|
|
|
+ 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:
|
|
|
USB_LOG_INFO("get Compat id properties\r\n");
|
|
|
//*data = (uint8_t *)msosv1_desc->comp_id_property[setup->wValue];
|
|
|
- desclen = g_usbd_core.msosv1_desc->comp_id_property[setup->wValue][0] +
|
|
|
- (g_usbd_core.msosv1_desc->comp_id_property[setup->wValue][1] << 8) +
|
|
|
- (g_usbd_core.msosv1_desc->comp_id_property[setup->wValue][2] << 16) +
|
|
|
- (g_usbd_core.msosv1_desc->comp_id_property[setup->wValue][3] << 24);
|
|
|
- memcpy(*data, g_usbd_core.msosv1_desc->comp_id_property[setup->wValue], desclen);
|
|
|
+ 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:
|
|
|
@@ -858,14 +857,14 @@ static int usbd_vendor_request_handler(struct usb_setup_packet *setup, uint8_t *
|
|
|
return -1;
|
|
|
}
|
|
|
}
|
|
|
- } else if (g_usbd_core.msosv2_desc) {
|
|
|
- if (setup->bRequest == g_usbd_core.msosv2_desc->vendor_code) {
|
|
|
+ } 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:
|
|
|
USB_LOG_INFO("GET MS OS 2.0 Descriptor\r\n");
|
|
|
//*data = (uint8_t *)msosv2_desc->compat_id;
|
|
|
- memcpy(*data, g_usbd_core.msosv2_desc->compat_id, g_usbd_core.msosv2_desc->compat_id_len);
|
|
|
- *len = g_usbd_core.msosv2_desc->compat_id_len;
|
|
|
+ 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:
|
|
|
USB_LOG_ERR("unknown vendor code\r\n");
|
|
|
@@ -874,10 +873,10 @@ static int usbd_vendor_request_handler(struct usb_setup_packet *setup, uint8_t *
|
|
|
}
|
|
|
}
|
|
|
#endif
|
|
|
- for (uint8_t i = 0; i < g_usbd_core.intf_offset; i++) {
|
|
|
- struct usbd_interface *intf = g_usbd_core.intf[i];
|
|
|
+ for (uint8_t i = 0; i < g_usbd_core[busid].intf_offset; i++) {
|
|
|
+ struct usbd_interface *intf = g_usbd_core[busid].intf[i];
|
|
|
|
|
|
- if (intf && intf->vendor_handler && (intf->vendor_handler(setup, data, len) == 0)) {
|
|
|
+ if (intf && intf->vendor_handler && (intf->vendor_handler(busid, setup, data, len) == 0)) {
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
@@ -894,32 +893,32 @@ static int usbd_vendor_request_handler(struct usb_setup_packet *setup, uint8_t *
|
|
|
*
|
|
|
* @return true if the request was handles successfully
|
|
|
*/
|
|
|
-static bool usbd_setup_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
|
|
+static bool usbd_setup_request_handler(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
|
|
{
|
|
|
switch (setup->bmRequestType & USB_REQUEST_TYPE_MASK) {
|
|
|
case USB_REQUEST_STANDARD:
|
|
|
#ifndef CONFIG_USB_HS
|
|
|
- //g_usbd_core.speed = USB_SPEED_FULL; /* next time will support getting device speed */
|
|
|
- if ((setup->bRequest == 0x06) && (setup->wValue == 0x0600) && (g_usbd_core.speed <= USB_SPEED_FULL)) {
|
|
|
+ //g_usbd_core[busid].speed = USB_SPEED_FULL; /* next time will support getting device speed */
|
|
|
+ if ((setup->bRequest == 0x06) && (setup->wValue == 0x0600) && (g_usbd_core[busid].speed <= USB_SPEED_FULL)) {
|
|
|
USB_LOG_WRN("Ignore DQD in fs\r\n"); /* Device Qualifier Descriptor */
|
|
|
return false;
|
|
|
}
|
|
|
#endif
|
|
|
- if (usbd_standard_request_handler(setup, data, len) < 0) {
|
|
|
+ if (usbd_standard_request_handler(busid, setup, data, len) < 0) {
|
|
|
USB_LOG_ERR("standard request error\r\n");
|
|
|
usbd_print_setup(setup);
|
|
|
return false;
|
|
|
}
|
|
|
break;
|
|
|
case USB_REQUEST_CLASS:
|
|
|
- if (usbd_class_request_handler(setup, data, len) < 0) {
|
|
|
+ if (usbd_class_request_handler(busid, setup, data, len) < 0) {
|
|
|
USB_LOG_ERR("class request error\r\n");
|
|
|
usbd_print_setup(setup);
|
|
|
return false;
|
|
|
}
|
|
|
break;
|
|
|
case USB_REQUEST_VENDOR:
|
|
|
- if (usbd_vendor_request_handler(setup, data, len) < 0) {
|
|
|
+ if (usbd_vendor_request_handler(busid, setup, data, len) < 0) {
|
|
|
USB_LOG_ERR("vendor request error\r\n");
|
|
|
usbd_print_setup(setup);
|
|
|
return false;
|
|
|
@@ -933,51 +932,51 @@ static bool usbd_setup_request_handler(struct usb_setup_packet *setup, uint8_t *
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-static void usbd_class_event_notify_handler(uint8_t event, void *arg)
|
|
|
+static void usbd_class_event_notify_handler(uint8_t busid, uint8_t event, void *arg)
|
|
|
{
|
|
|
- for (uint8_t i = 0; i < g_usbd_core.intf_offset; i++) {
|
|
|
- struct usbd_interface *intf = g_usbd_core.intf[i];
|
|
|
+ for (uint8_t i = 0; i < g_usbd_core[busid].intf_offset; i++) {
|
|
|
+ struct usbd_interface *intf = g_usbd_core[busid].intf[i];
|
|
|
|
|
|
if (arg) {
|
|
|
struct usb_interface_descriptor *desc = (struct usb_interface_descriptor *)arg;
|
|
|
if (intf && intf->notify_handler && (desc->bInterfaceNumber == (intf->intf_num))) {
|
|
|
- intf->notify_handler(event, arg);
|
|
|
+ intf->notify_handler(busid, event, arg);
|
|
|
}
|
|
|
} else {
|
|
|
if (intf && intf->notify_handler) {
|
|
|
- intf->notify_handler(event, arg);
|
|
|
+ intf->notify_handler(busid, event, arg);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void usbd_event_connect_handler(void)
|
|
|
+void usbd_event_connect_handler(uint8_t busid)
|
|
|
{
|
|
|
- usbd_event_handler(USBD_EVENT_CONNECTED);
|
|
|
+ g_usbd_core[busid].event_handler(USBD_EVENT_CONNECTED);
|
|
|
}
|
|
|
|
|
|
-void usbd_event_disconnect_handler(void)
|
|
|
+void usbd_event_disconnect_handler(uint8_t busid)
|
|
|
{
|
|
|
- usbd_event_handler(USBD_EVENT_DISCONNECTED);
|
|
|
+ g_usbd_core[busid].event_handler(USBD_EVENT_DISCONNECTED);
|
|
|
}
|
|
|
|
|
|
-void usbd_event_resume_handler(void)
|
|
|
+void usbd_event_resume_handler(uint8_t busid)
|
|
|
{
|
|
|
- usbd_event_handler(USBD_EVENT_RESUME);
|
|
|
+ g_usbd_core[busid].event_handler(USBD_EVENT_RESUME);
|
|
|
}
|
|
|
|
|
|
-void usbd_event_suspend_handler(void)
|
|
|
+void usbd_event_suspend_handler(uint8_t busid)
|
|
|
{
|
|
|
- usbd_event_handler(USBD_EVENT_SUSPEND);
|
|
|
+ g_usbd_core[busid].event_handler(USBD_EVENT_SUSPEND);
|
|
|
}
|
|
|
|
|
|
-void usbd_event_reset_handler(void)
|
|
|
+void usbd_event_reset_handler(uint8_t busid)
|
|
|
{
|
|
|
- usbd_set_address(0);
|
|
|
- g_usbd_core.configuration = 0;
|
|
|
+ usbd_set_address(busid, 0);
|
|
|
+ g_usbd_core[busid].configuration = 0;
|
|
|
|
|
|
#ifdef CONFIG_USBDEV_TEST_MODE
|
|
|
- g_usbd_core.test_mode = false;
|
|
|
+ g_usbd_core[busid].test_mode = false;
|
|
|
#endif
|
|
|
struct usb_endpoint_descriptor ep0;
|
|
|
|
|
|
@@ -987,18 +986,18 @@ void usbd_event_reset_handler(void)
|
|
|
ep0.bmAttributes = USB_ENDPOINT_TYPE_CONTROL;
|
|
|
ep0.bEndpointAddress = USB_CONTROL_IN_EP0;
|
|
|
ep0.bInterval = 0;
|
|
|
- usbd_ep_open(&ep0);
|
|
|
+ usbd_ep_open(busid, &ep0);
|
|
|
|
|
|
ep0.bEndpointAddress = USB_CONTROL_OUT_EP0;
|
|
|
- usbd_ep_open(&ep0);
|
|
|
+ usbd_ep_open(busid, &ep0);
|
|
|
|
|
|
- usbd_class_event_notify_handler(USBD_EVENT_RESET, NULL);
|
|
|
- usbd_event_handler(USBD_EVENT_RESET);
|
|
|
+ usbd_class_event_notify_handler(busid, USBD_EVENT_RESET, NULL);
|
|
|
+ g_usbd_core[busid].event_handler(USBD_EVENT_RESET);
|
|
|
}
|
|
|
|
|
|
-void usbd_event_ep0_setup_complete_handler(uint8_t *psetup)
|
|
|
+void usbd_event_ep0_setup_complete_handler(uint8_t busid, uint8_t *psetup)
|
|
|
{
|
|
|
- struct usb_setup_packet *setup = &g_usbd_core.setup;
|
|
|
+ struct usb_setup_packet *setup = &g_usbd_core[busid].setup;
|
|
|
|
|
|
memcpy(setup, psetup, 8);
|
|
|
#ifdef CONFIG_USBDEV_SETUP_LOG_PRINT
|
|
|
@@ -1007,73 +1006,73 @@ void usbd_event_ep0_setup_complete_handler(uint8_t *psetup)
|
|
|
if (setup->wLength > CONFIG_USBDEV_REQUEST_BUFFER_LEN) {
|
|
|
if ((setup->bmRequestType & USB_REQUEST_DIR_MASK) == USB_REQUEST_DIR_OUT) {
|
|
|
USB_LOG_ERR("Request buffer too small\r\n");
|
|
|
- usbd_ep_set_stall(USB_CONTROL_IN_EP0);
|
|
|
+ usbd_ep_set_stall(busid, USB_CONTROL_IN_EP0);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- g_usbd_core.ep0_data_buf = g_usbd_core.req_data;
|
|
|
- g_usbd_core.ep0_data_buf_residue = setup->wLength;
|
|
|
- g_usbd_core.ep0_data_buf_len = setup->wLength;
|
|
|
- g_usbd_core.zlp_flag = false;
|
|
|
+ g_usbd_core[busid].ep0_data_buf = g_usbd_core[busid].req_data;
|
|
|
+ g_usbd_core[busid].ep0_data_buf_residue = setup->wLength;
|
|
|
+ g_usbd_core[busid].ep0_data_buf_len = setup->wLength;
|
|
|
+ g_usbd_core[busid].zlp_flag = false;
|
|
|
|
|
|
/* handle class request when all the data is received */
|
|
|
if (setup->wLength && ((setup->bmRequestType & USB_REQUEST_DIR_MASK) == USB_REQUEST_DIR_OUT)) {
|
|
|
USB_LOG_DBG("Start reading %d bytes from ep0\r\n", setup->wLength);
|
|
|
- usbd_ep_start_read(USB_CONTROL_OUT_EP0, g_usbd_core.ep0_data_buf, setup->wLength);
|
|
|
+ usbd_ep_start_read(busid, USB_CONTROL_OUT_EP0, g_usbd_core[busid].ep0_data_buf, setup->wLength);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
/* Ask installed handler to process request */
|
|
|
- if (!usbd_setup_request_handler(setup, &g_usbd_core.ep0_data_buf, &g_usbd_core.ep0_data_buf_len)) {
|
|
|
- usbd_ep_set_stall(USB_CONTROL_IN_EP0);
|
|
|
+ if (!usbd_setup_request_handler(busid, setup, &g_usbd_core[busid].ep0_data_buf, &g_usbd_core[busid].ep0_data_buf_len)) {
|
|
|
+ usbd_ep_set_stall(busid, USB_CONTROL_IN_EP0);
|
|
|
return;
|
|
|
}
|
|
|
#ifdef CONFIG_USBDEV_TEST_MODE
|
|
|
/* send status in test mode, so do not execute downward, just return */
|
|
|
- if (g_usbd_core.test_mode) {
|
|
|
- g_usbd_core.test_mode = false;
|
|
|
+ if (g_usbd_core[busid].test_mode) {
|
|
|
+ g_usbd_core[busid].test_mode = false;
|
|
|
return;
|
|
|
}
|
|
|
#endif
|
|
|
/* Send smallest of requested and offered length */
|
|
|
- g_usbd_core.ep0_data_buf_residue = MIN(g_usbd_core.ep0_data_buf_len, setup->wLength);
|
|
|
- if (g_usbd_core.ep0_data_buf_residue > CONFIG_USBDEV_REQUEST_BUFFER_LEN) {
|
|
|
+ g_usbd_core[busid].ep0_data_buf_residue = MIN(g_usbd_core[busid].ep0_data_buf_len, setup->wLength);
|
|
|
+ if (g_usbd_core[busid].ep0_data_buf_residue > CONFIG_USBDEV_REQUEST_BUFFER_LEN) {
|
|
|
USB_LOG_ERR("Request buffer too small\r\n");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
/* Send data or status to host */
|
|
|
- usbd_ep_start_write(USB_CONTROL_IN_EP0, g_usbd_core.ep0_data_buf, g_usbd_core.ep0_data_buf_residue);
|
|
|
+ usbd_ep_start_write(busid, USB_CONTROL_IN_EP0, g_usbd_core[busid].ep0_data_buf, g_usbd_core[busid].ep0_data_buf_residue);
|
|
|
/*
|
|
|
* Set ZLP flag when host asks for a bigger length and the data size is
|
|
|
* multiplier of USB_CTRL_EP_MPS, to indicate the transfer done after zlp
|
|
|
* sent.
|
|
|
*/
|
|
|
- if ((setup->wLength > g_usbd_core.ep0_data_buf_len) && (!(g_usbd_core.ep0_data_buf_len % USB_CTRL_EP_MPS))) {
|
|
|
- g_usbd_core.zlp_flag = true;
|
|
|
+ if ((setup->wLength > g_usbd_core[busid].ep0_data_buf_len) && (!(g_usbd_core[busid].ep0_data_buf_len % USB_CTRL_EP_MPS))) {
|
|
|
+ g_usbd_core[busid].zlp_flag = true;
|
|
|
USB_LOG_DBG("EP0 Set zlp\r\n");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void usbd_event_ep0_in_complete_handler(uint8_t ep, uint32_t nbytes)
|
|
|
+void usbd_event_ep0_in_complete_handler(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
|
|
{
|
|
|
- struct usb_setup_packet *setup = &g_usbd_core.setup;
|
|
|
+ struct usb_setup_packet *setup = &g_usbd_core[busid].setup;
|
|
|
|
|
|
- g_usbd_core.ep0_data_buf += nbytes;
|
|
|
- g_usbd_core.ep0_data_buf_residue -= nbytes;
|
|
|
+ g_usbd_core[busid].ep0_data_buf += nbytes;
|
|
|
+ g_usbd_core[busid].ep0_data_buf_residue -= nbytes;
|
|
|
|
|
|
- USB_LOG_DBG("EP0 send %d bytes, %d remained\r\n", nbytes, g_usbd_core.ep0_data_buf_residue);
|
|
|
+ USB_LOG_DBG("EP0 send %d bytes, %d remained\r\n", nbytes, g_usbd_core[busid].ep0_data_buf_residue);
|
|
|
|
|
|
- if (g_usbd_core.ep0_data_buf_residue != 0) {
|
|
|
+ if (g_usbd_core[busid].ep0_data_buf_residue != 0) {
|
|
|
/* Start sending the remain data */
|
|
|
- usbd_ep_start_write(USB_CONTROL_IN_EP0, g_usbd_core.ep0_data_buf, g_usbd_core.ep0_data_buf_residue);
|
|
|
+ usbd_ep_start_write(busid, USB_CONTROL_IN_EP0, g_usbd_core[busid].ep0_data_buf, g_usbd_core[busid].ep0_data_buf_residue);
|
|
|
} else {
|
|
|
- if (g_usbd_core.zlp_flag == true) {
|
|
|
- g_usbd_core.zlp_flag = false;
|
|
|
+ if (g_usbd_core[busid].zlp_flag == true) {
|
|
|
+ g_usbd_core[busid].zlp_flag = false;
|
|
|
/* Send zlp to host */
|
|
|
USB_LOG_DBG("EP0 Send zlp\r\n");
|
|
|
- usbd_ep_start_write(USB_CONTROL_IN_EP0, NULL, 0);
|
|
|
+ usbd_ep_start_write(busid, USB_CONTROL_IN_EP0, NULL, 0);
|
|
|
} else {
|
|
|
/* Satisfying three conditions will jump here.
|
|
|
* 1. send status completely
|
|
|
@@ -1082,35 +1081,35 @@ void usbd_event_ep0_in_complete_handler(uint8_t ep, uint32_t nbytes)
|
|
|
*/
|
|
|
if (setup->wLength && ((setup->bmRequestType & USB_REQUEST_DIR_MASK) == USB_REQUEST_DIR_IN)) {
|
|
|
/* if all data has sent completely, start reading out status */
|
|
|
- usbd_ep_start_read(USB_CONTROL_OUT_EP0, NULL, 0);
|
|
|
+ usbd_ep_start_read(busid, USB_CONTROL_OUT_EP0, NULL, 0);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void usbd_event_ep0_out_complete_handler(uint8_t ep, uint32_t nbytes)
|
|
|
+void usbd_event_ep0_out_complete_handler(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
|
|
{
|
|
|
- struct usb_setup_packet *setup = &g_usbd_core.setup;
|
|
|
+ struct usb_setup_packet *setup = &g_usbd_core[busid].setup;
|
|
|
|
|
|
if (nbytes > 0) {
|
|
|
- g_usbd_core.ep0_data_buf += nbytes;
|
|
|
- g_usbd_core.ep0_data_buf_residue -= nbytes;
|
|
|
+ g_usbd_core[busid].ep0_data_buf += nbytes;
|
|
|
+ g_usbd_core[busid].ep0_data_buf_residue -= nbytes;
|
|
|
|
|
|
- USB_LOG_DBG("EP0 recv %d bytes, %d remained\r\n", nbytes, g_usbd_core.ep0_data_buf_residue);
|
|
|
+ USB_LOG_DBG("EP0 recv %d bytes, %d remained\r\n", nbytes, g_usbd_core[busid].ep0_data_buf_residue);
|
|
|
|
|
|
- if (g_usbd_core.ep0_data_buf_residue == 0) {
|
|
|
+ if (g_usbd_core[busid].ep0_data_buf_residue == 0) {
|
|
|
/* Received all, send data to handler */
|
|
|
- g_usbd_core.ep0_data_buf = g_usbd_core.req_data;
|
|
|
- if (!usbd_setup_request_handler(setup, &g_usbd_core.ep0_data_buf, &g_usbd_core.ep0_data_buf_len)) {
|
|
|
- usbd_ep_set_stall(USB_CONTROL_IN_EP0);
|
|
|
+ g_usbd_core[busid].ep0_data_buf = g_usbd_core[busid].req_data;
|
|
|
+ if (!usbd_setup_request_handler(busid, setup, &g_usbd_core[busid].ep0_data_buf, &g_usbd_core[busid].ep0_data_buf_len)) {
|
|
|
+ usbd_ep_set_stall(busid, USB_CONTROL_IN_EP0);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
/*Send status to host*/
|
|
|
- usbd_ep_start_write(USB_CONTROL_IN_EP0, NULL, 0);
|
|
|
+ usbd_ep_start_write(busid, USB_CONTROL_IN_EP0, NULL, 0);
|
|
|
} else {
|
|
|
/* Start reading the remain data */
|
|
|
- usbd_ep_start_read(USB_CONTROL_OUT_EP0, g_usbd_core.ep0_data_buf, g_usbd_core.ep0_data_buf_residue);
|
|
|
+ usbd_ep_start_read(busid, USB_CONTROL_OUT_EP0, g_usbd_core[busid].ep0_data_buf, g_usbd_core[busid].ep0_data_buf_residue);
|
|
|
}
|
|
|
} else {
|
|
|
/* Read out status completely, do nothing */
|
|
|
@@ -1118,130 +1117,104 @@ void usbd_event_ep0_out_complete_handler(uint8_t ep, uint32_t nbytes)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void usbd_event_ep_in_complete_handler(uint8_t ep, uint32_t nbytes)
|
|
|
+void usbd_event_ep_in_complete_handler(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
|
|
{
|
|
|
- if (g_usbd_core.tx_msg[ep & 0x7f].cb) {
|
|
|
- g_usbd_core.tx_msg[ep & 0x7f].cb(ep, nbytes);
|
|
|
+ if (g_usbd_core[busid].tx_msg[ep & 0x7f].cb) {
|
|
|
+ g_usbd_core[busid].tx_msg[ep & 0x7f].cb(busid, ep, nbytes);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void usbd_event_ep_out_complete_handler(uint8_t ep, uint32_t nbytes)
|
|
|
+void usbd_event_ep_out_complete_handler(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
|
|
{
|
|
|
- if (g_usbd_core.rx_msg[ep & 0x7f].cb) {
|
|
|
- g_usbd_core.rx_msg[ep & 0x7f].cb(ep, nbytes);
|
|
|
+ if (g_usbd_core[busid].rx_msg[ep & 0x7f].cb) {
|
|
|
+ g_usbd_core[busid].rx_msg[ep & 0x7f].cb(busid, ep, nbytes);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
|
|
-void usbd_desc_register(const struct usb_descriptor *desc)
|
|
|
+void usbd_desc_register(uint8_t busid, const struct usb_descriptor *desc)
|
|
|
{
|
|
|
- memset(&g_usbd_core, 0, sizeof(struct usbd_core_priv));
|
|
|
+ memset(&g_usbd_core[busid], 0, sizeof(struct usbd_core_priv));
|
|
|
|
|
|
- g_usbd_core.descriptors = desc;
|
|
|
- g_usbd_core.intf_offset = 0;
|
|
|
+ g_usbd_core[busid].descriptors = desc;
|
|
|
+ g_usbd_core[busid].intf_offset = 0;
|
|
|
|
|
|
- g_usbd_core.tx_msg[0].ep = 0x80;
|
|
|
- g_usbd_core.tx_msg[0].cb = usbd_event_ep0_in_complete_handler;
|
|
|
- g_usbd_core.rx_msg[0].ep = 0x00;
|
|
|
- g_usbd_core.rx_msg[0].cb = usbd_event_ep0_out_complete_handler;
|
|
|
+ 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;
|
|
|
}
|
|
|
#else
|
|
|
-void usbd_desc_register(const uint8_t *desc)
|
|
|
+void usbd_desc_register(uint8_t busid, const uint8_t *desc)
|
|
|
{
|
|
|
- memset(&g_usbd_core, 0, sizeof(struct usbd_core_priv));
|
|
|
+ memset(&g_usbd_core[busid], 0, sizeof(struct usbd_core_priv));
|
|
|
|
|
|
- g_usbd_core.descriptors = desc;
|
|
|
- g_usbd_core.intf_offset = 0;
|
|
|
+ g_usbd_core[busid].descriptors = desc;
|
|
|
+ g_usbd_core[busid].intf_offset = 0;
|
|
|
|
|
|
- g_usbd_core.tx_msg[0].ep = 0x80;
|
|
|
- g_usbd_core.tx_msg[0].cb = usbd_event_ep0_in_complete_handler;
|
|
|
- g_usbd_core.rx_msg[0].ep = 0x00;
|
|
|
- g_usbd_core.rx_msg[0].cb = usbd_event_ep0_out_complete_handler;
|
|
|
+ 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(struct usb_msosv1_descriptor *desc)
|
|
|
+void usbd_msosv1_desc_register(uint8_t busid, struct usb_msosv1_descriptor *desc)
|
|
|
{
|
|
|
- g_usbd_core.msosv1_desc = desc;
|
|
|
+ g_usbd_core[busid].msosv1_desc = desc;
|
|
|
}
|
|
|
|
|
|
/* Register MS OS Descriptors version 2 */
|
|
|
-void usbd_msosv2_desc_register(struct usb_msosv2_descriptor *desc)
|
|
|
+void usbd_msosv2_desc_register(uint8_t busid, struct usb_msosv2_descriptor *desc)
|
|
|
{
|
|
|
- g_usbd_core.msosv2_desc = desc;
|
|
|
+ g_usbd_core[busid].msosv2_desc = desc;
|
|
|
}
|
|
|
|
|
|
-void usbd_bos_desc_register(struct usb_bos_descriptor *desc)
|
|
|
+void usbd_bos_desc_register(uint8_t busid, struct usb_bos_descriptor *desc)
|
|
|
{
|
|
|
- g_usbd_core.bos_desc = desc;
|
|
|
+ g_usbd_core[busid].bos_desc = desc;
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
-void usbd_add_interface(struct usbd_interface *intf)
|
|
|
+void usbd_add_interface(uint8_t busid, struct usbd_interface *intf)
|
|
|
{
|
|
|
- intf->intf_num = g_usbd_core.intf_offset;
|
|
|
- g_usbd_core.intf[g_usbd_core.intf_offset] = intf;
|
|
|
- g_usbd_core.intf_offset++;
|
|
|
+ intf->intf_num = g_usbd_core[busid].intf_offset;
|
|
|
+ g_usbd_core[busid].intf[g_usbd_core[busid].intf_offset] = intf;
|
|
|
+ g_usbd_core[busid].intf_offset++;
|
|
|
}
|
|
|
|
|
|
-void usbd_add_endpoint(struct usbd_endpoint *ep)
|
|
|
+void usbd_add_endpoint(uint8_t busid, struct usbd_endpoint *ep)
|
|
|
{
|
|
|
if (ep->ep_addr & 0x80) {
|
|
|
- g_usbd_core.tx_msg[ep->ep_addr & 0x7f].ep = ep->ep_addr;
|
|
|
- g_usbd_core.tx_msg[ep->ep_addr & 0x7f].cb = ep->ep_cb;
|
|
|
+ g_usbd_core[busid].tx_msg[ep->ep_addr & 0x7f].ep = ep->ep_addr;
|
|
|
+ g_usbd_core[busid].tx_msg[ep->ep_addr & 0x7f].cb = ep->ep_cb;
|
|
|
} else {
|
|
|
- g_usbd_core.rx_msg[ep->ep_addr & 0x7f].ep = ep->ep_addr;
|
|
|
- g_usbd_core.rx_msg[ep->ep_addr & 0x7f].cb = ep->ep_cb;
|
|
|
+ g_usbd_core[busid].rx_msg[ep->ep_addr & 0x7f].ep = ep->ep_addr;
|
|
|
+ g_usbd_core[busid].rx_msg[ep->ep_addr & 0x7f].cb = ep->ep_cb;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-bool usb_device_is_configured(void)
|
|
|
+bool usb_device_is_configured(uint8_t busid)
|
|
|
{
|
|
|
- return g_usbd_core.configuration;
|
|
|
+ return g_usbd_core[busid].configuration;
|
|
|
}
|
|
|
|
|
|
-int usbd_initialize(void)
|
|
|
+int usbd_initialize(uint8_t busid, void (*event_handler)(uint8_t event))
|
|
|
{
|
|
|
int ret;
|
|
|
|
|
|
- ret = usb_dc_init();
|
|
|
- usbd_class_event_notify_handler(USBD_EVENT_INIT, NULL);
|
|
|
+ g_usbd_core[busid].event_handler = event_handler;
|
|
|
+ ret = usb_dc_init(busid);
|
|
|
+ usbd_class_event_notify_handler(busid, USBD_EVENT_INIT, NULL);
|
|
|
+ g_usbd_core[busid].event_handler(USBD_EVENT_INIT);
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-int usbd_deinitialize(void)
|
|
|
+int usbd_deinitialize(uint8_t busid)
|
|
|
{
|
|
|
- g_usbd_core.intf_offset = 0;
|
|
|
- usb_dc_deinit();
|
|
|
- usbd_class_event_notify_handler(USBD_EVENT_DEINIT, NULL);
|
|
|
+ g_usbd_core[busid].intf_offset = 0;
|
|
|
+ usb_dc_deinit(busid);
|
|
|
+ usbd_class_event_notify_handler(busid, USBD_EVENT_DEINIT, NULL);
|
|
|
+ g_usbd_core[busid].event_handler(USBD_EVENT_DEINIT);
|
|
|
return 0;
|
|
|
}
|
|
|
-
|
|
|
-__WEAK void usbd_event_handler(uint8_t event)
|
|
|
-{
|
|
|
- switch (event) {
|
|
|
- case USBD_EVENT_INIT:
|
|
|
- break;
|
|
|
- case USBD_EVENT_DEINIT:
|
|
|
- break;
|
|
|
- case USBD_EVENT_RESET:
|
|
|
- break;
|
|
|
- case USBD_EVENT_CONNECTED:
|
|
|
- break;
|
|
|
- case USBD_EVENT_DISCONNECTED:
|
|
|
- break;
|
|
|
- case USBD_EVENT_RESUME:
|
|
|
- break;
|
|
|
- case USBD_EVENT_SUSPEND:
|
|
|
- break;
|
|
|
- case USBD_EVENT_CONFIGURED:
|
|
|
- break;
|
|
|
- case USBD_EVENT_SET_REMOTE_WAKEUP:
|
|
|
- break;
|
|
|
- case USBD_EVENT_CLR_REMOTE_WAKEUP:
|
|
|
- break;
|
|
|
-
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
-}
|