diff --git a/class/audio/usbh_audio.c b/class/audio/usbh_audio.c index 875bd5a2..38f3bb81 100644 --- a/class/audio/usbh_audio.c +++ b/class/audio/usbh_audio.c @@ -48,7 +48,7 @@ static void usbh_audio_devno_free(struct usbh_audio *audio_class) int usbh_audio_open(struct usbh_audio *audio_class, const char *name, uint32_t samp_freq) { - struct usb_setup_packet *setup = &audio_class->hport->setup; + struct usb_setup_packet *setup = audio_class->hport->setup; struct usb_endpoint_descriptor *ep_desc; uint8_t mult; uint16_t mps; @@ -120,7 +120,7 @@ freq_found: int usbh_audio_close(struct usbh_audio *audio_class, const char *name) { - struct usb_setup_packet *setup = &audio_class->hport->setup; + struct usb_setup_packet *setup = audio_class->hport->setup; struct usb_endpoint_descriptor *ep_desc; int ret; uint8_t intf = 0xff; diff --git a/class/cdc/usbh_cdc_acm.c b/class/cdc/usbh_cdc_acm.c index 825b7cbf..bf1babb8 100644 --- a/class/cdc/usbh_cdc_acm.c +++ b/class/cdc/usbh_cdc_acm.c @@ -38,7 +38,7 @@ static void usbh_cdc_acm_devno_free(struct usbh_cdc_acm *cdc_acm_class) int usbh_cdc_acm_set_line_coding(struct usbh_cdc_acm *cdc_acm_class, struct cdc_line_coding *line_coding) { - struct usb_setup_packet *setup = &cdc_acm_class->hport->setup; + struct usb_setup_packet *setup = cdc_acm_class->hport->setup; setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE; setup->bRequest = CDC_REQUEST_SET_LINE_CODING; @@ -53,7 +53,7 @@ int usbh_cdc_acm_set_line_coding(struct usbh_cdc_acm *cdc_acm_class, struct cdc_ int usbh_cdc_acm_get_line_coding(struct usbh_cdc_acm *cdc_acm_class, struct cdc_line_coding *line_coding) { - struct usb_setup_packet *setup = &cdc_acm_class->hport->setup; + struct usb_setup_packet *setup = cdc_acm_class->hport->setup; int ret; setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE; @@ -72,7 +72,7 @@ int usbh_cdc_acm_get_line_coding(struct usbh_cdc_acm *cdc_acm_class, struct cdc_ int usbh_cdc_acm_set_line_state(struct usbh_cdc_acm *cdc_acm_class, bool dtr, bool rts) { - struct usb_setup_packet *setup = &cdc_acm_class->hport->setup; + struct usb_setup_packet *setup = cdc_acm_class->hport->setup; setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE; setup->bRequest = CDC_REQUEST_SET_CONTROL_LINE_STATE; diff --git a/class/hid/usbh_hid.c b/class/hid/usbh_hid.c index 4fb4a534..23ee2a05 100644 --- a/class/hid/usbh_hid.c +++ b/class/hid/usbh_hid.c @@ -39,7 +39,7 @@ static void usbh_hid_devno_free(struct usbh_hid *hid_class) static int usbh_hid_get_report_descriptor(struct usbh_hid *hid_class, uint8_t *buffer) { - struct usb_setup_packet *setup = &hid_class->hport->setup; + struct usb_setup_packet *setup = hid_class->hport->setup; int ret; setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_STANDARD | USB_REQUEST_RECIPIENT_INTERFACE; @@ -58,7 +58,7 @@ static int usbh_hid_get_report_descriptor(struct usbh_hid *hid_class, uint8_t *b int usbh_hid_set_idle(struct usbh_hid *hid_class, uint8_t report_id, uint8_t duration) { - struct usb_setup_packet *setup = &hid_class->hport->setup; + struct usb_setup_packet *setup = hid_class->hport->setup; setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE; setup->bRequest = HID_REQUEST_SET_IDLE; @@ -71,7 +71,7 @@ int usbh_hid_set_idle(struct usbh_hid *hid_class, uint8_t report_id, uint8_t dur int usbh_hid_get_idle(struct usbh_hid *hid_class, uint8_t *buffer) { - struct usb_setup_packet *setup = &hid_class->hport->setup; + struct usb_setup_packet *setup = hid_class->hport->setup; int ret; setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE; @@ -90,7 +90,7 @@ int usbh_hid_get_idle(struct usbh_hid *hid_class, uint8_t *buffer) int usbh_hid_set_protocol(struct usbh_hid *hid_class, uint8_t protocol) { - struct usb_setup_packet *setup = &hid_class->hport->setup; + struct usb_setup_packet *setup = hid_class->hport->setup; setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE; setup->bRequest = HID_REQUEST_SET_PROTOCOL; diff --git a/class/hub/usbh_hub.c b/class/hub/usbh_hub.c index ae4c70b0..09557d3a 100644 --- a/class/hub/usbh_hub.c +++ b/class/hub/usbh_hub.c @@ -17,16 +17,17 @@ static uint32_t g_devinuse = 0; USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_hub_buf[32]; +USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_hub_intbuf[CONFIG_USBHOST_MAX_EXTHUBS + 1][1]; usb_slist_t hub_class_head = USB_SLIST_OBJECT_INIT(hub_class_head); usb_osal_thread_t hub_thread; usb_osal_mq_t hub_mq; -USB_NOCACHE_RAM_SECTION struct usbh_hub roothub; +struct usbh_hub roothub; #if CONFIG_USBHOST_MAX_EXTHUBS > 0 -USB_NOCACHE_RAM_SECTION struct usbh_hub exthub[CONFIG_USBHOST_MAX_EXTHUBS]; +struct usbh_hub exthub[CONFIG_USBHOST_MAX_EXTHUBS]; #endif extern int usbh_hport_activate_ep0(struct usbh_hubport *hport); extern int usbh_hport_deactivate_ep0(struct usbh_hubport *hport); @@ -74,7 +75,7 @@ static int _usbh_hub_get_hub_descriptor(struct usbh_hub *hub, uint8_t *buffer) struct usb_setup_packet *setup; int ret; - setup = &hub->parent->setup; + setup = hub->parent->setup; setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_DEVICE; setup->bRequest = USB_REQUEST_GET_DESCRIPTOR; @@ -95,7 +96,7 @@ static int _usbh_hub_get_status(struct usbh_hub *hub, uint8_t *buffer) struct usb_setup_packet *setup; int ret; - setup = &hub->parent->setup; + setup = hub->parent->setup; setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_DEVICE; setup->bRequest = HUB_REQUEST_GET_STATUS; @@ -116,7 +117,7 @@ static int _usbh_hub_get_portstatus(struct usbh_hub *hub, uint8_t port, struct h struct usb_setup_packet *setup; int ret; - setup = &hub->parent->setup; + setup = hub->parent->setup; setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_OTHER; setup->bRequest = HUB_REQUEST_GET_STATUS; @@ -136,7 +137,7 @@ static int _usbh_hub_set_feature(struct usbh_hub *hub, uint8_t port, uint8_t fea { struct usb_setup_packet *setup; - setup = &hub->parent->setup; + setup = hub->parent->setup; setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_OTHER; setup->bRequest = HUB_REQUEST_SET_FEATURE; @@ -151,7 +152,7 @@ static int _usbh_hub_clear_feature(struct usbh_hub *hub, uint8_t port, uint8_t f { struct usb_setup_packet *setup; - setup = &hub->parent->setup; + setup = hub->parent->setup; setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_OTHER; setup->bRequest = HUB_REQUEST_CLEAR_FEATURE; @@ -310,6 +311,7 @@ static int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf) usbh_hub_register(hub); USB_LOG_INFO("Register HUB Class:%s\r\n", hport->config.intf[intf].devname); + hub->int_buffer = g_hub_intbuf[hub->index - 1]; usbh_int_urb_fill(&hub->intin_urb, hub->intin, hub->int_buffer, 1, 0, hub_int_complete_callback, hub); usbh_submit_urb(&hub->intin_urb); return 0; @@ -572,6 +574,7 @@ static void usbh_hub_thread_wakeup(struct usbh_hub *hub) void usbh_roothub_thread_wakeup(uint8_t port) { + roothub.int_buffer = g_hub_intbuf[roothub.index - 1]; roothub.int_buffer[0] |= (1 << port); usbh_hub_thread_wakeup(&roothub); } diff --git a/class/msc/usbh_msc.c b/class/msc/usbh_msc.c index 5c644322..9d053099 100644 --- a/class/msc/usbh_msc.c +++ b/class/msc/usbh_msc.c @@ -40,7 +40,7 @@ static void usbh_msc_devno_free(struct usbh_msc *msc_class) static int usbh_msc_get_maxlun(struct usbh_msc *msc_class, uint8_t *buffer) { - struct usb_setup_packet *setup = &msc_class->hport->setup; + struct usb_setup_packet *setup = msc_class->hport->setup; setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE; setup->bRequest = MSC_REQUEST_GET_MAX_LUN; diff --git a/class/video/usbh_video.c b/class/video/usbh_video.c index 0aba1af9..07070e53 100644 --- a/class/video/usbh_video.c +++ b/class/video/usbh_video.c @@ -97,7 +97,7 @@ static void usbh_video_devno_free(struct usbh_video *video_class) int usbh_video_get_cur(struct usbh_video *video_class, uint8_t intf, uint8_t entity_id, uint8_t cs, uint8_t *buf, uint16_t len) { - struct usb_setup_packet *setup = &video_class->hport->setup; + struct usb_setup_packet *setup = video_class->hport->setup; int ret; setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE; @@ -116,7 +116,7 @@ int usbh_video_get_cur(struct usbh_video *video_class, uint8_t intf, uint8_t ent int usbh_video_set_cur(struct usbh_video *video_class, uint8_t intf, uint8_t entity_id, uint8_t cs, uint8_t *buf, uint16_t len) { - struct usb_setup_packet *setup = &video_class->hport->setup; + struct usb_setup_packet *setup = video_class->hport->setup; setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_CLASS | USB_REQUEST_RECIPIENT_INTERFACE; setup->bRequest = VIDEO_REQUEST_SET_CUR; @@ -156,7 +156,7 @@ int usbh_video_open(struct usbh_video *video_class, uint16_t wHeight, uint8_t altsetting) { - struct usb_setup_packet *setup = &video_class->hport->setup; + struct usb_setup_packet *setup = video_class->hport->setup; struct usb_endpoint_descriptor *ep_desc; uint8_t mult; uint16_t mps; @@ -246,7 +246,7 @@ int usbh_video_open(struct usbh_video *video_class, int usbh_video_close(struct usbh_video *video_class) { - struct usb_setup_packet *setup = &video_class->hport->setup; + struct usb_setup_packet *setup = video_class->hport->setup; int ret = 0; USB_LOG_INFO("Close video device\r\n"); diff --git a/class/wireless/usbh_rndis.c b/class/wireless/usbh_rndis.c index 46164117..49feb491 100644 --- a/class/wireless/usbh_rndis.c +++ b/class/wireless/usbh_rndis.c @@ -13,7 +13,7 @@ USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_rndis_buf[1024]; static int usbh_rndis_init_msg_transfer(struct usbh_rndis *rndis_class) { - struct usb_setup_packet *setup = &rndis_class->hport->setup; + struct usb_setup_packet *setup = rndis_class->hport->setup; int ret = 0; rndis_initialize_msg_t *cmd; rndis_initialize_cmplt_t *resp; @@ -60,7 +60,7 @@ static int usbh_rndis_init_msg_transfer(struct usbh_rndis *rndis_class) int usbh_rndis_query_msg_transfer(struct usbh_rndis *rndis_class, uint32_t oid, uint32_t query_len, uint8_t *info, uint32_t *info_len) { - struct usb_setup_packet *setup = &rndis_class->hport->setup; + struct usb_setup_packet *setup = rndis_class->hport->setup; int ret = 0; rndis_query_msg_t *cmd; rndis_query_cmplt_t *resp; @@ -111,7 +111,7 @@ int usbh_rndis_query_msg_transfer(struct usbh_rndis *rndis_class, uint32_t oid, static int usbh_rndis_set_msg_transfer(struct usbh_rndis *rndis_class, uint32_t oid, uint8_t *info, uint32_t info_len) { - struct usb_setup_packet *setup = &rndis_class->hport->setup; + struct usb_setup_packet *setup = rndis_class->hport->setup; int ret = 0; rndis_set_msg_t *cmd; rndis_set_cmplt_t *resp; @@ -188,7 +188,7 @@ int usbh_rndis_bulk_in_transfer(struct usbh_rndis *rndis_class, uint8_t *buffer, int usbh_rndis_keepalive(struct usbh_rndis *rndis_class) { - struct usb_setup_packet *setup = &rndis_class->hport->setup; + struct usb_setup_packet *setup = rndis_class->hport->setup; int ret = 0; rndis_keepalive_msg_t *cmd; rndis_keepalive_cmplt_t *resp; diff --git a/core/usbh_core.c b/core/usbh_core.c index 6eb4ccd4..03741619 100644 --- a/core/usbh_core.c +++ b/core/usbh_core.c @@ -10,6 +10,7 @@ struct usbh_class_info *usbh_class_info_table_begin = NULL; struct usbh_class_info *usbh_class_info_table_end = NULL; USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t ep0_request_buffer[CONFIG_USBHOST_REQUEST_BUFFER_LEN]; +USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX struct usb_setup_packet g_setup[CONFIG_USBHOST_MAX_EXTHUBS + 1][CONFIG_USBHOST_MAX_EHPORTS]; /* general descriptor field offsets */ #define DESC_bLength 0 /** Length offset */ @@ -415,8 +416,8 @@ int usbh_enumerate(struct usbh_hubport *hport) uint16_t ep_mps; int ret; -#define USB_REQUEST_BUFFER_SIZE 256 - setup = &hport->setup; + hport->setup = &g_setup[hport->parent->index - 1][hport->port - 1]; + setup = hport->setup; /* Configure EP0 with the default maximum packet size */ usbh_hport_activate_ep0(hport); diff --git a/core/usbh_core.h b/core/usbh_core.h index 99f3a350..dafc11a7 100644 --- a/core/usbh_core.h +++ b/core/usbh_core.h @@ -123,11 +123,11 @@ struct usbh_interface_altsetting { }; 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; + struct usbh_interface_altsetting altsetting[CONFIG_USBHOST_MAX_INTF_ALTSETTINGS]; + uint8_t altsetting_num; }; struct usbh_configuration { @@ -146,8 +146,8 @@ struct usbh_hubport { const char *iManufacturer; const char *iProduct; const char *iSerialNumber; - uint8_t* raw_config_desc; - USB_MEM_ALIGNX struct usb_setup_packet setup; + uint8_t *raw_config_desc; + struct usb_setup_packet *setup; struct usbh_hub *parent; }; @@ -158,7 +158,7 @@ struct usbh_hub { uint8_t index; uint8_t hub_addr; usbh_pipe_t intin; - USB_MEM_ALIGNX uint8_t int_buffer[1]; + uint8_t *int_buffer; struct usbh_urb intin_urb; struct usb_hub_descriptor hub_desc; struct usbh_hubport child[CONFIG_USBHOST_MAX_EHPORTS]; @@ -184,6 +184,7 @@ struct usbh_hubport *usbh_find_hubport(uint8_t dev_addr); void *usbh_find_class_instance(const char *devname); int lsusb(int argc, char **argv); + #ifdef __cplusplus } #endif