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

@@ -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) {

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)
{
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);

View File

@@ -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;

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)
{
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);

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;
#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;