28 #include <linux/i2c.h> 29 #include <linux/i2c-dev.h> 37 #include <sys/ioctl.h> 60 debug(
"[%s] Kernel module \"i2c_dev\" not loaded.\n", __func__);
66 debug(
"[%s] Kernel module \"i2c_bcm2708\" not loaded.\n", __func__);
76 else if ( rev == REV_2 )
99 int fd = open (devname, O_RDWR);
103 debug(
"[%s] Can't open %s : %s\n", __func__, devname, strerror (errno));
123 if ( ioctl (fd, I2C_SLAVE, addr) < 0 )
125 debug(
"[%s] Can't select device %s: %s\n", __func__, addr, strerror (errno));
145 i2c_write (
unsigned int fd,
unsigned int addr,
unsigned char *data,
unsigned int len)
150 if ( write (fd, data, len) != len )
152 debug(
"[%s] I2C write (address: 0x%X) failed: %s\n", __func__, addr, strerror (errno));
158 printf (
"[%s] Can't select I2C device at address: 0x%X, write failed\n", __func__, addr);
176 i2c_read (
unsigned int fd,
unsigned int addr,
unsigned char *data,
unsigned int len)
182 if ( read (fd, buf, len) != len )
184 debug(
"[%s]: I2C read (address: 0x%X) failed: %s\n", __func__, addr, strerror (errno));
189 memcpy(data, buf, len);
195 debug(
"[%s] Can't select I2C device at address: 0x%X, write failed\n", __func__, addr);
int i2c_write(unsigned int fd, unsigned int addr, unsigned char *data, unsigned int len)
Initiates an I2C write operation.
int i2c_select_device(unsigned int fd, unsigned int addr)
Selects a specific I2C slave device.
int i2c_init_name(char *devname)
Initialises the i2c-dev interface for the sysfs entry specified by the devname parameter.
int i2c_init()
Initialises the i2c-dev interface for the I2C peripheral exposed on the P1 header (which is dependent...
int check_kernel_module(char *modulename)
Check if the kernel module specified is loaded.
int board_rev()
Return board revision.
Header for general library functionality.
int i2c_read(unsigned int fd, unsigned int addr, unsigned char *data, unsigned int len)
Initiates an I2C read operation.