fix: BE bitfield guards for audio structs and endian-safe wValue/wIndex extraction in UAC2 examples#3618
Open
Copilot wants to merge 5 commits into
Open
fix: BE bitfield guards for audio structs and endian-safe wValue/wIndex extraction in UAC2 examples#3618Copilot wants to merge 5 commits into
Copilot wants to merge 5 commits into
Conversation
…e field extraction - Add TU_BITFIELD_ORDER guards for audio10_desc_as_iso_data_ep_t.bmAttributes in audio.h - Add TU_BITFIELD_ORDER guards for audio20_control_request_t.bmRequestType_bit in audio.h - Fix cdc_uac2/src/uac2_app.c: replace alias cast with TU_U16_LOW/HIGH field extraction - Fix uac2_headset/src/main.c: replace alias cast with TU_U16_LOW/HIGH field extraction - Fix uac2_speaker_fb/src/main.c: replace alias cast with TU_U16_LOW/HIGH field extraction Addresses review comment: #3597 (comment) Agent-Logs-Url: https://github.com/hathach/tinyusb/sessions/8b695271-74b3-4a26-b3d8-c48ecdf2e481 Co-authored-by: HiFiPhile <4375114+HiFiPhile@users.noreply.github.com>
Co-authored-by: HiFiPhile <4375114+HiFiPhile@users.noreply.github.com>
Agent-Logs-Url: https://github.com/hathach/tinyusb/sessions/8b695271-74b3-4a26-b3d8-c48ecdf2e481 Co-authored-by: HiFiPhile <4375114+HiFiPhile@users.noreply.github.com>
… tracking Co-authored-by: HiFiPhile <4375114+HiFiPhile@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix remaining big-endian issues in audio related code
fix: BE bitfield guards for audio structs and endian-safe wValue/wIndex extraction in UAC2 examples
Apr 25, 2026
Collaborator
|
BE support for NET and MSC will be hard... |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR completes follow-up big-endian correctness fixes for TinyUSB’s audio class types and UAC2 examples, addressing remaining gaps after #3597’s setup-packet host-endian conversion and common bitfield-order guards.
Changes:
- Added
TU_BITFIELD_ORDERLE/BE guards for UAC1 ISO endpointbmAttributespacking inaudio10_desc_as_iso_data_ep_t. - Added
TU_BITFIELD_ORDERLE/BE guards for UAC2audio20_control_request_t.bmRequestType_bit. - Updated UAC2 example request parsing to extract
wValue/wIndexsubfields viaTU_U16_LOW/HIGHinstead of BE-broken alias casts.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/class/audio/audio.h |
Adds BE-safe bitfield layouts for duplicated endpoint attributes and UAC2 request-type bitfields. |
examples/device/cdc_uac2/src/uac2_app.c |
Removes alias-cast parsing and uses endian-safe extraction from wValue/wIndex. |
examples/device/uac2_headset/src/main.c |
Makes UAC2 entity/control/channel parsing endian-safe by extracting bytes from wValue/wIndex. |
examples/device/uac2_speaker_fb/src/main.c |
Same endian-safe extraction refactor for UAC2 control handling paths. |
.gitignore |
Adds ignore rules for fetched dependencies (not described in PR scope). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Follow-up to #3597: three big-endian correctness gaps missed by that PR's bitfield and setup-packet fixes.
src/class/audio/audio.haudio10_desc_as_iso_data_ep_t.bmAttributes— addedTU_BITFIELD_ORDERLE/BE guards (samexfer/sync/usagepacking astusb_desc_endpoint_t, which was fixed in fix #3596: big-endian host support for SETUP packet handling #3597 but this duplicate was missed). Read at runtime inaudio_device.cto classify ISO endpoints; reversed bits on BE would silently misclassify them.audio20_control_request_t.bmRequestType_bit— addedTU_BITFIELD_ORDERLE/BE guards mirroring the fix already applied totusb_control_request_tintusb_types.h.UAC2 example files (
cdc_uac2,uac2_headset,uac2_speaker_fb)After #3597 stores
wValue/wIndexin host byte order, the alias-cast pattern(audio20_control_request_t const *)p_requestbreaks on BE — bytes that map tobChannelNumber/bControlSelector/bEntityID/bInterfaceare swapped relative to the struct layout.Replaced alias casts with explicit
TU_U16_LOW/TU_U16_HIGHextraction, consistent with howaudio_device.calready handles these fields:Ref: #3597 (comment)
Original prompt
Implement the remaining big-endian fixes identified in PR review comment #3597 (comment).
Repository: hathach/tinyusb
Target branch: master
Context
PR #3597 introduced host-endian conversion for setup packet fields in
dcd_event_setup_receivedand added bitfield-order guards in some common USB types. A follow-up review identified 3 remaining endian issues in audio-related code and examples.Tasks
Add TU_BITFIELD_ORDER guards for
audio10_desc_as_iso_data_ep_t.bmAttributesinsrc/class/audio/audio.h.xfer:2,sync:2,usage:2, padding:2src/common/tusb_types.hfor endpoint attributes:#if (TU_BITFIELD_ORDER == TU_BITFIELD_LE) ... #elif (TU_BITFIELD_ORDER == TU_BITFIELD_BE) ... #else #error ... #endifpattern consistent with repository style.Add TU_BITFIELD_ORDER guards for
audio20_control_request_t.bmRequestType_bitinsrc/class/audio/audio.h.recipient:5,type:2,direction:1direction:1,type:2,recipient:5#if/#elif/#else #errorpattern as above and consistent withtusb_control_request_tinsrc/common/tusb_types.h.Fix UAC2 examples that rely on alias-casting/LE byte assumptions for
wValue/wIndexsubfields.examples/device/cdc_uac2/src/uac2_app.cexamples/device/uac2_headset/src/main.cexamples/device/uac2_speaker_fb/src/main.cp_request->wValueandp_request->wIndexis endian-safe after host-order conversion in setup event path.TU_U16_LOW,TU_U16_HIGH(or existing tinyusb helper equivalents) instead of raw alias assumptions.Validation expectations
Deliverables
masterwith:The following is the prior conversation context from the user's chat exploration (may be truncated):
User: fix issue in #3597 (comment)
Assistant: I can do that, but I need one clarification before I can make changes:
Do you want me to open a PR with the fix (I can do that directly), or just identify the fix and provide the patch here?
If you want the PR opened, I’ll proceed against
hathach/tinyusband target the appropriate base branch.User: identify the fix and open PR after my confirmation
Assistant: Perfect — I’ll do this in two steps:
#issuecomment-4320042007and identify the exact fixUser: do it
Assistant: Identified. The comment points out 3 remaining big-endian correctness gaps after PR #3597.
Proposed fix
Guard
audio10_desc_as_iso_data_ep_t.bmAttributesbitfields byTU_BITFIELD_ORDERsrc/class/audio/audio.haudio_device.cand will decode incorrectly on BE without mirrored layout.Guard
audio20_control_request_t.bmRequestType_bitbitfields byTU_BITFIELD_ORDERsrc/class/audio/audio.hFix UAC2 example alias-cast pattern that assumes LE byte placement
examples/device/cdc_uac2/src/uac2_app.cexamples/device/uac2_headset/src/main.cexamples/device/uac2_speaker_fb/src/main.cdcd_event_setup_received, aliasingwValue/wIndexbytes directly is wrong on BE.TU_U16_LOW/HIGH(p_request->wValue / wIndex)(or equivalent helper usage), not by raw byte reinterpretation assumptions.This exactly addresses the three items in:
#3597 (comment)
If you confirm, I’ll open a PR with these changes.
User: yes
Assistant: Great — I’m ready to open it, but I need one repo permission detail from you first:
Please confirm the target repository for the PR is exactly:
hathach/tinyusb(If yes, I’ll pro...
This pull request was created from Copilot chat.