25
25
26
26
/* Check all pins are defined only once */
27
27
#define DIGITAL_PIN_CHECK_UNIQUE (i, _ ) \
28
- ((DT_FOREACH_PROP_ELEM_SEP_VARGS( \
29
- DT_PATH (zephyr_user), digital_pin_gpios, DIGITAL_PIN_EXISTS, (+), \
30
- DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), digital_pin_gpios, i)), \
28
+ ((DT_FOREACH_PROP_ELEM_SEP_VARGS( \
29
+ DT_PATH (zephyr_user), digital_pin_gpios, DIGITAL_PIN_EXISTS, (+), \
30
+ DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), digital_pin_gpios, i)), \
31
31
DT_PHA_BY_IDX(DT_PATH(zephyr_user), digital_pin_gpios, i, pin))) == 1)
32
32
33
33
#if !LISTIFY(DT_PROP_LEN(DT_PATH(zephyr_user), digital_pin_gpios), DIGITAL_PIN_CHECK_UNIQUE, (&&))
44
44
(DIGITAL_PIN_EXISTS(n, p, i, dev, num) ? i : 0 )
45
45
46
46
/* Only matched pin returns non-zero value, so the sum is matched pin's index */
47
- #define DIGITAL_PIN_GPIOS_FIND_PIN (dev, pin ) \
48
- DT_FOREACH_PROP_ELEM_SEP_VARGS (DT_PATH(zephyr_user), digital_pin_gpios, \
49
- LED_BUILTIN_INDEX_BY_REG_AND_PINNUM, (+), dev, pin)
47
+ #define DIGITAL_PIN_GPIOS_FIND_PIN (dev, pin ) \
48
+ DT_FOREACH_PROP_ELEM_SEP_VARGS (DT_PATH(zephyr_user), digital_pin_gpios, \
49
+ LED_BUILTIN_INDEX_BY_REG_AND_PINNUM, (+), dev, pin)
50
50
51
51
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), builtin_led_gpios) && \
52
52
(DT_PROP_LEN(DT_PATH(zephyr_user), builtin_led_gpios) > 0 )
53
53
54
- #if !(DT_FOREACH_PROP_ELEM_SEP_VARGS( \
55
- DT_PATH (zephyr_user), digital_pin_gpios, DIGITAL_PIN_EXISTS, (+), \
56
- DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0)), \
57
- DT_PHA_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0, pin)) > 0)
54
+ #if !(DT_FOREACH_PROP_ELEM_SEP_VARGS( \
55
+ DT_PATH (zephyr_user), digital_pin_gpios, DIGITAL_PIN_EXISTS, (+), \
56
+ DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0)), \
57
+ DT_PHA_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0, pin)) > 0)
58
58
#warning "pin not found in digital_pin_gpios"
59
59
#else
60
60
#define LED_BUILTIN \
61
- DIGITAL_PIN_GPIOS_FIND_PIN ( \
62
- DT_REG_ADDR (DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0)), \
61
+ DIGITAL_PIN_GPIOS_FIND_PIN ( \
62
+ DT_REG_ADDR (DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0)), \
63
63
DT_PHA_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0, pin))
64
64
#endif
65
65
66
66
/* If digital-pin-gpios is not defined, tries to use the led0 alias */
67
67
#elif DT_NODE_EXISTS(DT_ALIAS(led0))
68
68
69
- #if !(DT_FOREACH_PROP_ELEM_SEP_VARGS(DT_PATH(zephyr_user), digital_pin_gpios, DIGITAL_PIN_EXISTS, \
70
- (+), DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_ALIAS(led0), gpios, 0 )), \
71
- DT_PHA_BY_IDX (DT_ALIAS(led0), gpios, 0, pin)) > 0)
69
+ #if !(DT_FOREACH_PROP_ELEM_SEP_VARGS(DT_PATH(zephyr_user), digital_pin_gpios, DIGITAL_PIN_EXISTS, \
70
+ (+), \
71
+ DT_REG_ADDR (DT_PHANDLE_BY_IDX(DT_ALIAS(led0), gpios, 0)), \
72
+ DT_PHA_BY_IDX(DT_ALIAS(led0), gpios, 0, pin)) > 0)
72
73
#warning "pin not found in digital_pin_gpios"
73
74
#else
74
75
#define LED_BUILTIN \
75
- DIGITAL_PIN_GPIOS_FIND_PIN (DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_ALIAS(led0), gpios, 0)), \
76
- DT_PHA_BY_IDX(DT_ALIAS(led0), gpios, 0, pin))
76
+ DIGITAL_PIN_GPIOS_FIND_PIN (DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_ALIAS(led0), gpios, 0)), \
77
+ DT_PHA_BY_IDX(DT_ALIAS(led0), gpios, 0, pin))
77
78
#endif
78
79
79
80
#endif // builtin_led_gpios
@@ -95,11 +96,13 @@ enum digitalPins {
95
96
96
97
#ifdef CONFIG_ADC
97
98
98
- #define AN_ENUMS (n, p, i ) A ## i = DIGITAL_PIN_GPIOS_FIND_PIN( \
99
- DT_REG_ADDR (DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), p, i)), \
100
- DT_PHA_BY_IDX(DT_PATH(zephyr_user), p, i, pin)),
101
- enum analogPins { DT_FOREACH_PROP_ELEM (DT_PATH (zephyr_user),
102
- adc_pin_gpios, AN_ENUMS) };
99
+ #define AN_ENUMS (n, p, i ) \
100
+ A##i = DIGITAL_PIN_GPIOS_FIND_PIN(DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), p, i)), \
101
+ DT_PHA_BY_IDX (DT_PATH(zephyr_user), p, i, pin)),
102
+
103
+ enum analogPins {
104
+ DT_FOREACH_PROP_ELEM (DT_PATH (zephyr_user), adc_pin_gpios, AN_ENUMS)
105
+ };
103
106
104
107
// We provide analogReadResolution APIs
105
108
void analogReadResolution (int bits);
@@ -112,8 +115,11 @@ void analogReadResolution(int bits);
112
115
#undef DAC1
113
116
#undef DAC2
114
117
#undef DAC3
115
- #define DAC_ENUMS (n, p, i ) DAC ## i = i,
116
- enum dacPins { DT_FOREACH_PROP_ELEM (DT_PATH (zephyr_user), dac_channels, DAC_ENUMS) NUM_OF_DACS };
118
+ #define DAC_ENUMS (n, p, i ) DAC##i = i,
119
+
120
+ enum dacPins {
121
+ DT_FOREACH_PROP_ELEM (DT_PATH (zephyr_user), dac_channels, DAC_ENUMS) NUM_OF_DACS
122
+ };
117
123
118
124
#endif
119
125
@@ -122,10 +128,10 @@ void noInterrupts(void);
122
128
123
129
int digitalPinToInterrupt (pin_size_t pin);
124
130
125
- #define digitalPinToPort (x ) (x)
131
+ #define digitalPinToPort (x ) (x)
126
132
#define digitalPinToBitMask (x ) (x)
127
- #define portOutputRegister (x ) (x)
128
- #define portInputRegister (x ) (x)
133
+ #define portOutputRegister (x ) (x)
134
+ #define portInputRegister (x ) (x)
129
135
130
136
void analogReadResolution (int bits);
131
137
void analogWriteResolution (int bits);
0 commit comments