I2C_LPC18xx.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* --------------------------------------------------------------------------
  2. * Copyright (c) 2013-2016 ARM Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * $Date: 02. March 2016
  19. * $Revision: V2.1
  20. *
  21. * Project: I2C Driver Definitions for NXP LPC18xx
  22. * -------------------------------------------------------------------------- */
  23. #ifndef __I2C_LPC18XX_H
  24. #define __I2C_LPC18XX_H
  25. #include "LPC18xx.h"
  26. #include "Driver_I2C.h"
  27. /* Clock Control Unit register */
  28. #define CCU_CLK_CFG_RUN (1 << 0)
  29. #define CCU_CLK_CFG_AUTO (1 << 1)
  30. #define CCU_CLK_STAT_RUN (1 << 0)
  31. #define CLK_SRC_PLL1 0x09 // I2C clock source
  32. /* I2C reset value for RGU */
  33. #define RGU_RESET_I2C0 (1 << 16) // I2C0 reset
  34. #define RGU_RESET_I2C1 (1 << 17) // I2C1 reset
  35. /* I2C Driver state flags */
  36. #define I2C_FLAG_INIT (1 << 0) // Driver initialized
  37. #define I2C_FLAG_POWER (1 << 1) // Driver power on
  38. #define I2C_FLAG_SETUP (1 << 2) // Master configured, clock set
  39. #define I2C_FLAG_SLAVE_RX (1 << 3) // Slave receive registered
  40. /* I2C Common Control flags */
  41. #define I2C_CON_AA (1 << 2) // Assert acknowledge bit
  42. #define I2C_CON_SI (1 << 3) // I2C interrupt bit
  43. #define I2C_CON_STO (1 << 4) // STOP bit
  44. #define I2C_CON_STA (1 << 5) // START bit
  45. #define I2C_CON_I2EN (1 << 6) // I2C interface enable
  46. #define I2C_CON_FLAGS (I2C_CON_AA | I2C_CON_SI | I2C_CON_STO | I2C_CON_STA)
  47. /* I2C Stalled Status flags */
  48. #define I2C_MASTER (1 << 0) // Master stalled
  49. #define I2C_SLAVE_TX (1 << 1) // Slave stalled on transmit
  50. #define I2C_SLAVE_RX (1 << 2) // Slave stalled on receive
  51. #define I2C_SLAVE (I2C_SLAVE_TX | I2C_SLAVE_RX)
  52. /* I2C Status Miscellaneous states */
  53. #define I2C_STAT_BUSERR 0x00 // I2C Bus error
  54. /* I2C Status Master mode */
  55. #define I2C_STAT_MA_START 0x08 // START transmitted
  56. #define I2C_STAT_MA_RSTART 0x10 // Repeated START transmitted
  57. #define I2C_STAT_MA_SLAW_A 0x18 // SLA+W transmitted, ACK received
  58. #define I2C_STAT_MA_SLAW_NA 0x20 // SLA+W transmitted, no ACK recvd
  59. #define I2C_STAT_MA_DT_A 0x28 // Data transmitted, ACK received
  60. #define I2C_STAT_MA_DT_NA 0x30 // Data transmitted, no ACK recvd
  61. #define I2C_STAT_MA_ALOST 0x38 // Arbitration lost SLA+W or data
  62. #define I2C_STAT_MA_SLAR_A 0x40 // SLA+R transmitted, ACK received
  63. #define I2C_STAT_MA_SLAR_NA 0x48 // SLA+R transmitted, no ACK recvd
  64. #define I2C_STAT_MA_DR_A 0x50 // Data received, ACK returned
  65. #define I2C_STAT_MA_DR_NA 0x58 // Data received, no ACK returned
  66. /* I2C Status Slave mode */
  67. #define I2C_STAT_SL_SLAW_A 0x60 // SLA+W received, ACK returned
  68. #define I2C_STAT_SL_ALOST_MW 0x68 // Arbitration lost SLA+W in Master mode
  69. #define I2C_STAT_SL_GCA_A 0x70 // General address recvd, ACK returned
  70. #define I2C_STAT_SL_ALOST_GC 0x78 // Arbitration lost in General call
  71. #define I2C_STAT_SL_DR_A 0x80 // Data received, ACK returned
  72. #define I2C_STAT_SL_DR_NA 0x88 // Data received, no ACK returned
  73. #define I2C_STAT_SL_DRGC_A 0x90 // Data recvd General call, ACK returned
  74. #define I2C_STAT_SL_DRGC_NA 0x98 // Data recvd General call, no ACK returned
  75. #define I2C_STAT_SL_STOP 0xA0 // STOP received while addressed
  76. #define I2C_STAT_SL_SLAR_A 0xA8 // SLA+R received, ACK returned
  77. #define I2C_STAT_SL_ALOST_MR 0xB0 // Arbitration lost SLA+R in Master mode
  78. #define I2C_STAT_SL_DT_A 0xB8 // Data transmitted, ACK received
  79. #define I2C_STAT_SL_DT_NA 0xC0 // Data transmitted, no ACK received
  80. #define I2C_STAT_SL_LDT_A 0xC8 // Last data transmitted, ACK received
  81. /* I2C Control Information */
  82. typedef struct {
  83. ARM_I2C_SignalEvent_t cb_event; // Event callback
  84. ARM_I2C_STATUS status; // Status flags
  85. uint8_t flags; // Control and state flags
  86. uint8_t sla_rw; // Slave address and RW bit
  87. bool pending; // Transfer pending (no STOP)
  88. uint8_t stalled; // Stall mode status flags
  89. uint8_t con_aa; // I2C slave CON flag
  90. int32_t cnt; // Master transfer count
  91. uint8_t *data; // Master data to transfer
  92. uint32_t num; // Number of bytes to transfer
  93. uint8_t *sdata; // Slave data to transfer
  94. uint32_t snum; // Number of bytes to transfer
  95. } I2C_CTRL;
  96. /* I2C Resource Configuration */
  97. typedef struct {
  98. LPC_I2Cn_Type *reg; // I2C register interface
  99. IRQn_Type i2c_ev_irq; // I2C Event IRQ Number
  100. volatile uint32_t *base_clk_reg; // Base clock register
  101. volatile uint32_t *pclk_cfg_reg; // Peripheral clock config register
  102. const volatile uint32_t *pclk_stat_reg; // Peripheral clock status register
  103. uint32_t rgu_val; // Peripheral reset value
  104. I2C_CTRL *ctrl; // Run-Time control information
  105. } const I2C_RESOURCES;
  106. #endif /* __I2C_LPC18XX_H */