i2c.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //*****************************************************************************
  2. //
  3. // i2c.h - Prototypes for the I2C Driver.
  4. //
  5. // Copyright (c) 2005-2010 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 6459 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_ERROR_STOP \
  64. 0x00000004
  65. #define I2C_MASTER_CMD_BURST_RECEIVE_START \
  66. 0x0000000b
  67. #define I2C_MASTER_CMD_BURST_RECEIVE_CONT \
  68. 0x00000009
  69. #define I2C_MASTER_CMD_BURST_RECEIVE_FINISH \
  70. 0x00000005
  71. #define I2C_MASTER_CMD_BURST_RECEIVE_ERROR_STOP \
  72. 0x00000004
  73. //*****************************************************************************
  74. //
  75. // I2C Master error status.
  76. //
  77. //*****************************************************************************
  78. #define I2C_MASTER_ERR_NONE 0
  79. #define I2C_MASTER_ERR_ADDR_ACK 0x00000004
  80. #define I2C_MASTER_ERR_DATA_ACK 0x00000008
  81. #define I2C_MASTER_ERR_ARB_LOST 0x00000010
  82. //*****************************************************************************
  83. //
  84. // I2C Slave action requests
  85. //
  86. //*****************************************************************************
  87. #define I2C_SLAVE_ACT_NONE 0
  88. #define I2C_SLAVE_ACT_RREQ 0x00000001 // Master has sent data
  89. #define I2C_SLAVE_ACT_TREQ 0x00000002 // Master has requested data
  90. #define I2C_SLAVE_ACT_RREQ_FBR 0x00000005 // Master has sent first byte
  91. //*****************************************************************************
  92. //
  93. // Miscellaneous I2C driver definitions.
  94. //
  95. //*****************************************************************************
  96. #define I2C_MASTER_MAX_RETRIES 1000 // Number of retries
  97. //*****************************************************************************
  98. //
  99. // I2C Slave interrupts.
  100. //
  101. //*****************************************************************************
  102. #define I2C_SLAVE_INT_STOP 0x00000004 // Stop Condition Interrupt.
  103. #define I2C_SLAVE_INT_START 0x00000002 // Start Condition Interrupt.
  104. #define I2C_SLAVE_INT_DATA 0x00000001 // Data Interrupt.
  105. //*****************************************************************************
  106. //
  107. // Prototypes for the APIs.
  108. //
  109. //*****************************************************************************
  110. extern void I2CIntRegister(unsigned long ulBase, void(fnHandler)(void));
  111. extern void I2CIntUnregister(unsigned long ulBase);
  112. extern tBoolean I2CMasterBusBusy(unsigned long ulBase);
  113. extern tBoolean I2CMasterBusy(unsigned long ulBase);
  114. extern void I2CMasterControl(unsigned long ulBase, unsigned long ulCmd);
  115. extern unsigned long I2CMasterDataGet(unsigned long ulBase);
  116. extern void I2CMasterDataPut(unsigned long ulBase, unsigned char ucData);
  117. extern void I2CMasterDisable(unsigned long ulBase);
  118. extern void I2CMasterEnable(unsigned long ulBase);
  119. extern unsigned long I2CMasterErr(unsigned long ulBase);
  120. extern void I2CMasterInitExpClk(unsigned long ulBase, unsigned long ulI2CClk,
  121. tBoolean bFast);
  122. extern void I2CMasterIntClear(unsigned long ulBase);
  123. extern void I2CMasterIntDisable(unsigned long ulBase);
  124. extern void I2CMasterIntEnable(unsigned long ulBase);
  125. extern tBoolean I2CMasterIntStatus(unsigned long ulBase, tBoolean bMasked);
  126. extern void I2CMasterSlaveAddrSet(unsigned long ulBase,
  127. unsigned char ucSlaveAddr,
  128. tBoolean bReceive);
  129. extern unsigned long I2CSlaveDataGet(unsigned long ulBase);
  130. extern void I2CSlaveDataPut(unsigned long ulBase, unsigned char ucData);
  131. extern void I2CSlaveDisable(unsigned long ulBase);
  132. extern void I2CSlaveEnable(unsigned long ulBase);
  133. extern void I2CSlaveInit(unsigned long ulBase, unsigned char ucSlaveAddr);
  134. extern void I2CSlaveIntClear(unsigned long ulBase);
  135. extern void I2CSlaveIntDisable(unsigned long ulBase);
  136. extern void I2CSlaveIntEnable(unsigned long ulBase);
  137. extern void I2CSlaveIntClearEx(unsigned long ulBase, unsigned long ulIntFlags);
  138. extern void I2CSlaveIntDisableEx(unsigned long ulBase,
  139. unsigned long ulIntFlags);
  140. extern void I2CSlaveIntEnableEx(unsigned long ulBase, unsigned long ulIntFlags);
  141. extern tBoolean I2CSlaveIntStatus(unsigned long ulBase, tBoolean bMasked);
  142. extern unsigned long I2CSlaveIntStatusEx(unsigned long ulBase,
  143. tBoolean bMasked);
  144. extern unsigned long I2CSlaveStatus(unsigned long ulBase);
  145. //*****************************************************************************
  146. //
  147. // Several I2C APIs have been renamed, with the original function name being
  148. // deprecated. These defines provide backward compatibility.
  149. //
  150. //*****************************************************************************
  151. #ifndef DEPRECATED
  152. #include "driverlib/sysctl.h"
  153. #define I2CMasterInit(a, b) \
  154. I2CMasterInitExpClk(a, SysCtlClockGet(), b)
  155. #endif
  156. //*****************************************************************************
  157. //
  158. // Mark the end of the C bindings section for C++ compilers.
  159. //
  160. //*****************************************************************************
  161. #ifdef __cplusplus
  162. }
  163. #endif
  164. #endif // __I2C_H__