diff options
Diffstat (limited to 'commandline/i2cget.c')
-rw-r--r-- | commandline/i2cget.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/commandline/i2cget.c b/commandline/i2cget.c index ed453ac..b7c0245 100644 --- a/commandline/i2cget.c +++ b/commandline/i2cget.c @@ -7,23 +7,34 @@ int main(int argc, char **argv) { int address, command; - unsigned char ret; + unsigned int ret; + char mode = 'c'; i2c_init(); i2c_start(); if (argc < 3) { - fputs("Usage: vusb-i2cget <address> <register>", stderr); + fputs("Usage: vusb-i2cget <address> <register> [mode]", stderr); return 1; } address = atoi(argv[1]); command = atoi(argv[2]); + + if (argc == 4) + mode = argv[3][0]; + i2c_tx_byte((address << 1) | 0); i2c_tx_byte(command); i2c_start(); i2c_tx_byte((address << 1) | 1); - ret = i2c_rx_byte(); + + if (mode == 'i') { + ret = i2c_rx_byte(1); + ret |= (i2c_rx_byte(0) << 8); + } + else + ret = i2c_rx_byte(0); i2c_stop(); i2c_deinit(); |