1 /******************************************************************************
2 *
3 * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
4 * Analog Devices, Inc.),
5 * Copyright (C) 2023-2024 Analog Devices, Inc.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 ******************************************************************************/
20
21 #include <stdio.h>
22 #include <stddef.h>
23 #include <stdint.h>
24 #include "mxc_device.h"
25 #include "mxc_assert.h"
26 #include "mxc_lock.h"
27 #include "mxc_sys.h"
28 #include "mxc_delay.h"
29 #include "i2c_regs.h"
30 #include "dma_regs.h"
31 #include "i2c.h"
32 #include "i2c_reva.h"
33
34 /* **** Definitions **** */
35 #define MXC_I2C_MAX_ADDR_WIDTH 0x7F
36
37 /*
38 * These definitions are used to set the slave address register
39 * for MAX32672 Rev. A parts. MAX32672 Rev.B was updated to use
40 * the i2c_reva_regs.h register set.
41 */
42 #define SLAVE_A1_REG_OFFSET ((uint32_t)0x44UL) /**< SLAVE_A1_REG_OFFSET */
43
44 #define SLAVE_A1_ADDR_POS 0 /**< SLAVE_A1_ADDR Position */
45 #define SLAVE_A1_ADDR ((uint32_t)(0x3FFUL << SLAVE_A1_ADDR_POS)) /**< SLAVE_A1_ADDR Mask */
46
47 #define SLAVE_A1_DIS_POS 10 /**< SLAVE_A1_DIS Position */
48 #define SLAVE_A1_DIS ((uint32_t)(0x1UL << SLAVE_A1_DIS_POS)) /**< SLAVE_A1_DIS Mask */
49
50 #define SLAVE_A1_IDX_POS 11 /**< SLAVE_A1_IDX Position */
51 #define SLAVE_A1_IDX ((uint32_t)(0x3UL << SLAVE_A1_IDX_POS)) /**< SLAVE_A1_IDX Mask */
52
53 #define SLAVE_A1_EXT_ADDR_EN_POS 15 /**< SLAVE_A1_EXT_ADDR_EN Position */
54 #define SLAVE_A1_EXT_ADDR_EN \
55 ((uint32_t)(0x1UL << SLAVE_A1_EXT_ADDR_EN_POS)) /**< SLAVE_A1_EXT_ADDR_EN Mask */
56
57 /* **** Variable Declaration **** */
58 uint32_t interruptCheck = MXC_F_I2C_INTFL0_ADDR_MATCH | MXC_F_I2C_INTFL0_DNR_ERR;
59
60 /* **** Function Prototypes **** */
61
62 /* ************************************************************************* */
63 /* Control/Configuration functions */
64 /* ************************************************************************* */
MXC_I2C_Init(mxc_i2c_regs_t * i2c,int masterMode,unsigned int slaveAddr)65 int MXC_I2C_Init(mxc_i2c_regs_t *i2c, int masterMode, unsigned int slaveAddr)
66 {
67 if (i2c == NULL) {
68 return E_NULL_PTR;
69 }
70
71 #ifndef MSDK_NO_GPIO_CLK_INIT
72 MXC_I2C_Shutdown(i2c); // Clear everything out
73
74 if (i2c == MXC_I2C0) {
75 MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_I2C0);
76 MXC_GPIO_Config(&gpio_cfg_i2c0);
77 } else if (i2c == MXC_I2C1) {
78 MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_I2C1);
79 MXC_GPIO_Config(&gpio_cfg_i2c1);
80 } else if (i2c == MXC_I2C2) {
81 MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_I2C2);
82 MXC_GPIO_Config(&gpio_cfg_i2c2);
83 } else {
84 return E_NO_DEVICE;
85 }
86 #endif // MSDK_NO_GPIO_CLK_INIT
87
88 return MXC_I2C_RevA_Init((mxc_i2c_reva_regs_t *)i2c, masterMode, slaveAddr);
89 }
90
MXC_I2C_SetSlaveAddr(mxc_i2c_regs_t * i2c,unsigned int slaveAddr,int idx)91 int MXC_I2C_SetSlaveAddr(mxc_i2c_regs_t *i2c, unsigned int slaveAddr, int idx)
92 {
93 if ((MXC_SYS_GetRevision() & 0xF0) == 0xB0) {
94 // Use multi-slave for MAX32672 Rev. B parts
95 return MXC_I2C_RevA_SetSlaveAddr((mxc_i2c_reva_regs_t *)i2c, slaveAddr, idx);
96 } else {
97 // Use single-slave for MAX32672 Rev. A parts
98 if (i2c == NULL) {
99 return E_NULL_PTR;
100 }
101
102 if (idx >= MXC_I2C_NUM_TARGET_ADDR) {
103 return E_NOT_SUPPORTED;
104 }
105
106 if (slaveAddr > SLAVE_A1_ADDR) {
107 // Only support addresses up to 10 bits
108 return E_BAD_PARAM;
109 }
110
111 uint32_t *slave_a1 = (uint32_t *)((uint32_t)i2c + SLAVE_A1_REG_OFFSET);
112
113 // Set the slave address to operate on
114 MXC_SETFIELD((*slave_a1), SLAVE_A1_IDX, (idx << SLAVE_A1_IDX_POS));
115
116 if (slaveAddr > MXC_I2C_MAX_ADDR_WIDTH) {
117 // Set for 10bit addressing mode
118 *slave_a1 |= SLAVE_A1_EXT_ADDR_EN;
119 } else {
120 // Clear for 7bit addressing mode
121 *slave_a1 &= ~SLAVE_A1_EXT_ADDR_EN;
122 }
123
124 // Set the slave address
125 MXC_SETFIELD((*slave_a1), SLAVE_A1_ADDR, (slaveAddr << SLAVE_A1_ADDR_POS));
126
127 // Enable the slave address
128 *slave_a1 &= ~SLAVE_A1_DIS;
129 }
130
131 return E_NO_ERROR;
132 }
133
MXC_I2C_Shutdown(mxc_i2c_regs_t * i2c)134 int MXC_I2C_Shutdown(mxc_i2c_regs_t *i2c)
135 {
136 // Configure GPIO for I2C
137 if (i2c == MXC_I2C0) {
138 MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_I2C0);
139 MXC_SYS_Reset_Periph(MXC_SYS_RESET0_I2C0);
140 } else if (i2c == MXC_I2C1) {
141 MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_I2C1);
142 MXC_SYS_Reset_Periph(MXC_SYS_RESET1_I2C1);
143 } else if (i2c == MXC_I2C2) {
144 MXC_SYS_ClockDisable(MXC_SYS_PERIPH_CLOCK_I2C2);
145 MXC_SYS_Reset_Periph(MXC_SYS_RESET1_I2C2);
146 } else {
147 return E_NO_DEVICE;
148 }
149
150 return MXC_I2C_RevA_Shutdown((mxc_i2c_reva_regs_t *)i2c);
151 }
152
MXC_I2C_Reset(mxc_i2c_regs_t * i2c)153 int MXC_I2C_Reset(mxc_i2c_regs_t *i2c)
154 {
155 // Configure GPIO for I2C
156 if (i2c == MXC_I2C0) {
157 MXC_SYS_Reset_Periph(MXC_SYS_RESET0_I2C0);
158 } else if (i2c == MXC_I2C1) {
159 MXC_SYS_Reset_Periph(MXC_SYS_RESET1_I2C1);
160 } else if (i2c == MXC_I2C2) {
161 MXC_SYS_Reset_Periph(MXC_SYS_RESET1_I2C2);
162 } else {
163 return E_NO_DEVICE;
164 }
165
166 return E_NO_ERROR;
167 }
168
MXC_I2C_SetFrequency(mxc_i2c_regs_t * i2c,unsigned int hz)169 int MXC_I2C_SetFrequency(mxc_i2c_regs_t *i2c, unsigned int hz)
170 {
171 return MXC_I2C_RevA_SetFrequency((mxc_i2c_reva_regs_t *)i2c, hz);
172 }
173
MXC_I2C_GetFrequency(mxc_i2c_regs_t * i2c)174 unsigned int MXC_I2C_GetFrequency(mxc_i2c_regs_t *i2c)
175 {
176 return MXC_I2C_RevA_GetFrequency((mxc_i2c_reva_regs_t *)i2c);
177 }
178
MXC_I2C_ReadyForSleep(mxc_i2c_regs_t * i2c)179 int MXC_I2C_ReadyForSleep(mxc_i2c_regs_t *i2c)
180 {
181 return MXC_I2C_RevA_ReadyForSleep((mxc_i2c_reva_regs_t *)i2c);
182 }
183
MXC_I2C_SetClockStretching(mxc_i2c_regs_t * i2c,int enable)184 int MXC_I2C_SetClockStretching(mxc_i2c_regs_t *i2c, int enable)
185 {
186 return MXC_I2C_RevA_SetClockStretching((mxc_i2c_reva_regs_t *)i2c, enable);
187 }
188
MXC_I2C_GetClockStretching(mxc_i2c_regs_t * i2c)189 int MXC_I2C_GetClockStretching(mxc_i2c_regs_t *i2c)
190 {
191 return MXC_I2C_RevA_GetClockStretching((mxc_i2c_reva_regs_t *)i2c);
192 }
193
MXC_I2C_DMA_Init(mxc_i2c_regs_t * i2c,mxc_dma_regs_t * dma,bool use_dma_tx,bool use_dma_rx)194 int MXC_I2C_DMA_Init(mxc_i2c_regs_t *i2c, mxc_dma_regs_t *dma, bool use_dma_tx, bool use_dma_rx)
195 {
196 return MXC_I2C_RevA_DMA_Init((mxc_i2c_reva_regs_t *)i2c, (mxc_dma_reva_regs_t *)dma, use_dma_tx,
197 use_dma_rx);
198 }
199
MXC_I2C_DMA_GetTXChannel(mxc_i2c_regs_t * i2c)200 int MXC_I2C_DMA_GetTXChannel(mxc_i2c_regs_t *i2c)
201 {
202 return MXC_I2C_RevA_DMA_GetTXChannel((mxc_i2c_reva_regs_t *)i2c);
203 }
204
MXC_I2C_DMA_GetRXChannel(mxc_i2c_regs_t * i2c)205 int MXC_I2C_DMA_GetRXChannel(mxc_i2c_regs_t *i2c)
206 {
207 return MXC_I2C_RevA_DMA_GetRXChannel((mxc_i2c_reva_regs_t *)i2c);
208 }
209
MXC_I2C_DMA_SetRequestSelect(mxc_i2c_regs_t * i2c,uint8_t * txData,uint8_t * rxData)210 int MXC_I2C_DMA_SetRequestSelect(mxc_i2c_regs_t *i2c, uint8_t *txData, uint8_t *rxData)
211 {
212 int i2cNum;
213 int txReqSel = -1;
214 int rxReqSel = -1;
215
216 if (i2c == NULL) {
217 return E_NULL_PTR;
218 }
219
220 i2cNum = MXC_I2C_GET_IDX((mxc_i2c_regs_t *)i2c);
221
222 if (txData != NULL) {
223 switch (i2cNum) {
224 case 0:
225 txReqSel = MXC_DMA_REQUEST_I2C0TX;
226 break;
227
228 case 1:
229 txReqSel = MXC_DMA_REQUEST_I2C1TX;
230 break;
231
232 case 2:
233 txReqSel = MXC_DMA_REQUEST_I2C2TX;
234 break;
235
236 default:
237 return E_BAD_PARAM;
238 }
239 }
240
241 if (rxData != NULL) {
242 switch (i2cNum) {
243 case 0:
244 rxReqSel = MXC_DMA_REQUEST_I2C0RX;
245 break;
246
247 case 1:
248 rxReqSel = MXC_DMA_REQUEST_I2C1RX;
249 break;
250
251 case 2:
252 rxReqSel = MXC_DMA_REQUEST_I2C2RX;
253 break;
254
255 default:
256 return E_BAD_PARAM;
257 }
258 }
259
260 return MXC_I2C_RevA_DMA_SetRequestSelect((mxc_i2c_reva_regs_t *)i2c,
261 (mxc_dma_reva_regs_t *)MXC_DMA, txReqSel, rxReqSel);
262 }
263
264 /* ************************************************************************* */
265 /* Low-level functions */
266 /* ************************************************************************* */
MXC_I2C_Start(mxc_i2c_regs_t * i2c)267 int MXC_I2C_Start(mxc_i2c_regs_t *i2c)
268 {
269 return MXC_I2C_RevA_Start((mxc_i2c_reva_regs_t *)i2c);
270 }
271
MXC_I2C_Stop(mxc_i2c_regs_t * i2c)272 int MXC_I2C_Stop(mxc_i2c_regs_t *i2c)
273 {
274 return MXC_I2C_RevA_Stop((mxc_i2c_reva_regs_t *)i2c);
275 }
276
MXC_I2C_WriteByte(mxc_i2c_regs_t * i2c,unsigned char byte)277 int MXC_I2C_WriteByte(mxc_i2c_regs_t *i2c, unsigned char byte)
278 {
279 return MXC_I2C_RevA_WriteByte((mxc_i2c_reva_regs_t *)i2c, byte);
280 }
281
MXC_I2C_ReadByte(mxc_i2c_regs_t * i2c,unsigned char * byte,int ack)282 int MXC_I2C_ReadByte(mxc_i2c_regs_t *i2c, unsigned char *byte, int ack)
283 {
284 return MXC_I2C_RevA_ReadByte((mxc_i2c_reva_regs_t *)i2c, byte, ack);
285 }
286
MXC_I2C_ReadByteInteractive(mxc_i2c_regs_t * i2c,unsigned char * byte,mxc_i2c_getAck_t getAck)287 int MXC_I2C_ReadByteInteractive(mxc_i2c_regs_t *i2c, unsigned char *byte, mxc_i2c_getAck_t getAck)
288 {
289 return MXC_I2C_RevA_ReadByteInteractive((mxc_i2c_reva_regs_t *)i2c, byte,
290 (mxc_i2c_reva_getAck_t)getAck);
291 }
292
MXC_I2C_Write(mxc_i2c_regs_t * i2c,unsigned char * bytes,unsigned int * len)293 int MXC_I2C_Write(mxc_i2c_regs_t *i2c, unsigned char *bytes, unsigned int *len)
294 {
295 return MXC_I2C_RevA_Write((mxc_i2c_reva_regs_t *)i2c, bytes, len);
296 }
297
MXC_I2C_Read(mxc_i2c_regs_t * i2c,unsigned char * bytes,unsigned int * len,int ack)298 int MXC_I2C_Read(mxc_i2c_regs_t *i2c, unsigned char *bytes, unsigned int *len, int ack)
299 {
300 return MXC_I2C_RevA_Read((mxc_i2c_reva_regs_t *)i2c, bytes, len, ack);
301 }
302
MXC_I2C_ReadRXFIFO(mxc_i2c_regs_t * i2c,volatile unsigned char * bytes,unsigned int len)303 int MXC_I2C_ReadRXFIFO(mxc_i2c_regs_t *i2c, volatile unsigned char *bytes, unsigned int len)
304 {
305 return MXC_I2C_RevA_ReadRXFIFO((mxc_i2c_reva_regs_t *)i2c, bytes, len);
306 }
307
MXC_I2C_ReadRXFIFODMA(mxc_i2c_regs_t * i2c,unsigned char * bytes,unsigned int len,mxc_i2c_dma_complete_cb_t callback)308 int MXC_I2C_ReadRXFIFODMA(mxc_i2c_regs_t *i2c, unsigned char *bytes, unsigned int len,
309 mxc_i2c_dma_complete_cb_t callback)
310 {
311 // The callback parameter was previously unused but keeping it for backwards-compatibility.
312 return MXC_I2C_RevA_ReadRXFIFODMA((mxc_i2c_reva_regs_t *)i2c, bytes, len, MXC_DMA);
313 }
314
MXC_I2C_GetRXFIFOAvailable(mxc_i2c_regs_t * i2c)315 int MXC_I2C_GetRXFIFOAvailable(mxc_i2c_regs_t *i2c)
316 {
317 return MXC_I2C_RevA_GetRXFIFOAvailable((mxc_i2c_reva_regs_t *)i2c);
318 }
319
MXC_I2C_WriteTXFIFO(mxc_i2c_regs_t * i2c,volatile unsigned char * bytes,unsigned int len)320 int MXC_I2C_WriteTXFIFO(mxc_i2c_regs_t *i2c, volatile unsigned char *bytes, unsigned int len)
321 {
322 return MXC_I2C_RevA_WriteTXFIFO((mxc_i2c_reva_regs_t *)i2c, bytes, len);
323 }
324
MXC_I2C_WriteTXFIFODMA(mxc_i2c_regs_t * i2c,unsigned char * bytes,unsigned int len,mxc_i2c_dma_complete_cb_t callback)325 int MXC_I2C_WriteTXFIFODMA(mxc_i2c_regs_t *i2c, unsigned char *bytes, unsigned int len,
326 mxc_i2c_dma_complete_cb_t callback)
327 {
328 // The callback parameter was previously unused but keeping it for backwards-compatibility.
329 return MXC_I2C_RevA_WriteTXFIFODMA((mxc_i2c_reva_regs_t *)i2c, bytes, len, MXC_DMA);
330 }
331
MXC_I2C_GetTXFIFOAvailable(mxc_i2c_regs_t * i2c)332 int MXC_I2C_GetTXFIFOAvailable(mxc_i2c_regs_t *i2c)
333 {
334 return MXC_I2C_RevA_GetTXFIFOAvailable((mxc_i2c_reva_regs_t *)i2c);
335 }
336
MXC_I2C_ClearRXFIFO(mxc_i2c_regs_t * i2c)337 void MXC_I2C_ClearRXFIFO(mxc_i2c_regs_t *i2c)
338 {
339 MXC_I2C_RevA_ClearRXFIFO((mxc_i2c_reva_regs_t *)i2c);
340 }
341
MXC_I2C_ClearTXFIFO(mxc_i2c_regs_t * i2c)342 void MXC_I2C_ClearTXFIFO(mxc_i2c_regs_t *i2c)
343 {
344 MXC_I2C_RevA_ClearTXFIFO((mxc_i2c_reva_regs_t *)i2c);
345 }
346
MXC_I2C_GetFlags(mxc_i2c_regs_t * i2c,unsigned int * flags0,unsigned int * flags1)347 int MXC_I2C_GetFlags(mxc_i2c_regs_t *i2c, unsigned int *flags0, unsigned int *flags1)
348 {
349 return MXC_I2C_RevA_GetFlags((mxc_i2c_reva_regs_t *)i2c, flags0, flags1);
350 }
351
MXC_I2C_ClearFlags(mxc_i2c_regs_t * i2c,unsigned int flags0,unsigned int flags1)352 void MXC_I2C_ClearFlags(mxc_i2c_regs_t *i2c, unsigned int flags0, unsigned int flags1)
353 {
354 MXC_I2C_RevA_ClearFlags((mxc_i2c_reva_regs_t *)i2c, flags0, flags1);
355 }
356
MXC_I2C_EnableInt(mxc_i2c_regs_t * i2c,unsigned int flags0,unsigned int flags1)357 void MXC_I2C_EnableInt(mxc_i2c_regs_t *i2c, unsigned int flags0, unsigned int flags1)
358 {
359 MXC_I2C_RevA_EnableInt((mxc_i2c_reva_regs_t *)i2c, flags0, flags1);
360 }
361
MXC_I2C_DisableInt(mxc_i2c_regs_t * i2c,unsigned int flags0,unsigned int flags1)362 void MXC_I2C_DisableInt(mxc_i2c_regs_t *i2c, unsigned int flags0, unsigned int flags1)
363 {
364 MXC_I2C_RevA_DisableInt((mxc_i2c_reva_regs_t *)i2c, flags0, flags1);
365 }
366
MXC_I2C_EnablePreload(mxc_i2c_regs_t * i2c)367 void MXC_I2C_EnablePreload(mxc_i2c_regs_t *i2c)
368 {
369 MXC_I2C_RevA_EnablePreload((mxc_i2c_reva_regs_t *)i2c);
370 }
371
MXC_I2C_DisablePreload(mxc_i2c_regs_t * i2c)372 void MXC_I2C_DisablePreload(mxc_i2c_regs_t *i2c)
373 {
374 MXC_I2C_RevA_DisablePreload((mxc_i2c_reva_regs_t *)i2c);
375 }
376
MXC_I2C_EnableGeneralCall(mxc_i2c_regs_t * i2c)377 void MXC_I2C_EnableGeneralCall(mxc_i2c_regs_t *i2c)
378 {
379 MXC_I2C_RevA_EnableGeneralCall((mxc_i2c_reva_regs_t *)i2c);
380 }
381
MXC_I2C_DisableGeneralCall(mxc_i2c_regs_t * i2c)382 void MXC_I2C_DisableGeneralCall(mxc_i2c_regs_t *i2c)
383 {
384 MXC_I2C_RevA_DisableGeneralCall((mxc_i2c_reva_regs_t *)i2c);
385 }
386
MXC_I2C_SetTimeout(mxc_i2c_regs_t * i2c,unsigned int timeout)387 void MXC_I2C_SetTimeout(mxc_i2c_regs_t *i2c, unsigned int timeout)
388 {
389 MXC_I2C_RevA_SetTimeout((mxc_i2c_reva_regs_t *)i2c, timeout);
390 }
391
MXC_I2C_GetTimeout(mxc_i2c_regs_t * i2c)392 unsigned int MXC_I2C_GetTimeout(mxc_i2c_regs_t *i2c)
393 {
394 return MXC_I2C_RevA_GetTimeout((mxc_i2c_reva_regs_t *)i2c);
395 }
396
MXC_I2C_Recover(mxc_i2c_regs_t * i2c,unsigned int retries)397 int MXC_I2C_Recover(mxc_i2c_regs_t *i2c, unsigned int retries)
398 {
399 return MXC_I2C_RevA_Recover((mxc_i2c_reva_regs_t *)i2c, retries);
400 }
401
402 /* ************************************************************************* */
403 /* Transaction level functions */
404 /* ************************************************************************* */
405
MXC_I2C_MasterTransaction(mxc_i2c_req_t * req)406 int MXC_I2C_MasterTransaction(mxc_i2c_req_t *req)
407 {
408 if (!(req->i2c->status & MXC_F_I2C_STATUS_TX_EM)) {
409 MXC_I2C_ClearTXFIFO(req->i2c);
410 }
411 if (!(req->i2c->status & MXC_F_I2C_STATUS_RX_EM)) {
412 MXC_I2C_ClearRXFIFO(req->i2c);
413 }
414
415 return MXC_I2C_RevA_MasterTransaction((mxc_i2c_reva_req_t *)req);
416 }
417
MXC_I2C_MasterTransactionAsync(mxc_i2c_req_t * req)418 int MXC_I2C_MasterTransactionAsync(mxc_i2c_req_t *req)
419 {
420 MXC_I2C_ClearRXFIFO(req->i2c);
421 MXC_I2C_ClearTXFIFO(req->i2c);
422
423 return MXC_I2C_RevA_MasterTransactionAsync((mxc_i2c_reva_req_t *)req);
424 }
425
MXC_I2C_MasterTransactionDMA(mxc_i2c_req_t * req)426 int MXC_I2C_MasterTransactionDMA(mxc_i2c_req_t *req)
427 {
428 MXC_I2C_ClearRXFIFO(req->i2c);
429 MXC_I2C_ClearTXFIFO(req->i2c);
430
431 return MXC_I2C_RevA_MasterTransactionDMA((mxc_i2c_reva_req_t *)req, MXC_DMA);
432 }
433
MXC_I2C_SlaveTransaction(mxc_i2c_regs_t * i2c,mxc_i2c_slave_handler_t callback)434 int MXC_I2C_SlaveTransaction(mxc_i2c_regs_t *i2c, mxc_i2c_slave_handler_t callback)
435 {
436 MXC_I2C_ClearRXFIFO(i2c);
437 MXC_I2C_ClearTXFIFO(i2c);
438
439 return MXC_I2C_RevA_SlaveTransaction((mxc_i2c_reva_regs_t *)i2c,
440 (mxc_i2c_reva_slave_handler_t)callback, interruptCheck);
441 }
442
MXC_I2C_SlaveTransactionAsync(mxc_i2c_regs_t * i2c,mxc_i2c_slave_handler_t callback)443 int MXC_I2C_SlaveTransactionAsync(mxc_i2c_regs_t *i2c, mxc_i2c_slave_handler_t callback)
444 {
445 MXC_I2C_ClearRXFIFO(i2c);
446 MXC_I2C_ClearTXFIFO(i2c);
447
448 return MXC_I2C_RevA_SlaveTransactionAsync(
449 (mxc_i2c_reva_regs_t *)i2c, (mxc_i2c_reva_slave_handler_t)callback, interruptCheck);
450 }
451
MXC_I2C_SetRXThreshold(mxc_i2c_regs_t * i2c,unsigned int numBytes)452 int MXC_I2C_SetRXThreshold(mxc_i2c_regs_t *i2c, unsigned int numBytes)
453 {
454 return MXC_I2C_RevA_SetRXThreshold((mxc_i2c_reva_regs_t *)i2c, numBytes);
455 }
456
MXC_I2C_GetRXThreshold(mxc_i2c_regs_t * i2c)457 unsigned int MXC_I2C_GetRXThreshold(mxc_i2c_regs_t *i2c)
458 {
459 return MXC_I2C_RevA_GetRXThreshold((mxc_i2c_reva_regs_t *)i2c);
460 }
461
MXC_I2C_SetTXThreshold(mxc_i2c_regs_t * i2c,unsigned int numBytes)462 int MXC_I2C_SetTXThreshold(mxc_i2c_regs_t *i2c, unsigned int numBytes)
463 {
464 return MXC_I2C_RevA_SetTXThreshold((mxc_i2c_reva_regs_t *)i2c, numBytes);
465 }
466
MXC_I2C_GetTXThreshold(mxc_i2c_regs_t * i2c)467 unsigned int MXC_I2C_GetTXThreshold(mxc_i2c_regs_t *i2c)
468 {
469 return MXC_I2C_RevA_GetTXThreshold((mxc_i2c_reva_regs_t *)i2c);
470 }
471
MXC_I2C_AsyncStop(mxc_i2c_regs_t * i2c)472 void MXC_I2C_AsyncStop(mxc_i2c_regs_t *i2c)
473 {
474 MXC_I2C_RevA_AsyncStop((mxc_i2c_reva_regs_t *)i2c);
475 }
476
MXC_I2C_AbortAsync(mxc_i2c_regs_t * i2c)477 void MXC_I2C_AbortAsync(mxc_i2c_regs_t *i2c)
478 {
479 MXC_I2C_RevA_AbortAsync((mxc_i2c_reva_regs_t *)i2c);
480 }
481
MXC_I2C_AsyncHandler(mxc_i2c_regs_t * i2c)482 void MXC_I2C_AsyncHandler(mxc_i2c_regs_t *i2c)
483 {
484 MXC_I2C_RevA_AsyncHandler((mxc_i2c_reva_regs_t *)i2c, interruptCheck);
485 }
486
MXC_I2C_DMACallback(int ch,int error)487 void MXC_I2C_DMACallback(int ch, int error)
488 {
489 MXC_I2C_RevA_DMACallback(ch, error);
490 }
491