diff options
author | Poul-Henning Kamp <phk@FreeBSD.org> | 2021-05-11 23:07:06 +0000 |
---|---|---|
committer | Poul-Henning Kamp <phk@FreeBSD.org> | 2021-05-11 23:07:06 +0000 |
commit | b2ae176d914acd63247e24d7e23dbe8f239fbfb0 (patch) | |
tree | 6fcb0ba1cebff24bb1265786f2e0ae4468a7f180 /usr.sbin/i2c | |
parent | 9db7da1f55b3f793c9b0e7d8fca5fbbc26c90691 (diff) | |
download | src-b2ae176d914acd63247e24d7e23dbe8f239fbfb0.tar.gz src-b2ae176d914acd63247e24d7e23dbe8f239fbfb0.zip |
Sixteen bit I2c addresses are always little endian.
Diffstat (limited to 'usr.sbin/i2c')
-rw-r--r-- | usr.sbin/i2c/i2c.c | 13 |
1 files 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; |