Mouse code for the MacroRat
mbed-dev/targets/TARGET_NUVOTON/TARGET_NUC472/device/StdDriver/nuc472_i2c.c@18:6a4db94011d3, 2017-05-14 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sun May 14 23:18:57 2017 +0000
- Revision:
- 18:6a4db94011d3
Publishing again
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /****************************************************************************//** |
sahilmgandhi | 18:6a4db94011d3 | 2 | * @file i2c.c |
sahilmgandhi | 18:6a4db94011d3 | 3 | * @version V0.10 |
sahilmgandhi | 18:6a4db94011d3 | 4 | * $Revision: 13 $ |
sahilmgandhi | 18:6a4db94011d3 | 5 | * $Date: 14/09/30 1:10p $ |
sahilmgandhi | 18:6a4db94011d3 | 6 | * @brief NUC472/NUC442 I2C driver source file |
sahilmgandhi | 18:6a4db94011d3 | 7 | * |
sahilmgandhi | 18:6a4db94011d3 | 8 | * @note |
sahilmgandhi | 18:6a4db94011d3 | 9 | * Copyright (C) 2014 Nuvoton Technology Corp. All rights reserved. |
sahilmgandhi | 18:6a4db94011d3 | 10 | *****************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 11 | |
sahilmgandhi | 18:6a4db94011d3 | 12 | #include "NUC472_442.h" |
sahilmgandhi | 18:6a4db94011d3 | 13 | |
sahilmgandhi | 18:6a4db94011d3 | 14 | /** @addtogroup NUC472_442_Device_Driver NUC472/NUC442 Device Driver |
sahilmgandhi | 18:6a4db94011d3 | 15 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 16 | */ |
sahilmgandhi | 18:6a4db94011d3 | 17 | |
sahilmgandhi | 18:6a4db94011d3 | 18 | /** @addtogroup NUC472_442_I2C_Driver I2C Driver |
sahilmgandhi | 18:6a4db94011d3 | 19 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 20 | */ |
sahilmgandhi | 18:6a4db94011d3 | 21 | |
sahilmgandhi | 18:6a4db94011d3 | 22 | |
sahilmgandhi | 18:6a4db94011d3 | 23 | /** @addtogroup NUC472_442_I2C_EXPORTED_FUNCTIONS I2C Exported Functions |
sahilmgandhi | 18:6a4db94011d3 | 24 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 25 | */ |
sahilmgandhi | 18:6a4db94011d3 | 26 | |
sahilmgandhi | 18:6a4db94011d3 | 27 | /** |
sahilmgandhi | 18:6a4db94011d3 | 28 | * @brief This function make I2C module be ready and set the wanted bus clock. |
sahilmgandhi | 18:6a4db94011d3 | 29 | * @param[in] i2c is the base address of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 30 | * @param[in] u32BusClock is the target bus speed of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 31 | * @return Actual I2C bus clock frequency. |
sahilmgandhi | 18:6a4db94011d3 | 32 | */ |
sahilmgandhi | 18:6a4db94011d3 | 33 | uint32_t I2C_Open(I2C_T *i2c, uint32_t u32BusClock) |
sahilmgandhi | 18:6a4db94011d3 | 34 | { |
sahilmgandhi | 18:6a4db94011d3 | 35 | uint32_t u32Div; |
sahilmgandhi | 18:6a4db94011d3 | 36 | uint32_t u32Pclk = CLK_GetPCLKFreq(); |
sahilmgandhi | 18:6a4db94011d3 | 37 | |
sahilmgandhi | 18:6a4db94011d3 | 38 | u32Div = (uint32_t) ((( u32Pclk * 10)/(u32BusClock * 4) + 5) / 10 - 1); /* Compute proper divider for I2C clock */ |
sahilmgandhi | 18:6a4db94011d3 | 39 | i2c->CLKDIV = u32Div; |
sahilmgandhi | 18:6a4db94011d3 | 40 | |
sahilmgandhi | 18:6a4db94011d3 | 41 | /* Enable I2C */ |
sahilmgandhi | 18:6a4db94011d3 | 42 | i2c->CTL |= I2C_CTL_I2CEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 43 | |
sahilmgandhi | 18:6a4db94011d3 | 44 | return ( u32Pclk / ((u32Div+1)<<2) ); |
sahilmgandhi | 18:6a4db94011d3 | 45 | } |
sahilmgandhi | 18:6a4db94011d3 | 46 | |
sahilmgandhi | 18:6a4db94011d3 | 47 | /** |
sahilmgandhi | 18:6a4db94011d3 | 48 | * @brief This function closes the I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 49 | * @param[in] i2c is the base address of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 50 | * @return none |
sahilmgandhi | 18:6a4db94011d3 | 51 | */ |
sahilmgandhi | 18:6a4db94011d3 | 52 | void I2C_Close(I2C_T *i2c) |
sahilmgandhi | 18:6a4db94011d3 | 53 | { |
sahilmgandhi | 18:6a4db94011d3 | 54 | /* Reset SPI */ |
sahilmgandhi | 18:6a4db94011d3 | 55 | if((uint32_t)i2c == I2C0_BASE) { |
sahilmgandhi | 18:6a4db94011d3 | 56 | SYS->IPRST1 |= SYS_IPRST1_I2C0RST_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 57 | SYS->IPRST1 &= ~SYS_IPRST1_I2C0RST_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 58 | } else if((uint32_t)i2c == I2C1_BASE) { |
sahilmgandhi | 18:6a4db94011d3 | 59 | SYS->IPRST1 |= SYS_IPRST1_I2C1RST_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 60 | SYS->IPRST1 &= ~SYS_IPRST1_I2C1RST_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 61 | } else if((uint32_t)i2c == I2C2_BASE) { |
sahilmgandhi | 18:6a4db94011d3 | 62 | SYS->IPRST1 |= SYS_IPRST1_I2C2RST_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 63 | SYS->IPRST1 &= ~SYS_IPRST1_I2C2RST_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 64 | } else { |
sahilmgandhi | 18:6a4db94011d3 | 65 | SYS->IPRST1 |= SYS_IPRST1_I2C3RST_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 66 | SYS->IPRST1 &= ~SYS_IPRST1_I2C3RST_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 67 | } |
sahilmgandhi | 18:6a4db94011d3 | 68 | |
sahilmgandhi | 18:6a4db94011d3 | 69 | /* Disable I2C */ |
sahilmgandhi | 18:6a4db94011d3 | 70 | i2c->CTL &= ~I2C_CTL_I2CEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 71 | } |
sahilmgandhi | 18:6a4db94011d3 | 72 | |
sahilmgandhi | 18:6a4db94011d3 | 73 | /** |
sahilmgandhi | 18:6a4db94011d3 | 74 | * @brief This function clears the time-out flag. |
sahilmgandhi | 18:6a4db94011d3 | 75 | * @param[in] i2c is the base address of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 76 | * @return none |
sahilmgandhi | 18:6a4db94011d3 | 77 | */ |
sahilmgandhi | 18:6a4db94011d3 | 78 | void I2C_ClearTimeoutFlag(I2C_T *i2c) |
sahilmgandhi | 18:6a4db94011d3 | 79 | { |
sahilmgandhi | 18:6a4db94011d3 | 80 | i2c->TOCTL |= I2C_TOCTL_TOIF_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 81 | } |
sahilmgandhi | 18:6a4db94011d3 | 82 | |
sahilmgandhi | 18:6a4db94011d3 | 83 | /** |
sahilmgandhi | 18:6a4db94011d3 | 84 | * @brief This function sets the control bit of the I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 85 | * @param[in] i2c is the base address of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 86 | * @param[in] u8Start sets START bit to I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 87 | * @param[in] u8Stop sets STOP bit to I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 88 | * @param[in] u8Si sets SI bit to I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 89 | * @param[in] u8Ack sets ACK bit to I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 90 | * @return none |
sahilmgandhi | 18:6a4db94011d3 | 91 | */ |
sahilmgandhi | 18:6a4db94011d3 | 92 | void I2C_Trigger(I2C_T *i2c, uint8_t u8Start, uint8_t u8Stop, uint8_t u8Si, uint8_t u8Ack) |
sahilmgandhi | 18:6a4db94011d3 | 93 | { |
sahilmgandhi | 18:6a4db94011d3 | 94 | uint32_t u32Reg = 0; |
sahilmgandhi | 18:6a4db94011d3 | 95 | uint32_t u32Val = i2c->CTL & ~(I2C_STA | I2C_STO | I2C_AA); |
sahilmgandhi | 18:6a4db94011d3 | 96 | |
sahilmgandhi | 18:6a4db94011d3 | 97 | if (u8Start) |
sahilmgandhi | 18:6a4db94011d3 | 98 | u32Reg |= I2C_STA; |
sahilmgandhi | 18:6a4db94011d3 | 99 | if (u8Stop) |
sahilmgandhi | 18:6a4db94011d3 | 100 | u32Reg |= I2C_STO; |
sahilmgandhi | 18:6a4db94011d3 | 101 | if (u8Si) |
sahilmgandhi | 18:6a4db94011d3 | 102 | u32Reg |= I2C_SI; |
sahilmgandhi | 18:6a4db94011d3 | 103 | if (u8Ack) |
sahilmgandhi | 18:6a4db94011d3 | 104 | u32Reg |= I2C_AA; |
sahilmgandhi | 18:6a4db94011d3 | 105 | |
sahilmgandhi | 18:6a4db94011d3 | 106 | i2c->CTL = u32Val | u32Reg; |
sahilmgandhi | 18:6a4db94011d3 | 107 | } |
sahilmgandhi | 18:6a4db94011d3 | 108 | |
sahilmgandhi | 18:6a4db94011d3 | 109 | /** |
sahilmgandhi | 18:6a4db94011d3 | 110 | * @brief This function disables the interrupt of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 111 | * @param[in] i2c is the base address of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 112 | * @return none |
sahilmgandhi | 18:6a4db94011d3 | 113 | */ |
sahilmgandhi | 18:6a4db94011d3 | 114 | void I2C_DisableInt(I2C_T *i2c) |
sahilmgandhi | 18:6a4db94011d3 | 115 | { |
sahilmgandhi | 18:6a4db94011d3 | 116 | i2c->CTL &= ~I2C_CTL_INTEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 117 | } |
sahilmgandhi | 18:6a4db94011d3 | 118 | |
sahilmgandhi | 18:6a4db94011d3 | 119 | /** |
sahilmgandhi | 18:6a4db94011d3 | 120 | * @brief This function enables the interrupt (EI bit) of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 121 | * @param[in] i2c is the base address of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 122 | * @return none |
sahilmgandhi | 18:6a4db94011d3 | 123 | */ |
sahilmgandhi | 18:6a4db94011d3 | 124 | void I2C_EnableInt(I2C_T *i2c) |
sahilmgandhi | 18:6a4db94011d3 | 125 | { |
sahilmgandhi | 18:6a4db94011d3 | 126 | i2c->CTL |= I2C_CTL_INTEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 127 | } |
sahilmgandhi | 18:6a4db94011d3 | 128 | |
sahilmgandhi | 18:6a4db94011d3 | 129 | /** |
sahilmgandhi | 18:6a4db94011d3 | 130 | * @brief This function returns the real bus clock of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 131 | * @param[in] i2c is the base address of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 132 | * @return Actual I2C bus clock frequency. |
sahilmgandhi | 18:6a4db94011d3 | 133 | */ |
sahilmgandhi | 18:6a4db94011d3 | 134 | uint32_t I2C_GetBusClockFreq(I2C_T *i2c) |
sahilmgandhi | 18:6a4db94011d3 | 135 | { |
sahilmgandhi | 18:6a4db94011d3 | 136 | uint32_t u32Divider = i2c->CLKDIV; |
sahilmgandhi | 18:6a4db94011d3 | 137 | |
sahilmgandhi | 18:6a4db94011d3 | 138 | return ( CLK_GetPCLKFreq() / ((u32Divider+1)<<2) ); |
sahilmgandhi | 18:6a4db94011d3 | 139 | } |
sahilmgandhi | 18:6a4db94011d3 | 140 | |
sahilmgandhi | 18:6a4db94011d3 | 141 | /** |
sahilmgandhi | 18:6a4db94011d3 | 142 | * @brief This function sets bus frequency of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 143 | * @param[in] i2c is the base address of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 144 | * @param[in] u32BusClock is the target bus speed of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 145 | * @return Actual I2C bus clock frequency. |
sahilmgandhi | 18:6a4db94011d3 | 146 | */ |
sahilmgandhi | 18:6a4db94011d3 | 147 | uint32_t I2C_SetBusClockFreq(I2C_T *i2c, uint32_t u32BusClock) |
sahilmgandhi | 18:6a4db94011d3 | 148 | { |
sahilmgandhi | 18:6a4db94011d3 | 149 | uint32_t u32Div; |
sahilmgandhi | 18:6a4db94011d3 | 150 | uint32_t u32Pclk = CLK_GetPCLKFreq(); |
sahilmgandhi | 18:6a4db94011d3 | 151 | |
sahilmgandhi | 18:6a4db94011d3 | 152 | u32Div = (uint32_t) (((u32Pclk * 10)/(u32BusClock * 4) + 5) / 10 - 1); /* Compute proper divider for I2C clock */ |
sahilmgandhi | 18:6a4db94011d3 | 153 | i2c->CLKDIV = u32Div; |
sahilmgandhi | 18:6a4db94011d3 | 154 | |
sahilmgandhi | 18:6a4db94011d3 | 155 | return ( u32Pclk / ((u32Div+1)<<2) ); |
sahilmgandhi | 18:6a4db94011d3 | 156 | } |
sahilmgandhi | 18:6a4db94011d3 | 157 | |
sahilmgandhi | 18:6a4db94011d3 | 158 | /** |
sahilmgandhi | 18:6a4db94011d3 | 159 | * @brief This function gets the interrupt flag of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 160 | * @param[in] i2c is the base address of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 161 | * @return Interrupt flag. |
sahilmgandhi | 18:6a4db94011d3 | 162 | * @retval 0 Flag is not set. |
sahilmgandhi | 18:6a4db94011d3 | 163 | * @retval 1 Flag is set. |
sahilmgandhi | 18:6a4db94011d3 | 164 | */ |
sahilmgandhi | 18:6a4db94011d3 | 165 | uint32_t I2C_GetIntFlag(I2C_T *i2c) |
sahilmgandhi | 18:6a4db94011d3 | 166 | { |
sahilmgandhi | 18:6a4db94011d3 | 167 | return ( (i2c->CTL & I2C_CTL_SI_Msk) == I2C_CTL_SI_Msk ? 1:0 ); |
sahilmgandhi | 18:6a4db94011d3 | 168 | } |
sahilmgandhi | 18:6a4db94011d3 | 169 | |
sahilmgandhi | 18:6a4db94011d3 | 170 | /** |
sahilmgandhi | 18:6a4db94011d3 | 171 | * @brief This function returns the status of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 172 | * @param[in] i2c is the base address of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 173 | * @return I2C status |
sahilmgandhi | 18:6a4db94011d3 | 174 | */ |
sahilmgandhi | 18:6a4db94011d3 | 175 | uint32_t I2C_GetStatus(I2C_T *i2c) |
sahilmgandhi | 18:6a4db94011d3 | 176 | { |
sahilmgandhi | 18:6a4db94011d3 | 177 | return ( i2c->STATUS ); |
sahilmgandhi | 18:6a4db94011d3 | 178 | } |
sahilmgandhi | 18:6a4db94011d3 | 179 | |
sahilmgandhi | 18:6a4db94011d3 | 180 | /** |
sahilmgandhi | 18:6a4db94011d3 | 181 | * @brief This function returns the data stored in data register of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 182 | * @param[in] i2c is the base address of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 183 | * @return I2C data. |
sahilmgandhi | 18:6a4db94011d3 | 184 | */ |
sahilmgandhi | 18:6a4db94011d3 | 185 | uint32_t I2C_GetData(I2C_T *i2c) |
sahilmgandhi | 18:6a4db94011d3 | 186 | { |
sahilmgandhi | 18:6a4db94011d3 | 187 | return ( i2c->DAT ); |
sahilmgandhi | 18:6a4db94011d3 | 188 | } |
sahilmgandhi | 18:6a4db94011d3 | 189 | |
sahilmgandhi | 18:6a4db94011d3 | 190 | /** |
sahilmgandhi | 18:6a4db94011d3 | 191 | * @brief This function writes the data to data register of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 192 | * @param[in] i2c is the base address of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 193 | * @param[in] u8Data is the data which will be write to data register of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 194 | * @return none |
sahilmgandhi | 18:6a4db94011d3 | 195 | */ |
sahilmgandhi | 18:6a4db94011d3 | 196 | void I2C_SetData(I2C_T *i2c, uint8_t u8Data) |
sahilmgandhi | 18:6a4db94011d3 | 197 | { |
sahilmgandhi | 18:6a4db94011d3 | 198 | i2c->DAT = u8Data; |
sahilmgandhi | 18:6a4db94011d3 | 199 | } |
sahilmgandhi | 18:6a4db94011d3 | 200 | |
sahilmgandhi | 18:6a4db94011d3 | 201 | /** |
sahilmgandhi | 18:6a4db94011d3 | 202 | * @brief Configure slave address and enable GC mode. |
sahilmgandhi | 18:6a4db94011d3 | 203 | * @param[in] i2c is the base address of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 204 | * @param[in] u8SlaveNo is the set number of salve address. |
sahilmgandhi | 18:6a4db94011d3 | 205 | * @param[in] u8SlaveAddr is the slave address. |
sahilmgandhi | 18:6a4db94011d3 | 206 | * @param[in] u8GCMode GC mode enable or not. Valid values are: |
sahilmgandhi | 18:6a4db94011d3 | 207 | * - \ref I2C_GCMODE_ENABLE |
sahilmgandhi | 18:6a4db94011d3 | 208 | * - \ref I2C_GCMODE_DISABLE |
sahilmgandhi | 18:6a4db94011d3 | 209 | * @return none |
sahilmgandhi | 18:6a4db94011d3 | 210 | */ |
sahilmgandhi | 18:6a4db94011d3 | 211 | void I2C_SetSlaveAddr(I2C_T *i2c, uint8_t u8SlaveNo, uint8_t u8SlaveAddr, uint8_t u8GCMode) |
sahilmgandhi | 18:6a4db94011d3 | 212 | { |
sahilmgandhi | 18:6a4db94011d3 | 213 | switch (u8SlaveNo) { |
sahilmgandhi | 18:6a4db94011d3 | 214 | case 0: |
sahilmgandhi | 18:6a4db94011d3 | 215 | i2c->ADDR0 = (u8SlaveAddr << 1) | u8GCMode; |
sahilmgandhi | 18:6a4db94011d3 | 216 | break; |
sahilmgandhi | 18:6a4db94011d3 | 217 | case 1: |
sahilmgandhi | 18:6a4db94011d3 | 218 | i2c->ADDR1 = (u8SlaveAddr << 1) | u8GCMode; |
sahilmgandhi | 18:6a4db94011d3 | 219 | break; |
sahilmgandhi | 18:6a4db94011d3 | 220 | case 2: |
sahilmgandhi | 18:6a4db94011d3 | 221 | i2c->ADDR2 = (u8SlaveAddr << 1) | u8GCMode; |
sahilmgandhi | 18:6a4db94011d3 | 222 | break; |
sahilmgandhi | 18:6a4db94011d3 | 223 | case 3: |
sahilmgandhi | 18:6a4db94011d3 | 224 | i2c->ADDR3 = (u8SlaveAddr << 1) | u8GCMode; |
sahilmgandhi | 18:6a4db94011d3 | 225 | break; |
sahilmgandhi | 18:6a4db94011d3 | 226 | default: |
sahilmgandhi | 18:6a4db94011d3 | 227 | i2c->ADDR0 = (u8SlaveAddr << 1) | u8GCMode; |
sahilmgandhi | 18:6a4db94011d3 | 228 | } |
sahilmgandhi | 18:6a4db94011d3 | 229 | } |
sahilmgandhi | 18:6a4db94011d3 | 230 | |
sahilmgandhi | 18:6a4db94011d3 | 231 | /** |
sahilmgandhi | 18:6a4db94011d3 | 232 | * @brief Configure the mask of slave address. The corresponding address bit is "Don't Care". |
sahilmgandhi | 18:6a4db94011d3 | 233 | * @param[in] i2c is the base address of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 234 | * @param[in] u8SlaveNo is the set number of salve address. |
sahilmgandhi | 18:6a4db94011d3 | 235 | * @param[in] u8SlaveAddrMask is the slave address mask. |
sahilmgandhi | 18:6a4db94011d3 | 236 | * @return none |
sahilmgandhi | 18:6a4db94011d3 | 237 | */ |
sahilmgandhi | 18:6a4db94011d3 | 238 | void I2C_SetSlaveAddrMask(I2C_T *i2c, uint8_t u8SlaveNo, uint8_t u8SlaveAddrMask) |
sahilmgandhi | 18:6a4db94011d3 | 239 | { |
sahilmgandhi | 18:6a4db94011d3 | 240 | switch (u8SlaveNo) { |
sahilmgandhi | 18:6a4db94011d3 | 241 | case 0: |
sahilmgandhi | 18:6a4db94011d3 | 242 | i2c->ADDRMSK0 = u8SlaveAddrMask << 1; |
sahilmgandhi | 18:6a4db94011d3 | 243 | break; |
sahilmgandhi | 18:6a4db94011d3 | 244 | case 1: |
sahilmgandhi | 18:6a4db94011d3 | 245 | i2c->ADDRMSK1 = u8SlaveAddrMask << 1; |
sahilmgandhi | 18:6a4db94011d3 | 246 | break; |
sahilmgandhi | 18:6a4db94011d3 | 247 | case 2: |
sahilmgandhi | 18:6a4db94011d3 | 248 | i2c->ADDRMSK2 = u8SlaveAddrMask << 1; |
sahilmgandhi | 18:6a4db94011d3 | 249 | break; |
sahilmgandhi | 18:6a4db94011d3 | 250 | case 3: |
sahilmgandhi | 18:6a4db94011d3 | 251 | i2c->ADDRMSK3 = u8SlaveAddrMask << 1; |
sahilmgandhi | 18:6a4db94011d3 | 252 | break; |
sahilmgandhi | 18:6a4db94011d3 | 253 | default: |
sahilmgandhi | 18:6a4db94011d3 | 254 | i2c->ADDRMSK0 = u8SlaveAddrMask << 1; |
sahilmgandhi | 18:6a4db94011d3 | 255 | } |
sahilmgandhi | 18:6a4db94011d3 | 256 | } |
sahilmgandhi | 18:6a4db94011d3 | 257 | |
sahilmgandhi | 18:6a4db94011d3 | 258 | /** |
sahilmgandhi | 18:6a4db94011d3 | 259 | * @brief This function enables timeout function and configures DIV4 function to support long timeout. |
sahilmgandhi | 18:6a4db94011d3 | 260 | * @param[in] i2c is the base address of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 261 | * @param[in] u8LongTimeout Enable timeout counter input clock is divide by 4. |
sahilmgandhi | 18:6a4db94011d3 | 262 | * @return none |
sahilmgandhi | 18:6a4db94011d3 | 263 | */ |
sahilmgandhi | 18:6a4db94011d3 | 264 | void I2C_EnableTimeout(I2C_T *i2c, uint8_t u8LongTimeout) |
sahilmgandhi | 18:6a4db94011d3 | 265 | { |
sahilmgandhi | 18:6a4db94011d3 | 266 | if(u8LongTimeout) |
sahilmgandhi | 18:6a4db94011d3 | 267 | i2c->TOCTL |= I2C_TOCTL_TOCDIV4_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 268 | else |
sahilmgandhi | 18:6a4db94011d3 | 269 | i2c->TOCTL &= ~I2C_TOCTL_TOCDIV4_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 270 | |
sahilmgandhi | 18:6a4db94011d3 | 271 | i2c->TOCTL |= I2C_TOCTL_TOCEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 272 | } |
sahilmgandhi | 18:6a4db94011d3 | 273 | |
sahilmgandhi | 18:6a4db94011d3 | 274 | /** |
sahilmgandhi | 18:6a4db94011d3 | 275 | * @brief This function disables time-out function. |
sahilmgandhi | 18:6a4db94011d3 | 276 | * @param[in] i2c is the base address of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 277 | * @return none |
sahilmgandhi | 18:6a4db94011d3 | 278 | */ |
sahilmgandhi | 18:6a4db94011d3 | 279 | void I2C_DisableTimeout(I2C_T *i2c) |
sahilmgandhi | 18:6a4db94011d3 | 280 | { |
sahilmgandhi | 18:6a4db94011d3 | 281 | i2c->TOCTL &= ~I2C_TOCTL_TOCEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 282 | } |
sahilmgandhi | 18:6a4db94011d3 | 283 | |
sahilmgandhi | 18:6a4db94011d3 | 284 | /** |
sahilmgandhi | 18:6a4db94011d3 | 285 | * @brief This function enables the wakeup function of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 286 | * @param[in] i2c is the base address of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 287 | * @return none |
sahilmgandhi | 18:6a4db94011d3 | 288 | */ |
sahilmgandhi | 18:6a4db94011d3 | 289 | void I2C_EnableWakeup(I2C_T *i2c) |
sahilmgandhi | 18:6a4db94011d3 | 290 | { |
sahilmgandhi | 18:6a4db94011d3 | 291 | i2c->WKCTL |= I2C_WKCTL_WKEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 292 | } |
sahilmgandhi | 18:6a4db94011d3 | 293 | |
sahilmgandhi | 18:6a4db94011d3 | 294 | /** |
sahilmgandhi | 18:6a4db94011d3 | 295 | * @brief This function disables the wakeup function of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 296 | * @param[in] i2c is the base address of I2C module. |
sahilmgandhi | 18:6a4db94011d3 | 297 | * @return none |
sahilmgandhi | 18:6a4db94011d3 | 298 | */ |
sahilmgandhi | 18:6a4db94011d3 | 299 | void I2C_DisableWakeup(I2C_T *i2c) |
sahilmgandhi | 18:6a4db94011d3 | 300 | { |
sahilmgandhi | 18:6a4db94011d3 | 301 | i2c->WKCTL &= ~I2C_WKCTL_WKEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 302 | } |
sahilmgandhi | 18:6a4db94011d3 | 303 | |
sahilmgandhi | 18:6a4db94011d3 | 304 | /*@}*/ /* end of group NUC472_442_I2C_EXPORTED_FUNCTIONS */ |
sahilmgandhi | 18:6a4db94011d3 | 305 | |
sahilmgandhi | 18:6a4db94011d3 | 306 | /*@}*/ /* end of group NUC472_442_I2C_Driver */ |
sahilmgandhi | 18:6a4db94011d3 | 307 | |
sahilmgandhi | 18:6a4db94011d3 | 308 | /*@}*/ /* end of group NUC472_442_Device_Driver */ |
sahilmgandhi | 18:6a4db94011d3 | 309 | |
sahilmgandhi | 18:6a4db94011d3 | 310 | /*** (C) COPYRIGHT 2014 Nuvoton Technology Corp. ***/ |