Fix ADC provisioning to gate on io_channels instead of adc_pin_gpios#8
Merged
soburi merged 4 commits intoconfigure_by_connector_deffrom Feb 10, 2026
Merged
Conversation
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
There was a problem hiding this comment.
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 onDT_NODE_HAS_PROP(..., io_channels)instead ofadc_pin_gpios. - Gate
channel_cfg[]initialization onio_channelsinstead ofadc_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_cfgis sized fromARRAY_SIZE(arduino_analog_pins)but now initialized fromDT_FOREACH_PROP_ELEM(..., io_channels, ...). Ifio_channelsexpands 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 andanalogReference()will iterate over them anyway. Either sizechannel_cfgfrom the same source (ARRAY_SIZE(arduino_adc)/DT_PROP_LEN(io_channels)), or keep the initialization source aligned witharduino_analog_pins, and/or add aBUILD_ASSERTthat 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 standalonechannel_cfg[]array, butanalogRead()callsadc_channel_setup()with&arduino_adc[idx].channel_cfginstead. Sincechannel_cfg[]is only a copy of the initial configs (and never wired back), changing the reference viaanalogReference()currently has no effect on subsequent reads. Ifchannel_cfg[]is meant to be the mutable config, consider using it inanalogRead()(or updatingarduino_adc[idx].channel_cfgfrom it beforeadc_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 fromio_channelscan break the implicit invariant thatanalog_pin_index()returns an index valid for botharduino_analog_pins[]andarduino_adc[].analogRead()uses the sameidxfor both arrays, butarduino_analog_pins[]is still sourced fromadc_pin_gpios(or connector map), so on boards where these lists differ in length/order you can get wrong channel selection or-EINVALfor 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.
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.
ADC provisioning arrays were incorrectly gated on
adc_pin_gpioswhile consuming data fromio_channels, causing boards that provideio-channelswithoutadc-pin-gpiosto incorrectly fall back to connector maps instead of using explicit provisioning.Changes
arduino_adc[]andchannel_cfg[]: Gate onDT_NODE_HAS_PROP(..., io_channels)(wasadc_pin_gpios)arduino_analog_pins[]: Remains gated onadc_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-channelscontrols provisioning andadc-pin-gpioscontrols association.✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.