Dependencies: X_NUCLEO_COMMON
Fork of X_NUCLEO_IKS01A1-f2df by
X_NUCLEO_IKS01A1-f255a2c75ecb/x_nucleo_iks01a1.cpp@1:7f97780b8ad4, 2017-02-09 (annotated)
- Committer:
- Salvatore94
- Date:
- Thu Feb 09 16:40:33 2017 +0000
- Revision:
- 1:7f97780b8ad4
- Parent:
- 0:5a49275457c6
Per peppe;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
antseggs | 0:5a49275457c6 | 1 | /** |
antseggs | 0:5a49275457c6 | 2 | ****************************************************************************** |
antseggs | 0:5a49275457c6 | 3 | * @file x_nucleo_iks01a1.cpp |
antseggs | 0:5a49275457c6 | 4 | * @author AST / EST |
antseggs | 0:5a49275457c6 | 5 | * @version V0.0.1 |
antseggs | 0:5a49275457c6 | 6 | * @date 08-October-2014 |
antseggs | 0:5a49275457c6 | 7 | * @brief Implementation file for the X_NUCLEO_IKS01A1 singleton class |
antseggs | 0:5a49275457c6 | 8 | ****************************************************************************** |
antseggs | 0:5a49275457c6 | 9 | * @attention |
antseggs | 0:5a49275457c6 | 10 | * |
antseggs | 0:5a49275457c6 | 11 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
antseggs | 0:5a49275457c6 | 12 | * |
antseggs | 0:5a49275457c6 | 13 | * Redistribution and use in source and binary forms, with or without modification, |
antseggs | 0:5a49275457c6 | 14 | * are permitted provided that the following conditions are met: |
antseggs | 0:5a49275457c6 | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
antseggs | 0:5a49275457c6 | 16 | * this list of conditions and the following disclaimer. |
antseggs | 0:5a49275457c6 | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
antseggs | 0:5a49275457c6 | 18 | * this list of conditions and the following disclaimer in the documentation |
antseggs | 0:5a49275457c6 | 19 | * and/or other materials provided with the distribution. |
antseggs | 0:5a49275457c6 | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
antseggs | 0:5a49275457c6 | 21 | * may be used to endorse or promote products derived from this software |
antseggs | 0:5a49275457c6 | 22 | * without specific prior written permission. |
antseggs | 0:5a49275457c6 | 23 | * |
antseggs | 0:5a49275457c6 | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
antseggs | 0:5a49275457c6 | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
antseggs | 0:5a49275457c6 | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
antseggs | 0:5a49275457c6 | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
antseggs | 0:5a49275457c6 | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
antseggs | 0:5a49275457c6 | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
antseggs | 0:5a49275457c6 | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
antseggs | 0:5a49275457c6 | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
antseggs | 0:5a49275457c6 | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
antseggs | 0:5a49275457c6 | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
antseggs | 0:5a49275457c6 | 34 | * |
antseggs | 0:5a49275457c6 | 35 | ****************************************************************************** |
antseggs | 0:5a49275457c6 | 36 | */ |
antseggs | 0:5a49275457c6 | 37 | |
antseggs | 0:5a49275457c6 | 38 | /* Includes ------------------------------------------------------------------*/ |
antseggs | 0:5a49275457c6 | 39 | #include "mbed.h" |
antseggs | 0:5a49275457c6 | 40 | #include "x_nucleo_iks01a1.h" |
antseggs | 0:5a49275457c6 | 41 | |
antseggs | 0:5a49275457c6 | 42 | /* Static variables ----------------------------------------------------------*/ |
antseggs | 0:5a49275457c6 | 43 | X_NUCLEO_IKS01A1* X_NUCLEO_IKS01A1::_instance = NULL; |
antseggs | 0:5a49275457c6 | 44 | |
antseggs | 0:5a49275457c6 | 45 | |
antseggs | 0:5a49275457c6 | 46 | /* Methods -------------------------------------------------------------------*/ |
antseggs | 0:5a49275457c6 | 47 | /** |
antseggs | 0:5a49275457c6 | 48 | * @brief Constructor |
antseggs | 0:5a49275457c6 | 49 | */ |
antseggs | 0:5a49275457c6 | 50 | X_NUCLEO_IKS01A1::X_NUCLEO_IKS01A1(DevI2C *ext_i2c, PinName ff_irq_pin) : dev_i2c(ext_i2c), |
antseggs | 0:5a49275457c6 | 51 | ht_sensor(new HTS221(*dev_i2c)), |
antseggs | 0:5a49275457c6 | 52 | magnetometer(new LIS3MDL(*dev_i2c)), |
antseggs | 0:5a49275457c6 | 53 | pt_sensor(new LPS25H(*dev_i2c)), |
antseggs | 0:5a49275457c6 | 54 | gyro_lsm6ds0(new LSM6DS0(*dev_i2c)) |
antseggs | 0:5a49275457c6 | 55 | { |
antseggs | 0:5a49275457c6 | 56 | if(ff_irq_pin == NC) { |
antseggs | 0:5a49275457c6 | 57 | gyro_lsm6ds3 = NULL; |
antseggs | 0:5a49275457c6 | 58 | } else { |
antseggs | 0:5a49275457c6 | 59 | gyro_lsm6ds3 = new LSM6DS3(*dev_i2c, ff_irq_pin); |
antseggs | 0:5a49275457c6 | 60 | } |
antseggs | 0:5a49275457c6 | 61 | } |
antseggs | 0:5a49275457c6 | 62 | |
antseggs | 0:5a49275457c6 | 63 | /** |
antseggs | 0:5a49275457c6 | 64 | * @brief Get singleton instance |
antseggs | 0:5a49275457c6 | 65 | * @return a pointer to the initialized singleton instance of class X_NUCLEO_IKS01A1. |
antseggs | 0:5a49275457c6 | 66 | * A return value of NULL indicates an out of memory situation. |
antseggs | 0:5a49275457c6 | 67 | * @param[in] ext_i2c (optional) pointer to an instance of DevI2C to be used |
antseggs | 0:5a49275457c6 | 68 | * for communication on the expansion board. |
antseggs | 0:5a49275457c6 | 69 | * Defaults to NULL. |
antseggs | 0:5a49275457c6 | 70 | * Taken into account only on the very first call of one of the 'Instance' functions. |
antseggs | 0:5a49275457c6 | 71 | * If not provided a new DevI2C will be created with standard |
antseggs | 0:5a49275457c6 | 72 | * configuration parameters. |
antseggs | 0:5a49275457c6 | 73 | * The used DevI2C object gets saved in instance variable dev_i2c. |
antseggs | 0:5a49275457c6 | 74 | * @param[in] ff_irq_pin (optional) PinName of the pin associated to asynchronous |
antseggs | 0:5a49275457c6 | 75 | * (i.e. interrupt based) free fall detection in case a LSM6DS3 3D |
antseggs | 0:5a49275457c6 | 76 | * Acceleromenter and 3D Gyroscope is mounted on top of the DIL 24-pin socket. |
antseggs | 0:5a49275457c6 | 77 | * Defaults to IKS01A1_PIN_FF. |
antseggs | 0:5a49275457c6 | 78 | * Taken into account only on the very first call of one of the 'Instance' functions. |
antseggs | 0:5a49275457c6 | 79 | * A value of 'NC' will avoid instantiation of the LSM6DS3 even if present. |
antseggs | 0:5a49275457c6 | 80 | */ |
antseggs | 0:5a49275457c6 | 81 | X_NUCLEO_IKS01A1* X_NUCLEO_IKS01A1::Instance(DevI2C *ext_i2c, PinName ff_irq_pin) { |
antseggs | 0:5a49275457c6 | 82 | if(_instance == NULL) { |
antseggs | 0:5a49275457c6 | 83 | if(ext_i2c == NULL) |
antseggs | 0:5a49275457c6 | 84 | ext_i2c = new DevI2C(IKS01A1_PIN_I2C_SDA, IKS01A1_PIN_I2C_SCL); |
antseggs | 0:5a49275457c6 | 85 | |
antseggs | 0:5a49275457c6 | 86 | if(ext_i2c != NULL) |
antseggs | 0:5a49275457c6 | 87 | _instance = new X_NUCLEO_IKS01A1(ext_i2c, ff_irq_pin); |
antseggs | 0:5a49275457c6 | 88 | |
antseggs | 0:5a49275457c6 | 89 | if(_instance != NULL) { |
antseggs | 0:5a49275457c6 | 90 | bool ret = _instance->Init(); |
antseggs | 0:5a49275457c6 | 91 | if(!ret) { |
antseggs | 0:5a49275457c6 | 92 | error("Failed to init X_NUCLEO_IKS01A1 expansion board!\n"); |
antseggs | 0:5a49275457c6 | 93 | } |
antseggs | 0:5a49275457c6 | 94 | } |
antseggs | 0:5a49275457c6 | 95 | } |
antseggs | 0:5a49275457c6 | 96 | |
antseggs | 0:5a49275457c6 | 97 | return _instance; |
antseggs | 0:5a49275457c6 | 98 | } |
antseggs | 0:5a49275457c6 | 99 | |
antseggs | 0:5a49275457c6 | 100 | /** |
antseggs | 0:5a49275457c6 | 101 | * @brief Get singleton instance |
antseggs | 0:5a49275457c6 | 102 | * @return a pointer to the initialized singleton instance of class X_NUCLEO_IKS01A1. |
antseggs | 0:5a49275457c6 | 103 | * A return value of NULL indicates an out of memory situation. |
antseggs | 0:5a49275457c6 | 104 | * @param[in] sda I2C data line pin. |
antseggs | 0:5a49275457c6 | 105 | * Taken into account only on the very first call of one of the 'Instance' functions. |
antseggs | 0:5a49275457c6 | 106 | * A new DevI2C will be created based on parameters 'sda' and 'scl'. |
antseggs | 0:5a49275457c6 | 107 | * The used DevI2C object gets saved in instance variable dev_i2c. |
antseggs | 0:5a49275457c6 | 108 | * @param[in] scl I2C clock line pin. |
antseggs | 0:5a49275457c6 | 109 | * Taken into account only on the very first call of one of the 'Instance' functions. |
antseggs | 0:5a49275457c6 | 110 | * A new DevI2C will be created based on parameters 'sda' and 'scl'. |
antseggs | 0:5a49275457c6 | 111 | * The used DevI2C object gets saved in instance variable dev_i2c. |
antseggs | 0:5a49275457c6 | 112 | * @param[in] ff_irq_pin (optional) PinName of the pin associated to asynchronous |
antseggs | 0:5a49275457c6 | 113 | * (i.e. interrupt based) free fall detection in case a LSM6DS3 3D |
antseggs | 0:5a49275457c6 | 114 | * Acceleromenter and 3D Gyroscope is mounted on top of the DIL 24-pin socket. |
antseggs | 0:5a49275457c6 | 115 | * Defaults to NC. |
antseggs | 0:5a49275457c6 | 116 | * Taken into account only on the very first call of one of the 'Instance' functions. |
antseggs | 0:5a49275457c6 | 117 | * A value of 'NC' will avoid instantiation of the LSM6DS3 even if present. |
antseggs | 0:5a49275457c6 | 118 | */ |
antseggs | 0:5a49275457c6 | 119 | X_NUCLEO_IKS01A1* X_NUCLEO_IKS01A1::Instance(PinName sda, PinName scl, PinName ff_irq_pin) { |
antseggs | 0:5a49275457c6 | 120 | if(_instance == NULL) { |
antseggs | 0:5a49275457c6 | 121 | DevI2C *ext_i2c = new DevI2C(sda, scl); |
antseggs | 0:5a49275457c6 | 122 | |
antseggs | 0:5a49275457c6 | 123 | if(ext_i2c != NULL) |
antseggs | 0:5a49275457c6 | 124 | _instance = new X_NUCLEO_IKS01A1(ext_i2c, ff_irq_pin); |
antseggs | 0:5a49275457c6 | 125 | |
antseggs | 0:5a49275457c6 | 126 | if(_instance != NULL) { |
antseggs | 0:5a49275457c6 | 127 | bool ret = _instance->Init(); |
antseggs | 0:5a49275457c6 | 128 | if(!ret) { |
antseggs | 0:5a49275457c6 | 129 | error("Failed to init X_NUCLEO_IKS01A1 expansion board!\n"); |
antseggs | 0:5a49275457c6 | 130 | } |
antseggs | 0:5a49275457c6 | 131 | } |
antseggs | 0:5a49275457c6 | 132 | } |
antseggs | 0:5a49275457c6 | 133 | |
antseggs | 0:5a49275457c6 | 134 | return _instance; |
antseggs | 0:5a49275457c6 | 135 | } |
antseggs | 0:5a49275457c6 | 136 | |
antseggs | 0:5a49275457c6 | 137 | /** |
antseggs | 0:5a49275457c6 | 138 | * @brief Initialize the singleton's HT sensor |
antseggs | 0:5a49275457c6 | 139 | * @retval true if initialization successful, |
antseggs | 0:5a49275457c6 | 140 | * @retval false otherwise |
antseggs | 0:5a49275457c6 | 141 | */ |
antseggs | 0:5a49275457c6 | 142 | bool X_NUCLEO_IKS01A1::Init_HTS221(void) { |
antseggs | 0:5a49275457c6 | 143 | uint8_t ht_id = 0; |
antseggs | 0:5a49275457c6 | 144 | HUM_TEMP_InitTypeDef InitStructure; |
antseggs | 0:5a49275457c6 | 145 | |
antseggs | 0:5a49275457c6 | 146 | /* Check presence */ |
antseggs | 0:5a49275457c6 | 147 | if((ht_sensor->ReadID(&ht_id) != HUM_TEMP_OK) || |
antseggs | 0:5a49275457c6 | 148 | (ht_id != I_AM_HTS221)) |
antseggs | 0:5a49275457c6 | 149 | { |
antseggs | 0:5a49275457c6 | 150 | delete ht_sensor; |
antseggs | 0:5a49275457c6 | 151 | ht_sensor = NULL; |
antseggs | 0:5a49275457c6 | 152 | return true; |
antseggs | 0:5a49275457c6 | 153 | } |
antseggs | 0:5a49275457c6 | 154 | |
antseggs | 0:5a49275457c6 | 155 | /* Configure sensor */ |
antseggs | 0:5a49275457c6 | 156 | InitStructure.OutputDataRate = HTS221_ODR_12_5Hz; |
antseggs | 0:5a49275457c6 | 157 | |
antseggs | 0:5a49275457c6 | 158 | if(ht_sensor->Init(&InitStructure) != HUM_TEMP_OK) |
antseggs | 0:5a49275457c6 | 159 | { |
antseggs | 0:5a49275457c6 | 160 | return false; |
antseggs | 0:5a49275457c6 | 161 | } |
antseggs | 0:5a49275457c6 | 162 | |
antseggs | 0:5a49275457c6 | 163 | return true; |
antseggs | 0:5a49275457c6 | 164 | } |
antseggs | 0:5a49275457c6 | 165 | |
antseggs | 0:5a49275457c6 | 166 | /** |
antseggs | 0:5a49275457c6 | 167 | * @brief Initialize the singleton's magnetometer |
antseggs | 0:5a49275457c6 | 168 | * @retval true if initialization successful, |
antseggs | 0:5a49275457c6 | 169 | * @retval false otherwise |
antseggs | 0:5a49275457c6 | 170 | */ |
antseggs | 0:5a49275457c6 | 171 | bool X_NUCLEO_IKS01A1::Init_LIS3MDL(void) { |
antseggs | 0:5a49275457c6 | 172 | uint8_t m_id = 0; |
antseggs | 0:5a49275457c6 | 173 | MAGNETO_InitTypeDef InitStructure; |
antseggs | 0:5a49275457c6 | 174 | |
antseggs | 0:5a49275457c6 | 175 | /* Check presence */ |
antseggs | 0:5a49275457c6 | 176 | if((magnetometer->ReadID(&m_id) != MAGNETO_OK) || |
antseggs | 0:5a49275457c6 | 177 | (m_id != I_AM_LIS3MDL_M)) |
antseggs | 0:5a49275457c6 | 178 | { |
antseggs | 0:5a49275457c6 | 179 | delete magnetometer; |
antseggs | 0:5a49275457c6 | 180 | magnetometer = NULL; |
antseggs | 0:5a49275457c6 | 181 | return true; |
antseggs | 0:5a49275457c6 | 182 | } |
antseggs | 0:5a49275457c6 | 183 | |
antseggs | 0:5a49275457c6 | 184 | /* Configure sensor */ |
antseggs | 0:5a49275457c6 | 185 | InitStructure.M_FullScale = LIS3MDL_M_FS_4; |
antseggs | 0:5a49275457c6 | 186 | InitStructure.M_OperatingMode = LIS3MDL_M_MD_CONTINUOUS; |
antseggs | 0:5a49275457c6 | 187 | InitStructure.M_XYOperativeMode = LIS3MDL_M_OM_HP; |
antseggs | 0:5a49275457c6 | 188 | InitStructure.M_OutputDataRate = LIS3MDL_M_DO_80; |
antseggs | 0:5a49275457c6 | 189 | |
antseggs | 0:5a49275457c6 | 190 | if(magnetometer->Init(&InitStructure) != MAGNETO_OK) |
antseggs | 0:5a49275457c6 | 191 | { |
antseggs | 0:5a49275457c6 | 192 | return false; |
antseggs | 0:5a49275457c6 | 193 | } |
antseggs | 0:5a49275457c6 | 194 | |
antseggs | 0:5a49275457c6 | 195 | return true; |
antseggs | 0:5a49275457c6 | 196 | } |
antseggs | 0:5a49275457c6 | 197 | |
antseggs | 0:5a49275457c6 | 198 | /** |
antseggs | 0:5a49275457c6 | 199 | * @brief Initialize the singleton's pressure sensor |
antseggs | 0:5a49275457c6 | 200 | * @retval true if initialization successful, |
antseggs | 0:5a49275457c6 | 201 | * @retval false otherwise |
antseggs | 0:5a49275457c6 | 202 | */ |
antseggs | 0:5a49275457c6 | 203 | bool X_NUCLEO_IKS01A1::Init_LPS25H(void) { |
antseggs | 0:5a49275457c6 | 204 | uint8_t p_id = 0; |
antseggs | 0:5a49275457c6 | 205 | PRESSURE_InitTypeDef InitStructure; |
antseggs | 0:5a49275457c6 | 206 | |
antseggs | 0:5a49275457c6 | 207 | /* Check presence */ |
antseggs | 0:5a49275457c6 | 208 | if((pt_sensor->ReadID(&p_id) != PRESSURE_OK) || |
antseggs | 0:5a49275457c6 | 209 | (p_id != I_AM_LPS25H)) |
antseggs | 0:5a49275457c6 | 210 | { |
antseggs | 0:5a49275457c6 | 211 | delete pt_sensor; |
antseggs | 0:5a49275457c6 | 212 | pt_sensor = NULL; |
antseggs | 0:5a49275457c6 | 213 | return true; |
antseggs | 0:5a49275457c6 | 214 | } |
antseggs | 0:5a49275457c6 | 215 | |
antseggs | 0:5a49275457c6 | 216 | /* Configure sensor */ |
antseggs | 0:5a49275457c6 | 217 | InitStructure.OutputDataRate = LPS25H_ODR_1Hz; |
antseggs | 0:5a49275457c6 | 218 | InitStructure.BlockDataUpdate = LPS25H_BDU_CONT; |
antseggs | 0:5a49275457c6 | 219 | InitStructure.DiffEnable = LPS25H_DIFF_ENABLE; |
antseggs | 0:5a49275457c6 | 220 | InitStructure.SPIMode = LPS25H_SPI_SIM_3W; |
antseggs | 0:5a49275457c6 | 221 | InitStructure.PressureResolution = LPS25H_P_RES_AVG_32; |
antseggs | 0:5a49275457c6 | 222 | InitStructure.TemperatureResolution = LPS25H_T_RES_AVG_16; |
antseggs | 0:5a49275457c6 | 223 | |
antseggs | 0:5a49275457c6 | 224 | if(pt_sensor->Init(&InitStructure) != PRESSURE_OK) |
antseggs | 0:5a49275457c6 | 225 | { |
antseggs | 0:5a49275457c6 | 226 | return false; |
antseggs | 0:5a49275457c6 | 227 | } |
antseggs | 0:5a49275457c6 | 228 | |
antseggs | 0:5a49275457c6 | 229 | return true; |
antseggs | 0:5a49275457c6 | 230 | } |
antseggs | 0:5a49275457c6 | 231 | |
antseggs | 0:5a49275457c6 | 232 | /** |
antseggs | 0:5a49275457c6 | 233 | * @brief Initialize the singleton's LSM6DS0 gyroscope |
antseggs | 0:5a49275457c6 | 234 | * @retval true if initialization successful, |
antseggs | 0:5a49275457c6 | 235 | * @retval false otherwise |
antseggs | 0:5a49275457c6 | 236 | */ |
antseggs | 0:5a49275457c6 | 237 | bool X_NUCLEO_IKS01A1::Init_LSM6DS0(void) { |
antseggs | 0:5a49275457c6 | 238 | IMU_6AXES_InitTypeDef InitStructure; |
antseggs | 0:5a49275457c6 | 239 | uint8_t xg_id = 0; |
antseggs | 0:5a49275457c6 | 240 | |
antseggs | 0:5a49275457c6 | 241 | /* Check presence */ |
antseggs | 0:5a49275457c6 | 242 | if((gyro_lsm6ds3 != NULL) || // by default do not instantiate two gyroscopes |
antseggs | 0:5a49275457c6 | 243 | (gyro_lsm6ds0->ReadID(&xg_id) != IMU_6AXES_OK) || |
antseggs | 0:5a49275457c6 | 244 | (xg_id != I_AM_LSM6DS0_XG)) |
antseggs | 0:5a49275457c6 | 245 | { |
antseggs | 0:5a49275457c6 | 246 | delete gyro_lsm6ds0; |
antseggs | 0:5a49275457c6 | 247 | gyro_lsm6ds0 = NULL; |
antseggs | 0:5a49275457c6 | 248 | return true; |
antseggs | 0:5a49275457c6 | 249 | } |
antseggs | 0:5a49275457c6 | 250 | |
antseggs | 0:5a49275457c6 | 251 | /* Configure sensor */ |
antseggs | 0:5a49275457c6 | 252 | InitStructure.G_FullScale = 2000.0f; /* 2000DPS */ |
antseggs | 0:5a49275457c6 | 253 | InitStructure.G_OutputDataRate = 119.0f; /* 119HZ */ |
antseggs | 0:5a49275457c6 | 254 | InitStructure.G_X_Axis = 1; /* Enable */ |
antseggs | 0:5a49275457c6 | 255 | InitStructure.G_Y_Axis = 1; /* Enable */ |
antseggs | 0:5a49275457c6 | 256 | InitStructure.G_Z_Axis = 1; /* Enable */ |
antseggs | 0:5a49275457c6 | 257 | |
antseggs | 0:5a49275457c6 | 258 | InitStructure.X_FullScale = 2.0f; /* 2G */ |
antseggs | 0:5a49275457c6 | 259 | InitStructure.X_OutputDataRate = 119.0f; /* 119HZ */ |
antseggs | 0:5a49275457c6 | 260 | InitStructure.X_X_Axis = 1; /* Enable */ |
antseggs | 0:5a49275457c6 | 261 | InitStructure.X_Y_Axis = 1; /* Enable */ |
antseggs | 0:5a49275457c6 | 262 | InitStructure.X_Z_Axis = 1; /* Enable */ |
antseggs | 0:5a49275457c6 | 263 | |
antseggs | 0:5a49275457c6 | 264 | if(gyro_lsm6ds0->Init(&InitStructure) != IMU_6AXES_OK) |
antseggs | 0:5a49275457c6 | 265 | { |
antseggs | 0:5a49275457c6 | 266 | return false; |
antseggs | 0:5a49275457c6 | 267 | } |
antseggs | 0:5a49275457c6 | 268 | |
antseggs | 0:5a49275457c6 | 269 | return true; |
antseggs | 0:5a49275457c6 | 270 | } |
antseggs | 0:5a49275457c6 | 271 | |
antseggs | 0:5a49275457c6 | 272 | /** |
antseggs | 0:5a49275457c6 | 273 | * @brief Initialize the singleton's LSMDS3 gyroscope |
antseggs | 0:5a49275457c6 | 274 | * @retval true if initialization successful, |
antseggs | 0:5a49275457c6 | 275 | * @retval false otherwise |
antseggs | 0:5a49275457c6 | 276 | */ |
antseggs | 0:5a49275457c6 | 277 | bool X_NUCLEO_IKS01A1::Init_LSM6DS3(void) { |
antseggs | 0:5a49275457c6 | 278 | IMU_6AXES_InitTypeDef InitStructure; |
antseggs | 0:5a49275457c6 | 279 | uint8_t xg_id = 0; |
antseggs | 0:5a49275457c6 | 280 | |
antseggs | 0:5a49275457c6 | 281 | /* Check presence */ |
antseggs | 0:5a49275457c6 | 282 | if(gyro_lsm6ds3 == NULL) return true; |
antseggs | 0:5a49275457c6 | 283 | |
antseggs | 0:5a49275457c6 | 284 | if((gyro_lsm6ds3->ReadID(&xg_id) != IMU_6AXES_OK) || |
antseggs | 0:5a49275457c6 | 285 | (xg_id != I_AM_LSM6DS3_XG)) |
antseggs | 0:5a49275457c6 | 286 | { |
antseggs | 0:5a49275457c6 | 287 | delete gyro_lsm6ds3; |
antseggs | 0:5a49275457c6 | 288 | gyro_lsm6ds3 = NULL; |
antseggs | 0:5a49275457c6 | 289 | return true; |
antseggs | 0:5a49275457c6 | 290 | } |
antseggs | 0:5a49275457c6 | 291 | |
antseggs | 0:5a49275457c6 | 292 | /* Configure sensor */ |
antseggs | 0:5a49275457c6 | 293 | InitStructure.G_FullScale = 2000.0f; /* 2000DPS */ |
antseggs | 0:5a49275457c6 | 294 | InitStructure.G_OutputDataRate = 104.0f; /* 104HZ */ |
antseggs | 0:5a49275457c6 | 295 | InitStructure.G_X_Axis = 1; /* Enable */ |
antseggs | 0:5a49275457c6 | 296 | InitStructure.G_Y_Axis = 1; /* Enable */ |
antseggs | 0:5a49275457c6 | 297 | InitStructure.G_Z_Axis = 1; /* Enable */ |
antseggs | 0:5a49275457c6 | 298 | |
antseggs | 0:5a49275457c6 | 299 | InitStructure.X_FullScale = 2.0f; /* 2G */ |
antseggs | 0:5a49275457c6 | 300 | InitStructure.X_OutputDataRate = 104.0f; /* 104HZ */ |
antseggs | 0:5a49275457c6 | 301 | InitStructure.X_X_Axis = 1; /* Enable */ |
antseggs | 0:5a49275457c6 | 302 | InitStructure.X_Y_Axis = 1; /* Enable */ |
antseggs | 0:5a49275457c6 | 303 | InitStructure.X_Z_Axis = 1; /* Enable */ |
antseggs | 0:5a49275457c6 | 304 | |
antseggs | 0:5a49275457c6 | 305 | if(gyro_lsm6ds3->Init(&InitStructure) != IMU_6AXES_OK) |
antseggs | 0:5a49275457c6 | 306 | { |
antseggs | 0:5a49275457c6 | 307 | return false; |
antseggs | 0:5a49275457c6 | 308 | } |
antseggs | 0:5a49275457c6 | 309 | |
antseggs | 0:5a49275457c6 | 310 | return true; |
antseggs | 0:5a49275457c6 | 311 | } |