Skip to content

Fix ADC array gating mismatch between adc_pin_gpios and io_channels#11

Merged
soburi merged 4 commits intoconfigure_by_connector_deffrom
copilot/sub-pr-4-please-work
Feb 10, 2026
Merged

Fix ADC array gating mismatch between adc_pin_gpios and io_channels#11
soburi merged 4 commits intoconfigure_by_connector_deffrom
copilot/sub-pr-4-please-work

Conversation

Copy link
Copy Markdown

Copilot AI commented Feb 10, 2026

The arduino_adc[] and channel_cfg[] arrays were gated on adc_pin_gpios but populated via DT_FOREACH_PROP_ELEM(..., io_channels, ...), causing build failures when only one property was defined.

Changes

  • Corrected gating condition: Changed from adc_pin_gpios to io_channels for arrays that iterate over io_channels property
  • Added length validation: Compile-time check ensures io_channels and adc_pin_gpios have matching lengths when both are present
const struct adc_dt_spec arduino_adc[] = {
-#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), adc_pin_gpios)
+#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), io_channels)
  DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), io_channels, ADC_DT_SPEC)
...

+#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), io_channels) && \
+    DT_NODE_HAS_PROP(DT_PATH(zephyr_user), adc_pin_gpios)
+#if DT_PROP_LEN(DT_PATH(zephyr_user), io_channels) != \
+    DT_PROP_LEN(DT_PATH(zephyr_user), adc_pin_gpios)
+#error "io_channels and adc_pin_gpios must have the same length"
+#endif
+#endif

Connector-based configuration path (ZARD_ADC_CONNECTOR) remains unchanged.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits February 10, 2026 23:02
…tion

Co-authored-by: soburi <458281+soburi@users.noreply.github.com>
Co-authored-by: soburi <458281+soburi@users.noreply.github.com>
Co-authored-by: soburi <458281+soburi@users.noreply.github.com>
Copilot AI changed the title [WIP] Update to address feedback on configure by connector def Fix ADC array gating mismatch between adc_pin_gpios and io_channels Feb 10, 2026
Copilot AI requested a review from soburi February 10, 2026 23:04
@soburi soburi marked this pull request as ready for review February 10, 2026 23:30
Copilot AI review requested due to automatic review settings February 10, 2026 23:30
@soburi soburi merged commit 5b861f1 into configure_by_connector_def Feb 10, 2026
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 fixes a conditional compilation mismatch in ADC array initialization where arrays were gated on adc_pin_gpios but populated from io_channels, causing build failures. The fix aligns the preprocessor guards with the data source and adds compile-time validation.

Changes:

  • Updated conditional guards for arduino_adc[] and channel_cfg[] arrays from adc_pin_gpios to io_channels
  • Added compile-time length validation ensuring io_channels and adc_pin_gpios match when both properties are defined
  • Added CodeQL build artifacts to .gitignore

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.

File Description
cores/arduino/zephyrCommon.cpp Fixed conditional compilation guards for ADC arrays to match their data source (io_channels) and added length validation
.gitignore Added CodeQL build directory entries (unrelated infrastructure change)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +320 to +326
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), io_channels) && \
DT_NODE_HAS_PROP(DT_PATH(zephyr_user), adc_pin_gpios)
#if DT_PROP_LEN(DT_PATH(zephyr_user), io_channels) != \
DT_PROP_LEN(DT_PATH(zephyr_user), adc_pin_gpios)
#error "io_channels and adc_pin_gpios must have the same length"
#endif
#endif
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

The validation logic is insufficient. While this check ensures matching lengths when both properties are present, the code still allows scenarios where only io_channels is defined without adc_pin_gpios. In that case, arduino_analog_pins would be empty (size 0), making channel_cfg zero-sized (line 312), but line 314 would still attempt to populate it from io_channels, causing a compilation error. The validation should be strengthened to require both properties be defined together when using the non-connector path, or the array sizing should be made consistent. Consider adding an error check like: #if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), io_channels) != DT_NODE_HAS_PROP(DT_PATH(zephyr_user), adc_pin_gpios)

Copilot uses AI. Check for mistakes.
@soburi soburi deleted the copilot/sub-pr-4-please-work branch February 11, 2026 03:52
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.

3 participants