@@ -46,12 +46,11 @@ void Uart::begin(unsigned long baudrate, uint16_t config)
46
46
pinPeripheral (uc_pinTX, g_APinDescription[uc_pinTX].ulPinType );
47
47
48
48
if (uc_pinRTS != NO_RTS_PIN) {
49
- pinMode (uc_pinRTS, OUTPUT);
50
- digitalWrite (uc_pinRTS, LOW);
49
+ pinPeripheral (uc_pinRTS, g_APinDescription[uc_pinRTS].ulPinType );
51
50
}
52
51
53
52
if (uc_pinCTS != NO_CTS_PIN) {
54
- pinMode (uc_pinCTS, INPUT );
53
+ pinPeripheral (uc_pinCTS, g_APinDescription[uc_pinCTS]. ulPinType );
55
54
}
56
55
57
56
sercom->initUART (UART_INT_CLOCK, SAMPLE_RATE_x16, baudrate);
@@ -86,9 +85,10 @@ void Uart::IrqHandler()
86
85
rxBuffer.store_char (sercom->readDataUART ());
87
86
88
87
if (uc_pinRTS != NO_RTS_PIN) {
89
- // if there is NOT enough space in the RX buffer, de-assert RTS
88
+ // if there is NOT enough space in the RX buffer,
89
+ // diable the receive complete interrupt
90
90
if (rxBuffer.availableForStore () < RTS_RX_THRESHOLD) {
91
- digitalWrite (uc_pinRTS, HIGH );
91
+ sercom-> disableReceiveCompleteInterruptUART ( );
92
92
}
93
93
}
94
94
}
@@ -132,9 +132,10 @@ int Uart::read()
132
132
int c = rxBuffer.read_char ();
133
133
134
134
if (uc_pinRTS != NO_RTS_PIN) {
135
- // if there is enough space in the RX buffer, assert RTS
135
+ // if there is enough space in the RX buffer,
136
+ // enable the receive completer interrupt
136
137
if (rxBuffer.availableForStore () > RTS_RX_THRESHOLD) {
137
- digitalWrite (uc_pinRTS, LOW );
138
+ sercom-> enableReceiveCompleteInterruptUART ( );
138
139
}
139
140
}
140
141
@@ -143,16 +144,6 @@ int Uart::read()
143
144
144
145
size_t Uart::write (const uint8_t data)
145
146
{
146
- if (uc_pinRTS != NO_RTS_PIN) {
147
- // assert RTS
148
- digitalWrite (uc_pinRTS, LOW);
149
- }
150
-
151
- if (uc_pinCTS != NO_CTS_PIN) {
152
- // wait until CTS is asserted
153
- while (digitalRead (uc_pinCTS) != LOW);
154
- }
155
-
156
147
if (sercom->isDataRegisterEmptyUART () && txBuffer.available () == 0 ) {
157
148
sercom->writeDataUART (data);
158
149
} else {
@@ -217,14 +208,22 @@ SercomParityMode Uart::extractParity(uint16_t config)
217
208
218
209
int Uart::attachRts (uint8_t pin)
219
210
{
220
- uc_pinRTS = pin;
211
+ if (uc_padTX == UART_TX_RTS_CTS_PAD_0_2_3) {
212
+ uc_pinRTS = pin;
221
213
222
- return 1 ;
214
+ return 1 ;
215
+ }
216
+
217
+ return 0 ;
223
218
}
224
219
225
220
int Uart::attachCts (uint8_t pin)
226
221
{
227
- uc_pinCTS = pin;
222
+ if (uc_padTX == UART_TX_RTS_CTS_PAD_0_2_3) {
223
+ uc_pinCTS = pin;
228
224
229
- return 1 ;
225
+ return 1 ;
226
+ }
227
+
228
+ return 0 ;
230
229
}
0 commit comments