diff --git a/src/utility/linux_kernel/gpio.cpp b/src/utility/linux_kernel/gpio.cpp index e70b5eb..0ca9e15 100644 --- a/src/utility/linux_kernel/gpio.cpp +++ b/src/utility/linux_kernel/gpio.cpp @@ -20,8 +20,8 @@ #include // close() #include // open() #include // ioctl() - #include // errno, strerror() - #include // std::string, strcpy() + #include // errno + #include // strerror(), memset(), strcpy() #include #include "linux/gpio.h" #include "gpio.h" diff --git a/src/utility/linux_kernel/gpio.h b/src/utility/linux_kernel/gpio.h index 4f64fd0..f04ef1c 100644 --- a/src/utility/linux_kernel/gpio.h +++ b/src/utility/linux_kernel/gpio.h @@ -20,8 +20,8 @@ #define CIRQUEPINNACLE_UTILITY_LINUX_KERNEL_GPIO_H_ #ifndef ARDUINO - #include - #include + #include // uintXX_t + #include // std::exception, std::string #include "linux/gpio.h" // gpiochip_info #ifdef __cplusplus diff --git a/src/utility/linux_kernel/i2c.cpp b/src/utility/linux_kernel/i2c.cpp index 0e0093d..b4138cb 100644 --- a/src/utility/linux_kernel/i2c.cpp +++ b/src/utility/linux_kernel/i2c.cpp @@ -18,11 +18,15 @@ */ #ifndef ARDUINO - #include - #include - #include - #include - #include + #include // free(), malloc() + #include // size_t + #include // uintXX_t + #include // sprintf + #include // close() + #include // open() + #include // ioctl() + #include // errno + #include // strerror() #include #include #include "i2c.h" @@ -51,7 +55,9 @@ namespace cirque_pinnacle_arduino_wrappers { sprintf(filename, "/dev/i2c-%d", busNumber); file = open(filename, O_RDWR); if (file < 0) { - throw I2CException("Can't open I2C bus. Check access rights."); + std::string msg = "[TwoWire::begin] Can't open I2C bus; "; + msg += strerror(errno); + throw I2CException(msg); } bus_fd = file; } @@ -65,7 +71,9 @@ namespace cirque_pinnacle_arduino_wrappers { void TwoWire::beginTransmission(uint8_t address) { if (ioctl(bus_fd, I2C_SLAVE, address) < 0) { - throw I2CException("Could not select I2C slave address."); + std::string msg = "[TwoWire::beginTransmission] Could not select I2C slave address; "; + msg += strerror(errno); + throw I2CException(msg); } xBuffIndex = 0; xBuffLen = 0; @@ -76,7 +84,9 @@ namespace cirque_pinnacle_arduino_wrappers { (void)sendStop; // param not used in this implementation if (::write(bus_fd, xBuff, xBuffLen) != xBuffLen) { - throw I2CException("Could not write data to I2C bus."); + std::string msg = "[TwoWire::endTransmission] Could not write data to I2C bus; "; + msg += strerror(errno); + throw I2CException(msg); } return xBuffLen; } @@ -102,7 +112,9 @@ namespace cirque_pinnacle_arduino_wrappers { xBuffIndex = 0; int retVal = ::read(bus_fd, xBuff, quantity); if (retVal < 0) { - throw I2CException("Could not read data from I2C bus."); + std::string msg = "[TwoWire::endTransmission] Could not read data from I2C bus; "; + msg += strerror(errno); + throw I2CException(msg); } xBuffLen = quantity; return xBuffLen; diff --git a/src/utility/linux_kernel/i2c.h b/src/utility/linux_kernel/i2c.h index fcbfa57..14139aa 100644 --- a/src/utility/linux_kernel/i2c.h +++ b/src/utility/linux_kernel/i2c.h @@ -20,8 +20,8 @@ #define CIRQUEPINNACLE_UTILITY_LINUX_KERNEL_I2C_H_ #ifndef ARDUINO - #include - #include + #include // uintXX_t + #include // std::exception, std::string #ifdef __cplusplus extern "C" { diff --git a/src/utility/linux_kernel/spi.cpp b/src/utility/linux_kernel/spi.cpp index efc2dc7..b82aed5 100644 --- a/src/utility/linux_kernel/spi.cpp +++ b/src/utility/linux_kernel/spi.cpp @@ -17,13 +17,13 @@ * SOFTWARE. */ #ifndef ARDUINO - #include + #include // uintXX_ts + #include // close() + #include // open() + #include // ioctl() + #include // errno, + #include // memset() strerror() #include - #include - #include - #include - #include - #include #include "spi.h" #ifdef __cplusplus @@ -61,7 +61,11 @@ namespace cirque_pinnacle_arduino_wrappers { fd = open(device, O_RDWR); if (fd < 0) { - throw SPIException("can't open device"); + std::string msg = "[SPIClass::begin] Could not open device "; + msg += device; + msg += "; "; + msg += strerror(errno); + throw SPIException(msg); } spiIsInitialized = true; @@ -70,35 +74,47 @@ namespace cirque_pinnacle_arduino_wrappers { // spi mode ret = ioctl(fd, SPI_IOC_WR_MODE, &settings.mode); if (ret == -1) { - throw SPIException("SPI can't set mode"); + std::string msg = "[SPIClass::begin] Could not set write mode; "; + msg += strerror(errno); + throw SPIException(msg); } ret = ioctl(fd, SPI_IOC_RD_MODE, &settings.mode); if (ret == -1) { - throw SPIException("SPI can't read mode"); + std::string msg = "[SPIClass::begin] Could not set read mode; "; + msg += strerror(errno); + throw SPIException(msg); } // bits per word uint8_t bits = PINNACLE_SPI_BITS_PER_WORD; ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits); if (ret == -1) { - throw SPIException("SPI can't set bits per word"); + std::string msg = "[SPIClass::begin] Could not set write bits per word; "; + msg += strerror(errno); + throw SPIException(msg); } ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits); if (ret == -1) { - throw SPIException("SPI can't read bits per word"); + std::string msg = "[SPIClass::begin] Could not set read bits per word; "; + msg += strerror(errno); + throw SPIException(msg); } // max speed Hz ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &settings.clock); if (ret == -1) { - throw SPIException("SPI can't set max speed Hz"); + std::string msg = "[SPIClass::begin] Could not set write max speed Hz; "; + msg += strerror(errno); + throw SPIException(msg); } ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &settings.clock); if (ret == -1) { - throw SPIException("SPI can't read max speed Hz"); + std::string msg = "[SPIClass::begin] Could not set read max speed Hz; "; + msg += strerror(errno); + throw SPIException(msg); } _spi_speed = settings.clock; @@ -120,7 +136,9 @@ namespace cirque_pinnacle_arduino_wrappers { int ret; ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr); if (ret < 1) { - throw SPIException("SPI ioctl() transfer failed."); + std::string msg = "[SPIClass::transfer(tx)] Could not transfer buffer; "; + msg += strerror(errno); + throw SPIException(msg); } return rx; } @@ -140,7 +158,9 @@ namespace cirque_pinnacle_arduino_wrappers { int ret; ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr); if (ret < 1) { - throw SPIException("SPI ioctl() transfer failed."); + std::string msg = "[SPIClass::transfer(tx, rx, len)] Could not transfer buffer; "; + msg += strerror(errno); + throw SPIException(msg); } } diff --git a/src/utility/linux_kernel/spi.h b/src/utility/linux_kernel/spi.h index 3bb2991..573c6c5 100644 --- a/src/utility/linux_kernel/spi.h +++ b/src/utility/linux_kernel/spi.h @@ -20,8 +20,8 @@ #define CIRQUEPINNACLE_UTILITY_LINUX_KERNEL_SPI_H_ #ifndef ARDUINO - #include - #include + #include // uintXX_t + #include // std::exception, std::string #include #ifdef __cplusplus