Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions drivers/i2c/fsl_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,12 +556,14 @@ static void I2C_TransferCommonIRQHandler(I2C_Type *base, void *handle)
* param base I2C base pointer
* param masterConfig A pointer to the master configuration structure
* param srcClock_Hz I2C peripheral clock frequency in Hz
* return the actual applied baudrate
*/
void I2C_MasterInit(I2C_Type *base, const i2c_master_config_t *masterConfig, uint32_t srcClock_Hz)
uint32_t I2C_MasterInit(I2C_Type *base, const i2c_master_config_t *masterConfig, uint32_t srcClock_Hz)
{
assert(NULL != masterConfig);
assert(0U != srcClock_Hz);

uint32_t baudrate;
/* Temporary register for filter read. */
uint8_t fltReg;
#if defined(FSL_FEATURE_I2C_HAS_DOUBLE_BUFFER_ENABLE) && FSL_FEATURE_I2C_HAS_DOUBLE_BUFFER_ENABLE
Expand Down Expand Up @@ -592,7 +594,7 @@ void I2C_MasterInit(I2C_Type *base, const i2c_master_config_t *masterConfig, uin
I2C_MasterClearStatusFlags(base, (uint32_t)kClearFlags);

/* Configure baud rate. */
I2C_MasterSetBaudRate(base, masterConfig->baudRate_Bps, srcClock_Hz);
baudrate = I2C_MasterSetBaudRate(base, masterConfig->baudRate_Bps, srcClock_Hz);

/* Read out the FLT register. */
fltReg = base->FLT;
Expand All @@ -618,6 +620,7 @@ void I2C_MasterInit(I2C_Type *base, const i2c_master_config_t *masterConfig, uin
s2Reg = (uint8_t)(base->S2 & (~I2C_S2_DFEN_MASK));
base->S2 = s2Reg | I2C_S2_DFEN(masterConfig->enableDoubleBuffering);
#endif
return baudrate;
}

/*!
Expand Down Expand Up @@ -764,8 +767,9 @@ void I2C_DisableInterrupts(I2C_Type *base, uint32_t mask)
* param base I2C base pointer
* param baudRate_Bps the baud rate value in bps
* param srcClock_Hz Source clock
* return the actual applied baudrate
*/
void I2C_MasterSetBaudRate(I2C_Type *base, uint32_t baudRate_Bps, uint32_t srcClock_Hz)
uint32_t I2C_MasterSetBaudRate(I2C_Type *base, uint32_t baudRate_Bps, uint32_t srcClock_Hz)
{
uint32_t multiplier;
uint32_t computedRate;
Expand Down Expand Up @@ -814,6 +818,8 @@ void I2C_MasterSetBaudRate(I2C_Type *base, uint32_t baudRate_Bps, uint32_t srcCl
#endif
/* Set frequency register based on best settings. */
base->F = I2C_F_MULT(bestMult) | I2C_F_ICR(bestIcr);

return computedRate;
}

/*!
Expand Down
6 changes: 4 additions & 2 deletions drivers/i2c/fsl_i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,9 @@ extern "C" {
* @param base I2C base pointer
* @param masterConfig A pointer to the master configuration structure
* @param srcClock_Hz I2C peripheral clock frequency in Hz
* @return the actual applied baudrate
*/
void I2C_MasterInit(I2C_Type *base, const i2c_master_config_t *masterConfig, uint32_t srcClock_Hz);
uint32_t I2C_MasterInit(I2C_Type *base, const i2c_master_config_t *masterConfig, uint32_t srcClock_Hz);

/*!
* @brief Initializes the I2C peripheral. Call this API to ungate the I2C clock
Expand Down Expand Up @@ -555,8 +556,9 @@ static inline uint32_t I2C_GetDataRegAddr(I2C_Type *base)
* @param base I2C base pointer
* @param baudRate_Bps the baud rate value in bps
* @param srcClock_Hz Source clock
* @return the actual applied baudrate
*/
void I2C_MasterSetBaudRate(I2C_Type *base, uint32_t baudRate_Bps, uint32_t srcClock_Hz);
uint32_t I2C_MasterSetBaudRate(I2C_Type *base, uint32_t baudRate_Bps, uint32_t srcClock_Hz);

/*!
* @brief Sends a START on the I2C bus.
Expand Down