Low level drive access functions should not generate output; it interferes with higher level formatting

This commit is contained in:
Gregory Nutt 2016-02-02 14:42:16 -06:00
parent 7c4f9eb8e9
commit bb9b4c8063
7 changed files with 23 additions and 46 deletions

View File

@ -1540,4 +1540,7 @@
modem in nsh. From Vladimir Komendantskiy (2019-01-31). modem in nsh. From Vladimir Komendantskiy (2019-01-31).
* apps/system/ubloxmodem: Moved the modem application from * apps/system/ubloxmodem: Moved the modem application from
examples/ to system/ (2016-01-31). examples/ to system/ (2016-01-31).
* apps/system/i2c: The I2C tool now obeys it OS interfacing:
it now uses an I2C character driver to access the I2C bus
(2016-02-02).

View File

@ -126,7 +126,7 @@ int i2ccmd_dev(FAR struct i2ctool_s *i2ctool, int argc, char **argv)
/* Get a handle to the I2C bus */ /* Get a handle to the I2C bus */
fd = i2cdev_open(i2ctool, i2ctool->bus); fd = i2cdev_open(i2ctool->bus);
if (fd < 0) if (fd < 0)
{ {
i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus); i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus);
@ -176,15 +176,15 @@ int i2ccmd_dev(FAR struct i2ctool_s *i2ctool, int argc, char **argv)
if (i2ctool->start) if (i2ctool->start)
{ {
ret = i2cdev_transfer(i2ctool, fd, &msg[0], 1); ret = i2cdev_transfer(fd, &msg[0], 1);
if (ret == OK) if (ret == OK)
{ {
ret = i2cdev_transfer(i2ctool, fd, &msg[1], 1); ret = i2cdev_transfer(fd, &msg[1], 1);
} }
} }
else else
{ {
ret = i2cdev_transfer(i2ctool, fd, msg, 2); ret = i2cdev_transfer(fd, msg, 2);
} }
if (ret == OK) if (ret == OK)

View File

@ -112,7 +112,7 @@ bool i2cdev_exists(int bus)
* Name: i2cdev_open * Name: i2cdev_open
****************************************************************************/ ****************************************************************************/
int i2cdev_open(FAR struct i2ctool_s *i2ctool, int bus) int i2cdev_open(int bus)
{ {
FAR char *devpath; FAR char *devpath;
int fd; int fd;
@ -123,27 +123,14 @@ int i2cdev_open(FAR struct i2ctool_s *i2ctool, int bus)
/* Open the file for read-only access (we need only IOCTLs) */ /* Open the file for read-only access (we need only IOCTLs) */
fd = open(devpath, O_RDONLY); return open(devpath, O_RDONLY);
if (fd < 0)
{
int errcode = errno;
/* We failed to open the driver */
i2ctool_printf(i2ctool, "ERROR: Failed to open %s: %d\n",
devpath, errcode);
return ERROR;
}
return fd;
} }
/**************************************************************************** /****************************************************************************
* Name: i2cdev_transfer * Name: i2cdev_transfer
****************************************************************************/ ****************************************************************************/
int i2cdev_transfer(FAR struct i2ctool_s *i2ctool, int fd, int i2cdev_transfer(int fd, FAR struct i2c_msg_s *msgv, int msgc)
FAR struct i2c_msg_s *msgv, int msgc)
{ {
struct i2c_transfer_s xfer; struct i2c_transfer_s xfer;
int ret; int ret;
@ -155,17 +142,5 @@ int i2cdev_transfer(FAR struct i2ctool_s *i2ctool, int fd,
/* Perform the IOCTL */ /* Perform the IOCTL */
ret = ioctl(fd, I2CIOC_TRANSFER, (unsigned long)((uintptr_t)&xfer)); return ioctl(fd, I2CIOC_TRANSFER, (unsigned long)((uintptr_t)&xfer));
if (ret < 0)
{
int errcode = errno;
/* We failed to open the driver */
i2ctool_printf(i2ctool, "ERROR: ioctl(I2CIOC_TRANSFER) failed: %d\n",
errcode);
return ERROR;
}
return OK;
} }

View File

@ -113,7 +113,7 @@ int i2ccmd_get(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv)
/* Get a handle to the I2C bus */ /* Get a handle to the I2C bus */
fd = i2cdev_open(i2ctool, i2ctool->bus); fd = i2cdev_open(i2ctool->bus);
if (fd < 0) if (fd < 0)
{ {
i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus); i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus);
@ -205,15 +205,15 @@ int i2ctool_get(FAR struct i2ctool_s *i2ctool, int fd, uint8_t regaddr,
if (i2ctool->start) if (i2ctool->start)
{ {
ret = i2cdev_transfer(i2ctool, fd, &msg[0], 1); ret = i2cdev_transfer(fd, &msg[0], 1);
if (ret== OK) if (ret== OK)
{ {
ret = i2cdev_transfer(i2ctool, fd, &msg[1], 1); ret = i2cdev_transfer(fd, &msg[1], 1);
} }
} }
else else
{ {
ret = i2cdev_transfer(i2ctool, fd, msg, 2); ret = i2cdev_transfer(fd, msg, 2);
} }
/* Return the result of the read operation */ /* Return the result of the read operation */

View File

@ -141,7 +141,7 @@ int i2ccmd_set(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv)
/* Get a handle to the I2C bus */ /* Get a handle to the I2C bus */
fd = i2cdev_open(i2ctool, i2ctool->bus); fd = i2cdev_open(i2ctool->bus);
if (fd < 0) if (fd < 0)
{ {
i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus); i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus);
@ -233,15 +233,15 @@ int i2ctool_set(FAR struct i2ctool_s *i2ctool, int fd, uint8_t regaddr,
if (i2ctool->start) if (i2ctool->start)
{ {
ret = i2cdev_transfer(i2ctool, fd, &msg[0], 1); ret = i2cdev_transfer(fd, &msg[0], 1);
if (ret == OK) if (ret == OK)
{ {
ret = i2cdev_transfer(i2ctool, fd, &msg[1], 1); ret = i2cdev_transfer(fd, &msg[1], 1);
} }
} }
else else
{ {
ret = i2cdev_transfer(i2ctool, fd, msg, 2); ret = i2cdev_transfer(fd, msg, 2);
} }
return ret; return ret;

View File

@ -143,7 +143,7 @@ int i2ccmd_verf(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv)
/* Get a handle to the I2C bus */ /* Get a handle to the I2C bus */
fd = i2cdev_open(i2ctool, i2ctool->bus); fd = i2cdev_open(i2ctool->bus);
if (fd < 0) if (fd < 0)
{ {
i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus); i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus);

View File

@ -208,8 +208,7 @@ int arg_hex(FAR char **arg, FAR long *value);
FAR char *i2cdev_path(int bus); FAR char *i2cdev_path(int bus);
bool i2cdev_exists(int bus); bool i2cdev_exists(int bus);
int i2cdev_open(FAR struct i2ctool_s *i2ctool, int bus); int i2cdev_open(int bus);
int i2cdev_transfer(FAR struct i2ctool_s *i2ctool, int fd, int i2cdev_transfer(int fd, FAR struct i2c_msg_s *msgv, int msgc);
FAR struct i2c_msg_s *msgv, int msgc);
#endif /* __APPS_SYSTEM_I2C_I2CTOOLS_H */ #endif /* __APPS_SYSTEM_I2C_I2CTOOLS_H */