30 #include <linux/i2c.h>
31 #include <linux/i2c-dev.h>
39 #include <sys/ioctl.h>
63 debug(
"[%s] Kernel module \"i2c_dev\" not loaded.\n", __func__);
69 debug(
"[%s] Kernel module \"i2c_bcm2708\" not loaded.\n", __func__);
79 else if ( rev == REV_2 )
102 int fd = open (devname, O_RDWR);
106 debug(
"[%s] Can't open %s : %s\n", __func__, devname, strerror (errno));
126 if ( ioctl (fd, I2C_SLAVE, addr) < 0 )
128 debug(
"[%s] Can't select device %s: %s\n", __func__, addr, strerror (errno));
148 i2c_write (
unsigned int fd,
unsigned int addr,
unsigned char *data,
unsigned int len)
153 if ( write (fd, data, len) != len )
155 debug(
"[%s] I2C write (address: 0x%X) failed: %s\n", __func__, addr, strerror (errno));
161 printf (
"[%s] Can't select I2C device at address: 0x%X, write failed\n", __func__, addr);
179 i2c_read (
unsigned int fd,
unsigned int addr,
unsigned char *data,
unsigned int len)
185 if ( read (fd, buf, len) != len )
187 debug(
"[%s]: I2C read (address: 0x%X) failed: %s\n", __func__, addr, strerror (errno));
192 memcpy(data, buf, len);
198 debug(
"[%s] Can't select I2C device at address: 0x%X, write failed\n", __func__, addr);