Ultra-compact high-performance eCompass module: ultra-low power 3D accelerometer and 3D magnetometer.
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Dependents: HelloWorld_ST_Sensors MOTENV_Mbed mbed-os-mqtt-client LSM303AGR_JS ... more
Diff: LSM303AGRMagSensor.cpp
- Revision:
- 2:e37be5550633
- Parent:
- 1:86d530a7f949
--- a/LSM303AGRMagSensor.cpp Wed Sep 27 16:49:51 2017 +0200 +++ b/LSM303AGRMagSensor.cpp Mon Oct 02 09:29:33 2017 +0200 @@ -42,7 +42,22 @@ /* Class Implementation ------------------------------------------------------*/ +LSM303AGRMagSensor::LSM303AGRMagSensor(SPI *spi, PinName cs_pin, PinName intmag_pin) : + _dev_spi(spi), _cs_pin(cs_pin), _intmag_pin(intmag_pin) // SPI3W ONLY +{ + assert (spi); + if (cs_pin == NC) + { + printf ("ERROR LSM303AGRMagSensor CS MUST NOT BE NC\n\r"); + _dev_spi = NULL; + _dev_i2c=NULL; + return; + } + _cs_pin = 0; // enable SPI3W disable I2C + _dev_i2c=NULL; + LSM303AGR_ACC_W_SPI_mode((void *)this, LSM303AGR_ACC_SIM_3_WIRES); +} /** Constructor * @param i2c object of an helper class which handles the I2C peripheral * @param address the address of the component's instance @@ -51,7 +66,8 @@ _dev_i2c(i2c), _address(address), _cs_pin(NC), _intmag_pin(intmag_pin) { assert (i2c); -}; + _dev_spi = NULL; +} /** * @brief Initializing the component.