summaryrefslogtreecommitdiff
path: root/i2c.c
diff options
context:
space:
mode:
authorroot <root@fedora-arm.domain.avtechpulse.com>1999-12-31 19:32:00 -0500
committerroot <root@fedora-arm.domain.avtechpulse.com>1999-12-31 19:32:00 -0500
commit428e1cde1fb3aa00734742b0491dd3a616c71c61 (patch)
tree9e147cc8432002a6731cacd2e3b0fbcb98c59158 /i2c.c
parentadfaeca9df5d4a9402a734aa62c6d855ac7e4a4a (diff)
Added I2C read/write support, on cape bus for now
Diffstat (limited to 'i2c.c')
-rw-r--r--i2c.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/i2c.c b/i2c.c
new file mode 100644
index 0000000..02e5812
--- /dev/null
+++ b/i2c.c
@@ -0,0 +1,53 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <linux/i2c.h>
+#include <linux/i2c-dev.h>
+
+
+#define I2C_BUS "/dev/i2c-3"
+
+
+int I2C_Write(int address, int value) {
+
+ struct i2c_smbus_ioctl_data argswrite;
+
+ argswrite.read_write = I2C_SMBUS_WRITE;
+ argswrite.size = I2C_SMBUS_BYTE;
+ argswrite.data = NULL;
+ argswrite.command = value;
+
+ int device = open(I2C_BUS, O_RDWR);
+
+ if (device == -1) return device;
+
+ ioctl(device, I2C_SLAVE, address);
+ ioctl(device, I2C_SMBUS, &argswrite);
+
+ close(device);
+}
+
+
+int I2C_Read(int address) {
+
+ union i2c_smbus_data data;
+ struct i2c_smbus_ioctl_data argsread;
+
+ argsread.read_write = I2C_SMBUS_READ;
+ argsread.size = I2C_SMBUS_BYTE;
+ argsread.data = &data;
+ argsread.command = 0;
+
+ int device = open(I2C_BUS, O_RDWR);
+
+ if (device == -1) return device;
+
+ ioctl(device, I2C_SLAVE, address);
+ ioctl(device, I2C_SMBUS, &argsread);
+
+ close(device);
+
+ return data.byte;
+}
+