Skip to content

Commit

Permalink
fix(i2c): prevent unused variable and functions
Browse files Browse the repository at this point in the history
when all I2C timings are defined

Signed-off-by: Frederic Pillon <[email protected]>
  • Loading branch information
fpistm committed Jan 16, 2024
1 parent 8f3eac4 commit 1863c25
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions libraries/Wire/src/utility/twi.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ extern "C" {
#if !defined (STM32F1xx) && !defined (STM32F2xx) && !defined (STM32F4xx) &&\
!defined (STM32L1xx)
#define I2C_TIMING
#if !defined(I2C_TIMING_SM) || !defined(I2C_TIMING_FM) || !defined(I2C_TIMING_FMP)
#define I2C_TIMING_COMPUTE
#endif /* !(I2C_TIMING_SM) || !(I2C_TIMING_FM) || !(I2C_TIMING_FMP)*/

#endif

#ifdef I2C_TIMING
#ifdef I2C_TIMING_COMPUTE
#ifndef I2C_VALID_TIMING_NBR
#define I2C_VALID_TIMING_NBR 8U
#endif
Expand Down Expand Up @@ -152,7 +156,7 @@ static const I2C_Charac_t I2C_Charac[] = {
.dnf = I2C_DIGITAL_FILTER_COEF,
}
};
#endif /* I2C_TIMING */
#endif /* I2C_TIMING_COMPUTE */

/* Family specific description for I2C */
typedef enum {
Expand Down Expand Up @@ -180,7 +184,7 @@ typedef enum {
/* Private Variables */
static I2C_HandleTypeDef *i2c_handles[I2C_NUM];

#ifdef I2C_TIMING
#ifdef I2C_TIMING_COMPUTE
/**
* @brief This function return the I2C clock source frequency.
* @param i2c: I2C instance
Expand Down Expand Up @@ -565,7 +569,7 @@ static uint32_t i2c_computeTiming(uint32_t clkSrcFreq, uint32_t i2c_speed)
}
return ret;
}
#endif /* I2C_TIMING */
#endif /* I2C_TIMING_COMPUTE */

/**
* @brief Compute I2C timing according current I2C clock source and
Expand All @@ -587,6 +591,9 @@ static uint32_t i2c_getTiming(i2c_t *obj, uint32_t frequency)
i2c_speed = 1000000;
}
#ifdef I2C_TIMING
#ifndef I2C_TIMING_COMPUTE
UNUSED(obj);
#endif
if (i2c_speed != 0U) {
switch (i2c_speed) {
default:
Expand Down

0 comments on commit 1863c25

Please sign in to comment.