drivers/periph/dac: add dac_play API for async multi sample output - #22261
Open
benpicco wants to merge 6 commits into
Open
drivers/periph/dac: add dac_play API for async multi sample output#22261benpicco wants to merge 6 commits into
benpicco wants to merge 6 commits into
Conversation
benpicco
marked this pull request as ready for review
May 8, 2026 17:23
benpicco
requested review from
MichelRottleuthner,
MrKevinWeiss,
aabadie,
dylad,
keestux and
leandrolanzieri
as code owners
May 8, 2026 17:23
crasbe
reviewed
May 8, 2026
crasbe
reviewed
Jul 20, 2026
fabian18
reviewed
Jul 21, 2026
fabian18
reviewed
Jul 21, 2026
fabian18
reviewed
Aug 5, 2026
fabian18
reviewed
Aug 7, 2026
fabian18
reviewed
Aug 25, 2026
Contributor
The `dac_set()` API says > The value is always given as 16-bit value and is internally scaled to the > actual resolution that the DAC unit provides (e.g. 12-bit). We didn't do that scaling before - enable it even though it breaks existing users.
benpicco
force-pushed
the
periph/dac_dma
branch
from
September 3, 2026 13:00
ebc8a7b to
32af49c
Compare
Contributor
Author
|
I think they are already fixed in this branch 🤔 |
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.
Contribution description
The
periph_dacAPI only plays single samples. Thedac_ddsdrives does exist, but it's interrupt based so it's prone to distortions when interrupts are disabled even for a brief time.The proper solution is to use DMA to feed the DAC and since the DAC API is CPU specific, the only way to do this is by extending the DAC API with a new
dac_play()function that allows to supply a buffer of samples that will then be played asynchronously.Support for this is indicated by the
periph_dac_playfeature.We can supply a completion callback to supply the next buffer or set it to loop mode where the same sample is played over and over again independent of the CPU (e.g. if we want to produce a constant sine wave).
dac_set()behaves on sam0Previously the 12 bit DAC was not left-adjusted, that means
dac_set(0xfff)would produce the highest amplitude whiledac_set(0x1000)would be clipped to 0.However our API doc says
Fix this by setting the
LEFTADJbit.This however means that existing users will experience a lower amplitude when they supply 12 bit values.
Testing procedure
Try out the different waveforms in
tests/periph/dac_play:(The overshooting for square and sawtooth waves are actually an artifact of the oscilloscope, the signal looks clean on the (more expensive) Tektronix scope)
Issues/PRs references
Declaration of AI-Tools / LLMs usage:
AI-Tools / LLMs that were used are: