i2c: Implement read function
Implement I2CDevice::read() by invoking i2c_smbus_read_xxx() APIs.
The code is referenced from i2c-tools' i2cget.c:
https://github.com/ev3dev/i2c-tools/blob/ev3dev-stretch/tools/i2cget.c
Tested: Verify on Witherspoon that it reads the PSU ppgrade mode status
register (1 byte) and CRC16 register (2 bytes) correctly.
Signed-off-by: Lei YU <mine260309@gmail.com>
Change-Id: I8759b6a35229f81120acf77f08429f7f79458b8b
diff --git a/tools/power-utils/updater.cpp b/tools/power-utils/updater.cpp
index 749b5dd..2668030 100644
--- a/tools/power-utils/updater.cpp
+++ b/tools/power-utils/updater.cpp
@@ -244,7 +244,21 @@
{
// TODO
uint8_t data;
- i2c->read(0x00, data);
+ uint8_t size;
+ uint16_t word;
+ std::vector<uint8_t> blockData(32);
+
+ i2c->read(data);
+ printf("Read byte 0x%02x\n", data);
+
+ i2c->read(0xf1, data);
+ printf("First read of 0x%02x, 0x%02x\n", 0xf1, data);
+
+ i2c->read(0xbd, word);
+ printf("Read word of 0x%02x, 0x%04x\n", 0xbd, word);
+
+ i2c->read(0x00, size, blockData.data()); // This throws on the device
+ printf("Read block data, size: %d\n", size);
return 0;
}