api_host.rst 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. 主机协议栈
  2. =========================
  3. CORE
  4. -----------------
  5. CLASS 驱动信息结构体
  6. """"""""""""""""""""""""""""""""""""
  7. .. code-block:: C
  8. struct usbh_class_info {
  9. uint8_t class; /* Base device class code */
  10. uint8_t subclass; /* Sub-class, depends on base class. Eg. */
  11. uint8_t protocol; /* Protocol, depends on base class. Eg. */
  12. uint16_t vid; /* Vendor ID (for vendor/product specific devices) */
  13. uint16_t pid; /* Product ID (for vendor/product specific devices) */
  14. const struct usbh_class_driver *class_driver;
  15. };
  16. 端点结构体
  17. """"""""""""""""""""""""""""""""""""
  18. .. code-block:: C
  19. typedef struct usbh_endpoint {
  20. struct usb_endpoint_descriptor ep_desc;
  21. } usbh_endpoint_t;
  22. 接口结构体
  23. """"""""""""""""""""""""""""""""""""
  24. .. code-block:: C
  25. typedef struct usbh_interface {
  26. struct usb_interface_descriptor intf_desc;
  27. struct usbh_endpoint ep[CONFIG_USBHOST_EP_NUM];
  28. char devname[CONFIG_USBHOST_DEV_NAMELEN];
  29. struct usbh_class_driver *class_driver;
  30. void *priv;
  31. } usbh_interface_t;
  32. 配置结构体
  33. """"""""""""""""""""""""""""""""""""
  34. .. code-block:: C
  35. typedef struct usbh_configuration {
  36. struct usb_configuration_descriptor config_desc;
  37. struct usbh_interface intf[CONFIG_USBHOST_INTF_NUM];
  38. } usbh_configuration_t;
  39. hubport 结构体
  40. """"""""""""""""""""""""""""""""""""
  41. .. code-block:: C
  42. typedef struct usbh_hubport {
  43. bool connected; /* True: device connected; false: disconnected */
  44. bool port_change; /* True: port changed; false: port do not change */
  45. uint8_t port; /* Hub port index */
  46. uint8_t dev_addr; /* device address */
  47. uint8_t speed; /* device speed */
  48. usbh_epinfo_t ep0; /* control ep info */
  49. struct usb_device_descriptor device_desc;
  50. struct usbh_configuration config;
  51. #if 0
  52. uint8_t* config_desc;
  53. #endif
  54. struct usb_setup_packet *setup;
  55. struct usbh_hub *parent; /*if NULL, is roothub*/
  56. } usbh_hubport_t;
  57. hub 结构体
  58. """"""""""""""""""""""""""""""""""""
  59. .. code-block:: C
  60. typedef struct usbh_hub {
  61. usb_slist_t list;
  62. uint8_t index; /* Hub index */
  63. uint8_t nports; /* Hub port number */
  64. uint8_t dev_addr; /* Hub device address */
  65. usbh_epinfo_t intin;
  66. uint8_t *int_buffer;
  67. struct hub_port_status *port_status;
  68. struct usb_hub_descriptor hub_desc;
  69. struct usbh_hubport child[CONFIG_USBHOST_EHPORTS];
  70. struct usbh_hubport *parent; /* Parent hub port */
  71. struct usb_work work;
  72. } usbh_hub_t;
  73. usbh_event_notify_handler
  74. """"""""""""""""""""""""""""""""""""
  75. ``usbh_event_notify_handler`` 是 USB 中断中的核心,用于处理不同的中断标志。包括复位、端点0 IN/OUT/SETUP、其他端点 IN/OUT 、SUSPEND、RESUME、SOF 中断等等。用于需要在 porting 接口中的 USB中断中调用该接口。
  76. .. code-block:: C
  77. void usbh_event_notify_handler(uint8_t event, uint8_t rhport);
  78. - **event** 中断事件
  79. - **rhport** roothub 端口号
  80. 其中 ``event`` 有如下类型:
  81. .. code-block:: C
  82. enum usbh_event_type {
  83. USBH_EVENT_ATTACHED,
  84. USBH_EVENT_REMOVED,
  85. };
  86. usbh_initialize
  87. """"""""""""""""""""""""""""""""""""
  88. ``usbh_initialize`` 用来初始化 usb 主机协议栈,包括:创建插拔检测用的信号量和枚举线程、高低工作队列、初始化 roothub端点0 配置,初始化 usb 主机控制器。
  89. .. code-block:: C
  90. int usbh_initialize(void);
  91. usbh_find_class_instance
  92. """"""""""""""""""""""""""""""""""""
  93. ``usbh_find_class_instance`` 根据注册的 class 名称查找对应的 class 结构体句柄。
  94. .. code-block:: C
  95. void *usbh_find_class_instance(const char *devname);
  96. - **devname** class 名称
  97. - **return** class 结构体句柄
  98. lsusb
  99. """"""""""""""""""""""""""""""""""""
  100. ``lsusb`` 用来查看和操作 hub 上的设备信息。需要借助 shell 插件使用。
  101. .. code-block:: C
  102. int lsusb(int argc, char **argv);
  103. CDC ACM
  104. -----------------
  105. HID
  106. -----------------
  107. MSC
  108. -----------------
  109. UAC
  110. -----------------
  111. UVC
  112. -----------------
  113. PORTING
  114. -----------------