Skip to content

Commit

Permalink
squash lpuart make mode selection not dependent on UART module
Browse files Browse the repository at this point in the history
squash lpuart support transmission modes
  • Loading branch information
Joakim Nohlgård committed Aug 22, 2017
1 parent ad9dcf8 commit aaceb4f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
32 changes: 22 additions & 10 deletions cpu/kinetis_common/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,28 @@ typedef enum {
#endif /* ndef DOXYGEN */

/**
* @name CPU specific UART modes values
* @{
* @brief UART transmission modes
*/
/** @brief 8 data bits, no parity, 1 stop bit */
#define UART_MODE_8N1 (0)
/** @brief 8 data bits, even parity, 1 stop bit */
#define UART_MODE_8E1 (UART_C1_PE_MASK | UART_C1_M_MASK)
/** @brief 8 data bits, odd parity, 1 stop bit */
#define UART_MODE_8O1 (UART_C1_PE_MASK | UART_C1_M_MASK | UART_C1_PT_MASK)
/** @} */
typedef enum {
/** @brief 8 data bits, no parity, 1 stop bit */
UART_MODE_8N1 = 0,
/** @brief 8 data bits, even parity, 1 stop bit */
#if defined(UART_C1_M_MASK)
/* LPUART and UART mode bits coincide, so the same setting for UART works on
* the LPUART as well */
UART_MODE_8E1 = (UART_C1_M_MASK | UART_C1_PE_MASK),
#elif defined(LPUART_CTRL_M_MASK)
/* For CPUs which only have the LPUART */
UART_MODE_8E1 = (LPUART_CTRL_M_MASK | LPUART_CTRL_PE_MASK),
#endif
/** @brief 8 data bits, odd parity, 1 stop bit */
#if defined(UART_C1_M_MASK)
UART_MODE_8O1 = (UART_C1_M_MASK | UART_C1_PE_MASK | UART_C1_PT_MASK),
#elif defined(LPUART_CTRL_M_MASK)
/* For CPUs which only have the LPUART */
UART_MODE_8O1 = (LPUART_CTRL_M_MASK | LPUART_CTRL_PE_MASK | LPUART_CTRL_PT_MASK),
#endif
} uart_mode_t;

#ifndef DOXYGEN
/**
Expand Down Expand Up @@ -336,7 +348,7 @@ typedef struct {
IRQn_Type irqn; /**< IRQ number for this module */
volatile uint32_t *scgc_addr; /**< Clock enable register, in SIM module */
uint8_t scgc_bit; /**< Clock enable bit, within the register */
uint8_t mode; /**< UART mode: data bits, parity, stop bits */
uart_mode_t mode; /**< UART mode: data bits, parity, stop bits */
uart_type_t type; /**< Hardware module type (KINETIS_UART or KINETIS_LPUART)*/
} uart_conf_t;

Expand Down
9 changes: 5 additions & 4 deletions cpu/kinetis_common/periph/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ static inline void uart_init_uart(uart_t uart, uint32_t baudrate)
/* disable transmitter and receiver */
dev->C2 &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK);

/* set defaults, 8-bit mode, no parity */
/* Select mode */
dev->C1 = uart_config[uart].mode;

/* calculate baudrate */
Expand Down Expand Up @@ -295,9 +295,9 @@ static inline void uart_init_lpuart(uart_t uart, uint32_t baudrate)

/* Remember to select a module clock in board_init! (SIM->SOPT2[LPUART0SRC]) */

/* set defaults, 8-bit mode, no parity */
/* Select mode */
/* transmitter and receiver disabled */
dev->CTRL = 0;
dev->CTRL = uart_config[uart].mode;

/* calculate baud rate divisor */
uint32_t div = clk / (baudrate * LPUART_OVERSAMPLING_RATE);
Expand All @@ -306,7 +306,8 @@ static inline void uart_init_lpuart(uart_t uart, uint32_t baudrate)
dev->BAUD = LPUART_BAUD_OSR(LPUART_OVERSAMPLING_RATE - 1) | LPUART_BAUD_SBR(div);

/* enable transmitter and receiver + RX interrupt */
dev->CTRL = LPUART_CTRL_TE_MASK | LPUART_CTRL_RE_MASK | LPUART_CTRL_RIE_MASK;
dev->CTRL |= LPUART_CTRL_TE_MASK | LPUART_CTRL_RE_MASK | LPUART_CTRL_RIE_MASK;

/* enable receive interrupt */
NVIC_EnableIRQ(uart_config[uart].irqn);
}
Expand Down

0 comments on commit aaceb4f

Please sign in to comment.