diff options
author | Alex Williams <alex.williams@ni.com> | 2018-10-16 08:23:35 -0700 |
---|---|---|
committer | Brent Stapleton <bstapleton@g.hmc.edu> | 2018-10-19 10:17:08 -0700 |
commit | 5e548c1a08cc559e30507b6dbe5c408a9bf96f51 (patch) | |
tree | ed275e931d82712839aa589d1dada567fbc2dddf /mpm | |
parent | a830fab2a00acd158f14d716e3493ef50afd8aeb (diff) | |
download | uhd-5e548c1a08cc559e30507b6dbe5c408a9bf96f51.tar.gz uhd-5e548c1a08cc559e30507b6dbe5c408a9bf96f51.tar.bz2 uhd-5e548c1a08cc559e30507b6dbe5c408a9bf96f51.zip |
mpm: i2c: Add vector-based transfer function
This could lead to a less-restricted implementation for use in Python.
Diffstat (limited to 'mpm')
-rw-r--r-- | mpm/include/mpm/i2c/i2c_iface.hpp | 12 | ||||
-rw-r--r-- | mpm/include/mpm/i2c/i2c_python.hpp | 11 | ||||
-rw-r--r-- | mpm/lib/i2c/i2cdev_iface.cpp | 18 |
3 files changed, 41 insertions, 0 deletions
diff --git a/mpm/include/mpm/i2c/i2c_iface.hpp b/mpm/include/mpm/i2c/i2c_iface.hpp index f19711242..aca5994b1 100644 --- a/mpm/include/mpm/i2c/i2c_iface.hpp +++ b/mpm/include/mpm/i2c/i2c_iface.hpp @@ -9,6 +9,7 @@ #include <boost/noncopyable.hpp> #include <memory> #include <string> +#include <vector> namespace mpm { namespace i2c { @@ -39,6 +40,17 @@ namespace mpm { namespace i2c { * \param rx_len Number of bytes to read */ virtual int transfer(uint8_t *tx, size_t tx_len, uint8_t *rx, size_t rx_len) = 0; + + /*! + * \param tx Buffer of data to send + * \param rx Buffer to hold read data + * + * All data in tx will be transmitted. + * The amount of data read will be determined by the number of elements + * in the rx vector. Those elements will be overwritten with the data. + * Use the resize() function for a new rx vector. + */ + virtual int transfer(std::vector<uint8_t> *tx, std::vector<uint8_t> *rx) = 0; }; }}; /* namespace mpm::i2c */ diff --git a/mpm/include/mpm/i2c/i2c_python.hpp b/mpm/include/mpm/i2c/i2c_python.hpp index c4211e238..d50b1d4d6 100644 --- a/mpm/include/mpm/i2c/i2c_python.hpp +++ b/mpm/include/mpm/i2c/i2c_python.hpp @@ -13,6 +13,17 @@ void export_i2c() { LIBMPM_BOOST_PREAMBLE("i2c") bp::def("make_i2cdev_regs_iface", &mpm::i2c::make_i2cdev_regs_iface); +/* + bp::def("make_i2cdev", &mpm::i2c::i2c_iface::make_i2cdev); + int (mpm::i2c::i2c_iface::*transfer_vec)(std::vector<uint8_t>*, + std::vector<uint8_t>*) = + &mpm::i2c::i2c_iface::transfer; + + bp::class_<mpm::i2c::i2c_iface, boost::noncopyable, + std::shared_ptr<mpm::i2c::i2c_iface> >("i2c_iface", bp::no_init) + .def("transfer", transfer_vec) + ; +*/ } 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<uint8_t> *tx, std::vector<uint8_t> *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; |