1 // Copyright (C) 2009 Ubixum, Inc.
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 * Utilities for reading and writing to i2c devices and as eeproms.
27 * i2c_write and i2c_read set this to FALSE at the beginning of a
28 * transaction. If for some reason, the read/write is taking too
29 * long or not returning, firmware can set this to TRUE to cause the
30 * routine to abort. (Usually done via an interrupt).
32 extern volatile __xdata BOOL cancel_i2c_trans;
35 * \brief write data to i2c bus.
37 * Writes data from addr buffer 1st, then data buffer.
38 * Either buffer can be NULL (as long as you set lenN to 0).
40 * Two buffers allows writing data all in one i2c write command without
41 * having to write a hardware address and a data byte with each
44 * \param addr i2c address
45 * \param len1 length of addr data
46 * \param addr_buf addr data
47 * \param len2 length of data
48 * \param data_buf data bytes
50 BOOL i2c_write ( BYTE addr, WORD len1, BYTE* addr_buf, WORD len2, BYTE* data_buf );
53 * \brief read data on the i2c bus.
55 * \param addr i2c address
56 * \param len number of bytes to read
57 * \param buf buffer to store data
59 BOOL i2c_read ( BYTE addr, WORD len, BYTE* buf);
62 * \brief read data from an attached eeprom.
64 * Writes the address of the data to read then reads len bytes into buf.
65 * This function checks the I2CS register to determine if a one or two
66 * byte address eepom was detected on the i2c bus. Reading from proms
67 * at non-standard addresses my require using the i2c_read/write commands
70 * \param prom_addr eeprom i2c address
71 * \param addr address of bytes to start reading
72 * \param len number of bytes to read
73 * \param buf data buffer
75 BOOL eeprom_read( BYTE prom_addr, WORD addr, WORD len, BYTE* buf);
78 * \brief write data to the eeprom
80 * This function checks the I2CS register to determin if a one or two
81 * two byte eeprom is detected. If the prom is not detected at boot time
82 * or is connected to alternate addresses, the i2c_read/write commands should
83 * be used explicitly insread of using this function.
85 * For each byte in buf, the address is written and then the data byte. Many
86 * proms support writing multiple bytes at the same time. For these, it is
87 * also better to use i2c_read/write explicitly. This function is rather slow
90 * \param prom_addr eeprom i2c address
91 * \param addr address of bytes to start writing
92 * \param len number of bytes to write
93 * \param buf data buffer
95 BOOL eeprom_write( BYTE prom_addr, WORD addr, WORD len, BYTE* buf);