i2c.h revision 895401859313187f15a800e62d43e6bcbf48fada
1/*
2 $License:
3   Copyright 2011 InvenSense, Inc.
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16  $
17 */
18/*******************************************************************************
19 *
20 * $Id: i2c.h 5629 2011-06-11 03:13:08Z mcaramello $
21 *
22 *******************************************************************************/
23
24#ifndef _I2C_H
25#define _I2C_H
26
27#include "mltypes.h"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33/* ------------ */
34/* - Defines. - */
35/* ------------ */
36
37/* - Error Codes. - */
38
39#define I2C_SUCCESS 0
40#define I2C_ERROR   1
41
42/* ---------- */
43/* - Enums. - */
44/* ---------- */
45
46/* --------------- */
47/* - Structures. - */
48/* --------------- */
49
50#define I2C_RBUFF_MAX    128
51#define I2C_RBUFF_SIZE    17
52
53#ifdef BB_I2C
54#define I2C_RBUFF_DYNAMIC  0
55#else
56#define I2C_RBUFF_DYNAMIC  1
57#endif
58
59typedef struct {
60
61	HANDLE  i2cHndl;
62	HANDLE  hDevice;                    // handle to the drive to be examined
63
64    MLU8      readBuffer[1024];
65	MLU8      writeBuffer[1024];
66
67    MLU16     rBuffRIndex;
68	MLU16     rBuffWIndex;
69#if !I2C_RBUFF_DYNAMIC
70    MLU8      rBuff[I2C_RBUFF_MAX][I2C_RBUFF_SIZE];
71#else
72    MLU8     *rBuff;
73#endif
74    MLU16     rBuffMax;
75	MLU16     rBuffNumBytes;
76
77    MLU8      runThread;
78	MLU8      autoProcess;
79
80} I2C_Vars_t;
81
82/* --------------------- */
83/* - Function p-types. - */
84/* --------------------- */
85
86#if (defined(BB_I2C))
87void set_i2c_open_bind_cb(int (*func)(unsigned int i2c_slave_addr));
88void set_i2c_open_cb(int (*func)(const char *dev, int rw));
89void set_i2c_close_cb(int (*func)(int fd));
90void set_i2c_lltransfer_cb(int (*func)(int fd, int client_addr, const char *write_buf, unsigned int write_len,
91                                                                      char *read_buf,  unsigned int read_len ));
92void set_i2c_write_register_cb(int (*func)(int fd, int client_addr, unsigned char reg, unsigned char value));
93void set_i2c_read_register_cb(unsigned char (*func)(int fd, int client_addr, unsigned char reg));
94void set_i2c_dump_register_cb(int (*func)(int fd, int client_addr, unsigned char start_reg, unsigned char *buff, int len));
95
96int           _i2c_write_register(int fd, int client_addr, unsigned char reg, unsigned char value);
97unsigned char _i2c_read_register (int fd, int client_addr, unsigned char reg);
98int            i2c_lltransfer    (int fd, int client_addr, const char *write_buf, unsigned int write_len,
99                                                                 char *read_buf,  unsigned int read_len );
100int            i2c_write_register(int fd, int client_addr, unsigned char reg, unsigned char value);
101unsigned char  i2c_read_register (int fd, int client_addr, unsigned char reg);
102int            i2c_dump_register (int fd, int client_addr, unsigned char start_reg, unsigned char *buff, int len);
103int i2c_open         (const char *dev, int rw);
104int i2c_close        (int fd);
105int i2c_open_bind    (unsigned int i2c_slave_addr);
106#endif
107
108int I2COpen           (unsigned char autoProcess, unsigned char createThread);
109int I2CClose          (void);
110int I2CDeviceIoControl(void);
111int I2CRead           (void);
112int I2CWrite          (void);
113int I2CSetBufferSize  (unsigned short bufferSize);
114int I2CBufferUpdate   (void);
115int I2CHandler        (void);
116int I2CReadBuffer     (unsigned short cnt, unsigned char bufferMode, unsigned char *rBuff);
117int I2CEmptyBuffer    (void);
118int I2CPktsInBuffer   (unsigned short *pktsInBuffer);
119int I2CCreateMutex    (void);
120int I2CLockMutex      (void);
121int I2CUnlockMutex    (void);
122
123int I2CWriteBurst     (unsigned char slaveAddr, unsigned char registerAddr, unsigned short length, unsigned char *data);
124int I2CReadBurst      (unsigned char slaveAddr, unsigned char registerAddr, unsigned short length, unsigned char *data);
125
126int I2COpenBB         (void);
127int I2CCloseBB        (int i2cHandle);
128
129#ifdef __cplusplus
130}
131#endif
132
133#endif /* _TEMPLATE_H */
134