Added SPI3w support through DevSPI
Dependencies: ST_INTERFACES X_NUCLEO_COMMON_3W
Fork of LPS22HB by
Revision 2:fba15124c67b, committed 2017-09-26
- Comitter:
- mapellil
- Date:
- Tue Sep 26 08:18:06 2017 +0000
- Parent:
- 1:8813c9be1720
- Commit message:
- Removed DevSPI dependency, now SPI3W is supported directly through SPI
Changed in this revision
LPS22HBSensor.cpp | Show annotated file Show diff for this revision Revisions of this file |
LPS22HBSensor.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/LPS22HBSensor.cpp Fri Sep 22 09:26:25 2017 +0000 +++ b/LPS22HBSensor.cpp Tue Sep 26 08:18:06 2017 +0000 @@ -47,7 +47,7 @@ /* Class Implementation ------------------------------------------------------*/ -LPS22HBSensor::LPS22HBSensor(DevSPI *spi, PinName cs_pin, PinName int_pin) : _dev_spi(spi), _cs_pin(cs_pin), _int_pin(int_pin) +LPS22HBSensor::LPS22HBSensor(SPI *spi, PinName cs_pin, PinName int_pin, SPI_type_t spi_type) : _dev_spi(spi), _cs_pin(cs_pin), _int_pin(int_pin), _spi_type(spi_type) { assert (spi); if (cs_pin == NC) @@ -61,8 +61,8 @@ _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); + if (_spi_type == SPI3W) LPS22HB_Set_SpiInterface ((void *)this, LPS22HB_SPI_3_WIRE); + else if (_spi_type == SPI4W) LPS22HB_Set_SpiInterface ((void *)this, LPS22HB_SPI_4_WIRE); LPS22HB_Set_I2C ((void *)this, LPS22HB_DISABLE); }
--- a/LPS22HBSensor.h Fri Sep 22 09:26:25 2017 +0000 +++ b/LPS22HBSensor.h Tue Sep 26 08:18:06 2017 +0000 @@ -58,7 +58,8 @@ class LPS22HBSensor : public PressureSensor, public TempSensor { public: - LPS22HBSensor(DevSPI *spi, PinName cs_pin, PinName int_pin=NC); +enum SPI_type_t {SPI3W, SPI4W}; + LPS22HBSensor(SPI *spi, PinName cs_pin, PinName int_pin=NC, SPI_type_t spi_type=SPI4W); LPS22HBSensor(DevI2C *i2c, uint8_t address=LPS22HB_ADDRESS_HIGH, PinName int_pin=NC); virtual int init(void *init); virtual int read_id(uint8_t *id); @@ -85,12 +86,12 @@ /* Write Reg Address */ _dev_spi->lock(); _cs_pin = 0; - if (!_dev_spi->isSPI3w()) { + if (_spi_type == SPI4W) { _dev_spi->write(RegisterAddr | 0x80); for (int i=0; i<NumByteToRead; i++) { *(pBuffer+i) = _dev_spi->write(0x00); } - } else { + } else if (_spi_type == SPI3W){ /* Write RD Reg Address with RD bit*/ uint8_t TxByte = RegisterAddr | 0x80; _dev_spi->write((char *)&TxByte, 1, (char *)pBuffer, (int) NumByteToRead); @@ -134,7 +135,7 @@ /* Helper classes. */ DevI2C *_dev_i2c; - DevSPI *_dev_spi; + SPI *_dev_spi; /* Configuration */ uint8_t _address; @@ -143,6 +144,7 @@ uint8_t _is_enabled; float _last_odr; + SPI_type_t _spi_type; }; #ifdef __cplusplus