diff options
author | Timofey Titovets <nefelim4ag@gmail.com> | 2024-10-21 16:53:51 +0200 |
---|---|---|
committer | KevinOConnor <kevin@koconnor.net> | 2024-10-26 22:06:30 -0400 |
commit | 8a1c3cd66870cf232cee50863796ec12088e042c (patch) | |
tree | 699810642fe269e0993ace3607d1555fc7410edf | |
parent | 2c246c7d339693dfb12c133b6a5b2611205db0e7 (diff) | |
download | kutter-8a1c3cd66870cf232cee50863796ec12088e042c.tar.gz kutter-8a1c3cd66870cf232cee50863796ec12088e042c.tar.xz kutter-8a1c3cd66870cf232cee50863796ec12088e042c.zip |
linux: forward i2c errors to i2ccmd
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
-rw-r--r-- | src/linux/i2c.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/linux/i2c.c b/src/linux/i2c.c index 2b8a7988..a728752a 100644 --- a/src/linux/i2c.c +++ b/src/linux/i2c.c @@ -88,11 +88,19 @@ i2c_setup(uint32_t bus, uint32_t rate, uint8_t addr) int i2c_write(struct i2c_config config, uint8_t write_len, uint8_t *data) { - int ret = write(config.fd, data, write_len); - if (ret != write_len) { - if (ret < 0) - report_errno("write value i2c", ret); - try_shutdown("Unable write i2c device"); + struct i2c_rdwr_ioctl_data i2c_data; + struct i2c_msg msgs[1]; + msgs[0].addr = config.addr; + msgs[0].flags = 0x0; + msgs[0].len = write_len; + msgs[0].buf = data; + i2c_data.nmsgs = 1; + i2c_data.msgs = &msgs[0]; + + int ret = ioctl(config.fd, I2C_RDWR, &i2c_data); + + if (ret < 0) { + return I2C_BUS_NACK; } return I2C_BUS_SUCCESS; @@ -124,8 +132,8 @@ i2c_read(struct i2c_config config, uint8_t reg_len, uint8_t *reg int ret = ioctl(config.fd, I2C_RDWR, &i2c_data); - if(ret < 0) { - try_shutdown("Unable to read i2c device"); + if (ret < 0) { + return I2C_BUS_NACK; } return I2C_BUS_SUCCESS; |