diff options
author | Daniel Friesel <derf@finalrewind.org> | 2016-12-25 12:53:23 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2016-12-25 12:53:23 +0100 |
commit | cc8498297af44ab850dc17c77a978c06253be016 (patch) | |
tree | db3163459163e0a667a882401958e89884afe148 | |
parent | 6f3959fe992199a7830bd8dd7e0ec10da867a4cf (diff) |
i2cget: support multi-byte reads
-rw-r--r-- | commandline/i2c-util.c | 20 | ||||
-rw-r--r-- | commandline/i2cget.c | 20 |
2 files changed, 18 insertions, 22 deletions
diff --git a/commandline/i2c-util.c b/commandline/i2c-util.c index 3608e36..be33d4b 100644 --- a/commandline/i2c-util.c +++ b/commandline/i2c-util.c @@ -1,20 +1,8 @@ -/* Name: powerSwitch.c - * Project: PowerSwitch based on AVR USB driver - * Author: Christian Starkjohann - * Creation Date: 2005-01-16 - * Tabsize: 4 - * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH - * License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt) - * This Revision: $Id$ - */ - /* -General Description: -This program controls the PowerSwitch USB device from the command line. -It must be linked with libusb, a library for accessing the USB bus from -Linux, FreeBSD, Mac OS X and other Unix operating systems. Libusb can be -obtained from http://libusb.sourceforge.net/. -*/ + * Copyright (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH + * and (c) 2016 by Daniel Friesel + * License: GNU GPL v2 + */ #include <unistd.h> #include <stdio.h> diff --git a/commandline/i2cget.c b/commandline/i2cget.c index f2bdb15..95243d4 100644 --- a/commandline/i2cget.c +++ b/commandline/i2cget.c @@ -7,13 +7,14 @@ int main(int argc, char **argv) { int i, address, cmdbuf; + int num_bytes = 1; unsigned int ret; char *conv_err; i2c_getopt(argc, argv); - if (argc < 3) { - fputs("Usage: vusb-i2cget <address> <register ...> ", stderr); + if (argc < 4) { + fputs("Usage: vusb-i2cget <address> <num_bytes> <register ...> ", stderr); return 1; } @@ -24,6 +25,13 @@ int main(int argc, char **argv) return 2; } + num_bytes = strtol(argv[2], &conv_err, 0); + + if (conv_err && *conv_err) { + fprintf(stderr, "num_bytes: Conversion error at '%s'\n", conv_err); + return 2; + } + i2c_init(); i2c_hw_start(); @@ -34,7 +42,7 @@ int main(int argc, char **argv) return 3; } - for (i = 2; i < argc; i++) { + for (i = 3; i < argc; i++) { cmdbuf = strtol(argv[i], &conv_err, 0); if (conv_err && *conv_err) { fprintf(stderr, "read command: Conversion error at '%s'\n", conv_err); @@ -58,12 +66,12 @@ int main(int argc, char **argv) return 3; } - ret = i2c_hw_rx_byte(0); + for (i = 0; i < num_bytes; i++) { + printf("%i\n", i2c_hw_rx_byte(1)); + } i2c_hw_stop(); i2c_deinit(); - printf("%i\n", ret); - return 0; } |