diff options
Diffstat (limited to 'commandline')
-rw-r--r-- | commandline/Makefile | 6 | ||||
-rw-r--r-- | commandline/i2cset.c | 31 | ||||
-rw-r--r-- | commandline/i2cwrite.c | 22 |
3 files changed, 34 insertions, 25 deletions
diff --git a/commandline/Makefile b/commandline/Makefile index 587f86c..3a1c918 100644 --- a/commandline/Makefile +++ b/commandline/Makefile @@ -9,7 +9,7 @@ LIBS = $(USBLIBS) PREFIX ?= /usr/local bin_dir = ${DESTDIR}${PREFIX}/bin -PROGRAMS = vusb-i2c vusb-i2cdetect vusb-i2cwrite vusb-i2cget +PROGRAMS = vusb-i2c vusb-i2cdetect vusb-i2cset vusb-i2cget all: $(PROGRAMS) @@ -19,7 +19,7 @@ all: $(PROGRAMS) i2c.o: i2c.c i2c-util.c i2c-util.h i2c-util.o: i2c-util.c i2cdetect.o: i2cdetect.c i2c-util.c i2c-util.h -i2cwrite.o: i2cwrite.c i2c-util.c i2c-util.h +i2cset.o: i2cset.c i2c-util.c i2c-util.h i2cget.o: i2cget.c i2c-util.c i2c-util.h vusb-i2c: i2c.o i2c-util.o @@ -28,7 +28,7 @@ vusb-i2c: i2c.o i2c-util.o vusb-i2cdetect: i2cdetect.o i2c-util.o $(CC) -o $@ $^ $(LIBS) -vusb-i2cwrite: i2cwrite.o i2c-util.o +vusb-i2cset: i2cset.o i2c-util.o $(CC) -o $@ $^ $(LIBS) vusb-i2cget: i2cget.o i2c-util.o diff --git a/commandline/i2cset.c b/commandline/i2cset.c new file mode 100644 index 0000000..971783a --- /dev/null +++ b/commandline/i2cset.c @@ -0,0 +1,31 @@ +#include <unistd.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "i2c-util.h" + +int main(int argc, char **argv) +{ + int i, address, got_ack; + + i2c_init(); + i2c_start(); + + if (argc < 3) { + fputs("Usage: i2cset <address> <data ...>", stderr); + return 1; + } + + address = atoi(argv[1]) << 1; + + got_ack = i2c_tx_byte(address); + + for (i = 2; i < argc; i++) { + i2c_tx_byte(atoi(argv[i])); + } + + i2c_stop(); + i2c_deinit(); + + return got_ack ? 0 : 1; +} diff --git a/commandline/i2cwrite.c b/commandline/i2cwrite.c deleted file mode 100644 index 56031f9..0000000 --- a/commandline/i2cwrite.c +++ /dev/null @@ -1,22 +0,0 @@ -#include <unistd.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "i2c-util.h" - -int main(int argc, char **argv) -{ - int i; - - i2c_init(); - i2c_start(); - - for (i = 1; i < argc; i++) { - i2c_tx_byte(atoi(argv[i])); - } - - i2c_stop(); - i2c_deinit(); - - return 0; -} |