Skip to content

Commit 58ac771

Browse files
committed
Uart: support even parity
Signed-off-by: prjh <[email protected]>
1 parent dc8b43f commit 58ac771

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

cores/nRF5/Uart.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void Uart::begin(unsigned long baudrate)
6464
begin(baudrate, (uint8_t)SERIAL_8N1);
6565
}
6666

67-
void Uart::begin(unsigned long baudrate, uint16_t /*config*/)
67+
void Uart::begin(unsigned long baudrate, uint16_t config)
6868
{
6969
// skip if already begun
7070
if ( _begun ) return;
@@ -75,9 +75,17 @@ void Uart::begin(unsigned long baudrate, uint16_t /*config*/)
7575
if (uc_hwFlow == 1) {
7676
nrfUart->PSELCTS = uc_pinCTS;
7777
nrfUart->PSELRTS = uc_pinRTS;
78-
nrfUart->CONFIG = (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos) | UART_CONFIG_HWFC_Enabled;
78+
if (config==SERIAL_8E1) {
79+
nrfUart->CONFIG = (UART_CONFIG_PARITY_Included << UART_CONFIG_PARITY_Pos) | UART_CONFIG_HWFC_Enabled;
80+
} else {
81+
nrfUart->CONFIG = (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos) | UART_CONFIG_HWFC_Enabled;
82+
}
7983
} else {
80-
nrfUart->CONFIG = (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos) | UART_CONFIG_HWFC_Disabled;
84+
if (config==SERIAL_8E1) {
85+
nrfUart->CONFIG = (UART_CONFIG_PARITY_Included << UART_CONFIG_PARITY_Pos) | UART_CONFIG_HWFC_Disabled;
86+
} else {
87+
nrfUart->CONFIG = (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos) | UART_CONFIG_HWFC_Disabled;
88+
}
8189
}
8290

8391
uint32_t nrfBaudRate;

0 commit comments

Comments
 (0)