hw_i2c_common.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * @brief I2C ROM API declarations and functions
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2014
  6. * All rights reserved.
  7. *
  8. * @par
  9. * Software that is described herein is for illustrative purposes only
  10. * which provides customers with programming information regarding the
  11. * LPC products. This software is supplied "AS IS" without any warranties of
  12. * any kind, and NXP Semiconductors and its licensor disclaim any and
  13. * all warranties, express or implied, including all implied warranties of
  14. * merchantability, fitness for a particular purpose and non-infringement of
  15. * intellectual property rights. NXP Semiconductors assumes no responsibility
  16. * or liability for the use of the software, conveys no license or rights under any
  17. * patent, copyright, mask work right, or any other intellectual property rights in
  18. * or to any products. NXP Semiconductors reserves the right to make changes
  19. * in the software without notification. NXP Semiconductors also makes no
  20. * representation or warranty that such application will be suitable for the
  21. * specified use without further testing or modification.
  22. *
  23. * @par
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors' and its
  26. * licensor's relevant copyrights in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. */
  31. #ifndef __HW_I2C_COMMON_H_
  32. #define __HW_I2C_COMMON_H_
  33. /**
  34. * @brief I2C register block structure
  35. */
  36. typedef struct { /* I2C0 Structure */
  37. volatile uint32_t CFG; /*!< I2C Configuration Register common for Master, Slave and Monitor */
  38. volatile uint32_t STAT; /*!< I2C Status Register common for Master, Slave and Monitor */
  39. volatile uint32_t INTENSET; /*!< I2C Interrupt Enable Set Register common for Master, Slave and Monitor */
  40. volatile uint32_t INTENCLR; /*!< I2C Interrupt Enable Clear Register common for Master, Slave and Monitor */
  41. volatile uint32_t TIMEOUT; /*!< I2C Timeout value Register */
  42. volatile uint32_t CLKDIV; /*!< I2C Clock Divider Register */
  43. volatile uint32_t INTSTAT; /*!< I2C Interrupt Status Register */
  44. volatile uint32_t RESERVED0;
  45. volatile uint32_t MSTCTL; /*!< I2C Master Control Register */
  46. volatile uint32_t MSTTIME; /*!< I2C Master Time Register for SCL */
  47. volatile uint32_t MSTDAT; /*!< I2C Master Data Register */
  48. volatile uint32_t RESERVED1[5];
  49. volatile uint32_t SLVCTL; /*!< I2C Slave Control Register */
  50. volatile uint32_t SLVDAT; /*!< I2C Slave Data Register */
  51. volatile uint32_t SLVADR[4]; /*!< I2C Slave Address Registers */
  52. volatile uint32_t SLVQUAL0; /*!< I2C Slave Address Qualifier 0 Register */
  53. volatile uint32_t RESERVED2[9];
  54. volatile uint32_t MONRXDAT; /*!< I2C Monitor Data Register */
  55. } LPC_I2C_T;
  56. /*
  57. * @brief I2C Configuration register Bit definition
  58. */
  59. #define I2C_CFG_MSTEN (1 << 0) /*!< Master Enable/Disable Bit */
  60. #define I2C_CFG_SLVEN (1 << 1) /*!< Slave Enable/Disable Bit */
  61. #define I2C_CFG_MONEN (1 << 2) /*!< Monitor Enable/Disable Bit */
  62. #define I2C_CFG_TIMEOUTEN (1 << 3) /*!< Timeout Enable/Disable Bit */
  63. #define I2C_CFG_MONCLKSTR (1 << 4) /*!< Monitor Clock Stretching Bit */
  64. #define I2C_CFG_MASK ((uint32_t) 0x1F) /*!< Configuration Register Mask */
  65. /*
  66. * @brief I2C Status register Bit definition
  67. */
  68. #define I2C_STAT_MSTPENDING (1 << 0) /*!< Master Pending Status Bit */
  69. #define I2C_STAT_MSTSTATE (0x7 << 1) /*!< Master State Code */
  70. #define I2C_STAT_MSTRARBLOSS (1 << 4) /*!< Master Arbitration Loss Bit */
  71. #define I2C_STAT_MSTSTSTPERR (1 << 6) /*!< Master Start Stop Error Bit */
  72. #define I2C_STAT_SLVPENDING (1 << 8) /*!< Slave Pending Status Bit */
  73. #define I2C_STAT_SLVSTATE (0x3 << 9) /*!< Slave State Code */
  74. #define I2C_STAT_SLVNOTSTR (1 << 11) /*!< Slave not stretching Clock Bit */
  75. #define I2C_STAT_SLVIDX (0x3 << 12) /*!< Slave Address Index */
  76. #define I2C_STAT_SLVSEL (1 << 14) /*!< Slave Selected Bit */
  77. #define I2C_STAT_SLVDESEL (1 << 15) /*!< Slave Deselect Bit */
  78. #define I2C_STAT_MONRDY (1 << 16) /*!< Monitor Ready Bit */
  79. #define I2C_STAT_MONOV (1 << 17) /*!< Monitor Overflow Flag */
  80. #define I2C_STAT_MONACTIVE (1 << 18) /*!< Monitor Active Flag */
  81. #define I2C_STAT_MONIDLE (1 << 19) /*!< Monitor Idle Flag */
  82. #define I2C_STAT_EVENTTIMEOUT (1 << 24) /*!< Event Timeout Interrupt Flag */
  83. #define I2C_STAT_SCLTIMEOUT (1 << 25) /*!< SCL Timeout Interrupt Flag */
  84. #define I2C_STAT_MSTCODE_IDLE (0) /*!< Master Idle State Code */
  85. #define I2C_STAT_MSTCODE_RXREADY (1) /*!< Master Receive Ready State Code */
  86. #define I2C_STAT_MSTCODE_TXREADY (2) /*!< Master Transmit Ready State Code */
  87. #define I2C_STAT_MSTCODE_NACKADR (3) /*!< Master NACK by slave on address State Code */
  88. #define I2C_STAT_MSTCODE_NACKDAT (4) /*!< Master NACK by slave on data State Code */
  89. #define I2C_STAT_SLVCODE_ADDR (0) /*!< Master Idle State Code */
  90. #define I2C_STAT_SLVCODE_RX (1) /*!< Received data is available Code */
  91. #define I2C_STAT_SLVCODE_TX (2) /*!< Data can be transmitted Code */
  92. /*
  93. * @brief I2C Interrupt Enable Set register Bit definition
  94. */
  95. #define I2C_INTENSET_MSTPENDING (1 << 0) /*!< Master Pending Interrupt Enable Bit */
  96. #define I2C_INTENSET_MSTRARBLOSS (1 << 4) /*!< Master Arbitration Loss Interrupt Enable Bit */
  97. #define I2C_INTENSET_MSTSTSTPERR (1 << 6) /*!< Master Start Stop Error Interrupt Enable Bit */
  98. #define I2C_INTENSET_SLVPENDING (1 << 8) /*!< Slave Pending Interrupt Enable Bit */
  99. #define I2C_INTENSET_SLVNOTSTR (1 << 11) /*!< Slave not stretching Clock Interrupt Enable Bit */
  100. #define I2C_INTENSET_SLVDESEL (1 << 15) /*!< Slave Deselect Interrupt Enable Bit */
  101. #define I2C_INTENSET_MONRDY (1 << 16) /*!< Monitor Ready Interrupt Enable Bit */
  102. #define I2C_INTENSET_MONOV (1 << 17) /*!< Monitor Overflow Interrupt Enable Bit */
  103. #define I2C_INTENSET_MONIDLE (1 << 19) /*!< Monitor Idle Interrupt Enable Bit */
  104. #define I2C_INTENSET_EVENTTIMEOUT (1 << 24) /*!< Event Timeout Interrupt Enable Bit */
  105. #define I2C_INTENSET_SCLTIMEOUT (1 << 25) /*!< SCL Timeout Interrupt Enable Bit */
  106. /*
  107. * @brief I2C Interrupt Enable Clear register Bit definition
  108. */
  109. #define I2C_INTENCLR_MSTPENDING (1 << 0) /*!< Master Pending Interrupt Clear Bit */
  110. #define I2C_INTENCLR_MSTRARBLOSS (1 << 4) /*!< Master Arbitration Loss Interrupt Clear Bit */
  111. #define I2C_INTENCLR_MSTSTSTPERR (1 << 6) /*!< Master Start Stop Error Interrupt Clear Bit */
  112. #define I2C_INTENCLR_SLVPENDING (1 << 8) /*!< Slave Pending Interrupt Clear Bit */
  113. #define I2C_INTENCLR_SLVNOTSTR (1 << 11) /*!< Slave not stretching Clock Interrupt Clear Bit */
  114. #define I2C_INTENCLR_SLVDESEL (1 << 15) /*!< Slave Deselect Interrupt Clear Bit */
  115. #define I2C_INTENCLR_MONRDY (1 << 16) /*!< Monitor Ready Interrupt Clear Bit */
  116. #define I2C_INTENCLR_MONOV (1 << 17) /*!< Monitor Overflow Interrupt Clear Bit */
  117. #define I2C_INTENCLR_MONIDLE (1 << 19) /*!< Monitor Idle Interrupt Clear Bit */
  118. #define I2C_INTENCLR_EVENTTIMEOUT (1 << 24) /*!< Event Timeout Interrupt Clear Bit */
  119. #define I2C_INTENCLR_SCLTIMEOUT (1 << 25) /*!< SCL Timeout Interrupt Clear Bit */
  120. /*
  121. * @brief I2C TimeOut Value Macro
  122. */
  123. #define I2C_TIMEOUT_VAL(n) (((uint32_t) ((n) - 1) & 0xFFF0) | 0x000F) /*!< Macro for Timeout value register */
  124. /*
  125. * @brief I2C Interrupt Status register Bit definition
  126. */
  127. #define I2C_INTSTAT_MSTPENDING (1 << 0) /*!< Master Pending Interrupt Status Bit */
  128. #define I2C_INTSTAT_MSTRARBLOSS (1 << 4) /*!< Master Arbitration Loss Interrupt Status Bit */
  129. #define I2C_INTSTAT_MSTSTSTPERR (1 << 6) /*!< Master Start Stop Error Interrupt Status Bit */
  130. #define I2C_INTSTAT_SLVPENDING (1 << 8) /*!< Slave Pending Interrupt Status Bit */
  131. #define I2C_INTSTAT_SLVNOTSTR (1 << 11) /*!< Slave not stretching Clock Interrupt Status Bit */
  132. #define I2C_INTSTAT_SLVDESEL (1 << 15) /*!< Slave Deselect Interrupt Status Bit */
  133. #define I2C_INTSTAT_MONRDY (1 << 16) /*!< Monitor Ready Interrupt Status Bit */
  134. #define I2C_INTSTAT_MONOV (1 << 17) /*!< Monitor Overflow Interrupt Status Bit */
  135. #define I2C_INTSTAT_MONIDLE (1 << 19) /*!< Monitor Idle Interrupt Status Bit */
  136. #define I2C_INTSTAT_EVENTTIMEOUT (1 << 24) /*!< Event Timeout Interrupt Status Bit */
  137. #define I2C_INTSTAT_SCLTIMEOUT (1 << 25) /*!< SCL Timeout Interrupt Status Bit */
  138. /*
  139. * @brief I2C Master Control register Bit definition
  140. */
  141. #define I2C_MSTCTL_MSTCONTINUE (1 << 0) /*!< Master Continue Bit */
  142. #define I2C_MSTCTL_MSTSTART (1 << 1) /*!< Master Start Control Bit */
  143. #define I2C_MSTCTL_MSTSTOP (1 << 2) /*!< Master Stop Control Bit */
  144. #define I2C_MSTCTL_MSTDMA (1 << 3) /*!< Master DMA Enable Bit */
  145. /*
  146. * @brief I2C Master Time Register Field definition
  147. */
  148. #define I2C_MSTTIME_MSTSCLLOW (0x07 << 0) /*!< Master SCL Low Time field */
  149. #define I2C_MSTTIME_MSTSCLHIGH (0x07 << 4) /*!< Master SCL High Time field */
  150. /*
  151. * @brief I2C Master Data Mask
  152. */
  153. #define I2C_MSTDAT_DATAMASK ((uint32_t) 0x00FF << 0) /*!< Master data mask */
  154. /*
  155. * @brief I2C Slave Control register Bit definition
  156. */
  157. #define I2C_SLVCTL_SLVCONTINUE (1 << 0) /*!< Slave Continue Bit */
  158. #define I2C_SLVCTL_SLVNACK (1 << 1) /*!< Slave NACK Bit */
  159. #define I2C_SLVCTL_SLVDMA (1 << 3) /*!< Slave DMA Enable Bit */
  160. /*
  161. * @brief I2C Slave Data Mask
  162. */
  163. #define I2C_SLVDAT_DATAMASK ((uint32_t) 0x00FF << 0) /*!< Slave data mask */
  164. /*
  165. * @brief I2C Slave Address register Bit definition
  166. */
  167. #define I2C_SLVADR_SADISABLE (1 << 0) /*!< Slave Address n Disable Bit */
  168. #define I2C_SLVADR_SLVADR (0x7F << 1) /*!< Slave Address field */
  169. #define I2C_SLVADR_MASK ((uint32_t) 0x00FF) /*!< Slave Address Mask */
  170. /*
  171. * @brief I2C Slave Address Qualifier 0 Register Bit definition
  172. */
  173. #define I2C_SLVQUAL_QUALMODE0 (1 << 0) /*!< Slave Qualifier Mode Enable Bit */
  174. #define I2C_SLVQUAL_SLVQUAL0 (0x7F << 1) /*!< Slave Qualifier Address for Address 0 */
  175. /*
  176. * @brief I2C Monitor Data Register Bit definition
  177. */
  178. #define I2C_MONRXDAT_DATA (0xFF << 0) /*!< Monitor Function Receive Data Field */
  179. #define I2C_MONRXDAT_MONSTART (1 << 8) /*!< Monitor Received Start Bit */
  180. #define I2C_MONRXDAT_MONRESTART (1 << 9) /*!< Monitor Received Repeated Start Bit */
  181. #define I2C_MONRXDAT_MONNACK (1 << 10) /*!< Monitor Received Nack Bit */
  182. #endif /* __HW_I2C_COMMON_H_ */