diff --git a/cherryusb_config_template.h b/cherryusb_config_template.h index c0eb9751..d7fc7270 100644 --- a/cherryusb_config_template.h +++ b/cherryusb_config_template.h @@ -79,11 +79,12 @@ /* ================ USB HOST Stack Configuration ================== */ -#define CONFIG_USBHOST_RHPORTS 1 -#define CONFIG_USBHOST_EXTHUB_NUM 1 -#define CONFIG_USBHOST_EHPORTS 4 -#define CONFIG_USBHOST_INTF_NUM 6 -#define CONFIG_USBHOST_EP_NUM 4 +#define CONFIG_USBHOST_MAX_RHPORTS 1 +#define CONFIG_USBHOST_MAX_EXTHUBS 1 +#define CONFIG_USBHOST_MAX_EHPORTS 4 +#define CONFIG_USBHOST_MAX_INTERFACES 6 +#define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 1 +#define CONFIG_USBHOST_MAX_ENDPOINTS 4 #define CONFIG_USBHOST_DEV_NAMELEN 16 diff --git a/class/cdc/usbh_cdc_acm.c b/class/cdc/usbh_cdc_acm.c index 0afbcde0..bb01e88c 100644 --- a/class/cdc/usbh_cdc_acm.c +++ b/class/cdc/usbh_cdc_acm.c @@ -111,7 +111,6 @@ int usbh_cdc_acm_set_line_state(struct usbh_cdc_acm *cdc_acm_class, bool dtr, bo static int usbh_cdc_acm_connect(struct usbh_hubport *hport, uint8_t intf) { - struct usbh_endpoint_cfg ep_cfg = { 0 }; struct usb_endpoint_descriptor *ep_desc; int ret; @@ -147,7 +146,7 @@ static int usbh_cdc_acm_connect(struct usbh_hubport *hport, uint8_t intf) } #ifdef CONFIG_USBHOST_CDC_ACM_NOTIFY - ep_desc = &hport->config.intf[intf].ep[0].ep_desc; + ep_desc = &hport->config.intf[intf].altsetting[0].ep[0].ep_desc; ep_cfg.ep_addr = ep_desc->bEndpointAddress; ep_cfg.ep_type = ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK; ep_cfg.ep_mps = ep_desc->wMaxPacketSize; @@ -156,25 +155,14 @@ static int usbh_cdc_acm_connect(struct usbh_hubport *hport, uint8_t intf) usbh_pipe_alloc(&cdc_acm_class->intin, &ep_cfg); #endif - for (uint8_t i = 0; i < hport->config.intf[intf + 1].intf_desc.bNumEndpoints; i++) { - ep_desc = &hport->config.intf[intf + 1].ep[i].ep_desc; + for (uint8_t i = 0; i < hport->config.intf[intf + 1].altsetting[0].intf_desc.bNumEndpoints; i++) { + ep_desc = &hport->config.intf[intf + 1].altsetting[0].ep[i].ep_desc; - ep_cfg.ep_addr = ep_desc->bEndpointAddress; - ep_cfg.ep_type = ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK; - ep_cfg.ep_mps = ep_desc->wMaxPacketSize & USB_MAXPACKETSIZE_MASK; - ep_cfg.ep_interval = ep_desc->bInterval; - ep_cfg.hport = hport; if (ep_desc->bEndpointAddress & 0x80) { - usbh_pipe_alloc(&cdc_acm_class->bulkin, &ep_cfg); + usbh_hport_activate_epx(&cdc_acm_class->bulkin, hport, ep_desc); } else { - usbh_pipe_alloc(&cdc_acm_class->bulkout, &ep_cfg); + usbh_hport_activate_epx(&cdc_acm_class->bulkout, hport, ep_desc); } - - USB_LOG_INFO("Ep=%02x Attr=%02u Mps=%d Interval=%02u\r\n", - ep_desc->bEndpointAddress, - ep_desc->bmAttributes, - ep_desc->wMaxPacketSize, - ep_desc->bInterval); } snprintf(hport->config.intf[intf].devname, CONFIG_USBHOST_DEV_NAMELEN, DEV_FORMAT, cdc_acm_class->minor); @@ -191,7 +179,6 @@ static int usbh_cdc_acm_disconnect(struct usbh_hubport *hport, uint8_t intf) struct usbh_cdc_acm *cdc_acm_class = (struct usbh_cdc_acm *)hport->config.intf[intf].priv; if (cdc_acm_class) { - usbh_cdc_acm_devno_free(cdc_acm_class); if (cdc_acm_class->bulkin) { diff --git a/class/hid/usbh_hid.c b/class/hid/usbh_hid.c index 9001e751..e844177b 100644 --- a/class/hid/usbh_hid.c +++ b/class/hid/usbh_hid.c @@ -112,7 +112,6 @@ int usbh_hid_get_idle(struct usbh_hid *hid_class, uint8_t *buffer) int usbh_hid_connect(struct usbh_hubport *hport, uint8_t intf) { - struct usbh_endpoint_cfg ep_cfg = { 0 }; struct usb_endpoint_descriptor *ep_desc; int ret; @@ -139,24 +138,13 @@ int usbh_hid_connect(struct usbh_hubport *hport, uint8_t intf) return ret; } - for (uint8_t i = 0; i < hport->config.intf[intf].intf_desc.bNumEndpoints; i++) { - ep_desc = &hport->config.intf[intf].ep[i].ep_desc; - ep_cfg.ep_addr = ep_desc->bEndpointAddress; - ep_cfg.ep_type = ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK; - ep_cfg.ep_mps = ep_desc->wMaxPacketSize & USB_MAXPACKETSIZE_MASK; - ep_cfg.ep_interval = ep_desc->bInterval; - ep_cfg.hport = hport; + for (uint8_t i = 0; i < hport->config.intf[intf].altsetting[0].intf_desc.bNumEndpoints; i++) { + ep_desc = &hport->config.intf[intf].altsetting[0].ep[i].ep_desc; if (ep_desc->bEndpointAddress & 0x80) { - usbh_pipe_alloc(&hid_class->intin, &ep_cfg); + usbh_hport_activate_epx(&hid_class->intin, hport, ep_desc); } else { - usbh_pipe_alloc(&hid_class->intout, &ep_cfg); + usbh_hport_activate_epx(&hid_class->intout, hport, ep_desc); } - - USB_LOG_INFO("Ep=%02x Attr=%02u Mps=%d Interval=%02u\r\n", - ep_desc->bEndpointAddress, - ep_desc->bmAttributes, - ep_desc->wMaxPacketSize, - ep_desc->bInterval); } snprintf(hport->config.intf[intf].devname, CONFIG_USBHOST_DEV_NAMELEN, DEV_FORMAT, hid_class->minor); diff --git a/class/hub/usbh_hub.c b/class/hub/usbh_hub.c index 3efdc195..892a3eef 100644 --- a/class/hub/usbh_hub.c +++ b/class/hub/usbh_hub.c @@ -26,7 +26,7 @@ usb_osal_thread_t hub_thread; USB_NOCACHE_RAM_SECTION struct usbh_hub roothub; struct usbh_hubport roothub_parent_port; -USB_NOCACHE_RAM_SECTION struct usbh_hub exthub[CONFIG_USBHOST_EXTHUB_NUM]; +USB_NOCACHE_RAM_SECTION struct usbh_hub exthub[CONFIG_USBHOST_MAX_EXTHUBS]; extern int usbh_hport_activate_ep0(struct usbh_hubport *hport); extern int usbh_hport_deactivate_ep0(struct usbh_hubport *hport); @@ -261,14 +261,13 @@ static void hub_int_complete_callback(void *arg, int nbytes) static int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf) { - struct usbh_endpoint_cfg ep_cfg = { 0 }; struct usb_endpoint_descriptor *ep_desc; struct hub_port_status port_status; int ret; int index; index = usbh_hub_devno_alloc(); - if (index > (CONFIG_USBHOST_EXTHUB_NUM + EXTHUB_FIRST_INDEX)) { + if (index > (CONFIG_USBHOST_MAX_EXTHUBS + EXTHUB_FIRST_INDEX)) { return -ENOMEM; } @@ -293,19 +292,9 @@ static int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf) hub->child[port].parent = hub; } - ep_desc = &hport->config.intf[intf].ep[0].ep_desc; - ep_cfg.ep_addr = ep_desc->bEndpointAddress; - ep_cfg.ep_type = ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK; - ep_cfg.ep_mps = ep_desc->wMaxPacketSize & USB_MAXPACKETSIZE_MASK; - ep_cfg.ep_interval = ep_desc->bInterval; - ep_cfg.hport = hport; + ep_desc = &hport->config.intf[intf].altsetting[0].ep[0].ep_desc; if (ep_desc->bEndpointAddress & 0x80) { - usbh_pipe_alloc(&hub->intin, &ep_cfg); - USB_LOG_INFO("Ep=%02x Attr=%02u Mps=%d Interval=%02u\r\n", - ep_desc->bEndpointAddress, - ep_desc->bmAttributes, - ep_desc->wMaxPacketSize, - ep_desc->bInterval); + usbh_hport_activate_epx(&hub->intin, hport, ep_desc); } else { return -1; } @@ -382,7 +371,7 @@ static void usbh_roothub_register(void) roothub.is_roothub = true; roothub.parent = &roothub_parent_port; roothub.hub_addr = roothub_parent_port.dev_addr; - roothub.hub_desc.bNbrPorts = CONFIG_USBHOST_RHPORTS; + roothub.hub_desc.bNbrPorts = CONFIG_USBHOST_MAX_RHPORTS; usbh_hub_register(&roothub); } @@ -542,7 +531,7 @@ static void usbh_hub_events(struct usbh_hub *hub) USB_LOG_INFO("Device on Hub %u, Port %u disconnected\r\n", hub->index, port + 1); usbh_device_unmount_done_callback(child); - memset(child, 0, sizeof(struct usbh_hubport)); + child->config.config_desc.bNumInterfaces = 0; } } } @@ -553,7 +542,6 @@ static void usbh_hub_thread(void *argument) size_t flags; int ret = 0; - usbh_roothub_register(); usb_hc_init(); while (1) { ret = usb_osal_sem_take(hub_event_wait, 0xffffffff); @@ -589,6 +577,8 @@ void usbh_hub_unregister(struct usbh_hub *hub) int usbh_hub_initialize(void) { + usbh_roothub_register(); + hub_event_wait = usb_osal_sem_create(0); if (hub_event_wait == NULL) { return -1; diff --git a/class/msc/usbh_msc.c b/class/msc/usbh_msc.c index f6fb3942..54abe2e4 100644 --- a/class/msc/usbh_msc.c +++ b/class/msc/usbh_msc.c @@ -305,7 +305,6 @@ int usbh_msc_scsi_read10(struct usbh_msc *msc_class, uint32_t start_sector, cons static int usbh_msc_connect(struct usbh_hubport *hport, uint8_t intf) { - struct usbh_endpoint_cfg ep_cfg = { 0 }; struct usb_endpoint_descriptor *ep_desc; int ret; @@ -329,25 +328,13 @@ static int usbh_msc_connect(struct usbh_hubport *hport, uint8_t intf) USB_LOG_INFO("Get max LUN:%u\r\n", g_msc_buf[0] + 1); - for (uint8_t i = 0; i < hport->config.intf[intf].intf_desc.bNumEndpoints; i++) { - ep_desc = &hport->config.intf[intf].ep[i].ep_desc; - - ep_cfg.ep_addr = ep_desc->bEndpointAddress; - ep_cfg.ep_type = ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK; - ep_cfg.ep_mps = ep_desc->wMaxPacketSize & USB_MAXPACKETSIZE_MASK; - ep_cfg.ep_interval = ep_desc->bInterval; - ep_cfg.hport = hport; + for (uint8_t i = 0; i < hport->config.intf[intf].altsetting[0].intf_desc.bNumEndpoints; i++) { + ep_desc = &hport->config.intf[intf].altsetting[0].ep[i].ep_desc; if (ep_desc->bEndpointAddress & 0x80) { - usbh_pipe_alloc(&msc_class->bulkin, &ep_cfg); + usbh_hport_activate_epx(&msc_class->bulkin, hport, ep_desc); } else { - usbh_pipe_alloc(&msc_class->bulkout, &ep_cfg); + usbh_hport_activate_epx(&msc_class->bulkout, hport, ep_desc); } - - USB_LOG_INFO("Ep=%02x Attr=%02u Mps=%d Interval=%02u\r\n", - ep_desc->bEndpointAddress, - ep_desc->bmAttributes, - ep_desc->wMaxPacketSize, - ep_desc->bInterval); } ret = usbh_msc_scsi_testunitready(msc_class); diff --git a/class/wireless/usbh_rndis.c b/class/wireless/usbh_rndis.c index cffe15a9..035a16d6 100644 --- a/class/wireless/usbh_rndis.c +++ b/class/wireless/usbh_rndis.c @@ -228,7 +228,7 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf) hport->config.intf[intf + 1].priv = NULL; #ifdef CONFIG_USBHOST_RNDIS_NOTIFY - ep_desc = &hport->config.intf[intf].ep[0].ep_desc; + ep_desc = &hport->config.intf[intf].altsetting[0].ep[0].ep_desc; ep_cfg.ep_addr = ep_desc->bEndpointAddress; ep_cfg.ep_type = ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK; ep_cfg.ep_mps = ep_desc->wMaxPacketSize & USB_MAXPACKETSIZE_MASK;; @@ -237,8 +237,8 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf) usbh_pipe_alloc(&rndis_class->intin, &ep_cfg); #endif - for (uint8_t i = 0; i < hport->config.intf[intf + 1].intf_desc.bNumEndpoints; i++) { - ep_desc = &hport->config.intf[intf + 1].ep[i].ep_desc; + for (uint8_t i = 0; i < hport->config.intf[intf + 1].altsetting[0].intf_desc.bNumEndpoints; i++) { + ep_desc = &hport->config.intf[intf + 1].altsetting[0].ep[i].ep_desc; ep_cfg.ep_addr = ep_desc->bEndpointAddress; ep_cfg.ep_type = ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK; diff --git a/core/usbh_core.c b/core/usbh_core.c index d2b246fb..b03cf632 100644 --- a/core/usbh_core.c +++ b/core/usbh_core.c @@ -169,10 +169,10 @@ static int parse_config_descriptor(struct usbh_hubport *hport, struct usb_config { struct usb_interface_descriptor *intf_desc; struct usb_endpoint_descriptor *ep_desc; - uint8_t cur_alt_setting; + uint8_t cur_alt_setting = 0xff; uint8_t cur_iface = 0xff; uint8_t cur_ep = 0xff; - uint8_t cur_ep_num; + uint8_t cur_ep_num = 0xff; uint32_t desc_len = 0; uint8_t *p; @@ -211,6 +211,8 @@ static int parse_config_descriptor(struct usbh_hubport *hport, struct usb_config p += USB_SIZEOF_CONFIG_DESC; desc_len = USB_SIZEOF_CONFIG_DESC; + memset(hport->config.intf, 0, sizeof(struct usbh_interface) * CONFIG_USBHOST_MAX_INTERFACES); + while (p[DESC_bLength] && (desc_len <= length)) { switch (p[DESC_bDescriptorType]) { case USB_DESCRIPTOR_TYPE_INTERFACE: @@ -219,14 +221,15 @@ static int parse_config_descriptor(struct usbh_hubport *hport, struct usb_config cur_alt_setting = intf_desc->bAlternateSetting; cur_ep_num = intf_desc->bNumEndpoints; cur_ep = 0; - if (cur_iface > CONFIG_USBHOST_INTF_NUM) { + if (cur_iface > CONFIG_USBHOST_MAX_INTERFACES) { return -ENOMEM; } - if (cur_ep_num > CONFIG_USBHOST_EP_NUM) { + if (cur_alt_setting > CONFIG_USBHOST_MAX_INTF_ALTSETTINGS) { + return -ENOMEM; + } + if (cur_ep_num > CONFIG_USBHOST_MAX_ENDPOINTS) { return -ENOMEM; } - - memset(&hport->config.intf[cur_iface], 0, sizeof(struct usbh_interface)); #if 0 USB_LOG_DBG("Interface Descriptor:\r\n"); USB_LOG_DBG("bLength: 0x%02x \r\n", intf_desc->bLength); @@ -239,15 +242,12 @@ static int parse_config_descriptor(struct usbh_hubport *hport, struct usb_config USB_LOG_DBG("bInterfaceProtocol: 0x%02x \r\n", intf_desc->bInterfaceProtocol); USB_LOG_DBG("iInterface: 0x%02x \r\n", intf_desc->iInterface); #endif - memcpy(&hport->config.intf[cur_iface].intf_desc, intf_desc, 9); - if (cur_alt_setting == 1) { - USB_LOG_WRN("Altsetting enable, the previous intf info will be overwrited\r\n"); - } + memcpy(&hport->config.intf[cur_iface].altsetting[cur_alt_setting].intf_desc, intf_desc, 9); + hport->config.intf[cur_iface].altsetting_num = cur_alt_setting + 1; break; case USB_DESCRIPTOR_TYPE_ENDPOINT: ep_desc = (struct usb_endpoint_descriptor *)p; - memset(&hport->config.intf[cur_iface].ep[cur_ep], 0, sizeof(struct usbh_endpoint)); - memcpy(&hport->config.intf[cur_iface].ep[cur_ep].ep_desc, ep_desc, 7); + memcpy(&hport->config.intf[cur_iface].altsetting[cur_alt_setting].ep[cur_ep].ep_desc, ep_desc, 7); cur_ep++; break; @@ -308,25 +308,27 @@ static void usbh_print_hubport_info(struct usbh_hubport *hport) USB_LOG_RAW("bMaxPower: 0x%02x \r\n", hport->config.config_desc.bMaxPower); for (uint8_t i = 0; i < hport->config.config_desc.bNumInterfaces; i++) { - USB_LOG_RAW("Interface Descriptor:\r\n"); - USB_LOG_RAW("bLength: 0x%02x \r\n", hport->config.intf[i].intf_desc.bLength); - USB_LOG_RAW("bDescriptorType: 0x%02x \r\n", hport->config.intf[i].intf_desc.bDescriptorType); - USB_LOG_RAW("bInterfaceNumber: 0x%02x \r\n", hport->config.intf[i].intf_desc.bInterfaceNumber); - USB_LOG_RAW("bAlternateSetting: 0x%02x \r\n", hport->config.intf[i].intf_desc.bAlternateSetting); - USB_LOG_RAW("bNumEndpoints: 0x%02x \r\n", hport->config.intf[i].intf_desc.bNumEndpoints); - USB_LOG_RAW("bInterfaceClass: 0x%02x \r\n", hport->config.intf[i].intf_desc.bInterfaceClass); - USB_LOG_RAW("bInterfaceSubClass: 0x%02x \r\n", hport->config.intf[i].intf_desc.bInterfaceSubClass); - USB_LOG_RAW("bInterfaceProtocol: 0x%02x \r\n", hport->config.intf[i].intf_desc.bInterfaceProtocol); - USB_LOG_RAW("iInterface: 0x%02x \r\n", hport->config.intf[i].intf_desc.iInterface); + for (uint8_t j = 0; j < hport->config.intf[i].altsetting_num; j++) { + USB_LOG_RAW("Interface Descriptor:\r\n"); + USB_LOG_RAW("bLength: 0x%02x \r\n", hport->config.intf[i].altsetting[j].intf_desc.bLength); + USB_LOG_RAW("bDescriptorType: 0x%02x \r\n", hport->config.intf[i].altsetting[j].intf_desc.bDescriptorType); + USB_LOG_RAW("bInterfaceNumber: 0x%02x \r\n", hport->config.intf[i].altsetting[j].intf_desc.bInterfaceNumber); + USB_LOG_RAW("bAlternateSetting: 0x%02x \r\n", hport->config.intf[i].altsetting[j].intf_desc.bAlternateSetting); + USB_LOG_RAW("bNumEndpoints: 0x%02x \r\n", hport->config.intf[i].altsetting[j].intf_desc.bNumEndpoints); + USB_LOG_RAW("bInterfaceClass: 0x%02x \r\n", hport->config.intf[i].altsetting[j].intf_desc.bInterfaceClass); + USB_LOG_RAW("bInterfaceSubClass: 0x%02x \r\n", hport->config.intf[i].altsetting[j].intf_desc.bInterfaceSubClass); + USB_LOG_RAW("bInterfaceProtocol: 0x%02x \r\n", hport->config.intf[i].altsetting[j].intf_desc.bInterfaceProtocol); + USB_LOG_RAW("iInterface: 0x%02x \r\n", hport->config.intf[i].altsetting[j].intf_desc.iInterface); - for (uint8_t j = 0; j < hport->config.intf[i].intf_desc.bNumEndpoints; j++) { - USB_LOG_RAW("Endpoint Descriptor:\r\n"); - USB_LOG_RAW("bLength: 0x%02x \r\n", hport->config.intf[i].ep[j].ep_desc.bLength); - USB_LOG_RAW("bDescriptorType: 0x%02x \r\n", hport->config.intf[i].ep[j].ep_desc.bDescriptorType); - USB_LOG_RAW("bEndpointAddress: 0x%02x \r\n", hport->config.intf[i].ep[j].ep_desc.bEndpointAddress); - USB_LOG_RAW("bmAttributes: 0x%02x \r\n", hport->config.intf[i].ep[j].ep_desc.bmAttributes); - USB_LOG_RAW("wMaxPacketSize: 0x%04x \r\n", hport->config.intf[i].ep[j].ep_desc.wMaxPacketSize); - USB_LOG_RAW("bInterval: 0x%02x \r\n", hport->config.intf[i].ep[j].ep_desc.bInterval); + for (uint8_t k = 0; k < hport->config.intf[i].altsetting[j].intf_desc.bNumEndpoints; k++) { + USB_LOG_RAW("Endpoint Descriptor:\r\n"); + USB_LOG_RAW("bLength: 0x%02x \r\n", hport->config.intf[i].altsetting[j].ep[k].ep_desc.bLength); + USB_LOG_RAW("bDescriptorType: 0x%02x \r\n", hport->config.intf[i].altsetting[j].ep[k].ep_desc.bDescriptorType); + USB_LOG_RAW("bEndpointAddress: 0x%02x \r\n", hport->config.intf[i].altsetting[j].ep[k].ep_desc.bEndpointAddress); + USB_LOG_RAW("bmAttributes: 0x%02x \r\n", hport->config.intf[i].altsetting[j].ep[k].ep_desc.bmAttributes); + USB_LOG_RAW("wMaxPacketSize: 0x%04x \r\n", hport->config.intf[i].altsetting[j].ep[k].ep_desc.wMaxPacketSize); + USB_LOG_RAW("bInterval: 0x%02x \r\n", hport->config.intf[i].altsetting[j].ep[k].ep_desc.bInterval); + } } } } @@ -359,6 +361,27 @@ int usbh_hport_deactivate_ep0(struct usbh_hubport *hport) return 0; } +int usbh_hport_activate_epx(usbh_pipe_t pipe, struct usbh_hubport *hport, struct usb_endpoint_descriptor *ep_desc) +{ + struct usbh_endpoint_cfg ep_cfg = { 0 }; + + ep_cfg.ep_addr = ep_desc->bEndpointAddress; + ep_cfg.ep_type = ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK; + ep_cfg.ep_mps = ep_desc->wMaxPacketSize & USB_MAXPACKETSIZE_MASK; + ep_cfg.ep_interval = ep_desc->bInterval; + ep_cfg.mult = (ep_desc->wMaxPacketSize & USB_MAXPACKETSIZE_ADDITIONAL_TRANSCATION_MASK) >> USB_MAXPACKETSIZE_ADDITIONAL_TRANSCATION_SHIFT; + ep_cfg.hport = hport; + + USB_LOG_INFO("Ep=%02x Attr=%02u Mps=%d Interval=%02u Mult=%02u\r\n", + ep_cfg.ep_addr, + ep_desc->bmAttributes, + ep_cfg.ep_mps, + ep_cfg.ep_interval, + ep_cfg.mult); + + return usbh_pipe_alloc(pipe, &ep_cfg); +} + int usbh_enumerate(struct usbh_hubport *hport) { struct usb_interface_descriptor *intf_desc; @@ -561,7 +584,7 @@ int usbh_enumerate(struct usbh_hubport *hport) USB_LOG_INFO("Enumeration success, start loading class driver\r\n"); /*search supported class driver*/ for (uint8_t i = 0; i < hport->config.config_desc.bNumInterfaces; i++) { - intf_desc = &hport->config.intf[i].intf_desc; + intf_desc = &hport->config.intf[i].altsetting[0].intf_desc; struct usbh_class_driver *class_driver = (struct usbh_class_driver *)usbh_find_class_driver(intf_desc->bInterfaceClass, intf_desc->bInterfaceSubClass, intf_desc->bInterfaceProtocol, hport->device_desc.idVendor, hport->device_desc.idProduct); diff --git a/core/usbh_core.h b/core/usbh_core.h index 65856b0c..8d9ee453 100644 --- a/core/usbh_core.h +++ b/core/usbh_core.h @@ -93,6 +93,23 @@ static inline void usbh_int_urb_fill(struct usbh_urb *urb, urb->arg = arg; } +static inline void usbh_iso_urb_fill(struct usbh_urb *urb, + usbh_pipe_t pipe, + uint8_t *transfer_buffer, + uint32_t transfer_buffer_length, + uint32_t timeout, + usbh_complete_callback_t complete, + void *arg) +{ + urb->pipe = pipe; + urb->setup = NULL; + urb->transfer_buffer = transfer_buffer; + urb->transfer_buffer_length = transfer_buffer_length; + urb->timeout = timeout; + urb->complete = complete; + urb->arg = arg; +} + struct usbh_class_info { uint8_t match_flags; /* Used for product specific matches; range is inclusive */ uint8_t class; /* Base device class code */ @@ -114,9 +131,14 @@ struct usbh_endpoint { struct usb_endpoint_descriptor ep_desc; }; -struct usbh_interface { +struct usbh_interface_altsetting { struct usb_interface_descriptor intf_desc; - struct usbh_endpoint ep[CONFIG_USBHOST_EP_NUM]; + struct usbh_endpoint ep[CONFIG_USBHOST_MAX_ENDPOINTS]; +}; + +struct usbh_interface { + struct usbh_interface_altsetting altsetting[CONFIG_USBHOST_MAX_INTF_ALTSETTINGS]; + uint8_t altsetting_num; char devname[CONFIG_USBHOST_DEV_NAMELEN]; struct usbh_class_driver *class_driver; void *priv; @@ -124,7 +146,7 @@ struct usbh_interface { struct usbh_configuration { struct usb_configuration_descriptor config_desc; - struct usbh_interface intf[CONFIG_USBHOST_INTF_NUM]; + struct usbh_interface intf[CONFIG_USBHOST_MAX_INTERFACES]; }; struct usbh_hubport { @@ -155,11 +177,13 @@ struct usbh_hub { USB_MEM_ALIGNX uint8_t int_buffer[1]; struct usbh_urb inturb; struct usb_hub_descriptor hub_desc; - struct usbh_hubport child[CONFIG_USBHOST_EHPORTS]; + struct usbh_hubport child[CONFIG_USBHOST_MAX_EHPORTS]; struct usbh_hubport *parent; usb_slist_t hub_event_list; }; +int usbh_hport_activate_epx(usbh_pipe_t pipe, struct usbh_hubport *hport, struct usb_endpoint_descriptor *ep_desc); + /* usb host transfer wrapper */ /** diff --git a/demo/es32/usb_device/ES32F369x/Inc/usb_config.h b/demo/es32/usb_device/ES32F369x/Inc/usb_config.h index 9573485f..d7fc7270 100644 --- a/demo/es32/usb_device/ES32F369x/Inc/usb_config.h +++ b/demo/es32/usb_device/ES32F369x/Inc/usb_config.h @@ -79,10 +79,12 @@ /* ================ USB HOST Stack Configuration ================== */ -#define CONFIG_USBHOST_RHPORTS 1 -#define CONFIG_USBHOST_EHPORTS 4 -#define CONFIG_USBHOST_INTF_NUM 6 -#define CONFIG_USBHOST_EP_NUM 4 +#define CONFIG_USBHOST_MAX_RHPORTS 1 +#define CONFIG_USBHOST_MAX_EXTHUBS 1 +#define CONFIG_USBHOST_MAX_EHPORTS 4 +#define CONFIG_USBHOST_MAX_INTERFACES 6 +#define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 1 +#define CONFIG_USBHOST_MAX_ENDPOINTS 4 #define CONFIG_USBHOST_DEV_NAMELEN 16 diff --git a/demo/es32/usb_host/ES32F369x/Inc/usb_config.h b/demo/es32/usb_host/ES32F369x/Inc/usb_config.h index fc84dcaf..078010e6 100644 --- a/demo/es32/usb_host/ES32F369x/Inc/usb_config.h +++ b/demo/es32/usb_host/ES32F369x/Inc/usb_config.h @@ -79,11 +79,12 @@ /* ================ USB HOST Stack Configuration ================== */ -#define CONFIG_USBHOST_RHPORTS 1 -#define CONFIG_USBHOST_EXTHUB_NUM 1 -#define CONFIG_USBHOST_EHPORTS 4 -#define CONFIG_USBHOST_INTF_NUM 6 -#define CONFIG_USBHOST_EP_NUM 4 +#define CONFIG_USBHOST_MAX_RHPORTS 1 +#define CONFIG_USBHOST_MAX_EXTHUBS 1 +#define CONFIG_USBHOST_MAX_EHPORTS 4 +#define CONFIG_USBHOST_MAX_INTERFACES 6 +#define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 1 +#define CONFIG_USBHOST_MAX_ENDPOINTS 4 #define CONFIG_USBHOST_DEV_NAMELEN 16 diff --git a/demo/hpm/usb_device/src/usb_config.h b/demo/hpm/usb_device/src/usb_config.h index 430b3cb4..ff2ec878 100644 --- a/demo/hpm/usb_device/src/usb_config.h +++ b/demo/hpm/usb_device/src/usb_config.h @@ -79,11 +79,12 @@ /* ================ USB HOST Stack Configuration ================== */ -#define CONFIG_USBHOST_RHPORTS 1 -#define CONFIG_USBHOST_EXTHUB_NUM 1 -#define CONFIG_USBHOST_EHPORTS 4 -#define CONFIG_USBHOST_INTF_NUM 6 -#define CONFIG_USBHOST_EP_NUM 4 +#define CONFIG_USBHOST_MAX_RHPORTS 1 +#define CONFIG_USBHOST_MAX_EXTHUBS 1 +#define CONFIG_USBHOST_MAX_EHPORTS 4 +#define CONFIG_USBHOST_MAX_INTERFACES 6 +#define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 1 +#define CONFIG_USBHOST_MAX_ENDPOINTS 4 #define CONFIG_USBHOST_DEV_NAMELEN 16 diff --git a/demo/hpm/usb_host/src/usb_config.h b/demo/hpm/usb_host/src/usb_config.h index 430b3cb4..ff2ec878 100644 --- a/demo/hpm/usb_host/src/usb_config.h +++ b/demo/hpm/usb_host/src/usb_config.h @@ -79,11 +79,12 @@ /* ================ USB HOST Stack Configuration ================== */ -#define CONFIG_USBHOST_RHPORTS 1 -#define CONFIG_USBHOST_EXTHUB_NUM 1 -#define CONFIG_USBHOST_EHPORTS 4 -#define CONFIG_USBHOST_INTF_NUM 6 -#define CONFIG_USBHOST_EP_NUM 4 +#define CONFIG_USBHOST_MAX_RHPORTS 1 +#define CONFIG_USBHOST_MAX_EXTHUBS 1 +#define CONFIG_USBHOST_MAX_EHPORTS 4 +#define CONFIG_USBHOST_MAX_INTERFACES 6 +#define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 1 +#define CONFIG_USBHOST_MAX_ENDPOINTS 4 #define CONFIG_USBHOST_DEV_NAMELEN 16 diff --git a/demo/stm32/usb_device/stm32f103c8t6/Core/Inc/usb_config.h b/demo/stm32/usb_device/stm32f103c8t6/Core/Inc/usb_config.h index 9573485f..d7fc7270 100644 --- a/demo/stm32/usb_device/stm32f103c8t6/Core/Inc/usb_config.h +++ b/demo/stm32/usb_device/stm32f103c8t6/Core/Inc/usb_config.h @@ -79,10 +79,12 @@ /* ================ USB HOST Stack Configuration ================== */ -#define CONFIG_USBHOST_RHPORTS 1 -#define CONFIG_USBHOST_EHPORTS 4 -#define CONFIG_USBHOST_INTF_NUM 6 -#define CONFIG_USBHOST_EP_NUM 4 +#define CONFIG_USBHOST_MAX_RHPORTS 1 +#define CONFIG_USBHOST_MAX_EXTHUBS 1 +#define CONFIG_USBHOST_MAX_EHPORTS 4 +#define CONFIG_USBHOST_MAX_INTERFACES 6 +#define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 1 +#define CONFIG_USBHOST_MAX_ENDPOINTS 4 #define CONFIG_USBHOST_DEV_NAMELEN 16 diff --git a/demo/stm32/usb_device/stm32f429igt6/Core/Inc/usb_config.h b/demo/stm32/usb_device/stm32f429igt6/Core/Inc/usb_config.h index 9573485f..d7fc7270 100644 --- a/demo/stm32/usb_device/stm32f429igt6/Core/Inc/usb_config.h +++ b/demo/stm32/usb_device/stm32f429igt6/Core/Inc/usb_config.h @@ -79,10 +79,12 @@ /* ================ USB HOST Stack Configuration ================== */ -#define CONFIG_USBHOST_RHPORTS 1 -#define CONFIG_USBHOST_EHPORTS 4 -#define CONFIG_USBHOST_INTF_NUM 6 -#define CONFIG_USBHOST_EP_NUM 4 +#define CONFIG_USBHOST_MAX_RHPORTS 1 +#define CONFIG_USBHOST_MAX_EXTHUBS 1 +#define CONFIG_USBHOST_MAX_EHPORTS 4 +#define CONFIG_USBHOST_MAX_INTERFACES 6 +#define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 1 +#define CONFIG_USBHOST_MAX_ENDPOINTS 4 #define CONFIG_USBHOST_DEV_NAMELEN 16 diff --git a/demo/stm32/usb_device/stm32h743vbt6/Core/Inc/usb_config.h b/demo/stm32/usb_device/stm32h743vbt6/Core/Inc/usb_config.h index 9573485f..d7fc7270 100644 --- a/demo/stm32/usb_device/stm32h743vbt6/Core/Inc/usb_config.h +++ b/demo/stm32/usb_device/stm32h743vbt6/Core/Inc/usb_config.h @@ -79,10 +79,12 @@ /* ================ USB HOST Stack Configuration ================== */ -#define CONFIG_USBHOST_RHPORTS 1 -#define CONFIG_USBHOST_EHPORTS 4 -#define CONFIG_USBHOST_INTF_NUM 6 -#define CONFIG_USBHOST_EP_NUM 4 +#define CONFIG_USBHOST_MAX_RHPORTS 1 +#define CONFIG_USBHOST_MAX_EXTHUBS 1 +#define CONFIG_USBHOST_MAX_EHPORTS 4 +#define CONFIG_USBHOST_MAX_INTERFACES 6 +#define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 1 +#define CONFIG_USBHOST_MAX_ENDPOINTS 4 #define CONFIG_USBHOST_DEV_NAMELEN 16 diff --git a/demo/stm32/usb_host/stm32f429igt6/Core/Inc/usb_config.h b/demo/stm32/usb_host/stm32f429igt6/Core/Inc/usb_config.h index bee802f4..796311dd 100644 --- a/demo/stm32/usb_host/stm32f429igt6/Core/Inc/usb_config.h +++ b/demo/stm32/usb_host/stm32f429igt6/Core/Inc/usb_config.h @@ -79,11 +79,12 @@ /* ================ USB HOST Stack Configuration ================== */ -#define CONFIG_USBHOST_RHPORTS 1 -#define CONFIG_USBHOST_EXTHUB_NUM 1 -#define CONFIG_USBHOST_EHPORTS 4 -#define CONFIG_USBHOST_INTF_NUM 6 -#define CONFIG_USBHOST_EP_NUM 4 +#define CONFIG_USBHOST_MAX_RHPORTS 1 +#define CONFIG_USBHOST_MAX_EXTHUBS 1 +#define CONFIG_USBHOST_MAX_EHPORTS 4 +#define CONFIG_USBHOST_MAX_INTERFACES 6 +#define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 1 +#define CONFIG_USBHOST_MAX_ENDPOINTS 4 #define CONFIG_USBHOST_DEV_NAMELEN 16 diff --git a/demo/stm32/usb_host/stm32h743xih6/Core/Inc/usb_config.h b/demo/stm32/usb_host/stm32h743xih6/Core/Inc/usb_config.h index bee802f4..796311dd 100644 --- a/demo/stm32/usb_host/stm32h743xih6/Core/Inc/usb_config.h +++ b/demo/stm32/usb_host/stm32h743xih6/Core/Inc/usb_config.h @@ -79,11 +79,12 @@ /* ================ USB HOST Stack Configuration ================== */ -#define CONFIG_USBHOST_RHPORTS 1 -#define CONFIG_USBHOST_EXTHUB_NUM 1 -#define CONFIG_USBHOST_EHPORTS 4 -#define CONFIG_USBHOST_INTF_NUM 6 -#define CONFIG_USBHOST_EP_NUM 4 +#define CONFIG_USBHOST_MAX_RHPORTS 1 +#define CONFIG_USBHOST_MAX_EXTHUBS 1 +#define CONFIG_USBHOST_MAX_EHPORTS 4 +#define CONFIG_USBHOST_MAX_INTERFACES 6 +#define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 1 +#define CONFIG_USBHOST_MAX_ENDPOINTS 4 #define CONFIG_USBHOST_DEV_NAMELEN 16 diff --git a/port/dwc2/usb_hc_dwc2.c b/port/dwc2/usb_hc_dwc2.c index 24d9da21..a9c8364e 100644 --- a/port/dwc2/usb_hc_dwc2.c +++ b/port/dwc2/usb_hc_dwc2.c @@ -540,7 +540,7 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf) uint8_t port; uint32_t status; - nports = CONFIG_USBHOST_RHPORTS; + nports = CONFIG_USBHOST_MAX_RHPORTS; port = setup->wIndex; if (setup->bmRequestType & USB_REQUEST_RECIPIENT_DEVICE) { switch (setup->bRequest) { diff --git a/port/musb/usb_hc_musb.c b/port/musb/usb_hc_musb.c index 32afeb3b..5318eac8 100644 --- a/port/musb/usb_hc_musb.c +++ b/port/musb/usb_hc_musb.c @@ -441,7 +441,7 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf) uint8_t port; uint32_t status; - nports = CONFIG_USBHOST_RHPORTS; + nports = CONFIG_USBHOST_MAX_RHPORTS; port = setup->wIndex; if (setup->bmRequestType & USB_REQUEST_RECIPIENT_DEVICE) { switch (setup->bRequest) {