76 #include <sys/types.h> 77 #include <sys/errno.h> 78 #include <sys/ioctl.h> 80 #include "rnr/rnrconfig.h" 102 if( i2c->
addr != addr )
126 device =
"/dev/i2c/0";
129 if( (i2c->
fd = open(device, O_RDWR)) < 0)
153 rc = (int)read(i2c->
fd, buf, (
size_t)len);
165 rc = (int)write(i2c->
fd , buf, (
size_t)len);
172 const byte_t *write_buf , uint_t write_len,
173 byte_t *read_buf , uint_t read_len)
182 msgs[0].
buf = (
char *)write_buf;
183 msgs[0].
len = (short)write_len;
188 msgs[1].
buf = (
char *)read_buf;
189 msgs[1].
len = (short)read_len;
216 return rc == 1? 1: 0;
236 if( callback != NULL )
238 if( (rc = callback(i2c, addr, context)) < 0 )
i2c_addr_t addr
address of the currently selected attached I2C device
i2c_msg_t * msgs
pointers to i2c_msgs
short len
message length (bytes)
int fd
opened file descriptor of the I2C bus device
ushort_t addr
7/10-bit slave address 0xxx xxxx
ushort_t i2c_addr_t
I2C Device Address Type.
static int i2c_select_device(i2c_t *i2c, i2c_addr_t addr)
Selects the I2C device on a given I2C Bus.
int i2c_transfer(i2c_t *i2c, i2c_addr_t addr, const byte_t *write_buf, uint_t write_len, byte_t *read_buf, uint_t read_len)
Perform a transfer with an I2C device.
int nmsgs
number of i2c_msgs
I2C SMBus IOCTL Multi-Message Structure.
int i2c_open(i2c_t *i2c, char const *device)
Open the host I2C Bus device.
#define I2C_ADDR_DEV_HIGH
last available device address
#define I2C_ADDR_NONE
no I2C address selected
int i2c_scan(i2c_t *i2c, int(*callback)(i2c_t *i2c, i2c_addr_t addr, void *context), void *context)
Scans the given I2C Bus to find all connected devices.
char * buf
pointer to message data
I2C character device interface.
void i2c_close(i2c_t *i2c)
Closes an I2C Bus.
#define I2C_RDWR
combined R/W transfer (one stop only)
#define I2C_SLAVE
change 7/10-bit slave address
#define I2C_M_NOFLAGS
no/clear flags
int i2c_read(i2c_t *i2c, i2c_addr_t addr, byte_t *buf, uint_t len)
Read from an I2C device.
int i2c_exists(i2c_t *i2c, i2c_addr_t addr)
Test the existance of a device at the given address on the given I2C Bus.
#define I2C_ADDR_DEV_LOW
first available device address
int i2c_write(i2c_t *i2c, i2c_addr_t addr, const byte_t *buf, uint_t len)
Write to an I2C device.
Low-level I2C communication level.