| NUC472_NUC442_BSP V3.04.000 The Board Support Package for NUC472/NUC442

i2c.h
Go to the documentation of this file.
1/****************************************************************************/
12#ifndef __I2C_H__
13#define __I2C_H__
14
15#ifdef __cplusplus
16extern "C"
17{
18#endif
19
20
33#define I2C_STA 0x20
34#define I2C_STO 0x10
35#define I2C_SI 0x08
36#define I2C_AA 0x04
38#define I2C_GCMODE_ENABLE 1
39#define I2C_GCMODE_DISABLE 0 /* end of group NUC472_442_I2C_EXPORTED_CONSTANTS */
42
43
55#define I2C_SET_CONTROL_REG(i2c, u8Ctrl) ( (i2c)->CTL = ((i2c)->CTL & ~0x3c) | u8Ctrl )
56
63#define I2C_START(i2c) ( (i2c)->CTL = ((i2c)->CTL & ~I2C_CTL_SI_Msk) | I2C_CTL_STA_Msk )
64
71#define I2C_STOP(i2c) ( (i2c)->CTL = ((i2c)->CTL & ~0x3c) | I2C_CTL_SI_Msk | I2C_CTL_STO_Msk )
72
79#define I2C_WAIT_READY(i2c) while(!((i2c)->CTL & I2C_CTL_SI_Msk))
80
87#define I2C_GET_DATA(i2c) ( (i2c)->DAT )
88
96#define I2C_SET_DATA(i2c, u8Data) ( (i2c)->DAT = u8Data )
97
104#define I2C_GET_STATUS(i2c) ( (i2c)->STATUS )
105
114#define I2C_GET_TIMEOUT_FLAG(i2c) ( ((i2c)->TOCTL & I2C_TOCTL_TOIF_Msk) == I2C_TOCTL_TOIF_Msk ? 1:0 )
115
124#define I2C_GET_WAKEUP_FLAG(i2c) ( ((i2c)->WKSTS & I2C_WKSTS_WKIF_Msk) == I2C_WKSTS_WKIF_Msk ? 1:0 )
125
131#define I2C_CLEAR_WAKEUP_FLAG(i2c) ((i2c)->WKSTS |= I2C_WKSTS_WKIF_Msk )
132
133
134uint32_t I2C_Open(I2C_T *i2c, uint32_t u32BusClock);
135void I2C_Close(I2C_T *i2c);
136void I2C_ClearTimeoutFlag(I2C_T *i2c);
137void I2C_Trigger(I2C_T *i2c, uint8_t u8Start, uint8_t u8Stop, uint8_t u8Si, uint8_t u8Ack);
138void I2C_DisableInt(I2C_T *i2c);
139void I2C_EnableInt(I2C_T *i2c);
140uint32_t I2C_GetBusClockFreq(I2C_T *i2c);
141uint32_t I2C_SetBusClockFreq(I2C_T *i2c, uint32_t u32BusClock);
142uint32_t I2C_GetIntFlag(I2C_T *i2c);
143uint32_t I2C_GetStatus(I2C_T *i2c);
144uint32_t I2C_GetData(I2C_T *i2c);
145void I2C_SetData(I2C_T *i2c, uint8_t u8Data);
146void I2C_SetSlaveAddr(I2C_T *i2c, uint8_t u8SlaveNo, uint8_t u8SlaveAddr, uint8_t u8GCMode);
147void I2C_SetSlaveAddrMask(I2C_T *i2c, uint8_t u8SlaveNo, uint8_t u8SlaveAddrMask);
148void I2C_EnableTimeout(I2C_T *i2c, uint8_t u8LongTimeout);
149void I2C_DisableTimeout(I2C_T *i2c);
150void I2C_EnableWakeup(I2C_T *i2c);
151void I2C_DisableWakeup(I2C_T *i2c);
152 /* end of group NUC472_442_I2C_EXPORTED_FUNCTIONS */
154 /* end of group NUC472_442_I2C_Driver */
156 /* end of group NUC472_442_Device_Driver */
158
159#ifdef __cplusplus
160}
161#endif
162
163#endif //__I2C_H__
164
165/*** (C) COPYRIGHT 2014 Nuvoton Technology Corp. ***/
I2C_SetSlaveAddrMask
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".
Definition: i2c.c:247
I2C_Close
void I2C_Close(I2C_T *i2c)
This function closes the I2C module.
Definition: i2c.c:53
I2C_SetBusClockFreq
uint32_t I2C_SetBusClockFreq(I2C_T *i2c, uint32_t u32BusClock)
This function sets bus frequency of I2C module.
Definition: i2c.c:155
I2C_Trigger
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.
Definition: i2c.c:100
I2C_EnableTimeout
void I2C_EnableTimeout(I2C_T *i2c, uint8_t u8LongTimeout)
This function enables timeout function and configures DIV4 function to support long timeout.
Definition: i2c.c:274
I2C_ClearTimeoutFlag
void I2C_ClearTimeoutFlag(I2C_T *i2c)
This function clears the time-out flag.
Definition: i2c.c:86
I2C_SetSlaveAddr
void I2C_SetSlaveAddr(I2C_T *i2c, uint8_t u8SlaveNo, uint8_t u8SlaveAddr, uint8_t u8GCMode)
Configure slave address and enable GC mode.
Definition: i2c.c:219
I2C_SetData
void I2C_SetData(I2C_T *i2c, uint8_t u8Data)
This function writes the data to data register of I2C module.
Definition: i2c.c:204
I2C_GetBusClockFreq
uint32_t I2C_GetBusClockFreq(I2C_T *i2c)
This function returns the real bus clock of I2C module.
Definition: i2c.c:142
I2C_EnableInt
void I2C_EnableInt(I2C_T *i2c)
This function enables the interrupt (EI bit) of I2C module.
Definition: i2c.c:132
I2C_DisableWakeup
void I2C_DisableWakeup(I2C_T *i2c)
This function disables the wakeup function of I2C module.
Definition: i2c.c:309
I2C_GetStatus
uint32_t I2C_GetStatus(I2C_T *i2c)
This function returns the status of I2C module.
Definition: i2c.c:183
I2C_DisableInt
void I2C_DisableInt(I2C_T *i2c)
This function disables the interrupt of I2C module.
Definition: i2c.c:122
I2C_GetData
uint32_t I2C_GetData(I2C_T *i2c)
This function returns the data stored in data register of I2C module.
Definition: i2c.c:193
I2C_EnableWakeup
void I2C_EnableWakeup(I2C_T *i2c)
This function enables the wakeup function of I2C module.
Definition: i2c.c:299
I2C_GetIntFlag
uint32_t I2C_GetIntFlag(I2C_T *i2c)
This function gets the interrupt flag of I2C module.
Definition: i2c.c:173
I2C_Open
uint32_t I2C_Open(I2C_T *i2c, uint32_t u32BusClock)
This function make I2C module be ready and set the wanted bus clock.
Definition: i2c.c:34
I2C_DisableTimeout
void I2C_DisableTimeout(I2C_T *i2c)
This function disables time-out function.
Definition: i2c.c:289
I2C_T
Definition: NUC472_442.h:16820