2 * Author: Brendan Le Foll <brendan.le.foll@intel.com>
3 * Copyright (c) 2014 Intel Corporation.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * This file defines the i2c interface for libmaa
45 * A structure representing an i2c device /dev/i2c-*
49 int hz; /**< frequency of communication */
50 int fh; /**< the file handle to the /dev/i2c-* device */
51 int addr; /**< the address of the i2c slave */
55 maa_i2c_context* maa_i2c_init();
57 /** Sets the frequency of the i2c context
59 * @param dev the i2c context
60 * @param hz The bus frequency in hertz
62 * @return maa_result_t the maa result.
64 maa_result_t maa_i2c_frequency(maa_i2c_context* dev, int hz);
66 /** Read from an i2c context
68 * @param dev the i2c context
69 * @param data pointer to the byte array to read data in to
70 * @param length max number of bytes to read
72 * @return maa_result_t the maa result.
74 maa_result_t maa_i2c_read(maa_i2c_context* dev, char *data, int length);
76 /** Read a single byte from the i2c context
78 * @param dev the i2c context
80 * @return byte the result of the read or -1 if failed.
82 int maa_i2c_read_byte(maa_i2c_context* dev);
84 /** Write to an i2c context
86 * @param dev the i2c context
87 * @param data pointer to the byte array to be written
88 * @param length the number of bytes to transmit
90 * @return maa_result_t the maa result.
92 maa_result_t maa_i2c_write(maa_i2c_context* dev, const char *data, int length);
94 /** Write a single byte to an i2c context
96 * @param dev the i2c context
97 * @data the byte to write
99 * @return maa_result_t the maa result.
101 maa_result_t maa_i2c_write_byte(maa_i2c_context* dev, int data);
103 /** Sets the i2c context address.
105 * @param dev the i2c context
106 * @param address The address to set for the slave (ignoring the least
107 * signifcant bit). If set to 0, the slave will only respond to the
108 * general call address.
110 * @return maa_result_t the maa result.
112 maa_result_t maa_i2c_address(maa_i2c_context* dev, int address);
114 /** De-inits an maa_i2c_context device
116 * @param dev the i2c context
118 * @return maa_result_t the maa result.
120 maa_result_t maa_i2c_stop(maa_i2c_context* dev);