summaryrefslogtreecommitdiff
path: root/commandline/i2cget.c
diff options
context:
space:
mode:
Diffstat (limited to 'commandline/i2cget.c')
-rw-r--r--commandline/i2cget.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/commandline/i2cget.c b/commandline/i2cget.c
new file mode 100644
index 0000000..ed453ac
--- /dev/null
+++ b/commandline/i2cget.c
@@ -0,0 +1,34 @@
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "i2c-util.h"
+
+int main(int argc, char **argv)
+{
+ int address, command;
+ unsigned char ret;
+
+ i2c_init();
+ i2c_start();
+
+ if (argc < 3) {
+ fputs("Usage: vusb-i2cget <address> <register>", stderr);
+ return 1;
+ }
+
+ address = atoi(argv[1]);
+ command = atoi(argv[2]);
+ i2c_tx_byte((address << 1) | 0);
+ i2c_tx_byte(command);
+ i2c_start();
+ i2c_tx_byte((address << 1) | 1);
+ ret = i2c_rx_byte();
+
+ i2c_stop();
+ i2c_deinit();
+
+ printf("%i\n", ret);
+
+ return 0;
+}