aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/types
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2013-07-24 17:46:04 -0700
committerJosh Blum <josh@joshknows.com>2013-07-24 17:46:04 -0700
commit0aeac60394420de1952ebc230a6fa2f8593df80a (patch)
treef08d6ca1555dc2df15a79c3da6d32cad9a6224d7 /host/lib/types
parent690637f78685b2979a9f128ce3c82149b5421c46 (diff)
downloaduhd-0aeac60394420de1952ebc230a6fa2f8593df80a.tar.gz
uhd-0aeac60394420de1952ebc230a6fa2f8593df80a.tar.bz2
uhd-0aeac60394420de1952ebc230a6fa2f8593df80a.zip
uhd: allow for 16 bit i2c and eeprom addrs
Diffstat (limited to 'host/lib/types')
-rw-r--r--host/lib/types/serial.cpp61
1 files changed, 57 insertions, 4 deletions
diff --git a/host/lib/types/serial.cpp b/host/lib/types/serial.cpp
index 562261bb7..9b8336dd8 100644
--- a/host/lib/types/serial.cpp
+++ b/host/lib/types/serial.cpp
@@ -44,8 +44,8 @@ spi_config_t::spi_config_t(edge_t edge):
}
void i2c_iface::write_eeprom(
- boost::uint8_t addr,
- boost::uint8_t offset,
+ boost::uint16_t addr,
+ boost::uint16_t offset,
const byte_vector_t &bytes
){
for (size_t i = 0; i < bytes.size(); i++){
@@ -57,8 +57,8 @@ void i2c_iface::write_eeprom(
}
byte_vector_t i2c_iface::read_eeprom(
- boost::uint8_t addr,
- boost::uint8_t offset,
+ boost::uint16_t addr,
+ boost::uint16_t offset,
size_t num_bytes
){
byte_vector_t bytes;
@@ -70,6 +70,59 @@ byte_vector_t i2c_iface::read_eeprom(
return bytes;
}
+struct eeprom16_impl : i2c_iface
+{
+ eeprom16_impl(i2c_iface* internal)
+ {
+ _internal = internal;
+ }
+ i2c_iface* _internal;
+
+ byte_vector_t read_i2c(
+ boost::uint16_t addr,
+ size_t num_bytes
+ ){
+ return _internal->read_i2c(addr, num_bytes);
+ }
+
+ void write_i2c(
+ boost::uint16_t addr,
+ const byte_vector_t &bytes
+ ){
+ return _internal->write_i2c(addr, bytes);
+ }
+
+ byte_vector_t read_eeprom(
+ boost::uint16_t addr,
+ boost::uint16_t offset,
+ size_t num_bytes
+ ){
+ byte_vector_t cmd = boost::assign::list_of(offset >> 8)(offset & 0xff);
+ this->write_i2c(addr, cmd);
+ return this->read_i2c(addr, num_bytes);
+ }
+
+ void write_eeprom(
+ boost::uint16_t addr,
+ boost::uint16_t offset,
+ const byte_vector_t &bytes
+ ){
+ for (size_t i = 0; i < bytes.size(); i++)
+ {
+ //write a byte at a time, its easy that way
+ boost::uint16_t offset_i = offset+i;
+ byte_vector_t cmd = boost::assign::list_of(offset_i >> 8)(offset_i & 0xff)(bytes[i]);
+ this->write_i2c(addr, cmd);
+ boost::this_thread::sleep(boost::posix_time::milliseconds(10)); //worst case write
+ }
+ }
+};
+
+i2c_iface::sptr i2c_iface::eeprom16(void)
+{
+ return i2c_iface::sptr(new eeprom16_impl(this));
+}
+
boost::uint32_t spi_iface::read_spi(
int which_slave,
const spi_config_t &config,