diff options
author | Daniel Friesel <derf@finalrewind.org> | 2015-12-27 16:54:43 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2015-12-27 16:54:43 +0100 |
commit | 9f7affef4da478251a572c7ce806dc05a4c3203c (patch) | |
tree | 316f941cf94a595b721a1eb9657f61bc90f198a2 | |
parent | 5e0499b2e51b57ba7c9bc7ec4058de400267fc67 (diff) | |
parent | 54380f5a63b5e5e220a77fb712309217be81170b (diff) |
Merge branch 'master' of lastlight:var/git_root/vusb-i2c
-rw-r--r-- | commandline/i2cget.c | 23 | ||||
-rw-r--r-- | commandline/i2cset.c | 18 |
2 files changed, 28 insertions, 13 deletions
diff --git a/commandline/i2cget.c b/commandline/i2cget.c index 041ffad..c7cd18f 100644 --- a/commandline/i2cget.c +++ b/commandline/i2cget.c @@ -6,7 +6,7 @@ int main(int argc, char **argv) { - int i, address, cmdbuf, got_ack; + int i, address, cmdbuf; unsigned int ret; char *conv_err; @@ -22,23 +22,32 @@ int main(int argc, char **argv) address = strtol(argv[1], &conv_err, 0); if (conv_err && *conv_err) { - fprintf(stderr, "address: Conversion error at '%s'", conv_err); + fprintf(stderr, "address: Conversion error at '%s'\n", conv_err); return 2; } - i2c_tx_byte((address << 1) | 0); + if (!i2c_tx_byte((address << 1) | 0)) { + fprintf(stderr, "Received NAK from slave 0x%02x, aborting\n", address); + return 3; + } for (i = 2; i < argc; i++) { cmdbuf = strtol(argv[i], &conv_err, 0); if (conv_err && *conv_err) { - fprintf(stderr, "read command: Conversion error at '%s'", conv_err); + fprintf(stderr, "read command: Conversion error at '%s'\n", conv_err); return 2; } - i2c_tx_byte(cmdbuf); + if (!i2c_tx_byte(cmdbuf)) { + fprintf(stderr, "Received NAK after byte %d (0x%02x)\n", i-1, cmdbuf); + return 4; + } } i2c_start(); - got_ack = i2c_tx_byte((address << 1) | 1); + if (!i2c_tx_byte((address << 1) | 1)) { + fprintf(stderr, "Received NAK after reSTART from slave 0x%02x, aborting\n", address); + return 3; + } ret = i2c_rx_byte(0); @@ -47,5 +56,5 @@ int main(int argc, char **argv) printf("%i\n", ret); - return got_ack ? 0 : 1; + return 0; } diff --git a/commandline/i2cset.c b/commandline/i2cset.c index 3edaf81..5b2662c 100644 --- a/commandline/i2cset.c +++ b/commandline/i2cset.c @@ -6,7 +6,7 @@ int main(int argc, char **argv) { - int i, address, cmdbuf, got_ack; + int i, address, cmdbuf; char *conv_err; i2c_getopt(argc, argv); @@ -21,23 +21,29 @@ int main(int argc, char **argv) address = strtol(argv[1], &conv_err, 0); if (conv_err && *conv_err) { - fprintf(stderr, "Conversion error at '%s'", conv_err); + fprintf(stderr, "Conversion error at '%s'\n", conv_err); return 2; } - got_ack = i2c_tx_byte(address << 1); + if (!i2c_tx_byte(address << 1)) { + fprintf(stderr, "Received NAK from slave 0x%02x, aborting\n", address); + return 3; + } for (i = 2; i < argc; i++) { cmdbuf = strtol(argv[i], &conv_err, 0); if (conv_err && *conv_err) { - fprintf(stderr, "write command: conversion error at '%s'", conv_err); + fprintf(stderr, "write command: conversion error at '%s'\n", conv_err); return 2; } - i2c_tx_byte(cmdbuf); + if (!i2c_tx_byte(cmdbuf)) { + fprintf(stderr, "Received NAK after byte %d (0x%02x)\n", i-1, cmdbuf); + return 4; + } } i2c_stop(); i2c_deinit(); - return got_ack ? 0 : 1; + return 0; } |