Skip to content

Commit a2b8112

Browse files
committed
Allow stdio port to use in HardwareSerial
Signed-off-by: Ajay Bhargav <[email protected]>
1 parent ea41dc0 commit a2b8112

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

cores/siwigsm/HardwareSerial.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <unistd.h>
44
#include <sys/termios.h>
55
#include <sys/ioctl.h>
6+
#include <string.h>
67

78
#include <lib.h>
89

@@ -38,12 +39,17 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config)
3839
if (_port_file == NULL)
3940
return;
4041

42+
is_stdio = !strcmp(_port_file, DEFAULT_STDIO_PORT);
43+
4144
if (_fd > 0)
4245
close(_fd);
4346

44-
_fd = open(_port_file, O_RDWR | O_NONBLOCK);
45-
if (_fd < 0)
46-
return;
47+
/* No need to init fd when stdio */
48+
if (!is_stdio) {
49+
_fd = open(_port_file, O_RDWR | O_NONBLOCK);
50+
if (_fd < 0)
51+
return;
52+
}
4753

4854
baud = baud ? baud : B115200;
4955
switch (baud) {
@@ -141,7 +147,7 @@ int HardwareSerial::read(void)
141147

142148
size_t HardwareSerial::write(uint8_t c)
143149
{
144-
return write_byte(_fd, &c);
150+
return write_byte(is_stdio ? STDOUT_FILENO : _fd, &c);
145151
}
146152

147153
void HardwareSerial::flush(void)

cores/siwigsm/HardwareSerial.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class HardwareSerial: public Stream {
8686
protected:
8787
const char *_port_file;
8888
int _fd;
89+
bool is_stdio;
8990
};
9091

9192
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL)

0 commit comments

Comments
 (0)