hw

Dependencies:   mbed LPS22HB LSM6DSL LSM303AGR HTS221

Committer:
b05901043
Date:
Thu Apr 23 08:11:36 2020 +0000
Revision:
2:efaeb347f9c7
Parent:
1:9fa494501f6f
enable sensors

Who changed what in which revision?

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