@@ -153,22 +153,44 @@ size_t pwm_pin_index(pin_size_t pinNumber) {
153153
154154#ifdef CONFIG_ADC
155155
156- #define ADC_DT_SPEC (n, p, i ) ADC_DT_SPEC_GET_BY_IDX(n, i)
157156#define ADC_CH_CFG (n, p, i ) arduino_adc[i].channel_cfg
158157
159- const struct adc_dt_spec arduino_adc[] = {
158+ #if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), adc_pin_gpios)
159+ #define ADC_DT_SPEC (n, p, i ) ADC_DT_SPEC_GET_BY_IDX(n, i)
160+
161+ constexpr struct adc_dt_spec arduino_adc[] = {
160162 DT_FOREACH_PROP_ELEM_SEP (DT_PATH (zephyr_user), io_channels, ADC_DT_SPEC, (,))
161163};
162164
163165/* io-channel-pins node provides a mapping digital pin numbers to adc channels */
164- const pin_size_t arduino_analog_pins[] = {
166+ constexpr pin_size_t arduino_analog_pins[] = {
165167 DT_FOREACH_PROP_ELEM_SEP (DT_PATH (zephyr_user), adc_pin_gpios, ZARD_GLOBAL_GPIO_NUM, (,))
166168};
167169
168170struct adc_channel_cfg channel_cfg[] = {
169171 DT_FOREACH_PROP_ELEM_SEP (DT_PATH (zephyr_user), io_channels, ADC_CH_CFG, (,))
170172};
171173
174+ #elif DT_NODE_EXISTS(DT_NODELABEL(arduino_adc))
175+ #define ADC_SPEC_ELEM (n, p, i ) \
176+ ADC_DT_SPEC_STRUCT (DT_MAP_PARENT_ARG_BY_IDX(n, p, i), \
177+ GET_ARG_N(1 , DT_MAP_PARENT_SPECIFIER_ARGS_BY_IDX(n, p, i)))
178+ #define ZARD_ADC_PIN_ID (i, _ ) A##i
179+
180+ constexpr struct adc_dt_spec arduino_adc[] = {
181+ DT_FOREACH_PROP_ELEM_SEP (DT_NODELABEL (arduino_adc), io_channel_map, ADC_SPEC_ELEM, (,))
182+ };
183+
184+ constexpr pin_size_t arduino_analog_pins[] = {
185+ LISTIFY (DT_PROP_LEN (DT_NODELABEL (arduino_adc), io_channel_map), ZARD_ADC_PIN_ID, (,))
186+ };
187+
188+ struct adc_channel_cfg channel_cfg[] = {
189+ DT_FOREACH_PROP_ELEM_SEP (DT_NODELABEL (arduino_adc), io_channel_map, ADC_CH_CFG, (,))
190+ };
191+
192+ #endif
193+
172194size_t analog_pin_index (pin_size_t pinNumber) {
173195 for (size_t i=0 ; i<ARRAY_SIZE (arduino_analog_pins); i++) {
174196 if (arduino_analog_pins[i] == pinNumber) {
0 commit comments