mirror of
https://github.com/eclipse/upm.git
synced 2025-03-24 01:10:22 +03:00
adis16448: throw exception(s) on fatal errors
Signed-off-by: Jon Trulson <jtrulson@ics.com> Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
parent
b0ac4b5da2
commit
f84973b0e4
@ -37,6 +37,8 @@
|
|||||||
//
|
//
|
||||||
//////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <stdexcept>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@ -54,14 +56,23 @@ using namespace upm;
|
|||||||
ADIS16448::ADIS16448(int bus, int rst)
|
ADIS16448::ADIS16448(int bus, int rst)
|
||||||
{
|
{
|
||||||
// Configure I/O
|
// Configure I/O
|
||||||
_rst = mraa_gpio_init(rst); //Initialize RST pin
|
//Initialize RST pin
|
||||||
|
if ( !(_rst = mraa_gpio_init(rst)) )
|
||||||
|
{
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": mraa_gpio_init() failed, invalid pin?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
mraa_gpio_dir(_rst, MRAA_GPIO_IN); //Set direction as INPUT
|
mraa_gpio_dir(_rst, MRAA_GPIO_IN); //Set direction as INPUT
|
||||||
|
|
||||||
// Configure SPI
|
// Configure SPI
|
||||||
_spi = mraa_spi_init(bus);
|
if ( !(_spi = mraa_spi_init(bus)) )
|
||||||
mraa_spi_frequency(_spi, 1000000); //Set SPI frequency to 1MHz
|
{
|
||||||
mraa_spi_mode(_spi, MRAA_SPI_MODE3); //Set SPI mode/polarity
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
mraa_spi_bit_per_word(_spi, 16); //Set # of bits per word
|
": mraa_spi_init() failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
configSPI();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
@ -102,8 +113,21 @@ void ADIS16448::resetDUT()
|
|||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
void ADIS16448::configSPI() {
|
void ADIS16448::configSPI() {
|
||||||
mraa_spi_frequency(_spi, 1000000); //Set SPI frequency to 1MHz
|
mraa_spi_frequency(_spi, 1000000); //Set SPI frequency to 1MHz
|
||||||
mraa_spi_mode(_spi, MRAA_SPI_MODE3); //Set SPI mode/polarity
|
|
||||||
mraa_spi_bit_per_word(_spi, 16); //Set # of bits per word
|
if ( mraa_spi_mode(_spi, MRAA_SPI_MODE3) != MRAA_SUCCESS )
|
||||||
|
{
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": mraa_spi_mode() failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//Set # of bits per word
|
||||||
|
|
||||||
|
if ( mraa_spi_bit_per_word(_spi, 16) != MRAA_SUCCESS )
|
||||||
|
{
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": mraa_spi_bit_per_word() failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
x
Reference in New Issue
Block a user