apps/system/i2c: Fix up some complaints from nxstyle.
This commit is contained in:
parent
720b854da2
commit
69022c9f2b
@ -55,8 +55,8 @@
|
||||
* Name: i2ctool_dump
|
||||
****************************************************************************/
|
||||
|
||||
static int i2ctool_dump(FAR struct i2ctool_s *i2ctool, int fd, uint8_t regaddr,
|
||||
FAR uint8_t *buf, int nbytes)
|
||||
static int i2ctool_dump(FAR struct i2ctool_s *i2ctool, int fd,
|
||||
uint8_t regaddr, FAR uint8_t *buf, int nbytes)
|
||||
{
|
||||
struct i2c_msg_s msg[2];
|
||||
int ret;
|
||||
@ -81,7 +81,7 @@ static int i2ctool_dump(FAR struct i2ctool_s *i2ctool, int fd, uint8_t regaddr,
|
||||
if (i2ctool->start)
|
||||
{
|
||||
ret = i2cdev_transfer(fd, &msg[0], 1);
|
||||
if (ret== OK)
|
||||
if (ret == OK)
|
||||
{
|
||||
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);
|
||||
|
||||
/* if the index register was set, print it */
|
||||
|
||||
if (i2ctool->hasregindx)
|
||||
{
|
||||
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 */
|
||||
|
||||
i2ctool_hexdump(OUTSTREAM(i2ctool), buf, dumpcnt);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
/* free read buffer */
|
||||
free(buf);
|
||||
/* free read buffer */
|
||||
|
||||
free(buf);
|
||||
|
||||
errout_with_fildes:
|
||||
(void)close(fd);
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
/****************************************************************************
|
||||
* 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 */
|
||||
|
||||
if (len > 16)
|
||||
{
|
||||
len = 16;
|
||||
}
|
||||
|
||||
/* print hex */
|
||||
|
||||
for (i = 0, p = addr; i < len; ++i, ++p)
|
||||
{
|
||||
if (i % 8 == 0)
|
||||
@ -80,6 +81,7 @@ static int hexdump_line(FILE *ostream, void *addr, int len)
|
||||
}
|
||||
|
||||
/* pad if necessary */
|
||||
|
||||
if (i <= 8)
|
||||
{
|
||||
fputc(' ', ostream);
|
||||
@ -91,6 +93,7 @@ static int hexdump_line(FILE *ostream, void *addr, int len)
|
||||
}
|
||||
|
||||
/* print ASCII */
|
||||
|
||||
fputs(" |", ostream);
|
||||
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 */
|
||||
|
||||
while (i++ < 16)
|
||||
{
|
||||
fputc(' ', ostream);
|
||||
}
|
||||
|
||||
fputs("|\n", ostream);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
@ -118,12 +121,15 @@ void i2ctool_hexdump(FILE *outstream, void *addr, int len)
|
||||
uint8_t *p = addr;
|
||||
|
||||
/* print one line at a time */
|
||||
|
||||
while (len > 0)
|
||||
{
|
||||
/* print address */
|
||||
|
||||
fprintf(outstream, "%08x ", p - (uint8_t *) addr);
|
||||
|
||||
/* print one line of data */
|
||||
|
||||
nbytes = hexdump_line(outstream, p, len);
|
||||
len -= nbytes;
|
||||
p += nbytes;
|
||||
|
@ -57,7 +57,8 @@
|
||||
****************************************************************************/
|
||||
|
||||
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
|
||||
@ -110,7 +111,8 @@ static int i2ccmd_help(FAR struct i2ctool_s *i2ctool, int argc, char **argv)
|
||||
{
|
||||
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
|
||||
{
|
||||
@ -158,7 +160,8 @@ static int i2ccmd_help(FAR struct i2ctool_s *i2ctool, int argc, char **argv)
|
||||
* 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]);
|
||||
return ERROR;
|
||||
@ -168,10 +171,11 @@ static int i2ccmd_unrecognized(FAR struct i2ctool_s *i2ctool, int argc, char **a
|
||||
* 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;
|
||||
const char *cmd;
|
||||
FAR const struct cmdmap_s *cmdmap;
|
||||
FAR const char *cmd;
|
||||
cmd_t handler;
|
||||
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 */
|
||||
|
||||
FAR char *value = getenv(arg+1);
|
||||
FAR char *value = getenv(arg + 1);
|
||||
if (value)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (FAR char*)"";
|
||||
return (FAR char *)"";
|
||||
}
|
||||
}
|
||||
#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[])
|
||||
{
|
||||
FAR char *newargs[MAX_ARGUMENTS+2];
|
||||
FAR char *newargs[MAX_ARGUMENTS + 2];
|
||||
FAR char *cmd;
|
||||
int nargs;
|
||||
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;
|
||||
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;
|
||||
|
||||
|
@ -54,9 +54,13 @@
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* 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_MAXADDR - Largest device address (default: 0x77)
|
||||
* CONFIG_I2CTOOL_MAXREGADDR - Largest register address (default: 0xff)
|
||||
@ -154,7 +158,8 @@ struct i2ctool_s
|
||||
#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
|
||||
{
|
||||
@ -182,7 +187,8 @@ extern const char g_i2cxfrerror[];
|
||||
|
||||
/* 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, ...);
|
||||
void i2ctool_flush(FAR struct i2ctool_s *i2ctool);
|
||||
void i2ctool_hexdump(FILE *outstream, void *addr, int len);
|
||||
|
Loading…
x
Reference in New Issue
Block a user