diff --git a/ChangeLog.txt b/ChangeLog.txt index 7e6b8bd0b..8e747a38f 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1540,4 +1540,7 @@ modem in nsh. From Vladimir Komendantskiy (2019-01-31). * apps/system/ubloxmodem: Moved the modem application from 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). diff --git a/system/i2c/i2c_dev.c b/system/i2c/i2c_dev.c index 284fc8ba8..7151a2f5c 100644 --- a/system/i2c/i2c_dev.c +++ b/system/i2c/i2c_dev.c @@ -126,7 +126,7 @@ int i2ccmd_dev(FAR struct i2ctool_s *i2ctool, int argc, char **argv) /* Get a handle to the I2C bus */ - fd = i2cdev_open(i2ctool, i2ctool->bus); + fd = i2cdev_open(i2ctool->bus); if (fd < 0) { 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) { - ret = i2cdev_transfer(i2ctool, fd, &msg[0], 1); + ret = i2cdev_transfer(fd, &msg[0], 1); if (ret == OK) { - ret = i2cdev_transfer(i2ctool, fd, &msg[1], 1); + ret = i2cdev_transfer(fd, &msg[1], 1); } } else { - ret = i2cdev_transfer(i2ctool, fd, msg, 2); + ret = i2cdev_transfer(fd, msg, 2); } if (ret == OK) diff --git a/system/i2c/i2c_devif.c b/system/i2c/i2c_devif.c index fb5384be2..db1ad5b3d 100644 --- a/system/i2c/i2c_devif.c +++ b/system/i2c/i2c_devif.c @@ -112,7 +112,7 @@ bool i2cdev_exists(int bus) * Name: i2cdev_open ****************************************************************************/ -int i2cdev_open(FAR struct i2ctool_s *i2ctool, int bus) +int i2cdev_open(int bus) { FAR char *devpath; 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) */ - fd = 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; + return open(devpath, O_RDONLY); } /**************************************************************************** * Name: i2cdev_transfer ****************************************************************************/ -int i2cdev_transfer(FAR struct i2ctool_s *i2ctool, int fd, - FAR struct i2c_msg_s *msgv, int msgc) +int i2cdev_transfer(int fd, FAR struct i2c_msg_s *msgv, int msgc) { struct i2c_transfer_s xfer; int ret; @@ -155,17 +142,5 @@ int i2cdev_transfer(FAR struct i2ctool_s *i2ctool, int fd, /* Perform the IOCTL */ - ret = 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; -} \ No newline at end of file + return ioctl(fd, I2CIOC_TRANSFER, (unsigned long)((uintptr_t)&xfer)); +} diff --git a/system/i2c/i2c_get.c b/system/i2c/i2c_get.c index 70777abde..acdea6b2a 100644 --- a/system/i2c/i2c_get.c +++ b/system/i2c/i2c_get.c @@ -113,7 +113,7 @@ int i2ccmd_get(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv) /* Get a handle to the I2C bus */ - fd = i2cdev_open(i2ctool, i2ctool->bus); + fd = i2cdev_open(i2ctool->bus); if (fd < 0) { 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) { - ret = i2cdev_transfer(i2ctool, fd, &msg[0], 1); + ret = i2cdev_transfer(fd, &msg[0], 1); if (ret== OK) { - ret = i2cdev_transfer(i2ctool, fd, &msg[1], 1); + ret = i2cdev_transfer(fd, &msg[1], 1); } } else { - ret = i2cdev_transfer(i2ctool, fd, msg, 2); + ret = i2cdev_transfer(fd, msg, 2); } /* Return the result of the read operation */ diff --git a/system/i2c/i2c_set.c b/system/i2c/i2c_set.c index b5cad99b1..ce3638280 100644 --- a/system/i2c/i2c_set.c +++ b/system/i2c/i2c_set.c @@ -141,7 +141,7 @@ int i2ccmd_set(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv) /* Get a handle to the I2C bus */ - fd = i2cdev_open(i2ctool, i2ctool->bus); + fd = i2cdev_open(i2ctool->bus); if (fd < 0) { 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) { - ret = i2cdev_transfer(i2ctool, fd, &msg[0], 1); + ret = i2cdev_transfer(fd, &msg[0], 1); if (ret == OK) { - ret = i2cdev_transfer(i2ctool, fd, &msg[1], 1); + ret = i2cdev_transfer(fd, &msg[1], 1); } } else { - ret = i2cdev_transfer(i2ctool, fd, msg, 2); + ret = i2cdev_transfer(fd, msg, 2); } return ret; diff --git a/system/i2c/i2c_verf.c b/system/i2c/i2c_verf.c index d5bd8339a..ed67d1409 100644 --- a/system/i2c/i2c_verf.c +++ b/system/i2c/i2c_verf.c @@ -143,7 +143,7 @@ int i2ccmd_verf(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv) /* Get a handle to the I2C bus */ - fd = i2cdev_open(i2ctool, i2ctool->bus); + fd = i2cdev_open(i2ctool->bus); if (fd < 0) { i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus); diff --git a/system/i2c/i2ctool.h b/system/i2c/i2ctool.h index da3997178..ea43f7035 100644 --- a/system/i2c/i2ctool.h +++ b/system/i2c/i2ctool.h @@ -208,8 +208,7 @@ int arg_hex(FAR char **arg, FAR long *value); FAR char *i2cdev_path(int bus); bool i2cdev_exists(int bus); -int i2cdev_open(FAR struct i2ctool_s *i2ctool, int bus); -int i2cdev_transfer(FAR struct i2ctool_s *i2ctool, int fd, - FAR struct i2c_msg_s *msgv, int msgc); +int i2cdev_open(int bus); +int i2cdev_transfer(int fd, FAR struct i2c_msg_s *msgv, int msgc); #endif /* __APPS_SYSTEM_I2C_I2CTOOLS_H */