Added SPI3w support through DevSPI
Dependencies: ST_INTERFACES X_NUCLEO_COMMON_3W
Fork of LPS22HB by
Diff: LPS22HBSensor.cpp
- Revision:
- 1:8813c9be1720
- Parent:
- 0:3de9cb936fd1
- Child:
- 2:fba15124c67b
--- a/LPS22HBSensor.cpp Mon Sep 04 16:06:45 2017 +0000 +++ b/LPS22HBSensor.cpp Fri Sep 22 09:26:25 2017 +0000 @@ -37,32 +37,49 @@ /* Includes ------------------------------------------------------------------*/ - - +#include "mbed.h" +//#include "SPI3W.h" +#include "SPI.h" +#include "DevI2C.h" #include "LPS22HBSensor.h" - +#include "LPS22HB_driver.h" +#include <assert.h> /* Class Implementation ------------------------------------------------------*/ +LPS22HBSensor::LPS22HBSensor(DevSPI *spi, PinName cs_pin, PinName int_pin) : _dev_spi(spi), _cs_pin(cs_pin), _int_pin(int_pin) +{ + assert (spi); + if (cs_pin == NC) + { + printf ("ERROR LPS22HBSensor CS MUST NOT BE NC\n\r"); + _dev_spi = NULL; + _dev_i2c=NULL; + return; + } + + _cs_pin = 1; + _dev_i2c=NULL; + + if (_dev_spi->isSPI3w()) LPS22HB_Set_SpiInterface ((void *)this, LPS22HB_SPI_3_WIRE); + else LPS22HB_Set_SpiInterface ((void *)this, LPS22HB_SPI_4_WIRE); + + LPS22HB_Set_I2C ((void *)this, LPS22HB_DISABLE); +} + /** Constructor * @param i2c object of an helper class which handles the I2C peripheral * @param address the address of the component's instance */ -LPS22HBSensor::LPS22HBSensor(DevI2C &i2c) : _dev_i2c(i2c) +LPS22HBSensor::LPS22HBSensor(DevI2C *i2c, uint8_t address, PinName int_pin) : + _dev_i2c(i2c), _address(address), _cs_pin(NC), _int_pin(int_pin) { - _address = LPS22HB_ADDRESS_HIGH; + assert (i2c); + _dev_spi = NULL; + LPS22HB_Set_I2C ((void *)this, LPS22HB_ENABLE); }; -/** Constructor - * @param i2c object of an helper class which handles the I2C peripheral - * @param address the address of the component's instance - */ -LPS22HBSensor::LPS22HBSensor(DevI2C &i2c, uint8_t address) : _dev_i2c(i2c), _address(address) -{ - -}; - /** * @brief Initializing the component. * @param[in] init pointer to device specific initalization structure. @@ -77,6 +94,7 @@ /* Power down the device */ if ( LPS22HB_Set_Odr( (void *)this, LPS22HB_ODR_ONE_SHOT ) == LPS22HB_ERROR ) +// if ( LPS22HB_Set_Odr( (void *)this, LPS22HB_ODR_25HZ ) == LPS22HB_ERROR ) { return 1; } @@ -168,7 +186,7 @@ { return 1; } - + /* Read WHO AM I register */ if ( LPS22HB_Get_DeviceID( (void *)this, id ) == LPS22HB_ERROR ) { @@ -222,7 +240,7 @@ int LPS22HBSensor::get_temperature(float *pfData) { int16_t int16data = 0; - + /* Read data from LPS22HB. */ if ( LPS22HB_Get_Temperature( (void *)this, &int16data ) == LPS22HB_ERROR ) {