ST Expansion SW Team / X_NUCLEO_IKS01A2_SPI3W

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON_SPI3W

Dependents:   sensor-node-ble

Fork of X_NUCLEO_IKS01A2 by Licio Mapelli

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers XNucleoIKS01A2.cpp Source File

XNucleoIKS01A2.cpp

Go to the documentation of this file.
00001 /**
00002  ******************************************************************************
00003  * @file    XNucleoIKS01A2.cpp
00004  * @author  CLab
00005  * @version V1.0.0
00006  * @date    9-August-2016
00007  * @brief   Implementation file for the X_NUCLEO_IKS01A2 singleton class
00008  ******************************************************************************
00009  * @attention
00010  *
00011  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
00012  *
00013  * Redistribution and use in source and binary forms, with or without modification,
00014  * are permitted provided that the following conditions are met:
00015  *   1. Redistributions of source code must retain the above copyright notice,
00016  *      this list of conditions and the following disclaimer.
00017  *   2. Redistributions in binary form must reproduce the above copyright notice,
00018  *      this list of conditions and the following disclaimer in the documentation
00019  *      and/or other materials provided with the distribution.
00020  *   3. Neither the name of STMicroelectronics nor the names of its contributors
00021  *      may be used to endorse or promote products derived from this software
00022  *      without specific prior written permission.
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00028  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00029  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00030  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00032  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  ******************************************************************************
00036 */ 
00037     
00038 /* Includes ------------------------------------------------------------------*/
00039 #include "mbed.h"
00040 #include "XNucleoIKS01A2.h"
00041 
00042 /* Static variables ----------------------------------------------------------*/
00043 XNucleoIKS01A2 *XNucleoIKS01A2::_instance = NULL;
00044 
00045 
00046 /* Methods -------------------------------------------------------------------*/
00047 /**
00048  * @brief  Constructor
00049  */
00050  
00051 XNucleoIKS01A2::XNucleoIKS01A2(DevI2C *ext_i2c, PinName int1, PinName int2) : dev_i2c(ext_i2c),
00052     ht_sensor(new HTS221Sensor(dev_i2c)),
00053     magnetometer(new LSM303AGRMagSensor(dev_i2c)),
00054     accelerometer(new LSM303AGRAccSensor(dev_i2c)),
00055     pt_sensor(new LPS22HBSensor(dev_i2c)),
00056     acc_gyro(new LSM6DSLSensor(dev_i2c, LSM6DSL_ACC_GYRO_I2C_ADDRESS_HIGH, int1, int2))
00057 {   
00058   ht_sensor->init(NULL);
00059   magnetometer->init(NULL);
00060   accelerometer->init(NULL);
00061   pt_sensor->init(NULL);
00062   acc_gyro->init(NULL);
00063 }
00064 
00065 /**
00066  * @brief     Get singleton instance
00067  * @return    a pointer to the initialized singleton instance of class XNucleoIKS01A2.
00068  *            A return value of NULL indicates an out of memory situation.
00069  * @param[in] ext_i2c (optional) pointer to an instance of DevI2C to be used
00070  *            for communication on the expansion board. 
00071  *            Defaults to NULL.
00072  *            Taken into account only on the very first call of one of the 'Instance' functions.
00073  *            If not provided a new DevI2C will be created with standard
00074  *            configuration parameters.
00075  *            The used DevI2C object gets saved in instance variable dev_i2c.
00076  * @param[in] int1 LSM6DSL INT1 pin.
00077  *            Taken into account only on the very first call of one of the 'Instance' functions.
00078  *            It maps the INT1 pin for LSM6DSL. Defaults to IKS01A2_PIN_LSM6DSL_INT1.
00079  * @param[in] int2 LSM6DSL INT1 pin.
00080  *            Taken into account only on the very first call of one of the 'Instance' functions.
00081  *            It maps the INT2 pin for LSM6DSL. Defaults to IKS01A2_PIN_LSM6DSL_INT2.
00082  */
00083 XNucleoIKS01A2 *XNucleoIKS01A2::instance(DevI2C *ext_i2c, PinName int1, PinName int2) {
00084     if(_instance == NULL) {
00085         if(ext_i2c == NULL)
00086             ext_i2c = new DevI2C(IKS01A2_PIN_I2C_SDA, IKS01A2_PIN_I2C_SCL);
00087 
00088         if(ext_i2c != NULL)
00089             _instance = new XNucleoIKS01A2(ext_i2c, int1, int2);
00090     }
00091 
00092     return _instance;
00093 }
00094 
00095 /**
00096  * @brief     Get singleton instance
00097  * @return    a pointer to the initialized singleton instance of class X_NUCLEO_IKS01A1.
00098  *            A return value of NULL indicates an out of memory situation.
00099  * @param[in] sda I2C data line pin.
00100  *            Taken into account only on the very first call of one of the 'Instance' functions.
00101  *            A new DevI2C will be created based on parameters 'sda' and 'scl'.
00102  *            The used DevI2C object gets saved in instance variable dev_i2c.
00103  * @param[in] scl I2C clock line pin.
00104  *            Taken into account only on the very first call of one of the 'Instance' functions.
00105  *            A new DevI2C will be created based on parameters 'sda' and 'scl'.
00106  *            The used DevI2C object gets saved in instance variable dev_i2c.
00107  * @param[in] int1 LSM6DSL INT1 pin.
00108  *            Taken into account only on the very first call of one of the 'Instance' functions.
00109  *            It maps the INT1 pin for LSM6DSL. Defaults to IKS01A2_PIN_LSM6DSL_INT1.
00110  * @param[in] int2 LSM6DSL INT1 pin.
00111  *            Taken into account only on the very first call of one of the 'Instance' functions.
00112  *            It maps the INT2 pin for LSM6DSL. Defaults to IKS01A2_PIN_LSM6DSL_INT2.
00113  */
00114 XNucleoIKS01A2 *XNucleoIKS01A2::instance(PinName sda, PinName scl, PinName int1, PinName int2) {
00115     if(_instance == NULL) {
00116         DevI2C *ext_i2c = new DevI2C(sda, scl);
00117 
00118         if(ext_i2c != NULL)
00119             _instance = new XNucleoIKS01A2(ext_i2c, int1, int2);
00120     }
00121 
00122     return _instance;
00123 }