Skip to content

Commit

Permalink
I2C: G0: add I2C3 support
Browse files Browse the repository at this point in the history
Signed-off-by: Frederic Pillon <[email protected]>
  • Loading branch information
fpistm committed May 21, 2021
1 parent a7099fe commit 54213f4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
25 changes: 22 additions & 3 deletions libraries/Wire/src/utility/twi.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ static uint32_t i2c_getClkFreq(I2C_TypeDef *i2c)
#endif // I2C2_BASE
#if defined I2C3_BASE
if (i2c == I2C3) {
#if defined(__HAL_RCC_GET_I2C3_SOURCE)
switch (__HAL_RCC_GET_I2C3_SOURCE()) {
case RCC_I2C3CLKSOURCE_HSI:
clkSrcFreq = HSI_VALUE;
Expand Down Expand Up @@ -307,6 +308,10 @@ static uint32_t i2c_getClkFreq(I2C_TypeDef *i2c)
default:
Error_Handler();
}
#else
/* STM32 G0 I2C3 has no independent clock */
clkSrcFreq = HAL_RCC_GetPCLK1Freq();
#endif
}
#endif // I2C3_BASE
#if defined I2C4_BASE
Expand Down Expand Up @@ -648,7 +653,7 @@ void i2c_custom_init(i2c_t *obj, uint32_t timing, uint32_t addressingMode, uint3
__HAL_RCC_I2C3_FORCE_RESET();
__HAL_RCC_I2C3_RELEASE_RESET();
obj->irq = I2C3_EV_IRQn;
#if !defined(STM32L0xx)
#if !defined(STM32G0xx) && !defined(STM32L0xx)
obj->irqER = I2C3_ER_IRQn;
#endif /* !STM32L0xx */
i2c_handles[I2C3_INDEX] = handle;
Expand Down Expand Up @@ -1138,11 +1143,25 @@ void I2C1_ER_IRQHandler(void)
*/
void I2C2_EV_IRQHandler(void)
{
#if defined(I2C3_BASE) && defined(STM32G0xx)
/* I2C2_3_IRQHandler */
I2C_HandleTypeDef *handle2 = i2c_handles[I2C2_INDEX];
I2C_HandleTypeDef *handle3 = i2c_handles[I2C3_INDEX];
if (handle2) {
HAL_I2C_EV_IRQHandler(handle2);
HAL_I2C_ER_IRQHandler(handle2);
}
if (handle3) {
HAL_I2C_EV_IRQHandler(handle3);
HAL_I2C_ER_IRQHandler(handle3);
}
#else
I2C_HandleTypeDef *handle = i2c_handles[I2C2_INDEX];
HAL_I2C_EV_IRQHandler(handle);
#if defined(STM32F0xx) || defined(STM32G0xx) || defined(STM32L0xx)
HAL_I2C_ER_IRQHandler(handle);
#endif /* STM32F0xx || STM32G0xx || STM32L0xx */
#endif
}

#if !defined(STM32F0xx) && !defined(STM32G0xx) && !defined(STM32L0xx)
Expand All @@ -1159,7 +1178,7 @@ void I2C2_ER_IRQHandler(void)
#endif /* !STM32F0xx && !STM32G0xx && !STM32L0xx */
#endif // I2C2_BASE

#if defined(I2C3_BASE)
#if defined(I2C3_BASE) && !defined(STM32G0xx)
/**
* @brief This function handles I2C3 interrupt.
* @param None
Expand All @@ -1186,7 +1205,7 @@ void I2C3_ER_IRQHandler(void)
HAL_I2C_ER_IRQHandler(handle);
}
#endif /* !STM32L0xx */
#endif // I2C3_BASE
#endif /* I2C3_BASE && ! STM32G0xx */

#if defined(I2C4_BASE)
/**
Expand Down
10 changes: 9 additions & 1 deletion libraries/Wire/src/utility/twi.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,21 @@ extern "C" {
#define I2C1_EV_IRQHandler I2C1_IRQHandler
#endif // defined(I2C1_BASE)
#if defined(I2C2_BASE)
#if defined(STM32G0xx) && defined(I2C3_BASE)
#define I2C2_EV_IRQn I2C2_3_IRQn
#define I2C2_EV_IRQHandler I2C2_3_IRQHandler
#else
#define I2C2_EV_IRQn I2C2_IRQn
#define I2C2_EV_IRQHandler I2C2_IRQHandler
#endif
#endif // defined(I2C2_BASE)
/* Only for STM32L0xx */
#if defined(I2C3_BASE)
#if defined(STM32G0xx)
#define I2C3_EV_IRQn I2C2_3_IRQn
#else
#define I2C3_EV_IRQn I2C3_IRQn
#define I2C3_EV_IRQHandler I2C3_IRQHandler
#endif
#endif // defined(I2C3_BASE)
/* Defined but no one has it */
#if defined(I2C4_BASE)
Expand Down

0 comments on commit 54213f4

Please sign in to comment.