Test

Dependencies:   HTS221 LPS22HB LSM303AGR LSM6DSL

Fork of X_NUCLEO_IKS01A2 by ST

Committer:
davide.aliprandi@st.com
Date:
Tue Mar 14 13:41:32 2017 +0100
Revision:
6:671fd10a51b7
Child:
13:138a7a28bd21
Aligning to ARM mbed coding style.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
davide.aliprandi@st.com 6:671fd10a51b7 1 /**
davide.aliprandi@st.com 6:671fd10a51b7 2 ******************************************************************************
davide.aliprandi@st.com 6:671fd10a51b7 3 * @file XNucleoIKS01A2.cpp
davide.aliprandi@st.com 6:671fd10a51b7 4 * @author CLab
davide.aliprandi@st.com 6:671fd10a51b7 5 * @version V1.0.0
davide.aliprandi@st.com 6:671fd10a51b7 6 * @date 9-August-2016
davide.aliprandi@st.com 6:671fd10a51b7 7 * @brief Implementation file for the X_NUCLEO_IKS01A2 singleton class
davide.aliprandi@st.com 6:671fd10a51b7 8 ******************************************************************************
davide.aliprandi@st.com 6:671fd10a51b7 9 * @attention
davide.aliprandi@st.com 6:671fd10a51b7 10 *
davide.aliprandi@st.com 6:671fd10a51b7 11 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
davide.aliprandi@st.com 6:671fd10a51b7 12 *
davide.aliprandi@st.com 6:671fd10a51b7 13 * Redistribution and use in source and binary forms, with or without modification,
davide.aliprandi@st.com 6:671fd10a51b7 14 * are permitted provided that the following conditions are met:
davide.aliprandi@st.com 6:671fd10a51b7 15 * 1. Redistributions of source code must retain the above copyright notice,
davide.aliprandi@st.com 6:671fd10a51b7 16 * this list of conditions and the following disclaimer.
davide.aliprandi@st.com 6:671fd10a51b7 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
davide.aliprandi@st.com 6:671fd10a51b7 18 * this list of conditions and the following disclaimer in the documentation
davide.aliprandi@st.com 6:671fd10a51b7 19 * and/or other materials provided with the distribution.
davide.aliprandi@st.com 6:671fd10a51b7 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
davide.aliprandi@st.com 6:671fd10a51b7 21 * may be used to endorse or promote products derived from this software
davide.aliprandi@st.com 6:671fd10a51b7 22 * without specific prior written permission.
davide.aliprandi@st.com 6:671fd10a51b7 23 *
davide.aliprandi@st.com 6:671fd10a51b7 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
davide.aliprandi@st.com 6:671fd10a51b7 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
davide.aliprandi@st.com 6:671fd10a51b7 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
davide.aliprandi@st.com 6:671fd10a51b7 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
davide.aliprandi@st.com 6:671fd10a51b7 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
davide.aliprandi@st.com 6:671fd10a51b7 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
davide.aliprandi@st.com 6:671fd10a51b7 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
davide.aliprandi@st.com 6:671fd10a51b7 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
davide.aliprandi@st.com 6:671fd10a51b7 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
davide.aliprandi@st.com 6:671fd10a51b7 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
davide.aliprandi@st.com 6:671fd10a51b7 34 *
davide.aliprandi@st.com 6:671fd10a51b7 35 ******************************************************************************
davide.aliprandi@st.com 6:671fd10a51b7 36 */
davide.aliprandi@st.com 6:671fd10a51b7 37
davide.aliprandi@st.com 6:671fd10a51b7 38 /* Includes ------------------------------------------------------------------*/
davide.aliprandi@st.com 6:671fd10a51b7 39 #include "mbed.h"
davide.aliprandi@st.com 6:671fd10a51b7 40 #include "XNucleoIKS01A2.h"
davide.aliprandi@st.com 6:671fd10a51b7 41
davide.aliprandi@st.com 6:671fd10a51b7 42 /* Static variables ----------------------------------------------------------*/
davide.aliprandi@st.com 6:671fd10a51b7 43 XNucleoIKS01A2 *XNucleoIKS01A2::_instance = NULL;
davide.aliprandi@st.com 6:671fd10a51b7 44
davide.aliprandi@st.com 6:671fd10a51b7 45
davide.aliprandi@st.com 6:671fd10a51b7 46 /* Methods -------------------------------------------------------------------*/
davide.aliprandi@st.com 6:671fd10a51b7 47 /**
davide.aliprandi@st.com 6:671fd10a51b7 48 * @brief Constructor
davide.aliprandi@st.com 6:671fd10a51b7 49 */
davide.aliprandi@st.com 6:671fd10a51b7 50 XNucleoIKS01A2::XNucleoIKS01A2(DevI2C *ext_i2c, PinName int1, PinName int2) : dev_i2c(ext_i2c),
davide.aliprandi@st.com 6:671fd10a51b7 51 ht_sensor(new HTS221Sensor(*dev_i2c)),
davide.aliprandi@st.com 6:671fd10a51b7 52 magnetometer(new LSM303AGRMagSensor(*dev_i2c)),
davide.aliprandi@st.com 6:671fd10a51b7 53 accelerometer(new LSM303AGRAccSensor(*dev_i2c)),
davide.aliprandi@st.com 6:671fd10a51b7 54 pt_sensor(new LPS22HBSensor(*dev_i2c)),
davide.aliprandi@st.com 6:671fd10a51b7 55 acc_gyro(new LSM6DSLSensor(*dev_i2c, int1, int2))
davide.aliprandi@st.com 6:671fd10a51b7 56 {
davide.aliprandi@st.com 6:671fd10a51b7 57 ht_sensor->init(NULL);
davide.aliprandi@st.com 6:671fd10a51b7 58 magnetometer->init(NULL);
davide.aliprandi@st.com 6:671fd10a51b7 59 accelerometer->init(NULL);
davide.aliprandi@st.com 6:671fd10a51b7 60 pt_sensor->init(NULL);
davide.aliprandi@st.com 6:671fd10a51b7 61 acc_gyro->init(NULL);
davide.aliprandi@st.com 6:671fd10a51b7 62 }
davide.aliprandi@st.com 6:671fd10a51b7 63
davide.aliprandi@st.com 6:671fd10a51b7 64 /**
davide.aliprandi@st.com 6:671fd10a51b7 65 * @brief Get singleton instance
davide.aliprandi@st.com 6:671fd10a51b7 66 * @return a pointer to the initialized singleton instance of class XNucleoIKS01A2.
davide.aliprandi@st.com 6:671fd10a51b7 67 * A return value of NULL indicates an out of memory situation.
davide.aliprandi@st.com 6:671fd10a51b7 68 * @param[in] ext_i2c (optional) pointer to an instance of DevI2C to be used
davide.aliprandi@st.com 6:671fd10a51b7 69 * for communication on the expansion board.
davide.aliprandi@st.com 6:671fd10a51b7 70 * Defaults to NULL.
davide.aliprandi@st.com 6:671fd10a51b7 71 * Taken into account only on the very first call of one of the 'Instance' functions.
davide.aliprandi@st.com 6:671fd10a51b7 72 * If not provided a new DevI2C will be created with standard
davide.aliprandi@st.com 6:671fd10a51b7 73 * configuration parameters.
davide.aliprandi@st.com 6:671fd10a51b7 74 * The used DevI2C object gets saved in instance variable dev_i2c.
davide.aliprandi@st.com 6:671fd10a51b7 75 * @param[in] int1 LSM6DSL INT1 pin.
davide.aliprandi@st.com 6:671fd10a51b7 76 * Taken into account only on the very first call of one of the 'Instance' functions.
davide.aliprandi@st.com 6:671fd10a51b7 77 * It maps the INT1 pin for LSM6DSL. Defaults to IKS01A2_PIN_LSM6DSL_INT1.
davide.aliprandi@st.com 6:671fd10a51b7 78 * @param[in] int2 LSM6DSL INT1 pin.
davide.aliprandi@st.com 6:671fd10a51b7 79 * Taken into account only on the very first call of one of the 'Instance' functions.
davide.aliprandi@st.com 6:671fd10a51b7 80 * It maps the INT2 pin for LSM6DSL. Defaults to IKS01A2_PIN_LSM6DSL_INT2.
davide.aliprandi@st.com 6:671fd10a51b7 81 */
davide.aliprandi@st.com 6:671fd10a51b7 82 XNucleoIKS01A2 *XNucleoIKS01A2::instance(DevI2C *ext_i2c, PinName int1, PinName int2) {
davide.aliprandi@st.com 6:671fd10a51b7 83 if(_instance == NULL) {
davide.aliprandi@st.com 6:671fd10a51b7 84 if(ext_i2c == NULL)
davide.aliprandi@st.com 6:671fd10a51b7 85 ext_i2c = new DevI2C(IKS01A2_PIN_I2C_SDA, IKS01A2_PIN_I2C_SCL);
davide.aliprandi@st.com 6:671fd10a51b7 86
davide.aliprandi@st.com 6:671fd10a51b7 87 if(ext_i2c != NULL)
davide.aliprandi@st.com 6:671fd10a51b7 88 _instance = new XNucleoIKS01A2(ext_i2c, int1, int2);
davide.aliprandi@st.com 6:671fd10a51b7 89 }
davide.aliprandi@st.com 6:671fd10a51b7 90
davide.aliprandi@st.com 6:671fd10a51b7 91 return _instance;
davide.aliprandi@st.com 6:671fd10a51b7 92 }
davide.aliprandi@st.com 6:671fd10a51b7 93
davide.aliprandi@st.com 6:671fd10a51b7 94 /**
davide.aliprandi@st.com 6:671fd10a51b7 95 * @brief Get singleton instance
davide.aliprandi@st.com 6:671fd10a51b7 96 * @return a pointer to the initialized singleton instance of class X_NUCLEO_IKS01A1.
davide.aliprandi@st.com 6:671fd10a51b7 97 * A return value of NULL indicates an out of memory situation.
davide.aliprandi@st.com 6:671fd10a51b7 98 * @param[in] sda I2C data line pin.
davide.aliprandi@st.com 6:671fd10a51b7 99 * Taken into account only on the very first call of one of the 'Instance' functions.
davide.aliprandi@st.com 6:671fd10a51b7 100 * A new DevI2C will be created based on parameters 'sda' and 'scl'.
davide.aliprandi@st.com 6:671fd10a51b7 101 * The used DevI2C object gets saved in instance variable dev_i2c.
davide.aliprandi@st.com 6:671fd10a51b7 102 * @param[in] scl I2C clock line pin.
davide.aliprandi@st.com 6:671fd10a51b7 103 * Taken into account only on the very first call of one of the 'Instance' functions.
davide.aliprandi@st.com 6:671fd10a51b7 104 * A new DevI2C will be created based on parameters 'sda' and 'scl'.
davide.aliprandi@st.com 6:671fd10a51b7 105 * The used DevI2C object gets saved in instance variable dev_i2c.
davide.aliprandi@st.com 6:671fd10a51b7 106 * @param[in] int1 LSM6DSL INT1 pin.
davide.aliprandi@st.com 6:671fd10a51b7 107 * Taken into account only on the very first call of one of the 'Instance' functions.
davide.aliprandi@st.com 6:671fd10a51b7 108 * It maps the INT1 pin for LSM6DSL. Defaults to IKS01A2_PIN_LSM6DSL_INT1.
davide.aliprandi@st.com 6:671fd10a51b7 109 * @param[in] int2 LSM6DSL INT1 pin.
davide.aliprandi@st.com 6:671fd10a51b7 110 * Taken into account only on the very first call of one of the 'Instance' functions.
davide.aliprandi@st.com 6:671fd10a51b7 111 * It maps the INT2 pin for LSM6DSL. Defaults to IKS01A2_PIN_LSM6DSL_INT2.
davide.aliprandi@st.com 6:671fd10a51b7 112 */
davide.aliprandi@st.com 6:671fd10a51b7 113 XNucleoIKS01A2 *XNucleoIKS01A2::instance(PinName sda, PinName scl, PinName int1, PinName int2) {
davide.aliprandi@st.com 6:671fd10a51b7 114 if(_instance == NULL) {
davide.aliprandi@st.com 6:671fd10a51b7 115 DevI2C *ext_i2c = new DevI2C(sda, scl);
davide.aliprandi@st.com 6:671fd10a51b7 116
davide.aliprandi@st.com 6:671fd10a51b7 117 if(ext_i2c != NULL)
davide.aliprandi@st.com 6:671fd10a51b7 118 _instance = new XNucleoIKS01A2(ext_i2c, int1, int2);
davide.aliprandi@st.com 6:671fd10a51b7 119 }
davide.aliprandi@st.com 6:671fd10a51b7 120
davide.aliprandi@st.com 6:671fd10a51b7 121 return _instance;
davide.aliprandi@st.com 6:671fd10a51b7 122 }