@@ -153,22 +153,44 @@ size_t pwm_pin_index(pin_size_t pinNumber) {
153
153
154
154
#ifdef CONFIG_ADC
155
155
156
- #define ADC_DT_SPEC (n, p, i ) ADC_DT_SPEC_GET_BY_IDX(n, i)
157
156
#define ADC_CH_CFG (n, p, i ) arduino_adc[i].channel_cfg
158
157
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[] = {
160
162
DT_FOREACH_PROP_ELEM_SEP (DT_PATH (zephyr_user), io_channels, ADC_DT_SPEC, (,))
161
163
};
162
164
163
165
/* 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[] = {
165
167
DT_FOREACH_PROP_ELEM_SEP (DT_PATH (zephyr_user), adc_pin_gpios, ZARD_GLOBAL_GPIO_NUM, (,))
166
168
};
167
169
168
170
struct adc_channel_cfg channel_cfg[] = {
169
171
DT_FOREACH_PROP_ELEM_SEP (DT_PATH (zephyr_user), io_channels, ADC_CH_CFG, (,))
170
172
};
171
173
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
+
172
194
size_t analog_pin_index (pin_size_t pinNumber) {
173
195
for (size_t i=0 ; i<ARRAY_SIZE (arduino_analog_pins); i++) {
174
196
if (arduino_analog_pins[i] == pinNumber) {
0 commit comments