Commit Graph

113 Commits

Author SHA1 Message Date
Tomas Rezucha
440f3308ab fix(usb/host): Fix occasional ISOC scheduler skipping transfers 2024-07-12 08:18:42 +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
morris
344db9a7e7 Merge branch 'feature/usb_hs_periodic_scheduler_v5.2' into 'release/v5.2'
feat(usb/host): Update ISOC scheduler for HS endpoints (backport 5.2)

See merge request espressif/esp-idf!29399
2024-03-07 10:03:20 +08:00
Tomas Rezucha
e3f811b5b8 feat(usb/host): Update ISOC scheduler for HS endpoints
USB-OTG uses 'sched_info' field of HCTSIZ register to schedule transactions
in USB microframes.
2024-03-04 10:00:35 +01:00
Darian Leung
50282f1e7a
fix(usb): Fix bug where usbh_process() misses an event
This commit fixes a bug where if multiple concurrent USBH API calls trigger
multiple events on the same device, some events will be lost. As a result,
those lost events don't get processed by the subsequent usbh_process() call.
2024-02-29 16:02:30 +08:00
Peter Marcisovsky
d786f187e9 feat(us/host): set device cfg during enumeration
- user callback funciton to set device configuration
      as a part of usb_host_install
    - callback provides device descriptor of a device being enumerated
    - user can set which cfg descriptor the USB device will be set with
    - user can filter device enumeration
    - Kconfig menu to enable callback function
    - usb_host_lib example demonstration
2024-02-21 12:34:04 +01:00
Darian Leung
b07a43e630
refactor(soc): Rename usb_otg_periph to usb_dwc_periph
- Renamed usb_otg_periph.h/c to usb_dwc_periph.h/c to match naming convention
of other DWC OTG related files
- Added compatibility header for usb_otg_periph.h
2024-02-19 15:45:04 +08:00
Darian Leung
2f6e45c79b
refactor(usb): Deprecate CONFIG_USB_OTG_SUPPORTED, use SOC_USB_OTG_SUPPORTED instead
Previously, USB build dependencies used the CONFIG_USB_OTG_SUPPORTED. However,
they could depend on `soc_caps.h` instead.
2024-02-19 15:45:02 +08:00
Darian Leung
f0219b73f9
refactor(hal/usb): Rename usb_fsls_phy API to match header/source names
Note: Also fixed some formatting issues in usb_wrap_struct.h
2024-02-19 15:45:02 +08:00
Darian Leung
f2ede42191
refactor(hal/usb): Rename usb_phy files to usb_fsls_phy
This commit renames USB PHY related HAL files from "usb_phy_xxx" to
"usb_fsls_phy_xxx" since they are only designed to support Full-Speed/Low-Speed
Serial USB PHYs. This renmaing is done to accommodate future USB PHYs that use
other PHY interfaces (e.g., UTMI, ULPI etc).
2024-02-19 15:45:01 +08:00
Darian Leung
3964fb2d04
refactor(usb/host): reformat code with astyle_py 2024-02-19 15:45:00 +08:00
Tomas Rezucha
1e2c271bd0
fix(usb/host): Correctly parse bInterval field in HighSpeed EP descriptors
For LS and FS interrupt endpoint: interval = bInterval
For isochronous and HS interrupt endpoint: interval = 2^(bInterval-1)
2024-02-19 15:44:59 +08:00
Tomas Rezucha
0ce4aa114e
fix(usb/host): Correctly parse MPS fields in HighSpeed EP descriptors
Bits [11,12] in HighSpeed periodic endpoints specify
the number of additional transaction opportunities per microframe
2024-02-19 15:44:59 +08:00
Darian Leung
b7c3f01ac8
change(usb/host): Remove some handler function event flags
This commit removes internal event flags in the USB Host Library event handling
functions (i.e., usb_host_lib_handle_events() and usb_host_client_handle_events()).

Previously, these flags were added to reduce the number of times semaphores
were given. However, these flags were removed as the performance gain is
negligible and made the logic more complicated.

For usb_host_client_handle_events(), the following flags were removed:

- Remove 'events_pending' flag. The semaphore is now always given
- Remove 'blocked' flag. The 'handling_events' flag is already sufficient
- Critical sections are now shortened due to simplication of semaphore usage.

For usb_host_lib_handle_events(), the following flags were removed:

- Remove 'process_pending' flag. The semaphore is now always given
- Renamed 'blocked' flag to 'handling_events'
2024-02-19 06:57:31 +08:00
Darian Leung
d9de61cbad
change(usb/host): Remove data buffer headers from URBs
This commit removes the ability to reserve a header in the data buffer of an
allocated URB. The header was required for a now defunct implementation of a
synchronous USB Host library API. Thus, headers are no longer required in
URB data buffers.
2024-02-19 06:57:30 +08:00
Tomas Rezucha
9b40d39120 refactor(usb/host): Move FIFO size configuration to HAL layer
The logic of calculating FIFO sizes is DWC OTG specific.
We move it to the HAL layer to provide better abstraction in the HDC layer.
2023-12-21 10:34:56 +01:00
Tomas Rezucha
71cd4df75a refactor(usb/host): Make private hal types USB_DWC specific 2023-12-21 10:34:46 +01:00
Tomas Rezucha
42277ac868 feat(usb/host): Add High Speed enumeration types 2023-12-21 10:33:49 +01:00
Roman Leonov
bc2ef597a4 fix(usb/host): remove bInterval verification during pipe opening for INTR and ISOC EPs 2023-12-05 16:44:53 +01:00
Tomas Rezucha
4cf3acb594 fix(usb/host): Do not abort on string descriptor overflow
Some devices return full LANGID table, even if short LANGID table was requested.
No memory overflow occurs, because we have allocated enough memory for transfers to the
default pipe. So we can ignore the error and continue with string desc fetching.
2023-12-05 16:44:53 +01:00
Darian Leung
af4991fb39 refactor(hal/usb_dwc): Add DWC OTG configuration values
This commit adds a subset of the DWC OTG configuration values to the
'usb_dwc_ll.h' file. Only relevant configuration values have been added.

Some DWC OTG releated constants have also been moved from 'usb_dwc_hal.h'
to 'usb_dwc_ll.h' and renamed.
2023-12-05 16:44:53 +01:00
wuzhenghui
b7f1aa5292 fix(esp_hw_support): fix lightsleep current leakage on usb-phy controlled pad 2023-11-16 17:18:43 +08:00
Jakob Hasse
548022fbe6 refactor(linux): excluded all non-Linux components from build
* All components which won't build (yet) on Linux are excluded.
  This enables switching to Linux in an application without
  explicitly setting COMPONENTS to main in the main
  CMakeLists.txt.
* ESP Timer provides headers for Linux now
* automatically disabling LWIP in Kconfig if it is not available

doc(linux): brought section
  "Component Linux/Mock Support Overview" up to date
2023-10-16 17:06:54 +08:00
Chen Yudong
2e11919f70 fix(ci): change build-test-rules files folder 2023-09-20 19:17:06 +08:00
Darian Leung
287bdc5e61 fix(test_apps): Trim builds of component test apps
Some component test apps do not use the "set(COMPONENTS main)" command in their
project level "CMakeLists.txt", thus leading to their builds pulling in all
ESP-IDF components.

This commit trims the build of multiple component test apps:

- Add "set(COMPONENTS main ...)" to project level "CMakeLists.txt"
- Add missing "PRIV_REQUIRES" in some "main" component "CMakeLists.txt"

Also removed repeated configuraiton options in legacy_i2c_driver/sdkconfig.ci.defaults
as they are already specified in legacy_i2c_driver/sdkconfig.defaults
2023-09-18 17:16:37 +08:00
Roman Leonov
c29db70510 bugfix(usb/host): Fix transfer direction determination during argument checking for regular EP transfer 2023-09-13 21:55:34 +02:00
Roman Leonov
e297470e62 Merge branch 'bugfix/usb/host/urb_compliance_verification_add' into 'master'
feature(usb/host) added URB check args and transfer check compliance for regular EP transfer submit

See merge request espressif/esp-idf!24106
2023-08-03 16:20:49 +08:00
Darian Leung
a1ed398481 usb_host: Fix coverity issues with hcd_install()
- Use single "err_ret" variable for returning errors
- Simplify bail out procedure by using more labels
2023-06-21 17:50:20 +08:00
morris
8885d20482 usbh: fix invalid assert on desc_status 2023-06-19 10:59:46 +08:00