drivers: uart: nrfx_uarte: Refactor driver configuration
Merged existing options into single word with flags. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
parent
614e14c629
commit
f93c700d5d
1 changed files with 35 additions and 21 deletions
|
@ -125,20 +125,30 @@ struct uarte_nrfx_data {
|
||||||
gppi_channel_t ppi_ch_endtx;
|
gppi_channel_t ppi_ch_endtx;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CTS_PIN_SET_MASK BIT(1)
|
/* Flag indicating that CTS pin is used. */
|
||||||
#define RTS_PIN_SET_MASK BIT(2)
|
#define UARTE_CFG_FLAG_CTS_PIN_SET BIT(0)
|
||||||
|
|
||||||
|
/* Flag indicating that RTS pin is used. */
|
||||||
|
#define UARTE_CFG_FLAG_RTS_PIN_SET BIT(1)
|
||||||
|
|
||||||
|
/* If enabled, pins are managed when going to low power mode. */
|
||||||
|
#define UARTE_CFG_FLAG_GPIO_MGMT BIT(2)
|
||||||
|
|
||||||
|
/* If enabled then ENDTX is PPI'ed to TXSTOP */
|
||||||
|
#define UARTE_CFG_FLAG_PPI_ENDTX BIT(3)
|
||||||
|
|
||||||
|
#define IS_CTS_PIN_SET(flags) (flags & UARTE_CFG_FLAG_CTS_PIN_SET)
|
||||||
|
#define IS_RTS_PIN_SET(flags) (flags & UARTE_CFG_FLAG_RTS_PIN_SET)
|
||||||
|
#define IS_HWFC_PINS_USED(flags) \
|
||||||
|
IS_CTS_PIN_SET(flags) | IS_RTS_PIN_SET(flags)
|
||||||
|
|
||||||
#define IS_CTS_PIN_SET(mask) (mask & CTS_PIN_SET_MASK)
|
|
||||||
#define IS_RTS_PIN_SET(mask) (mask & RTS_PIN_SET_MASK)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Structure for UARTE configuration.
|
* @brief Structure for UARTE configuration.
|
||||||
*/
|
*/
|
||||||
struct uarte_nrfx_config {
|
struct uarte_nrfx_config {
|
||||||
NRF_UARTE_Type *uarte_regs; /* Instance address */
|
NRF_UARTE_Type *uarte_regs; /* Instance address */
|
||||||
uint8_t rts_cts_pins_set;
|
uint32_t flags;
|
||||||
bool gpio_mgmt;
|
|
||||||
bool ppi_endtx;
|
|
||||||
#ifdef CONFIG_UART_ASYNC_API
|
#ifdef CONFIG_UART_ASYNC_API
|
||||||
nrfx_timer_t timer;
|
nrfx_timer_t timer;
|
||||||
#endif
|
#endif
|
||||||
|
@ -354,7 +364,7 @@ static int uarte_nrfx_configure(const struct device *dev,
|
||||||
uarte_cfg.hwfc = NRF_UARTE_HWFC_DISABLED;
|
uarte_cfg.hwfc = NRF_UARTE_HWFC_DISABLED;
|
||||||
break;
|
break;
|
||||||
case UART_CFG_FLOW_CTRL_RTS_CTS:
|
case UART_CFG_FLOW_CTRL_RTS_CTS:
|
||||||
if (get_dev_config(dev)->rts_cts_pins_set) {
|
if (IS_HWFC_PINS_USED(get_dev_config(dev)->flags)) {
|
||||||
uarte_cfg.hwfc = NRF_UARTE_HWFC_ENABLED;
|
uarte_cfg.hwfc = NRF_UARTE_HWFC_ENABLED;
|
||||||
} else {
|
} else {
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
|
@ -417,7 +427,7 @@ static int uarte_nrfx_err_check(const struct device *dev)
|
||||||
static bool is_tx_ready(const struct device *dev)
|
static bool is_tx_ready(const struct device *dev)
|
||||||
{
|
{
|
||||||
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
|
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
|
||||||
bool ppi_endtx = get_dev_config(dev)->ppi_endtx;
|
bool ppi_endtx = get_dev_config(dev)->flags & UARTE_CFG_FLAG_PPI_ENDTX;
|
||||||
|
|
||||||
return nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_TXSTOPPED) ||
|
return nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_TXSTOPPED) ||
|
||||||
(!ppi_endtx ?
|
(!ppi_endtx ?
|
||||||
|
@ -1450,7 +1460,7 @@ static int uarte_instance_init(const struct device *dev,
|
||||||
data->pm_state = DEVICE_PM_ACTIVE_STATE;
|
data->pm_state = DEVICE_PM_ACTIVE_STATE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (get_dev_config(dev)->ppi_endtx) {
|
if (get_dev_config(dev)->flags & UARTE_CFG_FLAG_PPI_ENDTX) {
|
||||||
err = endtx_stoptx_ppi_init(uarte, data);
|
err = endtx_stoptx_ppi_init(uarte, data);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
return err;
|
return err;
|
||||||
|
@ -1478,7 +1488,7 @@ static int uarte_instance_init(const struct device *dev,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!get_dev_config(dev)->ppi_endtx) {
|
if (!(get_dev_config(dev)->flags & UARTE_CFG_FLAG_PPI_ENDTX)) {
|
||||||
nrf_uarte_int_enable(uarte, NRF_UARTE_INT_ENDTX_MASK);
|
nrf_uarte_int_enable(uarte, NRF_UARTE_INT_ENDTX_MASK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1499,7 +1509,7 @@ static int uarte_instance_init(const struct device *dev,
|
||||||
|
|
||||||
static void uarte_nrfx_pins_enable(const struct device *dev, bool enable)
|
static void uarte_nrfx_pins_enable(const struct device *dev, bool enable)
|
||||||
{
|
{
|
||||||
if (!get_dev_config(dev)->gpio_mgmt) {
|
if (!(get_dev_config(dev)->flags & UARTE_CFG_FLAG_GPIO_MGMT)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1516,12 +1526,12 @@ static void uarte_nrfx_pins_enable(const struct device *dev, bool enable)
|
||||||
nrf_gpio_cfg_input(rx_pin, NRF_GPIO_PIN_NOPULL);
|
nrf_gpio_cfg_input(rx_pin, NRF_GPIO_PIN_NOPULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_RTS_PIN_SET(get_dev_config(dev)->rts_cts_pins_set)) {
|
if (IS_RTS_PIN_SET(get_dev_config(dev)->flags)) {
|
||||||
nrf_gpio_pin_write(rts_pin, 1);
|
nrf_gpio_pin_write(rts_pin, 1);
|
||||||
nrf_gpio_cfg_output(rts_pin);
|
nrf_gpio_cfg_output(rts_pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_CTS_PIN_SET(get_dev_config(dev)->rts_cts_pins_set)) {
|
if (IS_CTS_PIN_SET(get_dev_config(dev)->flags)) {
|
||||||
nrf_gpio_cfg_input(cts_pin,
|
nrf_gpio_cfg_input(cts_pin,
|
||||||
NRF_GPIO_PIN_NOPULL);
|
NRF_GPIO_PIN_NOPULL);
|
||||||
}
|
}
|
||||||
|
@ -1531,11 +1541,11 @@ static void uarte_nrfx_pins_enable(const struct device *dev, bool enable)
|
||||||
nrf_gpio_cfg_default(rx_pin);
|
nrf_gpio_cfg_default(rx_pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_RTS_PIN_SET(get_dev_config(dev)->rts_cts_pins_set)) {
|
if (IS_RTS_PIN_SET(get_dev_config(dev)->flags)) {
|
||||||
nrf_gpio_cfg_default(rts_pin);
|
nrf_gpio_cfg_default(rts_pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_CTS_PIN_SET(get_dev_config(dev)->rts_cts_pins_set)) {
|
if (IS_CTS_PIN_SET(get_dev_config(dev)->flags)) {
|
||||||
nrf_gpio_cfg_default(cts_pin);
|
nrf_gpio_cfg_default(cts_pin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1703,11 +1713,15 @@ static int uarte_nrfx_pm_control(const struct device *dev,
|
||||||
}; \
|
}; \
|
||||||
static const struct uarte_nrfx_config uarte_##idx##z_config = { \
|
static const struct uarte_nrfx_config uarte_##idx##z_config = { \
|
||||||
.uarte_regs = (NRF_UARTE_Type *)DT_REG_ADDR(UARTE(idx)), \
|
.uarte_regs = (NRF_UARTE_Type *)DT_REG_ADDR(UARTE(idx)), \
|
||||||
.rts_cts_pins_set = \
|
.flags = \
|
||||||
(UARTE_HAS_PROP(idx, rts_pin) ? RTS_PIN_SET_MASK : 0) |\
|
(UARTE_HAS_PROP(idx, rts_pin) ? \
|
||||||
(UARTE_HAS_PROP(idx, cts_pin) ? CTS_PIN_SET_MASK : 0), \
|
UARTE_CFG_FLAG_RTS_PIN_SET : 0) | \
|
||||||
.gpio_mgmt = IS_ENABLED(CONFIG_UART_##idx##_GPIO_MANAGEMENT), \
|
(UARTE_HAS_PROP(idx, cts_pin) ? \
|
||||||
.ppi_endtx = IS_ENABLED(CONFIG_UART_##idx##_ENHANCED_POLL_OUT),\
|
UARTE_CFG_FLAG_CTS_PIN_SET : 0) | \
|
||||||
|
(IS_ENABLED(CONFIG_UART_##idx##_GPIO_MANAGEMENT) ? \
|
||||||
|
UARTE_CFG_FLAG_GPIO_MGMT : 0) | \
|
||||||
|
(IS_ENABLED(CONFIG_UART_##idx##_ENHANCED_POLL_OUT) ? \
|
||||||
|
UARTE_CFG_FLAG_PPI_ENDTX : 0), \
|
||||||
IF_ENABLED(CONFIG_UART_##idx##_NRF_HW_ASYNC, \
|
IF_ENABLED(CONFIG_UART_##idx##_NRF_HW_ASYNC, \
|
||||||
(.timer = NRFX_TIMER_INSTANCE( \
|
(.timer = NRFX_TIMER_INSTANCE( \
|
||||||
CONFIG_UART_##idx##_NRF_HW_ASYNC_TIMER),)) \
|
CONFIG_UART_##idx##_NRF_HW_ASYNC_TIMER),)) \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue