usbhost.c 2.7 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. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2011-12-12 Yi Qiu first version
  23. */
  24. #include <rtthread.h>
  25. #include <drivers/usb_host.h>
  26. #define USB_HOST_CONTROLLER_NAME "usbh"
  27. #if defined(RT_USBH_HID_KEYBOARD) || defined(RT_USBH_HID_MOUSE)
  28. #include <hid.h>
  29. #endif
  30. /**
  31. * This function will initialize the usb host stack, all the usb class driver and
  32. * host controller driver are also be initialized here.
  33. *
  34. * @return none.
  35. */
  36. rt_err_t rt_usb_host_init(void)
  37. {
  38. ucd_t drv;
  39. rt_device_t uhc;
  40. #ifdef RT_USBH_HID
  41. uprotocal_t protocal;
  42. #endif
  43. uhc = rt_device_find(USB_HOST_CONTROLLER_NAME);
  44. if(uhc == RT_NULL)
  45. {
  46. rt_kprintf("can't find usb host controller %s\n", USB_HOST_CONTROLLER_NAME);
  47. return -RT_ERROR;
  48. }
  49. /* initialize usb hub */
  50. rt_usbh_hub_init();
  51. /* initialize class driver */
  52. rt_usbh_class_driver_init();
  53. #ifdef RT_USBH_MSTORAGE
  54. /* register mass storage class driver */
  55. drv = rt_usbh_class_driver_storage();
  56. rt_usbh_class_driver_register(drv);
  57. #endif
  58. #ifdef RT_USBH_HID
  59. /* register hid class driver */
  60. drv = rt_usbh_class_driver_hid();
  61. rt_usbh_class_driver_register(drv);
  62. #ifdef RT_USBH_HID_KEYBOARD
  63. /* register hid keyboard protocal */
  64. protocal = rt_usbh_hid_protocal_kbd();
  65. rt_usbh_hid_protocal_register(protocal);
  66. #endif
  67. #ifdef RT_USBH_HID_MOUSE
  68. /* register hid mouse protocal */
  69. protocal = rt_usbh_hid_protocal_mouse();
  70. rt_usbh_hid_protocal_register(protocal);
  71. #endif
  72. #endif
  73. #ifdef RT_USBH_ADK
  74. /* register adk class driver */
  75. drv = rt_usbh_class_driver_adk();
  76. rt_usbh_class_driver_register(drv);
  77. #endif
  78. /* register hub class driver */
  79. drv = rt_usbh_class_driver_hub();
  80. rt_usbh_class_driver_register(drv);
  81. /* initialize usb host controller */
  82. rt_device_init(uhc);
  83. return RT_EOK;
  84. }