rt-thread/components/drivers/usb/usbhost/core/usbhost.c

77 lines
1.9 KiB
C
Raw Normal View History

2013-01-08 22:40:58 +08:00
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
2013-01-08 22:40:58 +08:00
*
2018-10-14 19:37:18 +08:00
* SPDX-License-Identifier: Apache-2.0
2013-01-08 22:40:58 +08:00
*
* Change Logs:
* Date Author Notes
* 2011-12-12 Yi Qiu first version
2021-02-23 17:05:01 +08:00
* 2021-02-23 Leslie Lee provide possibility for multi usb host
2013-01-08 22:40:58 +08:00
*/
#include <rtthread.h>
#include <drivers/usb_host.h>
#define USB_HOST_CONTROLLER_NAME "usbh"
#if defined(RT_USBH_HID_KEYBOARD) || defined(RT_USBH_HID_MOUSE)
2013-01-08 22:40:58 +08:00
#include <hid.h>
#endif
/**
* This function will initialize the usb host stack, all the usb class driver and
* host controller driver are also be initialized here.
2021-03-08 18:19:04 +08:00
*
2013-01-08 22:40:58 +08:00
* @return none.
*/
2021-02-23 17:05:01 +08:00
rt_err_t rt_usb_host_init(const char *name)
2013-01-08 22:40:58 +08:00
{
ucd_t drv;
2021-03-08 18:19:04 +08:00
rt_device_t uhc;
2013-01-08 22:40:58 +08:00
2021-02-23 17:05:01 +08:00
uhc = rt_device_find(name);
if(uhc == RT_NULL)
{
2021-02-23 17:05:01 +08:00
rt_kprintf("can't find usb host controller %s\n", name);
return -RT_ERROR;
}
/* initialize usb hub */
2017-12-14 03:14:44 +08:00
rt_usbh_hub_init((uhcd_t)uhc);
2013-01-08 22:40:58 +08:00
/* initialize class driver */
rt_usbh_class_driver_init();
2013-01-08 22:40:58 +08:00
#ifdef RT_USBH_MSTORAGE
2013-01-08 22:40:58 +08:00
/* register mass storage class driver */
drv = rt_usbh_class_driver_storage();
rt_usbh_class_driver_register(drv);
2021-02-23 17:05:01 +08:00
#endif
#ifdef RT_USBH_HID
extern ucd_t rt_usbh_class_driver_hid(void);
2021-02-23 17:05:01 +08:00
/* register mass storage class driver */
drv = rt_usbh_class_driver_hid();
rt_usbh_class_driver_register(drv);
#ifdef RT_USBH_HID_MOUSE
{
extern uprotocal_t rt_usbh_hid_protocal_mouse(void);
rt_usbh_hid_protocal_register(rt_usbh_hid_protocal_mouse());
}
#endif
#ifdef RT_USBH_HID_KEYBOARD
{
extern uprotocal_t rt_usbh_hid_protocal_kbd(void);
rt_usbh_hid_protocal_register(rt_usbh_hid_protocal_kbd());
}
2021-02-23 17:05:01 +08:00
#endif
2013-01-08 22:40:58 +08:00
#endif
/* register hub class driver */
drv = rt_usbh_class_driver_hub();
rt_usbh_class_driver_register(drv);
/* initialize usb host controller */
rt_device_init(uhc);
2013-07-24 07:33:48 +08:00
return RT_EOK;
2022-01-26 11:00:16 +08:00
}