From 5e548c1a08cc559e30507b6dbe5c408a9bf96f51 Mon Sep 17 00:00:00 2001 From: Alex Williams Date: Tue, 16 Oct 2018 08:23:35 -0700 Subject: mpm: i2c: Add vector-based transfer function This could lead to a less-restricted implementation for use in Python. --- mpm/lib/i2c/i2cdev_iface.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'mpm/lib') diff --git a/mpm/lib/i2c/i2cdev_iface.cpp b/mpm/lib/i2c/i2cdev_iface.cpp index 43aeea5e2..d47d0f788 100644 --- a/mpm/lib/i2c/i2cdev_iface.cpp +++ b/mpm/lib/i2c/i2cdev_iface.cpp @@ -72,6 +72,24 @@ public: return ret; } + int transfer(std::vector *tx, std::vector *rx) + { + uint8_t *tx_data = NULL, *rx_data = NULL; + size_t tx_len = 0, rx_len = 0; + + if (tx) { + tx_data = tx->data(); + tx_len = tx->size(); + } + + if (rx) { + rx_data = rx->data(); + rx_len = rx->size(); + } + int ret = transfer(tx_data, tx_len, rx_data, rx_len); + return ret; + } + private: int _fd; const uint16_t _addr; -- cgit v1.2.3