Skip to content

Commit 17c8ceb

Browse files
committed
UART rework
many possible problems fixed in preparation for thread-safe
1 parent 50b060a commit 17c8ceb

File tree

4 files changed

+153
-132
lines changed

4 files changed

+153
-132
lines changed

Diff for: cores/esp32/HardwareSerial.cpp

+4-36
Original file line numberDiff line numberDiff line change
@@ -33,80 +33,48 @@ void HardwareSerial::setDebugOutput(bool en)
3333
return;
3434
}
3535
if(en) {
36-
if(_uart->txEnabled) {
37-
uartSetDebug(_uart);
38-
} else {
39-
uartSetDebug(0);
40-
}
36+
uartSetDebug(_uart);
4137
} else {
4238
if(uartGetDebug() == _uart_nr) {
4339
uartSetDebug(0);
4440
}
4541
}
4642
}
4743

48-
bool HardwareSerial::isTxEnabled(void)
49-
{
50-
if(_uart == 0) {
51-
return false;
52-
}
53-
return _uart->txEnabled;
54-
}
55-
56-
bool HardwareSerial::isRxEnabled(void)
57-
{
58-
if(_uart == 0) {
59-
return false;
60-
}
61-
return _uart->rxEnabled;
62-
}
63-
6444
int HardwareSerial::available(void)
6545
{
66-
if (_uart && _uart->rxEnabled) {
67-
return uartAvailable(_uart);
68-
}
69-
return 0;
46+
return uartAvailable(_uart);
7047
}
7148

7249
int HardwareSerial::peek(void)
7350
{
74-
if (_uart && _uart->rxEnabled) {
51+
if (available()) {
7552
return uartPeek(_uart);
7653
}
7754
return -1;
7855
}
7956

8057
int HardwareSerial::read(void)
8158
{
82-
if(_uart && _uart->rxEnabled) {
59+
if(available()) {
8360
return uartRead(_uart);
8461
}
8562
return -1;
8663
}
8764

8865
void HardwareSerial::flush()
8966
{
90-
if(_uart == 0 || !_uart->txEnabled) {
91-
return;
92-
}
9367
uartFlush(_uart);
9468
}
9569

9670
size_t HardwareSerial::write(uint8_t c)
9771
{
98-
if(_uart == 0 || !_uart->txEnabled) {
99-
return 0;
100-
}
10172
uartWrite(_uart, c);
10273
return 1;
10374
}
10475

10576
size_t HardwareSerial::write(const uint8_t *buffer, size_t size)
10677
{
107-
if(_uart == 0 || !_uart->txEnabled) {
108-
return 0;
109-
}
11078
uartWriteBuf(_uart, buffer, size);
11179
return size;
11280
}

Diff for: cores/esp32/HardwareSerial.h

-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ class HardwareSerial: public Stream
6565
operator bool() const;
6666

6767
void setDebugOutput(bool);
68-
bool isTxEnabled(void);
69-
bool isRxEnabled(void);
7068

7169
protected:
7270
int _uart_nr;

0 commit comments

Comments
 (0)