docs(ext_port): Maintainers Notes for the External Port Driver

This commit is contained in:
Roman Leonov 2024-11-21 19:48:44 +08:00
parent e1c0ad9189
commit adb468bade
7 changed files with 186 additions and 28 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 38 KiB

View File

@ -129,7 +129,8 @@ USB_DOCS = ['api-reference/peripherals/usb_device.rst',
'api-reference/peripherals/usb_host/usb_host_notes_index.rst',
'api-reference/peripherals/usb_host/usb_host_notes_usbh.rst',
'api-reference/peripherals/usb_host/usb_host_notes_enum.rst',
'api-reference/peripherals/usb_host/usb_host_notes_ext_hub.rst']
'api-reference/peripherals/usb_host/usb_host_notes_ext_hub.rst',
'api-reference/peripherals/usb_host/usb_host_notes_ext_port.rst']
I80_LCD_DOCS = ['api-reference/peripherals/lcd/i80_lcd.rst']
RGB_LCD_DOCS = ['api-reference/peripherals/lcd/rgb_lcd.rst']

View File

@ -34,17 +34,23 @@ The Host Library has the following features:
- Allows multiple class drivers to run simultaneously, i.e., multiple clients of the Host Library.
- A single device can be used by multiple clients simultaneously, e.g., composite devices.
- The Host Library itself and the underlying Host Stack does not internally instantiate any OS tasks. The number of tasks is entirely controlled by how the Host Library interface is used. However, a general rule of thumb regarding the number of tasks is ``(the number of host class drivers running + 1)``.
- Allows single Hub support (If option :ref:`CONFIG_USB_HOST_HUBS_SUPPORTED` is enabled).
- Allows multiple Hubs support (If option :ref:`CONFIG_USB_HOST_HUB_MULTI_LEVEL` is enabled).
Currently, the Host Library and the underlying Host Stack has the following limitations:
.. list::
- Only supports a single device, but the Host Library's API is designed for multiple device support.
- Only supports Asynchronous transfers.
- Only supports using one configuration. Changing to other configurations after enumeration is not supported yet.
- Transfer timeouts are not supported yet.
:esp32p4: - {IDF_TARGET_NAME} contains two USB-OTG peripherals USB 2.0 OTG High-Speed and USB 2.0 OTG Full-Speed. Only the High-Speed instance is supported now.
:esp32p4: - {IDF_TARGET_NAME} cannot enumerate Low-Speed devices yet.
- The External Hub Driver: Supports only devices with the same speed as upstream port speed (e.g., Low-speed device won't work through Full-speed external Hub).
- The External Hub Driver: Remote Wakeup feature is not supported (External Hubs are active, even if there are no devices inserted).
- The External Hub Driver: Doesn't handle error cases (overcurrent handling, errors during initialization etc. are not implemented yet).
- The External Hub Driver: No Interface selection. The Driver uses the first available Interface with Hub Class code (09h).
- The External Port Driver: No downstream port debounce mechanism (not implemented yet)
:esp32p4: - The External Hub Driver: No Transaction Translator layer (No FS/LS Devices support when a Hub is attached to HS Host).
.. -------------------------------------------------- Architecture -----------------------------------------------------
@ -97,7 +103,7 @@ Therefore, in addition to the client tasks, the Host Library also requires a tas
Devices
^^^^^^^
The Host Library shields clients from the details of device handling, encompassing details such as connection, memory allocation, and enumeration. The clients are provided only with a list of already connected and enumerated devices to choose from. By default during enumeration, each device is automatically configured to use the first configuration found, namely, the first configuration descriptor returned on a Get Configuration Descriptor request. For most standard devices, the first configuration will have a ``bConfigurationValue`` of ``1``. If option :ref:`CONFIG_USB_HOST_ENABLE_ENUM_FILTER_CALLBACK` is enabled, a different ``bConfigurationValue`` can be selected, see `Multiple configuration Support`_ for more details.
The Host Library shields clients from the details of device handling, encompassing details such as connection, memory allocation, and enumeration. The clients are provided only with a list of already connected and enumerated devices to choose from. By default during enumeration, each device is automatically configured to use the first configuration found, namely, the first configuration descriptor returned on a Get Configuration Descriptor request. For most standard devices, the first configuration will have a ``bConfigurationValue`` of ``1``. If option :ref:`CONFIG_USB_HOST_ENABLE_ENUM_FILTER_CALLBACK` is enabled, a different ``bConfigurationValue`` can be selected, see `Multiple Configuration Support`_ for more details.
It is possible for two or more clients to simultaneously communicate with the same device as long as they are not communicating to the same interface. However, multiple clients can simultaneously communicate with the same device's default endpoint (i.e., EP0), which will result in their control transfers being serialized.
@ -166,8 +172,8 @@ Lifecycle
The graph above illustrates the typical lifecycle of the Host Library with multiple clients and devices. Specifically, the example involves:
- two registered clients (Client 1 and Client 2).
- two connected devices (Device 1 and Device 2), where Client 1 communicates with Device 1 and Client 2 communicates with Device 2.
- Two registered clients (Client 1 and Client 2).
- Two connected devices (Device 1 and Device 2), where Client 1 communicates with Device 1 and Client 2 communicates with Device 2.
With reference to the graph above, the typical lifecycle involves the following key stages.
@ -438,6 +444,44 @@ Configurable parameters of the USB host stack can be configured with multiple op
* For reset recovery interval, refer to :ref:`CONFIG_USB_HOST_RESET_RECOVERY_MS`.
* For ``SetAddress()`` recovery interval, refer to :ref:`CONFIG_USB_HOST_SET_ADDR_RECOVERY_MS`.
Downstream Port Configuration
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
When external Hubs feature is supported, there are several parameters which could be configured for the external Hubs port.
Each external Hub has a Hub Descriptor which describes the device characteristics.
.. note::
For detailed information about Hub Descriptor, please refer to `USB 2.0 Specification <https://www.usb.org/document-library/usb-20-specification>`_ > Chapter 11.23.2.1 *Hub Descriptor*.
Configurable parameters of the downstream port can be configured with multiple options via Menuconfig.
* For custom value to stabilize the power after powering on the port (PwrOn2PwrGood value), refer to :ref:`CONFIG_USB_HOST_EXT_PORT_CUSTOM_POWER_ON_DELAY_MS`.
* For reset recovery interval, refer to :ref:`CONFIG_USB_HOST_EXT_PORT_RESET_RECOVERY_DELAY_MS`.
.. note::
The specification claims, that for a hub with no power switches, PwrOn2PwrGood must be set to zero. Meanwhile, for some devices, this value could be increased to give extra time for device to power-up. To enable this feature, refer to :ref:`CONFIG_USB_HOST_EXT_PORT_CUSTOM_POWER_ON_DELAY_ENABLE`.
Host Channels
"""""""""""""
When external Hubs support feature is enabled (:ref:`CONFIG_USB_HOST_HUBS_SUPPORTED`), the amount of Host channels plays important role, as each downstream device requires vacant channel.
To handle each attached device, different amount of channels are required. This amount does depend on the device class (EPs number).
Supported amount of channels for {IDF_TARGET_NAME} is {OTG_NUM_HOST_CHAN}.
.. note::
- One free channel is required to enumerate the device.
- From 1 to N (when N - number of EPs) free channels are required to claim the interface.
- When there are no more free Host channels available, the device could not be enumerated and its interface cannot be claimed.
Multiple Configuration Support
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,85 @@
USB Host External Port Driver (Ext Port)
========================================
Introduction
------------
The External Port Driver (henceforth referred to as Ext Port Driver) isolates the handling process for downstream facing ports, which are provided by the Ext Hub Driver.
.. note::
For more detailed information, please refer to `USB 2.0 Specification <https://www.usb.org/document-library/usb-20-specification>`_ > Chapter 11.5 **Downstream Facing Ports**.
Requirements
------------
Host Stack Requirements
^^^^^^^^^^^^^^^^^^^^^^^
The Ext Port Driver takes into consideration the requirements set for the overall Host Stack (see :doc:`./usb_host_notes_design`):
- The Ext Port Driver must not instantiate any tasks/threads
- The Ext Port Driver must be event driven, providing event callbacks and an event processing function
- The Ext Port Driver must use only API from underlying layer (The Ext Hub Driver)
Implementation & Usage
----------------------
Host Stack Interaction
^^^^^^^^^^^^^^^^^^^^^^
The Ext Port Driver is a part of The Ext Hub Driver, so the interaction and hierarchical place in USB Host Stack is the same as for the Ext Hub Driver. The Ext Hub and the Ext Port Drivers were split into two Drivers to achieve the goal of logic distinguishing between external Hubs and Downstream Facing Ports handling.
Ports handling
^^^^^^^^^^^^^^^
The Ext Port Driver can be installed via ``ext_port_install()`` call and uninstalled via ``ext_port_uninstall()`` call.
After installation, the Ext Port Driver API could be requested via ``ext_port_get_driver()`` call.
The Ext Port Driver API
-----------------------
The Ext Port Driver provides an API, which could be split into three groups: object control, device control and general.
The Ext Port Driver: Object Control
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Create object
- Delete object
The Ext Port Driver: Port Control
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Reset
- Disable
- Recycle
- Activate
- Get Speed
- Get status
- Set status
- Gone
The Ext Port Driver: General Purpose
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Request processing
Events & Processing
-------------------
The Ext Port Driver is completely event driven and all event handling is done via the ``ext_port_process()`` function. The ``ext_port_driver_config_t.proc_req_cb`` callback provided on the Ext Port Driver installation will be called when processing is required. Typically, ``ext_port_process()`` will be called from the Hub Driver ``hub_process()`` processing function.
The Ext Port Driver exposes the following events via ``ext_port_driver_config_t.event_cb``:
- ``EXT_PORT_CONNECTED`` Downstream facing port has a device connection event
- ``EXT_PORT_RESET_COMPLETED`` Downstream facing port has a device and completed the port reset
- ``EXT_PORT_DISCONNECTED`` Downstream facing port has a device disconnection event
The Ext Port Driver ports processing is based on the Hub class-specific request ``Get Port Status``.
After successful completion of the class-specific request ``Get Port Status`` and setting the new port status, the Ext Port Driver continues the port handling while it is required by ports' state and status.
.. note::
For more detailed information, please refer to `USB 2.0 Specification <https://www.usb.org/document-library/usb-20-specification>`_ > Chapter 11.24.2.7 **Get Port Status**

View File

@ -24,6 +24,7 @@ This document is split into the following sections:
usb_host_notes_usbh
usb_host_notes_enum
usb_host_notes_ext_hub
usb_host_notes_ext_port
Todo:
@ -40,21 +41,3 @@ Introduction
The ESP-IDF USB Host Stack allows the {IDF_TARGET_NAME} to operate as a USB Host. Operating as a USB Host allows the {IDF_TARGET_NAME} to communicate with a wide range of USB devices. However, most USB Host Stack implementations do not run on embedded hardware (i.e., runs on PCs and smartphones), thus have comparatively more resources (i.e., memory and CPU speed).
The implementation of the ESP-IDF USB Host Stack (henceforth referred to as the Host Stack) takes into account the embedded nature of the {IDF_TARGET_NAME} which is reflected in various aspects of the Host Stack's design.
Features & Limitations
^^^^^^^^^^^^^^^^^^^^^^
**The Host Stack currently supports the following notable features:**
.. only:: esp32p4
- Supports HS (High Speed)
- Supports FS (Full Speed) and LS (Low Speed) devices
- Supports all transfer types (Control, Bulk, Isochronous, and Interrupt)
- Automatically enumerates connected devices
- Allows multiple class drivers (i.e., Clients of the USB Host Library) to run simultaneously and share the same device (i.e., composite devices)
**The Host Stack currently has the following notable limitations:**
- No Hub support (currently only supports a single device)

View File

@ -18,7 +18,7 @@ USB 主机库(以下简称主机库)是 USB 主机栈的最底层,提供
然而,由于以下的某些原因(但不仅限于此),有时你可能需要直接使用主机库:
- 需要实现自定义主机 Class 驱动程序
- 需要更低级别的抽象
- 需要更低级别的 USB 主机 API
特性和限制
^^^^^^^^^^^^^^^^^^^^^^
@ -34,17 +34,23 @@ USB 主机库(以下简称主机库)是 USB 主机栈的最底层,提供
- 支持多个 Class 驱动程序同时运行,即主机的多个客户端同时运行。
- 单个设备可以由多个客户端同时使用,如复合设备。
- 主机库及其底层主机栈不会在内部自动创建操作系统任务,任务数量完全由主机库接口的使用方式决定。一般来说,任务数量为 ``(运行中的主机 Class 驱动程序数量 + 1``
- 支持单个 Hub启用选项 :ref:`CONFIG_USB_HOST_HUBS_SUPPORTED`)。
- 支持多个 Hub启用选项 :ref:`CONFIG_USB_HOST_HUB_MULTI_LEVEL`)。
目前,主机库及其底层主机栈存在以下限制:
.. list::
- 仅支持单个设备,而主机库的 API 支持多设备。
- 仅支持异步传输。
- 仅支持使用发现的首个配置,尚不支持变更为其他配置。
- 尚不支持传输超时。
:esp32p4: - {IDF_TARGET_NAME} 包含两个 USB-OTG 外设USB 2.0 OTG 高速和 USB 2.0 OTG 全速。目前仅支持高速实例。
:esp32p4: - {IDF_TARGET_NAME} 目前无法枚举低速设备。
- 外部 Hub 驱动:仅支持与上游端口速率相同的设备。(例如,低速设备无法通过全速外部 Hub 工作。)
- 外部 Hub 驱动:不支持远程唤醒功能(即使没有设备插入,外部 Hub 也处于工作状态)。
- 外部 Hub 驱动:不处理错误用例(尚未实现过流处理、初始化错误等功能)。
- 外部 Hub 驱动:不支持接口选择。驱动程序使用具有 Hub 类代码 (09h) 的第一个可用接口。
- 外部端口驱动:无下游端口去抖动机制(尚未实现)。
:esp32p4: - 外部 Hub 驱动:无事务转换层(当 Hub 连接到高速主机时,不支持全速/低速设备)。
.. -------------------------------------------------- Architecture -----------------------------------------------------
@ -97,7 +103,7 @@ USB 主机库(以下简称主机库)是 USB 主机栈的最底层,提供
设备
^^^^^^^
主机库隔离了客户端与设备处理的细节,包括连接、内存分配和枚举等,客户端只需提供已连接且已枚举的设备列表供选择。默认情况下,在枚举过程中,每个设备都会自动配置为使用找到的第一个配置,即通过获取配置描述符请求返回的第一个配置描述符。对于大多数标准设备,通常将第一个配置的 ``bConfigurationValue`` 设置为 ``1``。启用选项 :ref:`CONFIG_USB_HOST_ENABLE_ENUM_FILTER_CALLBACK` 后,可以选择不同的 ``bConfigurationValue``。获取更多详细信息,请参阅 `Multiple configuration Support_`
主机库隔离了客户端与设备处理的细节,包括连接、内存分配和枚举等,客户端只需提供已连接且已枚举的设备列表供选择。默认情况下,在枚举过程中,每个设备都会自动配置为使用找到的第一个配置,即通过获取配置描述符请求返回的第一个配置描述符。对于大多数标准设备,通常将第一个配置的 ``bConfigurationValue`` 设置为 ``1``。启用选项 :ref:`CONFIG_USB_HOST_ENABLE_ENUM_FILTER_CALLBACK` 后,可以选择不同的 ``bConfigurationValue``。获取更多详细信息,请参阅 `多项配置支持`_
只要不与相同接口通信,两个及以上的客户端可以同时与同一设备通信。然而,多个客户端同时与相同设备的默认端点(即 EP0通信将导致它们的控制传输序列化。
@ -438,6 +444,44 @@ USB 设备可能是热插拔的,因此必须配置电源开关和设备连接
* :ref:`CONFIG_USB_HOST_RESET_RECOVERY_MS` 用于配置重置恢复时间。
* :ref:`CONFIG_USB_HOST_SET_ADDR_RECOVERY_MS` 用于配置 ``SetAddress()`` 恢复时间。
下游端口配置
^^^^^^^^^^^^
当支持外部 Hub 功能时,可以为外部 Hub 端口配置多个参数。
每个外部 Hub 都有一个 Hub 描述符,用于描述设备特性。
.. note::
有关 Hub 描述符的详细信息,请参考 `USB 2.0 规范 <https://www.usb.org/document-library/usb-20-specification>`_ > 章节 11.23.2.1 *Hub Descriptor*
可以通过 Menuconfig 配置下游端口的可配置参数。
* 对于在端口上电后稳定电源的自定义值PwrOn2PwrGood 值),请参阅 :ref:`CONFIG_USB_HOST_EXT_PORT_CUSTOM_POWER_ON_DELAY_MS`
* 对于复位恢复间隔,请参阅 :ref:`CONFIG_USB_HOST_EXT_PORT_RESET_RECOVERY_DELAY_MS`
.. note::
规范规定,对于没有电源开关的 HubPwrOn2PwrGood 必须设置为零。同时,对于某些设备,可以增加此值以提供额外的上电时间。如需启用此功能,请参考 :ref:`CONFIG_USB_HOST_EXT_PORT_CUSTOM_POWER_ON_DELAY_ENABLE`
主机通道
"""""""""""""
当启用外部 Hub 支持功能(:ref:`CONFIG_USB_HOST_HUBS_SUPPORTED`)时,主机通道的数量非常重要,因为每个下游设备都需要空闲通道。
每个连接的设备需要不同数量的通道而所需通道数则取决于设备类别EP 数量)。
对于 {IDF_TARGET_NAME},支持的通道数量为 {OTG_NUM_HOST_CHAN}。
.. note::
- 需要一个空闲通道来枚举设备。
- 需要 1 到 NN 为 EP 数量)个空闲通道来占用接口。
- 如果所有的主机通道都已经被占用,则设备无法进行枚举,也无法获取接口。
多项配置支持
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1 @@
.. include:: ../../../../en/api-reference/peripherals/usb_host/usb_host_notes_ext_port.rst