diff options
| author | Wayne Lin <[email protected]> | 2022-01-26 14:54:14 +0800 |
|---|---|---|
| committer | Wayne Lin <[email protected]> | 2022-01-26 14:54:14 +0800 |
| commit | 648199808e598e0b35fa01c09a1909eeb857e0cd (patch) | |
| tree | 98edafc6ded6e3886e8ab066229ff404824c1b87 /components | |
| parent | 1577e91c50fb6cea131767163665a0640644fe96 (diff) | |
| parent | e665bacf89c5901244cd43e195a7ae039b3c0463 (diff) | |
Merge branch 'master' of https://github.com/RT-Thread/rt-thread into nuvoton
Diffstat (limited to 'components')
| -rw-r--r-- | components/drivers/include/drivers/usb_host.h | 8 | ||||
| -rw-r--r-- | components/drivers/usb/usbhost/core/driver.c | 17 | ||||
| -rw-r--r-- | components/drivers/usb/usbhost/core/hub.c | 33 | ||||
| -rw-r--r-- | components/drivers/usb/usbhost/core/usbhost.c | 18 |
4 files changed, 48 insertions, 28 deletions
diff --git a/components/drivers/include/drivers/usb_host.h b/components/drivers/include/drivers/usb_host.h index 2031e2cdc0..95dd1ff066 100644 --- a/components/drivers/include/drivers/usb_host.h +++ b/components/drivers/include/drivers/usb_host.h @@ -6,6 +6,7 @@ * Change Logs: * Date Author Notes * 2011-3-12 Yi Qiu first version + * 2021-02-23 Leslie Lee provide possibility for multi usb host */ #ifndef __RT_USB_HOST_H__ @@ -137,6 +138,7 @@ struct uhcd uhcd_ops_t ops; rt_uint8_t num_ports; uhub_t roothub; + struct rt_messagequeue *usb_mq; }; typedef struct uhcd* uhcd_t; @@ -163,7 +165,7 @@ struct uhost_msg typedef struct uhost_msg* uhost_msg_t; /* usb host system interface */ -rt_err_t rt_usb_host_init(void); +rt_err_t rt_usb_host_init(const char *name); void rt_usbh_hub_init(struct uhcd *hcd); /* usb host core interface */ @@ -203,7 +205,7 @@ rt_err_t rt_usbh_hub_clear_port_feature(uhub_t uhub, rt_uint16_t port, rt_err_t rt_usbh_hub_set_port_feature(uhub_t uhub, rt_uint16_t port, rt_uint16_t feature); rt_err_t rt_usbh_hub_reset_port(uhub_t uhub, rt_uint16_t port); -rt_err_t rt_usbh_event_signal(struct uhost_msg* msg); +rt_err_t rt_usbh_event_signal(uhcd_t uhcd, struct uhost_msg* msg); void rt_usbh_root_hub_connect_handler(struct uhcd *hcd, rt_uint8_t port, rt_bool_t isHS); @@ -265,5 +267,3 @@ rt_inline int rt_usb_hcd_setup_xfer(uhcd_t hcd, upipe_t pipe, ureq_t setup, int #endif #endif - - diff --git a/components/drivers/usb/usbhost/core/driver.c b/components/drivers/usb/usbhost/core/driver.c index 6dad1409a0..73360d307a 100644 --- a/components/drivers/usb/usbhost/core/driver.c +++ b/components/drivers/usb/usbhost/core/driver.c @@ -6,6 +6,7 @@ * Change Logs: * Date Author Notes * 2011-03-12 Yi Qiu first version + * 2021-02-23 Leslie Lee provide possibility for multi usb host */ #include <rtthread.h> @@ -13,6 +14,7 @@ #include <drivers/usb_host.h> static rt_list_t _driver_list; +static rt_bool_t _driver_list_created = RT_FALSE; /** * This function will initilize the usb class driver related data structure, @@ -22,8 +24,11 @@ static rt_list_t _driver_list; */ rt_err_t rt_usbh_class_driver_init(void) { - rt_list_init(&_driver_list); - + if (_driver_list_created == RT_FALSE) + { + rt_list_init(&_driver_list); + _driver_list_created = RT_TRUE; + } return RT_EOK; } @@ -39,8 +44,11 @@ rt_err_t rt_usbh_class_driver_register(ucd_t drv) { if (drv == RT_NULL) return -RT_ERROR; - /* insert class driver into driver list */ - rt_list_insert_after(&_driver_list, &(drv->list)); + if (rt_usbh_class_driver_find(drv->class_code, drv->subclass_code) == RT_NULL) + { + /* insert class driver into driver list */ + rt_list_insert_after(&_driver_list, &(drv->list)); + } return RT_EOK; } @@ -137,4 +145,3 @@ ucd_t rt_usbh_class_driver_find(int class_code, int subclass_code) /* not found */ return RT_NULL; } - diff --git a/components/drivers/usb/usbhost/core/hub.c b/components/drivers/usb/usbhost/core/hub.c index b6381ec300..eca06f6564 100644 --- a/components/drivers/usb/usbhost/core/hub.c +++ b/components/drivers/usb/usbhost/core/hub.c @@ -6,6 +6,7 @@ * Change Logs: * Date Author Notes * 2011-12-12 Yi Qiu first version + * 2021-02-23 Leslie Lee provide possibility for multi usb host */ #include <rtthread.h> @@ -13,9 +14,9 @@ #define USB_THREAD_STACK_SIZE 4096 -static struct rt_messagequeue *usb_mq; +// static struct rt_messagequeue *usb_mq; static struct uclass_driver hub_driver; -static struct uhub root_hub; +// static struct uhub root_hub; static rt_err_t root_hub_ctrl(struct uhcd *hcd, rt_uint16_t port, rt_uint8_t cmd, void *args) { @@ -92,7 +93,7 @@ void rt_usbh_root_hub_connect_handler(struct uhcd *hcd, rt_uint8_t port, rt_bool { hcd->roothub->port_status[port - 1] |= PORT_LSDA; } - rt_usbh_event_signal(&msg); + rt_usbh_event_signal(hcd, &msg); } void rt_usbh_root_hub_disconnect_handler(struct uhcd *hcd, rt_uint8_t port) @@ -102,7 +103,7 @@ void rt_usbh_root_hub_disconnect_handler(struct uhcd *hcd, rt_uint8_t port) msg.content.hub = hcd->roothub; hcd->roothub->port_status[port - 1] |= PORT_CCSC; hcd->roothub->port_status[port - 1] &= ~PORT_CCS; - rt_usbh_event_signal(&msg); + rt_usbh_event_signal(hcd, &msg); } /** @@ -647,12 +648,13 @@ ucd_t rt_usbh_class_driver_hub(void) */ static void rt_usbh_hub_thread_entry(void* parameter) { + uhcd_t hcd = (uhcd_t)parameter; while(1) { struct uhost_msg msg; /* receive message */ - if(rt_mq_recv(usb_mq, &msg, sizeof(struct uhost_msg), RT_WAITING_FOREVER) + if(rt_mq_recv(hcd->usb_mq, &msg, sizeof(struct uhost_msg), RT_WAITING_FOREVER) != RT_EOK ) continue; //RT_DEBUG_LOG(RT_DEBUG_USB, ("msg type %d\n", msg.type)); @@ -679,12 +681,12 @@ static void rt_usbh_hub_thread_entry(void* parameter) * * @return the error code, RT_EOK on successfully. */ -rt_err_t rt_usbh_event_signal(struct uhost_msg* msg) +rt_err_t rt_usbh_event_signal(uhcd_t hcd, struct uhost_msg* msg) { RT_ASSERT(msg != RT_NULL); /* send message to usb message queue */ - rt_mq_send(usb_mq, (void*)msg, sizeof(struct uhost_msg)); + rt_mq_send(hcd->usb_mq, (void*)msg, sizeof(struct uhost_msg)); return RT_EOK; } @@ -698,16 +700,18 @@ rt_err_t rt_usbh_event_signal(struct uhost_msg* msg) void rt_usbh_hub_init(uhcd_t hcd) { rt_thread_t thread; - /* link root hub to hcd */ - root_hub.is_roothub = RT_TRUE; - hcd->roothub = &root_hub; - root_hub.hcd = hcd; - root_hub.num_ports = hcd->num_ports; + /* create root hub for hcd */ + hcd->roothub = rt_malloc(sizeof(struct uhub)); + rt_memset(hcd->roothub, 0, sizeof(struct uhub)); + hcd->roothub->is_roothub = RT_TRUE; + hcd->roothub->hcd = hcd; + hcd->roothub->num_ports = hcd->num_ports; /* create usb message queue */ - usb_mq = rt_mq_create("usbh", 32, 16, RT_IPC_FLAG_FIFO); + + hcd->usb_mq = rt_mq_create(hcd->parent.parent.name, 32, 16, RT_IPC_FLAG_FIFO); /* create usb hub thread */ - thread = rt_thread_create("usbh", rt_usbh_hub_thread_entry, RT_NULL, + thread = rt_thread_create(hcd->parent.parent.name, rt_usbh_hub_thread_entry, hcd, USB_THREAD_STACK_SIZE, 8, 20); if(thread != RT_NULL) { @@ -715,4 +719,3 @@ void rt_usbh_hub_init(uhcd_t hcd) rt_thread_startup(thread); } } - diff --git a/components/drivers/usb/usbhost/core/usbhost.c b/components/drivers/usb/usbhost/core/usbhost.c index a76f6d4586..9a4c166acd 100644 --- a/components/drivers/usb/usbhost/core/usbhost.c +++ b/components/drivers/usb/usbhost/core/usbhost.c @@ -6,6 +6,7 @@ * Change Logs: * Date Author Notes * 2011-12-12 Yi Qiu first version + * 2021-02-23 Leslie Lee provide possibility for multi usb host */ #include <rtthread.h> #include <drivers/usb_host.h> @@ -22,15 +23,15 @@ * * @return none. */ -rt_err_t rt_usb_host_init(void) +rt_err_t rt_usb_host_init(const char *name) { ucd_t drv; rt_device_t uhc; - uhc = rt_device_find(USB_HOST_CONTROLLER_NAME); + uhc = rt_device_find(name); if(uhc == RT_NULL) { - rt_kprintf("can't find usb host controller %s\n", USB_HOST_CONTROLLER_NAME); + rt_kprintf("can't find usb host controller %s\n", name); return -RT_ERROR; } @@ -45,6 +46,16 @@ rt_err_t rt_usb_host_init(void) drv = rt_usbh_class_driver_storage(); rt_usbh_class_driver_register(drv); #endif +#ifdef RT_USBH_HID + /* register mass storage class driver */ + drv = rt_usbh_class_driver_hid(); + rt_usbh_class_driver_register(drv); +#ifdef RT_USBH_HID_MOUSE + uprotocal_t protocal; + protocal = rt_usbh_hid_protocal_mouse(); + rt_usbh_hid_protocal_register(protocal); +#endif +#endif /* register hub class driver */ drv = rt_usbh_class_driver_hub(); @@ -55,4 +66,3 @@ rt_err_t rt_usb_host_init(void) return RT_EOK; } - |
