diff options
author | Martin Braun <martin.braun@ettus.com> | 2017-04-19 18:55:16 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2017-12-22 15:03:46 -0800 |
commit | 36365930a6035e18dc3ec07d401d73e7730af8cf (patch) | |
tree | 5d1c2e3653c3f2edce464328fdf03eafaaffd476 /mpm/lib/spi/spidev_iface.cpp | |
parent | 0cdf67ad33628af28cf92ef4ad7eaa63c712b8b5 (diff) | |
download | uhd-36365930a6035e18dc3ec07d401d73e7730af8cf.tar.gz uhd-36365930a6035e18dc3ec07d401d73e7730af8cf.tar.bz2 uhd-36365930a6035e18dc3ec07d401d73e7730af8cf.zip |
mpm: Fixed a plethora of SPI-related issues
Diffstat (limited to 'mpm/lib/spi/spidev_iface.cpp')
-rw-r--r-- | mpm/lib/spi/spidev_iface.cpp | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/mpm/lib/spi/spidev_iface.cpp b/mpm/lib/spi/spidev_iface.cpp index 7108759f8..88ee46824 100644 --- a/mpm/lib/spi/spidev_iface.cpp +++ b/mpm/lib/spi/spidev_iface.cpp @@ -23,6 +23,8 @@ #include <linux/spi/spidev.h> #include <boost/format.hpp> +#include <iostream> + using namespace mpm::spi; /****************************************************************************** @@ -45,34 +47,53 @@ public: )); } - ret = ioctl(_fd, SPI_IOC_WR_MODE32, &_mode); + int MODE = 3; + ret = ioctl(_fd, SPI_IOC_WR_MODE32, &MODE); if (ret == -1) { - throw std::runtime_error("Could not set spidev mode"); + throw std::runtime_error(str( + boost::format("Could not set spidev mode to %X for spidev %s") + % uint16_t(_mode) % device + )); } ret = ioctl(_fd, SPI_IOC_RD_MODE32, &_mode); if (ret == -1) { - throw std::runtime_error("Could not get spidev mode"); + throw std::runtime_error(str( + boost::format("Could not get spidev mode for spidev %s") + % device + )); } ret = ioctl(_fd, SPI_IOC_WR_BITS_PER_WORD, &_bits); if (ret == -1) { - throw std::runtime_error("Could not set spidev bits per word"); + throw std::runtime_error(str( + boost::format("Could not set spidev bits per word to %d for spidev %s") + % uint16_t(_bits) % device + )); } ret = ioctl(_fd, SPI_IOC_RD_BITS_PER_WORD, &_bits); if (ret == -1) { - throw std::runtime_error("Could not get spidev bits per word"); + throw std::runtime_error(str( + boost::format("Could not get spidev bits per word for spidev %s") + % device + )); } ret = ioctl(_fd, SPI_IOC_WR_MAX_SPEED_HZ, &_speed); if (ret == -1) { - throw std::runtime_error("Could not set spidev max speed"); + throw std::runtime_error(str( + boost::format("Could not set spidev max speed to %d for spidev %s") + % _speed % device + )); } ret = ioctl(_fd, SPI_IOC_RD_MAX_SPEED_HZ, &_speed); if (ret == -1) { - throw std::runtime_error("Could not get spidev max speed"); + throw std::runtime_error(str( + boost::format("Could not get spidev max speed for spidev %s") + % device + )); } } @@ -138,7 +159,7 @@ public: private: int _fd; - uint8_t _mode = SPI_CPHA | SPI_CPOL; + uint32_t _mode = SPI_CPHA | SPI_CPOL; uint32_t _speed = 2000000; uint8_t _bits = 8; uint16_t _delay = 0; |