Dac adc#28
Conversation
Added a condition that the length of digital_pin_gpios is 0 or more. ------------------------------------------------------------------- Pick: arduino@d20ef628 Co-Authored-by: Martino Facchin <m.facchin@arduino.cc> Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
…sues The DIGITAL_PIN_EXISTS macro (used e.g. by LED_BUILTIN) was not working properly because the inline comments in devicetree_generated.h were confusing the preprocessor: one internal macro tried to create an unsigned constant by pasting a '*/' comment end marker with the 'U' character. Splitting that macro into two parts, so that the DT_REG_ADDR macro is invoked with an expanded argument, fixes the issue. ------------------------------------------------------------------- Pick: arduino@84651c2c Signed-off-by: Luca Burelli <l.burelli@arduino.cc> Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Add `DIGITAL_PIN_GPIOS_FIND_NODE` helper macro. ------------------------------------------------------------------- Pick: arduino@a60cd82a Co-Authored-by: Sebastian Romero <s.romero@arduino.cc> Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Silence a number of trivial compiler warnings in the Arduino core: - unused arguments - "constexpr const" ------------------------------------------------------------------ Pick: arduino@67251fb Signed-off-by: Luca Burelli <l.burelli@arduino.cc> Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR adds initial DAC support and introduces Arduino-style read/write resolution APIs for Zephyr-based Arduino core functions, aligning analog I/O behavior more closely with standard Arduino semantics.
Changes:
- Add devicetree-driven DAC device/channel configuration and a DAC-specific
analogWrite(dacPins, value)overload. - Add
analogWriteResolution()/analogReadResolution()APIs (including C++ getters via a new header). - Apply resolution-based scaling to PWM
analogWrite()and bit-shift mapping toanalogRead()results.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
cores/arduino/zephyrCommon.cpp |
Adds DAC globals, DAC analogWrite, resolution APIs, and applies scaling/mapping logic for PWM/DAC writes and ADC reads. |
cores/arduino/overloads.h |
Introduces C++-only overload declarations (DAC analogWrite) and resolution getters. |
cores/arduino/Arduino.h |
Adds DAC driver include, DAC pin enum generation, and resolution API declarations; includes overloads.h for C++. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ababaec Co-Authored-by: Martino Facchin <m.facchin@arduino.cc> Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
69b644f Co-Authored-by: Kurt Eckhardt <kurte@rockisland.com> Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Change analogReference declaration as a weak function. This is to accommodate the module configuration in the Arduino repository, but it does not have any adverse effects and is a way to coexist with the Zephyr repository, so we will include it. c8e82c1 Co-Authored-by: Martino Facchin <m.facchin@arduino.cc> Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #if (DT_NODE_HAS_PROP(DT_PATH(zephyr_user), dac)) | ||
|
|
||
| #define DAC_NODE DT_PHANDLE(DT_PATH(zephyr_user), dac) | ||
| #define DAC_RESOLUTION DT_PROP(DT_PATH(zephyr_user), dac_resolution) | ||
| static const struct device *const dac_dev = DEVICE_DT_GET(DAC_NODE); | ||
|
|
||
| #define DAC_CHANNEL_DEFINE(n, p, i) \ | ||
| { \ | ||
| .channel_id = DT_PROP_BY_IDX(n, p, i), \ | ||
| .resolution = DAC_RESOLUTION, \ | ||
| .buffered = true, \ | ||
| }, | ||
|
|
||
| static const struct dac_channel_cfg dac_ch_cfg[] = { | ||
| DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), dac_channels, DAC_CHANNEL_DEFINE)}; | ||
|
|
There was a problem hiding this comment.
The DAC devicetree guard only checks for the dac property, but this block also unconditionally uses dac_resolution and iterates dac_channels. Additionally, the DAC analogWrite(...) implementation later compiles under CONFIG_DAC even when this block is not compiled, which will break builds when CONFIG_DAC is enabled but the devicetree properties are missing. Please align the preprocessor guards so dac_dev/dac_ch_cfg and the DAC analogWrite(...) implementation are enabled/disabled together, and guard (or provide defaults for) dac_resolution/dac_channels usage explicitly.
| #ifdef CONFIG_DAC | ||
|
|
||
| void analogWrite(enum dacPins pinNumber, int value); | ||
|
|
There was a problem hiding this comment.
This header isn't self-contained: it declares APIs using enum dacPins without including the header that defines that enum (or forward-declaring it). Including overloads.h directly will fail to compile. Consider including <Arduino.h> here (consistent with other core headers) or adding an appropriate forward declaration.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| #endif |
There was a problem hiding this comment.
CONFIG_DAC currently errors out only when zephyr_user lacks dac_channels, but the implementation also depends on a zephyr_user.dac phandle and a zephyr_user.dac_resolution property. To avoid hard-to-diagnose compile errors and keep feature checks consistent with zephyrCommon.cpp, add compile-time checks for these required properties when CONFIG_DAC is enabled.
| #endif | |
| #if !DT_NODE_HAS_PROP(DT_PATH(zephyr_user), dac) | |
| #error "CONFIG_DAC is enabled, but zephyr_user node lacks dac; disable CONFIG_DAC or define dac phandle" | |
| #endif | |
| #if !DT_NODE_HAS_PROP(DT_PATH(zephyr_user), dac_resolution) | |
| #error "CONFIG_DAC is enabled, but zephyr_user node lacks dac_resolution; disable CONFIG_DAC or define dac_resolution" | |
| #endif | |
| #endif |
| #ifdef CONFIG_DAC | ||
|
|
||
| #if (DT_NODE_HAS_PROP(DT_PATH(zephyr_user), dac)) | ||
|
|
||
| #define DAC_NODE DT_PHANDLE(DT_PATH(zephyr_user), dac) | ||
| #define DAC_RESOLUTION DT_PROP(DT_PATH(zephyr_user), dac_resolution) | ||
| static const struct device *const dac_dev = DEVICE_DT_GET(DAC_NODE); | ||
|
|
||
| #define DAC_CHANNEL_DEFINE(n, p, i) \ | ||
| { \ | ||
| .channel_id = DT_PROP_BY_IDX(n, p, i), \ | ||
| .resolution = DAC_RESOLUTION, \ | ||
| .buffered = true, \ | ||
| }, | ||
|
|
||
| static const struct dac_channel_cfg dac_ch_cfg[] = { | ||
| DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), dac_channels, DAC_CHANNEL_DEFINE)}; | ||
|
|
||
| #endif |
There was a problem hiding this comment.
dac_dev / dac_ch_cfg are only defined when DT_NODE_HAS_PROP(DT_PATH(zephyr_user), dac) is true, but the DAC analogWrite() implementation is compiled under CONFIG_DAC unconditionally and uses those symbols. If CONFIG_DAC is enabled without a zephyr_user.dac phandle, this will fail to compile. Consider either removing this DT_NODE_HAS_PROP(..., dac) guard (and adding a compile-time #error when the required DT properties are missing) or extending the guard/feature checks so the implementation and declarations are consistent.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
ababaec Co-Authored-by: Martino Facchin <m.facchin@arduino.cc> Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
No description provided.