From 58ac771372ef3bfd1949adb36d8d88af41d14da7 Mon Sep 17 00:00:00 2001 From: prjh Date: Fri, 1 Nov 2019 22:30:33 +0100 Subject: [PATCH] Uart: support even parity Signed-off-by: prjh --- cores/nRF5/Uart.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cores/nRF5/Uart.cpp b/cores/nRF5/Uart.cpp index 6eb5efd1..272a63ac 100644 --- a/cores/nRF5/Uart.cpp +++ b/cores/nRF5/Uart.cpp @@ -64,7 +64,7 @@ void Uart::begin(unsigned long baudrate) begin(baudrate, (uint8_t)SERIAL_8N1); } -void Uart::begin(unsigned long baudrate, uint16_t /*config*/) +void Uart::begin(unsigned long baudrate, uint16_t config) { // skip if already begun if ( _begun ) return; @@ -75,9 +75,17 @@ void Uart::begin(unsigned long baudrate, uint16_t /*config*/) if (uc_hwFlow == 1) { nrfUart->PSELCTS = uc_pinCTS; nrfUart->PSELRTS = uc_pinRTS; - nrfUart->CONFIG = (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos) | UART_CONFIG_HWFC_Enabled; + if (config==SERIAL_8E1) { + nrfUart->CONFIG = (UART_CONFIG_PARITY_Included << UART_CONFIG_PARITY_Pos) | UART_CONFIG_HWFC_Enabled; + } else { + nrfUart->CONFIG = (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos) | UART_CONFIG_HWFC_Enabled; + } } else { - nrfUart->CONFIG = (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos) | UART_CONFIG_HWFC_Disabled; + if (config==SERIAL_8E1) { + nrfUart->CONFIG = (UART_CONFIG_PARITY_Included << UART_CONFIG_PARITY_Pos) | UART_CONFIG_HWFC_Disabled; + } else { + nrfUart->CONFIG = (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos) | UART_CONFIG_HWFC_Disabled; + } } uint32_t nrfBaudRate;