nrf5x: Add UART modecfg feature implementation

This commit is contained in:
Koen Zandberg 2019-06-17 21:19:16 +02:00
parent ea36d68703
commit 81df812c5b
No known key found for this signature in database
GPG Key ID: 0895A893E6D2985B
2 changed files with 61 additions and 0 deletions

View File

@ -4,6 +4,7 @@ FEATURES_PROVIDED += periph_flashpage
FEATURES_PROVIDED += periph_gpio periph_gpio_irq
FEATURES_PROVIDED += periph_hwrng
FEATURES_PROVIDED += periph_temperature
FEATURES_PROVIDED += periph_uart_modecfg
# Various other features (if any)
FEATURES_PROVIDED += radio_nrfmin

View File

@ -275,6 +275,39 @@ void uart_poweroff(uart_t uart)
dev(uart)->TASKS_STOPRX = 1;
}
int uart_mode(uart_t uart, uart_data_bits_t data_bits, uart_parity_t parity,
uart_stop_bits_t stop_bits)
{
if (stop_bits != UART_STOP_BITS_1 && stop_bits != UART_STOP_BITS_2) {
return UART_NOMODE;
}
if (data_bits != UART_DATA_BITS_8) {
return UART_NOMODE;
}
if (parity != UART_PARITY_NONE && parity != UART_PARITY_EVEN) {
return UART_NOMODE;
}
if (stop_bits == UART_STOP_BITS_2) {
dev(uart)->CONFIG |= UARTE_CONFIG_STOP_Msk;
}
else {
dev(uart)->CONFIG &= ~UARTE_CONFIG_STOP_Msk;
}
if (parity == UART_PARITY_EVEN) {
dev(uart)->CONFIG |= UARTE_CONFIG_PARITY_Msk;
}
else {
dev(uart)->CONFIG &= ~UARTE_CONFIG_PARITY_Msk;
}
return UART_OK;
}
static inline void irq_handler(uart_t uart)
{
if (dev(uart)->EVENTS_ENDRX == 1) {
@ -333,6 +366,33 @@ void uart_poweroff(uart_t uart)
NRF_UART0->TASKS_SUSPEND;
}
int uart_mode(uart_t uart, uart_data_bits_t data_bits, uart_parity_t parity,
uart_stop_bits_t stop_bits)
{
(void)uart;
if (stop_bits != UART_STOP_BITS_1) {
return UART_NOMODE;
}
if (data_bits != UART_DATA_BITS_8) {
return UART_NOMODE;
}
if (parity != UART_PARITY_NONE && parity != UART_PARITY_EVEN) {
return UART_NOMODE;
}
if (parity == UART_PARITY_EVEN) {
NRF_UART0->CONFIG |= UART_CONFIG_PARITY_Msk;
}
else {
NRF_UART0->CONFIG &= ~UART_CONFIG_PARITY_Msk;
}
return UART_OK;
}
static inline void irq_handler(uart_t uart)
{
(void)uart;