Skip to content

feat(usb_device): configurable bcdDevice, bMaxPower and remote-wakeup attribute - #796

Merged
finger563 merged 4 commits into
mainfrom
feat/usb-device-descriptor-fields
Sep 15, 2026
Merged

finger563 merged 4 commits into
mainfrom
feat/usb-device-descriptor-fields

Conversation

@finger563

Copy link
Copy Markdown
Contributor

espp::UsbDevice::Config gains three descriptor fields, all defaulting to the values that were hard-coded before, so existing users see no change:

Field Default Descriptor
bcd_device 0x0100 device descriptor bcdDevice (ignored for an XInput-only device, which keeps the Xbox 360 value)
max_power_ma 100 configuration descriptor bMaxPower (clamped to 500)
remote_wakeup true configuration descriptor bmAttributes remote-wakeup bit

Why: some hosts compare these against the device they expect. The Nintendo Switch is happier with a Pro Controller that reports bcdDevice 2.10 and 500 mA (found by a downstream fork of esp-usb-ble-hid); the dongle could not express that through UsbDevice until now.

Implementation note: the configuration descriptor's attribute and power bytes are written after TUD_CONFIG_DESCRIPTOR rather than passed to it — the macro's (_power_ma)/2 on a runtime value is a narrowing int → uint8_t inside the braced initializer and fails under -Werror=narrowing.

Built the usb_device example (esp32s3, IDF v6.1). Not hardware-tested.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU

… attribute

UsbDevice::Config gains bcd_device (default 0x0100, the previous
hard-coded value), max_power_ma (default 100 mA, as before; clamped to
500) and remote_wakeup (default true, as before). Some hosts compare
these against the device they expect: the Nintendo Switch is happier
with a Pro Controller that reports bcdDevice 2.10 and 500 mA, which the
esp-usb-ble-hid dongle could not express until now. An XInput-only
device keeps reporting the Xbox 360 bcdDevice.

The configuration descriptor's attribute and power bytes are patched in
after TUD_CONFIG_DESCRIPTOR since the macro's arithmetic on a runtime
value is a narrowing conversion inside the braced initializer.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
@github-actions

github-actions Bot commented Sep 15, 2026

Copy link
Copy Markdown

✅Static analysis result - no issues found! ✅

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

Adds configurability for USB device/configuration descriptor fields that were previously hard-coded, enabling better host compatibility (e.g., Nintendo Switch expectations) without changing defaults for existing users.

Changes:

  • Added bcd_device, max_power_ma, and remote_wakeup to espp::UsbDevice::Config.
  • Device descriptor now uses configurable bcdDevice for non–XInput-only devices.
  • Configuration descriptor bmAttributes and bMaxPower are patched post-TUD_CONFIG_DESCRIPTOR to avoid narrowing warnings at runtime.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
components/usb_device/src/usb_device.cpp Uses new config fields for bcdDevice, and patches config descriptor attributes/power bytes dynamically.
components/usb_device/include/usb_device.hpp Extends UsbDevice::Config with new descriptor-related fields and documentation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread components/usb_device/src/usb_device.cpp Outdated
Comment thread components/usb_device/src/usb_device.cpp Outdated
…; round bMaxPower up

The TUD_CONFIG_DESCRIPTOR macro cannot be expanded by cppcheck (it saw
a 1-byte array patched at [7]/[8]) and hid which arguments were real:
the 9-byte header is now spelled out field by field. bMaxPower (2 mA
units) is clamped to 500 mA and rounded up so an odd request is never
under-reported.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new field placement breaks positional aggregate initialization, and the public options are missing from both usage guides.

Get a fresh assessment by requesting another Copilot review.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Comment thread components/usb_device/include/usb_device.hpp Outdated
Comment thread components/usb_device/include/usb_device.hpp Outdated
finger563 and others added 2 commits September 15, 2026 11:51
…nt them

bcd_device / max_power_ma / remote_wakeup now come last in UsbDevice::Config
so positional aggregate initializers written against earlier releases keep
their member positions. The README and doc/en/buses/usb_cdc.rst feature
lists and usage snippets describe the three fields, the 500 mA clamp and
the 2 mA round-up.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
…ntity; log_level stays last

espp configs keep log_level as the final member and only promise named
(designated) initializer compatibility, so bcd_device / max_power_ma /
remote_wakeup sit with vid / pid / strings where they belong.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
@finger563
finger563 merged commit 1335496 into main Sep 15, 2026
164 checks passed
@finger563
finger563 deleted the feat/usb-device-descriptor-fields branch September 15, 2026 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants