summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2013-07-29 10:14:12 +0200
committerDaniel Friesel <derf@finalrewind.org>2013-07-29 10:14:12 +0200
commitad514a44325de866e94a2704e07b102bf8eca0be (patch)
tree7428ca7739b302bf104595565a58a67012eeda41
parent3fac022999e009cb7cfd7773c4e59308cb74889c (diff)
i2cget: read 16bit ints as well
-rw-r--r--commandline/i2c-util.c6
-rw-r--r--commandline/i2c-util.h2
-rw-r--r--commandline/i2cget.c17
3 files changed, 20 insertions, 5 deletions
diff --git a/commandline/i2c-util.c b/commandline/i2c-util.c
index 2771a4e..44ea4d3 100644
--- a/commandline/i2c-util.c
+++ b/commandline/i2c-util.c
@@ -267,17 +267,21 @@ unsigned char i2c_tx_byte(unsigned char byte)
return ack;
}
-unsigned char i2c_rx_byte()
+unsigned char i2c_rx_byte(unsigned char send_ack)
{
signed char i;
unsigned char ret = 0;
set_sda(1);
for (i = 7; i >= -1; i--) {
+ if (( i < 0) && send_ack)
+ set_sda(0);
set_scl(1);
usleep(10);
if ((i >= 0) && ( get_status() & (1 << BIT_SDA)))
ret |= (1 << i);
+ if (( i < 0) && send_ack)
+ set_sda(1);
set_scl(0);
usleep(10);
}
diff --git a/commandline/i2c-util.h b/commandline/i2c-util.h
index 4cd4919..6bf13b3 100644
--- a/commandline/i2c-util.h
+++ b/commandline/i2c-util.h
@@ -11,7 +11,7 @@ void set_scl(char value);
unsigned char get_status();
unsigned char i2c_tx_byte(unsigned char byte);
-unsigned char i2c_rx_byte();
+unsigned char i2c_rx_byte(unsigned char send_ack);
void i2c_start();
void i2c_stop();
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();