mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
periph/uart: add support for enhanced serial settings
As suggested in PR#5899 add a routine uart_mode() that will setup data bits, stop bits and parity at runtime. uart.h provides a set of enums defining these settings and each platform will override them to specify values corresponding to its configuration registers. The idea behind the enums is to specify default settings i.e. 8N1 through the 0 value item. Invoking uart_mode(uart, 0, 0, 0) will setup 8N1 mode. Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
This commit is contained in:
parent
782b181b63
commit
ddf19783d7
@ -111,6 +111,41 @@ enum {
|
||||
UART_NOMODE = -4 /**< given mode is not applicable */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Definition of possible parity modes
|
||||
*/
|
||||
#ifndef HAVE_UART_PARITY_T
|
||||
typedef enum {
|
||||
UART_PARITY_NONE, /**< no parity */
|
||||
UART_PARITY_EVEN, /**< even parity */
|
||||
UART_PARITY_ODD, /**< odd parity */
|
||||
UART_PARITY_MARK, /**< mark parity */
|
||||
UART_PARITY_SPACE /**< space parity */
|
||||
} uart_parity_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Definition of possible data bits lengths in a UART frame
|
||||
*/
|
||||
#ifndef HAVE_UART_DATA_BITS_T
|
||||
typedef enum {
|
||||
UART_DATA_BITS_5, /**< 5 data bits */
|
||||
UART_DATA_BITS_6, /**< 6 data bits */
|
||||
UART_DATA_BITS_7, /**< 7 data bits */
|
||||
UART_DATA_BITS_8, /**< 8 data bits */
|
||||
} uart_data_bits_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Definition of possible stop bits lengths in a UART frame
|
||||
*/
|
||||
#ifndef HAVE_UART_STOP_BITS_T
|
||||
typedef enum {
|
||||
UART_STOP_BITS_1, /**< 1 stop bit */
|
||||
UART_STOP_BITS_2, /**< 2 stop bits */
|
||||
} uart_stop_bits_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Initialize a given UART device
|
||||
*
|
||||
@ -137,6 +172,20 @@ enum {
|
||||
*/
|
||||
int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg);
|
||||
|
||||
/**
|
||||
* @brief Setup parity, data and stop bits for a given UART device
|
||||
*
|
||||
* @param[in] uart UART device to initialize
|
||||
* @param[in] data_bits number of data bits in a UART frame
|
||||
* @param[in] parity parity mode
|
||||
* @param[in] stop_bits number of stop bits in a UART frame
|
||||
*
|
||||
* @return UART_OK on success
|
||||
* @return UART_NOMODE on other errors
|
||||
*/
|
||||
int uart_mode(uart_t uart, uart_data_bits_t data_bits, uart_parity_t parity,
|
||||
uart_stop_bits_t stop_bits);
|
||||
|
||||
/**
|
||||
* @brief Write data from the given buffer to the specified UART device
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user