Skip to content

Commit a460315

Browse files
committed
zephyrSerial: export ARDUINO_ROUTER_SERIAL for Arduino_RouterBridge
If the board has an 'arduino,router-serial' node, then the functionality of the 'Serial' object is actually provided by the 'Monitor' object in the Arduino_RouterBridge library. Define the property for the UNO Q board and make sure the library is always included in every sketch so that the 'Serial' object is properly defined. A stub header is provided in the 'libraries/stubs' folder to handle the case of the library not being installed, so that the core can be used without requiring the installation of the libray. Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
1 parent 633cee8 commit a460315

5 files changed

Lines changed: 63 additions & 1 deletion

File tree

cores/arduino/zephyrSerial.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,17 @@ class ZephyrSerial : public HardwareSerial {
146146
#endif
147147
#endif
148148

149+
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), arduino_router_serial)
150+
/* If the board has an arduino,router-serial node, and the currently used
151+
* library has the support, then the 'Serial' object is actually the same as
152+
* the Monitor object in the Arduino_RouterBridge library.
153+
*/
154+
#define ZARD_SKIP_FIRST_SERIAL 1
155+
#define ZARD_FIRST_SERIAL_IS_ARDUINO_ROUTER 1
156+
#define ARDUINO_ROUTER_PHANDLE DT_PROP(DT_PATH(zephyr_user), arduino_router_serial)
157+
#define ARDUINO_ROUTER_SERIAL ZARD_SERIAL_NAME(ZARD_SERIAL_INDEXOF(ARDUINO_ROUTER_PHANDLE))
158+
#endif
159+
149160
/* Name of a Serial object for a given index. */
150161
#define ZARD_SERIAL_NAME(n) CONCAT(Serial, ZARD_SERIAL_STEM(n))
151162

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) Arduino s.r.l. and/or its affiliated companies
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once
8+
9+
/*
10+
* This is just a placeholder to handle the case of the Arduino_RouterBridge
11+
* library NOT being installed. If this file is chosen, the actual library is
12+
* missing and the user needs to be warned about it.
13+
*/
14+
15+
#error \
16+
"Please install the Arduino_RouterBridge library from the Library Manager for proper Serial support on this board."

variants/arduino_uno_q_stm32u585xx/arduino_uno_q_stm32u585xx.overlay

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@
328328
<&gpioc 1 0>,
329329
<&gpioc 0 0>;
330330

331+
arduino,router-serial = <&lpuart1>; /* 'Serial' is provided by the Monitor */
331332
serials = <&usart1>, <&lpuart1>;
332333
cans = <&fdcan1>;
333334
i2cs = <&i2c2>, <&i2c4>, <&i2c3>;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) Arduino s.r.l. and/or its affiliated companies
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once
8+
9+
/* This dance is necessary to force the inclusion of "Arduino_RouterBridge.h"
10+
* during the library discovery phase, so that the library include path is
11+
* added to the sketch build process.
12+
*
13+
* This will "discover" the stub in the libraries/stubs/ folder if the library
14+
* is not installed, and the actual header if it is.
15+
*/
16+
17+
#if ARDUINO_LIBRARY_DISCOVERY_PHASE
18+
#include "Arduino_RouterBridge.h"
19+
#else
20+
#if __has_include("Arduino_RouterBridge.h")
21+
#include "Arduino_RouterBridge.h"
22+
#endif
23+
#endif

variants/arduino_uno_q_stm32u585xx/variant.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
/*
22
* Copyright (c) 2022 Dhruva Gole
3+
* Copyright (c) Arduino s.r.l. and/or its affiliated companies
34
*
45
* SPDX-License-Identifier: Apache-2.0
56
*/
67

8+
#if !ARDUINO_LIBRARY_DISCOVERY_PHASE
9+
#if __has_include("Arduino_RouterBridge.h")
10+
#if __has_include("routerbridge_provides_serial.h")
11+
#define ARDUINO_ROUTERBRIDGE_PROVIDES_SERIAL
12+
#else
13+
#error "Please update the Arduino_RouterBridge library to the latest version to ensure Serial support on this board."
14+
#endif
15+
#endif
16+
#endif
17+
718
// TODO: correctly handle these legacy defines
819
#define MOSI 0
920
#define MISO 0
@@ -27,4 +38,4 @@
2738

2839
#define LED4_R DIGITAL_PIN_GPIOS_FIND_NODE(DT_NODELABEL(led4_red))
2940
#define LED4_G DIGITAL_PIN_GPIOS_FIND_NODE(DT_NODELABEL(led4_green))
30-
#define LED4_B DIGITAL_PIN_GPIOS_FIND_NODE(DT_NODELABEL(led4_blue))
41+
#define LED4_B DIGITAL_PIN_GPIOS_FIND_NODE(DT_NODELABEL(led4_blue))

0 commit comments

Comments
 (0)