usbhost.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * File : usbhost.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2011, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2011-3-12 Yi Qiu first version
  13. */
  14. #include <rtthread.h>
  15. #include "usbhost.h"
  16. #include "core.h"
  17. #include "hub.h"
  18. #if defined(RT_USB_HID_KEYBOARD) || defined(RT_USB_HID_MOUSE)
  19. #include <hid.h>
  20. #endif
  21. /**
  22. * This function will initialize the usb host stack, all the usb class driver and
  23. * host controller driver are also be initialized here.
  24. *
  25. * @return none.
  26. */
  27. void rt_usbhost_init(void)
  28. {
  29. ucd_t drv;
  30. rt_device_t dev;
  31. #ifdef RT_USB_CLASS_HID
  32. uprotocal_t protocal;
  33. #endif
  34. /* initialize usb hub */
  35. rt_usb_system_init();
  36. /* initialize class driver */
  37. rt_usb_class_driver_init();
  38. #ifdef RT_USB_CLASS_MASS_STORAGE
  39. /* register mass storage class driver */
  40. drv = rt_usb_class_driver_storage();
  41. rt_usb_class_driver_register(drv);
  42. #endif
  43. #ifdef RT_USB_CLASS_HID
  44. /* register hid class driver */
  45. drv = rt_usb_class_driver_hid();
  46. rt_usb_class_driver_register(drv);
  47. #ifdef RT_USB_HID_KEYBOARD
  48. /* register hid keyboard protocal */
  49. protocal = rt_usb_hid_protocal_kbd();
  50. rt_usb_hid_protocal_register(protocal);
  51. #endif
  52. #ifdef RT_USB_HID_MOUSE
  53. /* register hid mouse protocal */
  54. protocal = rt_usb_hid_protocal_mouse();
  55. rt_usb_hid_protocal_register(protocal);
  56. #endif
  57. #endif
  58. #ifdef RT_USB_CLASS_ADK
  59. /* register adk class driver */
  60. drv = rt_usb_class_driver_adk();
  61. rt_usb_class_driver_register(drv);
  62. #endif
  63. /* register hub class driver */
  64. drv = rt_usb_class_driver_hub();
  65. rt_usb_class_driver_register(drv);
  66. #ifdef RT_USB_HCD_MUSB
  67. /* register musb host controller driver */
  68. dev = rt_usb_hcd_musb();
  69. rt_device_register(dev, "musb", 0);
  70. rt_device_init(dev);
  71. #endif
  72. #ifdef RT_USB_HCD_OHCI
  73. /* register ohci host controller driver */
  74. dev = rt_usb_hcd_ohci();
  75. rt_device_register(dev, "ohci", 0);
  76. rt_device_init(dev);
  77. #endif
  78. #ifdef RT_USB_HCD_STM32
  79. /* register ohci host controller driver */
  80. dev = rt_usb_hcd_susb();
  81. rt_device_register(dev, "susb", 0);
  82. rt_device_init(dev);
  83. #endif
  84. }