diff options
-rw-r--r-- | src/include/device/i2c.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/include/device/i2c.h b/src/include/device/i2c.h index 78817bb300..8e59ba7c21 100644 --- a/src/include/device/i2c.h +++ b/src/include/device/i2c.h @@ -88,6 +88,28 @@ static inline int i2c_write_raw(unsigned bus, uint8_t chip, uint8_t *data, } /** + * Read multi-bytes with two segments in one frame + * + * [start][slave addr][w][register addr][start][slave addr][r][data...][stop] + */ +static inline int i2c_read_bytes(unsigned bus, uint8_t chip, uint8_t reg, + uint8_t *data, int len) +{ + struct i2c_seg seg[2]; + + seg[0].read = 0; + seg[0].chip = chip; + seg[0].buf = ® + seg[0].len = 1; + seg[1].read = 1; + seg[1].chip = chip; + seg[1].buf = data; + seg[1].len = len; + + return i2c_transfer(bus, seg, ARRAY_SIZE(seg)); +} + +/** * Read a byte with two segments in one frame * * [start][slave addr][w][register addr][start][slave addr][r][data][stop] |