Version with sensors supporting SPI 3-wires
Dependencies: ST_INTERFACES X_NUCLEO_COMMON_SPI3W
Fork of X_NUCLEO_IKS01A2 by
Revision 24:17e674bd19c8, committed 2017-09-07
- Comitter:
- mapellil
- Date:
- Thu Sep 07 14:22:17 2017 +0000
- Parent:
- 23:9ffbb64a8c19
- Commit message:
- Code cleanup
Changed in this revision
--- a/Components/HTS221Sensor/HTS221Sensor.h Thu Sep 07 12:53:06 2017 +0000 +++ b/Components/HTS221Sensor/HTS221Sensor.h Thu Sep 07 14:22:17 2017 +0000 @@ -60,7 +60,6 @@ { public: HTS221Sensor(SPI3W *spi3w, PinName cs_pin=NC, PinName drdy_pin=NC); - HTS221Sensor(SPI *spi, PinName cs_pin, PinName drdy_pin=NC); HTS221Sensor(DevI2C *i2c, uint8_t address=HTS221_I2C_ADDRESS, PinName drdy_pin=NC); virtual int init(void *init); virtual int read_id(uint8_t *id); @@ -82,20 +81,6 @@ */ uint8_t io_read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead) { - if (_dev_spi) { - /* Write Reg Address */ - _dev_spi->lock(); - _cs_pin = 0; - _dev_spi->write(RegisterAddr | 0x80); - - for (int i=0; i<NumByteToRead; i++) { - *(pBuffer+i) = _dev_spi->write(0x00); - } - - _cs_pin = 1; - _dev_spi->unlock(); - return 0; - } if (_dev_spi3w) return _dev_spi3w->spi3w_read(pBuffer, &_cs_pin, RegisterAddr, NumByteToRead); if (_dev_i2c) return (uint8_t) _dev_i2c->i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead); @@ -110,22 +95,7 @@ * @retval 0 if ok, an error code otherwise. */ uint8_t io_write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite) - { - int data; - if (_dev_spi) { - _dev_spi->lock(); - _cs_pin = 0; - data = _dev_spi->write(RegisterAddr); - - for (int i=0; i<NumByteToWrite; i++) { - data = _dev_spi->write(*(pBuffer+i)); - } - - _cs_pin = 1; - _dev_spi->unlock(); - return data; - } - + { if (_dev_spi3w) return _dev_spi3w->spi3w_write(pBuffer, &_cs_pin, RegisterAddr, NumByteToWrite); if (_dev_i2c) return (uint8_t) _dev_i2c->i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite); @@ -137,7 +107,6 @@ /* Helper classes. */ DevI2C * _dev_i2c; SPI3W * _dev_spi3w; - SPI * _dev_spi; /* Configuration */ uint8_t _address;
--- a/Components/LSM303AGRSensor/LSM303AGRMagSensor.h Thu Sep 07 12:53:06 2017 +0000 +++ b/Components/LSM303AGRSensor/LSM303AGRMagSensor.h Thu Sep 07 14:22:17 2017 +0000 @@ -60,7 +60,6 @@ { public: LSM303AGRMagSensor(SPI3W *spi3w, PinName cs_pin, PinName intmag_pin=NC); - LSM303AGRMagSensor(SPI *spi, PinName cs_pin, PinName intmag_pin=NC); LSM303AGRMagSensor(DevI2C *i2c, uint8_t address=LSM303AGR_MAG_I2C_ADDRESS, PinName intmag_pin=NC); virtual int init(void *init); @@ -86,21 +85,6 @@ */ uint8_t io_read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead) { - if (_dev_spi) { - /* Write Reg Address */ - _dev_spi->lock(); - _cs_pin = 0; - _dev_spi->write(RegisterAddr | 0x80); - - for (int i=0; i<NumByteToRead; i++) { - *(pBuffer+i) = _dev_spi->write(0x00); - } - - _cs_pin = 1; - _dev_spi->unlock(); - return 0; - } - if (_dev_spi3w) return _dev_spi3w->spi3w_read(pBuffer, &_cs_pin, RegisterAddr, NumByteToRead); if (_dev_i2c) return (uint8_t) _dev_i2c->i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead); @@ -115,22 +99,7 @@ * @retval 0 if ok, an error code otherwise. */ uint8_t io_write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite) - { - int data; - if (_dev_spi) { - _dev_spi->lock(); - _cs_pin = 0; - data = _dev_spi->write(RegisterAddr); - - for (int i=0; i<NumByteToWrite; i++) { - data = _dev_spi->write(*(pBuffer+i)); - } - - _cs_pin = 1; - _dev_spi->unlock(); - return data; - } - + { if (_dev_spi3w) return _dev_spi3w->spi3w_write(pBuffer, &_cs_pin, RegisterAddr, NumByteToWrite); if (_dev_i2c) return (uint8_t) _dev_i2c->i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite); @@ -142,7 +111,6 @@ /* Helper classes. */ DevI2C *_dev_i2c; SPI3W *_dev_spi3w; - SPI *_dev_spi; /* Configuration */ uint8_t _address;