20
20
#include <errno.h>
21
21
#include <zephyr/drivers/i2c.h>
22
22
#include <zephyr/drivers/pinctrl.h>
23
- #include "i2c_ll_stm32.h"
23
+ #include <zephyr/irq.h>
24
24
25
25
#ifdef CONFIG_I2C_STM32_BUS_RECOVERY
26
26
#include "i2c_bitbang.h"
27
27
#endif /* CONFIG_I2C_STM32_BUS_RECOVERY */
28
28
29
29
#define LOG_LEVEL CONFIG_I2C_LOG_LEVEL
30
30
#include <zephyr/logging/log.h>
31
- #include <zephyr/irq.h>
32
31
LOG_MODULE_REGISTER (i2c_ll_stm32 );
33
32
33
+ #include "i2c_ll_stm32.h"
34
34
#include "i2c-priv.h"
35
35
36
36
#if DT_HAS_COMPAT_STATUS_OKAY (st_stm32_i2c_v2 )
@@ -42,9 +42,9 @@ LOG_MODULE_REGISTER(i2c_ll_stm32);
42
42
/* This symbol takes the value 1 if one of the device instances */
43
43
/* is configured in dts with a domain clock */
44
44
#if STM32_DT_INST_DEV_DOMAIN_CLOCK_SUPPORT
45
- #define STM32_I2C_DOMAIN_CLOCK_SUPPORT 1
45
+ #define I2C_STM32_DOMAIN_CLOCK_SUPPORT 1
46
46
#else
47
- #define STM32_I2C_DOMAIN_CLOCK_SUPPORT 0
47
+ #define I2C_STM32_DOMAIN_CLOCK_SUPPORT 0
48
48
#endif
49
49
50
50
int i2c_stm32_get_config (const struct device * dev , uint32_t * config )
@@ -90,7 +90,7 @@ int i2c_stm32_runtime_configure(const struct device *dev, uint32_t config)
90
90
uint32_t i2c_clock = 0U ;
91
91
int ret ;
92
92
93
- if (IS_ENABLED (STM32_I2C_DOMAIN_CLOCK_SUPPORT ) && (cfg -> pclk_len > 1 )) {
93
+ if (IS_ENABLED (I2C_STM32_DOMAIN_CLOCK_SUPPORT ) && (cfg -> pclk_len > 1 )) {
94
94
if (clock_control_get_rate (clk , (clock_control_subsys_t )& cfg -> pclken [1 ],
95
95
& i2c_clock ) < 0 ) {
96
96
LOG_ERR ("Failed call clock_control_get_rate(pclken[1])" );
@@ -120,7 +120,7 @@ int i2c_stm32_runtime_configure(const struct device *dev, uint32_t config)
120
120
#if defined(I2C_CR1_SMBUS ) || defined(I2C_CR1_SMBDEN ) || defined(I2C_CR1_SMBHEN )
121
121
i2c_stm32_set_smbus_mode (dev , data -> mode );
122
122
#endif
123
- ret = stm32_i2c_configure_timing (dev , i2c_clock );
123
+ ret = i2c_stm32_configure_timing (dev , i2c_clock );
124
124
125
125
if (data -> smbalert_active ) {
126
126
LL_I2C_Enable (i2c );
@@ -210,7 +210,7 @@ static int i2c_stm32_transfer(const struct device *dev, struct i2c_msg *msg,
210
210
next = current + 1 ;
211
211
next_msg_flags = & (next -> flags );
212
212
}
213
- ret = stm32_i2c_transaction (dev , * current , next_msg_flags , slave );
213
+ ret = i2c_stm32_transaction (dev , * current , next_msg_flags , slave );
214
214
if (ret < 0 ) {
215
215
break ;
216
216
}
@@ -411,7 +411,7 @@ static int i2c_stm32_init(const struct device *dev)
411
411
412
412
i2c_stm32_activate (dev );
413
413
414
- if (IS_ENABLED (STM32_I2C_DOMAIN_CLOCK_SUPPORT ) && (cfg -> pclk_len > 1 )) {
414
+ if (IS_ENABLED (I2C_STM32_DOMAIN_CLOCK_SUPPORT ) && (cfg -> pclk_len > 1 )) {
415
415
/* Enable I2C clock source */
416
416
ret = clock_control_configure (clk ,
417
417
(clock_control_subsys_t ) & cfg -> pclken [1 ],
@@ -543,60 +543,60 @@ void i2c_stm32_smbalert_disable(const struct device *dev)
543
543
#ifdef CONFIG_I2C_STM32_INTERRUPT
544
544
545
545
#ifdef CONFIG_I2C_STM32_COMBINED_INTERRUPT
546
- #define STM32_I2C_IRQ_CONNECT_AND_ENABLE (index ) \
546
+ #define I2C_STM32_IRQ_CONNECT_AND_ENABLE (index ) \
547
547
do { \
548
548
IRQ_CONNECT(DT_INST_IRQN(index), \
549
549
DT_INST_IRQ(index, priority), \
550
- stm32_i2c_combined_isr , \
550
+ i2c_stm32_combined_isr , \
551
551
DEVICE_DT_INST_GET(index), 0); \
552
552
irq_enable(DT_INST_IRQN(index)); \
553
553
} while (false)
554
554
#else
555
- #define STM32_I2C_IRQ_CONNECT_AND_ENABLE (index ) \
555
+ #define I2C_STM32_IRQ_CONNECT_AND_ENABLE (index ) \
556
556
do { \
557
557
IRQ_CONNECT(DT_INST_IRQ_BY_NAME(index, event, irq), \
558
558
DT_INST_IRQ_BY_NAME(index, event, priority),\
559
- stm32_i2c_event_isr , \
559
+ i2c_stm32_event_isr , \
560
560
DEVICE_DT_INST_GET(index), 0); \
561
561
irq_enable(DT_INST_IRQ_BY_NAME(index, event, irq)); \
562
562
\
563
563
IRQ_CONNECT(DT_INST_IRQ_BY_NAME(index, error, irq), \
564
564
DT_INST_IRQ_BY_NAME(index, error, priority),\
565
- stm32_i2c_error_isr , \
565
+ i2c_stm32_error_isr , \
566
566
DEVICE_DT_INST_GET(index), 0); \
567
567
irq_enable(DT_INST_IRQ_BY_NAME(index, error, irq)); \
568
568
} while (false)
569
569
#endif /* CONFIG_I2C_STM32_COMBINED_INTERRUPT */
570
570
571
- #define STM32_I2C_IRQ_HANDLER_DECL (index ) \
571
+ #define I2C_STM32_IRQ_HANDLER_DECL (index ) \
572
572
static void i2c_stm32_irq_config_func_##index(const struct device *dev)
573
- #define STM32_I2C_IRQ_HANDLER_FUNCTION (index ) \
573
+ #define I2C_STM32_IRQ_HANDLER_FUNCTION (index ) \
574
574
.irq_config_func = i2c_stm32_irq_config_func_##index,
575
- #define STM32_I2C_IRQ_HANDLER (index ) \
575
+ #define I2C_STM32_IRQ_HANDLER (index ) \
576
576
static void i2c_stm32_irq_config_func_##index(const struct device *dev) \
577
577
{ \
578
- STM32_I2C_IRQ_CONNECT_AND_ENABLE (index); \
578
+ I2C_STM32_IRQ_CONNECT_AND_ENABLE (index); \
579
579
}
580
580
#else
581
581
582
- #define STM32_I2C_IRQ_HANDLER_DECL (index )
583
- #define STM32_I2C_IRQ_HANDLER_FUNCTION (index )
584
- #define STM32_I2C_IRQ_HANDLER (index )
582
+ #define I2C_STM32_IRQ_HANDLER_DECL (index )
583
+ #define I2C_STM32_IRQ_HANDLER_FUNCTION (index )
584
+ #define I2C_STM32_IRQ_HANDLER (index )
585
585
586
586
#endif /* CONFIG_I2C_STM32_INTERRUPT */
587
587
588
588
#ifdef CONFIG_I2C_STM32_V2_DMA
589
589
590
- #define I2C_DMA_INIT (index , dir ) \
591
- .dir##_dma = { \
592
- .dev_dma = COND_CODE_1(DT_INST_DMAS_HAS_NAME(index, dir),\
593
- (DEVICE_DT_GET(STM32_DMA_CTLR(index, dir))), (NULL)),\
594
- .dma_channel = COND_CODE_1(DT_INST_DMAS_HAS_NAME(index, dir),\
595
- (DT_INST_DMAS_CELL_BY_NAME(index, dir, channel)), (-1)),\
590
+ #define I2C_DMA_INIT (index , dir ) \
591
+ .dir##_dma = { \
592
+ .dev_dma = COND_CODE_1(DT_INST_DMAS_HAS_NAME(index, dir), \
593
+ (DEVICE_DT_GET(STM32_DMA_CTLR(index, dir))), (NULL)), \
594
+ .dma_channel = COND_CODE_1(DT_INST_DMAS_HAS_NAME(index, dir), \
595
+ (DT_INST_DMAS_CELL_BY_NAME(index, dir, channel)), (-1)), \
596
596
},
597
597
598
598
void i2c_stm32_dma_tx_cb (const struct device * dma_dev , void * user_data ,
599
- uint32_t channel , int status )
599
+ uint32_t channel , int status )
600
600
{
601
601
ARG_UNUSED (dma_dev );
602
602
ARG_UNUSED (user_data );
@@ -609,7 +609,7 @@ void i2c_stm32_dma_tx_cb(const struct device *dma_dev, void *user_data,
609
609
}
610
610
611
611
void i2c_stm32_dma_rx_cb (const struct device * dma_dev , void * user_data ,
612
- uint32_t channel , int status )
612
+ uint32_t channel , int status )
613
613
{
614
614
ARG_UNUSED (dma_dev );
615
615
ARG_UNUSED (user_data );
@@ -621,23 +621,23 @@ void i2c_stm32_dma_rx_cb(const struct device *dma_dev, void *user_data,
621
621
}
622
622
}
623
623
624
- #define I2C_DMA_DATA_INIT (index , dir , src , dest ) \
625
- .dma_##dir##_cfg = { \
626
- .dma_slot = STM32_DMA_SLOT(index, dir, slot), \
627
- .channel_direction = STM32_DMA_CONFIG_DIRECTION( \
628
- STM32_DMA_CHANNEL_CONFIG(index, dir)),\
629
- .cyclic = STM32_DMA_CONFIG_CYCLIC( \
630
- STM32_DMA_CHANNEL_CONFIG(index, dir)), \
631
- .channel_priority = STM32_DMA_CONFIG_PRIORITY( \
632
- STM32_DMA_CHANNEL_CONFIG(index, dir)), \
633
- .source_data_size = STM32_DMA_CONFIG_##src##_DATA_SIZE( \
634
- STM32_DMA_CHANNEL_CONFIG(index, dir)),\
635
- .dest_data_size = STM32_DMA_CONFIG_##dest##_DATA_SIZE( \
636
- STM32_DMA_CHANNEL_CONFIG(index, dir)), \
637
- .source_burst_length = 1, \
638
- .dest_burst_length = 1, \
639
- .dma_callback = i2c_stm32_dma_##dir##_cb, \
640
- }, \
624
+ #define I2C_DMA_DATA_INIT (index , dir , src , dest ) \
625
+ .dma_##dir##_cfg = { \
626
+ .dma_slot = STM32_DMA_SLOT(index, dir, slot), \
627
+ .channel_direction = STM32_DMA_CONFIG_DIRECTION( \
628
+ STM32_DMA_CHANNEL_CONFIG(index, dir)), \
629
+ .cyclic = STM32_DMA_CONFIG_CYCLIC( \
630
+ STM32_DMA_CHANNEL_CONFIG(index, dir)), \
631
+ .channel_priority = STM32_DMA_CONFIG_PRIORITY( \
632
+ STM32_DMA_CHANNEL_CONFIG(index, dir)), \
633
+ .source_data_size = STM32_DMA_CONFIG_##src##_DATA_SIZE( \
634
+ STM32_DMA_CHANNEL_CONFIG(index, dir)), \
635
+ .dest_data_size = STM32_DMA_CONFIG_##dest##_DATA_SIZE( \
636
+ STM32_DMA_CHANNEL_CONFIG(index, dir)), \
637
+ .source_burst_length = 1, \
638
+ .dest_burst_length = 1, \
639
+ .dma_callback = i2c_stm32_dma_##dir##_cb, \
640
+ }, \
641
641
642
642
#else
643
643
@@ -646,49 +646,49 @@ void i2c_stm32_dma_rx_cb(const struct device *dma_dev, void *user_data,
646
646
647
647
#endif /* CONFIG_I2C_STM32_V2_DMA */
648
648
649
- #define STM32_I2C_INIT (index ) \
650
- STM32_I2C_IRQ_HANDLER_DECL (index); \
651
- \
652
- IF_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32_i2c_v2), \
653
- (static const uint32_t i2c_timings_##index[] = \
654
- DT_INST_PROP_OR(index, timings, {});)) \
655
- \
656
- PINCTRL_DT_INST_DEFINE(index); \
657
- \
658
- static const struct stm32_pclken pclken_##index[] = \
659
- STM32_DT_INST_CLOCKS(index); \
660
- \
661
- static const struct i2c_stm32_config i2c_stm32_cfg_##index = { \
662
- .i2c = (I2C_TypeDef *)DT_INST_REG_ADDR(index), \
663
- .pclken = pclken_##index, \
664
- .pclk_len = DT_INST_NUM_CLOCKS(index), \
665
- STM32_I2C_IRQ_HANDLER_FUNCTION (index) \
666
- .bitrate = DT_INST_PROP(index, clock_frequency), \
667
- .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(index), \
668
- IF_ENABLED(CONFIG_I2C_STM32_BUS_RECOVERY, \
669
- (.scl = GPIO_DT_SPEC_INST_GET_OR(index, scl_gpios, {0}),\
670
- .sda = GPIO_DT_SPEC_INST_GET_OR(index, sda_gpios, {0}),))\
671
- IF_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32_i2c_v2), \
672
- (.timings = (const struct i2c_config_timing *) i2c_timings_##index,\
673
- .n_timings = ARRAY_SIZE(i2c_timings_##index),)) \
674
- I2C_DMA_INIT(index, tx) \
675
- I2C_DMA_INIT(index, rx) \
676
- }; \
677
- \
678
- static struct i2c_stm32_data i2c_stm32_dev_data_##index = { \
679
- I2C_DMA_DATA_INIT(index, tx, MEMORY, PERIPHERAL) \
680
- I2C_DMA_DATA_INIT(index, rx, PERIPHERAL, MEMORY) \
681
- }; \
682
- \
683
- PM_DEVICE_DT_INST_DEFINE(index, i2c_stm32_pm_action); \
684
- \
685
- I2C_DEVICE_DT_INST_DEFINE(index, i2c_stm32_init, \
686
- PM_DEVICE_DT_INST_GET(index), \
687
- &i2c_stm32_dev_data_##index, \
688
- &i2c_stm32_cfg_##index, \
689
- POST_KERNEL, CONFIG_I2C_INIT_PRIORITY, \
690
- &api_funcs); \
691
- \
692
- STM32_I2C_IRQ_HANDLER (index)
693
-
694
- DT_INST_FOREACH_STATUS_OKAY (STM32_I2C_INIT )
649
+ #define I2C_STM32_INIT (index ) \
650
+ I2C_STM32_IRQ_HANDLER_DECL (index); \
651
+ \
652
+ IF_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32_i2c_v2), \
653
+ (static const uint32_t i2c_timings_##index[] = \
654
+ DT_INST_PROP_OR(index, timings, {});)) \
655
+ \
656
+ PINCTRL_DT_INST_DEFINE(index); \
657
+ \
658
+ static const struct stm32_pclken pclken_##index[] = \
659
+ STM32_DT_INST_CLOCKS(index); \
660
+ \
661
+ static const struct i2c_stm32_config i2c_stm32_cfg_##index = { \
662
+ .i2c = (I2C_TypeDef *)DT_INST_REG_ADDR(index), \
663
+ .pclken = pclken_##index, \
664
+ .pclk_len = DT_INST_NUM_CLOCKS(index), \
665
+ I2C_STM32_IRQ_HANDLER_FUNCTION (index) \
666
+ .bitrate = DT_INST_PROP(index, clock_frequency), \
667
+ .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(index), \
668
+ IF_ENABLED(CONFIG_I2C_STM32_BUS_RECOVERY, \
669
+ (.scl = GPIO_DT_SPEC_INST_GET_OR(index, scl_gpios, {0}), \
670
+ .sda = GPIO_DT_SPEC_INST_GET_OR(index, sda_gpios, {0}),)) \
671
+ IF_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32_i2c_v2), \
672
+ (.timings = (const struct i2c_config_timing *) i2c_timings_##index, \
673
+ .n_timings = ARRAY_SIZE(i2c_timings_##index),)) \
674
+ I2C_DMA_INIT(index, tx) \
675
+ I2C_DMA_INIT(index, rx) \
676
+ }; \
677
+ \
678
+ static struct i2c_stm32_data i2c_stm32_dev_data_##index = { \
679
+ I2C_DMA_DATA_INIT(index, tx, MEMORY, PERIPHERAL) \
680
+ I2C_DMA_DATA_INIT(index, rx, PERIPHERAL, MEMORY) \
681
+ }; \
682
+ \
683
+ PM_DEVICE_DT_INST_DEFINE(index, i2c_stm32_pm_action); \
684
+ \
685
+ I2C_DEVICE_DT_INST_DEFINE(index, i2c_stm32_init, \
686
+ PM_DEVICE_DT_INST_GET(index), \
687
+ &i2c_stm32_dev_data_##index, \
688
+ &i2c_stm32_cfg_##index, \
689
+ POST_KERNEL, CONFIG_I2C_INIT_PRIORITY, \
690
+ &api_funcs); \
691
+ \
692
+ I2C_STM32_IRQ_HANDLER (index)
693
+
694
+ DT_INST_FOREACH_STATUS_OKAY (I2C_STM32_INIT )
0 commit comments