Skip to content

Conversation

@cgreening
Copy link

@cgreening cgreening commented Oct 3, 2025

Description

This PR enhances the USB Device UAC component with better volume control support and adds a new example demonstrating I2S audio integration.

Closes: #586

Component Changes

Added a new set_volume_db_cb callback to the uac_device_config_t structure that provides volume changes in decibels (dB), complementing the existing percentage-based set_volume_cb. This allows applications to implement more accurate gain control using logarithmic scaling.

New Example: usb_uac_i2s

Added a comprehensive example (examples/usb/device/usb_uac_i2s) demonstrating USB Audio Class integration with I2S peripherals:

Features:

  • I2S PDM RX for microphone input (mono, 16-bit)
  • I2S standard TX for speaker/amplifier output (mono, 16-bit)
  • Volume control with dB-to-gain conversion using power-of-10 formula
  • Mute functionality with zero-sample output
  • Sample clipping to prevent overflow (-32768 to 32767 range)
  • Configurable GPIO pins via menuconfig
  • Optional amplifier shutdown control (SD_MODE pin)

Hardware Support:

  • ESP32-S3 (primary target)
  • Works with any I2S PDM microphone
  • Works with any I2S PCM amplifier

Documentation Updates

Updated both English and Chinese documentation (docs/en/usb/usb_device/usb_device_uac.rst and docs/zh_CN/usb/usb_device/usb_device_uac.rst) with:

  • Usage example of the new set_volume_db_cb callback
  • Aligned code formatting in example snippets

Related

  • Component documentation: USB Device UAC
  • Related to existing usb_uac example but demonstrates I2S peripheral integration

Testing

  • ✅ Built successfully for ESP32-S3 target
  • ✅ Tested with I2S PDM microphone and I2S PCM amplifier hardware.- NOTE crackly output behaviour requires investigation
  • ✅ Verified volume control functionality (both mute and gain adjustment)
  • ✅ Tested audio input (microphone) and output (speaker) data paths
  • ✅ Confirmed device enumeration on host computer as USB audio device
  • ✅ Documentation builds without errors

Test Environment:

  • ESP32-S3 development board
  • I2S PDM microphone
  • I2S PCM amplifier/speaker
  • Host: macOS/Windows/Linux (USB audio device recognized)

Checklist

Before submitting a Pull Request, please ensure the following:

  • 🚨 This PR does not introduce breaking changes.
  • All CI checks (GH Actions) pass.
  • Documentation is updated as needed.
  • Tests are updated or added as necessary.
  • Code is well-commented, especially in complex areas.
  • Git history is clean — commits are squashed to the minimum necessary.

- Add set_volume_db_cb callback for decibel-based volume control
- Add usb_uac_i2s example with PDM microphone and PCM amplifier support
- Update documentation with new callback usage
@CLAassistant
Copy link

CLAassistant commented Oct 3, 2025

CLA assistant check
All committers have signed the CLA.

@github-actions
Copy link

github-actions bot commented Oct 3, 2025

Warnings
⚠️

Some issues found for the commit messages in this PR:

  • the commit message "Adds missing callback copy":
    • summary looks empty
    • type/action looks empty

Please fix these commit messages - here are some basic tips:

  • follow Conventional Commits style
  • correct format of commit message should be: <type/action>(<scope/component>): <summary>, for example fix(esp32): Fixed startup timeout issue
  • allowed types are: change,ci,docs,feat,fix,refactor,remove,revert,test
  • sufficiently descriptive message summary should be between 20 to 72 characters and start with upper case letter
  • avoid Jira references in commit messages (unavailable/irrelevant for our customers)

TIP: Install pre-commit hooks and run this check when committing (uses the Conventional Precommit Linter).

👋 Hello cgreening, we appreciate your contribution to this project!


Click to see more instructions ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- Resolve all warnings (⚠️ ) before requesting a review from human reviewers - they will appreciate it.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests.

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
4. If the change is approved and passes the tests it is merged into the default branch.

Generated by 🚫 dangerJS against 2f08dcf

@github-actions github-actions bot changed the title feat(usb_device_uac): add I2S example and volume dB callback feat(usb_device_uac): add I2S example and volume dB callback (AEGHB-1254) Oct 3, 2025
@YanKE01
Copy link
Contributor

YanKE01 commented Oct 24, 2025

Hi, @cgreening . I'm really sorry for getting to this PR so late. I was wondering if the example part could be moved to the examples/usb/device/usb_uac routine. We can use kconfig to choose between using the default volume_cb or db_cb. Since the usb_uac routine is based on our development board, this will help standardize the hardware environment for everyone. Additionally, remember to update the version number in the component's idf_component.yml to 1.3.0 and document the changes in the changelog.

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.

What are the units used in the uac_set_volume_cb_t callback (AEGHB-1240)

4 participants