drivers: serial: drop DEV_DATA/DEV_CFG usage
Stop using redundant DEV_DATA/DEV_CFG macros and use dev->data and dev->config instead. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
e8c15f68b2
commit
1674fec5b6
26 changed files with 700 additions and 623 deletions
|
@ -41,13 +41,9 @@ LOG_MODULE_REGISTER(uart_stm32);
|
|||
#define HAS_LPUART_1 (DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(lpuart1), \
|
||||
st_stm32_lpuart, okay))
|
||||
|
||||
/* convenience defines */
|
||||
#define DEV_CFG(dev) \
|
||||
((const struct uart_stm32_config *const)(dev)->config)
|
||||
#define DEV_DATA(dev) \
|
||||
((struct uart_stm32_data *const)(dev)->data)
|
||||
#define UART_STRUCT(dev) \
|
||||
((USART_TypeDef *)(DEV_CFG(dev))->uconf.base)
|
||||
((USART_TypeDef *) \
|
||||
((const struct uart_stm32_config *const)(dev)->config)->uconf.base)
|
||||
|
||||
#if HAS_LPUART_1
|
||||
#ifdef USART_PRESC_PRESCALER
|
||||
|
@ -82,7 +78,7 @@ uint32_t lpuartdiv_calc(const uint64_t clock_rate, const uint32_t baud_rate)
|
|||
#ifdef CONFIG_PM
|
||||
static void uart_stm32_pm_constraint_set(const struct device *dev)
|
||||
{
|
||||
struct uart_stm32_data *data = DEV_DATA(dev);
|
||||
struct uart_stm32_data *data = dev->data;
|
||||
|
||||
if (!data->pm_constraint_on) {
|
||||
data->pm_constraint_on = true;
|
||||
|
@ -92,7 +88,7 @@ static void uart_stm32_pm_constraint_set(const struct device *dev)
|
|||
|
||||
static void uart_stm32_pm_constraint_release(const struct device *dev)
|
||||
{
|
||||
struct uart_stm32_data *data = DEV_DATA(dev);
|
||||
struct uart_stm32_data *data = dev->data;
|
||||
|
||||
if (data->pm_constraint_on) {
|
||||
data->pm_constraint_on = false;
|
||||
|
@ -104,8 +100,8 @@ static void uart_stm32_pm_constraint_release(const struct device *dev)
|
|||
static inline void uart_stm32_set_baudrate(const struct device *dev,
|
||||
uint32_t baud_rate)
|
||||
{
|
||||
const struct uart_stm32_config *config = DEV_CFG(dev);
|
||||
struct uart_stm32_data *data = DEV_DATA(dev);
|
||||
const struct uart_stm32_config *config = dev->config;
|
||||
struct uart_stm32_data *data = dev->data;
|
||||
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
||||
|
||||
uint32_t clock_rate;
|
||||
|
@ -399,7 +395,7 @@ static inline enum uart_config_flow_control uart_stm32_ll2cfg_hwctrl(uint32_t fc
|
|||
static int uart_stm32_configure(const struct device *dev,
|
||||
const struct uart_config *cfg)
|
||||
{
|
||||
struct uart_stm32_data *data = DEV_DATA(dev);
|
||||
struct uart_stm32_data *data = dev->data;
|
||||
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
||||
const uint32_t parity = uart_stm32_cfg2ll_parity(cfg->parity);
|
||||
const uint32_t stopbits = uart_stm32_cfg2ll_stopbits(cfg->stop_bits);
|
||||
|
@ -489,7 +485,7 @@ static int uart_stm32_configure(const struct device *dev,
|
|||
static int uart_stm32_config_get(const struct device *dev,
|
||||
struct uart_config *cfg)
|
||||
{
|
||||
struct uart_stm32_data *data = DEV_DATA(dev);
|
||||
struct uart_stm32_data *data = dev->data;
|
||||
|
||||
cfg->baudrate = data->baud_rate;
|
||||
cfg->parity = uart_stm32_ll2cfg_parity(uart_stm32_get_parity(dev));
|
||||
|
@ -526,7 +522,7 @@ static void uart_stm32_poll_out(const struct device *dev,
|
|||
{
|
||||
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
||||
#ifdef CONFIG_PM
|
||||
struct uart_stm32_data *data = DEV_DATA(dev);
|
||||
struct uart_stm32_data *data = dev->data;
|
||||
#endif
|
||||
int key;
|
||||
|
||||
|
@ -612,7 +608,7 @@ static int uart_stm32_err_check(const struct device *dev)
|
|||
|
||||
static inline void __uart_stm32_get_clock(const struct device *dev)
|
||||
{
|
||||
struct uart_stm32_data *data = DEV_DATA(dev);
|
||||
struct uart_stm32_data *data = dev->data;
|
||||
const struct device *clk = DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE);
|
||||
|
||||
data->clock = clk;
|
||||
|
@ -674,7 +670,7 @@ static void uart_stm32_irq_tx_enable(const struct device *dev)
|
|||
{
|
||||
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
||||
#ifdef CONFIG_PM
|
||||
struct uart_stm32_data *data = DEV_DATA(dev);
|
||||
struct uart_stm32_data *data = dev->data;
|
||||
int key;
|
||||
#endif
|
||||
|
||||
|
@ -695,7 +691,7 @@ static void uart_stm32_irq_tx_disable(const struct device *dev)
|
|||
{
|
||||
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
||||
#ifdef CONFIG_PM
|
||||
struct uart_stm32_data *data = DEV_DATA(dev);
|
||||
struct uart_stm32_data *data = dev->data;
|
||||
int key;
|
||||
|
||||
key = irq_lock();
|
||||
|
@ -800,7 +796,7 @@ static void uart_stm32_irq_callback_set(const struct device *dev,
|
|||
uart_irq_callback_user_data_t cb,
|
||||
void *cb_data)
|
||||
{
|
||||
struct uart_stm32_data *data = DEV_DATA(dev);
|
||||
struct uart_stm32_data *data = dev->data;
|
||||
|
||||
data->user_cb = cb;
|
||||
data->user_data = cb_data;
|
||||
|
@ -919,7 +915,7 @@ static inline void async_timer_start(struct k_work_delayable *work,
|
|||
static void uart_stm32_dma_rx_flush(const struct device *dev)
|
||||
{
|
||||
struct dma_status stat;
|
||||
struct uart_stm32_data *data = DEV_DATA(dev);
|
||||
struct uart_stm32_data *data = dev->data;
|
||||
|
||||
if (dma_get_status(data->dma_rx.dma_dev,
|
||||
data->dma_rx.dma_channel, &stat) == 0) {
|
||||
|
@ -941,7 +937,7 @@ static void uart_stm32_dma_rx_flush(const struct device *dev)
|
|||
|
||||
static void uart_stm32_isr(const struct device *dev)
|
||||
{
|
||||
struct uart_stm32_data *data = DEV_DATA(dev);
|
||||
struct uart_stm32_data *data = dev->data;
|
||||
#if defined(CONFIG_PM) || defined(CONFIG_UART_ASYNC_API)
|
||||
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
||||
#endif
|
||||
|
@ -1020,7 +1016,7 @@ static int uart_stm32_async_callback_set(const struct device *dev,
|
|||
uart_callback_t callback,
|
||||
void *user_data)
|
||||
{
|
||||
struct uart_stm32_data *data = DEV_DATA(dev);
|
||||
struct uart_stm32_data *data = dev->data;
|
||||
|
||||
data->async_cb = callback;
|
||||
data->async_user_data = user_data;
|
||||
|
@ -1045,7 +1041,7 @@ static inline void uart_stm32_dma_tx_disable(const struct device *dev)
|
|||
static inline void uart_stm32_dma_rx_enable(const struct device *dev)
|
||||
{
|
||||
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
||||
struct uart_stm32_data *data = DEV_DATA(dev);
|
||||
struct uart_stm32_data *data = dev->data;
|
||||
|
||||
LL_USART_EnableDMAReq_RX(UartInstance);
|
||||
|
||||
|
@ -1054,14 +1050,14 @@ static inline void uart_stm32_dma_rx_enable(const struct device *dev)
|
|||
|
||||
static inline void uart_stm32_dma_rx_disable(const struct device *dev)
|
||||
{
|
||||
struct uart_stm32_data *data = DEV_DATA(dev);
|
||||
struct uart_stm32_data *data = dev->data;
|
||||
|
||||
data->dma_rx.enabled = false;
|
||||
}
|
||||
|
||||
static int uart_stm32_async_rx_disable(const struct device *dev)
|
||||
{
|
||||
struct uart_stm32_data *data = DEV_DATA(dev);
|
||||
struct uart_stm32_data *data = dev->data;
|
||||
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
||||
struct uart_event disabled_event = {
|
||||
.type = UART_RX_DISABLED
|
||||
|
@ -1101,7 +1097,7 @@ void uart_stm32_dma_tx_cb(const struct device *dma_dev, void *user_data,
|
|||
uint32_t channel, int status)
|
||||
{
|
||||
const struct device *uart_dev = user_data;
|
||||
struct uart_stm32_data *data = DEV_DATA(uart_dev);
|
||||
struct uart_stm32_data *data = uart_dev->data;
|
||||
struct dma_status stat;
|
||||
unsigned int key = irq_lock();
|
||||
|
||||
|
@ -1123,7 +1119,7 @@ void uart_stm32_dma_tx_cb(const struct device *dma_dev, void *user_data,
|
|||
|
||||
static void uart_stm32_dma_replace_buffer(const struct device *dev)
|
||||
{
|
||||
struct uart_stm32_data *data = DEV_DATA(dev);
|
||||
struct uart_stm32_data *data = dev->data;
|
||||
|
||||
/* Replace the buffer and relod the DMA */
|
||||
LOG_DBG("Replacing RX buffer: %d", data->rx_next_buffer_len);
|
||||
|
@ -1157,7 +1153,7 @@ void uart_stm32_dma_rx_cb(const struct device *dma_dev, void *user_data,
|
|||
uint32_t channel, int status)
|
||||
{
|
||||
const struct device *uart_dev = user_data;
|
||||
struct uart_stm32_data *data = DEV_DATA(uart_dev);
|
||||
struct uart_stm32_data *data = uart_dev->data;
|
||||
|
||||
if (status != 0) {
|
||||
async_evt_rx_err(data, status);
|
||||
|
@ -1193,7 +1189,7 @@ void uart_stm32_dma_rx_cb(const struct device *dma_dev, void *user_data,
|
|||
static int uart_stm32_async_tx(const struct device *dev,
|
||||
const uint8_t *tx_data, size_t buf_size, int32_t timeout)
|
||||
{
|
||||
struct uart_stm32_data *data = DEV_DATA(dev);
|
||||
struct uart_stm32_data *data = dev->data;
|
||||
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
||||
int ret;
|
||||
|
||||
|
@ -1252,7 +1248,7 @@ static int uart_stm32_async_tx(const struct device *dev,
|
|||
static int uart_stm32_async_rx_enable(const struct device *dev,
|
||||
uint8_t *rx_buf, size_t buf_size, int32_t timeout)
|
||||
{
|
||||
struct uart_stm32_data *data = DEV_DATA(dev);
|
||||
struct uart_stm32_data *data = dev->data;
|
||||
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
||||
int ret;
|
||||
|
||||
|
@ -1311,7 +1307,7 @@ static int uart_stm32_async_rx_enable(const struct device *dev,
|
|||
|
||||
static int uart_stm32_async_tx_abort(const struct device *dev)
|
||||
{
|
||||
struct uart_stm32_data *data = DEV_DATA(dev);
|
||||
struct uart_stm32_data *data = dev->data;
|
||||
size_t tx_buffer_length = data->dma_tx.buffer_length;
|
||||
struct dma_status stat;
|
||||
|
||||
|
@ -1364,7 +1360,7 @@ static void uart_stm32_async_tx_timeout(struct k_work *work)
|
|||
static int uart_stm32_async_rx_buf_rsp(const struct device *dev, uint8_t *buf,
|
||||
size_t len)
|
||||
{
|
||||
struct uart_stm32_data *data = DEV_DATA(dev);
|
||||
struct uart_stm32_data *data = dev->data;
|
||||
|
||||
LOG_DBG("replace buffer (%d)", len);
|
||||
data->rx_next_buffer = buf;
|
||||
|
@ -1375,7 +1371,7 @@ static int uart_stm32_async_rx_buf_rsp(const struct device *dev, uint8_t *buf,
|
|||
|
||||
static int uart_stm32_async_init(const struct device *dev)
|
||||
{
|
||||
struct uart_stm32_data *data = DEV_DATA(dev);
|
||||
struct uart_stm32_data *data = dev->data;
|
||||
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
||||
|
||||
data->uart_dev = dev;
|
||||
|
@ -1525,8 +1521,8 @@ static const struct uart_driver_api uart_stm32_driver_api = {
|
|||
*/
|
||||
static int uart_stm32_init(const struct device *dev)
|
||||
{
|
||||
const struct uart_stm32_config *config = DEV_CFG(dev);
|
||||
struct uart_stm32_data *data = DEV_DATA(dev);
|
||||
const struct uart_stm32_config *config = dev->config;
|
||||
struct uart_stm32_data *data = dev->data;
|
||||
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
||||
uint32_t ll_parity;
|
||||
uint32_t ll_datawidth;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue