You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/02/23 16:49:30 UTC
[incubator-nuttx-apps] 02/02: system/i2c: Fix nxstyle issues
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit f7e9d09566a36a982520121e6d6b527ab30c4fe1
Author: Gustavo Henrique Nihei <gu...@espressif.com>
AuthorDate: Tue Feb 23 10:44:21 2021 -0300
system/i2c: Fix nxstyle issues
---
system/i2c/i2c_get.c | 15 ++++++-----
system/i2c/i2c_main.c | 71 ++++++++++++++++++++++++++++++++++-----------------
system/i2c/i2c_set.c | 15 ++++++-----
system/i2c/i2c_verf.c | 26 +++++++++++--------
4 files changed, 79 insertions(+), 48 deletions(-)
diff --git a/system/i2c/i2c_get.c b/system/i2c/i2c_get.c
index ffa606d..ca8998e 100644
--- a/system/i2c/i2c_get.c
+++ b/system/i2c/i2c_get.c
@@ -116,8 +116,8 @@ int i2ccmd_get(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;
}
/* Loop for the requested number of repetitions */
@@ -135,7 +135,8 @@ int i2ccmd_get(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv)
if (ret == OK)
{
- i2ctool_printf(i2ctool, "READ Bus: %d Addr: %02x Subaddr: %02x Value: ",
+ i2ctool_printf(i2ctool,
+ "READ Bus: %d Addr: %02x Subaddr: %02x Value: ",
i2ctool->bus, i2ctool->addr, regaddr);
if (i2ctool->width == 8)
@@ -173,12 +174,12 @@ int i2ctool_get(FAR struct i2ctool_s *i2ctool, int fd, uint8_t regaddr,
FAR uint16_t *result)
{
struct i2c_msg_s msg[2];
+ int ret;
union
{
uint16_t data16;
uint8_t data8;
} u;
- int ret;
/* Set up data structures */
@@ -201,14 +202,14 @@ int i2ctool_get(FAR struct i2ctool_s *i2ctool, int fd, uint8_t regaddr,
}
else
{
- msg[1].buffer = (uint8_t*)&u.data16;
+ msg[1].buffer = (uint8_t *)&u.data16;
msg[1].length = 2;
}
if (i2ctool->start)
{
ret = i2cdev_transfer(fd, &msg[0], 1);
- if (ret== OK)
+ if (ret == OK)
{
ret = i2cdev_transfer(fd, &msg[1], 1);
}
@@ -235,7 +236,7 @@ int i2ctool_get(FAR struct i2ctool_s *i2ctool, int fd, uint8_t regaddr,
}
else
{
- msg[0].buffer = (uint8_t*)&u.data16;
+ msg[0].buffer = (uint8_t *)&u.data16;
msg[0].length = 2;
}
diff --git a/system/i2c/i2c_main.c b/system/i2c/i2c_main.c
index a4196b0..7a5e7c3 100644
--- a/system/i2c/i2c_main.c
+++ b/system/i2c/i2c_main.c
@@ -68,14 +68,20 @@ static struct i2ctool_s g_i2ctool;
static const struct cmdmap_s g_i2ccmds[] =
{
- { "?", i2ccmd_help, "Show help ", NULL },
- { "bus", i2ccmd_bus, "List buses ", NULL },
+ { "?", i2ccmd_help, "Show help ", NULL },
+ { "bus", i2ccmd_bus, "List buses ", NULL },
{ "dev", i2ccmd_dev, "List devices ", "[OPTIONS] <first> <last>" },
{ "get", i2ccmd_get, "Read register ", "[OPTIONS] [<repetitions>]" },
{ "dump", i2ccmd_dump, "Dump register ", "[OPTIONS] [<num bytes>]" },
{ "help", i2ccmd_help, "Show help ", NULL },
- { "set", i2ccmd_set, "Write register", "[OPTIONS] <value> [<repetitions>]" },
- { "verf", i2ccmd_verf, "Verify access ", "[OPTIONS] [<value>] [<repetitions>]" },
+ {
+ "set", i2ccmd_set, "Write register",
+ "[OPTIONS] <value> [<repetitions>]"
+ },
+ {
+ "verf", i2ccmd_verf, "Verify access ",
+ "[OPTIONS] [<value>] [<repetitions>]"
+ },
{ NULL, NULL, NULL, NULL }
};
@@ -85,7 +91,8 @@ static const struct cmdmap_s g_i2ccmds[] =
/* Common, message formats */
-const char g_i2cargrequired[] = "i2ctool: %s: missing required argument(s)\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";
@@ -120,38 +127,54 @@ static int i2ccmd_help(FAR struct i2ctool_s *i2ctool, int argc, char **argv)
}
}
- i2ctool_printf(i2ctool, "\nWhere common \"sticky\" OPTIONS include:\n");
- i2ctool_printf(i2ctool, " [-a addr] is the I2C device address (hex). "
- "Default: %02x Current: %02x\n",
+ i2ctool_printf(i2ctool,
+ "\nWhere common \"sticky\" OPTIONS include:\n");
+ i2ctool_printf(i2ctool,
+ " [-a addr] is the I2C device address (hex)."
+ " Default: %02x Current: %02x\n",
CONFIG_I2CTOOL_MINADDR, i2ctool->addr);
- i2ctool_printf(i2ctool, " [-b bus] is the I2C bus number (decimal). "
- "Default: %d Current: %d\n",
+ i2ctool_printf(i2ctool,
+ " [-b bus] is the I2C bus number (decimal)."
+ " Default: %d Current: %d\n",
CONFIG_I2CTOOL_MINBUS, i2ctool->bus);
- i2ctool_printf(i2ctool, " [-w width] is the data width (8 or 16 decimal). "
- "Default: 8 Current: %d\n",
+ i2ctool_printf(i2ctool,
+ " [-w width] is the data width (8 or 16 decimal)."
+ " Default: 8 Current: %d\n",
i2ctool->width);
- i2ctool_printf(i2ctool, " [-s|n], send/don't send start between command and data. "
- "Default: -n Current: %s\n",
+ i2ctool_printf(i2ctool,
+ " [-s|n], send/don't send start between command and data."
+ " Default: -n Current: %s\n",
i2ctool->start ? "-s" : "-n");
- i2ctool_printf(i2ctool, " [-i|j], Auto increment|don't increment regaddr on repetitions. "
- "Default: NO Current: %s\n",
+ i2ctool_printf(i2ctool,
+ " [-i|j], Auto increment|don't increment regaddr on "
+ "repetitions."
+ " Default: NO Current: %s\n",
i2ctool->autoincr ? "YES" : "NO");
- i2ctool_printf(i2ctool, " [-f freq] I2C frequency. "
- "Default: %d Current: %d\n",
+ i2ctool_printf(i2ctool,
+ " [-f freq] I2C frequency."
+ " Default: %d Current: %d\n",
CONFIG_I2CTOOL_DEFFREQ, i2ctool->freq);
i2ctool_printf(i2ctool, "\nSpecial non-sticky options:\n");
- i2ctool_printf(i2ctool, " [-r regaddr] is the I2C device register index (hex). "
- "Default: not used/sent\n");
+ i2ctool_printf(i2ctool,
+ " [-r regaddr] is the I2C device register index (hex)."
+ " Default: not used/sent\n");
i2ctool_printf(i2ctool, "\nNOTES:\n");
#ifndef CONFIG_DISABLE_ENVIRON
- i2ctool_printf(i2ctool, "o An environment variable like $PATH may be used for any argument.\n");
+ i2ctool_printf(i2ctool, "o An environment variable like $PATH may be used "
+ "for any argument.\n");
#endif
- i2ctool_printf(i2ctool, "o Arguments are \"sticky\". For example, once the I2C address is\n");
- i2ctool_printf(i2ctool, " specified, that address will be re-used until it is changed.\n");
+ i2ctool_printf(i2ctool,
+ "o Arguments are \"sticky\". For example, once "
+ "the I2C address is\n");
+ i2ctool_printf(i2ctool,
+ " specified, that address will be re-used until "
+ "it is changed.\n");
i2ctool_printf(i2ctool, "\nWARNING:\n");
- i2ctool_printf(i2ctool, "o The I2C dev command may have bad side effects on your I2C devices.\n");
+ i2ctool_printf(i2ctool,
+ "o The I2C dev command may have bad side effects "
+ "on your I2C devices.\n");
i2ctool_printf(i2ctool, " Use only at your own risk.\n");
return OK;
}
diff --git a/system/i2c/i2c_set.c b/system/i2c/i2c_set.c
index 14621c7..0214283 100644
--- a/system/i2c/i2c_set.c
+++ b/system/i2c/i2c_set.c
@@ -84,6 +84,7 @@ int i2ccmd_set(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv)
{
return ERROR;
}
+
argndx += nargs;
}
@@ -144,8 +145,8 @@ int i2ccmd_set(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;
}
/* Loop for the requested number of repetitions */
@@ -163,7 +164,8 @@ int i2ccmd_set(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv)
if (ret == OK)
{
- i2ctool_printf(i2ctool, "WROTE Bus: %d Addr: %02x Subaddr: %02x Value: ",
+ i2ctool_printf(i2ctool,
+ "WROTE Bus: %d Addr: %02x Subaddr: %02x Value: ",
i2ctool->bus, i2ctool->addr, i2ctool->regaddr);
if (i2ctool->width == 8)
{
@@ -200,13 +202,12 @@ int i2ctool_set(FAR struct i2ctool_s *i2ctool, int fd, uint8_t regaddr,
uint16_t value)
{
struct i2c_msg_s msg[2];
+ int ret;
union
{
uint16_t data16;
uint8_t data8;
} u;
- int ret;
-
if (i2ctool->hasregindx)
{
@@ -231,7 +232,7 @@ int i2ctool_set(FAR struct i2ctool_s *i2ctool, int fd, uint8_t regaddr,
else
{
u.data16 = value;
- msg[1].buffer = (uint8_t*)&u.data16;
+ msg[1].buffer = (uint8_t *)&u.data16;
msg[1].length = 2;
}
@@ -268,7 +269,7 @@ int i2ctool_set(FAR struct i2ctool_s *i2ctool, int fd, uint8_t regaddr,
else
{
u.data16 = value;
- msg[0].buffer = (uint8_t*)&u.data16;
+ msg[0].buffer = (uint8_t *)&u.data16;
msg[0].length = 2;
}
diff --git a/system/i2c/i2c_verf.c b/system/i2c/i2c_verf.c
index 1b4c603..0a306e0 100644
--- a/system/i2c/i2c_verf.c
+++ b/system/i2c/i2c_verf.c
@@ -86,12 +86,13 @@ int i2ccmd_verf(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv)
{
return ERROR;
}
+
argndx += nargs;
}
- /* The options may be followed by the optional wrvalue to be written. If omitted, then
- * the register address will be used as the wrvalue, providing an address-in-address
- * test.
+ /* The options may be followed by the optional wrvalue to be written.
+ * If omitted, then the register address will be used as the wrvalue,
+ * providing an address-in-address test.
*/
addrinaddr = true;
@@ -146,8 +147,8 @@ int i2ccmd_verf(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;
}
/* Loop for the requested number of repetitions */
@@ -157,8 +158,8 @@ int i2ccmd_verf(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv)
for (i = 0; i < repetitions; i++)
{
- /* If we are performing an address-in-address test, then use the register
- * address as the value to write.
+ /* If we are performing an address-in-address test, then use the
+ * register address as the value to write.
*/
if (addrinaddr)
@@ -180,16 +181,21 @@ int i2ccmd_verf(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv)
if (ret == OK)
{
- i2ctool_printf(i2ctool, "VERIFY Bus: %d Addr: %02x Subaddr: %02x Wrote: ",
+ i2ctool_printf(i2ctool,
+ "VERIFY Bus: %d Addr: %02x Subaddr: %02x Wrote: ",
i2ctool->bus, i2ctool->addr, i2ctool->regaddr);
if (i2ctool->width == 8)
{
- i2ctool_printf(i2ctool, "%02x Read: %02x", (int)wrvalue, (int)rdvalue);
+ i2ctool_printf(i2ctool,
+ "%02x Read: %02x",
+ (int)wrvalue, (int)rdvalue);
}
else
{
- i2ctool_printf(i2ctool, "%04x Read: %04x", (int)wrvalue, (int)rdvalue);
+ i2ctool_printf(i2ctool,
+ "%04x Read: %04x",
+ (int)wrvalue, (int)rdvalue);
}
if (wrvalue != rdvalue)