diff options
author | Daniel Friesel <derf@finalrewind.org> | 2018-01-17 20:46:46 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2018-01-17 20:46:46 +0100 |
commit | 66dff1bf02d3c648d4e15f7e76960560021fb4d1 (patch) | |
tree | 49f955095bcb57b5817cf8f205788e3d8f1d9ff7 | |
parent | 045391dddb59cc8b5cf8ee71ba0a367ba1a04ef7 (diff) |
i2cget: Support reads without prior register address write
-rw-r--r-- | commandline/i2cget.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/commandline/i2cget.c b/commandline/i2cget.c index f27ea51..ce83148 100644 --- a/commandline/i2cget.c +++ b/commandline/i2cget.c @@ -13,8 +13,8 @@ int main(int argc, char **argv) i2c_getopt(argc, argv); - if (argc < 4) { - fputs("Usage: vusb-i2cget <address> <num_bytes> <register ...> ", stderr); + if (argc < 3) { + fputs("Usage: vusb-i2cget <address> <num_bytes> [register ...] ", stderr); return 1; } @@ -33,13 +33,16 @@ int main(int argc, char **argv) } i2c_init(); - i2c_hw_start(); - if (!i2c_hw_tx_byte((address << 1) | 0)) { - fprintf(stderr, "Received NAK from slave 0x%02x, aborting\n", address); - i2c_hw_stop(); - i2c_deinit(); - return 3; + if (argc >= 3) { + i2c_hw_start(); + + if (!i2c_hw_tx_byte((address << 1) | 0)) { + fprintf(stderr, "Received NAK from slave 0x%02x, aborting\n", address); + i2c_hw_stop(); + i2c_deinit(); + return 3; + } } for (i = 3; i < argc; i++) { |