38 #define I2C_GCMODE_ENABLE 1 39 #define I2C_GCMODE_DISABLE 0 55 #define I2C_SET_CONTROL_REG(i2c, u8Ctrl) ( (i2c)->CON = ((i2c)->CON & ~0x1e) | u8Ctrl ) 63 #define I2C_START(i2c) ( (i2c)->CON = ((i2c)->CON & ~I2C_CON_I2C_STS_Msk) | I2C_CON_START_Msk ) 71 #define I2C_STOP(i2c) \ 73 (i2c)->CON |= (I2C_CON_I2C_STS_Msk | I2C_CON_STOP_Msk); \ 74 while((i2c)->CON & I2C_CON_STOP_Msk); \ 83 #define I2C_WAIT_READY(i2c) \ 85 while(!((i2c)->INTSTS & I2C_INTSTS_INTSTS_Msk)); \ 86 (i2c)->INTSTS |= I2C_INTSTS_INTSTS_Msk; \ 95 #define I2C_GET_DATA(i2c) ((i2c)->DATA ) 104 #define I2C_SET_DATA(i2c, u8Data) ( (i2c)->DATA = u8Data ) 112 #define I2C_GET_STATUS(i2c) ( (i2c)->STATUS ) 122 #define I2C_GET_TIMEOUT_FLAG(i2c) ( ((i2c)->INTSTS & I2C_INTSTS_TIF_Msk) == I2C_INTSTS_TIF_Msk ? 1:0 ) 130 #define I2C_CLEAR_TIMEOUT_FLAG(i2c) ( (i2c)->INTSTS |= I2C_INTSTS_TIF_Msk ) 140 #define I2C_GET_WAKEUP_FLAG(i2c) ( ((i2c)->STATUS2 & I2C_STATUS2_WKUPIF_Msk) == I2C_STATUS2_WKUPIF_Msk ? 1:0 ) 150 #define I2C_GET_WAKEUP_ACK_DONE_FLAG(i2c) ( ((i2c)->INTSTS & I2C_INTSTS_WAKEUP_ACK_DONE_Msk) == I2C_INTSTS_WAKEUP_ACK_DONE_Msk ? 1:0 ) 158 #define I2C_CLEAR_WAKEUP_FLAG(i2c) ( (i2c)->STATUS2 |= I2C_STATUS2_WKUPIF_Msk ) 167 #define I2C_CLEAR_WAKEUP_ACK_DONE_FLAG(i2c) ( (i2c)->INTSTS |= I2C_INTSTS_WAKEUP_ACK_DONE_Msk ) 175 #define I2C_DISABLE_FIFO(i2c) ( (i2c)->CON2 &= ~I2C_CON2_TWOFF_EN_Msk ) 183 #define I2C_ENABLE_FIFO(i2c) ( (i2c)->CON2 |= I2C_CON2_TWOFF_EN_Msk ) 191 #define I2C_DISABLE_CLOCK_STRETCH(i2c) ( (i2c)->CON2 |= I2C_CON2_NOSTRETCH_Msk ) 199 #define I2C_ENABLE_CLOCK_STRETCH(i2c) ( (i2c)->CON2 &= ~I2C_CON2_NOSTRETCH_Msk ) 207 #define I2C_DISABLE_OVERRUN_INT(i2c) ( (i2c)->CON2 &= ~I2C_CON2_OVER_INTEN_Msk ) 215 #define I2C_ENABLE_OVERRUN_INT(i2c) ( (i2c)->CON2 |= I2C_CON2_OVER_INTEN_Msk ) 223 #define I2C_ENABLE_UNDERRUN_INT(i2c) ( (i2c)->CON2 |= I2C_CON2_UNDER_INTEN_Msk ) 231 #define I2C_DISABLE_UNDERRUN_INT(i2c) ((i2c)->CON2 &= ~I2C_CON2_UNDER_INTEN_Msk ) 241 #define I2C_GET_BUS_FREE_FLAG(i2c) ( ((i2c)->STATUS2 & I2C_STATUS2_BUS_FREE_Msk) == I2C_STATUS2_BUS_FREE_Msk ? 1:0 ) 252 #define I2C_GET_WAKEUP_RW_FLAG(i2c) ( ((i2c)->STATUS2 & I2C_STATUS2_WR_STATUS_Msk) == I2C_STATUS2_WR_STATUS_Msk ? 1:0 ) 257 void I2C_Trigger(
I2C_T *i2c, uint8_t u8Start, uint8_t u8Stop, uint8_t u8Si, uint8_t u8Ack);
void I2C_EnableWakeup(I2C_T *i2c)
This function enables the wakeup function of I2C module.
void I2C_SetData(I2C_T *i2c, uint8_t u8Data)
This function writes the data to data register of I2C module.
void I2C_ClearIntFlag(I2C_T *i2c)
This function clears the interrupt flag of I2C module.
uint32_t I2C_GetIntFlag(I2C_T *i2c)
This function gets the interrupt flag of I2C module.
void I2C_DisableInt(I2C_T *i2c)
This function disables the interrupt of I2C module.
void I2C_DisableWakeup(I2C_T *i2c)
This function disables the wakeup function of I2C module.
uint32_t I2C_GetData(I2C_T *i2c)
This function returns the data stored in data register of I2C module.
void I2C_SetSlaveAddrMask(I2C_T *i2c, uint8_t u8SlaveNo, uint8_t u8SlaveAddrMask)
Configure the mask of slave address. The corresponding address bit is "Don't Care".
void I2C_Close(I2C_T *i2c)
This function closes the I2C module.
void I2C_EnableInt(I2C_T *i2c)
This function enables the interrupt (EI bit) of I2C module.
uint32_t I2C_SetBusClockFreq(I2C_T *i2c, uint32_t u32BusClock)
This function sets bus frequency of I2C module.
void I2C_DisableTimeout(I2C_T *i2c)
This function disables timeout function.
uint32_t I2C_GetBusClockFreq(I2C_T *i2c)
This function returns the real bus clock of I2C module.
void I2C_ClearTimeoutFlag(I2C_T *i2c)
This function clears the timeout flag.
void I2C_Trigger(I2C_T *i2c, uint8_t u8Start, uint8_t u8Stop, uint8_t u8Si, uint8_t u8Ack)
This function sets the control bit of the I2C module.
uint32_t I2C_Open(I2C_T *i2c, uint32_t u32BusClock)
This function make I2C module be ready and set the wanted bus clock.
uint32_t I2C_GetStatus(I2C_T *i2c)
This function returns the status of I2C module.
void I2C_EnableTimeout(I2C_T *i2c, uint8_t u8LongTimeout)
This function enables timeout function and configures DIV4 function to support long timeout.
void I2C_SetSlaveAddr(I2C_T *i2c, uint8_t u8SlaveNo, uint8_t u8SlaveAddr, uint8_t u8GCMode)
Configure slave address and enable GC mode.