From e8f2f55d5298f2b879c7b9a62971ee30a30d49f0 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 15 Mar 2023 16:42:54 -0500 Subject: [PATCH] Add "next address" support to i2cget, and enforce bus limit. --- toys/other/i2ctools.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/toys/other/i2ctools.c b/toys/other/i2ctools.c index d49f66f2..8c9adca9 100644 --- a/toys/other/i2ctools.c +++ b/toys/other/i2ctools.c @@ -13,7 +13,7 @@ USE_I2CDETECT(NEWTOY(i2cdetect, ">3aFlqry[!qr]", TOYFLAG_USR|TOYFLAG_SBIN)) USE_I2CDUMP(NEWTOY(i2cdump, "<2>2fy", TOYFLAG_USR|TOYFLAG_SBIN)) -USE_I2CGET(NEWTOY(i2cget, "<3>3fy", TOYFLAG_USR|TOYFLAG_SBIN)) +USE_I2CGET(NEWTOY(i2cget, "<2>3fy", TOYFLAG_USR|TOYFLAG_SBIN)) USE_I2CSET(NEWTOY(i2cset, "<4fy", TOYFLAG_USR|TOYFLAG_SBIN)) config I2CDETECT @@ -48,7 +48,7 @@ config I2CGET bool "i2cget" default y help - usage: i2cget [-fy] BUS CHIP ADDR + usage: i2cget [-fy] BUS CHIP [ADDR] Read an i2c register. @@ -263,9 +263,9 @@ void i2cdump_main(void) void i2cget_main(void) { - int bus = atolx_range(toys.optargs[0], 0, INT_MAX); + int bus = atolx_range(toys.optargs[0], 0, 0x3f); int chip = atolx_range(toys.optargs[1], 0, 0x7f); - int addr = atolx_range(toys.optargs[2], 0, 0xff); + int addr = (toys.optc == 3) ? atolx_range(toys.optargs[2], 0, 0xff) : -1; int fd, byte; confirm("Read register 0x%02x from chip 0x%02x on bus %d?", addr, chip, bus); -- 2.39.2