2 * Originally from mbed Microcontroller Library
3 * Copyright (c) 2006-2013 ARM Limited
4 * Copyright (c) 2014 Intel Corporation
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
23 * This file defines the i2c interface for libmaa
42 maa_gpio_context gpio;
45 maa_i2c_context* maa_i2c_init();
47 /** Set the frequency of the I2C interface
49 * @param dev the i2c context
50 * @param hz The bus frequency in hertz
52 void maa_i2c_frequency(maa_i2c_context* dev, int hz);
54 /** Checks to see if this I2C Slave has been addressed.
56 * @param dev the i2c context
58 * A status indicating if the device has been addressed, and how
59 * - NoData - the slave has not been addressed
60 * - ReadAddressed - the master has requested a read from this slave
61 * - WriteAddressed - the master is writing to this slave
62 * - WriteGeneral - the master is writing to all slave
64 int maa_i2c_receive(maa_i2c_context* dev);
66 /** Read from an I2C master.
68 * @param dev the i2c context
69 * @param data pointer to the byte array to read data in to
70 * @param length maximum number of bytes to read
76 int maa_i2c_read(maa_i2c_context* dev, char *data, int length);
78 /** Read a single byte from an I2C master.
80 * @param dev the i2c context
84 int maa_i2c_read_byte(maa_i2c_context* dev);
86 /** Write to an I2C master
88 * @param dev the i2c context
89 * @param data pointer to the byte array to be transmitted
90 * @param length the number of bytes to transmite
96 int maa_i2c_write(maa_i2c_context* dev, const char *data, int length);
98 /** Write a single byte to an I2C master.
100 * @param dev the i2c context
101 * @data the byte to write
104 * '1' if an ACK was received,
107 int maa_i2c_write_byte(maa_i2c_context* dev, int data);
109 /** Sets the I2C slave address.
111 * @param dev the i2c context
112 * @param address The address to set for the slave (ignoring the least
113 * signifcant bit). If set to 0, the slave will only respond to the
114 * general call address.
116 void maa_i2c_address(maa_i2c_context* dev, int address);
118 /** De-inits an maa_i2c_context device
120 * @param dev the i2c context
122 void maa_i2c_stop(maa_i2c_context* dev);