usbhost.c 1.6 KB
Newer Older
M
Ming, Bai 已提交
1
/*
2
 * Copyright (c) 2006-2021, RT-Thread Development Team
M
Ming, Bai 已提交
3
 *
4
 * SPDX-License-Identifier: Apache-2.0
M
Ming, Bai 已提交
5 6 7 8
 *
 * Change Logs:
 * Date           Author       Notes
 * 2011-12-12     Yi Qiu      first version
9
 * 2021-02-23     Leslie Lee  provide possibility for multi usb host
M
Ming, Bai 已提交
10 11 12 13
 */
#include <rtthread.h>
#include <drivers/usb_host.h>

14 15 16
#define USB_HOST_CONTROLLER_NAME      "usbh"

#if defined(RT_USBH_HID_KEYBOARD) || defined(RT_USBH_HID_MOUSE)
M
Ming, Bai 已提交
17 18 19 20 21 22
#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.
23
 *
M
Ming, Bai 已提交
24 25
 * @return none.
 */
26
rt_err_t rt_usb_host_init(const char *name)
M
Ming, Bai 已提交
27 28
{
    ucd_t drv;
29
    rt_device_t uhc;
M
Ming, Bai 已提交
30

31
    uhc = rt_device_find(name);
32 33
    if(uhc == RT_NULL)
    {
34
        rt_kprintf("can't find usb host controller %s\n", name);
35 36 37 38
        return -RT_ERROR;
    }

    /* initialize usb hub */
lymzzyh's avatar
lymzzyh 已提交
39
    rt_usbh_hub_init((uhcd_t)uhc);
M
Ming, Bai 已提交
40 41

    /* initialize class driver */
42
    rt_usbh_class_driver_init();
M
Ming, Bai 已提交
43

44
#ifdef RT_USBH_MSTORAGE
M
Ming, Bai 已提交
45
    /* register mass storage class driver */
46 47
    drv = rt_usbh_class_driver_storage();
    rt_usbh_class_driver_register(drv);
48 49 50 51 52 53 54 55 56 57
#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
M
Ming, Bai 已提交
58 59 60
#endif

    /* register hub class driver */
61 62 63 64 65
    drv = rt_usbh_class_driver_hub();
    rt_usbh_class_driver_register(drv);

    /* initialize usb host controller */
    rt_device_init(uhc);
B
bernard 已提交
66

67
    return RT_EOK;
G
guozhanxin 已提交
68
}