File tree 2 files changed +23
-2
lines changed
2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ void Uart::end()
50
50
{
51
51
sercom->resetUART ();
52
52
rxBuffer.clear ();
53
+ txBuffer.clear ();
53
54
}
54
55
55
56
void Uart::flush ()
@@ -59,6 +60,16 @@ void Uart::flush()
59
60
60
61
void Uart::IrqHandler ()
61
62
{
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
+
62
73
if (sercom->availableDataUART ()) {
63
74
rxBuffer.store_char (sercom->readDataUART ());
64
75
}
@@ -79,7 +90,7 @@ int Uart::available()
79
90
80
91
int Uart::availableForWrite ()
81
92
{
82
- return (sercom-> isDataRegisterEmptyUART () ? 1 : 0 );
93
+ return txBuffer. availableForStore ( );
83
94
}
84
95
85
96
int Uart::peek ()
@@ -94,7 +105,16 @@ int Uart::read()
94
105
95
106
size_t Uart::write (const uint8_t data)
96
107
{
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
+
98
118
return 1 ;
99
119
}
100
120
Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ class Uart : public HardwareSerial
46
46
private:
47
47
SERCOM *sercom;
48
48
RingBuffer rxBuffer;
49
+ RingBuffer txBuffer;
49
50
50
51
uint8_t uc_pinRX;
51
52
uint8_t uc_pinTX;
You can’t perform that action at this time.
0 commit comments