i2c.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /** @file I2C.h
  2. * @brief I2C Driver Definition File
  3. * @date 29.May.2013
  4. * @version 03.05.02
  5. *
  6. */
  7. /* (c) Texas Instruments 2009-2013, All rights reserved. */
  8. #ifndef __I2C_H__
  9. #define __I2C_H__
  10. #include "reg_i2c.h"
  11. /** @enum i2cMode
  12. * @brief Alias names for i2c modes
  13. * This enumeration is used to provide alias names for I2C modes:
  14. */
  15. enum i2cMode
  16. {
  17. I2C_FD_FORMAT = 0x0008U, /* Free Data Format */
  18. I2C_START_BYTE = 0x0010U,
  19. I2C_RESET_OUT = 0x0020U, I2C_RESET_IN = 0x0000U,
  20. I2C_DLOOPBACK = 0x0040U,
  21. I2C_REPEATMODE = 0x0080U, /* In Master Mode only */
  22. I2C_10BIT_AMODE = 0x0100U, I2C_7BIT_AMODE = 0x0000U,
  23. I2C_TRANSMITTER = 0x0200U, I2C_RECEIVER = 0x0000U,
  24. I2C_MASTER = 0x0400U, I2C_SLAVE = 0x0000U,
  25. I2C_STOP_COND = 0x0800U, /* In Master Mode only */
  26. I2C_START_COND = 0x2000U, /* In Master Mode only */
  27. I2C_FREE_RUN = 0x4000U,
  28. I2C_NACK_MODE = 0x8000U
  29. };
  30. /** @enum i2cBitCount
  31. * @brief Alias names for i2c bit count
  32. * This enumeration is used to provide alias names for I2C bit count:
  33. */
  34. enum i2cBitCount
  35. {
  36. I2C_2_BIT = 0x2U,
  37. I2C_3_BIT = 0x3U,
  38. I2C_4_BIT = 0x4U,
  39. I2C_5_BIT = 0x5U,
  40. I2C_6_BIT = 0x6U,
  41. I2C_7_BIT = 0x7U,
  42. I2C_8_BIT = 0x0U
  43. };
  44. /** @enum i2cIntFlags
  45. * @brief Interrupt Flag Definitions
  46. *
  47. * Used with I2CEnableNotification, I2CDisableNotification
  48. */
  49. enum i2cIntFlags
  50. {
  51. I2C_AL_INT = 0x0001U, /* arbitration lost */
  52. I2C_NACK_INT = 0x0002U, /* no acknowledgment */
  53. I2C_ARDY_INT = 0x0004U, /* access ready */
  54. I2C_RX_INT = 0x0008U, /* receive data ready */
  55. I2C_TX_INT = 0x0010U, /* transmit data ready */
  56. I2C_SCD_INT = 0x0020U, /* stop condition detect */
  57. I2C_AAS_INT = 0x0040U /* address as slave */
  58. };
  59. /** @enum i2cStatFlags
  60. * @brief Interrupt Status Definitions
  61. *
  62. */
  63. enum i2cStatFlags
  64. {
  65. I2C_AL = 0x0001U, /* arbitration lost */
  66. I2C_NACK = 0x0002U, /* no acknowledgement */
  67. I2C_ARDY = 0x0004U, /* access ready */
  68. I2C_RX = 0x0008U, /* receive data ready */
  69. I2C_TX = 0x0010U, /* transmit data ready */
  70. I2C_SCD = 0x0020U, /* stop condition detect */
  71. I2C_AD0 = 0x0100U, /* address Zero Status */
  72. I2C_AAS = 0x0200U, /* address as slave */
  73. I2C_XSMT = 0x0400U, /* Transmit shift empty not */
  74. I2C_RXFULL = 0x0800U, /* receive full */
  75. I2C_BUSBUSY = 0x1000U, /* bus busy */
  76. I2C_NACKSNT = 0x2000U, /* No Ack Sent */
  77. I2C_SDIR = 0x4000U /* Slave Direction */
  78. };
  79. /** @enum i2cDMA
  80. * @brief I2C DMA definitions
  81. *
  82. * Used before i2c transfer
  83. */
  84. enum i2cDMA
  85. {
  86. I2C_TXDMA = 0x20U,
  87. I2C_RXDMA = 0x10U
  88. };
  89. /**
  90. * @defgroup I2C I2C
  91. * @brief Inter-Integrated Circuit Module.
  92. *
  93. * The I2C is a multi-master communication module providing an interface between the Texas Instruments (TI) microcontroller
  94. * and devices compliant with Philips Semiconductor I2C-bus specification version 2.1 and connected by an I2Cbus.
  95. * This module will support any slave or master I2C compatible device.
  96. *
  97. * Related Files
  98. * - reg_i2c.h
  99. * - i2c.h
  100. * - i2c.c
  101. * @addtogroup I2C
  102. * @{
  103. */
  104. /* I2C Interface Functions */
  105. void i2cInit(void);
  106. void i2cSetOwnAdd(i2cBASE_t *i2c, uint32 oadd);
  107. void i2cSetSlaveAdd(i2cBASE_t *i2c, uint32 sadd);
  108. void i2cSetBaudrate(i2cBASE_t *i2c, uint32 baud);
  109. uint32 i2cIsTxReady(i2cBASE_t *i2c);
  110. void i2cSendByte(i2cBASE_t *i2c, uint8 byte);
  111. void i2cSend(i2cBASE_t *i2c, uint32 length, uint8 * data);
  112. uint32 i2cIsRxReady(i2cBASE_t *i2c);
  113. void i2cClearSCD(i2cBASE_t *i2c);
  114. uint32 i2cRxError(i2cBASE_t *i2c);
  115. uint32 i2cReceiveByte(i2cBASE_t *i2c);
  116. void i2cReceive(i2cBASE_t *i2c, uint32 length, uint8 * data);
  117. void i2cEnableNotification(i2cBASE_t *i2c, uint32 flags);
  118. void i2cDisableNotification(i2cBASE_t *i2c, uint32 flags);
  119. void i2cSetStart(i2cBASE_t *i2c);
  120. void i2cSetStop(i2cBASE_t *i2c);
  121. void i2cSetCount(i2cBASE_t *i2c ,uint32 cnt);
  122. void i2cEnableLoopback(i2cBASE_t *i2c);
  123. void i2cDisableLoopback(i2cBASE_t *i2c);
  124. /** @fn void i2cNotification(i2cBASE_t *i2c, uint32 flags)
  125. * @brief Interrupt callback
  126. * @param[in] i2c - I2C module base address
  127. * @param[in] flags - copy of error interrupt flags
  128. *
  129. * This is a callback that is provided by the application and is called apon
  130. * an interrupt. The parameter passed to the callback is a copy of the
  131. * interrupt flag register.
  132. */
  133. void i2cNotification(i2cBASE_t *i2c, uint32 flags);
  134. /**@}*/
  135. #endif