]> sigrok.org Git - sigrok-firmware-fx2lafw.git/blame - fx2lib/include/i2c.h
fx2lafw: add definitions for IBN (IN BULK NAK) interrupt
[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
040a6eae 14// License along with this library; if not, see <http://www.gnu.org/licenses/>.
3608c106
UH
15
16/** \file i2c.h
17 * Utilities for reading and writing to i2c devices and as eeproms.
18 **/
19
20#ifndef I2C_H
21#define I2C_H
22
23#include "fx2types.h"
24
25/**
26 * i2c_write and i2c_read set this to FALSE at the beginning of a
27 * transaction. If for some reason, the read/write is taking too
28 * long or not returning, firmware can set this to TRUE to cause the
29 * routine to abort. (Usually done via an interrupt).
30 **/
31extern volatile __xdata BOOL cancel_i2c_trans;
32
33/**
34 * \brief write data to i2c bus.
35 *
36 * Writes data from addr buffer 1st, then data buffer.
37 * Either buffer can be NULL (as long as you set lenN to 0).
38 *
39 * Two buffers allows writing data all in one i2c write command without
40 * having to write a hardware address and a data byte with each
41 * i2c transaction.
42 *
43 * \param addr i2c address
44 * \param len1 length of addr data
45 * \param addr_buf addr data
46 * \param len2 length of data
47 * \param data_buf data bytes
48 **/
49BOOL i2c_write ( BYTE addr, WORD len1, BYTE* addr_buf, WORD len2, BYTE* data_buf );
50
51/**
52 * \brief read data on the i2c bus.
53 *
54 * \param addr i2c address
55 * \param len number of bytes to read
56 * \param buf buffer to store data
57 **/
58BOOL i2c_read ( BYTE addr, WORD len, BYTE* buf);
59
60/**
61 * \brief read data from an attached eeprom.
62 *
63 * Writes the address of the data to read then reads len bytes into buf.
64 * This function checks the I2CS register to determine if a one or two
65 * byte address eepom was detected on the i2c bus. Reading from proms
66 * at non-standard addresses my require using the i2c_read/write commands
67 * explicitly.
68 *
69 * \param prom_addr eeprom i2c address
70 * \param addr address of bytes to start reading
71 * \param len number of bytes to read
72 * \param buf data buffer
73 **/
74BOOL eeprom_read( BYTE prom_addr, WORD addr, WORD len, BYTE* buf);
75
76/**
77 * \brief write data to the eeprom
78 *
79 * This function checks the I2CS register to determin if a one or two
80 * two byte eeprom is detected. If the prom is not detected at boot time
81 * or is connected to alternate addresses, the i2c_read/write commands should
82 * be used explicitly insread of using this function.
83 *
84 * For each byte in buf, the address is written and then the data byte. Many
85 * proms support writing multiple bytes at the same time. For these, it is
86 * also better to use i2c_read/write explicitly. This function is rather slow
87 * but is effective.
88 *
89 * \param prom_addr eeprom i2c address
90 * \param addr address of bytes to start writing
91 * \param len number of bytes to write
92 * \param buf data buffer
93 **/
94BOOL eeprom_write( BYTE prom_addr, WORD addr, WORD len, BYTE* buf);
95
96#endif