/* Set I2C bus frequency. 
Please refer to the reference manual, details on I2C clock generation, for max allowed theoretical frequencies for different modes. */
void I2C_BusFreqSet(I2C_TypeDef *i2c, uint32_t refFreq, uint32_t freq, I2C_ClockHLR_TypeDef type)
/* Set I2C bus frequency. 
Please refer to the reference manual, details on I2C clock generation, for max allowed theoretical frequencies for different modes. */
void I2C_BusFreqSet(I2C_TypeDef *i2c, uint32_t refFreq, uint32_t freq, I2C_ClockHLR_TypeDef type)
{
  uint32_t n;
  uint32_t div;
  (void)type;
  EFM_ASSERT(freq);
  if (!freq)
  {
    return;
  }
  if (!refFreq)
  {
    refFreq = CMU_ClockFreqGet(cmuClock_HFPER);
  }
  n = (uint32_t)(i2cNSum[(i2c->CTRL & _I2C_CTRL_CLHR_MASK) >> _I2C_CTRL_CLHR_SHIFT]);
  div = (refFreq - (4 * freq)) / (n * freq);
  EFM_ASSERT(div);
  if (div)
  {
    div--;
  }
  if ((i2c->CTRL & I2C_CTRL_SLAVE) && !div)
  {
    div = 1;
  }
  EFM_ASSERT(div <= _I2C_CLKDIV_DIV_MASK);
  i2c->CLKDIV = div;
}