Skip to content

Commit 2893f54

Browse files
committed
Fix core to match mbed deprecation
1 parent ffd6f5c commit 2893f54

File tree

4 files changed

+14
-30
lines changed

4 files changed

+14
-30
lines changed

cores/arduino/Serial.cpp

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void UART::begin(unsigned long baudrate, uint16_t config) {
7474

7575
void UART::begin(unsigned long baudrate) {
7676
if (_serial == NULL) {
77-
_serial = new mbed::RawSerial(tx, rx, baudrate);
77+
_serial = new mbed::UnbufferedSerial(tx, rx, baudrate);
7878
}
7979
if (rts != NC) {
8080
_serial->set_flow_control(mbed::SerialBase::Flow::RTSCTS, rts, cts);
@@ -86,7 +86,8 @@ void UART::begin(unsigned long baudrate) {
8686

8787
void UART::on_rx() {
8888
while(_serial->readable()) {
89-
rx_buffer.store_char(_serial->getc());
89+
char c;
90+
rx_buffer.store_char(_serial->read(&c, 1));
9091
}
9192
}
9293

@@ -115,33 +116,16 @@ void UART::flush() {
115116

116117
size_t UART::write(uint8_t c) {
117118
while (!_serial->writeable()) {}
118-
int ret = _serial->putc(c);
119+
int ret = _serial->write(&c, 1);
119120
return ret == -1 ? 0 : 1;
120121
}
121122

122-
#ifdef DEVICE_SERIAL_ASYNCH
123123
size_t UART::write(const uint8_t* c, size_t len) {
124-
125-
uint8_t* p = (uint8_t*)c;
126-
uint8_t* end = p + len;
127-
128-
while (!_serial->writeable()) yield();
129-
130-
auto _write_block = [this](const uint8_t* c, size_t len) {
131-
_block = true;
132-
_serial->write(c, len, mbed::callback(this, &UART::block_tx));
133-
while (_block == true) yield();
134-
return len;
135-
};
136-
137-
while ( p < end ) {
138-
size_t _len = end - p < WRITE_BUFF_SZ ? len % WRITE_BUFF_SZ : WRITE_BUFF_SZ;
139-
p += _write_block(p, _len);
140-
}
141-
142-
return len;
124+
while (!_serial->writeable()) {}
125+
_serial->set_blocking(true);
126+
int ret = _serial->write(c, len);
127+
return ret == -1 ? 0 : 1;
143128
}
144-
#endif
145129

146130
void UART::block_tx(int _a) {
147131
_block = false;

cores/arduino/Serial.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#include "api/RingBuffer.h"
2424
#include "Arduino.h"
25-
#include "mbed/drivers/RawSerial.h"
25+
#include "mbed/drivers/UnbufferedSerial.h"
2626

2727
#ifdef __cplusplus
2828

@@ -42,9 +42,7 @@ class UART : public HardwareSerial {
4242
int read(void);
4343
void flush(void);
4444
size_t write(uint8_t c);
45-
#ifdef DEVICE_SERIAL_ASYNCH
4645
size_t write(const uint8_t*, size_t);
47-
#endif
4846
using Print::write; // pull in write(str) and write(buf, size) from Print
4947
operator bool();
5048

@@ -54,7 +52,7 @@ class UART : public HardwareSerial {
5452
bool _block;
5553
// See https://github.com/ARMmbed/mbed-os/blob/f5b5989fc81c36233dbefffa1d023d1942468d42/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/serial_api.c#L76
5654
const size_t WRITE_BUFF_SZ = 32;
57-
mbed::RawSerial* _serial = NULL;
55+
mbed::UnbufferedSerial* _serial = NULL;
5856
PinName tx, rx, rts, cts;
5957
RingBufferN<256> rx_buffer;
6058
uint8_t intermediate_buf[4];

libraries/WiFi/src/WiFiClient.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ int arduino::WiFiClient::connect(IPAddress ip, uint16_t port) {
3030

3131
int arduino::WiFiClient::connect(const char *host, uint16_t port) {
3232
if (sock == NULL) {
33-
sock = new TCPSocket(WiFi.getNetwork());
33+
sock = new TCPSocket();
34+
((TCPSocket*)sock)->open(WiFi.getNetwork());
3435
}
3536
//sock->sigio(mbed::callback(this, &WiFiClient::getStatus));
3637
//sock->set_blocking(false);

libraries/WiFi/src/WiFiServer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ uint8_t arduino::WiFiServer::status() {
1717

1818
void arduino::WiFiServer::begin() {
1919
if (sock == NULL) {
20-
sock = new TCPSocket(WiFi.getNetwork());
20+
sock = new TCPSocket();
21+
((TCPSocket*)sock)->open(WiFi.getNetwork());
2122
}
2223
sock->bind(_port);
2324
sock->listen(5);

0 commit comments

Comments
 (0)