27 #ifndef LPC17XX_I2C_H_
28 #define LPC17XX_I2C_H_
50 #define I2C_I2CONSET_AA ((0x04))
51 #define I2C_I2CONSET_SI ((0x08))
52 #define I2C_I2CONSET_STO ((0x10))
53 #define I2C_I2CONSET_STA ((0x20))
54 #define I2C_I2CONSET_I2EN ((0x40))
60 #define I2C_I2CONCLR_AAC ((1<<2))
62 #define I2C_I2CONCLR_SIC ((1<<3))
64 #define I2C_I2CONCLR_STAC ((1<<5))
66 #define I2C_I2CONCLR_I2ENC ((1<<6))
72 #define I2C_STAT_CODE_BITMASK ((0xF8))
77 #define I2C_I2STAT_NO_INF ((0xF8))
81 #define I2C_I2STAT_M_TX_START ((0x08))
83 #define I2C_I2STAT_M_TX_RESTART ((0x10))
85 #define I2C_I2STAT_M_TX_SLAW_ACK ((0x18))
87 #define I2C_I2STAT_M_TX_SLAW_NACK ((0x20))
89 #define I2C_I2STAT_M_TX_DAT_ACK ((0x28))
91 #define I2C_I2STAT_M_TX_DAT_NACK ((0x30))
93 #define I2C_I2STAT_M_TX_ARB_LOST ((0x38))
97 #define I2C_I2STAT_M_RX_START ((0x08))
99 #define I2C_I2STAT_M_RX_RESTART ((0x10))
101 #define I2C_I2STAT_M_RX_ARB_LOST ((0x38))
103 #define I2C_I2STAT_M_RX_SLAR_ACK ((0x40))
105 #define I2C_I2STAT_M_RX_SLAR_NACK ((0x48))
107 #define I2C_I2STAT_M_RX_DAT_ACK ((0x50))
109 #define I2C_I2STAT_M_RX_DAT_NACK ((0x58))
113 #define I2C_I2STAT_S_RX_SLAW_ACK ((0x60))
116 #define I2C_I2STAT_S_RX_ARB_LOST_M_SLA ((0x68))
121 #define I2C_I2STAT_S_RX_GENCALL_ACK ((0x70))
124 #define I2C_I2STAT_S_RX_ARB_LOST_M_GENCALL ((0x78))
130 #define I2C_I2STAT_S_RX_PRE_SLA_DAT_ACK ((0x80))
133 #define I2C_I2STAT_S_RX_PRE_SLA_DAT_NACK ((0x88))
136 #define I2C_I2STAT_S_RX_PRE_GENCALL_DAT_ACK ((0x90))
139 #define I2C_I2STAT_S_RX_PRE_GENCALL_DAT_NACK ((0x98))
143 #define I2C_I2STAT_S_RX_STA_STO_SLVREC_SLVTRX ((0xA0))
147 #define I2C_I2STAT_S_TX_SLAR_ACK ((0xA8))
150 #define I2C_I2STAT_S_TX_ARB_LOST_M_SLA ((0xB0))
155 #define I2C_I2STAT_S_TX_DAT_ACK ((0xB8))
157 #define I2C_I2STAT_S_TX_DAT_NACK ((0xC0))
160 #define I2C_I2STAT_S_TX_LAST_DAT_ACK ((0xC8))
163 #define I2C_SLAVE_TIME_OUT 0x10000UL
169 #define I2C_I2DAT_BITMASK ((0xFF))
174 #define I2C_I2DAT_IDLE_CHAR (0xFF)
179 #define I2C_I2MMCTRL_MM_ENA ((1<<0))
180 #define I2C_I2MMCTRL_ENA_SCL ((1<<1))
181 #define I2C_I2MMCTRL_MATCH_ALL ((1<<2))
182 #define I2C_I2MMCTRL_BITMASK ((0x07))
188 #define I2DATA_BUFFER_BITMASK ((0xFF))
194 #define I2C_I2ADR_GC ((1<<0))
196 #define I2C_I2ADR_BITMASK ((0xFF))
202 #define I2C_I2MASK_MASK(n) ((n&0xFE))
208 #define I2C_I2SCLH_BITMASK ((0xFFFF))
214 #define I2C_I2SCLL_BITMASK ((0xFFFF))
217 #define I2C_SETUP_STATUS_ARBF (1<<8)
218 #define I2C_SETUP_STATUS_NOACKF (1<<9)
219 #define I2C_SETUP_STATUS_DONE (1<<10)
224 #define I2C_MONITOR_CFG_SCL_OUTPUT I2C_I2MMCTRL_ENA_SCL
225 #define I2C_MONITOR_CFG_MATCHALL I2C_I2MMCTRL_MATCH_ALL
229 #define PARAM_I2C_SLAVEADDR_CH(n) ((n>=0) && (n<=3))
232 #define PARAM_I2Cx(n) ((((uint32_t *)n)==((uint32_t *)LPC_I2C0)) \
233 || (((uint32_t *)n)==((uint32_t *)LPC_I2C1)) \
234 || (((uint32_t *)n)==((uint32_t *)LPC_I2C2)))
237 #define PARAM_I2C_MONITOR_CFG(n) ((n==I2C_MONITOR_CFG_SCL_OUTPUT) || (I2C_MONITOR_CFG_MATCHALL))
293 void (*callback)(void);
310 void (*callback)(void);