![]() |
M471M/R1/S BSP V3.01.000
The Board Support Package for M4521
|
Macros | |
#define | I2C_SET_CONTROL_REG(i2c, u8Ctrl) ((i2c)->CTL = ((i2c)->CTL & ~0x3c) | (u8Ctrl)) |
The macro is used to set I2C bus condition at One Time. More... | |
#define | I2C_START(i2c) ((i2c)->CTL = ((i2c)->CTL & ~I2C_CTL_SI_Msk) | I2C_CTL_STA_Msk) |
The macro is used to set START condition of I2C Bus. More... | |
#define | I2C_WAIT_READY(i2c) while(!((i2c)->CTL & I2C_CTL_SI_Msk)) |
The macro is used to wait I2C bus status get ready. More... | |
#define | I2C_GET_DATA(i2c) ((i2c)->DAT) |
The macro is used to Read I2C Bus Data Register. More... | |
#define | I2C_SET_DATA(i2c, u8Data) ((i2c)->DAT = (u8Data)) |
Write a Data to I2C Data Register. More... | |
#define | I2C_GET_STATUS(i2c) ((i2c)->STATUS) |
Get I2C Bus status code. More... | |
#define | I2C_GET_TIMEOUT_FLAG(i2c) ( ((i2c)->TOCTL & I2C_TOCTL_TOIF_Msk) == I2C_TOCTL_TOIF_Msk ? 1:0 ) |
Get Time-out flag from I2C Bus. More... | |
#define | I2C_GET_WAKEUP_FLAG(i2c) ( ((i2c)->WKSTS & I2C_WKSTS_WKIF_Msk) == I2C_WKSTS_WKIF_Msk ? 1:0 ) |
To get wake-up flag from I2C Bus. More... | |
#define | I2C_CLEAR_WAKEUP_FLAG(i2c) ((i2c)->WKSTS = I2C_WKSTS_WKIF_Msk) |
To clear wake-up flag. More... | |
#define | I2C_SMBUS_GET_STATUS(i2c) ((i2c)->BUSSTS) |
To get SMBus Status. More... | |
#define | I2C_SMBUS_GET_PEC_VALUE(i2c) ((i2c)->PKTCRC) |
Get SMBus CRC value. More... | |
#define | I2C_SMBUS_SET_PACKET_BYTE_COUNT(i2c, u32PktSize) ((i2c)->PKTSIZE = (u32PktSize)) |
Set SMBus Bytes number of Transmission or reception. More... | |
#define | I2C_SMBUS_ENABLE_ALERT(i2c) ((i2c)->BUSCTL |= I2C_BUSCTL_ALERTEN_Msk) |
Enable SMBus Alert function. More... | |
#define | I2C_SMBUS_DISABLE_ALERT(i2c) ((i2c)->BUSCTL &= ~I2C_BUSCTL_ALERTEN_Msk) |
Disable SMBus Alert pin function. More... | |
#define | I2C_SMBUS_SET_SUSCON_OUT(i2c) ((i2c)->BUSCTL |= I2C_BUSCTL_SCTLOEN_Msk) |
Set SMBus SUSCON pin is output mode. More... | |
#define | I2C_SMBUS_SET_SUSCON_IN(i2c) ((i2c)->BUSCTL &= ~I2C_BUSCTL_SCTLOEN_Msk) |
Set SMBus SUSCON pin is input mode. More... | |
#define | I2C_SMBUS_SET_SUSCON_HIGH(i2c) ((i2c)->BUSCTL |= I2C_BUSCTL_SCTLOSTS_Msk) |
Set SMBus SUSCON pin output high state. More... | |
#define | I2C_SMBUS_SET_SUSCON_LOW(i2c) ((i2c)->BUSCTL &= ~I2C_BUSCTL_SCTLOSTS_Msk) |
Set SMBus SUSCON pin output low state. More... | |
#define | I2C_SMBUS_ACK_MANUAL(i2c) ((i2c)->BUSCTL |= I2C_BUSCTL_ACKMEN_Msk) |
Enable SMBus Acknowledge control by manual. More... | |
#define | I2C_SMBUS_ACK_AUTO(i2c) ((i2c)->BUSCTL &= ~I2C_BUSCTL_ACKMEN_Msk) |
Disable SMBus Acknowledge control by manual. More... | |
#define | I2C_SMBUS_9THBIT_INT_ENABLE(i2c) ((i2c)->BUSCTL |= I2C_BUSCTL_ACKM9SI_Msk) |
Enable SMBus Acknowledge manual interrupt. More... | |
#define | I2C_SMBUS_9THBIT_INT_DISABLE(i2c) ((i2c)->BUSCTL &= ~I2C_BUSCTL_ACKM9SI_Msk) |
Disable SMBus Acknowledge manual interrupt. More... | |
#define | I2C_SMBUS_RST_PEC_AT_START_ENABLE(i2c) ((i2c)->BUSCTL |= I2C_BUSCTL_PECCLR_Msk) |
Enable SMBus PEC clear at REPEAT START. More... | |
#define | I2C_SMBUS_RST_PEC_AT_START_DISABLE(i2c) ((i2c)->BUSCTL &= ~I2C_BUSCTL_PECCLR_Msk) |
Disable SMBus PEC clear at Repeat START. More... | |
Functions | |
static __INLINE int32_t | I2C_STOP (I2C_T *i2c) |
The macro is used to set STOP condition of I2C Bus. More... | |
void | I2C_ClearTimeoutFlag (I2C_T *i2c) |
Clear Time-out Counter flag. More... | |
void | I2C_Close (I2C_T *i2c) |
Disable specify I2C Controller. More... | |
void | I2C_Trigger (I2C_T *i2c, uint8_t u8Start, uint8_t u8Stop, uint8_t u8Si, uint8_t u8Ack) |
Set Control bit of I2C Controller. More... | |
void | I2C_DisableInt (I2C_T *i2c) |
Disable Interrupt of I2C Controller. More... | |
void | I2C_EnableInt (I2C_T *i2c) |
Enable Interrupt of I2C Controller. More... | |
uint32_t | I2C_GetBusClockFreq (I2C_T *i2c) |
Get I2C Bus Clock. More... | |
uint32_t | I2C_GetIntFlag (I2C_T *i2c) |
Get Interrupt Flag. More... | |
uint32_t | I2C_GetStatus (I2C_T *i2c) |
Get I2C Bus Status Code. More... | |
uint32_t | I2C_Open (I2C_T *i2c, uint32_t u32BusClock) |
Enable specify I2C Controller and set Clock Divider. More... | |
uint8_t | I2C_GetData (I2C_T *i2c) |
Read a Byte from I2C Bus. More... | |
void | I2C_SetSlaveAddr (I2C_T *i2c, uint8_t u8SlaveNo, uint8_t u8SlaveAddr, uint8_t u8GCMode) |
Set 7-bit Slave Address and GC Mode. More... | |
void | I2C_SetSlaveAddrMask (I2C_T *i2c, uint8_t u8SlaveNo, uint8_t u8SlaveAddrMask) |
Configure the mask bits of 7-bit Slave Address. More... | |
uint32_t | I2C_SetBusClockFreq (I2C_T *i2c, uint32_t u32BusClock) |
Set I2C Bus Clock. More... | |
void | I2C_EnableTimeout (I2C_T *i2c, uint8_t u8LongTimeout) |
Enable Time-out Counter Function and support Long Time-out. More... | |
void | I2C_DisableTimeout (I2C_T *i2c) |
Disable Time-out Counter Function. More... | |
void | I2C_EnableWakeup (I2C_T *i2c) |
Enable I2C Wake-up Function. More... | |
void | I2C_DisableWakeup (I2C_T *i2c) |
Disable I2C Wake-up Function. More... | |
void | I2C_SetData (I2C_T *i2c, uint8_t u8Data) |
Send a byte to I2C Bus. More... | |
uint32_t | I2C_SMBusGetStatus (I2C_T *i2c) |
To get SMBus Status. More... | |
void | I2C_SMBusClearInterruptFlag (I2C_T *i2c, uint8_t u8SMBusIntFlag) |
Clear SMBus Interrupt Flag. More... | |
void | I2C_SMBusSetPacketByteCount (I2C_T *i2c, uint32_t u32PktSize) |
Set SMBus Bytes Counts of Transmission or Reception. More... | |
void | I2C_SMBusOpen (I2C_T *i2c, uint8_t u8HostDevice) |
Init SMBus Host/Device Mode. More... | |
void | I2C_SMBusClose (I2C_T *i2c) |
Disable SMBus function. More... | |
void | I2C_SMBusPECTxEnable (I2C_T *i2c, uint8_t u8PECTxEn) |
Enable SMBus PEC Transmit Function. More... | |
uint8_t | I2C_SMBusGetPECValue (I2C_T *i2c) |
Get SMBus CRC value. More... | |
void | I2C_SMBusIdleTimeout (I2C_T *i2c, uint32_t us, uint32_t u32Hclk) |
Calculate Time-out of SMBus idle period. More... | |
void | I2C_SMBusTimeout (I2C_T *i2c, uint32_t ms, uint32_t u32Pclk) |
Calculate Time-out of SMBus active period. More... | |
void | I2C_SMBusClockLoTimeout (I2C_T *i2c, uint32_t ms, uint32_t u32Pclk) |
Calculate Cumulative Clock low Time-out of SMBus active period. More... | |
#define I2C_CLEAR_WAKEUP_FLAG | ( | i2c | ) | ((i2c)->WKSTS = I2C_WKSTS_WKIF_Msk) |
#define I2C_GET_DATA | ( | i2c | ) | ((i2c)->DAT) |
#define I2C_GET_STATUS | ( | i2c | ) | ((i2c)->STATUS) |
#define I2C_GET_TIMEOUT_FLAG | ( | i2c | ) | ( ((i2c)->TOCTL & I2C_TOCTL_TOIF_Msk) == I2C_TOCTL_TOIF_Msk ? 1:0 ) |
#define I2C_GET_WAKEUP_FLAG | ( | i2c | ) | ( ((i2c)->WKSTS & I2C_WKSTS_WKIF_Msk) == I2C_WKSTS_WKIF_Msk ? 1:0 ) |
#define I2C_SET_CONTROL_REG | ( | i2c, | |
u8Ctrl | |||
) | ((i2c)->CTL = ((i2c)->CTL & ~0x3c) | (u8Ctrl)) |
#define I2C_SET_DATA | ( | i2c, | |
u8Data | |||
) | ((i2c)->DAT = (u8Data)) |
#define I2C_SMBUS_9THBIT_INT_DISABLE | ( | i2c | ) | ((i2c)->BUSCTL &= ~I2C_BUSCTL_ACKM9SI_Msk) |
#define I2C_SMBUS_9THBIT_INT_ENABLE | ( | i2c | ) | ((i2c)->BUSCTL |= I2C_BUSCTL_ACKM9SI_Msk) |
#define I2C_SMBUS_ACK_AUTO | ( | i2c | ) | ((i2c)->BUSCTL &= ~I2C_BUSCTL_ACKMEN_Msk) |
#define I2C_SMBUS_ACK_MANUAL | ( | i2c | ) | ((i2c)->BUSCTL |= I2C_BUSCTL_ACKMEN_Msk) |
#define I2C_SMBUS_DISABLE_ALERT | ( | i2c | ) | ((i2c)->BUSCTL &= ~I2C_BUSCTL_ALERTEN_Msk) |
Disable SMBus Alert pin function.
[in] | i2c | Specify I2C port |
Device Mode(BMHEN=0): If ALERTEN(I2C_BUSCTL[4]) is clear, the Alert pin will pull hi, and reply NACK when get ARP from host Host Mode(BMHEN=1): If ALERTEN(I2C_BUSCTL[4]) is clear, the Alert pin is not supported to receive alert state(Lo trigger)
#define I2C_SMBUS_ENABLE_ALERT | ( | i2c | ) | ((i2c)->BUSCTL |= I2C_BUSCTL_ALERTEN_Msk) |
Enable SMBus Alert function.
[in] | i2c | Specify I2C port |
Device Mode(BMHEN=0): If ALERTEN(I2C_BUSCTL[4]) is set, the Alert pin will pull lo, and reply ACK when get ARP from host Host Mode(BMHEN=1): If ALERTEN(I2C_BUSCTL[4]) is set, the Alert pin is supported to receive alert state(Lo trigger)
#define I2C_SMBUS_GET_PEC_VALUE | ( | i2c | ) | ((i2c)->PKTCRC) |
#define I2C_SMBUS_GET_STATUS | ( | i2c | ) | ((i2c)->BUSSTS) |
#define I2C_SMBUS_RST_PEC_AT_START_DISABLE | ( | i2c | ) | ((i2c)->BUSCTL &= ~I2C_BUSCTL_PECCLR_Msk) |
#define I2C_SMBUS_RST_PEC_AT_START_ENABLE | ( | i2c | ) | ((i2c)->BUSCTL |= I2C_BUSCTL_PECCLR_Msk) |
#define I2C_SMBUS_SET_PACKET_BYTE_COUNT | ( | i2c, | |
u32PktSize | |||
) | ((i2c)->PKTSIZE = (u32PktSize)) |
#define I2C_SMBUS_SET_SUSCON_HIGH | ( | i2c | ) | ((i2c)->BUSCTL |= I2C_BUSCTL_SCTLOSTS_Msk) |
#define I2C_SMBUS_SET_SUSCON_IN | ( | i2c | ) | ((i2c)->BUSCTL &= ~I2C_BUSCTL_SCTLOEN_Msk) |
#define I2C_SMBUS_SET_SUSCON_LOW | ( | i2c | ) | ((i2c)->BUSCTL &= ~I2C_BUSCTL_SCTLOSTS_Msk) |
#define I2C_SMBUS_SET_SUSCON_OUT | ( | i2c | ) | ((i2c)->BUSCTL |= I2C_BUSCTL_SCTLOEN_Msk) |
#define I2C_START | ( | i2c | ) | ((i2c)->CTL = ((i2c)->CTL & ~I2C_CTL_SI_Msk) | I2C_CTL_STA_Msk) |
#define I2C_WAIT_READY | ( | i2c | ) | while(!((i2c)->CTL & I2C_CTL_SI_Msk)) |
void I2C_ClearTimeoutFlag | ( | I2C_T * | i2c | ) |
void I2C_Close | ( | I2C_T * | i2c | ) |
void I2C_DisableInt | ( | I2C_T * | i2c | ) |
void I2C_DisableTimeout | ( | I2C_T * | i2c | ) |
void I2C_DisableWakeup | ( | I2C_T * | i2c | ) |
void I2C_EnableInt | ( | I2C_T * | i2c | ) |
void I2C_EnableTimeout | ( | I2C_T * | i2c, |
uint8_t | u8LongTimeout | ||
) |
void I2C_EnableWakeup | ( | I2C_T * | i2c | ) |
uint32_t I2C_GetBusClockFreq | ( | I2C_T * | i2c | ) |
uint8_t I2C_GetData | ( | I2C_T * | i2c | ) |
uint32_t I2C_GetIntFlag | ( | I2C_T * | i2c | ) |
uint32_t I2C_GetStatus | ( | I2C_T * | i2c | ) |
uint32_t I2C_Open | ( | I2C_T * | i2c, |
uint32_t | u32BusClock | ||
) |
Enable specify I2C Controller and set Clock Divider.
[in] | i2c | Specify I2C port |
[in] | u32BusClock | The target I2C bus clock in Hz |
The function enable the specify I2C Controller and set proper Clock Divider in I2C CLOCK DIVIDED REGISTER (I2CLK) according to the target I2C Bus clock. I2C Bus clock = PCLK / (4*(divider+1).
uint32_t I2C_SetBusClockFreq | ( | I2C_T * | i2c, |
uint32_t | u32BusClock | ||
) |
void I2C_SetData | ( | I2C_T * | i2c, |
uint8_t | u8Data | ||
) |
void I2C_SetSlaveAddr | ( | I2C_T * | i2c, |
uint8_t | u8SlaveNo, | ||
uint8_t | u8SlaveAddr, | ||
uint8_t | u8GCMode | ||
) |
Set 7-bit Slave Address and GC Mode.
[in] | i2c | Specify I2C port |
[in] | u8SlaveNo | Set the number of I2C address register (0~3) |
[in] | u8SlaveAddr | 7-bit slave address |
[in] | u8GCMode | Enable/Disable GC mode (I2C_GCMODE_ENABLE / I2C_GCMODE_DISABLE) |
This function is used to set 7-bit slave addresses in I2C SLAVE ADDRESS REGISTER (I2CADDR0~3) and enable GC Mode.
void I2C_SetSlaveAddrMask | ( | I2C_T * | i2c, |
uint8_t | u8SlaveNo, | ||
uint8_t | u8SlaveAddrMask | ||
) |
void I2C_SMBusClearInterruptFlag | ( | I2C_T * | i2c, |
uint8_t | u8SMBusIntFlag | ||
) |
void I2C_SMBusClockLoTimeout | ( | I2C_T * | i2c, |
uint32_t | ms, | ||
uint32_t | u32Pclk | ||
) |
Calculate Cumulative Clock low Time-out of SMBus active period.
[in] | i2c | Specify I2C port |
[in] | ms | Time-out length(ms) |
[in] | u32Pclk | peripheral clock frequency |
This function is used to set SMBus Time-out length when bus is in Active state. Time-out length is calculate the SCL line "clocks" low cumulative timing.
void I2C_SMBusClose | ( | I2C_T * | i2c | ) |
uint8_t I2C_SMBusGetPECValue | ( | I2C_T * | i2c | ) |
uint32_t I2C_SMBusGetStatus | ( | I2C_T * | i2c | ) |
void I2C_SMBusIdleTimeout | ( | I2C_T * | i2c, |
uint32_t | us, | ||
uint32_t | u32Hclk | ||
) |
void I2C_SMBusOpen | ( | I2C_T * | i2c, |
uint8_t | u8HostDevice | ||
) |
Init SMBus Host/Device Mode.
[in] | i2c | Specify I2C port |
[in] | u8HostDevice | Init SMBus port mode(I2C_SMBH_ENABLE(1)/I2C_SMBD_ENABLE(0)) |
Using SMBus communication must specify the port is a Host or a Device.
void I2C_SMBusPECTxEnable | ( | I2C_T * | i2c, |
uint8_t | u8PECTxEn | ||
) |
void I2C_SMBusSetPacketByteCount | ( | I2C_T * | i2c, |
uint32_t | u32PktSize | ||
) |
void I2C_SMBusTimeout | ( | I2C_T * | i2c, |
uint32_t | ms, | ||
uint32_t | u32Pclk | ||
) |
Calculate Time-out of SMBus active period.
[in] | i2c | Specify I2C port |
[in] | ms | Time-out length(ms) |
[in] | u32Pclk | peripheral clock frequency |
This function is used to set SMBus Time-out length when bus is in active state. Time-out length is calculate the SCL line "one clock" pull low timing.
|
static |
void I2C_Trigger | ( | I2C_T * | i2c, |
uint8_t | u8Start, | ||
uint8_t | u8Stop, | ||
uint8_t | u8Si, | ||
uint8_t | u8Ack | ||
) |