i2c.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. //*****************************************************************************
  2. //
  3. // i2c.h - Prototypes for the I2C Driver.
  4. //
  5. // Copyright (c) 2005-2014 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions
  10. // are met:
  11. //
  12. // Redistributions of source code must retain the above copyright
  13. // notice, this list of conditions and the following disclaimer.
  14. //
  15. // Redistributions in binary form must reproduce the above copyright
  16. // notice, this list of conditions and the following disclaimer in the
  17. // documentation and/or other materials provided with the
  18. // distribution.
  19. //
  20. // Neither the name of Texas Instruments Incorporated nor the names of
  21. // its contributors may be used to endorse or promote products derived
  22. // from this software without specific prior written permission.
  23. //
  24. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  27. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  28. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  31. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  32. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. // This is part of revision 2.1.0.12573 of the Tiva Peripheral Driver Library.
  37. //
  38. //*****************************************************************************
  39. #ifndef __DRIVERLIB_I2C_H__
  40. #define __DRIVERLIB_I2C_H__
  41. //*****************************************************************************
  42. //
  43. // If building with a C++ compiler, make all of the definitions in this header
  44. // have a C binding.
  45. //
  46. //*****************************************************************************
  47. #ifdef __cplusplus
  48. extern "C"
  49. {
  50. #endif
  51. //*****************************************************************************
  52. //
  53. // Defines for the API.
  54. //
  55. //*****************************************************************************
  56. //*****************************************************************************
  57. //
  58. // Interrupt defines.
  59. //
  60. //*****************************************************************************
  61. #define I2C_INT_MASTER 0x00000001
  62. #define I2C_INT_SLAVE 0x00000002
  63. //*****************************************************************************
  64. //
  65. // I2C Master commands.
  66. //
  67. //*****************************************************************************
  68. #define I2C_MASTER_CMD_SINGLE_SEND \
  69. 0x00000007
  70. #define I2C_MASTER_CMD_SINGLE_RECEIVE \
  71. 0x00000007
  72. #define I2C_MASTER_CMD_BURST_SEND_START \
  73. 0x00000003
  74. #define I2C_MASTER_CMD_BURST_SEND_CONT \
  75. 0x00000001
  76. #define I2C_MASTER_CMD_BURST_SEND_FINISH \
  77. 0x00000005
  78. #define I2C_MASTER_CMD_BURST_SEND_STOP \
  79. 0x00000004
  80. #define I2C_MASTER_CMD_BURST_SEND_ERROR_STOP \
  81. 0x00000004
  82. #define I2C_MASTER_CMD_BURST_RECEIVE_START \
  83. 0x0000000b
  84. #define I2C_MASTER_CMD_BURST_RECEIVE_CONT \
  85. 0x00000009
  86. #define I2C_MASTER_CMD_BURST_RECEIVE_FINISH \
  87. 0x00000005
  88. #define I2C_MASTER_CMD_BURST_RECEIVE_ERROR_STOP \
  89. 0x00000004
  90. #define I2C_MASTER_CMD_QUICK_COMMAND \
  91. 0x00000027
  92. #define I2C_MASTER_CMD_HS_MASTER_CODE_SEND \
  93. 0x00000013
  94. #define I2C_MASTER_CMD_FIFO_SINGLE_SEND \
  95. 0x00000046
  96. #define I2C_MASTER_CMD_FIFO_SINGLE_RECEIVE \
  97. 0x00000046
  98. #define I2C_MASTER_CMD_FIFO_BURST_SEND_START \
  99. 0x00000042
  100. #define I2C_MASTER_CMD_FIFO_BURST_SEND_CONT \
  101. 0x00000040
  102. #define I2C_MASTER_CMD_FIFO_BURST_SEND_FINISH \
  103. 0x00000044
  104. #define I2C_MASTER_CMD_FIFO_BURST_SEND_ERROR_STOP \
  105. 0x00000004
  106. #define I2C_MASTER_CMD_FIFO_BURST_RECEIVE_START \
  107. 0x0000004a
  108. #define I2C_MASTER_CMD_FIFO_BURST_RECEIVE_CONT \
  109. 0x00000048
  110. #define I2C_MASTER_CMD_FIFO_BURST_RECEIVE_FINISH \
  111. 0x00000044
  112. #define I2C_MASTER_CMD_FIFO_BURST_RECEIVE_ERROR_STOP \
  113. 0x00000004
  114. //*****************************************************************************
  115. //
  116. // I2C Master glitch filter configuration.
  117. //
  118. //*****************************************************************************
  119. #define I2C_MASTER_GLITCH_FILTER_DISABLED \
  120. 0
  121. #define I2C_MASTER_GLITCH_FILTER_1 \
  122. 0x00010000
  123. #define I2C_MASTER_GLITCH_FILTER_2 \
  124. 0x00020000
  125. #define I2C_MASTER_GLITCH_FILTER_3 \
  126. 0x00030000
  127. #define I2C_MASTER_GLITCH_FILTER_4 \
  128. 0x00040000
  129. #define I2C_MASTER_GLITCH_FILTER_8 \
  130. 0x00050000
  131. #define I2C_MASTER_GLITCH_FILTER_16 \
  132. 0x00060000
  133. #define I2C_MASTER_GLITCH_FILTER_32 \
  134. 0x00070000
  135. //*****************************************************************************
  136. //
  137. // I2C Master error status.
  138. //
  139. //*****************************************************************************
  140. #define I2C_MASTER_ERR_NONE 0
  141. #define I2C_MASTER_ERR_ADDR_ACK 0x00000004
  142. #define I2C_MASTER_ERR_DATA_ACK 0x00000008
  143. #define I2C_MASTER_ERR_ARB_LOST 0x00000010
  144. #define I2C_MASTER_ERR_CLK_TOUT 0x00000080
  145. //*****************************************************************************
  146. //
  147. // I2C Slave action requests
  148. //
  149. //*****************************************************************************
  150. #define I2C_SLAVE_ACT_NONE 0
  151. #define I2C_SLAVE_ACT_RREQ 0x00000001 // Master has sent data
  152. #define I2C_SLAVE_ACT_TREQ 0x00000002 // Master has requested data
  153. #define I2C_SLAVE_ACT_RREQ_FBR 0x00000005 // Master has sent first byte
  154. #define I2C_SLAVE_ACT_OWN2SEL 0x00000008 // Master requested secondary slave
  155. #define I2C_SLAVE_ACT_QCMD 0x00000010 // Master has sent a Quick Command
  156. #define I2C_SLAVE_ACT_QCMD_DATA 0x00000020 // Master Quick Command value
  157. //*****************************************************************************
  158. //
  159. // Miscellaneous I2C driver definitions.
  160. //
  161. //*****************************************************************************
  162. #define I2C_MASTER_MAX_RETRIES 1000 // Number of retries
  163. //*****************************************************************************
  164. //
  165. // I2C Master interrupts.
  166. //
  167. //*****************************************************************************
  168. #define I2C_MASTER_INT_RX_FIFO_FULL \
  169. 0x00000800 // RX FIFO Full Interrupt
  170. #define I2C_MASTER_INT_TX_FIFO_EMPTY \
  171. 0x00000400 // TX FIFO Empty Interrupt
  172. #define I2C_MASTER_INT_RX_FIFO_REQ \
  173. 0x00000200 // RX FIFO Request Interrupt
  174. #define I2C_MASTER_INT_TX_FIFO_REQ \
  175. 0x00000100 // TX FIFO Request Interrupt
  176. #define I2C_MASTER_INT_ARB_LOST \
  177. 0x00000080 // Arb Lost Interrupt
  178. #define I2C_MASTER_INT_STOP 0x00000040 // Stop Condition Interrupt
  179. #define I2C_MASTER_INT_START 0x00000020 // Start Condition Interrupt
  180. #define I2C_MASTER_INT_NACK 0x00000010 // Addr/Data NACK Interrupt
  181. #define I2C_MASTER_INT_TX_DMA_DONE \
  182. 0x00000008 // TX DMA Complete Interrupt
  183. #define I2C_MASTER_INT_RX_DMA_DONE \
  184. 0x00000004 // RX DMA Complete Interrupt
  185. #define I2C_MASTER_INT_TIMEOUT 0x00000002 // Clock Timeout Interrupt
  186. #define I2C_MASTER_INT_DATA 0x00000001 // Data Interrupt
  187. //*****************************************************************************
  188. //
  189. // I2C Slave interrupts.
  190. //
  191. //*****************************************************************************
  192. #define I2C_SLAVE_INT_RX_FIFO_FULL \
  193. 0x00000100 // RX FIFO Full Interrupt
  194. #define I2C_SLAVE_INT_TX_FIFO_EMPTY \
  195. 0x00000080 // TX FIFO Empty Interrupt
  196. #define I2C_SLAVE_INT_RX_FIFO_REQ \
  197. 0x00000040 // RX FIFO Request Interrupt
  198. #define I2C_SLAVE_INT_TX_FIFO_REQ \
  199. 0x00000020 // TX FIFO Request Interrupt
  200. #define I2C_SLAVE_INT_TX_DMA_DONE \
  201. 0x00000010 // TX DMA Complete Interrupt
  202. #define I2C_SLAVE_INT_RX_DMA_DONE \
  203. 0x00000008 // RX DMA Complete Interrupt
  204. #define I2C_SLAVE_INT_STOP 0x00000004 // Stop Condition Interrupt
  205. #define I2C_SLAVE_INT_START 0x00000002 // Start Condition Interrupt
  206. #define I2C_SLAVE_INT_DATA 0x00000001 // Data Interrupt
  207. //*****************************************************************************
  208. //
  209. // I2C Slave FIFO configuration macros.
  210. //
  211. //*****************************************************************************
  212. #define I2C_SLAVE_TX_FIFO_ENABLE \
  213. 0x00000002
  214. #define I2C_SLAVE_RX_FIFO_ENABLE \
  215. 0x00000004
  216. //*****************************************************************************
  217. //
  218. // I2C FIFO configuration macros.
  219. //
  220. //*****************************************************************************
  221. #define I2C_FIFO_CFG_TX_MASTER 0x00000000
  222. #define I2C_FIFO_CFG_TX_SLAVE 0x00008000
  223. #define I2C_FIFO_CFG_RX_MASTER 0x00000000
  224. #define I2C_FIFO_CFG_RX_SLAVE 0x80000000
  225. #define I2C_FIFO_CFG_TX_MASTER_DMA \
  226. 0x00002000
  227. #define I2C_FIFO_CFG_TX_SLAVE_DMA \
  228. 0x0000a000
  229. #define I2C_FIFO_CFG_RX_MASTER_DMA \
  230. 0x20000000
  231. #define I2C_FIFO_CFG_RX_SLAVE_DMA \
  232. 0xa0000000
  233. #define I2C_FIFO_CFG_TX_NO_TRIG 0x00000000
  234. #define I2C_FIFO_CFG_TX_TRIG_1 0x00000001
  235. #define I2C_FIFO_CFG_TX_TRIG_2 0x00000002
  236. #define I2C_FIFO_CFG_TX_TRIG_3 0x00000003
  237. #define I2C_FIFO_CFG_TX_TRIG_4 0x00000004
  238. #define I2C_FIFO_CFG_TX_TRIG_5 0x00000005
  239. #define I2C_FIFO_CFG_TX_TRIG_6 0x00000006
  240. #define I2C_FIFO_CFG_TX_TRIG_7 0x00000007
  241. #define I2C_FIFO_CFG_TX_TRIG_8 0x00000008
  242. #define I2C_FIFO_CFG_RX_NO_TRIG 0x00000000
  243. #define I2C_FIFO_CFG_RX_TRIG_1 0x00010000
  244. #define I2C_FIFO_CFG_RX_TRIG_2 0x00020000
  245. #define I2C_FIFO_CFG_RX_TRIG_3 0x00030000
  246. #define I2C_FIFO_CFG_RX_TRIG_4 0x00040000
  247. #define I2C_FIFO_CFG_RX_TRIG_5 0x00050000
  248. #define I2C_FIFO_CFG_RX_TRIG_6 0x00060000
  249. #define I2C_FIFO_CFG_RX_TRIG_7 0x00070000
  250. #define I2C_FIFO_CFG_RX_TRIG_8 0x00080000
  251. //*****************************************************************************
  252. //
  253. // I2C FIFO status.
  254. //
  255. //*****************************************************************************
  256. #define I2C_FIFO_RX_BELOW_TRIG_LEVEL \
  257. 0x00040000
  258. #define I2C_FIFO_RX_FULL 0x00020000
  259. #define I2C_FIFO_RX_EMPTY 0x00010000
  260. #define I2C_FIFO_TX_BELOW_TRIG_LEVEL \
  261. 0x00000004
  262. #define I2C_FIFO_TX_FULL 0x00000002
  263. #define I2C_FIFO_TX_EMPTY 0x00000001
  264. //*****************************************************************************
  265. //
  266. // Prototypes for the APIs.
  267. //
  268. //*****************************************************************************
  269. extern void I2CIntRegister(uint32_t ui32Base, void(pfnHandler)(void));
  270. extern void I2CIntUnregister(uint32_t ui32Base);
  271. extern void I2CTxFIFOConfigSet(uint32_t ui32Base, uint32_t ui32Config);
  272. extern void I2CTxFIFOFlush(uint32_t ui32Base);
  273. extern void I2CRxFIFOConfigSet(uint32_t ui32Base, uint32_t ui32Config);
  274. extern void I2CRxFIFOFlush(uint32_t ui32Base);
  275. extern uint32_t I2CFIFOStatus(uint32_t ui32Base);
  276. extern void I2CFIFODataPut(uint32_t ui32Base, uint8_t ui8Data);
  277. extern uint32_t I2CFIFODataPutNonBlocking(uint32_t ui32Base,
  278. uint8_t ui8Data);
  279. extern uint32_t I2CFIFODataGet(uint32_t ui32Base);
  280. extern uint32_t I2CFIFODataGetNonBlocking(uint32_t ui32Base,
  281. uint8_t *pui8Data);
  282. extern void I2CMasterBurstLengthSet(uint32_t ui32Base,
  283. uint8_t ui8Length);
  284. extern uint32_t I2CMasterBurstCountGet(uint32_t ui32Base);
  285. extern void I2CMasterGlitchFilterConfigSet(uint32_t ui32Base,
  286. uint32_t ui32Config);
  287. extern void I2CSlaveFIFOEnable(uint32_t ui32Base, uint32_t ui32Config);
  288. extern void I2CSlaveFIFODisable(uint32_t ui32Base);
  289. extern bool I2CMasterBusBusy(uint32_t ui32Base);
  290. extern bool I2CMasterBusy(uint32_t ui32Base);
  291. extern void I2CMasterControl(uint32_t ui32Base, uint32_t ui32Cmd);
  292. extern uint32_t I2CMasterDataGet(uint32_t ui32Base);
  293. extern void I2CMasterDataPut(uint32_t ui32Base, uint8_t ui8Data);
  294. extern void I2CMasterDisable(uint32_t ui32Base);
  295. extern void I2CMasterEnable(uint32_t ui32Base);
  296. extern uint32_t I2CMasterErr(uint32_t ui32Base);
  297. extern void I2CMasterInitExpClk(uint32_t ui32Base, uint32_t ui32I2CClk,
  298. bool bFast);
  299. extern void I2CMasterIntClear(uint32_t ui32Base);
  300. extern void I2CMasterIntDisable(uint32_t ui32Base);
  301. extern void I2CMasterIntEnable(uint32_t ui32Base);
  302. extern bool I2CMasterIntStatus(uint32_t ui32Base, bool bMasked);
  303. extern void I2CMasterIntEnableEx(uint32_t ui32Base,
  304. uint32_t ui32IntFlags);
  305. extern void I2CMasterIntDisableEx(uint32_t ui32Base,
  306. uint32_t ui32IntFlags);
  307. extern uint32_t I2CMasterIntStatusEx(uint32_t ui32Base,
  308. bool bMasked);
  309. extern void I2CMasterIntClearEx(uint32_t ui32Base,
  310. uint32_t ui32IntFlags);
  311. extern void I2CMasterTimeoutSet(uint32_t ui32Base, uint32_t ui32Value);
  312. extern void I2CSlaveACKOverride(uint32_t ui32Base, bool bEnable);
  313. extern void I2CSlaveACKValueSet(uint32_t ui32Base, bool bACK);
  314. extern uint32_t I2CMasterLineStateGet(uint32_t ui32Base);
  315. extern void I2CMasterSlaveAddrSet(uint32_t ui32Base,
  316. uint8_t ui8SlaveAddr,
  317. bool bReceive);
  318. extern uint32_t I2CSlaveDataGet(uint32_t ui32Base);
  319. extern void I2CSlaveDataPut(uint32_t ui32Base, uint8_t ui8Data);
  320. extern void I2CSlaveDisable(uint32_t ui32Base);
  321. extern void I2CSlaveEnable(uint32_t ui32Base);
  322. extern void I2CSlaveInit(uint32_t ui32Base, uint8_t ui8SlaveAddr);
  323. extern void I2CSlaveAddressSet(uint32_t ui32Base, uint8_t ui8AddrNum,
  324. uint8_t ui8SlaveAddr);
  325. extern void I2CSlaveIntClear(uint32_t ui32Base);
  326. extern void I2CSlaveIntDisable(uint32_t ui32Base);
  327. extern void I2CSlaveIntEnable(uint32_t ui32Base);
  328. extern void I2CSlaveIntClearEx(uint32_t ui32Base, uint32_t ui32IntFlags);
  329. extern void I2CSlaveIntDisableEx(uint32_t ui32Base,
  330. uint32_t ui32IntFlags);
  331. extern void I2CSlaveIntEnableEx(uint32_t ui32Base, uint32_t ui32IntFlags);
  332. extern bool I2CSlaveIntStatus(uint32_t ui32Base, bool bMasked);
  333. extern uint32_t I2CSlaveIntStatusEx(uint32_t ui32Base,
  334. bool bMasked);
  335. extern uint32_t I2CSlaveStatus(uint32_t ui32Base);
  336. //*****************************************************************************
  337. //
  338. // Mark the end of the C bindings section for C++ compilers.
  339. //
  340. //*****************************************************************************
  341. #ifdef __cplusplus
  342. }
  343. #endif
  344. #endif // __DRIVERLIB_I2C_H__