1 //***************************************************************************** 2 // 3 // i2c.h - Prototypes for the I2C Driver. 4 // 5 // Copyright (c) 2005-2011 Texas Instruments Incorporated. All rights reserved. 6 // Software License Agreement 7 // 8 // Texas Instruments (TI) is supplying this software for use solely and 9 // exclusively on TI's microcontroller products. The software is owned by 10 // TI and/or its suppliers, and is protected under applicable copyright 11 // laws. You may not combine this software with "viral" open-source 12 // software in order to form a larger program. 13 // 14 // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. 15 // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT 16 // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY 18 // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL 19 // DAMAGES, FOR ANY REASON WHATSOEVER. 20 // 21 // This is part of revision 8264 of the Stellaris Peripheral Driver Library. 22 // 23 //***************************************************************************** 24 25 #ifndef __I2C_H__ 26 #define __I2C_H__ 27 28 //***************************************************************************** 29 // 30 // If building with a C++ compiler, make all of the definitions in this header 31 // have a C binding. 32 // 33 //***************************************************************************** 34 #ifdef __cplusplus 35 extern "C" 36 { 37 #endif 38 39 //***************************************************************************** 40 // 41 // Defines for the API. 42 // 43 //***************************************************************************** 44 45 //***************************************************************************** 46 // 47 // Interrupt defines. 48 // 49 //***************************************************************************** 50 #define I2C_INT_MASTER 0x00000001 51 #define I2C_INT_SLAVE 0x00000002 52 53 //***************************************************************************** 54 // 55 // I2C Master commands. 56 // 57 //***************************************************************************** 58 #define I2C_MASTER_CMD_SINGLE_SEND \ 59 0x00000007 60 #define I2C_MASTER_CMD_SINGLE_RECEIVE \ 61 0x00000007 62 #define I2C_MASTER_CMD_BURST_SEND_START \ 63 0x00000003 64 #define I2C_MASTER_CMD_BURST_SEND_CONT \ 65 0x00000001 66 #define I2C_MASTER_CMD_BURST_SEND_FINISH \ 67 0x00000005 68 #define I2C_MASTER_CMD_BURST_SEND_STOP \ 69 0x00000004 70 #define I2C_MASTER_CMD_BURST_SEND_ERROR_STOP \ 71 0x00000004 72 #define I2C_MASTER_CMD_BURST_RECEIVE_START \ 73 0x0000000b 74 #define I2C_MASTER_CMD_BURST_RECEIVE_CONT \ 75 0x00000009 76 #define I2C_MASTER_CMD_BURST_RECEIVE_FINISH \ 77 0x00000005 78 #define I2C_MASTER_CMD_BURST_RECEIVE_ERROR_STOP \ 79 0x00000004 80 #define I2C_MASTER_CMD_QUICK_COMMAND \ 81 0x00000027 82 83 //***************************************************************************** 84 // 85 // I2C Master error status. 86 // 87 //***************************************************************************** 88 #define I2C_MASTER_ERR_NONE 0 89 #define I2C_MASTER_ERR_ADDR_ACK 0x00000004 90 #define I2C_MASTER_ERR_DATA_ACK 0x00000008 91 #define I2C_MASTER_ERR_ARB_LOST 0x00000010 92 93 //***************************************************************************** 94 // 95 // I2C Slave action requests 96 // 97 //***************************************************************************** 98 #define I2C_SLAVE_ACT_NONE 0 99 #define I2C_SLAVE_ACT_RREQ 0x00000001 // Master has sent data 100 #define I2C_SLAVE_ACT_TREQ 0x00000002 // Master has requested data 101 #define I2C_SLAVE_ACT_RREQ_FBR 0x00000005 // Master has sent first byte 102 #define I2C_SLAVE_ACT_OWN2SEL 0x00000008 // Master requested secondary slave 103 #define I2C_SLAVE_ACT_QCMD 0x00000010 // Master has sent a Quick Command 104 #define I2C_SLAVE_ACT_QCMD_DATA 0x00000020 // Master Quick Command value 105 106 //***************************************************************************** 107 // 108 // Miscellaneous I2C driver definitions. 109 // 110 //***************************************************************************** 111 #define I2C_MASTER_MAX_RETRIES 1000 // Number of retries 112 113 //***************************************************************************** 114 // 115 // I2C Master interrupts. 116 // 117 //***************************************************************************** 118 #define I2C_MASTER_INT_TIMEOUT 0x00000002 // Clock Timeout Interrupt. 119 #define I2C_MASTER_INT_DATA 0x00000001 // Data Interrupt. 120 121 //***************************************************************************** 122 // 123 // I2C Slave interrupts. 124 // 125 //***************************************************************************** 126 #define I2C_SLAVE_INT_STOP 0x00000004 // Stop Condition Interrupt. 127 #define I2C_SLAVE_INT_START 0x00000002 // Start Condition Interrupt. 128 #define I2C_SLAVE_INT_DATA 0x00000001 // Data Interrupt. 129 130 //***************************************************************************** 131 // 132 // Prototypes for the APIs. 133 // 134 //***************************************************************************** 135 extern void I2CIntRegister(unsigned long ulBase, void(fnHandler)(void)); 136 extern void I2CIntUnregister(unsigned long ulBase); 137 extern tBoolean I2CMasterBusBusy(unsigned long ulBase); 138 extern tBoolean I2CMasterBusy(unsigned long ulBase); 139 extern void I2CMasterControl(unsigned long ulBase, unsigned long ulCmd); 140 extern unsigned long I2CMasterDataGet(unsigned long ulBase); 141 extern void I2CMasterDataPut(unsigned long ulBase, unsigned char ucData); 142 extern void I2CMasterDisable(unsigned long ulBase); 143 extern void I2CMasterEnable(unsigned long ulBase); 144 extern unsigned long I2CMasterErr(unsigned long ulBase); 145 extern void I2CMasterInitExpClk(unsigned long ulBase, unsigned long ulI2CClk, 146 tBoolean bFast); 147 extern void I2CMasterIntClear(unsigned long ulBase); 148 extern void I2CMasterIntDisable(unsigned long ulBase); 149 extern void I2CMasterIntEnable(unsigned long ulBase); 150 extern tBoolean I2CMasterIntStatus(unsigned long ulBase, tBoolean bMasked); 151 extern void I2CMasterIntEnableEx(unsigned long ulBase, 152 unsigned long ulIntFlags); 153 extern void I2CMasterIntDisableEx(unsigned long ulBase, 154 unsigned long ulIntFlags); 155 extern unsigned long I2CMasterIntStatusEx(unsigned long ulBase, 156 tBoolean bMasked); 157 extern void I2CMasterIntClearEx(unsigned long ulBase, 158 unsigned long ulIntFlags); 159 extern void I2CMasterTimeoutSet(unsigned long ulBase, unsigned long ulValue); 160 extern void I2CSlaveACKOverride(unsigned long ulBase, tBoolean bEnable); 161 extern void I2CSlaveACKValueSet(unsigned long ulBase, tBoolean bACK); 162 extern unsigned long I2CMasterLineStateGet(unsigned long ulBase); 163 extern void I2CMasterSlaveAddrSet(unsigned long ulBase, 164 unsigned char ucSlaveAddr, 165 tBoolean bReceive); 166 extern unsigned long I2CSlaveDataGet(unsigned long ulBase); 167 extern void I2CSlaveDataPut(unsigned long ulBase, unsigned char ucData); 168 extern void I2CSlaveDisable(unsigned long ulBase); 169 extern void I2CSlaveEnable(unsigned long ulBase); 170 extern void I2CSlaveInit(unsigned long ulBase, unsigned char ucSlaveAddr); 171 extern void I2CSlaveAddressSet(unsigned long ulBase, unsigned char ucAddrNum, 172 unsigned char ucSlaveAddr); 173 extern void I2CSlaveIntClear(unsigned long ulBase); 174 extern void I2CSlaveIntDisable(unsigned long ulBase); 175 extern void I2CSlaveIntEnable(unsigned long ulBase); 176 extern void I2CSlaveIntClearEx(unsigned long ulBase, unsigned long ulIntFlags); 177 extern void I2CSlaveIntDisableEx(unsigned long ulBase, 178 unsigned long ulIntFlags); 179 extern void I2CSlaveIntEnableEx(unsigned long ulBase, unsigned long ulIntFlags); 180 extern tBoolean I2CSlaveIntStatus(unsigned long ulBase, tBoolean bMasked); 181 extern unsigned long I2CSlaveIntStatusEx(unsigned long ulBase, 182 tBoolean bMasked); 183 extern unsigned long I2CSlaveStatus(unsigned long ulBase); 184 185 //***************************************************************************** 186 // 187 // Several I2C APIs have been renamed, with the original function name being 188 // deprecated. These defines provide backward compatibility. 189 // 190 //***************************************************************************** 191 #ifndef DEPRECATED 192 #include "driverlib/sysctl.h" 193 #define I2CMasterInit(a, b) \ 194 I2CMasterInitExpClk(a, SysCtlClockGet(), b) 195 #endif 196 197 //***************************************************************************** 198 // 199 // Mark the end of the C bindings section for C++ compilers. 200 // 201 //***************************************************************************** 202 #ifdef __cplusplus 203 } 204 #endif 205 206 #endif // __I2C_H__ 207