feat(m5stack-cardputer): Better mic+speaker support and update example accordingly#671
Merged
Merged
Conversation
|
✅Static analysis result - no issues found! ✅ |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds full-duplex audio support for the M5Stack Cardputer ADV variant by sharing a single I2S bus between speaker (DAC) and microphone (ADC) via the ES8311 codec, and updates documentation + the example app to demonstrate simultaneous record/playback.
Changes:
- Implement shared ADV full-duplex I2S channel allocation and stereo-slot RX capture with in-task mono compaction.
- Refactor ES8311 init so shared/common registers are written once and both DAC/ADC paths can coexist.
- Update public docs and the example (record/playback controls + optional PSRAM buffer preference) to match the new behavior.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| components/m5stack-cardputer/src/microphone.cpp | Uses shared ADV I2S RX channel for full-duplex; compacts stereo capture to mono for ADC slot. |
| components/m5stack-cardputer/src/m5stack-cardputer.cpp | Adds common ES8311 init path and adjusts codec init sequences for DAC/ADC coexistence. |
| components/m5stack-cardputer/src/audio.cpp | Introduces ADV shared full-duplex I2S setup; updates buffering and play_audio API to return queued bytes. |
| components/m5stack-cardputer/README.md | Updates component note to reflect full-duplex support on ADV and shared sample-rate behavior. |
| components/m5stack-cardputer/include/m5stack-cardputer.hpp | Documents ADV full-duplex constraints; updates play_audio return type and buffer sizing logic. |
| components/m5stack-cardputer/example/sdkconfig.defaults | Enables SPIRAM support (ignore-not-found) so example can prefer PSRAM when present. |
| components/m5stack-cardputer/example/README.md | Documents new ADV record/playback controls and limitations on original Cardputer. |
| components/m5stack-cardputer/example/main/m5stack_cardputer_example.cpp | Adds mic recording + playback streaming logic and UI controls for ADV. |
| components/m5stack-cardputer/example/main/gui.hpp | Updates on-device help text for new recording/playback controls. |
- compute the microphone RX buffer size in size_t to avoid int overflow before conversion (CodeQL) - replace std::all_of over the ES8311 register tables with plain loops to avoid relying on transitive <algorithm> includes - handle xStreamBufferCreate() allocation failure in initialize_sound(), tearing down the just-created I2S channel(s) instead of crashing in xStreamBufferReset() Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… satisfy cppcheck cppcheck's useStlAlgorithm check flags the raw loops the previous review asked for; use std::all_of again but with explicit <algorithm> / <iterator> includes so the build does not rely on transitive includes either. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Description
Motivation and Context
Previous versions of the M5Stack Cardputer driver did not support full-duplex audio operation, which limited the functionality of the device. This update enables users to record and play back audio simultaneously, enhancing the capabilities of the Cardputer ADV.
How has this been tested?
Build and run the updated driver on an M5Stack Cardputer ADV. Test the recording and playback functionality using the provided example code, ensuring that audio is captured and played back correctly without distortion or static.
Screenshots (if appropriate, e.g. schematic, board, console logs, lab pictures):
Types of changes
Checklist:
Software
.github/workflows/build.ymlfile to add my new test to the automated cloud build github action.