summaryrefslogtreecommitdiffstats
path: root/host/lib/usrp/fx2
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-06-29 21:16:28 -0700
committerJosh Blum <josh@joshknows.com>2011-06-29 21:16:28 -0700
commitba088e27b054ddec8e5ec05f53da113f92c2be07 (patch)
tree6137e759e0d6bebc08d3eaa2ea9334738615986c /host/lib/usrp/fx2
parent11539ef6f690b4ebd69485be9a61f5422d8cdc99 (diff)
downloaduhd-ba088e27b054ddec8e5ec05f53da113f92c2be07.tar.gz
uhd-ba088e27b054ddec8e5ec05f53da113f92c2be07.tar.bz2
uhd-ba088e27b054ddec8e5ec05f53da113f92c2be07.zip
b100: got b100 into the properties tree like usrp2
Diffstat (limited to 'host/lib/usrp/fx2')
-rw-r--r--host/lib/usrp/fx2/fx2_ctrl.cpp36
-rw-r--r--host/lib/usrp/fx2/fx2_ctrl.hpp5
2 files changed, 39 insertions, 2 deletions
diff --git a/host/lib/usrp/fx2/fx2_ctrl.cpp b/host/lib/usrp/fx2/fx2_ctrl.cpp
index 06ca51c25..5b2f100c6 100644
--- a/host/lib/usrp/fx2/fx2_ctrl.cpp
+++ b/host/lib/usrp/fx2/fx2_ctrl.cpp
@@ -409,6 +409,42 @@ public:
return usrp_control_read(VRQ_I2C_READ, i2c_addr, 0, buf, len);
}
+ static const bool iface_debug = false;
+ static const size_t max_i2c_data_bytes = 64;
+
+ void write_i2c(boost::uint8_t addr, const byte_vector_t &bytes)
+ {
+ UHD_ASSERT_THROW(bytes.size() < max_i2c_data_bytes);
+
+ unsigned char buff[max_i2c_data_bytes];
+ std::copy(bytes.begin(), bytes.end(), buff);
+
+ int ret = this->usrp_i2c_write(addr & 0xff,
+ buff,
+ bytes.size());
+
+ if (iface_debug && (ret < 0))
+ uhd::runtime_error("USRP: failed i2c write");
+ }
+
+ byte_vector_t read_i2c(boost::uint8_t addr, size_t num_bytes)
+ {
+ UHD_ASSERT_THROW(num_bytes < max_i2c_data_bytes);
+
+ unsigned char buff[max_i2c_data_bytes];
+ int ret = this->usrp_i2c_read(addr & 0xff,
+ buff,
+ num_bytes);
+
+ if (iface_debug && ((ret < 0) || (unsigned)ret < (num_bytes)))
+ uhd::runtime_error("USRP: failed i2c read");
+
+ byte_vector_t out_bytes;
+ for (size_t i = 0; i < num_bytes; i++)
+ out_bytes.push_back(buff[i]);
+
+ return out_bytes;
+ }
private:
diff --git a/host/lib/usrp/fx2/fx2_ctrl.hpp b/host/lib/usrp/fx2/fx2_ctrl.hpp
index 37fa09605..eeff6287d 100644
--- a/host/lib/usrp/fx2/fx2_ctrl.hpp
+++ b/host/lib/usrp/fx2/fx2_ctrl.hpp
@@ -18,13 +18,14 @@
#ifndef INCLUDED_USRP_CTRL_HPP
#define INCLUDED_USRP_CTRL_HPP
-#include <uhd/transport/usb_control.hpp>
+#include <uhd/transport/usb_control.hpp>
+#include <uhd/types/serial.hpp> //i2c iface
#include <boost/shared_ptr.hpp>
#include <boost/utility.hpp>
namespace uhd{ namespace usrp{
-class fx2_ctrl : boost::noncopyable{
+class fx2_ctrl : boost::noncopyable, public uhd::i2c_iface{
public:
typedef boost::shared_ptr<fx2_ctrl> sptr;