Fix ADC array gating mismatch between adc_pin_gpios and io_channels#11
Conversation
…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>
There was a problem hiding this comment.
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[]andchannel_cfg[]arrays fromadc_pin_gpiostoio_channels - Added compile-time length validation ensuring
io_channelsandadc_pin_gpiosmatch 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.
| #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 |
There was a problem hiding this comment.
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)
The
arduino_adc[]andchannel_cfg[]arrays were gated onadc_pin_gpiosbut populated viaDT_FOREACH_PROP_ELEM(..., io_channels, ...), causing build failures when only one property was defined.Changes
adc_pin_gpiostoio_channelsfor arrays that iterate overio_channelspropertyio_channelsandadc_pin_gpioshave matching lengths when both are presentConnector-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.