add interface altsetting struct

This commit is contained in:
sakumisu
2022-09-14 19:50:06 +08:00
parent 3d0b58bb4e
commit b25b0f0b6c
19 changed files with 168 additions and 155 deletions

View File

@@ -79,11 +79,12 @@
/* ================ USB HOST Stack Configuration ================== */ /* ================ USB HOST Stack Configuration ================== */
#define CONFIG_USBHOST_RHPORTS 1 #define CONFIG_USBHOST_MAX_RHPORTS 1
#define CONFIG_USBHOST_EXTHUB_NUM 1 #define CONFIG_USBHOST_MAX_EXTHUBS 1
#define CONFIG_USBHOST_EHPORTS 4 #define CONFIG_USBHOST_MAX_EHPORTS 4
#define CONFIG_USBHOST_INTF_NUM 6 #define CONFIG_USBHOST_MAX_INTERFACES 6
#define CONFIG_USBHOST_EP_NUM 4 #define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 1
#define CONFIG_USBHOST_MAX_ENDPOINTS 4
#define CONFIG_USBHOST_DEV_NAMELEN 16 #define CONFIG_USBHOST_DEV_NAMELEN 16

View File

@@ -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) 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; struct usb_endpoint_descriptor *ep_desc;
int ret; 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 #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_addr = ep_desc->bEndpointAddress;
ep_cfg.ep_type = ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK; ep_cfg.ep_type = ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK;
ep_cfg.ep_mps = ep_desc->wMaxPacketSize; 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); usbh_pipe_alloc(&cdc_acm_class->intin, &ep_cfg);
#endif #endif
for (uint8_t i = 0; i < hport->config.intf[intf + 1].intf_desc.bNumEndpoints; i++) { for (uint8_t i = 0; i < hport->config.intf[intf + 1].altsetting[0].intf_desc.bNumEndpoints; i++) {
ep_desc = &hport->config.intf[intf + 1].ep[i].ep_desc; 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) { 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 { } 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); 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; struct usbh_cdc_acm *cdc_acm_class = (struct usbh_cdc_acm *)hport->config.intf[intf].priv;
if (cdc_acm_class) { if (cdc_acm_class) {
usbh_cdc_acm_devno_free(cdc_acm_class); usbh_cdc_acm_devno_free(cdc_acm_class);
if (cdc_acm_class->bulkin) { if (cdc_acm_class->bulkin) {

View File

@@ -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) int usbh_hid_connect(struct usbh_hubport *hport, uint8_t intf)
{ {
struct usbh_endpoint_cfg ep_cfg = { 0 };
struct usb_endpoint_descriptor *ep_desc; struct usb_endpoint_descriptor *ep_desc;
int ret; int ret;
@@ -139,24 +138,13 @@ int usbh_hid_connect(struct usbh_hubport *hport, uint8_t intf)
return ret; return ret;
} }
for (uint8_t i = 0; i < hport->config.intf[intf].intf_desc.bNumEndpoints; i++) { for (uint8_t i = 0; i < hport->config.intf[intf].altsetting[0].intf_desc.bNumEndpoints; i++) {
ep_desc = &hport->config.intf[intf].ep[i].ep_desc; ep_desc = &hport->config.intf[intf].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) { if (ep_desc->bEndpointAddress & 0x80) {
usbh_pipe_alloc(&hid_class->intin, &ep_cfg); usbh_hport_activate_epx(&hid_class->intin, hport, ep_desc);
} else { } 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); snprintf(hport->config.intf[intf].devname, CONFIG_USBHOST_DEV_NAMELEN, DEV_FORMAT, hid_class->minor);

View File

@@ -26,7 +26,7 @@ usb_osal_thread_t hub_thread;
USB_NOCACHE_RAM_SECTION struct usbh_hub roothub; USB_NOCACHE_RAM_SECTION struct usbh_hub roothub;
struct usbh_hubport roothub_parent_port; 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_activate_ep0(struct usbh_hubport *hport);
extern int usbh_hport_deactivate_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) 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 usb_endpoint_descriptor *ep_desc;
struct hub_port_status port_status; struct hub_port_status port_status;
int ret; int ret;
int index; int index;
index = usbh_hub_devno_alloc(); 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; return -ENOMEM;
} }
@@ -293,19 +292,9 @@ static int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf)
hub->child[port].parent = hub; hub->child[port].parent = hub;
} }
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;
ep_cfg.ep_interval = ep_desc->bInterval;
ep_cfg.hport = hport;
if (ep_desc->bEndpointAddress & 0x80) { if (ep_desc->bEndpointAddress & 0x80) {
usbh_pipe_alloc(&hub->intin, &ep_cfg); usbh_hport_activate_epx(&hub->intin, 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);
} else { } else {
return -1; return -1;
} }
@@ -382,7 +371,7 @@ static void usbh_roothub_register(void)
roothub.is_roothub = true; roothub.is_roothub = true;
roothub.parent = &roothub_parent_port; roothub.parent = &roothub_parent_port;
roothub.hub_addr = roothub_parent_port.dev_addr; 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); 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); USB_LOG_INFO("Device on Hub %u, Port %u disconnected\r\n", hub->index, port + 1);
usbh_device_unmount_done_callback(child); 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; size_t flags;
int ret = 0; int ret = 0;
usbh_roothub_register();
usb_hc_init(); usb_hc_init();
while (1) { while (1) {
ret = usb_osal_sem_take(hub_event_wait, 0xffffffff); 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) int usbh_hub_initialize(void)
{ {
usbh_roothub_register();
hub_event_wait = usb_osal_sem_create(0); hub_event_wait = usb_osal_sem_create(0);
if (hub_event_wait == NULL) { if (hub_event_wait == NULL) {
return -1; return -1;

View File

@@ -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) 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; struct usb_endpoint_descriptor *ep_desc;
int ret; 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); 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++) { for (uint8_t i = 0; i < hport->config.intf[intf].altsetting[0].intf_desc.bNumEndpoints; i++) {
ep_desc = &hport->config.intf[intf].ep[i].ep_desc; ep_desc = &hport->config.intf[intf].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) { if (ep_desc->bEndpointAddress & 0x80) {
usbh_pipe_alloc(&msc_class->bulkin, &ep_cfg); usbh_hport_activate_epx(&msc_class->bulkin, hport, ep_desc);
} else { } 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); ret = usbh_msc_scsi_testunitready(msc_class);

View File

@@ -228,7 +228,7 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf)
hport->config.intf[intf + 1].priv = NULL; hport->config.intf[intf + 1].priv = NULL;
#ifdef CONFIG_USBHOST_RNDIS_NOTIFY #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_addr = ep_desc->bEndpointAddress;
ep_cfg.ep_type = ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK; ep_cfg.ep_type = ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK;
ep_cfg.ep_mps = ep_desc->wMaxPacketSize & USB_MAXPACKETSIZE_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); usbh_pipe_alloc(&rndis_class->intin, &ep_cfg);
#endif #endif
for (uint8_t i = 0; i < hport->config.intf[intf + 1].intf_desc.bNumEndpoints; i++) { for (uint8_t i = 0; i < hport->config.intf[intf + 1].altsetting[0].intf_desc.bNumEndpoints; i++) {
ep_desc = &hport->config.intf[intf + 1].ep[i].ep_desc; ep_desc = &hport->config.intf[intf + 1].altsetting[0].ep[i].ep_desc;
ep_cfg.ep_addr = ep_desc->bEndpointAddress; ep_cfg.ep_addr = ep_desc->bEndpointAddress;
ep_cfg.ep_type = ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK; ep_cfg.ep_type = ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK;

View File

@@ -169,10 +169,10 @@ static int parse_config_descriptor(struct usbh_hubport *hport, struct usb_config
{ {
struct usb_interface_descriptor *intf_desc; struct usb_interface_descriptor *intf_desc;
struct usb_endpoint_descriptor *ep_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_iface = 0xff;
uint8_t cur_ep = 0xff; uint8_t cur_ep = 0xff;
uint8_t cur_ep_num; uint8_t cur_ep_num = 0xff;
uint32_t desc_len = 0; uint32_t desc_len = 0;
uint8_t *p; uint8_t *p;
@@ -211,6 +211,8 @@ static int parse_config_descriptor(struct usbh_hubport *hport, struct usb_config
p += USB_SIZEOF_CONFIG_DESC; p += USB_SIZEOF_CONFIG_DESC;
desc_len = 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)) { while (p[DESC_bLength] && (desc_len <= length)) {
switch (p[DESC_bDescriptorType]) { switch (p[DESC_bDescriptorType]) {
case USB_DESCRIPTOR_TYPE_INTERFACE: 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_alt_setting = intf_desc->bAlternateSetting;
cur_ep_num = intf_desc->bNumEndpoints; cur_ep_num = intf_desc->bNumEndpoints;
cur_ep = 0; cur_ep = 0;
if (cur_iface > CONFIG_USBHOST_INTF_NUM) { if (cur_iface > CONFIG_USBHOST_MAX_INTERFACES) {
return -ENOMEM; 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; return -ENOMEM;
} }
memset(&hport->config.intf[cur_iface], 0, sizeof(struct usbh_interface));
#if 0 #if 0
USB_LOG_DBG("Interface Descriptor:\r\n"); USB_LOG_DBG("Interface Descriptor:\r\n");
USB_LOG_DBG("bLength: 0x%02x \r\n", intf_desc->bLength); 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("bInterfaceProtocol: 0x%02x \r\n", intf_desc->bInterfaceProtocol);
USB_LOG_DBG("iInterface: 0x%02x \r\n", intf_desc->iInterface); USB_LOG_DBG("iInterface: 0x%02x \r\n", intf_desc->iInterface);
#endif #endif
memcpy(&hport->config.intf[cur_iface].intf_desc, intf_desc, 9); memcpy(&hport->config.intf[cur_iface].altsetting[cur_alt_setting].intf_desc, intf_desc, 9);
if (cur_alt_setting == 1) { hport->config.intf[cur_iface].altsetting_num = cur_alt_setting + 1;
USB_LOG_WRN("Altsetting enable, the previous intf info will be overwrited\r\n");
}
break; break;
case USB_DESCRIPTOR_TYPE_ENDPOINT: case USB_DESCRIPTOR_TYPE_ENDPOINT:
ep_desc = (struct usb_endpoint_descriptor *)p; 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].altsetting[cur_alt_setting].ep[cur_ep].ep_desc, ep_desc, 7);
memcpy(&hport->config.intf[cur_iface].ep[cur_ep].ep_desc, ep_desc, 7);
cur_ep++; cur_ep++;
break; 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); 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++) { for (uint8_t i = 0; i < hport->config.config_desc.bNumInterfaces; i++) {
USB_LOG_RAW("Interface Descriptor:\r\n"); for (uint8_t j = 0; j < hport->config.intf[i].altsetting_num; j++) {
USB_LOG_RAW("bLength: 0x%02x \r\n", hport->config.intf[i].intf_desc.bLength); USB_LOG_RAW("Interface Descriptor:\r\n");
USB_LOG_RAW("bDescriptorType: 0x%02x \r\n", hport->config.intf[i].intf_desc.bDescriptorType); USB_LOG_RAW("bLength: 0x%02x \r\n", hport->config.intf[i].altsetting[j].intf_desc.bLength);
USB_LOG_RAW("bInterfaceNumber: 0x%02x \r\n", hport->config.intf[i].intf_desc.bInterfaceNumber); USB_LOG_RAW("bDescriptorType: 0x%02x \r\n", hport->config.intf[i].altsetting[j].intf_desc.bDescriptorType);
USB_LOG_RAW("bAlternateSetting: 0x%02x \r\n", hport->config.intf[i].intf_desc.bAlternateSetting); USB_LOG_RAW("bInterfaceNumber: 0x%02x \r\n", hport->config.intf[i].altsetting[j].intf_desc.bInterfaceNumber);
USB_LOG_RAW("bNumEndpoints: 0x%02x \r\n", hport->config.intf[i].intf_desc.bNumEndpoints); USB_LOG_RAW("bAlternateSetting: 0x%02x \r\n", hport->config.intf[i].altsetting[j].intf_desc.bAlternateSetting);
USB_LOG_RAW("bInterfaceClass: 0x%02x \r\n", hport->config.intf[i].intf_desc.bInterfaceClass); USB_LOG_RAW("bNumEndpoints: 0x%02x \r\n", hport->config.intf[i].altsetting[j].intf_desc.bNumEndpoints);
USB_LOG_RAW("bInterfaceSubClass: 0x%02x \r\n", hport->config.intf[i].intf_desc.bInterfaceSubClass); USB_LOG_RAW("bInterfaceClass: 0x%02x \r\n", hport->config.intf[i].altsetting[j].intf_desc.bInterfaceClass);
USB_LOG_RAW("bInterfaceProtocol: 0x%02x \r\n", hport->config.intf[i].intf_desc.bInterfaceProtocol); USB_LOG_RAW("bInterfaceSubClass: 0x%02x \r\n", hport->config.intf[i].altsetting[j].intf_desc.bInterfaceSubClass);
USB_LOG_RAW("iInterface: 0x%02x \r\n", hport->config.intf[i].intf_desc.iInterface); 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++) { 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("Endpoint Descriptor:\r\n");
USB_LOG_RAW("bLength: 0x%02x \r\n", hport->config.intf[i].ep[j].ep_desc.bLength); 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].ep[j].ep_desc.bDescriptorType); 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].ep[j].ep_desc.bEndpointAddress); 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].ep[j].ep_desc.bmAttributes); 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].ep[j].ep_desc.wMaxPacketSize); 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].ep[j].ep_desc.bInterval); 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; 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) int usbh_enumerate(struct usbh_hubport *hport)
{ {
struct usb_interface_descriptor *intf_desc; 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"); USB_LOG_INFO("Enumeration success, start loading class driver\r\n");
/*search supported class driver*/ /*search supported class driver*/
for (uint8_t i = 0; i < hport->config.config_desc.bNumInterfaces; i++) { 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); 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);

View File

@@ -93,6 +93,23 @@ static inline void usbh_int_urb_fill(struct usbh_urb *urb,
urb->arg = arg; 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 { struct usbh_class_info {
uint8_t match_flags; /* Used for product specific matches; range is inclusive */ uint8_t match_flags; /* Used for product specific matches; range is inclusive */
uint8_t class; /* Base device class code */ uint8_t class; /* Base device class code */
@@ -114,9 +131,14 @@ struct usbh_endpoint {
struct usb_endpoint_descriptor ep_desc; struct usb_endpoint_descriptor ep_desc;
}; };
struct usbh_interface { struct usbh_interface_altsetting {
struct usb_interface_descriptor intf_desc; 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]; char devname[CONFIG_USBHOST_DEV_NAMELEN];
struct usbh_class_driver *class_driver; struct usbh_class_driver *class_driver;
void *priv; void *priv;
@@ -124,7 +146,7 @@ struct usbh_interface {
struct usbh_configuration { struct usbh_configuration {
struct usb_configuration_descriptor config_desc; 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 { struct usbh_hubport {
@@ -155,11 +177,13 @@ struct usbh_hub {
USB_MEM_ALIGNX uint8_t int_buffer[1]; USB_MEM_ALIGNX uint8_t int_buffer[1];
struct usbh_urb inturb; struct usbh_urb inturb;
struct usb_hub_descriptor hub_desc; 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; struct usbh_hubport *parent;
usb_slist_t hub_event_list; 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 */ /* usb host transfer wrapper */
/** /**

View File

@@ -79,10 +79,12 @@
/* ================ USB HOST Stack Configuration ================== */ /* ================ USB HOST Stack Configuration ================== */
#define CONFIG_USBHOST_RHPORTS 1 #define CONFIG_USBHOST_MAX_RHPORTS 1
#define CONFIG_USBHOST_EHPORTS 4 #define CONFIG_USBHOST_MAX_EXTHUBS 1
#define CONFIG_USBHOST_INTF_NUM 6 #define CONFIG_USBHOST_MAX_EHPORTS 4
#define CONFIG_USBHOST_EP_NUM 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 #define CONFIG_USBHOST_DEV_NAMELEN 16

View File

@@ -79,11 +79,12 @@
/* ================ USB HOST Stack Configuration ================== */ /* ================ USB HOST Stack Configuration ================== */
#define CONFIG_USBHOST_RHPORTS 1 #define CONFIG_USBHOST_MAX_RHPORTS 1
#define CONFIG_USBHOST_EXTHUB_NUM 1 #define CONFIG_USBHOST_MAX_EXTHUBS 1
#define CONFIG_USBHOST_EHPORTS 4 #define CONFIG_USBHOST_MAX_EHPORTS 4
#define CONFIG_USBHOST_INTF_NUM 6 #define CONFIG_USBHOST_MAX_INTERFACES 6
#define CONFIG_USBHOST_EP_NUM 4 #define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 1
#define CONFIG_USBHOST_MAX_ENDPOINTS 4
#define CONFIG_USBHOST_DEV_NAMELEN 16 #define CONFIG_USBHOST_DEV_NAMELEN 16

View File

@@ -79,11 +79,12 @@
/* ================ USB HOST Stack Configuration ================== */ /* ================ USB HOST Stack Configuration ================== */
#define CONFIG_USBHOST_RHPORTS 1 #define CONFIG_USBHOST_MAX_RHPORTS 1
#define CONFIG_USBHOST_EXTHUB_NUM 1 #define CONFIG_USBHOST_MAX_EXTHUBS 1
#define CONFIG_USBHOST_EHPORTS 4 #define CONFIG_USBHOST_MAX_EHPORTS 4
#define CONFIG_USBHOST_INTF_NUM 6 #define CONFIG_USBHOST_MAX_INTERFACES 6
#define CONFIG_USBHOST_EP_NUM 4 #define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 1
#define CONFIG_USBHOST_MAX_ENDPOINTS 4
#define CONFIG_USBHOST_DEV_NAMELEN 16 #define CONFIG_USBHOST_DEV_NAMELEN 16

View File

@@ -79,11 +79,12 @@
/* ================ USB HOST Stack Configuration ================== */ /* ================ USB HOST Stack Configuration ================== */
#define CONFIG_USBHOST_RHPORTS 1 #define CONFIG_USBHOST_MAX_RHPORTS 1
#define CONFIG_USBHOST_EXTHUB_NUM 1 #define CONFIG_USBHOST_MAX_EXTHUBS 1
#define CONFIG_USBHOST_EHPORTS 4 #define CONFIG_USBHOST_MAX_EHPORTS 4
#define CONFIG_USBHOST_INTF_NUM 6 #define CONFIG_USBHOST_MAX_INTERFACES 6
#define CONFIG_USBHOST_EP_NUM 4 #define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 1
#define CONFIG_USBHOST_MAX_ENDPOINTS 4
#define CONFIG_USBHOST_DEV_NAMELEN 16 #define CONFIG_USBHOST_DEV_NAMELEN 16

View File

@@ -79,10 +79,12 @@
/* ================ USB HOST Stack Configuration ================== */ /* ================ USB HOST Stack Configuration ================== */
#define CONFIG_USBHOST_RHPORTS 1 #define CONFIG_USBHOST_MAX_RHPORTS 1
#define CONFIG_USBHOST_EHPORTS 4 #define CONFIG_USBHOST_MAX_EXTHUBS 1
#define CONFIG_USBHOST_INTF_NUM 6 #define CONFIG_USBHOST_MAX_EHPORTS 4
#define CONFIG_USBHOST_EP_NUM 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 #define CONFIG_USBHOST_DEV_NAMELEN 16

View File

@@ -79,10 +79,12 @@
/* ================ USB HOST Stack Configuration ================== */ /* ================ USB HOST Stack Configuration ================== */
#define CONFIG_USBHOST_RHPORTS 1 #define CONFIG_USBHOST_MAX_RHPORTS 1
#define CONFIG_USBHOST_EHPORTS 4 #define CONFIG_USBHOST_MAX_EXTHUBS 1
#define CONFIG_USBHOST_INTF_NUM 6 #define CONFIG_USBHOST_MAX_EHPORTS 4
#define CONFIG_USBHOST_EP_NUM 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 #define CONFIG_USBHOST_DEV_NAMELEN 16

View File

@@ -79,10 +79,12 @@
/* ================ USB HOST Stack Configuration ================== */ /* ================ USB HOST Stack Configuration ================== */
#define CONFIG_USBHOST_RHPORTS 1 #define CONFIG_USBHOST_MAX_RHPORTS 1
#define CONFIG_USBHOST_EHPORTS 4 #define CONFIG_USBHOST_MAX_EXTHUBS 1
#define CONFIG_USBHOST_INTF_NUM 6 #define CONFIG_USBHOST_MAX_EHPORTS 4
#define CONFIG_USBHOST_EP_NUM 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 #define CONFIG_USBHOST_DEV_NAMELEN 16

View File

@@ -79,11 +79,12 @@
/* ================ USB HOST Stack Configuration ================== */ /* ================ USB HOST Stack Configuration ================== */
#define CONFIG_USBHOST_RHPORTS 1 #define CONFIG_USBHOST_MAX_RHPORTS 1
#define CONFIG_USBHOST_EXTHUB_NUM 1 #define CONFIG_USBHOST_MAX_EXTHUBS 1
#define CONFIG_USBHOST_EHPORTS 4 #define CONFIG_USBHOST_MAX_EHPORTS 4
#define CONFIG_USBHOST_INTF_NUM 6 #define CONFIG_USBHOST_MAX_INTERFACES 6
#define CONFIG_USBHOST_EP_NUM 4 #define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 1
#define CONFIG_USBHOST_MAX_ENDPOINTS 4
#define CONFIG_USBHOST_DEV_NAMELEN 16 #define CONFIG_USBHOST_DEV_NAMELEN 16

View File

@@ -79,11 +79,12 @@
/* ================ USB HOST Stack Configuration ================== */ /* ================ USB HOST Stack Configuration ================== */
#define CONFIG_USBHOST_RHPORTS 1 #define CONFIG_USBHOST_MAX_RHPORTS 1
#define CONFIG_USBHOST_EXTHUB_NUM 1 #define CONFIG_USBHOST_MAX_EXTHUBS 1
#define CONFIG_USBHOST_EHPORTS 4 #define CONFIG_USBHOST_MAX_EHPORTS 4
#define CONFIG_USBHOST_INTF_NUM 6 #define CONFIG_USBHOST_MAX_INTERFACES 6
#define CONFIG_USBHOST_EP_NUM 4 #define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 1
#define CONFIG_USBHOST_MAX_ENDPOINTS 4
#define CONFIG_USBHOST_DEV_NAMELEN 16 #define CONFIG_USBHOST_DEV_NAMELEN 16

View File

@@ -540,7 +540,7 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
uint8_t port; uint8_t port;
uint32_t status; uint32_t status;
nports = CONFIG_USBHOST_RHPORTS; nports = CONFIG_USBHOST_MAX_RHPORTS;
port = setup->wIndex; port = setup->wIndex;
if (setup->bmRequestType & USB_REQUEST_RECIPIENT_DEVICE) { if (setup->bmRequestType & USB_REQUEST_RECIPIENT_DEVICE) {
switch (setup->bRequest) { switch (setup->bRequest) {

View File

@@ -441,7 +441,7 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
uint8_t port; uint8_t port;
uint32_t status; uint32_t status;
nports = CONFIG_USBHOST_RHPORTS; nports = CONFIG_USBHOST_MAX_RHPORTS;
port = setup->wIndex; port = setup->wIndex;
if (setup->bmRequestType & USB_REQUEST_RECIPIENT_DEVICE) { if (setup->bmRequestType & USB_REQUEST_RECIPIENT_DEVICE) {
switch (setup->bRequest) { switch (setup->bRequest) {