i2c.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. #ifndef __I2C_H__
  25. #define __I2C_H__
  26. //*****************************************************************************
  27. //
  28. // If building with a C++ compiler, make all of the definitions in this header
  29. // have a C binding.
  30. //
  31. //*****************************************************************************
  32. #ifdef __cplusplus
  33. extern "C"
  34. {
  35. #endif
  36. //*****************************************************************************
  37. //
  38. // Defines for the API.
  39. //
  40. //*****************************************************************************
  41. //*****************************************************************************
  42. //
  43. // Interrupt defines.
  44. //
  45. //*****************************************************************************
  46. #define I2C_INT_MASTER 0x00000001
  47. #define I2C_INT_SLAVE 0x00000002
  48. //*****************************************************************************
  49. //
  50. // I2C Master commands.
  51. //
  52. //*****************************************************************************
  53. #define I2C_MASTER_CMD_SINGLE_SEND \
  54. 0x00000007
  55. #define I2C_MASTER_CMD_SINGLE_RECEIVE \
  56. 0x00000007
  57. #define I2C_MASTER_CMD_BURST_SEND_START \
  58. 0x00000003
  59. #define I2C_MASTER_CMD_BURST_SEND_CONT \
  60. 0x00000001
  61. #define I2C_MASTER_CMD_BURST_SEND_FINISH \
  62. 0x00000005
  63. #define I2C_MASTER_CMD_BURST_SEND_STOP \
  64. 0x00000004
  65. #define I2C_MASTER_CMD_BURST_SEND_ERROR_STOP \
  66. 0x00000004
  67. #define I2C_MASTER_CMD_BURST_RECEIVE_START \
  68. 0x0000000b
  69. #define I2C_MASTER_CMD_BURST_RECEIVE_CONT \
  70. 0x00000009
  71. #define I2C_MASTER_CMD_BURST_RECEIVE_FINISH \
  72. 0x00000005
  73. #define I2C_MASTER_CMD_BURST_RECEIVE_ERROR_STOP \
  74. 0x00000004
  75. #define I2C_MASTER_CMD_QUICK_COMMAND \
  76. 0x00000027
  77. //*****************************************************************************
  78. //
  79. // I2C Master error status.
  80. //
  81. //*****************************************************************************
  82. #define I2C_MASTER_ERR_NONE 0
  83. #define I2C_MASTER_ERR_ADDR_ACK 0x00000004
  84. #define I2C_MASTER_ERR_DATA_ACK 0x00000008
  85. #define I2C_MASTER_ERR_ARB_LOST 0x00000010
  86. //*****************************************************************************
  87. //
  88. // I2C Slave action requests
  89. //
  90. //*****************************************************************************
  91. #define I2C_SLAVE_ACT_NONE 0
  92. #define I2C_SLAVE_ACT_RREQ 0x00000001 // Master has sent data
  93. #define I2C_SLAVE_ACT_TREQ 0x00000002 // Master has requested data
  94. #define I2C_SLAVE_ACT_RREQ_FBR 0x00000005 // Master has sent first byte
  95. #define I2C_SLAVE_ACT_OWN2SEL 0x00000008 // Master requested secondary slave
  96. #define I2C_SLAVE_ACT_QCMD 0x00000010 // Master has sent a Quick Command
  97. #define I2C_SLAVE_ACT_QCMD_DATA 0x00000020 // Master Quick Command value
  98. //*****************************************************************************
  99. //
  100. // Miscellaneous I2C driver definitions.
  101. //
  102. //*****************************************************************************
  103. #define I2C_MASTER_MAX_RETRIES 1000 // Number of retries
  104. //*****************************************************************************
  105. //
  106. // I2C Master interrupts.
  107. //
  108. //*****************************************************************************
  109. #define I2C_MASTER_INT_TIMEOUT 0x00000002 // Clock Timeout Interrupt.
  110. #define I2C_MASTER_INT_DATA 0x00000001 // Data Interrupt.
  111. //*****************************************************************************
  112. //
  113. // I2C Slave interrupts.
  114. //
  115. //*****************************************************************************
  116. #define I2C_SLAVE_INT_STOP 0x00000004 // Stop Condition Interrupt.
  117. #define I2C_SLAVE_INT_START 0x00000002 // Start Condition Interrupt.
  118. #define I2C_SLAVE_INT_DATA 0x00000001 // Data Interrupt.
  119. //*****************************************************************************
  120. //
  121. // Prototypes for the APIs.
  122. //
  123. //*****************************************************************************
  124. extern void I2CIntRegister(unsigned long ulBase, void(fnHandler)(void));
  125. extern void I2CIntUnregister(unsigned long ulBase);
  126. extern tBoolean I2CMasterBusBusy(unsigned long ulBase);
  127. extern tBoolean I2CMasterBusy(unsigned long ulBase);
  128. extern void I2CMasterControl(unsigned long ulBase, unsigned long ulCmd);
  129. extern unsigned long I2CMasterDataGet(unsigned long ulBase);
  130. extern void I2CMasterDataPut(unsigned long ulBase, unsigned char ucData);
  131. extern void I2CMasterDisable(unsigned long ulBase);
  132. extern void I2CMasterEnable(unsigned long ulBase);
  133. extern unsigned long I2CMasterErr(unsigned long ulBase);
  134. extern void I2CMasterInitExpClk(unsigned long ulBase, unsigned long ulI2CClk,
  135. tBoolean bFast);
  136. extern void I2CMasterIntClear(unsigned long ulBase);
  137. extern void I2CMasterIntDisable(unsigned long ulBase);
  138. extern void I2CMasterIntEnable(unsigned long ulBase);
  139. extern tBoolean I2CMasterIntStatus(unsigned long ulBase, tBoolean bMasked);
  140. extern void I2CMasterIntEnableEx(unsigned long ulBase,
  141. unsigned long ulIntFlags);
  142. extern void I2CMasterIntDisableEx(unsigned long ulBase,
  143. unsigned long ulIntFlags);
  144. extern unsigned long I2CMasterIntStatusEx(unsigned long ulBase,
  145. tBoolean bMasked);
  146. extern void I2CMasterIntClearEx(unsigned long ulBase,
  147. unsigned long ulIntFlags);
  148. extern void I2CMasterTimeoutSet(unsigned long ulBase, unsigned long ulValue);
  149. extern void I2CSlaveACKOverride(unsigned long ulBase, tBoolean bEnable);
  150. extern void I2CSlaveACKValueSet(unsigned long ulBase, tBoolean bACK);
  151. extern unsigned long I2CMasterLineStateGet(unsigned long ulBase);
  152. extern void I2CMasterSlaveAddrSet(unsigned long ulBase,
  153. unsigned char ucSlaveAddr,
  154. tBoolean bReceive);
  155. extern unsigned long I2CSlaveDataGet(unsigned long ulBase);
  156. extern void I2CSlaveDataPut(unsigned long ulBase, unsigned char ucData);
  157. extern void I2CSlaveDisable(unsigned long ulBase);
  158. extern void I2CSlaveEnable(unsigned long ulBase);
  159. extern void I2CSlaveInit(unsigned long ulBase, unsigned char ucSlaveAddr);
  160. extern void I2CSlaveAddressSet(unsigned long ulBase, unsigned char ucAddrNum,
  161. unsigned char ucSlaveAddr);
  162. extern void I2CSlaveIntClear(unsigned long ulBase);
  163. extern void I2CSlaveIntDisable(unsigned long ulBase);
  164. extern void I2CSlaveIntEnable(unsigned long ulBase);
  165. extern void I2CSlaveIntClearEx(unsigned long ulBase, unsigned long ulIntFlags);
  166. extern void I2CSlaveIntDisableEx(unsigned long ulBase,
  167. unsigned long ulIntFlags);
  168. extern void I2CSlaveIntEnableEx(unsigned long ulBase, unsigned long ulIntFlags);
  169. extern tBoolean I2CSlaveIntStatus(unsigned long ulBase, tBoolean bMasked);
  170. extern unsigned long I2CSlaveIntStatusEx(unsigned long ulBase,
  171. tBoolean bMasked);
  172. extern unsigned long I2CSlaveStatus(unsigned long ulBase);
  173. //*****************************************************************************
  174. //
  175. // Several I2C APIs have been renamed, with the original function name being
  176. // deprecated. These defines provide backward compatibility.
  177. //
  178. //*****************************************************************************
  179. #ifndef DEPRECATED
  180. #include "driverlib/sysctl.h"
  181. #define I2CMasterInit(a, b) \
  182. I2CMasterInitExpClk(a, SysCtlClockGet(), b)
  183. #endif
  184. //*****************************************************************************
  185. //
  186. // Mark the end of the C bindings section for C++ compilers.
  187. //
  188. //*****************************************************************************
  189. #ifdef __cplusplus
  190. }
  191. #endif
  192. #endif // __I2C_H__