Skip to content

Commit bc9493e

Browse files
Remove tracking of whether write() was called.
Tracking _written was required on AVR devices to work around a hardware limitation when implementing flush(). The ESP8266 doesn't have the same issue, so we can remove the tracking and make write() more lightweight. The cost is a minor increase in work done in flush() when write() was not previously called, but this should be much rarer than individual character writes.
1 parent 2375fb0 commit bc9493e

File tree

2 files changed

+1
-7
lines changed

2 files changed

+1
-7
lines changed

cores/esp8266/HardwareSerial.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ int uart_get_debug() {
485485
// ####################################################################################################
486486

487487
HardwareSerial::HardwareSerial(int uart_nr) :
488-
_uart_nr(uart_nr), _uart(0), _tx_buffer(0), _rx_buffer(0), _written(false) {
488+
_uart_nr(uart_nr), _uart(0), _tx_buffer(0), _rx_buffer(0) {
489489
}
490490

491491
void HardwareSerial::begin(unsigned long baud, byte config, byte mode) {
@@ -519,7 +519,6 @@ void HardwareSerial::begin(unsigned long baud, byte config, byte mode) {
519519
_uart->txEnabled = false;
520520
}
521521
}
522-
_written = false;
523522
delay(1);
524523

525524
uart_finish_init(_uart);
@@ -626,8 +625,6 @@ void HardwareSerial::flush() {
626625
return;
627626
if(!_uart->txEnabled)
628627
return;
629-
if(!_written)
630-
return;
631628

632629
const int uart_nr = _uart->uart_nr;
633630
while(true) {
@@ -643,13 +640,11 @@ void HardwareSerial::flush() {
643640
}
644641
yield();
645642
}
646-
_written = false;
647643
}
648644

649645
size_t HardwareSerial::write(uint8_t c) {
650646
if(_uart == 0 || !_uart->txEnabled)
651647
return 0;
652-
_written = true;
653648

654649
bool tx_now = false;
655650
const int uart_nr = _uart->uart_nr;

cores/esp8266/HardwareSerial.h

-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ class HardwareSerial: public Stream {
117117
uart_t* _uart;
118118
cbuf* _tx_buffer;
119119
cbuf* _rx_buffer;
120-
bool _written;
121120
};
122121

123122
extern HardwareSerial Serial;

0 commit comments

Comments
 (0)