1 /****************************************************************************
3 * Copyright (c) 2006 Dave Hylands <dhylands@gmail.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
14 ****************************************************************************/
19 * @brief Global definitions for interfacing with the AVR TWI (aka I2C)
22 ****************************************************************************/
24 * @defgroup xxx Readable version of xxx.
26 * @brief Brief description of what xxx does.
28 * Longer description of what xxx does.
30 ****************************************************************************/
33 #define I2C_H /**< Include Guard */
35 /* ---- Include Files ---------------------------------------------------- */
39 #if !defined( CONFIG_H )
49 /* ---- Constants and Types ---------------------------------------------- */
55 #define I2C_ERROR_NONE 0 // No Error
56 #define I2C_ERROR_ADDR_NACK -1 // No response to SLA+R/W
57 #define I2C_ERROR_DATA_NACK -2 // NACK during data transmission
58 #define I2C_ERROR_ARBITRATION_LOST -3 // Lost arbitration
59 #define I2C_ERROR_BAD_LEN -4 // Length is wonky
60 #define I2C_ERROR_BAD_CRC -5 // CRC failed
61 #define I2C_ERROR_BUS_ERROR -6 // Someting weird on the i2c bus
63 typedef int8_t I2C_Error_t
;
66 * Since we're loosely following the SMBus spec, we restrict the amount
67 * of data in each transaction to 32 bytes.
70 #define I2C_MAX_DATA_LEN 32
73 * I2C_Addr_t can contain the address of any device on the bus. This
74 * module only supports 7 bit addressing.
77 typedef uint8_t I2C_Addr_t
;
80 * The I2C_CRC macro can be used to remove all CRC support at compile time.
92 * I2C_Data_t encapsulates the data being read or written on the i2c bus.
93 * This module follows the SMBus spec, whihch specifies a maximum payload
104 // For reads, m_len is the number of bytes actually read (doesn't include
105 // the CRC - if present). If a block transfer was performed which has a
106 // length byte, this length will include the length byte.
110 // Note: Under SMBus, a block write can consist of a command, a length,
111 // 32 bytes of payload, and a CRC.
113 // A read response can consist of a length, 32 bytes of data, and a CRC.
115 uint8_t m_data
[ I2C_MAX_DATA_LEN
+ 2]; // +1 for the command, +1 for length
119 /* ---- Variable Externs ------------------------------------------------- */
122 * Description of variable.
125 /* ---- Function Prototypes ---------------------------------------------- */
128 * Just include prototypes here. Put full descriptions in the .c files.