Skip to content

Fix ADC provisioning to gate on io_channels instead of adc_pin_gpios#8

Merged
soburi merged 4 commits intoconfigure_by_connector_deffrom
copilot/sub-pr-4-another-one
Feb 10, 2026
Merged

Fix ADC provisioning to gate on io_channels instead of adc_pin_gpios#8
soburi merged 4 commits intoconfigure_by_connector_deffrom
copilot/sub-pr-4-another-one

Conversation

Copy link
Copy Markdown

Copilot AI commented Feb 10, 2026

ADC provisioning arrays were incorrectly gated on adc_pin_gpios while consuming data from io_channels, causing boards that provide io-channels without adc-pin-gpios to incorrectly fall back to connector maps instead of using explicit provisioning.

Changes

  • arduino_adc[] and channel_cfg[]: Gate on DT_NODE_HAS_PROP(..., io_channels) (was adc_pin_gpios)
  • arduino_analog_pins[]: Remains gated on adc_pin_gpios (correct for pin-to-channel association)

This decouples provisioning (ADC channel availability) from association (pin-to-channel mapping), aligning implementation with documented behavior where io-channels controls provisioning and adc-pin-gpios controls association.

// Before: provisioning incorrectly gated on association property
const struct adc_dt_spec arduino_adc[] = {
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), adc_pin_gpios)  // Wrong: checks association
  DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), io_channels, ADC_DT_SPEC)  // Uses provisioning
#elif defined(ZARD_ADC_CONNECTOR)
  DT_FOREACH_MAP_ENTRY(DT_NODELABEL(ZARD_ADC_CONNECTOR), io_channel_map, ADC_CONN_CHANNEL_DT)
#endif
};

// After: provisioning gated on provisioning property
const struct adc_dt_spec arduino_adc[] = {
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), io_channels)  // Correct: checks provisioning
  DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), io_channels, ADC_DT_SPEC)
#elif defined(ZARD_ADC_CONNECTOR)
  DT_FOREACH_MAP_ENTRY(DT_NODELABEL(ZARD_ADC_CONNECTOR), io_channel_map, ADC_CONN_CHANNEL_DT)
#endif
};

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits February 10, 2026 22:58
The ADC provisioning arrays (arduino_adc[] and channel_cfg[]) should
be gated on the presence of io_channels, not adc_pin_gpios. The
io_channels property provides the actual ADC channel provisioning data,
while adc_pin_gpios only provides pin-to-channel association.

This fix ensures that when io-channels is provided without adc-pin-gpios
(e.g., when using connector io-channel-map for association), the ADC
provisioning correctly uses io-channels instead of incorrectly falling
back to the connector map.

The association array (arduino_analog_pins[]) correctly remains gated
on adc_pin_gpios since it represents the pin mapping, not provisioning.

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 connector definition configuration based on feedback Fix ADC provisioning to gate on io_channels instead of adc_pin_gpios Feb 10, 2026
Copilot AI requested a review from soburi February 10, 2026 23:00
@soburi soburi marked this pull request as ready for review February 10, 2026 23:29
Copilot AI review requested due to automatic review settings February 10, 2026 23:29
@soburi soburi merged commit 0556fbf 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

Fixes ADC provisioning selection so boards that define io-channels (but not adc-pin-gpios) don’t incorrectly fall back to connector-based ADC provisioning.

Changes:

  • Gate arduino_adc[] provisioning on DT_NODE_HAS_PROP(..., io_channels) instead of adc_pin_gpios.
  • Gate channel_cfg[] initialization on io_channels instead of adc_pin_gpios.
  • Ignore CodeQL build artifacts in .gitignore.

Reviewed changes

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

File Description
cores/arduino/zephyrCommon.cpp Switch ADC provisioning/config generation to be driven by io_channels rather than adc_pin_gpios.
.gitignore Add CodeQL-generated directories/files to ignore list.
Comments suppressed due to low confidence (3)

cores/arduino/zephyrCommon.cpp:317

  • channel_cfg is sized from ARRAY_SIZE(arduino_analog_pins) but now initialized from DT_FOREACH_PROP_ELEM(..., io_channels, ...). If io_channels expands to more initializers than there are analog pins, this will be a hard compile error (excess elements). If it expands to fewer, the tail entries stay zero-initialized and analogReference() will iterate over them anyway. Either size channel_cfg from the same source (ARRAY_SIZE(arduino_adc) / DT_PROP_LEN(io_channels)), or keep the initialization source aligned with arduino_analog_pins, and/or add a BUILD_ASSERT that the counts match.
struct adc_channel_cfg channel_cfg[ARRAY_SIZE(arduino_analog_pins)] = {
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), io_channels)
  DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), io_channels, ADC_CH_CFG)
#elif defined(ZARD_ADC_CONNECTOR)
  DT_FOREACH_MAP_ENTRY(DT_NODELABEL(ZARD_ADC_CONNECTOR), io_channel_map, ADC_CONN_CHANNEL_CFG)
#endif

cores/arduino/zephyrCommon.cpp:318

  • analogReference() updates the standalone channel_cfg[] array, but analogRead() calls adc_channel_setup() with &arduino_adc[idx].channel_cfg instead. Since channel_cfg[] is only a copy of the initial configs (and never wired back), changing the reference via analogReference() currently has no effect on subsequent reads. If channel_cfg[] is meant to be the mutable config, consider using it in analogRead() (or updating arduino_adc[idx].channel_cfg from it before adc_channel_setup()).
struct adc_channel_cfg channel_cfg[ARRAY_SIZE(arduino_analog_pins)] = {
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), io_channels)
  DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), io_channels, ADC_CH_CFG)
#elif defined(ZARD_ADC_CONNECTOR)
  DT_FOREACH_MAP_ENTRY(DT_NODELABEL(ZARD_ADC_CONNECTOR), io_channel_map, ADC_CONN_CHANNEL_CFG)
#endif
};

cores/arduino/zephyrCommon.cpp:300

  • Changing arduino_adc[] to be populated from io_channels can break the implicit invariant that analog_pin_index() returns an index valid for both arduino_analog_pins[] and arduino_adc[]. analogRead() uses the same idx for both arrays, but arduino_analog_pins[] is still sourced from adc_pin_gpios (or connector map), so on boards where these lists differ in length/order you can get wrong channel selection or -EINVAL for valid analog pins. Consider introducing an explicit pin->ADC-spec mapping (e.g., store channel_id/device per pin), or add a compile-time assertion/guard that the provisioning list and association list lengths/order match when using mixed sources.
const struct adc_dt_spec arduino_adc[] = {
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), io_channels)
  DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), io_channels, ADC_DT_SPEC)
#elif defined(ZARD_ADC_CONNECTOR)
  DT_FOREACH_MAP_ENTRY(DT_NODELABEL(ZARD_ADC_CONNECTOR), io_channel_map, ADC_CONN_CHANNEL_DT)
#endif

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

@soburi soburi deleted the copilot/sub-pr-4-another-one branch February 11, 2026 03:53
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