Skip to content

Commit fe30fe5

Browse files
committed
zephyrSerial: export automatic serial macros
Export two macros that automatically map to Serial objects depending on the current board's DT configuration: - ARDUINO_CONSOLE_SERIAL: Serial object used for the Zephyr console - ARDUINO_HARDWARE_SERIAL: First generic Serial object (usually on pins D0/D1) Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
1 parent 0f7575d commit fe30fe5

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

cores/arduino/zephyrSerial.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,22 @@ class ZephyrSerial : public HardwareSerial {
116116

117117
} // namespace arduino
118118

119+
/* Return the index of it if matched, oterwise return an empty string. */
120+
#define ZARD_SERIAL_MATCH(n, p, i, node) \
121+
COND_CODE_1(DT_SAME_NODE(DT_PHANDLE_BY_IDX(n, p, i), node), (i), ())
122+
123+
/* Only matched device returns non-empty value, so the overall expansion is
124+
* matched device's index.
125+
*/
126+
#define ZARD_SERIAL_INDEXOF(node) \
127+
DT_FOREACH_PROP_ELEM_VARGS(DT_PATH(zephyr_user), serials, ZARD_SERIAL_MATCH, node)
128+
129+
/* Serial object associated with the Zephyr console. */
130+
#define ARDUINO_CONSOLE_SERIAL ZARD_SERIAL_NAME(ZARD_SERIAL_INDEXOF(DT_CHOSEN(zephyr_console)))
131+
132+
/* Serial object associated with the first HW serial (usually on D0/D1). */
133+
#define ARDUINO_HARDWARE_SERIAL ZARD_SERIAL_NAME(0)
134+
119135
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm_serial)
120136
/* Devicetree requires a SerialUSB object for 'Serial'. */
121137
#define ZARD_SKIP_FIRST_SERIAL 1

0 commit comments

Comments
 (0)