diff options
author | Mark Meserve <mark.meserve@ni.com> | 2017-09-01 15:11:50 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2017-12-22 15:04:01 -0800 |
commit | 01ddd50e55fae3382c1300616747fc9aebb39523 (patch) | |
tree | f3fc5e98d7b38e47ae70256b310ac2e1d776045b /mpm/lib/spi/spidev_iface.cpp | |
parent | 2472134af0ead2472d441a71343348a03fc96808 (diff) | |
download | uhd-01ddd50e55fae3382c1300616747fc9aebb39523.tar.gz uhd-01ddd50e55fae3382c1300616747fc9aebb39523.tar.bz2 uhd-01ddd50e55fae3382c1300616747fc9aebb39523.zip |
mpm: spi: Added 16-bit SPI transactions
- Adds convenience method to read 16-bit SPI transactions
- Fixes peek16 in spi_regs_iface to actually use 16-bit transactions
Diffstat (limited to 'mpm/lib/spi/spidev_iface.cpp')
-rw-r--r-- | mpm/lib/spi/spidev_iface.cpp | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/mpm/lib/spi/spidev_iface.cpp b/mpm/lib/spi/spidev_iface.cpp index 74cb6bc88..522238e19 100644 --- a/mpm/lib/spi/spidev_iface.cpp +++ b/mpm/lib/spi/spidev_iface.cpp @@ -89,11 +89,35 @@ public: )); } - // Assumes that only a single byte is being read. - // TODO the function does not advertise this. Should probably fix. return uint32_t(rx[2]); } + uint32_t transfer24_16( + const uint32_t data_ + ) { + int ret(0); + + uint32_t data = data_; + uint8_t *tx_data = reinterpret_cast<uint8_t *>(&data); + + // Create tx and rx buffers: + uint8_t tx[] = {tx_data[2], tx_data[1], tx_data[0]}; // FIXME guarantee endianness + uint8_t rx[3]; // Buffer length must match tx buffer + + if (transfer( + _fd, + &tx[0], &rx[0], + 3, + _speed, _bits, _delay + ) != 0) { + throw mpm::runtime_error(str( + boost::format("SPI Transaction failed!") + )); + } + + return uint32_t(rx[1] << 8 | rx[2]); + } + private: int _fd; const uint32_t _mode; |