140 Commits

Author SHA1 Message Date
morris
1a49691899 Merge branch 'feature/usb_host_hub_support_collective_backport_p3_v5.2' into 'release/v5.2'
feat(usb_host): Hub Support Collective backport part 3/3 (v5.2)

See merge request espressif/esp-idf!33283
2024-11-20 10:40:09 +08:00
Daniel Mangum
38e9c8dbdf fix(usb_host): return ESP_ERR_NO_MEM on failed alloc in client register
Fixes issue where ESP_ERR_NO_MEM was being silently discarded after
cleaning up after a failed malloc in usb_host_client_register.

Signed-off-by: Daniel Mangum <georgedanielmangum@gmail.com>
2024-11-13 10:03:08 +01:00
Roman Leonov
1618fd8a0f refactor(usb_host): Removed error in enum when stalled, added hcd_dwc no more free channels 2024-10-25 12:31:39 +02:00
Roman Leonov
bb23c18edd fix(ext_port): Added port recovery delay 2024-10-25 12:30:31 +02:00
Roman Leonov
d83c477422 refactor(usb_host/examples): Enabled external Hub support feature 2024-10-18 10:46:53 +02:00
Roman Leonov
e62df280e0 feat(ext_port): Added External Port driver 2024-10-18 10:46:51 +02:00
morris
dc45972144 Merge branch 'feat/usb_disconnect_api_backport_v5.2' into 'release/v5.2'
refactor(usb): Update HCD tests to use port power off for disconnections backport v5.2

See merge request espressif/esp-idf!33526
2024-10-17 17:00:59 +08:00
Peter Marcisovsky
7aece79530 fix(usb_host): Update log level and error poropagation 2024-10-10 12:51:06 +02:00
Peter Marcisovsky
f02ee8ef5d refactor(usb_host): Fixed function return values in usb_host stack:
- updated doxygen for the whole usb_host stack
    - doxygen for test_apps is not updated
    - fixed error codes propagation problems in the usb_host stack
2024-10-10 12:51:06 +02:00
Tomas Rezucha
d2a8b5e577 fix(usb/host): Correctly handle unpowered port in HUB 2024-10-09 11:16:17 +02:00
Darian Leung
62a3b50c94 refactor(usb): Remove use of usb_phy_action() from unit tests
Currently, USB Host unit tests that require a software triggered disconnection/
reconnection rely on the 'usb_phy_action()' function.

This commit replaces those calls with 'hcd_port_command()' or
'usb_host_lib_set_root_port_power()'.

Note: Also removed 'test_usb_common.h/c' as it is no longer necessary are the
function call replacements.
2024-10-09 11:16:17 +02:00
Darian Leung
dc838f6123 feat(usb): Add usb_host_lib_set_root_port_power()
This commit adds the usb_host_lib_set_root_port_power() function. This provides
a public API for users to power the root port OFF or ON at runtime, thus trigger
a disconnection or allow connections respectively.

In addition, the usb_host_config_t.root_port_unpowered install configuration is
provided to allow users to install the USB Host Library without automatically
powering ON the root port.
2024-10-09 11:16:17 +02:00
Roman Leonov
e1feca0d48 refactor(hub): Cleaned up dev_tree_node debug output, moved node freeing 2024-09-06 22:53:50 +02:00
Roman Leonov
3d2edb47bb refactor(ext_hub): Prerequisites for the Ext Port Driver 2024-09-06 10:37:01 +02:00
Roman Leonov
5b346ca9d8 fix(usb_host): The Enumeration Driver, cancellation on error 2024-09-06 10:37:01 +02:00
Roman Leonov
ec6f52a717 feat(ext_hub): Added External Hub driver 2024-09-06 10:02:38 +02:00
Roman Leonov
59be21b763 fix(usb_host): Increased address map for clients and changed the uid member type 2024-09-06 10:02:37 +02:00
Tomas Rezucha
9f0ef05192 fix(enum): Returned usb_round_up_to_mps for control request of string descriptors 2024-09-06 10:02:37 +02:00
Roman Leonov
38bb90dd9a feat(hub): Added device tree nodes list and uid calculation logic 2024-09-06 10:02:37 +02:00
Roman Leonov
c5ee01dd0b fix(enum): Fixed STALL on descriptor request, removed unused value 2024-09-06 10:02:37 +02:00
Roman Leonov
410a6a21c5 refactor(enum): Curved out Enumeration process from Hub Driver 2024-09-06 10:02:37 +02:00
Roman Leonov
284b978cb4 refactor(hub): Updated HUB api for ENUM driver 2024-09-06 10:02:37 +02:00
Roman Leonov
30681356d8 refactor(usbh): Updated USBH api for ENUM driver 2024-09-06 10:02:37 +02:00
Alexey Lapshin
3759f41b94 fix(usb): fix warnings found by GNU static analyzer 2024-08-21 14:05:31 +07:00
morris
a536949363 Merge branch 'feature/usb_host_multi_configuration_backport_v5.2' into 'release/v5.2'
feat(usb/host): multiconfiguration support backport (v5.2)

See merge request espressif/esp-idf!32055
2024-08-02 11:44:12 +08:00
Peter Marcisovsky
597451afbe refactor(usb_host): Update USB Host multiconfig public API
- previous usb_host_get_config_desc_free()
    - updated usb_host_free_config_desc()
2024-07-17 09:02:43 +02:00
Tomas Rezucha
440f3308ab fix(usb/host): Fix occasional ISOC scheduler skipping transfers 2024-07-12 08:18:42 +02:00
Peter Marcisovsky
8611a66a0f feat(usb/host): multiconfiguration support
- usb host reads device's configuration on request
    - a control transfer is sent
    - memory is allocated for a new descriptor
    - user must manually free the memory
2024-07-11 11:28:52 +02:00
Tomas Rezucha
49d9fc0250 fix(usb/host): Decode error flags in ISOC transfers 2024-07-03 09:15:53 +02:00
Darian Leung
ae9a280ca1
fix(usb): Make string descriptor checks in unit tests optional
Checking for an exact match for product or serial and string descriptors can
lead to test failures if the USB devices connected to the runner is changed. This
commit adds some kconfig options to make the string descriptor checks optional,
with the product and serial string checks being disabled by default.
2024-06-09 12:36:25 +08:00
Darian Leung
6ead402d15
refactor(usb): Split test device descriptors from mock class files
Previously, descriptors of the test devices were stored direclty in the mock
device files (e.g., "mock_[hid|msc].[h|c]"). This commit splits out the device
descriptors to separate files (e.g., "dev_[hid|msc].c") along with getter
functions.

Users that want to run the tests locally on a different device simply need to
update the "dev_[hid|msc].c" file for their device.
2024-06-09 12:19:53 +08:00
Darian Leung
edd41c24c3
refactor(usb): Rename mock class files
- Rename "test_usb_mock_..." class files to "mock_..."
- Fixed some codespell issues
- Fixed comment spacing
2024-06-09 11:30:03 +08:00
morris
f0a69d8a0c Merge branch 'feature/usb_host_hub_support_collective_backport_v5.2' into 'release/v5.2'
refactor(usb/host): Prerequisite Refactoring For Hub Collective backport (v5.2)

See merge request espressif/esp-idf!29448
2024-06-07 13:12:51 +08:00
Darian Leung
36de16d97c
refactor(hal/usb): Add new USB PHY related HAL API
This commit adds/updates the USB PHY related HAL APIs. The following changes
are made:

- Updated 'usb_wrap_hal.h' API
- Added 'usb_serial_jtag_hal.h' API
2024-06-04 20:35:49 +08:00
Darian Leung
d944e85a57
feat(hal/usb): Update USB WRAP and USJ LL
- Added LL cap macros to distinguish feature differences between the LLs of
  different targets:
    - '..._LL_EXT_PHY_SUPPORTED' indicates whether the USB WRAP/USJ supports
      routing to an external FSLS PHY.
- Tidied up some RCC LL functions and their callers.
- Added 'usb_wrap_types.h' and 'usb_serial_jtag_types.h' to provide types used
  in LLs.
- Fixed some spelling/naming issues as part of code-spell pre-commit
2024-06-04 20:35:49 +08:00
Darian Leung
14a581939c
refactor(hal/usb): Refactor usb_wrap_ll.h
This commit rewrite the 'usb_wrap_ll.h' API as follows:

- All APIs renamed from 'usb_fsls_phy_ll_...()' to 'usb_wrap_ll_...()'
- APIs now match their equivalent counter parts in 'usb_serial_jtag_ll.h'
2024-06-04 20:35:48 +08:00
Darian Leung
81f6d7abbe
refactor(hal/usb): Remove usb_fsls_phy_ll.h
For targets that only contain a USJ peripheral (and not a DWC OTG), their
'usb_fsls_phy_ll.h' headers only contain a single function
('usb_fsls_phy_ll_int_jtag_enable()') whose feature is already covered by
functions in 'usb_serial_jtag_ll.h'. Thus, this header is redundant.

This commit does the following:

- Remove 'usb_fsls_phy_ll.h' for targets that only contain a USJ peripheral
- Rename 'usb_fsls_phy_[hal|ll].[h|c]' to `usb_wrap_[hal|ll].[h|c]` for targets
that contain a DWC OTG peripheral. This better reflects the underlying peripheral
that the LL header accesses.
2024-06-04 20:35:47 +08:00
Darian Leung
64faf3aa9f
refactor(usb/usbh): Update USBH device creation and enumeration handling
This commit updates how the USBH handles device creation and enumeration so that
upper layers (such as the Hub driver) can use the USBH API for enumeration instead
of calling the HCD.

USBH Updates:

USBH now creates unenumerated devices set to address 0 with no device/config
descriptor. A newly created device can be opened and communicated with immediately
(using control transfers). This allows the Hub driver to call the USBH instead of
the HCD. Summary of USBH changes:

- Added new APIs to add/remove a device. Devices are now created as unenumerated
and can be immediately opened and communicated with.
- Added new APIs to enumerate a device (see 'usbh_dev_set_...()' functions). Device
must be locked (see 'usbh_dev_enum_lock()') before enumeration functions can be called.
- Added UID for each device. This allows the particular USBH without needing to
use the device's handle (which implies opening the device).

Hub Driver Updates:

Hub driver now calls the USBH for enumeration. Summary of USBH changes:

- Replace all 'hcd_pipe_...()' calls with 'usbh_dev_...()' calls
- Refactored port event handling to fit with new USBH API
- Updated to use UID to uniquely identify devices without opening them

USB Host Updates:

- Reroute USBH control transfers to clients and hub driver
2024-06-04 20:34:57 +08:00
Darian Leung
9141d48b41
refactor(usb/hub): Update Hub driver port request logic 2024-06-04 20:34:57 +08:00
Darian Leung
0c8ec63c10
refactor(usb/hcd): Allow port resets with allocated pipes
This commit updates the HCD API to allow port resets to occur even if pipes
are allocated. The pipes cannot be active and the port reset will simply
restore the pipes (by reinitializing their channel registers) following the
reset.

Changes:

- Allow port resets while channels are allocated
- Remove pipe persistance API 'hcd_pipe_set_persist_reset()'
2024-06-04 20:34:56 +08:00
Darian Leung
fe206dab59
refactor(usb/usbh): Rename device pool functions and ref_count
This commit renames the following APIs and variables in the USBH:

- Rename the prefix of device pool functions from 'usbh_dev_...' to
  'usbh_devs_...'.
- Rename 'ref_count' to 'open_count'. This variable tracks the number of times
  a device has been opened.
2024-06-04 20:34:55 +08:00
Darian Leung
72d6c31ac7
refactor(usb/host): Refactor USBH function grouping
This commit rearranges the USBH functions into new groupings to provide a
clearer abstraction. This is in preparation for refactoring/removing the Hub
related functions in the USBH API. This commit DOES NOT MAKE ANY BEHAVIORAL
CHANGES to the code.

Functions are now grouped into...

- USBH Processing: Functions dealing with overall USBH processing
- Device Pool: Functions that add/remove/open/close devices from the internal
               device pool
- Device: Functions that pertain to setting/getting a particular device
- Endpoints: Functions that pertain to a particular endpoint
- Transfer: Functions that pertain to sending transfers
2024-06-04 20:34:55 +08:00
Roman Leonov
32a7719177
refactor(hcd_dwc): Added mps request from hcd_dwc 2024-06-04 20:34:54 +08:00
Darian Leung
455674ae8c
refactor(usb/host): Simplify USBH and Hub interaction
Previously, on a device disconnection, the USBH and Hub would the require the
following 2-way interaction:

- Hub -> usbh_hub_pass_event() -> USBH to indicate a port error
- USBH -> usbh_hub_req_cb_t -> Hub to request port recovery after the device
has been freed.

The 2-way interaction has been simplified:

- USBH now nofities upper layers of devices being freed via the
USBH_EVENT_DEV_FREE event
- Hub now handles port recovery only after a device has been freed
2024-06-04 20:34:54 +08:00
Roman Leonov
4139edba23
refactor(usb_host): Renamed hub_driver_state to root_port_state 2024-06-04 20:34:53 +08:00
Tomas Rezucha
6913f2721f
feat(usb/host): Add missing sync types from USB specification 2024-06-04 20:34:52 +08:00
Roman Leonov
7ae41ebd8b
feat(usb_host): Added KConfig parameter for External HUB support enable 2024-06-04 20:34:52 +08:00
Roman Leonov
2d6aae5aa3
refactor(usb_host): Added chapter11 header, refactor chapter9 header 2024-06-04 20:34:51 +08:00
Darian Leung
95e6dd3884
refactor(usb): Remove USBH control transfer callback
This commit merges the USBH control transfer callback into the USBH event
callback. This simplifies the code as the USBH now uses a single callback.
2024-06-04 20:34:50 +08:00
Darian Leung
83a629f68b
refactor(usb): Update USBH event callback arguments
This commit does the following:

- Updates the USBH event callback arguments to now pass a usbh_event_data_t
which can contain different data for each event
- Updated event names
2024-06-04 20:34:50 +08:00