i2cget can be used without passing command byte
i2cget 3 0x50 0x5F <-- should shift out register 0x5F
i2cget 3 0x50 <-- should shift out register 0x60
---
 toys/other/i2ctools.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)


Related to https://github.com/landley/toybox/issues/414
From a914d1c316bc2c1a7c97994e5d4d7bd2d3cc8380 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jarno=20M=C3=A4kip=C3=A4=C3=A4?= <jmaki...@gmail.com>
Date: Fri, 17 Mar 2023 23:03:10 +0200
Subject: [PATCH] i2cget: add support for reading without passing command

i2cget can be used without passing command byte
i2cget 3 0x50 0x5F <-- should shift out register 0x5F
i2cget 3 0x50 <-- should shift out register 0x60
---
 toys/other/i2ctools.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/toys/other/i2ctools.c b/toys/other/i2ctools.c
index 8c9adca9..d20eb1ab 100644
--- a/toys/other/i2ctools.c
+++ b/toys/other/i2ctools.c
@@ -271,7 +271,10 @@ void i2cget_main(void)
   confirm("Read register 0x%02x from chip 0x%02x on bus %d?", addr, chip, bus);
 
   fd = i2c_open(bus, FLAG(f) ? I2C_SLAVE_FORCE : I2C_SLAVE, chip);
-  if (i2c_read_byte(fd, addr, &byte)==-1) perror_exit("i2c_read_byte");
+  if (toys.optc == 3) {
+    if (i2c_read_byte(fd, addr, &byte)==-1) perror_exit("i2c_read_byte");
+  } else if (read(fd, &byte, 1) != 1) perror_exit("i2c_read");
+
   printf("0x%02x\n", byte);
   close(fd);
 }
-- 
2.34.1

_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to