1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-21 10:26:06 +03:00

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.
This commit is contained in:
Christopher Pascoe 2015-12-29 12:46:25 -05:00
parent 2375fb0f86
commit bc9493e690
2 changed files with 1 additions and 7 deletions

View File

@ -485,7 +485,7 @@ int uart_get_debug() {
// #################################################################################################### // ####################################################################################################
HardwareSerial::HardwareSerial(int uart_nr) : HardwareSerial::HardwareSerial(int uart_nr) :
_uart_nr(uart_nr), _uart(0), _tx_buffer(0), _rx_buffer(0), _written(false) { _uart_nr(uart_nr), _uart(0), _tx_buffer(0), _rx_buffer(0) {
} }
void HardwareSerial::begin(unsigned long baud, byte config, byte mode) { void HardwareSerial::begin(unsigned long baud, byte config, byte mode) {
@ -519,7 +519,6 @@ void HardwareSerial::begin(unsigned long baud, byte config, byte mode) {
_uart->txEnabled = false; _uart->txEnabled = false;
} }
} }
_written = false;
delay(1); delay(1);
uart_finish_init(_uart); uart_finish_init(_uart);
@ -626,8 +625,6 @@ void HardwareSerial::flush() {
return; return;
if(!_uart->txEnabled) if(!_uart->txEnabled)
return; return;
if(!_written)
return;
const int uart_nr = _uart->uart_nr; const int uart_nr = _uart->uart_nr;
while(true) { while(true) {
@ -643,13 +640,11 @@ void HardwareSerial::flush() {
} }
yield(); yield();
} }
_written = false;
} }
size_t HardwareSerial::write(uint8_t c) { size_t HardwareSerial::write(uint8_t c) {
if(_uart == 0 || !_uart->txEnabled) if(_uart == 0 || !_uart->txEnabled)
return 0; return 0;
_written = true;
bool tx_now = false; bool tx_now = false;
const int uart_nr = _uart->uart_nr; const int uart_nr = _uart->uart_nr;

View File

@ -117,7 +117,6 @@ class HardwareSerial: public Stream {
uart_t* _uart; uart_t* _uart;
cbuf* _tx_buffer; cbuf* _tx_buffer;
cbuf* _rx_buffer; cbuf* _rx_buffer;
bool _written;
}; };
extern HardwareSerial Serial; extern HardwareSerial Serial;