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/include/mpm/i2c/i2c_iface.hpp | 12 ++++++++++++ mpm/include/mpm/i2c/i2c_python.hpp | 11 +++++++++++ 2 files changed, 23 insertions(+) (limited to 'mpm/include') 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 #include #include +#include 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 *tx, std::vector *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*, + std::vector*) = + &mpm::i2c::i2c_iface::transfer; + + bp::class_ >("i2c_iface", bp::no_init) + .def("transfer", transfer_vec) + ; +*/ } -- cgit v1.2.3