Merge pull request #11294 from gschorcht/cpu/esp32/periph/conf/uart
boards/esp32: changes the approach for configurations of UART interfaces in board definitions
This commit is contained in:
commit
795ad18f2e
@ -149,6 +149,35 @@ static const gpio_t dac_channels[] = DAC_GPIOS;
|
|||||||
* @name UART configuration
|
* @name UART configuration
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef UART0_TXD
|
||||||
|
#define UART0_TXD (GPIO1) /**< TxD of UART_DEV(0) used on all ESP32 boards */
|
||||||
|
#endif
|
||||||
|
#ifndef UART0_RXD
|
||||||
|
#define UART0_RXD (GPIO3) /**< RxD of UART_DEV(0) used on all ESP32 boards */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Static array with configuration for declared I2C devices
|
||||||
|
*/
|
||||||
|
static const uart_conf_t uart_config[] = {
|
||||||
|
{
|
||||||
|
.txd = UART0_TXD,
|
||||||
|
.rxd = UART0_RXD,
|
||||||
|
},
|
||||||
|
#if defined(UART1_TXD) && defined(UART1_RXD)
|
||||||
|
{
|
||||||
|
.txd = UART1_TXD,
|
||||||
|
.rxd = UART1_RXD,
|
||||||
|
},
|
||||||
|
#endif
|
||||||
|
#if defined(UART2_TXD) && defined(UART2_RXD)
|
||||||
|
{
|
||||||
|
.txd = UART2_TXD,
|
||||||
|
.rxd = UART2_RXD,
|
||||||
|
},
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Number of UART interfaces
|
* @brief Number of UART interfaces
|
||||||
*
|
*
|
||||||
|
|||||||
@ -420,25 +420,33 @@ extern const unsigned spi_bus_num;
|
|||||||
* configuration and is always available. All ESP32 boards use it as standard
|
* configuration and is always available. All ESP32 boards use it as standard
|
||||||
* configuration for the console.
|
* configuration for the console.
|
||||||
*
|
*
|
||||||
* UART_DEV(0).TXD GPIO1
|
* UART_DEV(0).TXD GPIO1
|
||||||
* UART_DEV(0).RXD GPIO3
|
* UART_DEV(0).RXD GPIO3
|
||||||
*
|
*
|
||||||
* The pin configuration of UART_DEV(1) and UART_DEV(2) are defined in
|
* The pin configuration of UART_DEV(1) and UART_DEV(2) are defined in
|
||||||
* board specific peripheral configuration by
|
* board specific peripheral configuration by
|
||||||
*
|
*
|
||||||
* UARTn_TXD, the GPIO used as TxD signal, and
|
* - UARTn_TXD, the GPIO used as TxD signal, and
|
||||||
* UARTn_RXD, the GPIO used as RxD signal,
|
* - UARTn_RXD, the GPIO used as RxD signal,
|
||||||
*
|
*
|
||||||
* where n can be 2 or 3. If they are not defined, the UART interface
|
* where n can be 1 or 2. If they are not defined, the according UART interface
|
||||||
* UART_DEV(n) is not used.
|
* UART_DEV(n) is not used.
|
||||||
*
|
*
|
||||||
* UART_NUMOF is determined automatically from the board-specific peripheral
|
* UART_NUMOF is determined automatically from the board-specific peripheral
|
||||||
* definitions of UARTn_TXD and UARTn_RXD.
|
* definitions of UARTn_*.
|
||||||
*
|
*
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
/** @} */
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief UART configuration structure type
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
gpio_t txd; /**< GPIO used as TxD pin */
|
||||||
|
gpio_t rxd; /**< GPIO used as RxD pin */
|
||||||
|
} uart_conf_t;
|
||||||
|
|
||||||
|
/** @} */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,8 +50,7 @@
|
|||||||
|
|
||||||
struct uart_hw_t {
|
struct uart_hw_t {
|
||||||
uart_dev_t* regs; /* pointer to register data struct of the UART device */
|
uart_dev_t* regs; /* pointer to register data struct of the UART device */
|
||||||
uint8_t pin_txd; /* TxD pin */
|
uint8_t mod; /* peripheral hardware module of the UART interface */
|
||||||
uint8_t pin_rxd; /* RxD pin */
|
|
||||||
bool used; /* indicates whether UART is used */
|
bool used; /* indicates whether UART is used */
|
||||||
uint32_t baudrate; /* used baudrate */
|
uint32_t baudrate; /* used baudrate */
|
||||||
uart_data_bits_t data; /* used data bits */
|
uart_data_bits_t data; /* used data bits */
|
||||||
@ -67,8 +66,7 @@ struct uart_hw_t {
|
|||||||
static struct uart_hw_t _uarts[] = {
|
static struct uart_hw_t _uarts[] = {
|
||||||
{
|
{
|
||||||
.regs = &UART0,
|
.regs = &UART0,
|
||||||
.pin_txd = GPIO1,
|
.mod = PERIPH_UART0_MODULE,
|
||||||
.pin_rxd = GPIO3,
|
|
||||||
.used = false,
|
.used = false,
|
||||||
.baudrate = STDIO_UART_BAUDRATE,
|
.baudrate = STDIO_UART_BAUDRATE,
|
||||||
.data = UART_DATA_BITS_8,
|
.data = UART_DATA_BITS_8,
|
||||||
@ -78,10 +76,9 @@ static struct uart_hw_t _uarts[] = {
|
|||||||
.signal_rxd = U0RXD_IN_IDX,
|
.signal_rxd = U0RXD_IN_IDX,
|
||||||
.int_src = ETS_UART0_INTR_SOURCE
|
.int_src = ETS_UART0_INTR_SOURCE
|
||||||
},
|
},
|
||||||
#if defined(UART1_TXD) && defined(UART1_RXD)
|
{
|
||||||
{ .regs = &UART1,
|
.regs = &UART1,
|
||||||
.pin_txd = UART1_TXD,
|
.mod = PERIPH_UART1_MODULE,
|
||||||
.pin_rxd = UART1_RXD,
|
|
||||||
.used = false,
|
.used = false,
|
||||||
.baudrate = STDIO_UART_BAUDRATE,
|
.baudrate = STDIO_UART_BAUDRATE,
|
||||||
.data = UART_DATA_BITS_8,
|
.data = UART_DATA_BITS_8,
|
||||||
@ -91,11 +88,9 @@ static struct uart_hw_t _uarts[] = {
|
|||||||
.signal_rxd = U1RXD_IN_IDX,
|
.signal_rxd = U1RXD_IN_IDX,
|
||||||
.int_src = ETS_UART1_INTR_SOURCE
|
.int_src = ETS_UART1_INTR_SOURCE
|
||||||
},
|
},
|
||||||
#endif
|
{
|
||||||
#if defined(UART2_TXD) && defined(UART2_RXD)
|
.regs = &UART2,
|
||||||
{ .regs = &UART2,
|
.mod = PERIPH_UART2_MODULE,
|
||||||
.pin_txd = UART2_TXD,
|
|
||||||
.pin_rxd = UART2_RXD,
|
|
||||||
.used = false,
|
.used = false,
|
||||||
.baudrate = STDIO_UART_BAUDRATE,
|
.baudrate = STDIO_UART_BAUDRATE,
|
||||||
.data = UART_DATA_BITS_8,
|
.data = UART_DATA_BITS_8,
|
||||||
@ -105,7 +100,6 @@ static struct uart_hw_t _uarts[] = {
|
|||||||
.signal_rxd = U2RXD_IN_IDX,
|
.signal_rxd = U2RXD_IN_IDX,
|
||||||
.int_src = ETS_UART2_INTR_SOURCE
|
.int_src = ETS_UART2_INTR_SOURCE
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* declaration of external functions */
|
/* declaration of external functions */
|
||||||
@ -131,30 +125,29 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
|
|||||||
if (uart == UART_DEV(1) || uart == UART_DEV(2)) {
|
if (uart == UART_DEV(1) || uart == UART_DEV(2)) {
|
||||||
|
|
||||||
/* reset the pins when they were already used as UART pins */
|
/* reset the pins when they were already used as UART pins */
|
||||||
if (gpio_get_pin_usage(_uarts[uart].pin_txd) == _UART) {
|
if (gpio_get_pin_usage(uart_config[uart].txd) == _UART) {
|
||||||
gpio_set_pin_usage(_uarts[uart].pin_txd, _GPIO);
|
gpio_set_pin_usage(uart_config[uart].txd, _GPIO);
|
||||||
}
|
}
|
||||||
if (gpio_get_pin_usage(_uarts[uart].pin_rxd) == _UART) {
|
if (gpio_get_pin_usage(uart_config[uart].rxd) == _UART) {
|
||||||
gpio_set_pin_usage(_uarts[uart].pin_rxd, _GPIO);
|
gpio_set_pin_usage(uart_config[uart].rxd, _GPIO);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* try to initialize the pins as GPIOs first */
|
/* try to initialize the pins as GPIOs first */
|
||||||
if (gpio_init (_uarts[uart].pin_rxd, GPIO_IN) ||
|
if (gpio_init (uart_config[uart].rxd, GPIO_IN) ||
|
||||||
gpio_init (_uarts[uart].pin_txd, GPIO_OUT)) {
|
gpio_init (uart_config[uart].txd, GPIO_OUT)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* store the usage type in GPIO table */
|
/* store the usage type in GPIO table */
|
||||||
gpio_set_pin_usage(_uarts[uart].pin_txd, _UART);
|
gpio_set_pin_usage(uart_config[uart].txd, _UART);
|
||||||
gpio_set_pin_usage(_uarts[uart].pin_rxd, _UART);
|
gpio_set_pin_usage(uart_config[uart].rxd, _UART);
|
||||||
|
|
||||||
/* connect TxD pin to the TxD output signal through the GPIO matrix */
|
/* connect TxD pin to the TxD output signal through the GPIO matrix */
|
||||||
GPIO.func_out_sel_cfg[_uarts[uart].pin_txd].func_sel = _uarts[uart].signal_txd;
|
GPIO.func_out_sel_cfg[uart_config[uart].txd].func_sel = _uarts[uart].signal_txd;
|
||||||
|
|
||||||
/* connect RxD input signal to the RxD pin through the GPIO matrix */
|
/* connect RxD input signal to the RxD pin through the GPIO matrix */
|
||||||
GPIO.func_in_sel_cfg[_uarts[uart].signal_rxd].sig_in_sel = 1;
|
GPIO.func_in_sel_cfg[_uarts[uart].signal_rxd].sig_in_sel = 1;
|
||||||
GPIO.func_in_sel_cfg[_uarts[uart].signal_rxd].sig_in_inv = 0;
|
GPIO.func_in_sel_cfg[_uarts[uart].signal_rxd].sig_in_inv = 0;
|
||||||
GPIO.func_in_sel_cfg[_uarts[uart].signal_rxd].func_sel = _uarts[uart].pin_rxd;
|
GPIO.func_in_sel_cfg[_uarts[uart].signal_rxd].func_sel = uart_config[uart].rxd;
|
||||||
}
|
}
|
||||||
_uarts[uart].baudrate = baudrate;
|
_uarts[uart].baudrate = baudrate;
|
||||||
|
|
||||||
@ -187,40 +180,17 @@ void uart_write(uart_t uart, const uint8_t *data, size_t len)
|
|||||||
|
|
||||||
void uart_poweron (uart_t uart)
|
void uart_poweron (uart_t uart)
|
||||||
{
|
{
|
||||||
switch (uart) {
|
CHECK_PARAM (uart < UART_NUMOF);
|
||||||
#if UART_NUMOF
|
|
||||||
case 0: periph_module_enable(PERIPH_UART0_MODULE);
|
periph_module_enable(_uarts[uart].mod);
|
||||||
_uart_config(uart);
|
_uart_config(uart);
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
#if UART_NUMOF > 1
|
|
||||||
case 1: periph_module_enable(PERIPH_UART1_MODULE);
|
|
||||||
_uart_config(uart);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
#if UART_NUMOF > 2
|
|
||||||
case 2: periph_module_enable(PERIPH_UART2_MODULE);
|
|
||||||
_uart_config(uart);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void uart_poweroff (uart_t uart)
|
void uart_poweroff (uart_t uart)
|
||||||
{
|
{
|
||||||
switch (uart) {
|
CHECK_PARAM (uart < UART_NUMOF);
|
||||||
#if UART_NUMOF
|
|
||||||
case 0: periph_module_disable(PERIPH_UART0_MODULE); break;
|
periph_module_disable(_uarts[uart].mod);
|
||||||
#endif
|
|
||||||
#if UART_NUMOF > 1
|
|
||||||
case 1: periph_module_disable(PERIPH_UART1_MODULE); break;
|
|
||||||
#endif
|
|
||||||
#if UART_NUMOF > 2
|
|
||||||
case 2: periph_module_disable(PERIPH_UART2_MODULE); break;
|
|
||||||
#endif
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* systemwide UART initializations */
|
/* systemwide UART initializations */
|
||||||
@ -236,7 +206,7 @@ void uart_print_config(void)
|
|||||||
{
|
{
|
||||||
for (unsigned uart = 0; uart < UART_NUMOF; uart++) {
|
for (unsigned uart = 0; uart < UART_NUMOF; uart++) {
|
||||||
ets_printf("\tUART_DEV(%d)\ttxd=%d rxd=%d\n", uart,
|
ets_printf("\tUART_DEV(%d)\ttxd=%d rxd=%d\n", uart,
|
||||||
_uarts[uart].pin_txd, _uarts[uart].pin_rxd);
|
uart_config[uart].txd, uart_config[uart].rxd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user