usbhost.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2011-12-12 Yi Qiu first version
  9. * 2021-02-23 Leslie Lee provide possibility for multi usb host
  10. */
  11. #include <rtthread.h>
  12. #include <drivers/usb_host.h>
  13. #define USB_HOST_CONTROLLER_NAME "usbh"
  14. #if defined(RT_USBH_HID_KEYBOARD) || defined(RT_USBH_HID_MOUSE)
  15. #include <hid.h>
  16. #endif
  17. /**
  18. * This function will initialize the usb host stack, all the usb class driver and
  19. * host controller driver are also be initialized here.
  20. *
  21. * @return none.
  22. */
  23. rt_err_t rt_usb_host_init(const char *name)
  24. {
  25. ucd_t drv;
  26. rt_device_t uhc;
  27. uhc = rt_device_find(name);
  28. if(uhc == RT_NULL)
  29. {
  30. rt_kprintf("can't find usb host controller %s\n", name);
  31. return -RT_ERROR;
  32. }
  33. /* initialize usb hub */
  34. rt_usbh_hub_init((uhcd_t)uhc);
  35. /* initialize class driver */
  36. rt_usbh_class_driver_init();
  37. #ifdef RT_USBH_MSTORAGE
  38. /* register mass storage class driver */
  39. drv = rt_usbh_class_driver_storage();
  40. rt_usbh_class_driver_register(drv);
  41. #endif
  42. #ifdef RT_USBH_HID
  43. extern ucd_t rt_usbh_class_driver_hid(void);
  44. /* register mass storage class driver */
  45. drv = rt_usbh_class_driver_hid();
  46. rt_usbh_class_driver_register(drv);
  47. #ifdef RT_USBH_HID_MOUSE
  48. {
  49. extern uprotocal_t rt_usbh_hid_protocal_mouse(void);
  50. rt_usbh_hid_protocal_register(rt_usbh_hid_protocal_mouse());
  51. }
  52. #endif
  53. #ifdef RT_USBH_HID_KEYBOARD
  54. {
  55. extern uprotocal_t rt_usbh_hid_protocal_kbd(void);
  56. rt_usbh_hid_protocal_register(rt_usbh_hid_protocal_kbd());
  57. }
  58. #endif
  59. #endif
  60. /* register hub class driver */
  61. drv = rt_usbh_class_driver_hub();
  62. rt_usbh_class_driver_register(drv);
  63. /* initialize usb host controller */
  64. rt_device_init(uhc);
  65. return RT_EOK;
  66. }