From 7ef3a94541d5a932c9d644766235de62d3271474 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 5 Sep 2021 18:27:28 -0500 Subject: [PATCH] Minor cleanup (mostly whitespace and curly brackets). --- toys/other/i2ctools.c | 69 ++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 37 deletions(-) diff --git a/toys/other/i2ctools.c b/toys/other/i2ctools.c index 1a0bc6a4..bac891a5 100644 --- a/toys/other/i2ctools.c +++ b/toys/other/i2ctools.c @@ -68,6 +68,7 @@ config I2CSET */ #define FOR_i2cdetect +#define TT this.i2ctools #include "toys.h" #include @@ -108,27 +109,25 @@ static unsigned long i2c_get_funcs(int bus) static int i2c_read_byte(int fd, int addr, int *byte) { union i2c_smbus_data data; - struct i2c_smbus_ioctl_data ioctl_data = { .read_write=I2C_SMBUS_READ, - .size=I2C_SMBUS_BYTE_DATA, .command=addr, .data=&data }; + struct i2c_smbus_ioctl_data ioctl_data = { .read_write = I2C_SMBUS_READ, + .size = I2C_SMBUS_BYTE_DATA, .command = addr, .data = &data }; memset(&data, 0, sizeof(data)); - if (ioctl(fd, I2C_SMBUS, &ioctl_data) == -1) return -1; + if (ioctl(fd, I2C_SMBUS, &ioctl_data)==-1) return -1; *byte = data.byte; return 0; } static int i2c_quick_write(int fd, int addr) { - struct i2c_smbus_ioctl_data ioctl_data = { .read_write=I2C_SMBUS_QUICK, - .size=0, .command=addr }; + struct i2c_smbus_ioctl_data ioctl_data = { .read_write = I2C_SMBUS_QUICK, + .size = 0, .command = addr }; return ioctl(fd, I2C_SMBUS, &ioctl_data); } static void i2cdetect_dash_F(int bus) { - size_t i; - struct { int mask; const char *name; } funcs[] = { {I2C_FUNC_I2C, "I2C"}, {I2C_FUNC_SMBUS_QUICK, "SMBus Quick Command"}, @@ -146,13 +145,12 @@ static void i2cdetect_dash_F(int bus) {I2C_FUNC_SMBUS_WRITE_I2C_BLOCK, "I2C Write Block"}, {I2C_FUNC_SMBUS_READ_I2C_BLOCK, "I2C Read Block"}, }; - unsigned long supported = i2c_get_funcs(bus); + unsigned long sup = i2c_get_funcs(bus); + int i; printf("Functionalities implemented by %s:\n", toybuf); - for (i = 0; i < ARRAY_LEN(funcs); ++i) { - printf("%-32s %s\n", funcs[i].name, - (supported & funcs[i].mask) ? "yes" : "no"); - } + for (i = 0; i < ARRAY_LEN(funcs); ++i) + printf("%-32s %s\n", funcs[i].name, (sup & funcs[i].mask) ? "yes" : "no"); } static int i2cdetect_dash_l(struct dirtree *node) @@ -164,7 +162,7 @@ static int i2cdetect_dash_l(struct dirtree *node) if (!node->parent) return DIRTREE_RECURSE; // Skip the directory itself. - if (sscanf(node->name, "i2c-%d", &bus) != 1) return 0; + if (sscanf(node->name, "i2c-%d", &bus)!=1) return 0; funcs = i2c_get_funcs(bus); fname = dirtree_path(node, &suffix_len); @@ -173,10 +171,9 @@ static int i2cdetect_dash_l(struct dirtree *node) free(fname); if ((p = strchr(toybuf, '\n'))) *p = 0; - // "i2c-1 i2c Synopsys DesignWare I2C adapter I2C adapter" + // "i2c-1 i2c Synopsys DesignWare I2C adapter I2C adapter" printf("%s\t%-10s\t%-32s\t%s\n", node->name, - (funcs & I2C_FUNC_I2C) ? "i2c" : "?", - toybuf, + (funcs & I2C_FUNC_I2C) ? "i2c" : "?", toybuf, (funcs & I2C_FUNC_I2C) ? "I2C Adapter" : "?"); return 0; @@ -198,9 +195,9 @@ void i2cdetect_main(void) last = 0x7f; } - if (toys.optc != 1 && toys.optc != 3) help_exit("Needs 1 or 3 arguments"); + if (toys.optc!=1 && toys.optc!=3) help_exit("Needs 1 or 3 arguments"); bus = atolx_range(*toys.optargs, 0, INT_MAX); - if (toys.optc == 3) { + if (toys.optc==3) { first = atolx_range(toys.optargs[1], 0, 0x7f); last = atolx_range(toys.optargs[2], 0, 0x7f); if (first > last) error_exit("first > last"); @@ -212,8 +209,8 @@ void i2cdetect_main(void) printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f\n"); for (row = 0; row <= 0x70; row += 16) { xprintf("%02x:", row & 0xf0); - for (addr = row; addr < row + 16; ++addr) { - if (addr < first || addr > last) printf(" "); + for (addr = row; addrlast) printf(" "); else { if (ioctl(fd, I2C_SLAVE, addr) == -1) { if (errno == EBUSY) { @@ -245,12 +242,12 @@ void i2cdump_main(void) confirm("Dump chip 0x%02x on bus %d?", chip, bus); - fd = i2c_open(bus, FLAG(f)?I2C_SLAVE_FORCE:I2C_SLAVE, chip); + fd = i2c_open(bus, FLAG(f) ? I2C_SLAVE_FORCE : I2C_SLAVE, chip); printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef\n"); - for (row = 0; row <= 0xf0; row += 16) { + for (row = 0; row<=0xf0; row += 16) { xprintf("%02x:", row & 0xf0); - for (addr = row; addr < row + 16; ++addr) { - if (i2c_read_byte(fd, addr, &byte) == -1) perror_exit("i2c_read_byte"); + for (addr = row; addr= 5) { - if (toys.optc - 4 > I2C_SMBUS_BLOCK_MAX) error_exit("too much data"); + } else if (*mode=='i' && toys.optc>=5) { + if (toys.optc-4>I2C_SMBUS_BLOCK_MAX) error_exit("too much data"); ioctl_data.size = I2C_SMBUS_I2C_BLOCK_DATA; - for (i = 0; i < toys.optc - 4; ++i) + for (i = 0; i