@@ -27,6 +27,18 @@ Uart::Uart(NRF_UART_Type *_nrfUart, IRQn_Type _IRQn, uint8_t _pinRX, uint8_t _pi
27
27
IRQn = _IRQn;
28
28
uc_pinRX = g_ADigitalPinMap[_pinRX];
29
29
uc_pinTX = g_ADigitalPinMap[_pinTX];
30
+ uc_hwFlow = 0 ;
31
+ }
32
+
33
+ Uart::Uart (NRF_UART_Type *_nrfUart, IRQn_Type _IRQn, uint8_t _pinRX, uint8_t _pinTX, uint8_t _pinCTS, uint8_t _pinRTS)
34
+ {
35
+ nrfUart = _nrfUart;
36
+ IRQn = _IRQn;
37
+ uc_pinRX = g_ADigitalPinMap[_pinRX];
38
+ uc_pinTX = g_ADigitalPinMap[_pinTX];
39
+ uc_pinCTS = g_ADigitalPinMap[_pinCTS];
40
+ uc_pinRTS = g_ADigitalPinMap[_pinRTS];
41
+ uc_hwFlow = 1 ;
30
42
}
31
43
32
44
void Uart::begin (unsigned long baudrate)
@@ -39,7 +51,14 @@ void Uart::begin(unsigned long baudrate, uint16_t /*config*/)
39
51
nrfUart->PSELTXD = uc_pinTX;
40
52
nrfUart->PSELRXD = uc_pinRX;
41
53
42
- nrfUart->CONFIG = (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos) | UART_CONFIG_HWFC_Disabled;
54
+ if (uc_hwFlow == 1 ) {
55
+ nrfUart->PSELCTS = uc_pinCTS;
56
+ nrfUart->PSELRTS = uc_pinRTS;
57
+ nrfUart->CONFIG = (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos) | UART_CONFIG_HWFC_Enabled;
58
+ } else {
59
+ nrfUart->CONFIG = (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos) | UART_CONFIG_HWFC_Disabled;
60
+ }
61
+
43
62
44
63
uint32_t nrfBaudRate;
45
64
@@ -144,6 +163,9 @@ void Uart::end()
144
163
nrfUart->PSELTXD = 0xFFFFFFFF ;
145
164
nrfUart->PSELRXD = 0xFFFFFFFF ;
146
165
166
+ nrfUart->PSELRTS = 0xFFFFFFFF ;
167
+ nrfUart->PSELCTS = 0xFFFFFFFF ;
168
+
147
169
rxBuffer.clear ();
148
170
}
149
171
@@ -188,8 +210,18 @@ size_t Uart::write(const uint8_t data)
188
210
}
189
211
190
212
#if defined(NRF52)
191
- Uart Serial ( NRF_UART0, UARTE0_UART0_IRQn, PIN_SERIAL_RX, PIN_SERIAL_TX );
213
+ #define NRF_UART0_IRQn UARTE0_UART0_IRQn
214
+ #elif defined(NRF51)
215
+ #define NRF_UART0_IRQn UART0_IRQn
216
+ #endif
192
217
218
+ #if defined(PIN_SERIAL_CTS) && defined(PIN_SERIAL_RTS)
219
+ Uart Serial ( NRF_UART0, NRF_UART0_IRQn, PIN_SERIAL_RX, PIN_SERIAL_TX, PIN_SERIAL_CTS, PIN_SERIAL_RTS );
220
+ #else
221
+ Uart Serial ( NRF_UART0, NRF_UART0_IRQn, PIN_SERIAL_RX, PIN_SERIAL_TX );
222
+ #endif
223
+
224
+ #if defined(NRF52)
193
225
extern " C"
194
226
{
195
227
void UARTE0_UART0_IRQHandler ()
@@ -198,8 +230,6 @@ extern "C"
198
230
}
199
231
}
200
232
#elif defined(NRF51)
201
- Uart Serial ( NRF_UART0, UART0_IRQn, PIN_SERIAL_RX, PIN_SERIAL_TX );
202
-
203
233
extern " C"
204
234
{
205
235
void UART0_IRQHandler ()
0 commit comments