Skip to content

Conversation

@HiFiPhile
Copy link
Collaborator

@HiFiPhile HiFiPhile commented Sep 30, 2025

Describe the PR

This PR adds USB Audio Class 1.0 (UAC1) support, now audio device driver supports both UAC1 and UAC2 with dynamic switching possibility based on host capabilities.

For asynchronous OUT with feedback, now it's recommended to use UAC1 for Full-Speed device for better OS compatibility, while UAC2 is recommended only for High-Speed device for better performance.

Let me break down this PR:

USBD

  • Add UAC1 constants to audio.h with prefix audio10_, UAC2 renamed with prefix audio20_
  • Add UAC1 descriptor macros to usbd.h, refactor fixed size descriptor macros to use auto size with the help of TU_ARGS_APPLY_EXPAND
  • Support UAC1 without IAD (Interface Association Descriptor)

Audio device

  • Add UAC1 descriptor parsing and control request handling
  • Update IN flow control to support UAC1 (OUT feedback by FIFO counting is auto supported)
  • Calculate descriptor length by driver, remove CFG_TUD_AUDIO_FUNC_n_DESC_LEN config
  • Remove CFG_TUD_AUDIO_ENABLE_FEEDBACK_FORMAT_CORRECTION, now UAC1 always use 3-bytes 10.14 format while UAC2 always use 4-bytes 16.16 format

Examples

  • uac2_speaker_fb: Add UAC1 support with automatic fallback based on host capabilities
    • Remove OS guessing quirks
  • audio_test_multi_rate: Add UAC1 support with automatic fallback based on host capabilities
  • uac2_headset: Add UAC1 support with automatic fallback based on host capabilities
    • UAC1 status interrupt is not supported by most OS, if you need volume control either use UAC2 or old day HID interface

Testing

On STM32F407 & STM32F723:

Example OS UAC1 (FS) UAC2 (HS)
uac2_speaker_fb Windows 10
uac2_speaker_fb macOS 13
uac2_speaker_fb Archlinux
audio_test_multi_rate Windows 10
audio_test_multi_rate macOS 13
audio_test_multi_rate Archlinux
uac2_headset Windows 10
uac2_headset macOS 13 Seems OK, can't verify in VM Seems OK, can't verify in VM
uac2_headset Archlinux

Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: Mengsk <admin@hifiphile.com>
Signed-off-by: Mengsk <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: Mengsk <admin@hifiphile.com>
Signed-off-by: Mengsk <admin@hifiphile.com>
Copilot AI review requested due to automatic review settings September 30, 2025 15:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds comprehensive USB Audio Class 1.0 (UAC1) support to TinyUSB's audio device driver, enabling dynamic switching between UAC1 and UAC2 based on host capabilities. The implementation focuses on improving compatibility with Full-Speed devices by recommending UAC1 for better OS compatibility while maintaining UAC2 for High-Speed performance.

  • Adds complete UAC1 constants, descriptors, and macros with audio10_ prefix
  • Implements UAC1 descriptor parsing and control request handling in audio device driver
  • Updates examples to support both UAC1 and UAC2 with automatic fallback capability

Reviewed Changes

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

Show a summary per file
File Description
src/device/usbd.h Adds UAC1 descriptor templates and renames UAC2 macros for clarity
src/device/usbd.c Adds UAC1 device support without IAD descriptor handling
src/common/tusb_compiler.h Adds TU_ARGS_APPLY_EXPAND macro for variable argument expansion
src/common/tusb_common.h Adds U24 byte manipulation macros for UAC1 feedback format
src/class/midi/midi_host.c Updates to use renamed UAC1 constants
src/class/audio/audio_device.h Removes deprecated config options and adds version detection API
src/class/audio/audio_device.c Implements UAC1 parsing, control handling, and feedback format logic
src/class/audio/audio.h Comprehensive UAC1/UAC2 constants reorganization and new descriptors
examples/device/uac2_speaker_fb/* Removes OS guessing quirks, adds UAC1/UAC2 dual support
examples/device/uac2_headset/* Updates to use renamed UAC2 constants
examples/device/cdc_uac2/* Updates to use renamed UAC2 constants

@HiFiPhile
Copy link
Collaborator Author

HiFiPhile commented Oct 1, 2025

I've an issue with DWC2 where sometimes it can't send IN ISO packet (a ZLP is sent instead of data) when bInterval > 1

It seems like packet needs to scheduled manually when bInterval > 1, at least even/odd toggling is needed.
image

Signed-off-by: HiFiPhile <admin@hifiphile.com>
@HiFiPhile HiFiPhile force-pushed the uac1 branch 2 times, most recently from 3a9fec6 to a944c0d Compare October 1, 2025 07:46
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
@hathach
Copy link
Owner

hathach commented Oct 4, 2025

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting

@hathach
Copy link
Owner

hathach commented Oct 4, 2025

@codex merge master branch to this PR

@chatgpt-codex-connector
Copy link

For now, I can only help with PRs you've created.

@hathach
Copy link
Owner

hathach commented Oct 4, 2025

@copilot merge master branch to this PR

hathach and others added 3 commits October 4, 2025 15:41
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Signed-off-by: HiFiPhile <admin@hifiphile.com>
Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

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

Gates Failed
Prevent hotspot decline (2 hotspots with Complex Method, Complex Conditional, Bumpy Road Ahead, Deep, Nested Complexity)
Enforce critical code health rules (2 files with Bumpy Road Ahead, Deep, Nested Complexity)
Enforce advisory code health rules (5 files with Complex Method, Overall Code Complexity, Code Duplication, Complex Conditional)

Gates Passed
1 Quality Gates Passed

See analysis details in CodeScene

Reason for failure
Prevent hotspot decline Violations Code Health Impact
usbd.c 3 rules in this hotspot 5.74 → 5.14 Suppress
audio_device.c 3 rules in this hotspot 3.71 → 3.44 Suppress
Enforce critical code health rules Violations Code Health Impact
usbd.c 1 critical rule 5.74 → 5.14 Suppress
audio_device.c 1 critical rule 3.71 → 3.44 Suppress
Enforce advisory code health rules Violations Code Health Impact
main.c 2 advisory rules 9.61 → 8.29 Suppress
main.c 2 advisory rules 8.17 → 7.29 Suppress
main.c 2 advisory rules 9.24 → 8.49 Suppress
usbd.c 2 advisory rules 5.74 → 5.14 Suppress
audio_device.c 2 advisory rules 3.71 → 3.44 Suppress

Quality Gate Profile: Clean Code Collective
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.

Copy link
Owner

@hathach hathach left a comment

Choose a reason for hiding this comment

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

perfect !! Thank you very much, I didn't test but go through code changes. It looks great, audio is by far the most complicated driver. I think its descriptor is too complicated to have template descirptor as macro. I will try to improve it later on with typedef struct like video example. Thank you very much for putting lots of effort into the driver.

@hathach hathach merged commit dfcab87 into hathach:master Oct 31, 2025
109 of 114 checks passed
@HiFiPhile HiFiPhile deleted the uac1 branch November 25, 2025 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants