1
0

usbhost.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. /* register mass storage class driver */
  44. drv = rt_usbh_class_driver_hid();
  45. rt_usbh_class_driver_register(drv);
  46. #ifdef RT_USBH_HID_MOUSE
  47. uprotocal_t protocal;
  48. protocal = rt_usbh_hid_protocal_mouse();
  49. rt_usbh_hid_protocal_register(protocal);
  50. #endif
  51. #endif
  52. /* register hub class driver */
  53. drv = rt_usbh_class_driver_hub();
  54. rt_usbh_class_driver_register(drv);
  55. /* initialize usb host controller */
  56. rt_device_init(uhc);
  57. return RT_EOK;
  58. }