diff options
author | Daniel Friesel <derf@finalrewind.org> | 2013-10-04 11:38:15 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2013-10-04 11:38:15 +0200 |
commit | 52da7aebb9bb2929ecdc9838ab54f6bb76e949bb (patch) | |
tree | 6baae2b44f43b7614f983c25d5356456e058c02e | |
parent | 6e37676eeb19cfea01180dd6bd00fe888131a196 (diff) |
i2cget: Allow read commands of arbitrary length
-rw-r--r-- | commandline/i2cget.c | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/commandline/i2cget.c b/commandline/i2cget.c index 4138722..a0b2330 100644 --- a/commandline/i2cget.c +++ b/commandline/i2cget.c @@ -6,16 +6,15 @@ int main(int argc, char **argv) { - int address, command, got_ack; + int i, address, cmdbuf, got_ack; unsigned int ret; - char mode = 'c'; char *conv_err; i2c_init(); i2c_start(); if (argc < 3) { - fputs("Usage: vusb-i2cget <address> <register> [mode]", stderr); + fputs("Usage: vusb-i2cget <address> <register ...> ", stderr); return 1; } @@ -26,27 +25,21 @@ int main(int argc, char **argv) return 2; } - command = strtol(argv[2], &conv_err, 0); + i2c_tx_byte((address << 1) | 0); - if (conv_err && *conv_err) { - fprintf(stderr, "command: conversion error at '%s'", conv_err); - return 2; + 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); + return 2; + } + i2c_tx_byte(cmdbuf); } - if (argc == 4) - mode = argv[3][0]; - - i2c_tx_byte((address << 1) | 0); - i2c_tx_byte(command); i2c_start(); got_ack = i2c_tx_byte((address << 1) | 1); - if (mode == 'i') { - ret = i2c_rx_byte(1); - ret |= (i2c_rx_byte(0) << 8); - } - else - ret = i2c_rx_byte(0); + ret = i2c_rx_byte(0); i2c_stop(); i2c_deinit(); |