Skip to content

Commit 1645143

Browse files
pillo79KurtE
authored andcommitted
Arduino.h: fix DIGITAL_PIN_EXISTS macro to avoid comment expansion issues
The DIGITAL_PIN_EXISTS macro (used e.g. by LED_BUILTIN) was not working properly because the inline comments in devicetree_generated.h were confusing the preprocessor: one internal macro tried to create an unsigned constant by pasting a '*/' comment end marker with the 'U' character. Splitting that macro into two parts, so that the DT_REG_ADDR macro is invoked with an expanded argument, fixes the issue. Signed-off-by: Luca Burelli <[email protected]>
1 parent c2cc111 commit 1645143

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Diff for: cores/arduino/Arduino.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
#include <math.h>
1818

1919
#if DT_PROP_LEN(DT_PATH(zephyr_user), digital_pin_gpios) > 0
20+
/* Note: DT_REG_ADDR needs an expanded argument or it will not work properly */
21+
#define DIGITAL_PIN_MATCHES(dev_pha, pin, dev, num) \
22+
(((dev == DT_REG_ADDR(dev_pha)) && (num == pin)) ? 1 : 0)
2023
#define DIGITAL_PIN_EXISTS(n, p, i, dev, num) \
21-
(((dev == DT_REG_ADDR(DT_PHANDLE_BY_IDX(n, p, i))) && \
22-
(num == DT_PHA_BY_IDX(n, p, i, pin))) \
23-
? 1 \
24-
: 0)
24+
DIGITAL_PIN_MATCHES(DT_PHANDLE_BY_IDX(n, p, i), DT_PHA_BY_IDX(n, p, i, pin), dev, num)
2525

2626
/* Check all pins are defined only once */
2727
#define DIGITAL_PIN_CHECK_UNIQUE(i, _) \
@@ -142,4 +142,4 @@ void analogWriteResolution(int bits);
142142
// Allow namespace-less operations if Arduino.h is included
143143
using namespace arduino;
144144

145-
#endif // __cplusplus
145+
#endif // __cplusplus

0 commit comments

Comments
 (0)