1515#include <zephyr/drivers/i2c.h>
1616
1717#define DIGITAL_PIN_EXISTS (n , p , i , dev , num ) \
18- (((dev == DT_REG_ADDR(DT_PHANDLE_BY_IDX(n, p, i))) && \
19- (num == DT_PHA_BY_IDX(n, p, i, pin))) \
20- ? 1 \
21- : 0)
18+ (((dev == DT_REG_ADDR(DT_PHANDLE_BY_IDX(n, p, i))) && (num == DT_PHA_BY_IDX(n, p, i, pin))) ? \
19+ 1 : \
20+ 0)
2221
2322/* Check all pins are defined only once */
2423#define DIGITAL_PIN_CHECK_UNIQUE (i , _ ) \
25- ((DT_FOREACH_PROP_ELEM_SEP_VARGS( \
26- DT_PATH(zephyr_user), digital_pin_gpios, DIGITAL_PIN_EXISTS, (+), \
27- DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), digital_pin_gpios, i)), \
24+ ((DT_FOREACH_PROP_ELEM_SEP_VARGS( \
25+ DT_PATH(zephyr_user), digital_pin_gpios, DIGITAL_PIN_EXISTS, (+), \
26+ DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), digital_pin_gpios, i)), \
2827 DT_PHA_BY_IDX(DT_PATH(zephyr_user), digital_pin_gpios, i, pin))) == 1)
2928
3029#if !LISTIFY (DT_PROP_LEN (DT_PATH (zephyr_user ), digital_pin_gpios ), DIGITAL_PIN_CHECK_UNIQUE , (&& ))
3837 (DIGITAL_PIN_EXISTS(n, p, i, dev, num) ? i : 0)
3938
4039/* Only matched pin returns non-zero value, so the sum is matched pin's index */
41- #define DIGITAL_PIN_GPIOS_FIND_PIN (dev , pin ) \
42- DT_FOREACH_PROP_ELEM_SEP_VARGS(DT_PATH(zephyr_user), digital_pin_gpios, \
43- LED_BUILTIN_INDEX_BY_REG_AND_PINNUM, (+), dev, pin)
40+ #define DIGITAL_PIN_GPIOS_FIND_PIN (dev , pin ) \
41+ DT_FOREACH_PROP_ELEM_SEP_VARGS(DT_PATH(zephyr_user), digital_pin_gpios, \
42+ LED_BUILTIN_INDEX_BY_REG_AND_PINNUM, (+), dev, pin)
4443
4544#if DT_NODE_HAS_PROP (DT_PATH (zephyr_user ), builtin_led_gpios ) && \
4645 (DT_PROP_LEN (DT_PATH (zephyr_user ), builtin_led_gpios ) > 0 )
4746
48- #if !(DT_FOREACH_PROP_ELEM_SEP_VARGS ( \
49- DT_PATH (zephyr_user ), digital_pin_gpios , DIGITAL_PIN_EXISTS , (+ ), \
50- DT_REG_ADDR (DT_PHANDLE_BY_IDX (DT_PATH (zephyr_user ), builtin_led_gpios , 0 )), \
51- DT_PHA_BY_IDX (DT_PATH (zephyr_user ), builtin_led_gpios , 0 , pin )) > 0 )
47+ #if !(DT_FOREACH_PROP_ELEM_SEP_VARGS ( \
48+ DT_PATH (zephyr_user ), digital_pin_gpios , DIGITAL_PIN_EXISTS , (+ ), \
49+ DT_REG_ADDR (DT_PHANDLE_BY_IDX (DT_PATH (zephyr_user ), builtin_led_gpios , 0 )), \
50+ DT_PHA_BY_IDX (DT_PATH (zephyr_user ), builtin_led_gpios , 0 , pin )) > 0 )
5251#warning "pin not found in digital_pin_gpios"
5352#else
5453#define ZARD_LED_BUILTIN \
6059/* If digital-pin-gpios is not defined, tries to use the led0 alias */
6160#elif DT_NODE_EXISTS (DT_ALIAS (led0 ))
6261
63- #if !(DT_FOREACH_PROP_ELEM_SEP_VARGS (DT_PATH (zephyr_user ), digital_pin_gpios , DIGITAL_PIN_EXISTS , \
64- (+ ), DT_REG_ADDR (DT_PHANDLE_BY_IDX (DT_ALIAS (led0 ), gpios , 0 )), \
65- DT_PHA_BY_IDX (DT_ALIAS (led0 ), gpios , 0 , pin )) > 0 )
62+ #if !(DT_FOREACH_PROP_ELEM_SEP_VARGS (DT_PATH (zephyr_user ), digital_pin_gpios , DIGITAL_PIN_EXISTS , \
63+ (+ ), \
64+ DT_REG_ADDR (DT_PHANDLE_BY_IDX (DT_ALIAS (led0 ), gpios , 0 )), \
65+ DT_PHA_BY_IDX (DT_ALIAS (led0 ), gpios , 0 , pin )) > 0 )
6666#warning "pin not found in digital_pin_gpios"
6767#else
6868#define ZARD_LED_BUILTIN \
@@ -85,11 +85,13 @@ enum digitalPins {
8585
8686#ifdef CONFIG_ADC
8787
88- #define AN_ENUMS (n , p , i ) A ## i = DIGITAL_PIN_GPIOS_FIND_PIN( \
89- DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), p, i)), \
90- DT_PHA_BY_IDX(DT_PATH(zephyr_user), p, i, pin)),
91- enum analogPins { DT_FOREACH_PROP_ELEM (DT_PATH (zephyr_user ),
92- adc_pin_gpios , AN_ENUMS ) };
88+ #define AN_ENUMS (n , p , i ) \
89+ A##i = DIGITAL_PIN_GPIOS_FIND_PIN(DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), p, i)), \
90+ DT_PHA_BY_IDX(DT_PATH(zephyr_user), p, i, pin)),
91+
92+ enum analogPins {
93+ DT_FOREACH_PROP_ELEM (DT_PATH (zephyr_user ), adc_pin_gpios , AN_ENUMS )
94+ };
9395
9496#endif
9597
0 commit comments