i2c: move over to using std::expected for reads
Moves over to using std::expected for reads. This was mostly
an experiment, but I ended up testing and liking it more
than our out-value implementation. Put it up and make the world
a slightly better place.
Tested: put onto nvl32-obmc, i2c ready still works
Change-Id: I637cee5175fc684b6d02096a525b61ab6f4ab918
Signed-off-by: Marc Olberding <molberding@nvidia.com>
diff --git a/i2c.cpp b/i2c.cpp
index 0ad97fc..d33b00b 100644
--- a/i2c.cpp
+++ b/i2c.cpp
@@ -109,16 +109,16 @@
close(fd);
}
-int RawDevice::read_byte(uint8_t reg, uint8_t& val)
+std::expected<uint8_t, std::error_code> RawDevice::read_byte(uint8_t reg)
{
int result = i2c_smbus_read_byte_data(fd, reg);
if (result < 0)
{
- return -result;
+ return std::unexpected(
+ std::error_code(-result, std::system_category()));
}
- val = result;
- return 0;
+ return result;
}
} // namespace i2c