File tree Expand file tree Collapse file tree 4 files changed +77
-5
lines changed Expand file tree Collapse file tree 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)())
11881188
11891189#if defined(STM32H747xx) && defined(CORE_CM4)
11901190
1191- RPCDebugCommInterface::RPCDebugCommInterface (arduino::RPC * pSerial) :
1191+ RPCDebugCommInterface::RPCDebugCommInterface (arduino::SerialRPCClass * pSerial) :
11921192 _pSerial(pSerial)
11931193{
1194- _pSerial->begin ();
1194+ // _pSerial->begin();
11951195}
11961196
11971197RPCDebugCommInterface::~RPCDebugCommInterface ()
Original file line number Diff line number Diff line change 3636
3737#if defined(STM32H747xx) && defined(CORE_CM4)
3838// include RPC out of arduino namespace
39- #include " RPC_internal .h"
39+ #include " SerialRPC .h"
4040#endif
4141
4242namespace arduino {
@@ -102,7 +102,7 @@ class UsbDebugCommInterface : public DebugCommInterface {
102102// Use the RPC interface to communicate with GDB from M4 core
103103class RPCDebugCommInterface : public DebugCommInterface {
104104public:
105- RPCDebugCommInterface (arduino::RPC *);
105+ RPCDebugCommInterface (arduino::SerialRPCClass *);
106106 virtual ~RPCDebugCommInterface ();
107107
108108 virtual bool readable ();
@@ -112,7 +112,7 @@ class RPCDebugCommInterface : public DebugCommInterface {
112112 virtual void attach (void (*pCallback)());
113113
114114protected:
115- arduino::RPC * _pSerial;
115+ arduino::SerialRPCClass * _pSerial;
116116};
117117#endif
118118
You can’t perform that action at this time.
0 commit comments