apps/system/i2c: Fix up some complaints from nxstyle.

This commit is contained in:
Gregory Nutt 2019-10-15 06:30:57 +08:00
parent 720b854da2
commit 69022c9f2b
4 changed files with 97 additions and 77 deletions

View File

@ -55,8 +55,8 @@
* Name: i2ctool_dump * Name: i2ctool_dump
****************************************************************************/ ****************************************************************************/
static int i2ctool_dump(FAR struct i2ctool_s *i2ctool, int fd, uint8_t regaddr, static int i2ctool_dump(FAR struct i2ctool_s *i2ctool, int fd,
FAR uint8_t *buf, int nbytes) uint8_t regaddr, FAR uint8_t *buf, int nbytes)
{ {
struct i2c_msg_s msg[2]; struct i2c_msg_s msg[2];
int ret; int ret;
@ -81,7 +81,7 @@ static int i2ctool_dump(FAR struct i2ctool_s *i2ctool, int fd, uint8_t regaddr,
if (i2ctool->start) if (i2ctool->start)
{ {
ret = i2cdev_transfer(fd, &msg[0], 1); ret = i2cdev_transfer(fd, &msg[0], 1);
if (ret== OK) if (ret == OK)
{ {
ret = i2cdev_transfer(fd, &msg[1], 1); ret = i2cdev_transfer(fd, &msg[1], 1);
} }
@ -203,6 +203,7 @@ int i2ccmd_dump(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv)
i2ctool->bus, i2ctool->addr); i2ctool->bus, i2ctool->addr);
/* if the index register was set, print it */ /* if the index register was set, print it */
if (i2ctool->hasregindx) if (i2ctool->hasregindx)
{ {
i2ctool_printf(i2ctool, "%02x\n", regaddr); i2ctool_printf(i2ctool, "%02x\n", regaddr);
@ -213,6 +214,7 @@ int i2ccmd_dump(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv)
} }
/* dump the data in hex and ASCII format */ /* dump the data in hex and ASCII format */
i2ctool_hexdump(OUTSTREAM(i2ctool), buf, dumpcnt); i2ctool_hexdump(OUTSTREAM(i2ctool), buf, dumpcnt);
} }
else else
@ -220,8 +222,9 @@ int i2ccmd_dump(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv)
i2ctool_printf(i2ctool, g_i2cxfrerror, argv[0], -ret); i2ctool_printf(i2ctool, g_i2cxfrerror, argv[0], -ret);
} }
/* free read buffer */ /* free read buffer */
free(buf);
free(buf);
errout_with_fildes: errout_with_fildes:
(void)close(fd); (void)close(fd);

View File

@ -1,4 +1,3 @@
/**************************************************************************** /****************************************************************************
* apps/system/i2c/i2c_hexdump.c * apps/system/i2c/i2c_hexdump.c
* *
@ -63,12 +62,14 @@ static int hexdump_line(FILE *ostream, void *addr, int len)
} }
/* print at most 16 chars */ /* print at most 16 chars */
if (len > 16) if (len > 16)
{ {
len = 16; len = 16;
} }
/* print hex */ /* print hex */
for (i = 0, p = addr; i < len; ++i, ++p) for (i = 0, p = addr; i < len; ++i, ++p)
{ {
if (i % 8 == 0) if (i % 8 == 0)
@ -80,6 +81,7 @@ static int hexdump_line(FILE *ostream, void *addr, int len)
} }
/* pad if necessary */ /* pad if necessary */
if (i <= 8) if (i <= 8)
{ {
fputc(' ', ostream); fputc(' ', ostream);
@ -91,6 +93,7 @@ static int hexdump_line(FILE *ostream, void *addr, int len)
} }
/* print ASCII */ /* print ASCII */
fputs(" |", ostream); fputs(" |", ostream);
for (i = 0, p = addr; i < len; ++i, ++p) for (i = 0, p = addr; i < len; ++i, ++p)
{ {
@ -98,13 +101,13 @@ static int hexdump_line(FILE *ostream, void *addr, int len)
} }
/* pad if necessary */ /* pad if necessary */
while (i++ < 16) while (i++ < 16)
{ {
fputc(' ', ostream); fputc(' ', ostream);
} }
fputs("|\n", ostream); fputs("|\n", ostream);
return len; return len;
} }
@ -118,12 +121,15 @@ void i2ctool_hexdump(FILE *outstream, void *addr, int len)
uint8_t *p = addr; uint8_t *p = addr;
/* print one line at a time */ /* print one line at a time */
while (len > 0) while (len > 0)
{ {
/* print address */ /* print address */
fprintf(outstream, "%08x ", p - (uint8_t *) addr); fprintf(outstream, "%08x ", p - (uint8_t *) addr);
/* print one line of data */ /* print one line of data */
nbytes = hexdump_line(outstream, p, len); nbytes = hexdump_line(outstream, p, len);
len -= nbytes; len -= nbytes;
p += nbytes; p += nbytes;

View File

@ -57,7 +57,8 @@
****************************************************************************/ ****************************************************************************/
static int i2ccmd_help(FAR struct i2ctool_s *i2ctool, int argc, char **argv); static int i2ccmd_help(FAR struct i2ctool_s *i2ctool, int argc, char **argv);
static int i2ccmd_unrecognized(FAR struct i2ctool_s *i2ctool, int argc, char **argv); static int i2ccmd_unrecognized(FAR struct i2ctool_s *i2ctool, int argc,
FAR char **argv);
/**************************************************************************** /****************************************************************************
* Private Data * Private Data
@ -110,7 +111,8 @@ static int i2ccmd_help(FAR struct i2ctool_s *i2ctool, int argc, char **argv)
{ {
if (ptr->usage) if (ptr->usage)
{ {
i2ctool_printf(i2ctool, " %s: %s %s\n", ptr->desc, ptr->cmd, ptr->usage); i2ctool_printf(i2ctool, " %s: %s %s\n",
ptr->desc, ptr->cmd, ptr->usage);
} }
else else
{ {
@ -158,7 +160,8 @@ static int i2ccmd_help(FAR struct i2ctool_s *i2ctool, int argc, char **argv)
* Name: i2ccmd_unrecognized * Name: i2ccmd_unrecognized
****************************************************************************/ ****************************************************************************/
static int i2ccmd_unrecognized(FAR struct i2ctool_s *i2ctool, int argc, char **argv) static int i2ccmd_unrecognized(FAR struct i2ctool_s *i2ctool, int argc,
FAR char **argv)
{ {
i2ctool_printf(i2ctool, g_i2ccmdnotfound, argv[0]); i2ctool_printf(i2ctool, g_i2ccmdnotfound, argv[0]);
return ERROR; return ERROR;
@ -168,10 +171,11 @@ static int i2ccmd_unrecognized(FAR struct i2ctool_s *i2ctool, int argc, char **a
* Name: i2c_execute * Name: i2c_execute
****************************************************************************/ ****************************************************************************/
static int i2c_execute(FAR struct i2ctool_s *i2ctool, int argc, char *argv[]) static int i2c_execute(FAR struct i2ctool_s *i2ctool, int argc,
FAR char *argv[])
{ {
const struct cmdmap_s *cmdmap; FAR const struct cmdmap_s *cmdmap;
const char *cmd; FAR const char *cmd;
cmd_t handler; cmd_t handler;
int ret; int ret;
@ -230,14 +234,14 @@ static FAR char *i2c_argument(FAR struct i2ctool_s *i2ctool,
{ {
/* Return the value of the environment variable with this name */ /* Return the value of the environment variable with this name */
FAR char *value = getenv(arg+1); FAR char *value = getenv(arg + 1);
if (value) if (value)
{ {
return value; return value;
} }
else else
{ {
return (FAR char*)""; return (FAR char *)"";
} }
} }
#endif #endif
@ -253,12 +257,12 @@ static FAR char *i2c_argument(FAR struct i2ctool_s *i2ctool,
static int i2c_parse(FAR struct i2ctool_s *i2ctool, int argc, char *argv[]) static int i2c_parse(FAR struct i2ctool_s *i2ctool, int argc, char *argv[])
{ {
FAR char *newargs[MAX_ARGUMENTS+2]; FAR char *newargs[MAX_ARGUMENTS + 2];
FAR char *cmd; FAR char *cmd;
int nargs; int nargs;
int index; int index;
/* Parse out the command, skipping the first argument (the program name)*/ /* Parse out the command, skipping the first argument (the program name) */
index = 1; index = 1;
cmd = i2c_argument(i2ctool, argc, argv, &index); cmd = i2c_argument(i2ctool, argc, argv, &index);
@ -419,7 +423,8 @@ int i2ctool_printf(FAR struct i2ctool_s *i2ctool, const char *fmt, ...)
* *
****************************************************************************/ ****************************************************************************/
ssize_t i2ctool_write(FAR struct i2ctool_s *i2ctool, FAR const void *buffer, size_t nbytes) ssize_t i2ctool_write(FAR struct i2ctool_s *i2ctool, FAR const void *buffer,
size_t nbytes)
{ {
ssize_t ret; ssize_t ret;

View File

@ -54,9 +54,13 @@
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
/* Configuration ************************************************************/ /* Configuration ************************************************************/
/* CONFIG_I2CTOOL_MINBUS - Smallest bus index supported by the hardware (default 0).
* CONFIG_I2CTOOL_MAXBUS - Largest bus index supported by the hardware (default 3) /* CONFIG_I2CTOOL_MINBUS - Smallest bus index supported by the hardware
* (default 0).
* CONFIG_I2CTOOL_MAXBUS - Largest bus index supported by the hardware
* (default 3)
* CONFIG_I2CTOOL_MINADDR - Minium device address (default: 0x03) * CONFIG_I2CTOOL_MINADDR - Minium device address (default: 0x03)
* CONFIG_I2CTOOL_MAXADDR - Largest device address (default: 0x77) * CONFIG_I2CTOOL_MAXADDR - Largest device address (default: 0x77)
* CONFIG_I2CTOOL_MAXREGADDR - Largest register address (default: 0xff) * CONFIG_I2CTOOL_MAXREGADDR - Largest register address (default: 0xff)
@ -154,7 +158,8 @@ struct i2ctool_s
#endif #endif
}; };
typedef int (*cmd_t)(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv); typedef int (*cmd_t)(FAR struct i2ctool_s *i2ctool, int argc,
FAR char **argv);
struct cmdmap_s struct cmdmap_s
{ {
@ -182,7 +187,8 @@ extern const char g_i2cxfrerror[];
/* Message handler */ /* Message handler */
ssize_t i2ctool_write(FAR struct i2ctool_s *i2ctool, FAR const void *buffer, size_t nbytes); ssize_t i2ctool_write(FAR struct i2ctool_s *i2ctool, FAR const void *buffer,
size_t nbytes);
int i2ctool_printf(FAR struct i2ctool_s *i2ctool, const char *fmt, ...); int i2ctool_printf(FAR struct i2ctool_s *i2ctool, const char *fmt, ...);
void i2ctool_flush(FAR struct i2ctool_s *i2ctool); void i2ctool_flush(FAR struct i2ctool_s *i2ctool);
void i2ctool_hexdump(FILE *outstream, void *addr, int len); void i2ctool_hexdump(FILE *outstream, void *addr, int len);