@@ -46,12 +46,11 @@ void Uart::begin(unsigned long baudrate, uint16_t config)
4646 pinPeripheral (uc_pinTX, g_APinDescription[uc_pinTX].ulPinType );
4747
4848 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 );
5150 }
5251
5352 if (uc_pinCTS != NO_CTS_PIN) {
54- pinMode (uc_pinCTS, INPUT );
53+ pinPeripheral (uc_pinCTS, g_APinDescription[uc_pinCTS]. ulPinType );
5554 }
5655
5756 sercom->initUART (UART_INT_CLOCK, SAMPLE_RATE_x16, baudrate);
@@ -86,9 +85,10 @@ void Uart::IrqHandler()
8685 rxBuffer.store_char (sercom->readDataUART ());
8786
8887 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
9090 if (rxBuffer.availableForStore () < RTS_RX_THRESHOLD) {
91- digitalWrite (uc_pinRTS, HIGH );
91+ sercom-> disableReceiveCompleteInterruptUART ( );
9292 }
9393 }
9494 }
@@ -132,9 +132,10 @@ int Uart::read()
132132 int c = rxBuffer.read_char ();
133133
134134 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
136137 if (rxBuffer.availableForStore () > RTS_RX_THRESHOLD) {
137- digitalWrite (uc_pinRTS, LOW );
138+ sercom-> enableReceiveCompleteInterruptUART ( );
138139 }
139140 }
140141
@@ -143,16 +144,6 @@ int Uart::read()
143144
144145size_t Uart::write (const uint8_t data)
145146{
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-
156147 if (sercom->isDataRegisterEmptyUART () && txBuffer.available () == 0 ) {
157148 sercom->writeDataUART (data);
158149 } else {
@@ -217,14 +208,22 @@ SercomParityMode Uart::extractParity(uint16_t config)
217208
218209int Uart::attachRts (uint8_t pin)
219210{
220- uc_pinRTS = pin;
211+ if (uc_padTX == UART_TX_RTS_CTS_PAD_0_2_3) {
212+ uc_pinRTS = pin;
221213
222- return 1 ;
214+ return 1 ;
215+ }
216+
217+ return 0 ;
223218}
224219
225220int Uart::attachCts (uint8_t pin)
226221{
227- uc_pinCTS = pin;
222+ if (uc_padTX == UART_TX_RTS_CTS_PAD_0_2_3) {
223+ uc_pinCTS = pin;
228224
229- return 1 ;
225+ return 1 ;
226+ }
227+
228+ return 0 ;
230229}
0 commit comments