Skip to content

Commit 67e3168

Browse files
committed
Serial: Deprecate the class and promote UnbufferedSerial instead
1 parent 6be7aad commit 67e3168

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

drivers/Serial.h

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ namespace mbed {
3333
* @{
3434
*/
3535

36-
/** A serial port (UART) for communication with other serial devices
36+
/** @deprecated
37+
* A serial port (UART) for communication with other serial devices
3738
*
3839
* Can be used for Full Duplex communication, or Simplex by specifying
3940
* one pin as NC (Not Connected)
@@ -53,7 +54,11 @@ namespace mbed {
5354
* }
5455
* @endcode
5556
*/
56-
class Serial : public SerialBase, public Stream, private NonCopyable<Serial> {
57+
class
58+
MBED_DEPRECATED_SINCE(
59+
"mbed-os-6.0.0",
60+
"Use printf and puts instead to access the console, BufferedSerial for blocking applications or UnbufferedSerial if bypassing locks in IRQ or short of RAM."
61+
) Serial : public SerialBase, public Stream, private NonCopyable<Serial> {
5762

5863
public:
5964
#if DEVICE_SERIAL_ASYNCH
@@ -67,7 +72,8 @@ class Serial : public SerialBase, public Stream, private NonCopyable<Serial> {
6772
using SerialBase::enable_input;
6873
using SerialBase::enable_output;
6974

70-
/** Create a Serial port, connected to the specified transmit and receive pins
75+
/** @deprecated
76+
* Create a Serial port, connected to the specified transmit and receive pins
7177
*
7278
* @param tx Transmit pin
7379
* @param rx Receive pin
@@ -77,9 +83,11 @@ class Serial : public SerialBase, public Stream, private NonCopyable<Serial> {
7783
* @note
7884
* Either tx or rx may be specified as NC (Not Connected) if unused
7985
*/
86+
MBED_DEPRECATED("The class has been deprecated and will be removed in the future.")
8087
Serial(PinName tx, PinName rx, const char *name = NULL, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
8188

82-
/** Create a Serial port, connected to the specified transmit and receive pins
89+
/** @deprecated
90+
* Create a Serial port, connected to the specified transmit and receive pins
8391
*
8492
* @param static_pinmap reference to structure which holds static pinmap.
8593
* @param name The name of the stream associated with this serial port (optional)
@@ -88,10 +96,13 @@ class Serial : public SerialBase, public Stream, private NonCopyable<Serial> {
8896
* @note
8997
* Either tx or rx may be specified as NC (Not Connected) if unused
9098
*/
99+
MBED_DEPRECATED("The class has been deprecated and will be removed in the future.")
91100
Serial(const serial_pinmap_t &static_pinmap, const char *name = NULL, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
101+
MBED_DEPRECATED("The class has been deprecated and will be removed in the future.")
92102
Serial(const serial_pinmap_t &&, const char * = NULL, int = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE) = delete; // prevent passing of temporary objects
93103

94-
/** Create a Serial port, connected to the specified transmit and receive pins, with the specified baud
104+
/** @deprecated
105+
* Create a Serial port, connected to the specified transmit and receive pins, with the specified baud
95106
*
96107
* @param tx Transmit pin
97108
* @param rx Receive pin
@@ -100,31 +111,38 @@ class Serial : public SerialBase, public Stream, private NonCopyable<Serial> {
100111
* @note
101112
* Either tx or rx may be specified as NC (Not Connected) if unused
102113
*/
114+
MBED_DEPRECATED("The class has been deprecated and will be removed in the future.")
103115
Serial(PinName tx, PinName rx, int baud);
104116

105-
/** Create a Serial port, connected to the specified transmit and receive pins, with the specified baud
117+
/** @deprecated
118+
* Create a Serial port, connected to the specified transmit and receive pins, with the specified baud
106119
*
107120
* @param static_pinmap reference to structure which holds static pinmap.
108121
* @param baud The baud rate of the serial port
109122
*
110123
* @note
111124
* Either tx or rx may be specified as NC (Not Connected) if unused
112125
*/
126+
MBED_DEPRECATED("The class has been deprecated and will be removed in the future.")
113127
Serial(const serial_pinmap_t &static_pinmap, int baud);
128+
MBED_DEPRECATED("The class has been deprecated and will be removed in the future.")
114129
Serial(const serial_pinmap_t &&, int) = delete; // prevent passing of temporary objects
115130

116131
/* Stream gives us a FileHandle with non-functional poll()/readable()/writable. Pass through
117132
* the calls from the SerialBase instead for backwards compatibility. This problem is
118133
* part of why Stream and Serial should be deprecated.
119134
*/
135+
MBED_DEPRECATED("The class has been deprecated and will be removed in the future.")
120136
bool readable()
121137
{
122138
return SerialBase::readable();
123139
}
140+
MBED_DEPRECATED("The class has been deprecated and will be removed in the future.")
124141
bool writable()
125142
{
126143
return SerialBase::writeable();
127144
}
145+
MBED_DEPRECATED("The class has been deprecated and will be removed in the future.")
128146
bool writeable()
129147
{
130148
return SerialBase::writeable();

drivers/UnbufferedSerial.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@ class UnbufferedSerial:
155155
*/
156156
virtual short poll(short events) const;
157157

158+
/* Resolve ambiguities versus our private SerialBase
159+
* (for writable, spelling differs, but just in case)
160+
*/
161+
using SerialBase::readable;
162+
using SerialBase::writeable;
163+
using SerialBase::format;
164+
using SerialBase::attach;
165+
using SerialBase::baud;
166+
158167
#if DEVICE_SERIAL_FC
159168
// For now use the base enum - but in future we may have extra options
160169
// such as XON/XOFF or manual GPIO RTSCTS.

features/FEATURE_BLE/targets/TARGET_CORDIO/driver/H4TransportDriver.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ uint16_t H4TransportDriver::write(uint8_t type, uint16_t len, uint8_t *pData)
5353
while (i < len + 1) {
5454
uint8_t to_write = i == 0 ? type : pData[i - 1];
5555
while (uart.writeable() == 0);
56-
uart.putc(to_write);
56+
uart.write(&to_write, 1);
5757
++i;
5858
}
5959
return len;
@@ -62,7 +62,8 @@ uint16_t H4TransportDriver::write(uint8_t type, uint16_t len, uint8_t *pData)
6262
void H4TransportDriver::on_controller_irq()
6363
{
6464
while (uart.readable()) {
65-
uint8_t char_received = uart.getc();
65+
uint8_t char_received;
66+
uart.read(&char_received, 1);
6667
on_data_received(&char_received, 1);
6768
}
6869
}

features/FEATURE_BLE/targets/TARGET_Cypress/COMPONENT_CYW43XXX/CyH4TransportDriver.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ uint16_t CyH4TransportDriver::write(uint8_t type, uint16_t len, uint8_t *pData)
151151
while (i < len + 1) {
152152
uint8_t to_write = i == 0 ? type : pData[i - 1];
153153
while (uart.writeable() == 0);
154-
uart.putc(to_write);
154+
uart.write(&to_write, 1);
155155
++i;
156156
}
157157

@@ -165,8 +165,10 @@ void CyH4TransportDriver::on_controller_irq()
165165
sleep_manager_lock_deep_sleep();
166166

167167
while (uart.readable()) {
168-
uint8_t char_received = uart.getc();
169-
on_data_received(&char_received, 1);
168+
uint8_t char_received;
169+
if (uart.read(&char_received, 1)) {
170+
on_data_received(&char_received, 1);
171+
}
170172
}
171173

172174
sleep_manager_unlock_deep_sleep();

0 commit comments

Comments
 (0)