usbhost.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2006-2018, 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. */
  10. #include <rtthread.h>
  11. #include <drivers/usb_host.h>
  12. #define USB_HOST_CONTROLLER_NAME "usbh"
  13. #if defined(RT_USBH_HID_KEYBOARD) || defined(RT_USBH_HID_MOUSE)
  14. #include <hid.h>
  15. #endif
  16. /**
  17. * This function will initialize the usb host stack, all the usb class driver and
  18. * host controller driver are also be initialized here.
  19. *
  20. * @return none.
  21. */
  22. rt_err_t rt_usb_host_init(void)
  23. {
  24. ucd_t drv;
  25. rt_device_t uhc;
  26. uhc = rt_device_find(USB_HOST_CONTROLLER_NAME);
  27. if(uhc == RT_NULL)
  28. {
  29. rt_kprintf("can't find usb host controller %s\n", USB_HOST_CONTROLLER_NAME);
  30. return -RT_ERROR;
  31. }
  32. /* initialize usb hub */
  33. rt_usbh_hub_init((uhcd_t)uhc);
  34. /* initialize class driver */
  35. rt_usbh_class_driver_init();
  36. #ifdef RT_USBH_MSTORAGE
  37. /* register mass storage class driver */
  38. drv = rt_usbh_class_driver_storage();
  39. rt_usbh_class_driver_register(drv);
  40. #endif
  41. /* register hub class driver */
  42. drv = rt_usbh_class_driver_hub();
  43. rt_usbh_class_driver_register(drv);
  44. /* initialize usb host controller */
  45. rt_device_init(uhc);
  46. return RT_EOK;
  47. }