Skip to content

Dac adc#28

Closed
soburi wants to merge 15 commits intocleanup_commonfrom
dac_adc
Closed

Dac adc#28
soburi wants to merge 15 commits intocleanup_commonfrom
dac_adc

Conversation

@soburi
Copy link
Copy Markdown
Owner

@soburi soburi commented Mar 1, 2026

No description provided.

facchinm and others added 4 commits March 1, 2026 10:11
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>
Copilot AI review requested due to automatic review settings March 1, 2026 02:00
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 to analogRead() 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.

Comment thread cores/arduino/zephyrCommon.cpp
Comment thread cores/arduino/zephyrCommon.cpp Outdated
Comment thread cores/arduino/zephyrCommon.cpp Outdated
Comment thread cores/arduino/zephyrCommon.cpp
Comment thread cores/arduino/zephyrCommon.cpp
Comment thread cores/arduino/zephyrCommon.cpp Outdated
Comment thread cores/arduino/Arduino.h Outdated
Comment thread cores/arduino/zephyrCommon.cpp
facchinm and others added 3 commits March 1, 2026 12:01
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>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread cores/arduino/overloads.h
Comment thread cores/arduino/zephyrCommon.cpp
Comment thread cores/arduino/zephyrCommon.cpp Outdated
Comment thread cores/arduino/zephyrCommon.cpp
Comment thread cores/arduino/zephyrCommon.cpp Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread cores/arduino/overloads.h
Comment on lines +180 to +195
#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)};

Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread cores/arduino/zephyrCommon.cpp
Comment thread cores/arduino/overloads.h
Comment on lines +9 to +12
#ifdef CONFIG_DAC

void analogWrite(enum dacPins pinNumber, int value);

Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread cores/arduino/Arduino.h
Comment thread cores/arduino/zephyrCommon.cpp
Comment thread cores/arduino/zephyrCommon.cpp
facchinm and others added 5 commits March 1, 2026 12:46
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread cores/arduino/zephyrCommon.cpp
Comment thread cores/arduino/zephyrCommon.cpp Outdated
Comment thread cores/arduino/zephyrCommon.cpp
Comment thread cores/arduino/Arduino.h Outdated
Comment on lines +130 to +131

#endif
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
#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

Copilot uses AI. Check for mistakes.
Comment on lines +178 to +196
#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
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread cores/arduino/zephyrCommon.cpp
soburi and others added 3 commits March 1, 2026 13:09
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>
@soburi soburi closed this Apr 17, 2026
@soburi soburi deleted the dac_adc branch April 17, 2026 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants