i2c.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. //*****************************************************************************
  2. //
  3. // i2c.h - Prototypes for the I2C Driver.
  4. //
  5. // Copyright (c) 2005-2009 Luminary Micro, Inc. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Luminary Micro, Inc. (LMI) is supplying this software for use solely and
  9. // exclusively on LMI's microcontroller products.
  10. //
  11. // The software is owned by LMI and/or its suppliers, and is protected under
  12. // applicable copyright laws. All rights are reserved. You may not combine
  13. // this software with "viral" open-source software in order to form a larger
  14. // program. Any use in violation of the foregoing restrictions may subject
  15. // the user to criminal sanctions under applicable laws, as well as to civil
  16. // liability for the breach of the terms and conditions of this license.
  17. //
  18. // THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
  19. // OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
  20. // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
  21. // LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
  22. // CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
  23. //
  24. // This is part of revision 4694 of the Stellaris Peripheral Driver Library.
  25. //
  26. //*****************************************************************************
  27. #ifndef __I2C_H__
  28. #define __I2C_H__
  29. //*****************************************************************************
  30. //
  31. // If building with a C++ compiler, make all of the definitions in this header
  32. // have a C binding.
  33. //
  34. //*****************************************************************************
  35. #ifdef __cplusplus
  36. extern "C"
  37. {
  38. #endif
  39. //*****************************************************************************
  40. //
  41. // Defines for the API.
  42. //
  43. //*****************************************************************************
  44. //*****************************************************************************
  45. //
  46. // Interrupt defines.
  47. //
  48. //*****************************************************************************
  49. #define I2C_INT_MASTER 0x00000001
  50. #define I2C_INT_SLAVE 0x00000002
  51. //*****************************************************************************
  52. //
  53. // I2C Master commands.
  54. //
  55. //*****************************************************************************
  56. #define I2C_MASTER_CMD_SINGLE_SEND 0x00000007
  57. #define I2C_MASTER_CMD_SINGLE_RECEIVE 0x00000007
  58. #define I2C_MASTER_CMD_BURST_SEND_START 0x00000003
  59. #define I2C_MASTER_CMD_BURST_SEND_CONT 0x00000001
  60. #define I2C_MASTER_CMD_BURST_SEND_FINISH 0x00000005
  61. #define I2C_MASTER_CMD_BURST_SEND_ERROR_STOP 0x00000004
  62. #define I2C_MASTER_CMD_BURST_RECEIVE_START 0x0000000b
  63. #define I2C_MASTER_CMD_BURST_RECEIVE_CONT 0x00000009
  64. #define I2C_MASTER_CMD_BURST_RECEIVE_FINISH 0x00000005
  65. #define I2C_MASTER_CMD_BURST_RECEIVE_ERROR_STOP 0x00000005
  66. //*****************************************************************************
  67. //
  68. // I2C Master error status.
  69. //
  70. //*****************************************************************************
  71. #define I2C_MASTER_ERR_NONE 0
  72. #define I2C_MASTER_ERR_ADDR_ACK 0x00000004
  73. #define I2C_MASTER_ERR_DATA_ACK 0x00000008
  74. #define I2C_MASTER_ERR_ARB_LOST 0x00000010
  75. //*****************************************************************************
  76. //
  77. // I2C Slave action requests
  78. //
  79. //*****************************************************************************
  80. #define I2C_SLAVE_ACT_NONE 0
  81. #define I2C_SLAVE_ACT_RREQ 0x00000001 // Master has sent data
  82. #define I2C_SLAVE_ACT_TREQ 0x00000002 // Master has requested data
  83. #define I2C_SLAVE_ACT_RREQ_FBR 0x00000005 // Master has sent first byte
  84. //*****************************************************************************
  85. //
  86. // Miscellaneous I2C driver definitions.
  87. //
  88. //*****************************************************************************
  89. #define I2C_MASTER_MAX_RETRIES 1000 // Number of retries
  90. //*****************************************************************************
  91. //
  92. // I2C Slave interrupts.
  93. //
  94. //*****************************************************************************
  95. #define I2C_SLAVE_INT_STOP 0x00000004 // Stop Condition Interrupt.
  96. #define I2C_SLAVE_INT_START 0x00000002 // Start Condition Interrupt.
  97. #define I2C_SLAVE_INT_DATA 0x00000001 // Data Interrupt.
  98. //*****************************************************************************
  99. //
  100. // Prototypes for the APIs.
  101. //
  102. //*****************************************************************************
  103. extern void I2CIntRegister(unsigned long ulBase, void(fnHandler)(void));
  104. extern void I2CIntUnregister(unsigned long ulBase);
  105. extern tBoolean I2CMasterBusBusy(unsigned long ulBase);
  106. extern tBoolean I2CMasterBusy(unsigned long ulBase);
  107. extern void I2CMasterControl(unsigned long ulBase, unsigned long ulCmd);
  108. extern unsigned long I2CMasterDataGet(unsigned long ulBase);
  109. extern void I2CMasterDataPut(unsigned long ulBase, unsigned char ucData);
  110. extern void I2CMasterDisable(unsigned long ulBase);
  111. extern void I2CMasterEnable(unsigned long ulBase);
  112. extern unsigned long I2CMasterErr(unsigned long ulBase);
  113. extern void I2CMasterInitExpClk(unsigned long ulBase, unsigned long ulI2CClk,
  114. tBoolean bFast);
  115. extern void I2CMasterIntClear(unsigned long ulBase);
  116. extern void I2CMasterIntDisable(unsigned long ulBase);
  117. extern void I2CMasterIntEnable(unsigned long ulBase);
  118. extern tBoolean I2CMasterIntStatus(unsigned long ulBase, tBoolean bMasked);
  119. extern void I2CMasterSlaveAddrSet(unsigned long ulBase,
  120. unsigned char ucSlaveAddr,
  121. tBoolean bReceive);
  122. extern unsigned long I2CSlaveDataGet(unsigned long ulBase);
  123. extern void I2CSlaveDataPut(unsigned long ulBase, unsigned char ucData);
  124. extern void I2CSlaveDisable(unsigned long ulBase);
  125. extern void I2CSlaveEnable(unsigned long ulBase);
  126. extern void I2CSlaveInit(unsigned long ulBase, unsigned char ucSlaveAddr);
  127. extern void I2CSlaveIntClear(unsigned long ulBase);
  128. extern void I2CSlaveIntDisable(unsigned long ulBase);
  129. extern void I2CSlaveIntEnable(unsigned long ulBase);
  130. extern void I2CSlaveIntClearEx(unsigned long ulBase, unsigned long ulIntFlags);
  131. extern void I2CSlaveIntDisableEx(unsigned long ulBase,
  132. unsigned long ulIntFlags);
  133. extern void I2CSlaveIntEnableEx(unsigned long ulBase, unsigned long ulIntFlags);
  134. extern tBoolean I2CSlaveIntStatus(unsigned long ulBase, tBoolean bMasked);
  135. extern unsigned long I2CSlaveIntStatusEx(unsigned long ulBase,
  136. tBoolean bMasked);
  137. extern unsigned long I2CSlaveStatus(unsigned long ulBase);
  138. //*****************************************************************************
  139. //
  140. // Several I2C APIs have been renamed, with the original function name being
  141. // deprecated. These defines provide backward compatibility.
  142. //
  143. //*****************************************************************************
  144. #ifndef DEPRECATED
  145. #include "driverlib/sysctl.h"
  146. #define I2CMasterInit(a, b) \
  147. I2CMasterInitExpClk(a, SysCtlClockGet(), b)
  148. #endif
  149. //*****************************************************************************
  150. //
  151. // Mark the end of the C bindings section for C++ compilers.
  152. //
  153. //*****************************************************************************
  154. #ifdef __cplusplus
  155. }
  156. #endif
  157. #endif // __I2C_H__