aboutsummaryrefslogtreecommitdiffstats
path: root/mpm/lib/i2c
diff options
context:
space:
mode:
Diffstat (limited to 'mpm/lib/i2c')
-rw-r--r--mpm/lib/i2c/i2cdev_iface.cpp24
1 files changed, 15 insertions, 9 deletions
diff --git a/mpm/lib/i2c/i2cdev_iface.cpp b/mpm/lib/i2c/i2cdev_iface.cpp
index 9d2c6b4b2..b723dea06 100644
--- a/mpm/lib/i2c/i2cdev_iface.cpp
+++ b/mpm/lib/i2c/i2cdev_iface.cpp
@@ -64,23 +64,29 @@ public:
return ret;
}
- int transfer(std::vector<uint8_t>* tx, std::vector<uint8_t>* rx, bool do_close)
+ std::vector<uint8_t> transfer(
+ std::vector<uint8_t>& tx, size_t num_rx_bytes, bool do_close)
{
uint8_t *tx_data = NULL, *rx_data = NULL;
size_t tx_len = 0, rx_len = 0;
+ std::vector<uint8_t> rx(num_rx_bytes);
- if (tx) {
- tx_data = tx->data();
- tx_len = tx->size();
+ if (!tx.empty()) {
+ tx_data = tx.data();
+ tx_len = tx.size();
}
- if (rx) {
- rx_data = rx->data();
- rx_len = rx->size();
+ if (num_rx_bytes) {
+ rx_data = rx.data();
+ rx_len = rx.size();
}
- int ret = transfer(tx_data, tx_len, rx_data, rx_len, do_close);
- return ret;
+ const int err = transfer(tx_data, tx_len, rx_data, num_rx_bytes, do_close);
+ if (err) {
+ throw mpm::runtime_error("I2C Transaction failed!");
+ }
+
+ return rx;
}
private: