2 * Author: Brendan Le Foll
4 * Copyright © 2014 Intel Corporation
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 /** An I2C Master, used for communicating with I2C slave devices
39 * // Read from I2C slave at address 0x62
48 * i2c.read(address, data, 2);
67 /** Create an I2C Master interface, connected to the specified pins
69 * @param sda I2C data line pin
70 * @param scl I2C clock line pin
72 I2C(unsigned int sda, unsigned int scl);
74 /** Set the frequency of the I2C interface
76 * @param hz The bus frequency in hertz
78 void frequency(int hz);
80 /** Read from an I2C slave
82 * Performs a complete read transaction. The bottom bit of
83 * the address is forced to 1 to indicate a read.
85 * @param address 8-bit I2C slave address [ addr | 1 ]
86 * @param data Pointer to the byte-array to read data in to
87 * @param length Number of bytes to read
88 * @param repeated Repeated start, true - don't send stop at end
92 * non-0 on failure (nack)
94 int read(int address, char *data, int length, bool repeated = false);
96 /** Read a single byte from the I2C bus
98 * @param ack indicates if the byte is to be acknowledged (1 = acknowledge)
105 /** Write to an I2C slave
107 * Performs a complete write transaction. The bottom bit of
108 * the address is forced to 0 to indicate a write.
110 * @param address 8-bit I2C slave address [ addr | 0 ]
111 * @param data Pointer to the byte-array data to send
112 * @param length Number of bytes to send
113 * @param repeated Repeated start, true - do not send stop at end
116 * 0 on success (ack),
117 * non-0 on failure (nack)
119 int write(int address, const char *data, int length, bool repeated = false);
121 /** Write single byte out on the I2C bus
122 * @param data data to write out on bus
125 * '1' if an ACK was received,
130 /** Creates a start condition on the I2C bus
134 /** Creates a stop condition on the I2C bus