@@ -53,15 +53,21 @@ extern "C" {
53
53
#define SLAVE_MODE_LISTEN 2
54
54
55
55
/* Family specific description for I2C */
56
- #if defined(STM32F7xx ) || defined(STM32H7xx ) || defined(STM32L4xx )
57
- #define I2C_NUM (4)
58
- #elif defined(STM32F2xx ) || defined(STM32F3xx ) || defined(STM32F4xx ) || defined(STM32L0xx )
59
- #define I2C_NUM (3)
60
- #elif defined(STM32F0xx ) || defined(STM32F1xx ) || defined(STM32L1xx )
61
- #define I2C_NUM (2)
62
- #else
63
- #error "Unknown Family - unknown I2C_NUM"
56
+ typedef enum {
57
+ #if defined(I2C1_BASE )
58
+ I2C1_INDEX ,
59
+ #endif
60
+ #if defined(I2C2_BASE )
61
+ I2C2_INDEX ,
62
+ #endif
63
+ #if defined(I2C3_BASE )
64
+ I2C3_INDEX ,
65
+ #endif
66
+ #if defined(I2C4_BASE )
67
+ I2C4_INDEX ,
64
68
#endif
69
+ I2C_NUM
70
+ } i2c_index_t ;
65
71
66
72
/* Private Variables */
67
73
static I2C_HandleTypeDef * i2c_handles [I2C_NUM ];
@@ -121,7 +127,7 @@ void i2c_custom_init(i2c_t *obj, i2c_timing_e timing, uint32_t addressingMode, u
121
127
#if !defined(STM32F0xx ) && !defined(STM32L0xx )
122
128
obj -> irqER = I2C1_ER_IRQn ;
123
129
#endif // !defined(STM32F0xx) && !defined(STM32L0xx)
124
- i2c_handles [0 ] = handle ;
130
+ i2c_handles [I2C1_INDEX ] = handle ;
125
131
}
126
132
#endif // I2C1_BASE
127
133
#if defined I2C2_BASE
@@ -134,7 +140,7 @@ void i2c_custom_init(i2c_t *obj, i2c_timing_e timing, uint32_t addressingMode, u
134
140
#if !defined(STM32F0xx ) && !defined(STM32L0xx )
135
141
obj -> irqER = I2C2_ER_IRQn ;
136
142
#endif // !defined(STM32F0xx) && !defined(STM32L0xx)
137
- i2c_handles [1 ] = handle ;
143
+ i2c_handles [I2C2_INDEX ] = handle ;
138
144
}
139
145
#endif // I2C2_BASE
140
146
#if defined I2C3_BASE
@@ -147,7 +153,7 @@ void i2c_custom_init(i2c_t *obj, i2c_timing_e timing, uint32_t addressingMode, u
147
153
#if !defined(STM32F0xx ) && !defined(STM32L0xx )
148
154
obj -> irqER = I2C3_ER_IRQn ;
149
155
#endif // !defined(STM32F0xx) && !defined(STM32L0xx)
150
- i2c_handles [2 ] = handle ;
156
+ i2c_handles [I2C3_INDEX ] = handle ;
151
157
}
152
158
#endif // I2C3_BASE
153
159
#if defined I2C4_BASE
@@ -160,7 +166,7 @@ void i2c_custom_init(i2c_t *obj, i2c_timing_e timing, uint32_t addressingMode, u
160
166
#if !defined(STM32F0xx ) && !defined(STM32L0xx )
161
167
obj -> irqER = I2C4_ER_IRQn ;
162
168
#endif // !defined(STM32F0xx) && !defined(STM32L0xx)
163
- i2c_handles [3 ] = handle ;
169
+ i2c_handles [I2C4_INDEX ] = handle ;
164
170
}
165
171
#endif // I2C4_BASE
166
172
@@ -577,7 +583,7 @@ void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c)
577
583
*/
578
584
void I2C1_EV_IRQHandler (void )
579
585
{
580
- I2C_HandleTypeDef * handle = i2c_handles [0 ];
586
+ I2C_HandleTypeDef * handle = i2c_handles [I2C1_INDEX ];
581
587
HAL_I2C_EV_IRQHandler (handle );
582
588
#if defined(STM32F0xx ) || defined(STM32L0xx )
583
589
HAL_I2C_ER_IRQHandler (handle );
@@ -592,7 +598,7 @@ void I2C1_EV_IRQHandler(void)
592
598
*/
593
599
void I2C1_ER_IRQHandler (void )
594
600
{
595
- I2C_HandleTypeDef * handle = i2c_handles [0 ];
601
+ I2C_HandleTypeDef * handle = i2c_handles [I2C1_INDEX ];
596
602
HAL_I2C_ER_IRQHandler (handle );
597
603
}
598
604
#endif // !defined(STM32F0xx) && !defined(STM32L0xx)
@@ -606,7 +612,7 @@ void I2C1_ER_IRQHandler(void)
606
612
*/
607
613
void I2C2_EV_IRQHandler (void )
608
614
{
609
- I2C_HandleTypeDef * handle = i2c_handles [1 ];
615
+ I2C_HandleTypeDef * handle = i2c_handles [I2C2_INDEX ];
610
616
HAL_I2C_EV_IRQHandler (handle );
611
617
#if defined(STM32F0xx ) || defined(STM32L0xx )
612
618
HAL_I2C_ER_IRQHandler (handle );
@@ -621,7 +627,7 @@ void I2C2_EV_IRQHandler(void)
621
627
*/
622
628
void I2C2_ER_IRQHandler (void )
623
629
{
624
- I2C_HandleTypeDef * handle = i2c_handles [1 ];
630
+ I2C_HandleTypeDef * handle = i2c_handles [I2C2_INDEX ];
625
631
HAL_I2C_ER_IRQHandler (handle );
626
632
}
627
633
#endif // !defined(STM32F0xx) && !defined(STM32L0xx)
@@ -635,7 +641,7 @@ void I2C2_ER_IRQHandler(void)
635
641
*/
636
642
void I2C3_EV_IRQHandler (void )
637
643
{
638
- I2C_HandleTypeDef * handle = i2c_handles [2 ];
644
+ I2C_HandleTypeDef * handle = i2c_handles [I2C3_INDEX ];
639
645
HAL_I2C_EV_IRQHandler (handle );
640
646
#if defined(STM32F0xx ) || defined(STM32L0xx )
641
647
HAL_I2C_ER_IRQHandler (handle );
@@ -650,7 +656,7 @@ void I2C3_EV_IRQHandler(void)
650
656
*/
651
657
void I2C3_ER_IRQHandler (void )
652
658
{
653
- I2C_HandleTypeDef * handle = i2c_handles [2 ];
659
+ I2C_HandleTypeDef * handle = i2c_handles [I2C3_INDEX ];
654
660
HAL_I2C_ER_IRQHandler (handle );
655
661
}
656
662
#endif // !defined(STM32F0xx) && !defined(STM32L0xx)
@@ -664,7 +670,7 @@ void I2C3_ER_IRQHandler(void)
664
670
*/
665
671
void I2C4_EV_IRQHandler (void )
666
672
{
667
- I2C_HandleTypeDef * handle = i2c_handles [3 ];
673
+ I2C_HandleTypeDef * handle = i2c_handles [I2C4_INDEX ];
668
674
HAL_I2C_EV_IRQHandler (handle );
669
675
#if defined(STM32F0xx ) || defined(STM32L0xx )
670
676
HAL_I2C_ER_IRQHandler (handle );
@@ -679,7 +685,7 @@ void I2C4_EV_IRQHandler(void)
679
685
*/
680
686
void I2C4_ER_IRQHandler (void )
681
687
{
682
- I2C_HandleTypeDef * handle = i2c_handles [3 ];
688
+ I2C_HandleTypeDef * handle = i2c_handles [I2C4_INDEX ];
683
689
HAL_I2C_ER_IRQHandler (handle );
684
690
}
685
691
#endif // !defined(STM32F0xx) && !defined(STM32L0xx)
0 commit comments