feat(usb_device): Config::port to pick the USB-OTG port (ESP32-P4) - #802
Merged
Merged
Conversation
esp_tinyusb's tinyusb_config_t.port selects the peripheral on targets with two USB-OTG controllers; TinyUSB defaults to the high-speed port on the ESP32-P4. Boards do not always route that port to a device-capable connector (the M5Stack Tab5 wires it to its USB-A host jack; its USB-C carries the full-speed port), so let the application choose: -1 keeps the TinyUSB default, otherwise the value is validated against TINYUSB_PORT_MAX and passed through. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BAeyJSuzVyqvSe4mffGUZo
|
✅Static analysis result - no issues found! ✅ |
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Fix validation for values below -1 and update the published documentation.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (2)
What changed in this PR
Adds configurable USB-OTG port selection for UsbDevice, primarily supporting ESP32-P4 boards.
Changes:
- Adds
Config::portwith-1preserving TinyUSB’s default. - Applies selected port configuration and documents ESP32-P4/Tab5 usage.
- Requires stricter validation and documentation updates before approval.
| File | Summary | Findings |
|---|---|---|
components/usb_device/src/usb_device.cpp |
Applies the selected TinyUSB port. | Moderate: reject values below -1 (3 votes). |
components/usb_device/README.md |
Documents port selection and the Tab5 use case. | Nit: update linked usb_cdc.rst documentation (3 votes). |
components/usb_device/include/usb_device.hpp |
Adds Config::port. |
None. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+1499
to
+1500
| if (config_.port >= 0) { | ||
| if (config_.port >= static_cast<int>(TINYUSB_PORT_MAX)) { |
Comment on lines
+82
to
+85
| - **Port selection** (`Config::port`): on targets with two USB-OTG | ||
| controllers (ESP32-P4) pick the full-speed or the high-speed port; boards do | ||
| not always route the high-speed port to a device-capable connector (the | ||
| M5Stack Tab5's USB-C carries the full-speed port). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
UsbDevice::Config::port(default -1 = TinyUSB's default for the target) selects the USB-OTG peripheral through esp_tinyusb'stinyusb_config_t.port, validated againstTINYUSB_PORT_MAX.Test plan
port = 0enumerates on the Mac after the application swaps OTG 1.1 onto FSLS PHY 0 (LP_SYS.usb_ctrl); the SD card mounts as a drive and hands back to the application.port = -1) leavesTINYUSB_DEFAULT_CONFIG()untouched.🤖 Generated with Claude Code
https://claude.ai/code/session_01BAeyJSuzVyqvSe4mffGUZo