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
****************************************************************************/
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);
}
@ -176,8 +176,8 @@ int i2ccmd_dump(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv)
fd = i2cdev_open(i2ctool->bus);
if (fd < 0)
{
i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus);
return ERROR;
i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus);
return ERROR;
}
regaddr = i2ctool->regaddr;
@ -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);

View File

@ -1,4 +1,3 @@
/****************************************************************************
* apps/system/i2c/i2c_hexdump.c
*
@ -58,53 +57,57 @@ static int hexdump_line(FILE *ostream, void *addr, int len)
uint8_t *p;
if (len <= 0)
{
return 0;
}
{
return 0;
}
/* print at most 16 chars */
if (len > 16)
{
len = 16;
}
{
len = 16;
}
/* print hex */
for (i = 0, p = addr; i < len; ++i, ++p)
{
if (i % 8 == 0)
{
fputc(' ', ostream);
}
{
fputc(' ', ostream);
}
fprintf(ostream, "%02x ", *p);
}
/* pad if necessary */
if (i <= 8)
{
fputc(' ', ostream);
}
{
fputc(' ', ostream);
}
while (i++ < 16)
{
fputs(" ", ostream);
}
{
fputs(" ", ostream);
}
/* print ASCII */
fputs(" |", ostream);
for (i = 0, p = addr; i < len; ++i, ++p)
{
fputc(isprint(*p) ? *p : '.', ostream);
}
{
fputc(isprint(*p) ? *p : '.', ostream);
}
/* pad if necessary */
while (i++ < 16)
{
fputc(' ', ostream);
}
{
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;

View File

@ -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
@ -84,13 +85,13 @@ static const struct cmdmap_s g_i2ccmds[] =
/* Common, message formats */
const char g_i2cargrequired[] = "i2ctool: %s: missing required argument(s)\n";
const char g_i2carginvalid[] = "i2ctool: %s: argument invalid\n";
const char g_i2cargrange[] = "i2ctool: %s: value out of range\n";
const char g_i2ccmdnotfound[] = "i2ctool: %s: command not found\n";
const char g_i2ctoomanyargs[] = "i2ctool: %s: too many arguments\n";
const char g_i2ccmdfailed[] = "i2ctool: %s: %s failed: %d\n";
const char g_i2cxfrerror[] = "i2ctool: %s: Transfer failed: %d\n";
const char g_i2cargrequired[] = "i2ctool: %s: missing required argument(s)\n";
const char g_i2carginvalid[] = "i2ctool: %s: argument invalid\n";
const char g_i2cargrange[] = "i2ctool: %s: value out of range\n";
const char g_i2ccmdnotfound[] = "i2ctool: %s: command not found\n";
const char g_i2ctoomanyargs[] = "i2ctool: %s: too many arguments\n";
const char g_i2ccmdfailed[] = "i2ctool: %s: %s failed: %d\n";
const char g_i2cxfrerror[] = "i2ctool: %s: Transfer failed: %d\n";
/****************************************************************************
* Private Functions
@ -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,37 +171,38 @@ 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;
cmd_t handler;
int ret;
FAR const struct cmdmap_s *cmdmap;
FAR const char *cmd;
cmd_t handler;
int ret;
/* The form of argv is:
*
* argv[0]: The command name. This is argv[0] when the arguments
* are, finally, received by the command vtblr
* argv[1]: The beginning of argument (up to MAX_ARGUMENTS)
* argv[argc]: NULL terminating pointer
*/
/* The form of argv is:
*
* argv[0]: The command name. This is argv[0] when the arguments
* are, finally, received by the command vtblr
* argv[1]: The beginning of argument (up to MAX_ARGUMENTS)
* argv[argc]: NULL terminating pointer
*/
/* See if the command is one that we understand */
/* See if the command is one that we understand */
cmd = argv[0];
handler = i2ccmd_unrecognized;
cmd = argv[0];
handler = i2ccmd_unrecognized;
for (cmdmap = g_i2ccmds; cmdmap->cmd; cmdmap++)
{
if (strcmp(cmdmap->cmd, cmd) == 0)
{
handler = cmdmap->handler;
break;
}
}
for (cmdmap = g_i2ccmds; cmdmap->cmd; cmdmap++)
{
if (strcmp(cmdmap->cmd, cmd) == 0)
{
handler = cmdmap->handler;
break;
}
}
ret = handler(i2ctool, argc, argv);
return ret;
ret = handler(i2ctool, argc, argv);
return 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;

View File

@ -54,13 +54,17 @@
/****************************************************************************
* 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_MINADDR - Minium device address (default: 0x03)
* CONFIG_I2CTOOL_MAXADDR - Largest device address (default: 0x77)
/* 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)
* CONFIG_I2CTOOL_DEFFREQ - Default frequency (default: 4000000)
* CONFIG_I2CTOOL_DEFFREQ - Default frequency (default: 4000000)
*/
#ifndef CONFIG_I2CTOOL_MINBUS
@ -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);