• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
30 extern "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 
59 typedef 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))
87 void set_i2c_open_bind_cb(int (*func)(unsigned int i2c_slave_addr));
88 void set_i2c_open_cb(int (*func)(const char *dev, int rw));
89 void set_i2c_close_cb(int (*func)(int fd));
90 void 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 ));
92 void set_i2c_write_register_cb(int (*func)(int fd, int client_addr, unsigned char reg, unsigned char value));
93 void set_i2c_read_register_cb(unsigned char (*func)(int fd, int client_addr, unsigned char reg));
94 void set_i2c_dump_register_cb(int (*func)(int fd, int client_addr, unsigned char start_reg, unsigned char *buff, int len));
95 
96 int           _i2c_write_register(int fd, int client_addr, unsigned char reg, unsigned char value);
97 unsigned char _i2c_read_register (int fd, int client_addr, unsigned char reg);
98 int            i2c_lltransfer    (int fd, int client_addr, const char *write_buf, unsigned int write_len,
99                                                                  char *read_buf,  unsigned int read_len );
100 int            i2c_write_register(int fd, int client_addr, unsigned char reg, unsigned char value);
101 unsigned char  i2c_read_register (int fd, int client_addr, unsigned char reg);
102 int            i2c_dump_register (int fd, int client_addr, unsigned char start_reg, unsigned char *buff, int len);
103 int i2c_open         (const char *dev, int rw);
104 int i2c_close        (int fd);
105 int i2c_open_bind    (unsigned int i2c_slave_addr);
106 #endif
107 
108 int I2COpen           (unsigned char autoProcess, unsigned char createThread);
109 int I2CClose          (void);
110 int I2CDeviceIoControl(void);
111 int I2CRead           (void);
112 int I2CWrite          (void);
113 int I2CSetBufferSize  (unsigned short bufferSize);
114 int I2CBufferUpdate   (void);
115 int I2CHandler        (void);
116 int I2CReadBuffer     (unsigned short cnt, unsigned char bufferMode, unsigned char *rBuff);
117 int I2CEmptyBuffer    (void);
118 int I2CPktsInBuffer   (unsigned short *pktsInBuffer);
119 int I2CCreateMutex    (void);
120 int I2CLockMutex      (void);
121 int I2CUnlockMutex    (void);
122 
123 int I2CWriteBurst     (unsigned char slaveAddr, unsigned char registerAddr, unsigned short length, unsigned char *data);
124 int I2CReadBurst      (unsigned char slaveAddr, unsigned char registerAddr, unsigned short length, unsigned char *data);
125 
126 int I2COpenBB         (void);
127 int I2CCloseBB        (int i2cHandle);
128 
129 #ifdef __cplusplus
130 }
131 #endif
132 
133 #endif /* _TEMPLATE_H */
134