InPlay API
hal_i2c.h
1 
12 #ifndef HAL_I2C_H
13 #define HAL_I2C_H
14 
23 #include <stdint.h>
24 #include "in_mmap.h"
25 
26 /*
27  * Defines
28  ****************************************************************************************
29  */
30 
31 #define I2C_REG_CON_OFS 0x00000000UL
32 #define I2C_REG_TAR_OFS 0x00000004UL
33 #define I2C_REG_SAR_OFS 0x00000008UL
34 #define I2C_REG_DATA_OFS 0x00000010UL
35 #define I2C_REG_SS_HCNT_OFS 0x00000014UL
36 #define I2C_REG_SS_LCNT_OFS 0x00000018UL
37 #define I2C_REG_FS_HCNT_OFS 0x0000001CUL
38 #define I2C_REG_FS_LCNT_OFS 0x00000020UL
39 #define I2C_REG_HS_HCNT_OFS 0x00000024UL
40 #define I2C_REG_HS_LCNT_OFS 0x00000028UL
41 #define I2C_REG_ISR_OFS 0x0000002CUL
42 #define I2C_REG_IMR_OFS 0x00000030UL
43 #define I2C_REG_RISR_OFS 0x00000034UL
44 #define I2C_REG_RFTL_OFS 0x00000038UL
45 #define I2C_REG_TFTL_OFS 0x0000003CUL
46 #define I2C_REG_ICR_OFS 0x00000040UL
47 #define I2C_REG_ICRU_OFS 0x00000044UL
48 #define I2C_REG_ICRO_OFS 0x00000048UL
49 #define I2C_REG_ICTO_OFS 0x0000004CUL
50 #define I2C_REG_CRR_OFS 0x00000050UL
51 #define I2C_REG_CTA_OFS 0x00000054UL
52 #define I2C_REG_CRD_OFS 0x00000058UL
53 #define I2C_REG_CACT_OFS 0x0000005CUL
54 #define I2C_REG_CSD_OFS 0x00000060UL
55 #define I2C_REG_CSAD_OFS 0x00000064UL
56 #define I2C_REG_CLR_GEN_CALL_OFS 0x00000068UL
57 #define I2C_REG_ICE_OFS 0x0000006CUL
58 #define I2C_REG_IS_OFS 0x00000070UL
59 #define I2C_REG_TXFLR_OFS 0x00000074UL
60 #define I2C_REG_RXFLR_OFS 0x00000078UL
61 #define I2C_REG_SDAH_OFS 0x0000007CUL
62 #define I2C_REG_ABTS_OFS 0x00000080UL
63 #define I2C_REG_NACK_OFS 0x00000084UL
64 #define I2C_REG_DMA_CR_OFS 0x00000088UL
65 #define I2C_REG_DMA_TDLR_OFS 0x0000008CUL
66 #define I2C_REG_DMA_RDLR_OFS 0x00000090UL
67 #define I2C_REG_SDAS_OFS 0x00000094UL
68 #define I2C_REG_ACK_GC_OFS 0x00000098UL
69 #define I2C_REG_ES_OFS 0x0000009CUL
70 #define I2C_REG_FS_SPK_OFS 0x000000A0UL
71 #define I2C_REG_HS_SPK_OFS 0x000000A4UL
72 #define I2C_REG_ICRD_OFS 0x000000A8UL
73 
74 #define I2C_FIFO_DEPTH 8
75 #define I2C_RX_FIFO_TL 4
76 #define I2C_TX_FIFO_TL 4
77 
78 enum i2c_id{
79  I2C0_ID,
80  I2C1_ID,
81 };
82 
83 enum i2c_speed {
84  I2C_SPEED_100K,
85  I2C_SPEED_400K,
86  I2C_SPEED_1000K,
87 };
88 
89 enum i2c_error {
90  I2C_ERR_OK = 0,
91  I2C_ERR_INVALID_PARAM = -1,
92  I2C_ERR_INVALID_STATE = -2,
93  I2C_ERR_RX_UNDER_RUN = -3,
94  I2C_ERR_RX_OVER_RUN = -4,
95  I2C_ERR_TX_OVER_FLOW = -5,
96  I2C_ERR_ADDR_NO_ACK = -6,
97  I2C_ERR_TXDATA_NO_ACK = -7,
98  I2C_ERR_SDA_STUCK_AT_LOW = -8,
99  I2C_ERR_UNKNOWN = -9,
100  I2C_ERR_DMA_BUSY = -10,
101  I2C_ERR_DMA_FAIL = -11,
102  I2C_ERR_DMA_ALLOC_BUF_FAIL = -12,
103  I2C_ERR_TMO = -13,
104  I2C_ERR_RESET = -14,
105  I2C_ERR_BUSY = -15,
106  I2C_ERR_MAX = -100,
107 } ;
108 
109 enum i2c_dir {
110  I2C_DIR_WRITE,
111  I2C_DIR_READ,
112 };
113 
114 typedef struct i2c_init {
115  int prio;
116  int speed;
117  void *arg;
118  void (*callback)(void *arg, int id, int status);
119 
120 } i2c_init_t;
121 /*
122  * Inline Functions
123  ****************************************************************************************
124  */
125 
126 #define I2C_CON_MASTER_MODE 0x00000001UL
127 #define I2C_CON_SPEED 0x00000006UL
128 #define I2C_CON_10BIT_SLAVE 0x00000008UL
129 #define I2C_CON_RESTART_EN 0x00000020UL
130 
131 #define I2C_CON_SLAVE_DISABLE 0x00000040UL
132 #define I2C_CON_SLAVE_STOP_DET 0x00000080UL
133 #define I2C_CON_TX_EMPTY_CTRL 0x00000100UL
134 #define I2C_CON_RX_FIFO_FULL_HLD_CTRL 0x00000200UL
135 
136 #define I2C_CON_SPEED_STD (0x1UL << 1)
137 #define I2C_CON_SPEED_FAST (0x2UL << 1)
138 
139 static INLINE void i2c_con_clear(uint32_t i2c_base)
140 {
141  WR_WORD((i2c_base + I2C_REG_CON_OFS), 0);
142 }
143 
144 static INLINE void i2c_speed(uint32_t i2c_base, int speed)
145 {
146  uint32_t reg = RD_WORD(i2c_base + I2C_REG_CON_OFS);
147 
148  reg &= ~I2C_CON_SPEED;
149 
150  if (speed == I2C_SPEED_100K) {
151  reg |= I2C_CON_SPEED_STD;
152  } else {
153  reg |= I2C_CON_SPEED_FAST;
154  }
155 
156  WR_WORD(i2c_base + I2C_REG_CON_OFS, reg);
157 }
158 
159 static INLINE void i2c_master_enable(uint32_t i2c_base)
160 {
161  uint32_t reg = RD_WORD(i2c_base + I2C_REG_CON_OFS);
162 
163  reg |= I2C_CON_MASTER_MODE;
164  reg |= I2C_CON_SLAVE_DISABLE;
165 
166  WR_WORD(i2c_base + I2C_REG_CON_OFS, reg);
167 }
168 
169 static INLINE void i2c_slave_enable(uint32_t i2c_base)
170 {
171  uint32_t reg = RD_WORD(i2c_base + I2C_REG_CON_OFS);
172 
173  reg &= ~I2C_CON_MASTER_MODE;
174  reg &= ~I2C_CON_SLAVE_DISABLE;
175 
176  WR_WORD(i2c_base + I2C_REG_CON_OFS, reg);
177 
178 }
179 static INLINE void i2c_slave_stop_det_enable(uint32_t i2c_base)
180 {
181  uint32_t reg = RD_WORD(i2c_base + I2C_REG_CON_OFS);
182 
183  reg |= I2C_CON_SLAVE_STOP_DET;
184 
185  WR_WORD(i2c_base + I2C_REG_CON_OFS, reg);
186 
187 }
188 static INLINE void i2c_restart_enable(uint32_t i2c_base)
189 {
190  uint32_t reg = RD_WORD(i2c_base + I2C_REG_CON_OFS);
191 
192  reg |= I2C_CON_RESTART_EN;
193 
194  WR_WORD(i2c_base + I2C_REG_CON_OFS, reg);
195 }
196 static INLINE void i2c_restart_disable(uint32_t i2c_base)
197 {
198  uint32_t reg = RD_WORD(i2c_base + I2C_REG_CON_OFS);
199 
200  reg &= ~I2C_CON_RESTART_EN;
201 
202  WR_WORD(i2c_base + I2C_REG_CON_OFS, reg);
203 }
204 
205 /******************* Bit definition for I2C_TAR register ********************/
206 #define I2C_TAR 0x000003FFUL /* bit[0:9] = target address */
207 
208 static INLINE void i2c_tar(uint32_t i2c_base, uint8_t taddr)
209 {
210  WR_WORD(i2c_base + I2C_REG_TAR_OFS, taddr);
211 }
212 
213 
214 /******************* Bit definition for I2C_SAR register ********************/
215 #define I2C_SAR 0x000003FFUL /* bit[0:9] = Slave address */
216 
217 static INLINE void i2c_sar(uint32_t i2c_base, uint8_t saddr)
218 {
219  WR_WORD(i2c_base + I2C_REG_SAR_OFS, saddr);
220 }
221 
222 
223 /******************* Bit definition for I2C_DATA_CMD register ********************/
224 #define I2C_DATA 0x000000FFUL /* bit[0:7] = data */
225 #define I2C_READ 0x00000100UL /* bit[8] = 0: write, 1: read */
226 #define I2C_STOP 0x00000200UL /* bit[9] = 1: stop, 0: otherwise */
227 #define I2C_RESTART 0x00000400UL /* bit[9] = 1: stop, 0: otherwise */
228 
229 static INLINE void i2c_write(uint32_t i2c_base, uint8_t data, int read, int stop, int restart)
230 {
231  uint16_t reg;
232 
233  reg = data;
234  if (read)
235  reg |= I2C_READ;
236  if (stop)
237  reg |= I2C_STOP;
238  if (restart)
239  reg |= I2C_RESTART;
240 
241  WR_WORD(i2c_base + I2C_REG_DATA_OFS, reg);
242 }
243 
244 static INLINE uint8_t i2c_read(uint32_t i2c_base)
245 {
246  return (RD_WORD(i2c_base + I2C_REG_DATA_OFS) & 0xFF);
247 }
248 
249 
250 /******************* Bit definition for I2C_SS_SCL_HCNT register **********************/
251 #define I2C_SS_SCL_HCNT 0x0000FFFFUL /* bit[0:15] = standard speed SCL clock high period count */
252 
253 static INLINE void i2c_ss_scl_hcnt(uint32_t i2c_base, uint16_t hcnt)
254 {
255  WR_WORD(i2c_base + I2C_REG_SS_HCNT_OFS, hcnt);
256 }
257 
258 /********************* Bit definition for I2C_SS_SCL_LCNT register **********************/
259 #define I2C_SS_SCL_LCNT 0x0000FFFFUL /* bit[0:15] = standard speed SCL clock low period count */
260 
261 static INLINE void i2c_ss_scl_lcnt(uint32_t i2c_base, uint16_t lcnt)
262 {
263  WR_WORD(i2c_base + I2C_REG_SS_LCNT_OFS, lcnt);
264 }
265 
266 /******************* Bit definition for I2C_FS_SCL_HCNT register ********************/
267 #define I2C_FS_SCL_HCNT 0x0000FFFFUL /* bit[0:15] = Fast mode speed SCL clock high period count */
268 
269 static INLINE void i2c_fs_scl_hcnt(uint32_t i2c_base, uint16_t hcnt)
270 {
271  WR_WORD(i2c_base + I2C_REG_FS_HCNT_OFS, hcnt);
272 }
273 
274 /******************* Bit definition for I2C_FS_SCL_LCNT register ********************/
275 #define I2C_FS_SCL_LCNT 0x0000FFFFUL /* bit[0:15] = Fast mode speed SCL clock low period count */
276 
277 static INLINE void i2c_fs_scl_lcnt(uint32_t i2c_base, uint16_t lcnt)
278 {
279  WR_WORD(i2c_base + I2C_REG_FS_LCNT_OFS, lcnt);
280 }
281 
282 
283 /******************* Bit definition for I2C_INTR_STAT register ********************/
284 /******************* Bit definition for I2C_INTR_MASK register ********************/
285 /******************* Bit definition for I2C_RAW_INTR_STAT register ********************/
286 #define I2C_INTR_RX_UNDER 0x00000001UL
287 #define I2C_INTR_RX_OVER 0x00000002UL
288 #define I2C_INTR_RX_FULL 0x00000004UL
289 #define I2C_INTR_TX_OVER 0x00000008UL
290 #define I2C_INTR_TX_EMPTY 0x00000010UL
291 #define I2C_INTR_RD_REQ 0x00000020UL
292 #define I2C_INTR_TX_ABRT 0x00000040UL
293 #define I2C_INTR_RX_DONE 0x00000080UL
294 #define I2C_INTR_ACTIVITY 0x00000100UL
295 #define I2C_INTR_STOP_DET 0x00000200UL
296 #define I2C_INTR_START_DET 0x00000400UL
297 //#define I2C_INTR_GEN_CALL 0x00000800UL
298 //#define I2C_INTR_RESTART_DET 0x00001000UL
299 #define I2C_INTR_MST_ON_HOLD 0x00002000UL
300 //#define I2C_INTR_SCL_STUCK_LOW 0x00004000UL
301 #define I2C_INTR_MASK_ALL 0x00007FFFUL
302 static INLINE uint32_t i2c_intr_status(uint32_t i2c_base)
303 {
304  return RD_WORD(i2c_base + I2C_REG_ISR_OFS);
305 }
306 
307 static INLINE uint32_t i2c_intr_raw_status(uint32_t i2c_base)
308 {
309  return RD_WORD(i2c_base + I2C_REG_RISR_OFS);
310 }
311 
312 static INLINE void i2c_intr_mask(uint32_t i2c_base, uint32_t mask)
313 {
314  uint32_t reg = RD_WORD(i2c_base + I2C_REG_IMR_OFS);
315  reg &= ~mask;
316  WR_WORD(i2c_base + I2C_REG_IMR_OFS, reg);
317 }
318 
319 static INLINE void i2c_intr_unmask(uint32_t i2c_base, uint32_t unmask)
320 {
321  uint32_t reg = RD_WORD(i2c_base + I2C_REG_IMR_OFS);
322  reg |= unmask;
323  WR_WORD(i2c_base + I2C_REG_IMR_OFS, reg);
324 }
325 
326 static INLINE void i2c_intr_clr(uint32_t i2c_base)
327 {
328  RD_WORD(i2c_base + I2C_REG_ICR_OFS);
329 }
330 
331 static INLINE void i2c_intr_clr_rxu(uint32_t i2c_base)
332 {
333  RD_WORD(i2c_base + I2C_REG_ICRU_OFS);
334 }
335 
336 static INLINE void i2c_intr_clr_rxo(uint32_t i2c_base)
337 {
338  RD_WORD(i2c_base + I2C_REG_ICRO_OFS);
339 }
340 
341 static INLINE void i2c_intr_clr_txo(uint32_t i2c_base)
342 {
343  RD_WORD(i2c_base + I2C_REG_ICTO_OFS);
344 }
345 
346 static INLINE void i2c_intr_clr_req(uint32_t i2c_base)
347 {
348  RD_WORD(i2c_base + I2C_REG_CRR_OFS);
349 }
350 
351 static INLINE void i2c_intr_clr_abt(uint32_t i2c_base)
352 {
353  RD_WORD(i2c_base + I2C_REG_CTA_OFS);
354 }
355 
356 static INLINE void i2c_intr_clr_rxd(uint32_t i2c_base)
357 {
358  RD_WORD(i2c_base + I2C_REG_CRD_OFS);
359 }
360 
361 static INLINE void i2c_intr_clr_activity(uint32_t i2c_base)
362 {
363  RD_WORD(i2c_base + I2C_REG_CACT_OFS);
364 }
365 
366 static INLINE void i2c_intr_clr_stop(uint32_t i2c_base)
367 {
368  RD_WORD(i2c_base + I2C_REG_CSD_OFS);
369 }
370 
371 static INLINE void i2c_intr_clr_start(uint32_t i2c_base)
372 {
373  RD_WORD(i2c_base + I2C_REG_CSAD_OFS);
374 }
375 
376 /******************* Bit definition for I2C_RX_TL register ********************/
377 #define I2C_RX_TL 0x000000FFUL /* bit[0:15] = Receive FIFO Threshold Level */
378 
379 static INLINE void i2c_rx_fifo_tl(uint32_t i2c_base, uint8_t level)
380 {
381  WR_WORD(i2c_base + I2C_REG_RFTL_OFS, level);
382 }
383 
384 static INLINE uint8_t i2c_get_rx_fifo_tl(uint32_t i2c_base)
385 {
386  return (RD_WORD(i2c_base + I2C_REG_RFTL_OFS) & 0xFF);
387 }
388 
389 /******************* Bit definition for I2C_TX_TL register ********************/
390 #define I2C_TX_TL 0x000000FFUL /* bit[0:15] = Transmit FIFO Threshold Level */
391 
392 static INLINE void i2c_tx_fifo_tl(uint32_t i2c_base, uint16_t level)
393 {
394  WR_WORD(i2c_base + I2C_REG_TFTL_OFS, level);
395 }
396 
397 static INLINE uint8_t i2c_get_tx_fifo_tl(uint32_t i2c_base)
398 {
399  return (RD_WORD(i2c_base + I2C_REG_TFTL_OFS) & 0xFF);
400 }
401 
402 
403 /******************* Bit definition for I2C_ENABLE_STATUS register ********************/
404 #define I2C_ES_ENABLE 0x00000001UL /* bit[0] = I2C Enable Status */
405 #define I2C_ES_SLV_DISABLE_BUSY 0x00000002UL /* bit[1] = Slave disable while busy */
406 #define I2C_ES_SLV_RX_DATA_LOST 0x00000004UL /* bit[2] = Slave received data lost */
407 static INLINE uint32_t i2c_enable_status(uint32_t i2c_base)
408 {
409  return (RD_WORD(i2c_base + I2C_REG_ES_OFS));
410 }
411 
412 /******************* Bit definition for I2C_ENABLE register ********************/
413 #define I2C_ENABLE 0x00000001UL /* bit[0] = Enable I2C */
414 #define I2C_ABORT 0x00000002UL /* bit[1] = Abort operation in progress */
415 
416 static INLINE void i2c_enable(uint32_t i2c_base)
417 {
418  uint32_t reg = RD_WORD(i2c_base + I2C_REG_ICE_OFS);
419  reg |= 0x1UL;
420  WR_WORD(i2c_base + I2C_REG_ICE_OFS, reg);
421 }
422 
423 static INLINE void i2c_disable(uint32_t i2c_base)
424 {
425  uint32_t reg = RD_WORD(i2c_base + I2C_REG_ICE_OFS);
426  reg &= ~0x1UL;
427  WR_WORD(i2c_base + I2C_REG_ICE_OFS, reg);
428 
429  //while (i2c_enable_status(i2c_base) & I2C_ES_ENABLE);
430 }
431 
432 static INLINE void i2c_abort(uint32_t i2c_base, int enable)
433 {
434  uint32_t reg = RD_WORD(i2c_base + I2C_REG_ICE_OFS);
435  if (enable)
436  reg |= I2C_ABORT;
437  else
438  reg &= ~I2C_ABORT;
439 
440  WR_WORD(i2c_base + I2C_REG_ICE_OFS, reg);
441 }
442 
443 
444 
445 /******************* Bit definition for I2C_STATUS register ********************/
446 #define I2C_STATUS_ACTIVITY 0x00000001UL /* bit[0] = Activity */
447 #define I2C_STATUS_TFNF 0x00000002UL /* bit[1] = TX FIFO not full */
448 #define I2C_STATUS_TFE 0x00000004UL /* bit[2] = TX FIFO empty */
449 #define I2C_STATUS_RFNE 0x00000008UL /* bit[3] = RX FIFO not empty */
450 #define I2C_STATUS_RFF 0x00000010UL /* bit[4] = RX FIFO full */
451 
452 static INLINE uint32_t i2c_status(uint32_t i2c_base)
453 {
454  return (RD_WORD(i2c_base + I2C_REG_IS_OFS));
455 }
456 
457 /******************* Bit definition for I2C_FLR register ********************/
458 static INLINE uint8_t i2c_rx_fifo_level(uint32_t i2c_base)
459 {
460  return (RD_WORD(i2c_base + I2C_REG_RXFLR_OFS) & 0xF);
461 }
462 
463 static INLINE uint8_t i2c_tx_fifo_level(uint32_t i2c_base)
464 {
465  return (RD_WORD(i2c_base + I2C_REG_TXFLR_OFS) & 0xF);
466 }
467 
468 /******************* Bit definition for I2C_TX_ABRT_SOURCE register ********************/
469 #define I2C_ABRT_ADDR_NOACK 0x00000001UL
470 #define I2C_ABRT_TXDATA_NOACK 0x00000008UL
471 #define I2C_ABRT_SLVFLUSH_TXFIFO 0x00002000UL
472 #define I2C_ABRT_SLV_ARBLOST 0x00004000UL
473 #define I2C_ABRT_SLVRD_INTX 0x00008000UL
474 #define I2C_ABRT_USER_ABRT 0x00010000UL
475 #define I2C_ABRT_SDA_STUCK_AT_LOW 0x00020000UL
476 #define I2C_ABRT_TX_FLUSH_CNT 0xFF800000UL
477 
478 static INLINE uint32_t i2c_abt_source(uint32_t i2c_base)
479 {
480  return (RD_WORD(i2c_base + I2C_REG_ABTS_OFS));
481 }
482 
483 /******************* Bit definition for I2C DMA Control register ********************/
484 #define I2C_TX_DMA_EN 0x00000002UL
485 #define I2C_RX_DMA_EN 0x00000001UL
486 
487 static INLINE void i2c_dma_tx_enable(uint32_t i2c_base)
488 {
489  uint32_t reg = RD_WORD(i2c_base + I2C_REG_DMA_CR_OFS);
490  reg |= I2C_TX_DMA_EN;
491  WR_WORD(i2c_base + I2C_REG_DMA_CR_OFS, reg);
492 }
493 
494 static INLINE void i2c_dma_tx_disable(uint32_t i2c_base)
495 {
496  uint32_t reg = RD_WORD(i2c_base + I2C_REG_DMA_CR_OFS);
497  reg &= ~I2C_TX_DMA_EN;
498  WR_WORD(i2c_base + I2C_REG_DMA_CR_OFS, reg);
499 }
500 
501 static INLINE void i2c_dma_rx_enable(uint32_t i2c_base)
502 {
503  uint32_t reg = RD_WORD(i2c_base + I2C_REG_DMA_CR_OFS);
504  reg |= I2C_RX_DMA_EN;
505  WR_WORD(i2c_base + I2C_REG_DMA_CR_OFS, reg);
506 }
507 
508 static INLINE void i2c_dma_rx_disable(uint32_t i2c_base)
509 {
510  uint32_t reg = RD_WORD(i2c_base + I2C_REG_DMA_CR_OFS);
511  reg &= ~I2C_RX_DMA_EN;
512  WR_WORD(i2c_base + I2C_REG_DMA_CR_OFS, reg);
513 }
514 
515 
516 /******************* Bit definition for I2C DMA Data Level register ********************/
517 static INLINE void i2c_dma_tx_data_level(uint32_t i2c_base, uint32_t level)
518 {
519  WR_WORD(i2c_base + I2C_REG_DMA_TDLR_OFS, (level & 0xF));
520 }
521 
522 static INLINE void i2c_dma_rx_data_level(uint32_t i2c_base, uint32_t level)
523 {
524  WR_WORD(i2c_base + I2C_REG_DMA_RDLR_OFS, (level & 0xF));
525 }
526 
527 static INLINE void i2c_reset(int id)
528 {
529  uint32_t reg = RD_WORD(GLOBAL_REG_RESET_CTRL_1);
530 
531  // Toggle 1-0-1 to reset
532  if (id == I2C0_ID) {
533  reg &= ~GLOBAL_REG_RESET_CTRL_1_CTL_RESET_1_D0_CPU_I2C_0_IC_RSTN_REG;
534  } else {
535  reg &= ~GLOBAL_REG_RESET_CTRL_1_CTL_RESET_1_D0_CPU_I2C_1_IC_RSTN_REG;
536  }
537  WR_WORD(GLOBAL_REG_RESET_CTRL_1, reg);
538  if (id == I2C0_ID) {
539  reg |= GLOBAL_REG_RESET_CTRL_1_CTL_RESET_1_D0_CPU_I2C_0_IC_RSTN_REG;
540  } else {
541  reg |= GLOBAL_REG_RESET_CTRL_1_CTL_RESET_1_D0_CPU_I2C_1_IC_RSTN_REG;
542  }
543  WR_WORD(GLOBAL_REG_RESET_CTRL_1, reg);
544 }
545 
546 /******************************************************************************/
547 /* */
548 /* Inter-integrated Circuit Interface */
549 /* */
550 /******************************************************************************/
551 
563 void *hal_i2c_open(int id, i2c_init_t *init);
564 
575 void hal_i2c_close(void *hdl);
576 
589 int hal_mi2c_read(void *hdl, uint8_t tar, uint8_t *buffer, uint16_t buffer_len);
590 int hal_mi2c_read_dma(void *hdl, uint8_t tar, uint8_t *buffer, uint16_t buffer_len);
591 int hal_mi2c_read_poll(void *hdl, uint8_t tar, uint8_t *buffer, uint16_t buffer_len);
592 
593 
606 int hal_mi2c_write(void *hdl, uint8_t tar, uint8_t *buffer, uint16_t buffer_len);
607 int hal_mi2c_write_dma(void *hdl, uint8_t tar, uint8_t *buffer, uint16_t buffer_len);
608 int hal_mi2c_write_poll(void *hdl, uint8_t tar, uint8_t *buffer, uint16_t buffer_len);
609 
624 int hal_mi2c_mix_tran_start_poll(void *hdl, int speed, uint8_t tar, int dir_write, uint8_t *buffer, uint16_t buffer_len);
625 
641 int hal_mi2c_mix_tran_continue_poll(void *hdl, uint8_t tar, int dir_write, int restart, uint8_t *buffer, uint16_t buffer_len);
642 
658 int hal_mi2c_mix_tran_end_poll(void *hdl, uint8_t tar, int dir_write, int restart, uint8_t *buffer, uint16_t buffer_len);
659 
660 
675 int hal_si2c_read(void *hdl, uint8_t sar, uint8_t *buffer, uint16_t buffer_len);
676 int hal_si2c_read_dma(void *hdl, uint8_t sar, uint8_t *buffer, uint16_t buffer_len);
677 
691 int hal_si2c_write(void *hdl, uint8_t sar, uint8_t *buffer, uint16_t buffer_len);
692 int hal_si2c_write_dma(void *hdl, uint8_t sar, uint8_t *buffer, uint16_t buffer_len);
693 
694 
709 int hal_mi2c_write_read(void *hdl, uint8_t tar, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len);
710 
720 int hal_i2c_set_tmo(void *hdl, uint32_t tmo);
721 
723 
724 #endif // HAL_I2C_H
int hal_mi2c_write(void *hdl, uint8_t tar, uint8_t *buffer, uint16_t buffer_len)
I2c master write function.
int hal_mi2c_mix_tran_continue_poll(void *hdl, uint8_t tar, int dir_write, int restart, uint8_t *buffer, uint16_t buffer_len)
Continue of I2c master read/write mixed function.
int hal_si2c_write(void *hdl, uint8_t sar, uint8_t *buffer, uint16_t buffer_len)
I2c slave write function.
int hal_si2c_read(void *hdl, uint8_t sar, uint8_t *buffer, uint16_t buffer_len)
I2c slave read function.
int hal_mi2c_write_read(void *hdl, uint8_t tar, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
I2c master write and read function.
void hal_i2c_close(void *hdl)
Close the I2c driver.
int hal_mi2c_mix_tran_start_poll(void *hdl, int speed, uint8_t tar, int dir_write, uint8_t *buffer, uint16_t buffer_len)
Start of I2c master read/write mixed function.
void * hal_i2c_open(int id, i2c_init_t *init)
Open the I2c driver.
int hal_i2c_set_tmo(void *hdl, uint32_t tmo)
Set the I2c timeout.
int hal_mi2c_read(void *hdl, uint8_t tar, uint8_t *buffer, uint16_t buffer_len)
I2c master read function.
int hal_mi2c_mix_tran_end_poll(void *hdl, uint8_t tar, int dir_write, int restart, uint8_t *buffer, uint16_t buffer_len)
End of I2c master read/write mixed function.