Skip to content

Commit a2e2d78

Browse files
committed
adc
1 parent 3929375 commit a2e2d78

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

cores/arduino/Arduino.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,23 @@ enum digitalPins {
6363
#endif
6464

6565
#ifdef CONFIG_ADC
66+
67+
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), adc_pin_gpios)
6668
#define ZARD_AN_ENUMS(n, p, i) A##i = ZARD_GLOBAL_GPIO_NUM(n, p, i)
6769
enum analogPins {
6870
DT_FOREACH_PROP_ELEM_SEP(DT_PATH(zephyr_user), adc_pin_gpios, ZARD_AN_ENUMS, (, )),
6971
NUM_OF_ANALOG_PINS
7072
};
73+
#elif DT_NODE_EXISTS(DT_NODELABEL(arduino_adc))
74+
#define ZARD_MKR_HDR_AN_ENUMS(n, p, i) \
75+
A##i = UTIL_CAT(D, GET_ARG_N(1, DT_MAP_PARENT_SPECIFIER_ARGS_BY_IDX(n, p, i)))
76+
77+
enum analogPins {
78+
DT_FOREACH_PROP_ELEM_SEP(DT_NODELABEL(arduino_adc), io_channel_map, ZARD_MKR_HDR_AN_ENUMS, (, )),
79+
NUM_OF_ANALOG_PINS
80+
};
81+
#endif
82+
7183
#endif
7284

7385
void interrupts(void);

cores/arduino/zephyrCommon.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

168170
struct 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+
172194
size_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

Comments
 (0)