Nano100AN Series BSP  V3.02.002
The Board Support Package for Nano100AN Series
i2c.h
Go to the documentation of this file.
1 /****************************************************************************/
12 #ifndef __I2C_H__
13 #define __I2C_H__
14 
15 #ifdef __cplusplus
16 extern "C"
17 {
18 #endif
19 
20 
33 #define I2C_STA 0x08
34 #define I2C_STO 0x04
35 #define I2C_SI 0x10
36 #define I2C_AA 0x02
38 #define I2C_GCMODE_ENABLE 1
39 #define I2C_GCMODE_DISABLE 0
41  /* end of group NANO100_I2C_EXPORTED_CONSTANTS */
42 
43 
55 #define I2C_SET_CONTROL_REG(i2c, u8Ctrl) ( (i2c)->CON = ((i2c)->CON & ~0x1e) | u8Ctrl )
56 
63 #define I2C_START(i2c) ( (i2c)->CON = ((i2c)->CON & ~I2C_CON_I2C_STS_Msk) | I2C_CON_START_Msk )
64 
71 static __INLINE void I2C_STOP(I2C_T *i2c)
72 {
74  while(i2c->CON & I2C_CON_STOP_Msk);
75 }
76 
83 static __INLINE void I2C_WAIT_READY(I2C_T *i2c)
84 {
85  while(!(i2c->INTSTS & I2C_INTSTS_INTSTS_Msk));
87 }
88 
95 #define I2C_GET_DATA(i2c) ( (i2c)->DATA )
96 
104 #define I2C_SET_DATA(i2c, u8Data) ( (i2c)->DATA = u8Data )
105 
112 #define I2C_GET_STATUS(i2c) ( (i2c)->STATUS )
113 
122 #define I2C_GET_TIMEOUT_FLAG(i2c) ( ((i2c)->INTSTS & I2C_INTSTS_TIF_Msk) == I2C_INTSTS_TIF_Msk ? 1:0 )
123 
130 #define I2C_CLEAR_TIMEOUT_FLAG(i2c) ( (i2c)->INTSTS |= I2C_INTSTS_TIF_Msk )
131 
132 uint32_t I2C_Open(I2C_T *i2c, uint32_t u32BusClock);
133 void I2C_Close(I2C_T *i2c);
134 void I2C_ClearTimeoutFlag(I2C_T *i2c);
135 void I2C_Trigger(I2C_T *i2c, uint8_t u8Start, uint8_t u8Stop, uint8_t u8Si, uint8_t u8Ack);
136 void I2C_DisableInt(I2C_T *i2c);
137 void I2C_EnableInt(I2C_T *i2c);
138 uint32_t I2C_GetBusClockFreq(I2C_T *i2c);
139 uint32_t I2C_SetBusClockFreq(I2C_T *i2c, uint32_t u32BusClock);
140 uint32_t I2C_GetIntFlag(I2C_T *i2c);
141 void I2C_ClearIntFlag(I2C_T *i2c);
142 uint32_t I2C_GetStatus(I2C_T *i2c);
143 uint32_t I2C_GetData(I2C_T *i2c);
144 void I2C_SetData(I2C_T *i2c, uint8_t u8Data);
145 void I2C_SetSlaveAddr(I2C_T *i2c, uint8_t u8SlaveNo, uint8_t u8SlaveAddr, uint8_t u8GCMode);
146 void I2C_SetSlaveAddrMask(I2C_T *i2c, uint8_t u8SlaveNo, uint8_t u8SlaveAddrMask);
147 void I2C_EnableTimeout(I2C_T *i2c, uint8_t u8LongTimeout);
148 void I2C_DisableTimeout(I2C_T *i2c);
149 void I2C_EnableWakeup(I2C_T *i2c);
150 void I2C_DisableWakeup(I2C_T *i2c);
151  /* end of group NANO100_I2C_EXPORTED_FUNCTIONS */
153  /* end of group NANO100_I2C_Driver */
155  /* end of group NANO100_Device_Driver */
157 
158 #ifdef __cplusplus
159 }
160 #endif
161 
162 #endif //__I2C_H__
163 
164 /*** (C) COPYRIGHT 2014 Nuvoton Technology Corp. ***/
uint32_t I2C_SetBusClockFreq(I2C_T *i2c, uint32_t u32BusClock)
This function sets bus frequency of I2C module.
Definition: i2c.c:144
void I2C_ClearTimeoutFlag(I2C_T *i2c)
This function clears the timeout flag.
Definition: i2c.c:75
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
void I2C_EnableInt(I2C_T *i2c)
This function enables the interrupt (EI bit) of I2C module.
Definition: i2c.c:121
#define I2C_INTSTS_INTSTS_Msk
#define I2C_CON_I2C_STS_Msk
void I2C_Close(I2C_T *i2c)
This function closes the I2C module.
Definition: i2c.c:52
void I2C_DisableTimeout(I2C_T *i2c)
This function disables timeout function.
Definition: i2c.c:271
uint32_t I2C_GetStatus(I2C_T *i2c)
This function returns the status of I2C module.
Definition: i2c.c:181
void I2C_SetData(I2C_T *i2c, uint8_t u8Data)
This function writes the data to data register of I2C module.
Definition: i2c.c:202
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:237
static __INLINE void I2C_STOP(I2C_T *i2c)
This macro only set STOP bit to the control register of I2C module.
Definition: i2c.h:71
uint32_t I2C_GetData(I2C_T *i2c)
This function returns the data stored in data register of I2C module.
Definition: i2c.c:191
__IO uint32_t INTSTS
uint32_t I2C_GetIntFlag(I2C_T *i2c)
This function gets the interrupt flag of I2C module.
Definition: i2c.c:161
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:89
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:217
void I2C_DisableWakeup(I2C_T *i2c)
static __INLINE void I2C_WAIT_READY(I2C_T *i2c)
This macro will return when I2C module is ready.
Definition: i2c.h:83
void I2C_ClearIntFlag(I2C_T *i2c)
This function clears the interrupt flag of I2C module.
Definition: i2c.c:171
#define I2C_CON_STOP_Msk
void I2C_DisableInt(I2C_T *i2c)
This function disables the interrupt of I2C module.
Definition: i2c.c:111
void I2C_EnableWakeup(I2C_T *i2c)
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:256
uint32_t I2C_GetBusClockFreq(I2C_T *i2c)
This function returns the real bus clock of I2C module.
Definition: i2c.c:131
__IO uint32_t CON