core: arduino: analogWrite: Fix DAC output calculation#374
Open
soburi wants to merge 1 commit intoarduino:mainfrom
Open
core: arduino: analogWrite: Fix DAC output calculation#374soburi wants to merge 1 commit intoarduino:mainfrom
soburi wants to merge 1 commit intoarduino:mainfrom
Conversation
soburi
commented
Mar 1, 2026
- Correct max value calculation
- Add guard for DAC entry is not defined case
- initialize only if DAC not initialized
There was a problem hiding this comment.
Pull request overview
Updates the Zephyr-based Arduino core’s DAC-backed analogWrite() to produce correct full-scale outputs, avoid setup work on every call, and compile cleanly when DAC channel configuration is missing from the devicetree.
Changes:
- Fix DAC max/output scaling by mapping to
(2^resolution - 1)and clamping the input range. - Add devicetree guard for missing
dac-channelsand makeanalogWrite(DAC…)a no-op when not defined. - Initialize DAC channels once (per channel) and only after verifying the DAC device is ready.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
cores/arduino/zephyrCommon.cpp |
Adds guarded DAC channel config, one-time channel setup, input clamping, and corrected max/output scaling for DAC writes. |
cores/arduino/Arduino.h |
Guards DAC enum expansion so builds succeed when dac-channels isn’t defined in the devicetree. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b373f7c to
e0e5e23
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Correct max value calculation - Add guard for DAC entry is not defined case - initialize only if DAC not initialized Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
e0e5e23 to
a039a68
Compare
Built
|
| Artifact | Board | Core | Tests | RAM | Sketches | Warnings | Errors |
|---|---|---|---|---|---|---|---|
✅ zephyr_contrib |
ek_ra8d1
| 📗 | ✅ |
11.9% |
2 | - | - |
frdm_mcxn947
| 3 🏷️ | ✅ |
58.0% |
2 | - | - | |
frdm_rw612
| 1 🏷️ | ✅ |
83.0% |
2 | - | - | |
✔️* zephyr_main |
giga
| 4 🏷️ | ✅* |
54.5% |
44 | 8 | - |
nano33ble
| 1 🏷️ | ✅* |
78.7% |
22 | 8 | - | |
nano_matter
| 📗 | ✔️* |
|
20 | 8 | (2*) | |
niclasense
| 2 🏷️ | ✅* |
|
20 | 8 | - | |
opta
| 4 🏷️ | ✔️* |
46.7% |
54 | 8 | (2*) | |
portentac33
| 3 🏷️ | ✔️* |
|
56 | 8 | (8*) | |
portentah7
| 3 🏷️ | ✔️* |
47.3% |
58 | 8 | (2*) | |
✅* zephyr_unoq |
unoq
| 📗 | ✅* |
26.4% |
60 | 8 | - |
Legend
Board Test Status description 🔥 🔥 Test run failed to complete. ❌ 🔴 Test completed with unexpected errors. ✔️* 🚫 Test completed with errors, but all are known/expected. ✅* 🟡 Test completed with some warnings; no errors detected. ✅ 🟢 Test passed successfully, with no warnings or errors. 🌑 🌑 Test was skipped.
Author
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.