diff options
author | Josh Blum <josh@joshknows.com> | 2010-04-26 00:17:08 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-04-26 00:17:08 -0700 |
commit | 0c609b96574095affe12d9aaa53bead98faba4f3 (patch) | |
tree | 9e10b9d6ddabca60b33898514df5948f8ed02b18 /host/lib/types.cpp | |
parent | 61ec6711bb4bbae7a8a26cc631eeb88fb3e7d688 (diff) | |
download | uhd-0c609b96574095affe12d9aaa53bead98faba4f3.tar.gz uhd-0c609b96574095affe12d9aaa53bead98faba4f3.tar.bz2 uhd-0c609b96574095affe12d9aaa53bead98faba4f3.zip |
Added i2c interface to serial.hpp, using in usrp2_iface for i2c and eeprom.
Diffstat (limited to 'host/lib/types.cpp')
-rw-r--r-- | host/lib/types.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/host/lib/types.cpp b/host/lib/types.cpp index 91887840c..a1b9b21a9 100644 --- a/host/lib/types.cpp +++ b/host/lib/types.cpp @@ -31,6 +31,7 @@ #include <boost/foreach.hpp> #include <boost/format.hpp> #include <boost/cstdint.hpp> +#include <boost/assign/list_of.hpp> #include <stdexcept> #include <complex> @@ -250,3 +251,29 @@ spi_config_t::spi_config_t(edge_t edge){ mosi_edge = edge; miso_edge = edge; } + +void i2c_iface::write_eeprom( + boost::uint8_t addr, + boost::uint8_t offset, + const byte_vector_t &bytes +){ + BOOST_FOREACH(boost::uint8_t byte, bytes){ + //write a byte at a time, its easy that way + byte_vector_t cmd = boost::assign::list_of(offset)(byte); + this->write_i2c(addr, cmd); + } +} + +byte_vector_t i2c_iface::read_eeprom( + boost::uint8_t addr, + boost::uint8_t offset, + size_t num_bytes +){ + byte_vector_t bytes; + for (size_t i = 0; i < num_bytes; i++){ + //do a zero byte write to start read cycle + this->write_i2c(addr, byte_vector_t(1, offset)); + bytes.push_back(this->read_i2c(addr, 1).at(0)); + } + return bytes; +} |