simple i2c library  v0.8
Covers I2C basics like start/stop conditions and byte & data send & receive
simplei2c.h
1 
8 #ifndef __i2c_H
9 #define __i2c_H
10 
11 #ifdef __cplusplus
12 extern "C"
13 {
14 #endif
15 
16 #include <propeller.h>
17 
18 
19 typedef struct i2c_st
20 {
21  volatile int scl_mask;
22  volatile int scl_mask_inv;
23  int sda_mask;
24  int sda_mask_inv;
25  int drivescl; /* flag to force scl if non-zero */
26 } i2c;
27 
41 HUBTEXT i2c *i2c_open(i2c *bus, int sclPin, int sdaPin, int sclDrive);
42 
48 HUBTEXT void i2c_start(i2c *bus);
49 
55 HUBTEXT void i2c_stop(i2c *bus);
56 
67 HUBTEXT int i2c_writeByte(i2c *bus, int byte);
68 
78 HUBTEXT int i2c_readByte(i2c *bus, int ackState);
79 
92 HUBTEXT int i2c_writeData(i2c *bus, const unsigned char *data, int count);
93 
107 HUBTEXT int i2c_readData(i2c *bus, unsigned char *data, int count);
108 
118 HUBTEXT int i2c_poll(i2c *bus, int addr);
119 
120 #ifdef __cplusplus
121 }
122 #endif
123 
124 #endif
125 /* __i2c_H */
126 
127 /*
128 +--------------------------------------------------------------------
129 | TERMS OF USE: MIT License
130 +--------------------------------------------------------------------
131 Permission is hereby granted, free of charge, to any person obtaining
132 a copy of this software and associated documentation files
133 (the "Software"), to deal in the Software without restriction,
134 including without limitation the rights to use, copy, modify, merge,
135 publish, distribute, sublicense, and/or sell copies of the Software,
136 and to permit persons to whom the Software is furnished to do so,
137 subject to the following conditions:
138 
139 The above copyright notice and this permission notice shall be
140 included in all copies or substantial portions of the Software.
141 
142 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
143 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
144 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
145 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
146 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
147 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
148 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
149 +--------------------------------------------------------------------
150 */