libattr: remove libattr because it is clashing with udev/attr and is not used by...
[openembedded.git] / recipes / i2c / files / i2c.h
blobbbfd276cec03a524ec96660aa343e249e7d396b0
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
10 * license.
12 * See README and COPYING for more details.
14 ****************************************************************************/
15 /**
17 * @file i2c.h
19 * @brief Global definitions for interfacing with the AVR TWI (aka I2C)
20 * hardware
22 ****************************************************************************/
23 /**
24 * @defgroup xxx Readable version of xxx.
26 * @brief Brief description of what xxx does.
28 * Longer description of what xxx does.
30 ****************************************************************************/
32 #if !defined( I2C_H )
33 #define I2C_H /**< Include Guard */
35 /* ---- Include Files ---------------------------------------------------- */
37 #include <inttypes.h>
39 #if !defined( CONFIG_H )
40 # include "Config.h"
41 #endif
44 /**
45 * @addtogroup I2C
46 * @{
49 /* ---- Constants and Types ---------------------------------------------- */
51 /**
52 * Error Codes
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;
65 /**
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
72 /**
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;
79 /**
80 * The I2C_CRC macro can be used to remove all CRC support at compile time.
83 #if CFG_I2C_USE_CRC
84 # define I2C_CRC(x) x
85 #else
87 # define I2C_CRC(x)
88 #endif
91 /**
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
94 * of 32 bytes.
97 typedef struct
99 #if CFG_I2C_USE_CRC
100 uint8_t m_crc;
101 #endif
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.
108 uint8_t m_len;
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
117 } I2C_Data_t;
119 /* ---- Variable Externs ------------------------------------------------- */
122 * Description of variable.
125 /* ---- Function Prototypes ---------------------------------------------- */
128 * Just include prototypes here. Put full descriptions in the .c files.
131 /** @} */
133 #endif /* I2C_H */