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.
Prior to this change, if interrupts were disabled during a call to
HardwareSerial::write() when the circular buffer was full, or
HardwareSerial::flush() when the circular buffer was non-empty,
we would loop forever and trip a watchdog timeout.
Prior to this change, the interrupt could fire during initialisation,
necessitating a deep check that the HardwareSerial structure had valid
_tx_buffer or _rx_buffer each time an interrupt occurred.
By keeping uart_t's and HardwareSerial's (txEnabled, _tx_buffer) and
(rxEnabled, _rx_buffer) in sync, we can remove this extra check, as
well as fixing a null pointer dereference if e.g. _tx_buffer allocation
failed and write() was subsequently called.
This is required per the non-OS SDK doc, which states:
"Using non-OS SDK, please do not call any function defined with
ICACHE_FLASH_ATTR in the interrupt handler."
This avoids an "Illegal instruction" exception with epc1 pointing at a valid
instruction (in flash) for one of the moved methods.
Not sure why, but this reduces the occurrence rate of an occasional ~3.25 or
~7μs intercharacter delay, which was interfering with use of the UART to
generate precise timing pulses (such as driving WS2812 LEDs).