File tree 4 files changed +77
-5
lines changed
4 files changed +77
-5
lines changed Original file line number Diff line number Diff line change
1
+ #include " SerialRPC.h"
2
+
3
+ arduino::SerialRPCClass SerialRPC;
Original file line number Diff line number Diff line change
1
+ #include " RPC_internal.h"
2
+ #include " Arduino.h"
3
+
4
+ namespace arduino {
5
+
6
+ class SerialRPCClass : public Stream {
7
+
8
+ public:
9
+ SerialRPCClass () {};
10
+ void end () {};
11
+ int available (void ) {
12
+ return rx_buffer.available ();
13
+ };
14
+ int peek (void ) {
15
+ return rx_buffer.peek ();
16
+ }
17
+ int read (void ) {
18
+ return rx_buffer.read_char ();
19
+ }
20
+ void flush (void ) {};
21
+
22
+ using Print::write; // pull in write(str) and write(buf, size) from Print
23
+
24
+ void onWrite (std::vector<uint8_t > vec) {
25
+ for (int i = 0 ; i < vec.size (); i++) {
26
+ rx_buffer.store_char (vec[i]);
27
+ }
28
+ // call attached function
29
+ if (_rx) {
30
+ _rx.call ();
31
+ }
32
+ }
33
+
34
+ size_t write (uint8_t c) {
35
+ write (&c, 1 );
36
+ }
37
+
38
+ size_t write (uint8_t * buf, size_t len) {
39
+ tx_buffer.clear ();
40
+ for (int i=0 ; i<len; i++) {
41
+ tx_buffer.push_back (buf[i]);
42
+ }
43
+ RPC1.call (" on_write" , tx_buffer);
44
+ }
45
+
46
+ int begin () {
47
+ RPC1.begin ();
48
+ RPC1.bind (" on_write" , mbed::callback (this , &SerialRPCClass::onWrite));
49
+ }
50
+
51
+ operator bool () {
52
+ return RPC1;
53
+ }
54
+
55
+ void attach (void (*fptr)(void ))
56
+ {
57
+ if (fptr != NULL ) {
58
+ _rx = mbed::Callback<void ()>(fptr);
59
+ }
60
+ }
61
+
62
+ private:
63
+ mbed::Callback<void ()> _rx;
64
+ RingBufferN<1024 > rx_buffer;
65
+ std::vector<uint8_t > tx_buffer;
66
+ };
67
+ }
68
+
69
+ extern arduino::SerialRPCClass SerialRPC;
Original file line number Diff line number Diff line change @@ -1188,10 +1188,10 @@ void UsbDebugCommInterface::attach(void (*pCallback)())
1188
1188
1189
1189
#if defined(STM32H747xx) && defined(CORE_CM4)
1190
1190
1191
- RPCDebugCommInterface::RPCDebugCommInterface (arduino::RPC * pSerial) :
1191
+ RPCDebugCommInterface::RPCDebugCommInterface (arduino::SerialRPCClass * pSerial) :
1192
1192
_pSerial(pSerial)
1193
1193
{
1194
- _pSerial->begin ();
1194
+ // _pSerial->begin();
1195
1195
}
1196
1196
1197
1197
RPCDebugCommInterface::~RPCDebugCommInterface ()
Original file line number Diff line number Diff line change 36
36
37
37
#if defined(STM32H747xx) && defined(CORE_CM4)
38
38
// include RPC out of arduino namespace
39
- #include " RPC_internal .h"
39
+ #include " SerialRPC .h"
40
40
#endif
41
41
42
42
namespace arduino {
@@ -102,7 +102,7 @@ class UsbDebugCommInterface : public DebugCommInterface {
102
102
// Use the RPC interface to communicate with GDB from M4 core
103
103
class RPCDebugCommInterface : public DebugCommInterface {
104
104
public:
105
- RPCDebugCommInterface (arduino::RPC *);
105
+ RPCDebugCommInterface (arduino::SerialRPCClass *);
106
106
virtual ~RPCDebugCommInterface ();
107
107
108
108
virtual bool readable ();
@@ -112,7 +112,7 @@ class RPCDebugCommInterface : public DebugCommInterface {
112
112
virtual void attach (void (*pCallback)());
113
113
114
114
protected:
115
- arduino::RPC * _pSerial;
115
+ arduino::SerialRPCClass * _pSerial;
116
116
};
117
117
#endif
118
118
You can’t perform that action at this time.
0 commit comments