Skip to content

Commit 8dbc30a

Browse files
sgilbert182carlescufi
authored andcommitted
i2c: stm32: Add macros to get settings from device tree
Add macrobatics to pull DMA settings from device tree Signed-off-by: Simon Gilbert <[email protected]>
1 parent ce03586 commit 8dbc30a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

drivers/i2c/i2c_ll_stm32.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* SPDX-License-Identifier: Apache-2.0
66
*/
77

8+
#include <zephyr/drivers/dma.h>
9+
#include <zephyr/drivers/dma/dma_stm32.h>
810
#include <zephyr/drivers/clock_control/stm32_clock_control.h>
911
#include <zephyr/drivers/clock_control.h>
1012
#include <zephyr/pm/device.h>
@@ -582,6 +584,20 @@ static void i2c_stm32_irq_config_func_##index(const struct device *dev) \
582584

583585
#endif /* CONFIG_I2C_STM32_INTERRUPT */
584586

587+
#ifdef CONFIG_I2C_STM32_V2_DMA
588+
589+
#define I2C_DMA_INIT(index, dir) \
590+
.dir##_dma = {.dev_dma = COND_CODE_1(DT_INST_DMAS_HAS_NAME(index, dir), \
591+
(DEVICE_DT_GET(STM32_DMA_CTLR(index, dir))), (NULL)), \
592+
.dma_channel = COND_CODE_1(DT_INST_DMAS_HAS_NAME(index, dir), \
593+
(DT_INST_DMAS_CELL_BY_NAME(index, dir, channel)), (-1))},
594+
595+
#else
596+
597+
#define I2C_DMA_INIT(index, dir)
598+
599+
#endif /* CONFIG_I2C_STM32_V2_DMA */
600+
585601
#define STM32_I2C_INIT(index) \
586602
STM32_I2C_IRQ_HANDLER_DECL(index); \
587603
\
@@ -607,6 +623,8 @@ static const struct i2c_stm32_config i2c_stm32_cfg_##index = { \
607623
IF_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32_i2c_v2), \
608624
(.timings = (const struct i2c_config_timing *) i2c_timings_##index,\
609625
.n_timings = ARRAY_SIZE(i2c_timings_##index),)) \
626+
I2C_DMA_INIT(index, tx) \
627+
I2C_DMA_INIT(index, rx) \
610628
}; \
611629
\
612630
static struct i2c_stm32_data i2c_stm32_dev_data_##index; \

0 commit comments

Comments
 (0)