rtt更新
This commit is contained in:
@@ -45,12 +45,18 @@ USB_NOCACHE_RAM_SECTION struct usbd_core_priv {
|
||||
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[CONFIG_USBDEV_REQUEST_BUFFER_LEN];
|
||||
|
||||
/** Currently selected configuration */
|
||||
uint8_t configuration;
|
||||
uint8_t device_address;
|
||||
bool self_powered;
|
||||
bool remote_wakeup_support;
|
||||
bool remote_wakeup_enabled;
|
||||
bool is_suspend;
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
uint8_t speed;
|
||||
#endif
|
||||
@@ -58,6 +64,7 @@ USB_NOCACHE_RAM_SECTION struct usbd_core_priv {
|
||||
bool test_req;
|
||||
#endif
|
||||
struct usbd_interface *intf[16];
|
||||
uint8_t intf_altsetting[16];
|
||||
uint8_t intf_offset;
|
||||
|
||||
struct usbd_tx_rx_msg tx_msg[CONFIG_USBDEV_EP_NUM];
|
||||
@@ -92,6 +99,7 @@ static bool is_device_configured(uint8_t busid)
|
||||
* This function sets endpoint configuration according to one specified in USB
|
||||
* endpoint descriptor and then enables it for data transfers.
|
||||
*
|
||||
* @param [in] busid busid
|
||||
* @param [in] ep Endpoint descriptor byte array
|
||||
*
|
||||
* @return true if successfully configured and enabled
|
||||
@@ -99,9 +107,9 @@ static bool is_device_configured(uint8_t busid)
|
||||
static bool usbd_set_endpoint(uint8_t busid, const struct usb_endpoint_descriptor *ep)
|
||||
{
|
||||
USB_LOG_DBG("Open ep:0x%02x type:%u mps:%u\r\n",
|
||||
ep->bEndpointAddress,
|
||||
USB_GET_ENDPOINT_TYPE(ep->bmAttributes),
|
||||
USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize));
|
||||
ep->bEndpointAddress,
|
||||
USB_GET_ENDPOINT_TYPE(ep->bmAttributes),
|
||||
USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize));
|
||||
|
||||
if (ep->bEndpointAddress & 0x80) {
|
||||
g_usbd_core[busid].tx_msg[ep->bEndpointAddress & 0x7f].ep_mps = USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize);
|
||||
@@ -119,6 +127,7 @@ static bool usbd_set_endpoint(uint8_t busid, const struct usb_endpoint_descripto
|
||||
* This function cancels transfers that are associated with endpoint and
|
||||
* disabled endpoint itself.
|
||||
*
|
||||
* @param [in] busid busid
|
||||
* @param [in] ep Endpoint descriptor byte array
|
||||
*
|
||||
* @return true if successfully deconfigured and disabled
|
||||
@@ -126,8 +135,8 @@ static bool usbd_set_endpoint(uint8_t busid, const struct usb_endpoint_descripto
|
||||
static bool usbd_reset_endpoint(uint8_t busid, const struct usb_endpoint_descriptor *ep)
|
||||
{
|
||||
USB_LOG_DBG("Close ep:0x%02x type:%u\r\n",
|
||||
ep->bEndpointAddress,
|
||||
USB_GET_ENDPOINT_TYPE(ep->bmAttributes));
|
||||
ep->bEndpointAddress,
|
||||
USB_GET_ENDPOINT_TYPE(ep->bmAttributes));
|
||||
|
||||
return usbd_ep_close(busid, ep->bEndpointAddress) == 0 ? true : false;
|
||||
}
|
||||
@@ -138,6 +147,7 @@ static bool usbd_reset_endpoint(uint8_t busid, const struct usb_endpoint_descrip
|
||||
* This function parses the list of installed USB descriptors and attempts
|
||||
* to find the specified USB descriptor.
|
||||
*
|
||||
* @param [in] busid busid
|
||||
* @param [in] type_index Type and index of the descriptor
|
||||
* @param [out] data Descriptor data
|
||||
* @param [out] len Descriptor length
|
||||
@@ -174,6 +184,9 @@ static bool usbd_get_descriptor(uint8_t busid, uint16_t type_index, uint8_t **da
|
||||
break;
|
||||
}
|
||||
desc_len = ((desc[CONF_DESC_wTotalLength]) | (desc[CONF_DESC_wTotalLength + 1] << 8));
|
||||
|
||||
g_usbd_core[busid].self_powered = (desc[7] & USB_CONFIG_POWERED_MASK) ? true : false;
|
||||
g_usbd_core[busid].remote_wakeup_support = (desc[7] & USB_CONFIG_REMOTE_WAKEUP) ? true : false;
|
||||
break;
|
||||
case USB_DESCRIPTOR_TYPE_STRING:
|
||||
if (index == USB_OSDESC_STRING_DESC_INDEX) {
|
||||
@@ -336,6 +349,9 @@ static bool usbd_get_descriptor(uint8_t busid, uint16_t type_index, uint8_t **da
|
||||
*/
|
||||
*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];
|
||||
@@ -358,6 +374,7 @@ static bool usbd_get_descriptor(uint8_t busid, uint16_t type_index, uint8_t **da
|
||||
* index and alternate setting by parsing the installed USB descriptor list.
|
||||
* A configuration index of 0 unconfigures the device.
|
||||
*
|
||||
* @param [in] busid busid
|
||||
* @param [in] config_index Configuration index
|
||||
* @param [in] alt_setting Alternate setting number
|
||||
*
|
||||
@@ -427,6 +444,7 @@ static bool usbd_set_configuration(uint8_t busid, uint8_t config_index, uint8_t
|
||||
/**
|
||||
* @brief set USB interface
|
||||
*
|
||||
* @param [in] busid busid
|
||||
* @param [in] iface Interface index
|
||||
* @param [in] alt_setting Alternate setting number
|
||||
*
|
||||
@@ -477,10 +495,12 @@ static bool usbd_set_interface(uint8_t busid, uint8_t iface, uint8_t alt_setting
|
||||
if (cur_iface == iface) {
|
||||
ep_desc = (struct usb_endpoint_descriptor *)p;
|
||||
|
||||
if (cur_alt_setting != alt_setting) {
|
||||
if (alt_setting == 0) {
|
||||
ret = usbd_reset_endpoint(busid, ep_desc);
|
||||
} else {
|
||||
goto find_end;
|
||||
} else if (cur_alt_setting == alt_setting) {
|
||||
ret = usbd_set_endpoint(busid, ep_desc);
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -498,6 +518,7 @@ static bool usbd_set_interface(uint8_t busid, uint8_t iface, uint8_t alt_setting
|
||||
}
|
||||
}
|
||||
|
||||
find_end:
|
||||
usbd_class_event_notify_handler(busid, USBD_EVENT_SET_INTERFACE, (void *)if_desc);
|
||||
|
||||
return ret;
|
||||
@@ -506,6 +527,7 @@ static bool usbd_set_interface(uint8_t busid, uint8_t iface, uint8_t alt_setting
|
||||
/**
|
||||
* @brief handle a standard device request
|
||||
*
|
||||
* @param [in] busid busid
|
||||
* @param [in] setup The setup packet
|
||||
* @param [in,out] data Data buffer
|
||||
* @param [in,out] len Pointer to data length
|
||||
@@ -522,6 +544,12 @@ static bool usbd_std_device_req_handler(uint8_t busid, struct usb_setup_packet *
|
||||
/* bit 0: self-powered */
|
||||
/* bit 1: remote wakeup */
|
||||
(*data)[0] = 0x00;
|
||||
if (g_usbd_core[busid].self_powered) {
|
||||
(*data)[0] |= USB_GETSTATUS_SELF_POWERED;
|
||||
}
|
||||
if (g_usbd_core[busid].remote_wakeup_enabled) {
|
||||
(*data)[0] |= USB_GETSTATUS_REMOTE_WAKEUP;
|
||||
}
|
||||
(*data)[1] = 0x00;
|
||||
*len = 2;
|
||||
break;
|
||||
@@ -530,8 +558,10 @@ static bool usbd_std_device_req_handler(uint8_t busid, struct usb_setup_packet *
|
||||
case USB_REQUEST_SET_FEATURE:
|
||||
if (value == USB_FEATURE_REMOTE_WAKEUP) {
|
||||
if (setup->bRequest == USB_REQUEST_SET_FEATURE) {
|
||||
g_usbd_core[busid].remote_wakeup_enabled = true;
|
||||
g_usbd_core[busid].event_handler(busid, USBD_EVENT_SET_REMOTE_WAKEUP);
|
||||
} else {
|
||||
g_usbd_core[busid].remote_wakeup_enabled = false;
|
||||
g_usbd_core[busid].event_handler(busid, USBD_EVENT_CLR_REMOTE_WAKEUP);
|
||||
}
|
||||
} else if (value == USB_FEATURE_TEST_MODE) {
|
||||
@@ -543,6 +573,7 @@ static bool usbd_std_device_req_handler(uint8_t busid, struct usb_setup_packet *
|
||||
break;
|
||||
|
||||
case USB_REQUEST_SET_ADDRESS:
|
||||
g_usbd_core[busid].device_address = value;
|
||||
usbd_set_address(busid, value);
|
||||
*len = 0;
|
||||
break;
|
||||
@@ -556,17 +587,20 @@ static bool usbd_std_device_req_handler(uint8_t busid, struct usb_setup_packet *
|
||||
break;
|
||||
|
||||
case USB_REQUEST_GET_CONFIGURATION:
|
||||
*data = (uint8_t *)&g_usbd_core[busid].configuration;
|
||||
(*data)[0] = g_usbd_core[busid].configuration;
|
||||
*len = 1;
|
||||
break;
|
||||
|
||||
case USB_REQUEST_SET_CONFIGURATION:
|
||||
value &= 0xFF;
|
||||
|
||||
if (!usbd_set_configuration(busid, value, 0)) {
|
||||
if (value == 0) {
|
||||
g_usbd_core[busid].configuration = 0;
|
||||
} else if (!usbd_set_configuration(busid, value, 0)) {
|
||||
ret = false;
|
||||
} else {
|
||||
g_usbd_core[busid].configuration = value;
|
||||
g_usbd_core[busid].is_suspend = false;
|
||||
usbd_class_event_notify_handler(busid, USBD_EVENT_CONFIGURED, NULL);
|
||||
g_usbd_core[busid].event_handler(busid, USBD_EVENT_CONFIGURED);
|
||||
}
|
||||
@@ -589,6 +623,7 @@ static bool usbd_std_device_req_handler(uint8_t busid, struct usb_setup_packet *
|
||||
/**
|
||||
* @brief handle a standard interface request
|
||||
*
|
||||
* @param [in] busid busid
|
||||
* @param [in] setup The setup packet
|
||||
* @param [in,out] data Data buffer
|
||||
* @param [in,out] len Pointer to data length
|
||||
@@ -600,6 +635,16 @@ static bool usbd_std_interface_req_handler(uint8_t busid, struct usb_setup_packe
|
||||
uint8_t type = HI_BYTE(setup->wValue);
|
||||
uint8_t intf_num = LO_BYTE(setup->wIndex);
|
||||
bool ret = true;
|
||||
const uint8_t *p;
|
||||
uint32_t desc_len = 0;
|
||||
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)) {
|
||||
@@ -614,7 +659,39 @@ static bool usbd_std_interface_req_handler(uint8_t busid, struct usb_setup_packe
|
||||
break;
|
||||
|
||||
case USB_REQUEST_GET_DESCRIPTOR:
|
||||
if (type == 0x22) { /* HID_DESCRIPTOR_TYPE_HID_REPORT */
|
||||
if (type == 0x21) { /* HID_DESCRIPTOR_TYPE_HID */
|
||||
while (p[DESC_bLength] != 0U) {
|
||||
switch (p[DESC_bDescriptorType]) {
|
||||
case USB_DESCRIPTOR_TYPE_CONFIGURATION:
|
||||
current_desc_len = 0;
|
||||
desc_len = (p[CONF_DESC_wTotalLength]) |
|
||||
(p[CONF_DESC_wTotalLength + 1] << 8);
|
||||
|
||||
break;
|
||||
|
||||
case USB_DESCRIPTOR_TYPE_INTERFACE:
|
||||
cur_iface = p[INTF_DESC_bInterfaceNumber];
|
||||
break;
|
||||
case 0x21:
|
||||
if (cur_iface == intf_num) {
|
||||
*data = (uint8_t *)p;
|
||||
//memcpy(*data, p, p[DESC_bLength]);
|
||||
*len = p[DESC_bLength];
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* skip to next descriptor */
|
||||
p += p[DESC_bLength];
|
||||
current_desc_len += p[DESC_bLength];
|
||||
if (current_desc_len >= desc_len && desc_len) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (type == 0x22) { /* HID_DESCRIPTOR_TYPE_HID_REPORT */
|
||||
for (uint8_t i = 0; i < g_usbd_core[busid].intf_offset; i++) {
|
||||
struct usbd_interface *intf = g_usbd_core[busid].intf[i];
|
||||
|
||||
@@ -633,11 +710,12 @@ static bool usbd_std_interface_req_handler(uint8_t busid, struct usb_setup_packe
|
||||
ret = false;
|
||||
break;
|
||||
case USB_REQUEST_GET_INTERFACE:
|
||||
(*data)[0] = 0;
|
||||
(*data)[0] = g_usbd_core[busid].intf_altsetting[intf_num];
|
||||
*len = 1;
|
||||
break;
|
||||
|
||||
case USB_REQUEST_SET_INTERFACE:
|
||||
g_usbd_core[busid].intf_altsetting[intf_num] = LO_BYTE(setup->wValue);
|
||||
usbd_set_interface(busid, setup->wIndex, setup->wValue);
|
||||
*len = 0;
|
||||
break;
|
||||
@@ -653,6 +731,7 @@ static bool usbd_std_interface_req_handler(uint8_t busid, struct usb_setup_packe
|
||||
/**
|
||||
* @brief handle a standard endpoint request
|
||||
*
|
||||
* @param [in] busid busid
|
||||
* @param [in] setup The setup packet
|
||||
* @param [in,out] data Data buffer
|
||||
* @param [in,out] len Pointer to data length
|
||||
@@ -663,6 +742,7 @@ static bool usbd_std_endpoint_req_handler(uint8_t busid, struct usb_setup_packet
|
||||
{
|
||||
uint8_t ep = (uint8_t)setup->wIndex;
|
||||
bool ret = true;
|
||||
uint8_t stalled;
|
||||
|
||||
/* Only when device is configured, then endpoint requests can be valid. */
|
||||
if (!is_device_configured(busid)) {
|
||||
@@ -671,7 +751,12 @@ static bool usbd_std_endpoint_req_handler(uint8_t busid, struct usb_setup_packet
|
||||
|
||||
switch (setup->bRequest) {
|
||||
case USB_REQUEST_GET_STATUS:
|
||||
(*data)[0] = 0x00;
|
||||
usbd_ep_is_stalled(busid, ep, &stalled);
|
||||
if (stalled) {
|
||||
(*data)[0] = 0x01;
|
||||
} else {
|
||||
(*data)[0] = 0x00;
|
||||
}
|
||||
(*data)[1] = 0x00;
|
||||
*len = 2;
|
||||
break;
|
||||
@@ -711,6 +796,7 @@ static bool usbd_std_endpoint_req_handler(uint8_t busid, struct usb_setup_packet
|
||||
/**
|
||||
* @brief handle standard requests (list in chapter 9)
|
||||
*
|
||||
* @param [in] busid busid
|
||||
* @param [in] setup The setup packet
|
||||
* @param [in,out] data Data buffer
|
||||
* @param [in,out] len Pointer to data length
|
||||
@@ -754,8 +840,7 @@ static int usbd_standard_request_handler(uint8_t busid, struct usb_setup_packet
|
||||
/**
|
||||
* @brief handler for class requests
|
||||
*
|
||||
* If a custom request handler was installed, this handler is called first.
|
||||
*
|
||||
* @param [in] busid busid
|
||||
* @param [in] setup The setup packet
|
||||
* @param [in,out] data Data buffer
|
||||
* @param [in,out] len Pointer to data length
|
||||
@@ -787,8 +872,7 @@ static int usbd_class_request_handler(uint8_t busid, struct usb_setup_packet *se
|
||||
/**
|
||||
* @brief handler for vendor requests
|
||||
*
|
||||
* If a custom request handler was installed, this handler is called first.
|
||||
*
|
||||
* @param [in] busid busid
|
||||
* @param [in] setup The setup packet
|
||||
* @param [in,out] data Data buffer
|
||||
* @param [in,out] len Pointer to data length
|
||||
@@ -841,10 +925,12 @@ static int usbd_vendor_request_handler(uint8_t busid, struct usb_setup_packet *s
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} else if (g_usbd_core[busid].descriptors->webusb_url_descriptor) {
|
||||
}
|
||||
|
||||
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:
|
||||
case WEBUSB_REQUEST_GET_URL:
|
||||
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);
|
||||
@@ -897,6 +983,22 @@ static int usbd_vendor_request_handler(uint8_t busid, struct usb_setup_packet *s
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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:
|
||||
USB_LOG_ERR("unknown vendor code\r\n");
|
||||
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];
|
||||
@@ -912,6 +1014,7 @@ static int usbd_vendor_request_handler(uint8_t busid, struct usb_setup_packet *s
|
||||
/**
|
||||
* @brief handle setup request( standard/class/vendor/other)
|
||||
*
|
||||
* @param [in] busid busid
|
||||
* @param [in] setup The setup packet
|
||||
* @param [in,out] data Data buffer
|
||||
* @param [in,out] len Pointer to data length
|
||||
@@ -985,17 +1088,22 @@ void usbd_event_disconnect_handler(uint8_t busid)
|
||||
|
||||
void usbd_event_resume_handler(uint8_t busid)
|
||||
{
|
||||
g_usbd_core[busid].is_suspend = false;
|
||||
g_usbd_core[busid].event_handler(busid, USBD_EVENT_RESUME);
|
||||
}
|
||||
|
||||
void usbd_event_suspend_handler(uint8_t busid)
|
||||
{
|
||||
g_usbd_core[busid].event_handler(busid, USBD_EVENT_SUSPEND);
|
||||
if (g_usbd_core[busid].device_address > 0) {
|
||||
g_usbd_core[busid].is_suspend = true;
|
||||
g_usbd_core[busid].event_handler(busid, USBD_EVENT_SUSPEND);
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_event_reset_handler(uint8_t busid)
|
||||
{
|
||||
usbd_set_address(busid, 0);
|
||||
g_usbd_core[busid].device_address = 0;
|
||||
g_usbd_core[busid].configuration = 0;
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
g_usbd_core[busid].speed = USB_SPEED_UNKNOWN;
|
||||
@@ -1068,7 +1176,7 @@ void usbd_event_ep0_setup_complete_handler(uint8_t busid, uint8_t *psetup)
|
||||
#ifdef CONFIG_USBDEV_EP0_INDATA_NO_COPY
|
||||
g_usbd_core[busid].ep0_data_buf = buf;
|
||||
#else
|
||||
memcpy(g_usbd_core[busid].ep0_data_buf, buf, g_usbd_core[busid].ep0_data_buf_residue);
|
||||
usb_memcpy(g_usbd_core[busid].ep0_data_buf, buf, g_usbd_core[busid].ep0_data_buf_residue);
|
||||
#endif
|
||||
} else {
|
||||
/* use memcpy(*data, xxx, len); has copied into ep0 buffer, we do nothing */
|
||||
@@ -1091,6 +1199,8 @@ void usbd_event_ep0_in_complete_handler(uint8_t busid, uint8_t ep, uint32_t nbyt
|
||||
{
|
||||
struct usb_setup_packet *setup = &g_usbd_core[busid].setup;
|
||||
|
||||
(void)ep;
|
||||
|
||||
g_usbd_core[busid].ep0_data_buf += nbytes;
|
||||
g_usbd_core[busid].ep0_data_buf_residue -= nbytes;
|
||||
|
||||
@@ -1130,6 +1240,8 @@ void usbd_event_ep0_out_complete_handler(uint8_t busid, uint8_t ep, uint32_t nby
|
||||
{
|
||||
struct usb_setup_packet *setup = &g_usbd_core[busid].setup;
|
||||
|
||||
(void)ep;
|
||||
|
||||
if (nbytes > 0) {
|
||||
g_usbd_core[busid].ep0_data_buf += nbytes;
|
||||
g_usbd_core[busid].ep0_data_buf_residue -= nbytes;
|
||||
@@ -1213,6 +1325,11 @@ 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)
|
||||
@@ -1256,7 +1373,30 @@ bool usb_device_is_configured(uint8_t busid)
|
||||
return g_usbd_core[busid].configuration;
|
||||
}
|
||||
|
||||
int usbd_initialize(uint8_t busid, uint32_t reg_base, void (*event_handler)(uint8_t busid, uint8_t event))
|
||||
bool usb_device_is_suspend(uint8_t busid)
|
||||
{
|
||||
return g_usbd_core[busid].is_suspend;
|
||||
}
|
||||
|
||||
int usbd_send_remote_wakeup(uint8_t busid)
|
||||
{
|
||||
if (g_usbd_core[busid].remote_wakeup_support && g_usbd_core[busid].remote_wakeup_enabled && g_usbd_core[busid].is_suspend) {
|
||||
return usbd_set_remote_wakeup(busid);
|
||||
} else {
|
||||
if (!g_usbd_core[busid].remote_wakeup_support) {
|
||||
USB_LOG_ERR("device does not support remote wakeup\r\n");
|
||||
}
|
||||
if (!g_usbd_core[busid].remote_wakeup_enabled) {
|
||||
USB_LOG_ERR("device remote wakeup is not enabled\r\n");
|
||||
}
|
||||
if (!g_usbd_core[busid].is_suspend) {
|
||||
USB_LOG_ERR("device is not in suspend state\r\n");
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int usbd_initialize(uint8_t busid, uintptr_t reg_base, void (*event_handler)(uint8_t busid, uint8_t event))
|
||||
{
|
||||
int ret;
|
||||
struct usbd_bus *bus;
|
||||
@@ -1279,9 +1419,15 @@ int usbd_initialize(uint8_t busid, uint32_t reg_base, void (*event_handler)(uint
|
||||
|
||||
int usbd_deinitialize(uint8_t busid)
|
||||
{
|
||||
g_usbd_core[busid].intf_offset = 0;
|
||||
usb_dc_deinit(busid);
|
||||
usbd_class_event_notify_handler(busid, USBD_EVENT_DEINIT, NULL);
|
||||
if (busid >= CONFIG_USBDEV_MAX_BUS) {
|
||||
USB_LOG_ERR("bus overflow\r\n");
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
g_usbd_core[busid].event_handler(busid, USBD_EVENT_DEINIT);
|
||||
usbd_class_event_notify_handler(busid, USBD_EVENT_DEINIT, NULL);
|
||||
usb_dc_deinit(busid);
|
||||
g_usbd_core[busid].intf_offset = 0;
|
||||
return 0;
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@ extern "C" {
|
||||
#include "usb_log.h"
|
||||
#include "usb_dc.h"
|
||||
#include "usb_memcpy.h"
|
||||
#include "usb_version.h"
|
||||
|
||||
enum usbd_event_type {
|
||||
/* USB DCD IRQ */
|
||||
@@ -71,13 +72,13 @@ struct usb_descriptor {
|
||||
const char *(*string_descriptor_callback)(uint8_t speed, uint8_t index);
|
||||
const struct usb_msosv1_descriptor *msosv1_descriptor;
|
||||
const struct usb_msosv2_descriptor *msosv2_descriptor;
|
||||
const struct usb_webusb_url_ex_descriptor *webusb_url_descriptor;
|
||||
const struct usb_webusb_descriptor *webusb_url_descriptor;
|
||||
const struct usb_bos_descriptor *bos_descriptor;
|
||||
};
|
||||
|
||||
struct usbd_bus {
|
||||
uint8_t busid;
|
||||
uint32_t reg_base;
|
||||
uintptr_t reg_base;
|
||||
};
|
||||
|
||||
extern struct usbd_bus g_usbdev_bus[];
|
||||
@@ -93,6 +94,7 @@ 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);
|
||||
@@ -101,8 +103,10 @@ void usbd_add_endpoint(uint8_t busid, struct usbd_endpoint *ep);
|
||||
uint16_t usbd_get_ep_mps(uint8_t busid, uint8_t ep);
|
||||
uint8_t usbd_get_ep_mult(uint8_t busid, uint8_t ep);
|
||||
bool usb_device_is_configured(uint8_t busid);
|
||||
bool usb_device_is_suspend(uint8_t busid);
|
||||
int usbd_send_remote_wakeup(uint8_t busid);
|
||||
|
||||
int usbd_initialize(uint8_t busid, uint32_t reg_base, void (*event_handler)(uint8_t busid, uint8_t event));
|
||||
int usbd_initialize(uint8_t busid, uintptr_t reg_base, void (*event_handler)(uint8_t busid, uint8_t event));
|
||||
int usbd_deinitialize(uint8_t busid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@@ -93,19 +93,22 @@ static const struct usbh_class_driver *usbh_find_class_driver(uint8_t class, uin
|
||||
struct usbh_class_info *index = NULL;
|
||||
|
||||
for (index = usbh_class_info_table_begin; index < usbh_class_info_table_end; index++) {
|
||||
if ((index->match_flags & USB_CLASS_MATCH_INTF_CLASS) && !(index->class == class)) {
|
||||
if ((index->match_flags & USB_CLASS_MATCH_INTF_CLASS) && !(index->bInterfaceClass == class)) {
|
||||
continue;
|
||||
}
|
||||
if ((index->match_flags & USB_CLASS_MATCH_INTF_SUBCLASS) && !(index->subclass == subclass)) {
|
||||
if ((index->match_flags & USB_CLASS_MATCH_INTF_SUBCLASS) && !(index->bInterfaceSubClass == subclass)) {
|
||||
continue;
|
||||
}
|
||||
if ((index->match_flags & USB_CLASS_MATCH_INTF_PROTOCOL) && !(index->protocol == protocol)) {
|
||||
if ((index->match_flags & USB_CLASS_MATCH_INTF_PROTOCOL) && !(index->bInterfaceProtocol == protocol)) {
|
||||
continue;
|
||||
}
|
||||
if (index->match_flags & USB_CLASS_MATCH_VID_PID && index->id_table) {
|
||||
/* scan id table */
|
||||
uint32_t i;
|
||||
for (i = 0; index->id_table[i][0] && index->id_table[i][0] != vid && index->id_table[i][1] != pid; i++) {
|
||||
for (i = 0; index->id_table[i][0]; i++) {
|
||||
if (index->id_table[i][0] == vid && index->id_table[i][1] == pid) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* do not match, continue next */
|
||||
if (!index->id_table[i][0]) {
|
||||
@@ -486,7 +489,7 @@ int usbh_enumerate(struct usbh_hubport *hport)
|
||||
goto errout;
|
||||
}
|
||||
USB_LOG_INFO("The device has %d interfaces\r\n", ((struct usb_configuration_descriptor *)ep0_request_buffer[hport->bus->busid])->bNumInterfaces);
|
||||
hport->raw_config_desc = usb_malloc(wTotalLength);
|
||||
hport->raw_config_desc = usb_osal_malloc(wTotalLength + 1);
|
||||
if (hport->raw_config_desc == NULL) {
|
||||
ret = -USB_ERR_NOMEM;
|
||||
USB_LOG_ERR("No memory to alloc for raw_config_desc\r\n");
|
||||
@@ -495,6 +498,8 @@ int usbh_enumerate(struct usbh_hubport *hport)
|
||||
|
||||
config_value = ((struct usb_configuration_descriptor *)ep0_request_buffer[hport->bus->busid])->bConfigurationValue;
|
||||
memcpy(hport->raw_config_desc, ep0_request_buffer[hport->bus->busid], wTotalLength);
|
||||
hport->raw_config_desc[wTotalLength] = '\0';
|
||||
|
||||
#ifdef CONFIG_USBHOST_GET_STRING_DESC
|
||||
uint8_t string_buffer[128];
|
||||
|
||||
@@ -549,7 +554,7 @@ int usbh_enumerate(struct usbh_hubport *hport)
|
||||
setup->wLength = 16;
|
||||
|
||||
ret = usbh_control_transfer(hport, setup, ep0_request_buffer[hport->bus->busid]);
|
||||
if (ret < 0 && (ret != -EPERM)) {
|
||||
if (ret < 0 && (ret != -USB_ERR_STALL)) {
|
||||
USB_LOG_ERR("Failed to get msosv1 compat id,errorcode:%d\r\n", ret);
|
||||
goto errout;
|
||||
}
|
||||
@@ -576,7 +581,7 @@ int usbh_enumerate(struct usbh_hubport *hport)
|
||||
|
||||
errout:
|
||||
if (hport->raw_config_desc) {
|
||||
usb_free(hport->raw_config_desc);
|
||||
usb_osal_free(hport->raw_config_desc);
|
||||
hport->raw_config_desc = NULL;
|
||||
}
|
||||
return ret;
|
||||
@@ -600,7 +605,7 @@ void usbh_hubport_release(struct usbh_hubport *hport)
|
||||
}
|
||||
}
|
||||
|
||||
static void usbh_bus_init(struct usbh_bus *bus, uint8_t busid, uint32_t reg_base)
|
||||
static void usbh_bus_init(struct usbh_bus *bus, uint8_t busid, uintptr_t reg_base)
|
||||
{
|
||||
memset(bus, 0, sizeof(struct usbh_bus));
|
||||
bus->busid = busid;
|
||||
@@ -613,7 +618,7 @@ static void usbh_bus_init(struct usbh_bus *bus, uint8_t busid, uint32_t reg_base
|
||||
usb_slist_add_tail(&g_bus_head, &bus->list);
|
||||
}
|
||||
|
||||
int usbh_initialize(uint8_t busid, uint32_t reg_base)
|
||||
int usbh_initialize(uint8_t busid, uintptr_t reg_base)
|
||||
{
|
||||
struct usbh_bus *bus;
|
||||
|
||||
@@ -649,6 +654,12 @@ int usbh_deinitialize(uint8_t busid)
|
||||
{
|
||||
struct usbh_bus *bus;
|
||||
|
||||
if (busid >= CONFIG_USBHOST_MAX_BUS) {
|
||||
USB_LOG_ERR("bus overflow\r\n");
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
bus = &g_usbhost_bus[busid];
|
||||
|
||||
usbh_hub_deinitialize(bus);
|
||||
@@ -731,7 +742,7 @@ static void *usbh_list_all_interface_name(struct usbh_hub *hub, const char *devn
|
||||
struct usbh_hub *hub_next;
|
||||
void *priv;
|
||||
|
||||
for (uint8_t port = 0; port < hub->hub_desc.bNbrPorts; port++) {
|
||||
for (uint8_t port = 0; port < hub->nports; port++) {
|
||||
hport = &hub->child[port];
|
||||
if (hport->connected) {
|
||||
for (uint8_t itf = 0; itf < hport->config.config_desc.bNumInterfaces; itf++) {
|
||||
@@ -760,8 +771,9 @@ static void usbh_list_all_interface_driver(struct usbh_hub *hub)
|
||||
{
|
||||
struct usbh_hubport *hport;
|
||||
struct usbh_hub *hub_next;
|
||||
const char *speed_table[] = { "error-speed", "low-speed", "full-speed", "high-speed", "wireless-speed", "super-speed", "superplus-speed" };
|
||||
|
||||
for (uint8_t port = 0; port < hub->hub_desc.bNbrPorts; port++) {
|
||||
for (uint8_t port = 0; port < hub->nports; port++) {
|
||||
hport = &hub->child[port];
|
||||
if (hport->connected) {
|
||||
for (uint8_t itf = 0; itf < hport->config.config_desc.bNumInterfaces; itf++) {
|
||||
@@ -770,11 +782,12 @@ static void usbh_list_all_interface_driver(struct usbh_hub *hub)
|
||||
USB_LOG_RAW("\t");
|
||||
}
|
||||
|
||||
USB_LOG_RAW("|__Port %u, dev addr:0x%02x, If %u, ClassDriver=%s\r\n",
|
||||
USB_LOG_RAW("|__Port %u, dev addr:0x%02x, If %u, ClassDriver=%s, %s\r\n",
|
||||
hport->port,
|
||||
hport->dev_addr,
|
||||
itf,
|
||||
hport->config.intf[itf].class_driver->driver_name);
|
||||
hport->config.intf[itf].class_driver->driver_name,
|
||||
speed_table[hport->speed]);
|
||||
|
||||
if (strcmp(hport->config.intf[itf].class_driver->driver_name, "hub") == 0) {
|
||||
hub_next = hport->config.intf[itf].priv;
|
||||
@@ -794,7 +807,7 @@ static void usbh_list_all_interface_desc(struct usbh_bus *bus, struct usbh_hub *
|
||||
struct usbh_hubport *hport;
|
||||
struct usbh_hub *hub_next;
|
||||
|
||||
for (uint8_t port = 0; port < hub->hub_desc.bNbrPorts; port++) {
|
||||
for (uint8_t port = 0; port < hub->nports; port++) {
|
||||
hport = &hub->child[port];
|
||||
if (hport->connected) {
|
||||
USB_LOG_RAW("\r\nBus %u, Hub %u, Port %u, dev addr:0x%02x, VID:PID 0x%04x:0x%04x\r\n",
|
||||
@@ -821,6 +834,37 @@ static void usbh_list_all_interface_desc(struct usbh_bus *bus, struct usbh_hub *
|
||||
}
|
||||
}
|
||||
|
||||
static struct usbh_hubport *usbh_list_all_hubport(struct usbh_hub *hub, uint8_t hub_index, uint8_t hub_port)
|
||||
{
|
||||
struct usbh_hubport *hport;
|
||||
struct usbh_hub *hub_next;
|
||||
|
||||
if (hub->index == hub_index) {
|
||||
hport = &hub->child[hub_port - 1];
|
||||
return hport;
|
||||
} else {
|
||||
for (uint8_t port = 0; port < hub->nports; port++) {
|
||||
hport = &hub->child[port];
|
||||
if (hport->connected) {
|
||||
for (uint8_t itf = 0; itf < hport->config.config_desc.bNumInterfaces; itf++) {
|
||||
if (hport->config.intf[itf].class_driver && hport->config.intf[itf].class_driver->driver_name) {
|
||||
if (strcmp(hport->config.intf[itf].class_driver->driver_name, "hub") == 0) {
|
||||
hub_next = hport->config.intf[itf].priv;
|
||||
|
||||
if (hub_next && hub_next->connected) {
|
||||
hport = usbh_list_all_hubport(hub_next, hub_index, hub_port);
|
||||
if (hport) {
|
||||
return hport;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
void *usbh_find_class_instance(const char *devname)
|
||||
{
|
||||
usb_slist_t *bus_list;
|
||||
@@ -845,6 +889,23 @@ void *usbh_find_class_instance(const char *devname)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct usbh_hubport *usbh_find_hubport(uint8_t busid, uint8_t hub_index, uint8_t hub_port)
|
||||
{
|
||||
struct usbh_hub *hub;
|
||||
struct usbh_bus *bus;
|
||||
struct usbh_hubport *hport;
|
||||
size_t flags;
|
||||
|
||||
flags = usb_osal_enter_critical_section();
|
||||
|
||||
bus = &g_usbhost_bus[busid];
|
||||
hub = &bus->hcd.roothub;
|
||||
|
||||
hport = usbh_list_all_hubport(hub, hub_index, hub_port);
|
||||
usb_osal_leave_critical_section(flags);
|
||||
return hport;
|
||||
}
|
||||
|
||||
int lsusb(int argc, char **argv)
|
||||
{
|
||||
usb_slist_t *bus_list;
|
||||
@@ -888,7 +949,7 @@ int lsusb(int argc, char **argv)
|
||||
USB_LOG_RAW("/: Bus %u, Hub %u, ports=%u, is roothub\r\n",
|
||||
bus->busid,
|
||||
hub->index,
|
||||
hub->hub_desc.bNbrPorts);
|
||||
hub->nports);
|
||||
usbh_list_all_interface_driver(hub);
|
||||
}
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@
|
||||
#include "usb_osal.h"
|
||||
#include "usbh_hub.h"
|
||||
#include "usb_memcpy.h"
|
||||
#include "usb_version.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -60,9 +61,9 @@ extern "C" {
|
||||
|
||||
struct usbh_class_info {
|
||||
uint8_t match_flags; /* Used for product specific matches; range is inclusive */
|
||||
uint8_t class; /* Base device class code */
|
||||
uint8_t subclass; /* Sub-class, depends on base class. Eg. */
|
||||
uint8_t protocol; /* Protocol, depends on base class. Eg. */
|
||||
uint8_t bInterfaceClass; /* Base device class code */
|
||||
uint8_t bInterfaceSubClass; /* Sub-class, depends on base class. Eg. */
|
||||
uint8_t bInterfaceProtocol; /* Protocol, depends on base class. Eg. */
|
||||
const uint16_t (*id_table)[2]; /* List of Vendor/Product ID pairs */
|
||||
const struct usbh_class_driver *class_driver;
|
||||
};
|
||||
@@ -101,6 +102,9 @@ struct usbh_hubport {
|
||||
uint8_t port; /* Hub port index */
|
||||
uint8_t dev_addr; /* device address */
|
||||
uint8_t speed; /* device speed */
|
||||
uint8_t depth; /* distance from root hub */
|
||||
uint8_t route; /* route string */
|
||||
uint8_t slot_id; /* slot id */
|
||||
struct usb_device_descriptor device_desc;
|
||||
struct usbh_configuration config;
|
||||
const char *iManufacturer;
|
||||
@@ -109,6 +113,7 @@ struct usbh_hubport {
|
||||
uint8_t *raw_config_desc;
|
||||
struct usb_setup_packet *setup;
|
||||
struct usbh_hub *parent;
|
||||
struct usbh_hub *self; /* if this hubport is a hub */
|
||||
struct usbh_bus *bus;
|
||||
struct usb_endpoint_descriptor ep0;
|
||||
struct usbh_urb ep0_urb;
|
||||
@@ -120,7 +125,13 @@ struct usbh_hub {
|
||||
bool is_roothub;
|
||||
uint8_t index;
|
||||
uint8_t hub_addr;
|
||||
struct usb_hub_descriptor hub_desc;
|
||||
uint8_t speed;
|
||||
uint8_t nports;
|
||||
uint8_t powerdelay;
|
||||
uint8_t tt_think;
|
||||
bool ismtt;
|
||||
struct usb_hub_descriptor hub_desc; /* USB 2.0 only */
|
||||
struct usb_hub_ss_descriptor hub_ss_desc; /* USB 3.0 only */
|
||||
struct usbh_hubport child[CONFIG_USBHOST_MAX_EHPORTS];
|
||||
struct usbh_hubport *parent;
|
||||
struct usbh_bus *bus;
|
||||
@@ -143,9 +154,9 @@ struct usbh_devaddr_map {
|
||||
};
|
||||
|
||||
struct usbh_hcd {
|
||||
uint32_t reg_base;
|
||||
uintptr_t reg_base;
|
||||
uint8_t hcd_id;
|
||||
uint8_t roothub_intbuf[1];
|
||||
uint8_t roothub_intbuf[2]; /* at most 15 roothub ports */
|
||||
struct usbh_hub roothub;
|
||||
};
|
||||
|
||||
@@ -261,9 +272,10 @@ int usbh_get_string_desc(struct usbh_hubport *hport, uint8_t index, uint8_t *out
|
||||
*/
|
||||
int usbh_set_interface(struct usbh_hubport *hport, uint8_t intf, uint8_t altsetting);
|
||||
|
||||
int usbh_initialize(uint8_t busid, uint32_t reg_base);
|
||||
int usbh_initialize(uint8_t busid, uintptr_t reg_base);
|
||||
int usbh_deinitialize(uint8_t busid);
|
||||
void *usbh_find_class_instance(const char *devname);
|
||||
struct usbh_hubport *usbh_find_hubport(uint8_t busid, uint8_t hub_index, uint8_t hub_port);
|
||||
|
||||
int lsusb(int argc, char **argv);
|
||||
|
||||
|
Reference in New Issue
Block a user