Skip to content

Conversation

HiFiPhile
Copy link
Collaborator

Previously alt settings are saved in an array sized by CFG_TUD_AUDIO_FUNC_n_N_AS_INT, since we limit each audio instance to one IN EP and one OUT EP, we can save directly the current alt setting value in the instance, which avoid a lookup operation.

  • No more need to define CFG_TUD_AUDIO_FUNC_1_N_AS_INT
  • No more need to call audiod_get_AS_interface_index in each transfer, on STM32F7 this call cost 600 cycles = 3us !
  • Remaining usage of audiod_get_AS_interface_index_global is replaced by audiod_verify_itf_exists

PS:
In current state it looks like adding UAC1 compatibility is not too complicated, most code should be already compatible.

I've tested on Windows, you can test more if I didn't break anything @PanRe @kf6gpe @gmikitiuk @mastupristi

@Copilot Copilot AI review requested due to automatic review settings September 27, 2025 20:50
Copy link
Contributor

@Copilot 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 simplifies alternate setting management in the TinyUSB audio device class by removing the array-based storage and using direct field storage instead. The change eliminates the need for CFG_TUD_AUDIO_FUNC_n_N_AS_INT configuration and removes lookup operations that were costing 600 cycles (3µs) on STM32F7.

Key Changes

  • Replaced array-based alternate setting storage with direct fields in the audio instance structure
  • Removed configuration requirements for CFG_TUD_AUDIO_FUNC_n_N_AS_INT across all examples
  • Eliminated audiod_get_AS_interface_index function calls that required expensive lookups

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

File Description
src/class/audio/audio_device.h Removes configuration validation for CFG_TUD_AUDIO_FUNC_n_N_AS_INT
src/class/audio/audio_device.c Core implementation changes - adds direct alt setting fields, removes lookup functions
examples/device/*/src/tusb_config.h Removes CFG_TUD_AUDIO_FUNC_1_N_AS_INT configuration from all audio examples

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.

thank you

@hathach hathach merged commit 5130850 into master Sep 29, 2025
215 of 217 checks passed
@hathach hathach deleted the uac_simplify branch September 29, 2025 02:36
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