cpu/cc2538: Add periph_uart_mode implementation
This commit adds the periph_uart_mode USEMODULE It implements all functionality defined in the common uart driver This means all parity modes, data bits, and stop bits
This commit is contained in:
parent
5d63e28e59
commit
0aa6b04249
@ -1,5 +1,6 @@
|
|||||||
FEATURES_PROVIDED += periph_cpuid
|
FEATURES_PROVIDED += periph_cpuid
|
||||||
FEATURES_PROVIDED += periph_hwrng
|
FEATURES_PROVIDED += periph_hwrng
|
||||||
|
FEATURES_PROVIDED += periph_uart_modecfg
|
||||||
FEATURES_PROVIDED += puf_sram
|
FEATURES_PROVIDED += puf_sram
|
||||||
|
|
||||||
-include $(RIOTCPU)/cortexm_common/Makefile.features
|
-include $(RIOTCPU)/cortexm_common/Makefile.features
|
||||||
|
|||||||
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "vendor/hw_ssi.h"
|
#include "vendor/hw_ssi.h"
|
||||||
|
#include "vendor/hw_uart.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -167,6 +168,46 @@ typedef struct {
|
|||||||
} uart_conf_t;
|
} uart_conf_t;
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
#ifndef DOXYGEN
|
||||||
|
/**
|
||||||
|
* @brief Override parity values
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define HAVE_UART_PARITY_T
|
||||||
|
typedef enum {
|
||||||
|
UART_PARITY_NONE = 0, /**< no parity */
|
||||||
|
UART_PARITY_EVEN = (UART_LCRH_PEN | UART_LCRH_EPS), /**< even parity */
|
||||||
|
UART_PARITY_ODD = UART_LCRH_PEN, /**< odd parity */
|
||||||
|
UART_PARITY_MARK = (UART_LCRH_PEN | UART_LCRH_SPS), /**< mark */
|
||||||
|
UART_PARITY_SPACE = (UART_LCRH_PEN | UART_LCRH_EPS | UART_LCRH_SPS) /**< space */
|
||||||
|
} uart_parity_t;
|
||||||
|
/** @} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Override data bits length values
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define HAVE_UART_DATA_BITS_T
|
||||||
|
typedef enum {
|
||||||
|
UART_DATA_BITS_5 = (0 << UART_LCRH_WLEN_S), /**< 5 data bits */
|
||||||
|
UART_DATA_BITS_6 = (1 << UART_LCRH_WLEN_S), /**< 6 data bits */
|
||||||
|
UART_DATA_BITS_7 = (2 << UART_LCRH_WLEN_S), /**< 7 data bits */
|
||||||
|
UART_DATA_BITS_8 = (3 << UART_LCRH_WLEN_S), /**< 8 data bits */
|
||||||
|
} uart_data_bits_t;
|
||||||
|
/** @} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Override stop bits length values
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define HAVE_UART_STOP_BITS_T
|
||||||
|
typedef enum {
|
||||||
|
UART_STOP_BITS_1 = 0, /**< 1 stop bit */
|
||||||
|
UART_STOP_BITS_2 = UART_LCRH_STP2, /**< 2 stop bits */
|
||||||
|
} uart_stop_bits_t;
|
||||||
|
/** @} */
|
||||||
|
#endif /* DOXYGEN */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name Override SPI mode settings
|
* @name Override SPI mode settings
|
||||||
* @{
|
* @{
|
||||||
|
|||||||
@ -157,6 +157,35 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
|
|||||||
return UART_OK;
|
return UART_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef MODULE_PERIPH_UART_MODECFG
|
||||||
|
int uart_mode(uart_t uart, uart_data_bits_t data_bits, uart_parity_t parity,
|
||||||
|
uart_stop_bits_t stop_bits)
|
||||||
|
{
|
||||||
|
assert(uart < UART_NUMOF);
|
||||||
|
|
||||||
|
assert(data_bits == UART_DATA_BITS_5 ||
|
||||||
|
data_bits == UART_DATA_BITS_6 ||
|
||||||
|
data_bits == UART_DATA_BITS_7 ||
|
||||||
|
data_bits == UART_DATA_BITS_8);
|
||||||
|
|
||||||
|
assert(parity == UART_PARITY_NONE ||
|
||||||
|
parity == UART_PARITY_EVEN ||
|
||||||
|
parity == UART_PARITY_ODD ||
|
||||||
|
parity == UART_PARITY_MARK ||
|
||||||
|
parity == UART_PARITY_SPACE);
|
||||||
|
|
||||||
|
assert(stop_bits == UART_STOP_BITS_1 ||
|
||||||
|
stop_bits == UART_STOP_BITS_2);
|
||||||
|
|
||||||
|
cc2538_reg_t *lcrh = &(uart_config[uart].dev->cc2538_uart_lcrh.LCRH);
|
||||||
|
uint32_t tmp = *lcrh;
|
||||||
|
tmp &= ~(UART_LCRH_WLEN_M | UART_LCRH_FEN_M | UART_LCRH_STP2_M |
|
||||||
|
UART_LCRH_PEN | UART_LCRH_EPS | UART_LCRH_SPS);
|
||||||
|
*lcrh = tmp | data_bits | parity | stop_bits;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void uart_write(uart_t uart, const uint8_t *data, size_t len)
|
void uart_write(uart_t uart, const uint8_t *data, size_t len)
|
||||||
{
|
{
|
||||||
assert(uart < UART_NUMOF);
|
assert(uart < UART_NUMOF);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user