File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ void Uart::end()
5050{
5151 sercom->resetUART ();
5252 rxBuffer.clear ();
53+ txBuffer.clear ();
5354}
5455
5556void Uart::flush ()
@@ -59,6 +60,16 @@ void Uart::flush()
5960
6061void Uart::IrqHandler ()
6162{
63+ if (sercom->isDataRegisterEmptyUART ()) {
64+ if (txBuffer.available ()) {
65+ uint8_t data = txBuffer.read_char ();
66+
67+ sercom->writeDataUART (data);
68+ } else {
69+ sercom->disableDataRegisterEmptyInterruptUART ();
70+ }
71+ }
72+
6273 if (sercom->availableDataUART ()) {
6374 rxBuffer.store_char (sercom->readDataUART ());
6475 }
@@ -79,7 +90,7 @@ int Uart::available()
7990
8091int Uart::availableForWrite ()
8192{
82- return (sercom-> isDataRegisterEmptyUART () ? 1 : 0 );
93+ return txBuffer. availableForStore ( );
8394}
8495
8596int Uart::peek ()
@@ -94,7 +105,16 @@ int Uart::read()
94105
95106size_t Uart::write (const uint8_t data)
96107{
97- sercom->writeDataUART (data);
108+ if (sercom->isDataRegisterEmptyUART ()) {
109+ sercom->writeDataUART (data);
110+ } else {
111+ while (txBuffer.isFull ()); // spin lock until a spot opens up in the buffer
112+
113+ txBuffer.store_char (data);
114+
115+ sercom->enableDataRegisterEmptyInterruptUART ();
116+ }
117+
98118 return 1 ;
99119}
100120
Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ class Uart : public HardwareSerial
4646 private:
4747 SERCOM *sercom;
4848 RingBuffer rxBuffer;
49+ RingBuffer txBuffer;
4950
5051 uint8_t uc_pinRX;
5152 uint8_t uc_pinTX;
You can’t perform that action at this time.
0 commit comments