Skip to content

Commit 82a30d4

Browse files
committed
PortentaX8: allow using RPC as fake Serial
1 parent 92119bc commit 82a30d4

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

cores/arduino/Arduino.h

+10
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ extern analogin_config_t adcCurrentConfig;
112112
#define Serial3 _UART3_
113113
#define Serial4 _UART4_
114114

115+
#if defined(RPC_SERIAL)
116+
#undef Serial
117+
#if __has_include("RPC.h")
118+
#define Serial RPC
119+
#else
120+
extern ErrorSerialClass ErrorSerial;
121+
#define Serial ErrorSerial
122+
#endif
123+
#endif
124+
115125
#include "overloads.h"
116126
#endif
117127

libraries/RPC/src/RPC.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ static void disableCM4Autoboot() {
139139
}
140140
}
141141

142-
int RPCClass::begin() {
142+
int RPCClass::begin(long unsigned int np, uint16_t nd) {
143143

144144
OpenAMP_MPU_Config();
145145

@@ -194,7 +194,7 @@ int RPCClass::begin() {
194194

195195
#ifdef CORE_CM4
196196

197-
int RPCClass::begin() {
197+
int RPCClass::begin(long unsigned int np, uint16_t nd) {
198198

199199
eventThread = new rtos::Thread(osPriorityHigh);
200200
eventThread->start(&eventHandler);

libraries/RPC/src/RPC.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace arduino {
4444
class RPCClass : public Stream, public rpc::detail::dispatcher {
4545
public:
4646
RPCClass() {};
47-
int begin();
47+
int begin(long unsigned int = 0, uint16_t = 0);
4848
void end() {};
4949
int available(void) {
5050
return rx_buffer.available();

variants/PORTENTA_X8/pins_arduino.h

+28-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static const uint8_t SCK = PIN_SPI_SCK;
100100
#define PIN_WIRE_SDA (11u)
101101
#define PIN_WIRE_SCL (12u)
102102

103-
//#define SERIAL_CDC 0
103+
#define RPC_SERIAL 1
104104
#define HAS_UNIQUE_ISERIAL_DESCRIPTOR
105105
#define BOARD_VENDORID 0x2341
106106
#define BOARD_PRODUCTID 0x0061
@@ -136,4 +136,31 @@ void _ontouch1200bps_();
136136

137137
#define USB_MAX_POWER (500)
138138

139+
#ifdef __cplusplus
140+
141+
#include "api/HardwareSerial.h"
142+
143+
#define MACRO_ERROR_SERIAL_STR "\n\n****\nPlease include RPC library to use Serial\n****\n\n"
144+
#define MACRO_ERROR_SERIAL __attribute__ ((error(MACRO_ERROR_SERIAL_STR)))
145+
146+
class ErrorSerialClass : public arduino::HardwareSerial {
147+
public:
148+
ErrorSerialClass() {};
149+
~ErrorSerialClass() {};
150+
void MACRO_ERROR_SERIAL begin(long unsigned int);
151+
void MACRO_ERROR_SERIAL begin(long unsigned int, uint16_t);
152+
size_t MACRO_ERROR_SERIAL write(uint8_t);
153+
MACRO_ERROR_SERIAL operator bool();
154+
void MACRO_ERROR_SERIAL end();
155+
int MACRO_ERROR_SERIAL peek();
156+
int MACRO_ERROR_SERIAL read();
157+
int MACRO_ERROR_SERIAL available();
158+
void MACRO_ERROR_SERIAL flush();
159+
};
160+
161+
extern ErrorSerialClass ErrorSerial;
162+
163+
#endif
164+
165+
139166
#endif //__PINS_ARDUINO__

0 commit comments

Comments
 (0)