diff options
author | Alex Williams <alex.williams@ni.com> | 2018-10-12 17:17:13 -0700 |
---|---|---|
committer | Brent Stapleton <bstapleton@g.hmc.edu> | 2018-10-19 10:17:08 -0700 |
commit | a830fab2a00acd158f14d716e3493ef50afd8aeb (patch) | |
tree | 96425e10026d94dfcef46ebbfa8cc5bccb5cf90f /mpm/include | |
parent | 0e30a5ca0872762a36be15f030a763c7f67dd003 (diff) | |
download | uhd-a830fab2a00acd158f14d716e3493ef50afd8aeb.tar.gz uhd-a830fab2a00acd158f14d716e3493ef50afd8aeb.tar.bz2 uhd-a830fab2a00acd158f14d716e3493ef50afd8aeb.zip |
mpm: Add i2c APIs for simple transfers
Diffstat (limited to 'mpm/include')
-rw-r--r-- | mpm/include/mpm/i2c/CMakeLists.txt | 11 | ||||
-rw-r--r-- | mpm/include/mpm/i2c/i2c_iface.hpp | 45 | ||||
-rw-r--r-- | mpm/include/mpm/i2c/i2c_python.hpp | 18 | ||||
-rw-r--r-- | mpm/include/mpm/i2c/i2c_regs_iface.hpp | 34 |
4 files changed, 108 insertions, 0 deletions
diff --git a/mpm/include/mpm/i2c/CMakeLists.txt b/mpm/include/mpm/i2c/CMakeLists.txt new file mode 100644 index 000000000..13851bca0 --- /dev/null +++ b/mpm/include/mpm/i2c/CMakeLists.txt @@ -0,0 +1,11 @@ +# +# Copyright 2018 Ettus Research, National Instruments Company +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +INSTALL(FILES + i2c_iface.hpp + i2c_regs_iface.hpp + DESTINATION ${INCLUDE_DIR}/mpm/i2c +) diff --git a/mpm/include/mpm/i2c/i2c_iface.hpp b/mpm/include/mpm/i2c/i2c_iface.hpp new file mode 100644 index 000000000..f19711242 --- /dev/null +++ b/mpm/include/mpm/i2c/i2c_iface.hpp @@ -0,0 +1,45 @@ +// +// Copyright 2018 Ettus Research, a National Instruments Company +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#pragma once + +#include <boost/noncopyable.hpp> +#include <memory> +#include <string> + +namespace mpm { namespace i2c { + + /*! Implementation of a uhd::i2c_iface that uses Linux's i2c-dev underneath. + */ + class i2c_iface : public boost::noncopyable + { + public: + using sptr = std::shared_ptr<i2c_iface>; + + /*! + * \param bus The path to the i2c bus segment used (e.g. "/dev/i2c3") + * \param addr Address of the slave device on the bus segment + * \param ten_bit_addr Whether the slave device's address is 10 bits + * \param timeout_ms Time to wait for ACK from slave device + */ + static sptr make_i2cdev( + const std::string &bus, + const uint16_t addr, + const bool ten_bit_addr, + const int timeout_ms + ); + + /*! + * \param tx Buffer of data to send + * \param tx_len Size (in bytes) of TX buffer + * \param rx Buffer to hold read data + * \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; + }; + +}}; /* namespace mpm::i2c */ + diff --git a/mpm/include/mpm/i2c/i2c_python.hpp b/mpm/include/mpm/i2c/i2c_python.hpp new file mode 100644 index 000000000..c4211e238 --- /dev/null +++ b/mpm/include/mpm/i2c/i2c_python.hpp @@ -0,0 +1,18 @@ +// +// Copyright 2018 Ettus Research, a National Instruments Company +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#pragma once + +#include "i2c_regs_iface.hpp" +#include "i2c_iface.hpp" + +void export_i2c() { + LIBMPM_BOOST_PREAMBLE("i2c") + + bp::def("make_i2cdev_regs_iface", &mpm::i2c::make_i2cdev_regs_iface); + +} + diff --git a/mpm/include/mpm/i2c/i2c_regs_iface.hpp b/mpm/include/mpm/i2c/i2c_regs_iface.hpp new file mode 100644 index 000000000..b63f00994 --- /dev/null +++ b/mpm/include/mpm/i2c/i2c_regs_iface.hpp @@ -0,0 +1,34 @@ +// +// Copyright 2018 Ettus Research, a National Instruments Company +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#pragma once + +#include <mpm/types/regs_iface.hpp> +#include <mpm/i2c/i2c_iface.hpp> + +namespace mpm { namespace i2c { + + /*! The regs_iface class can only be used for certain i2c devices + * For more control over the length of write and read data, use the lower-level + * i2c_iface + */ + mpm::types::regs_iface::sptr make_i2c_regs_iface( + mpm::i2c::i2c_iface::sptr i2c_iface, + const size_t reg_addr_size + ); + + /*! Convenience factory for regs_iface based on i2c based on i2cdev + */ + mpm::types::regs_iface::sptr make_i2cdev_regs_iface( + const std::string &bus, + const uint16_t addr, + const bool ten_bit_addr, + const int timeout_ms, + const size_t reg_addr_size + ); + +}}; /* namespace mpm::i2c */ + |