]> sigrok.org Git - sigrok-firmware-fx2lafw.git/blame - fx2lib/include/i2c.h
GPL headers: Use correct project name.
[sigrok-firmware-fx2lafw.git] / fx2lib / include / i2c.h
CommitLineData
3608c106
UH
1// Copyright (C) 2009 Ubixum, Inc.
2//
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.
7//
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.
12//
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
16
17/** \file i2c.h
18 * Utilities for reading and writing to i2c devices and as eeproms.
19 **/
20
21#ifndef I2C_H
22#define I2C_H
23
24#include "fx2types.h"
25
26/**
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).
31 **/
32extern volatile __xdata BOOL cancel_i2c_trans;
33
34/**
35 * \brief write data to i2c bus.
36 *
37 * Writes data from addr buffer 1st, then data buffer.
38 * Either buffer can be NULL (as long as you set lenN to 0).
39 *
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
42 * i2c transaction.
43 *
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
49 **/
50BOOL i2c_write ( BYTE addr, WORD len1, BYTE* addr_buf, WORD len2, BYTE* data_buf );
51
52/**
53 * \brief read data on the i2c bus.
54 *
55 * \param addr i2c address
56 * \param len number of bytes to read
57 * \param buf buffer to store data
58 **/
59BOOL i2c_read ( BYTE addr, WORD len, BYTE* buf);
60
61/**
62 * \brief read data from an attached eeprom.
63 *
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
68 * explicitly.
69 *
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
74 **/
75BOOL eeprom_read( BYTE prom_addr, WORD addr, WORD len, BYTE* buf);
76
77/**
78 * \brief write data to the eeprom
79 *
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.
84 *
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
88 * but is effective.
89 *
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
94 **/
95BOOL eeprom_write( BYTE prom_addr, WORD addr, WORD len, BYTE* buf);
96
97#endif