-
-
Notifications
You must be signed in to change notification settings - Fork 212
/
Copy path0100-SerialBase-implement-sw-flow-control.patch
88 lines (81 loc) · 2.55 KB
/
0100-SerialBase-implement-sw-flow-control.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
From d74af6c60c8098de8a7839a2af09f0159f673ca5 Mon Sep 17 00:00:00 2001
From: Martino Facchin <m.facchin@arduino.cc>
Date: Thu, 5 Aug 2021 15:13:58 +0200
Subject: [PATCH 100/204] SerialBase: implement sw flow control
---
drivers/include/drivers/SerialBase.h | 9 ++++++++-
drivers/source/SerialBase.cpp | 14 ++++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/drivers/include/drivers/SerialBase.h b/drivers/include/drivers/SerialBase.h
index 9288c271e1..7d8734c7af 100644
--- a/drivers/include/drivers/SerialBase.h
+++ b/drivers/include/drivers/SerialBase.h
@@ -26,6 +26,9 @@
#include "platform/mbed_toolchain.h"
#include "platform/NonCopyable.h"
+#include "drivers/DigitalOut.h"
+#include "drivers/DigitalIn.h"
+
#if DEVICE_SERIAL_ASYNCH
#include "platform/CThunk.h"
#include "hal/dma_api.h"
@@ -71,7 +74,8 @@ public:
Disabled = 0,
RTS,
CTS,
- RTSCTS
+ RTSCTS,
+ RTSCTS_SW
};
/** Set the transmission format used by the serial port
@@ -326,8 +330,11 @@ protected:
Flow _flow_type = Disabled;
PinName _flow1 = NC;
PinName _flow2 = NC;
+ DigitalIn* _cts_pin;
+ DigitalOut* _rts_pin;
const serial_fc_pinmap_t *_static_pinmap_fc = NULL;
void (SerialBase::*_set_flow_control_sp_func)(Flow, const serial_fc_pinmap_t &) = NULL;
+ bool sw_flow_control = false;
#endif
#endif
diff --git a/drivers/source/SerialBase.cpp b/drivers/source/SerialBase.cpp
index 40bf7d0b61..7c21d12e9c 100644
--- a/drivers/source/SerialBase.cpp
+++ b/drivers/source/SerialBase.cpp
@@ -71,6 +71,9 @@ int SerialBase::readable()
{
lock();
int ret = serial_readable(&_serial);
+ if (sw_flow_control == true && _rts_pin != nullptr) {
+ *_rts_pin = !!!ret;
+ }
unlock();
return ret;
}
@@ -80,6 +83,9 @@ int SerialBase::writeable()
{
lock();
int ret = serial_writable(&_serial);
+ if (sw_flow_control) {
+ ret = ret & !(*_cts_pin);
+ }
unlock();
return ret;
}
@@ -319,6 +325,14 @@ void SerialBase::set_flow_control(Flow type, PinName flow1, PinName flow2)
serial_set_flow_control(&_serial, flow_type, flow1, flow2);
break;
+ case RTSCTS_SW:
+ sw_flow_control = true;
+ if (_flow1 != NC)
+ _cts_pin = new DigitalIn(_flow1);
+ if (_flow2 != NC)
+ _rts_pin = new DigitalOut(_flow2, 0);
+ break;
+
default:
break;
}
--
2.39.1