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
38 maa_gpio_context gpio;
41 maa_i2c_context* maa_i2c_init();
43 /** Set the frequency of the I2C interface
45 * @param dev the i2c context
46 * @param hz The bus frequency in hertz
48 void maa_i2c_frequency(maa_i2c_context* dev, int hz);
50 /** Checks to see if this I2C Slave has been addressed.
52 * @param dev the i2c context
54 * A status indicating if the device has been addressed, and how
55 * - NoData - the slave has not been addressed
56 * - ReadAddressed - the master has requested a read from this slave
57 * - WriteAddressed - the master is writing to this slave
58 * - WriteGeneral - the master is writing to all slave
60 int maa_i2c_receive(maa_i2c_context* dev);
62 /** Read from an I2C master.
64 * @param dev the i2c context
65 * @param data pointer to the byte array to read data in to
66 * @param length maximum number of bytes to read
72 int maa_i2c_read(maa_i2c_context* dev, char *data, int length);
74 /** Read a single byte from an I2C master.
76 * @param dev the i2c context
80 int maa_i2c_read_byte(maa_i2c_context* dev);
82 /** Write to an I2C master
84 * @param dev the i2c context
85 * @param data pointer to the byte array to be transmitted
86 * @param length the number of bytes to transmite
92 int maa_i2c_write(maa_i2c_context* dev, const char *data, int length);
94 /** Write a single byte to an I2C master.
96 * @param dev the i2c context
97 * @data the byte to write
100 * '1' if an ACK was received,
103 int maa_i2c_write_byte(maa_i2c_context* dev, int data);
105 /** Sets the I2C slave address.
107 * @param dev the i2c context
108 * @param address The address to set for the slave (ignoring the least
109 * signifcant bit). If set to 0, the slave will only respond to the
110 * general call address.
112 void maa_i2c_address(maa_i2c_context* dev, int address);
114 /** De-inits an maa_i2c_context device
116 * @param dev the i2c context
118 void maa_i2c_stop(maa_i2c_context* dev);