Date: Tue, 11 May 2021 23:07:59 GMT From: Poul-Henning Kamp <phk@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: b2ae176d914a - main - Sixteen bit I2c addresses are always little endian. Message-ID: <202105112307.14BN7xUk094908@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by phk: URL: https://cgit.FreeBSD.org/src/commit/?id=b2ae176d914acd63247e24d7e23dbe8f239fbfb0 commit b2ae176d914acd63247e24d7e23dbe8f239fbfb0 Author: Poul-Henning Kamp <phk@FreeBSD.org> AuthorDate: 2021-05-11 23:07:06 +0000 Commit: Poul-Henning Kamp <phk@FreeBSD.org> CommitDate: 2021-05-11 23:07:06 +0000 Sixteen bit I2c addresses are always little endian. --- usr.sbin/i2c/i2c.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/usr.sbin/i2c/i2c.c b/usr.sbin/i2c/i2c.c index 1df12cf44460..23613ee744f9 100644 --- a/usr.sbin/i2c/i2c.c +++ b/usr.sbin/i2c/i2c.c @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$"); #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <sys/endian.h> #include <sys/ioctl.h> #include <dev/iicbus/iic.h> @@ -570,22 +571,18 @@ i2c_rdwr_transfer(const char *dev, struct options i2c_opt, char *i2c_buf) struct iic_msg msgs[2]; struct iic_rdwr_data xfer; int fd, i; - union { - uint8_t buf[2]; - uint8_t off8; - uint16_t off16; - } off; + uint8_t off_buf[2]; i = 0; if (i2c_opt.width > 0) { msgs[i].flags = IIC_M_WR | IIC_M_NOSTOP; msgs[i].slave = i2c_opt.addr; - msgs[i].buf = off.buf; + msgs[i].buf = off_buf; if (i2c_opt.width == 8) { - off.off8 = (uint8_t)i2c_opt.off; + off_buf[0] = i2c_opt.off; msgs[i].len = 1; } else { - off.off16 = (uint16_t)i2c_opt.off; + le16enc(off_buf, i2c_opt.off); msgs[i].len = 2; } ++i;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202105112307.14BN7xUk094908>