..

Dependencies:   STTS751 LPS22HH LIS2MDL HTS221 LIS2DW12 LSM6DSO

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers XNucleoIKS01A3.cpp Source File

XNucleoIKS01A3.cpp

Go to the documentation of this file.
00001 /**
00002  ******************************************************************************
00003  * @file    XNucleoIKS01A3.cpp
00004  * @author  SRA
00005  * @version V1.0.0
00006  * @date    5-March-2019
00007  * @brief   Implementation file for the X_NUCLEO_IKS01A3 singleton class
00008  ******************************************************************************
00009  * @attention
00010  *
00011  * <h2><center>&copy; COPYRIGHT(c) 2019 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 "XNucleoIKS01A3.h"
00041 
00042 /* Static variables ----------------------------------------------------------*/
00043 XNucleoIKS01A3 *XNucleoIKS01A3::_instance = NULL;
00044 
00045 
00046 /* Methods -------------------------------------------------------------------*/
00047 /**
00048  * @brief  Constructor
00049  */
00050 XNucleoIKS01A3::XNucleoIKS01A3(DevI2C *ext_i2c, PinName lsm6dso_int1, PinName lsm6dso_int2, PinName lis2dw12_int1, PinName lps22hh_int, PinName stts751_int) : dev_i2c(ext_i2c),
00051     ht_sensor(new HTS221Sensor(dev_i2c)),
00052     magnetometer(new LIS2MDLSensor(dev_i2c)),
00053     accelerometer(new LIS2DW12Sensor(dev_i2c, LIS2DW12_I2C_ADD_H, lis2dw12_int1)),
00054     pt_sensor(new LPS22HHSensor(dev_i2c, LPS22HH_I2C_ADD_H, lps22hh_int)),
00055     acc_gyro(new LSM6DSOSensor(dev_i2c, LSM6DSO_I2C_ADD_H, lsm6dso_int1, lsm6dso_int2)),
00056     t_sensor(new STTS751Sensor(dev_i2c, STTS751_1xxxx_ADD_7K5, stts751_int))
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     t_sensor->init(NULL);
00064 }
00065 
00066 /**
00067  * @brief     Get singleton instance
00068  * @return    a pointer to the initialized singleton instance of class XNucleoIKS01A3.
00069  *            A return value of NULL indicates an out of memory situation.
00070  * @param[in] ext_i2c (optional) pointer to an instance of DevI2C to be used
00071  *            for communication on the expansion board.
00072  *            Defaults to NULL.
00073  *            Taken into account only on the very first call of one of the 'Instance' functions.
00074  *            If not provided a new DevI2C will be created with standard
00075  *            configuration parameters.
00076  *            The used DevI2C object gets saved in instance variable dev_i2c.
00077  * @param[in] lsm6dso_int1 LSM6DSO INT1 pin.
00078  *            Taken into account only on the very first call of one of the 'Instance' functions.
00079  *            It maps the INT1 pin for LSM6DSO. Defaults to IKS01A3_PIN_LSM6DSO_INT1.
00080  * @param[in] lsm6dso_int2 LSM6DSO INT2 pin.
00081  *            Taken into account only on the very first call of one of the 'Instance' functions.
00082  *            It maps the INT2 pin for LSM6DSO. Defaults to IKS01A3_PIN_LSM6DSO_INT2.
00083  * @param[in] lis2dw12_int1 LIS2DW12 INT1 pin.
00084  *            Taken into account only on the very first call of one of the 'Instance' functions.
00085  *            It maps the INT1 pin for LIS2DW12. Defaults to IKS01A3_PIN_LIS2DW12_INT1.
00086  * @param[in] lps22hh_int LPS22HH INT pin.
00087  *            Taken into account only on the very first call of one of the 'Instance' functions.
00088  *            It maps the INT pin for LPS22HH. Defaults to IKS01A3_PIN_LPS22HH_INT.
00089  * @param[in] stts751_int STTS751 INT pin.
00090  *            Taken into account only on the very first call of one of the 'Instance' functions.
00091  *            It maps the INT pin for STTS751. Defaults to IKS01A3_PIN_STTS751_INT.
00092  */
00093 XNucleoIKS01A3 *XNucleoIKS01A3::instance(DevI2C *ext_i2c, PinName lsm6dso_int1, PinName lsm6dso_int2, PinName lis2dw12_int1, PinName lps22hh_int, PinName stts751_int)
00094 {
00095     if (_instance == NULL) {
00096         if (ext_i2c == NULL) {
00097             ext_i2c = new DevI2C(IKS01A3_PIN_I2C_SDA, IKS01A3_PIN_I2C_SCL);
00098         }
00099 
00100         if (ext_i2c != NULL) {
00101             _instance = new XNucleoIKS01A3(ext_i2c, lsm6dso_int1, lsm6dso_int2, lis2dw12_int1, lps22hh_int, stts751_int);
00102         }
00103     }
00104 
00105     return _instance;
00106 }
00107 
00108 /**
00109  * @brief     Get singleton instance
00110  * @return    a pointer to the initialized singleton instance of class X_NUCLEO_IKS01A3.
00111  *            A return value of NULL indicates an out of memory situation.
00112  * @param[in] sda I2C data line pin.
00113  *            Taken into account only on the very first call of one of the 'Instance' functions.
00114  *            A new DevI2C will be created based on parameters 'sda' and 'scl'.
00115  *            The used DevI2C object gets saved in instance variable dev_i2c.
00116  * @param[in] scl I2C clock line pin.
00117  *            Taken into account only on the very first call of one of the 'Instance' functions.
00118  *            A new DevI2C will be created based on parameters 'sda' and 'scl'.
00119  *            The used DevI2C object gets saved in instance variable dev_i2c.
00120  * @param[in] lsm6dso_int1 LSM6DSO INT1 pin.
00121  *            Taken into account only on the very first call of one of the 'Instance' functions.
00122  *            It maps the INT1 pin for LSM6DSO. Defaults to IKS01A3_PIN_LSM6DSO_INT1.
00123  * @param[in] lsm6dso_int2 LSM6DSO INT2 pin.
00124  *            Taken into account only on the very first call of one of the 'Instance' functions.
00125  *            It maps the INT2 pin for LSM6DSO. Defaults to IKS01A3_PIN_LSM6DSO_INT2.
00126  * @param[in] lis2dw12_int1 LIS2DW12 INT1 pin.
00127  *            Taken into account only on the very first call of one of the 'Instance' functions.
00128  *            It maps the INT1 pin for LIS2DW12. Defaults to IKS01A3_PIN_LIS2DW12_INT1.
00129  * @param[in] lps22hh_int LPS22HH INT pin.
00130  *            Taken into account only on the very first call of one of the 'Instance' functions.
00131  *            It maps the INT pin for LPS22HH. Defaults to IKS01A3_PIN_LPS22HH_INT.
00132  * @param[in] stts751_int STTS751 INT pin.
00133  *            Taken into account only on the very first call of one of the 'Instance' functions.
00134  *            It maps the INT pin for STTS751. Defaults to IKS01A3_PIN_STTS751_INT.
00135  */
00136 XNucleoIKS01A3 *XNucleoIKS01A3::instance(PinName sda, PinName scl, PinName lsm6dso_int1, PinName lsm6dso_int2, PinName lis2dw12_int1, PinName lps22hh_int, PinName stts751_int)
00137 {
00138     if (_instance == NULL) {
00139         DevI2C *ext_i2c = new DevI2C(sda, scl);
00140 
00141         if (ext_i2c != NULL) {
00142             _instance = new XNucleoIKS01A3(ext_i2c, lsm6dso_int1, lsm6dso_int2, lis2dw12_int1, lps22hh_int, stts751_int);
00143         }
00144     }
00145 
00146     return _instance;
00147 }