drivers: serial: numicro: drop usage of uart_device_config
Create a driver specific configuration structure, containing the required fields only. Since the config struct can now store a pointer to the UART structure, casts from address to (UART_T *) are no longer needed. UART_STRUCT has also been dropped in favor of using the config pointer directly now that it is possible. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
863a661f70
commit
dd3e3a7ee2
1 changed files with 13 additions and 15 deletions
|
@ -11,12 +11,8 @@
|
|||
|
||||
#define DT_DRV_COMPAT nuvoton_numicro_uart
|
||||
|
||||
#define UART_STRUCT(dev) \
|
||||
((UART_T *) \
|
||||
((const struct uart_numicro_config * const)(dev)->config)->devcfg.base)
|
||||
|
||||
struct uart_numicro_config {
|
||||
struct uart_device_config devcfg;
|
||||
UART_T *uart;
|
||||
uint32_t id_rst;
|
||||
uint32_t id_clk;
|
||||
};
|
||||
|
@ -28,9 +24,10 @@ struct uart_numicro_data {
|
|||
|
||||
static int uart_numicro_poll_in(const struct device *dev, unsigned char *c)
|
||||
{
|
||||
const struct uart_numicro_config *config = dev->config;
|
||||
uint32_t count;
|
||||
|
||||
count = UART_Read(UART_STRUCT(dev), c, 1);
|
||||
count = UART_Read(config->uart, c, 1);
|
||||
if (!count) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -40,7 +37,9 @@ static int uart_numicro_poll_in(const struct device *dev, unsigned char *c)
|
|||
|
||||
static void uart_numicro_poll_out(const struct device *dev, unsigned char c)
|
||||
{
|
||||
UART_Write(UART_STRUCT(dev), &c, 1);
|
||||
const struct uart_numicro_config *config = dev->config;
|
||||
|
||||
UART_Write(config->uart, &c, 1);
|
||||
}
|
||||
|
||||
static int uart_numicro_err_check(const struct device *dev)
|
||||
|
@ -99,6 +98,7 @@ static inline uint32_t uart_numicro_convert_parity(enum uart_config_parity parit
|
|||
static int uart_numicro_configure(const struct device *dev,
|
||||
const struct uart_config *cfg)
|
||||
{
|
||||
const struct uart_numicro_config *config = dev->config;
|
||||
struct uart_numicro_data *ddata = dev->data;
|
||||
int32_t databits, stopbits;
|
||||
uint32_t parity;
|
||||
|
@ -114,17 +114,17 @@ static int uart_numicro_configure(const struct device *dev,
|
|||
}
|
||||
|
||||
if (cfg->flow_ctrl == UART_CFG_FLOW_CTRL_NONE) {
|
||||
UART_DisableFlowCtrl(UART_STRUCT(dev));
|
||||
UART_DisableFlowCtrl(config->uart);
|
||||
} else if (cfg->flow_ctrl == UART_CFG_FLOW_CTRL_RTS_CTS) {
|
||||
UART_EnableFlowCtrl(UART_STRUCT(dev));
|
||||
UART_EnableFlowCtrl(config->uart);
|
||||
} else {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
parity = uart_numicro_convert_parity(cfg->parity);
|
||||
|
||||
UART_SetLineConfig(UART_STRUCT(dev), cfg->baudrate, databits,
|
||||
parity, stopbits);
|
||||
UART_SetLineConfig(config->uart, cfg->baudrate, databits, parity,
|
||||
stopbits);
|
||||
|
||||
memcpy(&ddata->ucfg, cfg, sizeof(*cfg));
|
||||
|
||||
|
@ -165,7 +165,7 @@ static int uart_numicro_init(const struct device *dev)
|
|||
|
||||
SYS_LockReg();
|
||||
|
||||
UART_Open(UART_STRUCT(dev), ddata->ucfg.baudrate);
|
||||
UART_Open(config->uart, ddata->ucfg.baudrate);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -183,9 +183,7 @@ static const struct uart_driver_api uart_numicro_driver_api = {
|
|||
#define NUMICRO_INIT(index) \
|
||||
\
|
||||
static const struct uart_numicro_config uart_numicro_cfg_##index = { \
|
||||
.devcfg = { \
|
||||
.base = (uint8_t *)DT_INST_REG_ADDR(index), \
|
||||
}, \
|
||||
.uart = (UART_T *)DT_INST_REG_ADDR(index), \
|
||||
.id_rst = UART##index##_RST, \
|
||||
.id_clk = UART##index##_MODULE, \
|
||||
}; \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue