iNEMO inertial module: 3D accelerometer and 3D gyroscope.

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   HelloWorld_ST_Sensors MOTENV_Mbed mbed-os-mqtt-client LSM6DSL_JS ... more

Committer:
cparata
Date:
Tue Feb 08 08:27:15 2022 +0000
Revision:
9:fad44d0eacd4
Parent:
8:9a1017389cc7
Fix typo on MBED_MAJOR_VERSION

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nikapov 0:704c89673b57 1 /**
nikapov 0:704c89673b57 2 ******************************************************************************
nikapov 0:704c89673b57 3 * @file LSM6DSLSensor.cpp
nikapov 0:704c89673b57 4 * @author CLab
nikapov 0:704c89673b57 5 * @version V1.0.0
nikapov 0:704c89673b57 6 * @date 5 August 2016
nikapov 0:704c89673b57 7 * @brief Implementation of an LSM6DSL Inertial Measurement Unit (IMU) 6 axes
nikapov 0:704c89673b57 8 * sensor.
nikapov 0:704c89673b57 9 ******************************************************************************
nikapov 0:704c89673b57 10 * @attention
nikapov 0:704c89673b57 11 *
nikapov 0:704c89673b57 12 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
nikapov 0:704c89673b57 13 *
nikapov 0:704c89673b57 14 * Redistribution and use in source and binary forms, with or without modification,
nikapov 0:704c89673b57 15 * are permitted provided that the following conditions are met:
nikapov 0:704c89673b57 16 * 1. Redistributions of source code must retain the above copyright notice,
nikapov 0:704c89673b57 17 * this list of conditions and the following disclaimer.
nikapov 0:704c89673b57 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
nikapov 0:704c89673b57 19 * this list of conditions and the following disclaimer in the documentation
nikapov 0:704c89673b57 20 * and/or other materials provided with the distribution.
nikapov 0:704c89673b57 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
nikapov 0:704c89673b57 22 * may be used to endorse or promote products derived from this software
nikapov 0:704c89673b57 23 * without specific prior written permission.
nikapov 0:704c89673b57 24 *
nikapov 0:704c89673b57 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
nikapov 0:704c89673b57 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
nikapov 0:704c89673b57 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
nikapov 0:704c89673b57 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
nikapov 0:704c89673b57 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
nikapov 0:704c89673b57 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
nikapov 0:704c89673b57 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
nikapov 0:704c89673b57 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
nikapov 0:704c89673b57 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
nikapov 0:704c89673b57 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
nikapov 0:704c89673b57 35 *
nikapov 0:704c89673b57 36 ******************************************************************************
nikapov 0:704c89673b57 37 */
nikapov 0:704c89673b57 38
nikapov 0:704c89673b57 39
nikapov 0:704c89673b57 40 /* Includes ------------------------------------------------------------------*/
nikapov 0:704c89673b57 41
nikapov 0:704c89673b57 42 #include "LSM6DSLSensor.h"
nikapov 0:704c89673b57 43
nikapov 0:704c89673b57 44 /* Class Implementation ------------------------------------------------------*/
nikapov 0:704c89673b57 45
mapellil 2:578a45c4dad5 46 LSM6DSLSensor::LSM6DSLSensor(SPI *spi, PinName cs_pin, PinName int1_pin, PinName int2_pin, SPI_type_t spi_type ) :
mapellil 2:578a45c4dad5 47 _dev_spi(spi), _cs_pin(cs_pin), _int1_irq(int1_pin), _int2_irq(int2_pin), _spi_type(spi_type)
mapellil 2:578a45c4dad5 48 {
mapellil 2:578a45c4dad5 49 assert (spi);
mapellil 2:578a45c4dad5 50 if (cs_pin == NC)
mapellil 2:578a45c4dad5 51 {
mapellil 2:578a45c4dad5 52 printf ("ERROR LPS22HBSensor CS MUST NOT BE NC\n\r");
mapellil 2:578a45c4dad5 53 _dev_spi = NULL;
mapellil 2:578a45c4dad5 54 _dev_i2c=NULL;
mapellil 2:578a45c4dad5 55 return;
mapellil 2:578a45c4dad5 56 }
mapellil 2:578a45c4dad5 57 _cs_pin = 1;
mapellil 2:578a45c4dad5 58 _dev_i2c=NULL;
mapellil 2:578a45c4dad5 59
mapellil 2:578a45c4dad5 60 if (_spi_type == SPI3W) LSM6DSL_ACC_GYRO_W_SPI_Mode((void *)this, LSM6DSL_ACC_GYRO_SIM_3_WIRE);
mapellil 2:578a45c4dad5 61 else LSM6DSL_ACC_GYRO_W_SPI_Mode((void *)this, LSM6DSL_ACC_GYRO_SIM_4_WIRE);
mapellil 2:578a45c4dad5 62
mapellil 2:578a45c4dad5 63 LSM6DSL_ACC_GYRO_W_I2C_MASTER_Enable((void *)this, LSM6DSL_ACC_GYRO_MASTER_ON_DISABLED);
mapellil 2:578a45c4dad5 64 }
mapellil 2:578a45c4dad5 65
nikapov 0:704c89673b57 66 /** Constructor
nikapov 0:704c89673b57 67 * @param i2c object of an helper class which handles the I2C peripheral
nikapov 0:704c89673b57 68 * @param address the address of the component's instance
nikapov 0:704c89673b57 69 */
mapellil 1:c583f32fe272 70 LSM6DSLSensor::LSM6DSLSensor(DevI2C *i2c, uint8_t address, PinName int1_pin, PinName int2_pin) :
mapellil 1:c583f32fe272 71 _dev_i2c(i2c), _address(address), _cs_pin(NC), _int1_irq(int1_pin), _int2_irq(int2_pin)
nikapov 0:704c89673b57 72 {
mapellil 1:c583f32fe272 73 assert (i2c);
mapellil 2:578a45c4dad5 74 _dev_spi = NULL;
mapellil 2:578a45c4dad5 75 }
nikapov 0:704c89673b57 76
nikapov 0:704c89673b57 77 /**
nikapov 0:704c89673b57 78 * @brief Initializing the component.
nikapov 0:704c89673b57 79 * @param[in] init pointer to device specific initalization structure.
nikapov 0:704c89673b57 80 * @retval "0" in case of success, an error code otherwise.
nikapov 0:704c89673b57 81 */
nikapov 0:704c89673b57 82 int LSM6DSLSensor::init(void *init)
nikapov 0:704c89673b57 83 {
nikapov 0:704c89673b57 84 /* Enable register address automatically incremented during a multiple byte
nikapov 0:704c89673b57 85 access with a serial interface. */
nikapov 0:704c89673b57 86 if ( LSM6DSL_ACC_GYRO_W_IF_Addr_Incr( (void *)this, LSM6DSL_ACC_GYRO_IF_INC_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 87 {
nikapov 0:704c89673b57 88 return 1;
nikapov 0:704c89673b57 89 }
nikapov 0:704c89673b57 90
nikapov 0:704c89673b57 91 /* Enable BDU */
nikapov 0:704c89673b57 92 if ( LSM6DSL_ACC_GYRO_W_BDU( (void *)this, LSM6DSL_ACC_GYRO_BDU_BLOCK_UPDATE ) == MEMS_ERROR )
nikapov 0:704c89673b57 93 {
nikapov 0:704c89673b57 94 return 1;
nikapov 0:704c89673b57 95 }
nikapov 0:704c89673b57 96
nikapov 0:704c89673b57 97 /* FIFO mode selection */
nikapov 0:704c89673b57 98 if ( LSM6DSL_ACC_GYRO_W_FIFO_MODE( (void *)this, LSM6DSL_ACC_GYRO_FIFO_MODE_BYPASS ) == MEMS_ERROR )
nikapov 0:704c89673b57 99 {
nikapov 0:704c89673b57 100 return 1;
nikapov 0:704c89673b57 101 }
nikapov 0:704c89673b57 102
nikapov 0:704c89673b57 103 /* Output data rate selection - power down. */
nikapov 0:704c89673b57 104 if ( LSM6DSL_ACC_GYRO_W_ODR_XL( (void *)this, LSM6DSL_ACC_GYRO_ODR_XL_POWER_DOWN ) == MEMS_ERROR )
nikapov 0:704c89673b57 105 {
nikapov 0:704c89673b57 106 return 1;
nikapov 0:704c89673b57 107 }
nikapov 0:704c89673b57 108
nikapov 0:704c89673b57 109 /* Full scale selection. */
nikapov 0:704c89673b57 110 if ( set_x_fs( 2.0f ) == 1 )
nikapov 0:704c89673b57 111 {
nikapov 0:704c89673b57 112 return 1;
nikapov 0:704c89673b57 113 }
nikapov 0:704c89673b57 114
nikapov 0:704c89673b57 115 /* Output data rate selection - power down */
nikapov 0:704c89673b57 116 if ( LSM6DSL_ACC_GYRO_W_ODR_G( (void *)this, LSM6DSL_ACC_GYRO_ODR_G_POWER_DOWN ) == MEMS_ERROR )
nikapov 0:704c89673b57 117 {
nikapov 0:704c89673b57 118 return 1;
nikapov 0:704c89673b57 119 }
nikapov 0:704c89673b57 120
nikapov 0:704c89673b57 121 /* Full scale selection. */
nikapov 0:704c89673b57 122 if ( set_g_fs( 2000.0f ) == 1 )
nikapov 0:704c89673b57 123 {
nikapov 0:704c89673b57 124 return 1;
nikapov 0:704c89673b57 125 }
nikapov 0:704c89673b57 126
nikapov 0:704c89673b57 127 _x_last_odr = 104.0f;
nikapov 0:704c89673b57 128
nikapov 0:704c89673b57 129 _x_is_enabled = 0;
nikapov 0:704c89673b57 130
nikapov 0:704c89673b57 131 _g_last_odr = 104.0f;
nikapov 0:704c89673b57 132
nikapov 0:704c89673b57 133 _g_is_enabled = 0;
nikapov 0:704c89673b57 134
nikapov 0:704c89673b57 135 return 0;
nikapov 0:704c89673b57 136 }
nikapov 0:704c89673b57 137
nikapov 0:704c89673b57 138 /**
nikapov 0:704c89673b57 139 * @brief Enable LSM6DSL Accelerator
nikapov 0:704c89673b57 140 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 141 */
nikapov 0:704c89673b57 142 int LSM6DSLSensor::enable_x(void)
nikapov 0:704c89673b57 143 {
nikapov 0:704c89673b57 144 /* Check if the component is already enabled */
nikapov 0:704c89673b57 145 if ( _x_is_enabled == 1 )
nikapov 0:704c89673b57 146 {
nikapov 0:704c89673b57 147 return 0;
nikapov 0:704c89673b57 148 }
nikapov 0:704c89673b57 149
nikapov 0:704c89673b57 150 /* Output data rate selection. */
nikapov 0:704c89673b57 151 if ( set_x_odr_when_enabled( _x_last_odr ) == 1 )
nikapov 0:704c89673b57 152 {
nikapov 0:704c89673b57 153 return 1;
nikapov 0:704c89673b57 154 }
nikapov 0:704c89673b57 155
nikapov 0:704c89673b57 156 _x_is_enabled = 1;
nikapov 0:704c89673b57 157
nikapov 0:704c89673b57 158 return 0;
nikapov 0:704c89673b57 159 }
nikapov 0:704c89673b57 160
nikapov 0:704c89673b57 161 /**
nikapov 0:704c89673b57 162 * @brief Enable LSM6DSL Gyroscope
nikapov 0:704c89673b57 163 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 164 */
nikapov 0:704c89673b57 165 int LSM6DSLSensor::enable_g(void)
nikapov 0:704c89673b57 166 {
nikapov 0:704c89673b57 167 /* Check if the component is already enabled */
nikapov 0:704c89673b57 168 if ( _g_is_enabled == 1 )
nikapov 0:704c89673b57 169 {
nikapov 0:704c89673b57 170 return 0;
nikapov 0:704c89673b57 171 }
nikapov 0:704c89673b57 172
nikapov 0:704c89673b57 173 /* Output data rate selection. */
nikapov 0:704c89673b57 174 if ( set_g_odr_when_enabled( _g_last_odr ) == 1 )
nikapov 0:704c89673b57 175 {
nikapov 0:704c89673b57 176 return 1;
nikapov 0:704c89673b57 177 }
nikapov 0:704c89673b57 178
nikapov 0:704c89673b57 179 _g_is_enabled = 1;
nikapov 0:704c89673b57 180
nikapov 0:704c89673b57 181 return 0;
nikapov 0:704c89673b57 182 }
nikapov 0:704c89673b57 183
nikapov 0:704c89673b57 184 /**
nikapov 0:704c89673b57 185 * @brief Disable LSM6DSL Accelerator
nikapov 0:704c89673b57 186 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 187 */
nikapov 0:704c89673b57 188 int LSM6DSLSensor::disable_x(void)
nikapov 0:704c89673b57 189 {
nikapov 0:704c89673b57 190 /* Check if the component is already disabled */
nikapov 0:704c89673b57 191 if ( _x_is_enabled == 0 )
nikapov 0:704c89673b57 192 {
nikapov 0:704c89673b57 193 return 0;
nikapov 0:704c89673b57 194 }
nikapov 0:704c89673b57 195
nikapov 0:704c89673b57 196 /* Store actual output data rate. */
nikapov 0:704c89673b57 197 if ( get_x_odr( &_x_last_odr ) == 1 )
nikapov 0:704c89673b57 198 {
nikapov 0:704c89673b57 199 return 1;
nikapov 0:704c89673b57 200 }
nikapov 0:704c89673b57 201
nikapov 0:704c89673b57 202 /* Output data rate selection - power down. */
nikapov 0:704c89673b57 203 if ( LSM6DSL_ACC_GYRO_W_ODR_XL( (void *)this, LSM6DSL_ACC_GYRO_ODR_XL_POWER_DOWN ) == MEMS_ERROR )
nikapov 0:704c89673b57 204 {
nikapov 0:704c89673b57 205 return 1;
nikapov 0:704c89673b57 206 }
nikapov 0:704c89673b57 207
nikapov 0:704c89673b57 208 _x_is_enabled = 0;
nikapov 0:704c89673b57 209
nikapov 0:704c89673b57 210 return 0;
nikapov 0:704c89673b57 211 }
nikapov 0:704c89673b57 212
nikapov 0:704c89673b57 213 /**
nikapov 0:704c89673b57 214 * @brief Disable LSM6DSL Gyroscope
nikapov 0:704c89673b57 215 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 216 */
nikapov 0:704c89673b57 217 int LSM6DSLSensor::disable_g(void)
nikapov 0:704c89673b57 218 {
nikapov 0:704c89673b57 219 /* Check if the component is already disabled */
nikapov 0:704c89673b57 220 if ( _g_is_enabled == 0 )
nikapov 0:704c89673b57 221 {
nikapov 0:704c89673b57 222 return 0;
nikapov 0:704c89673b57 223 }
nikapov 0:704c89673b57 224
nikapov 0:704c89673b57 225 /* Store actual output data rate. */
nikapov 0:704c89673b57 226 if ( get_g_odr( &_g_last_odr ) == 1 )
nikapov 0:704c89673b57 227 {
nikapov 0:704c89673b57 228 return 1;
nikapov 0:704c89673b57 229 }
nikapov 0:704c89673b57 230
nikapov 0:704c89673b57 231 /* Output data rate selection - power down */
nikapov 0:704c89673b57 232 if ( LSM6DSL_ACC_GYRO_W_ODR_G( (void *)this, LSM6DSL_ACC_GYRO_ODR_G_POWER_DOWN ) == MEMS_ERROR )
nikapov 0:704c89673b57 233 {
nikapov 0:704c89673b57 234 return 1;
nikapov 0:704c89673b57 235 }
nikapov 0:704c89673b57 236
nikapov 0:704c89673b57 237 _g_is_enabled = 0;
nikapov 0:704c89673b57 238
nikapov 0:704c89673b57 239 return 0;
nikapov 0:704c89673b57 240 }
nikapov 0:704c89673b57 241
nikapov 0:704c89673b57 242 /**
nikapov 0:704c89673b57 243 * @brief Read ID of LSM6DSL Accelerometer and Gyroscope
nikapov 0:704c89673b57 244 * @param p_id the pointer where the ID of the device is stored
nikapov 0:704c89673b57 245 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 246 */
nikapov 0:704c89673b57 247 int LSM6DSLSensor::read_id(uint8_t *id)
nikapov 0:704c89673b57 248 {
nikapov 0:704c89673b57 249 if(!id)
nikapov 0:704c89673b57 250 {
nikapov 0:704c89673b57 251 return 1;
nikapov 0:704c89673b57 252 }
nikapov 0:704c89673b57 253
nikapov 0:704c89673b57 254 /* Read WHO AM I register */
nikapov 0:704c89673b57 255 if ( LSM6DSL_ACC_GYRO_R_WHO_AM_I( (void *)this, id ) == MEMS_ERROR )
nikapov 0:704c89673b57 256 {
nikapov 0:704c89673b57 257 return 1;
nikapov 0:704c89673b57 258 }
nikapov 0:704c89673b57 259
nikapov 0:704c89673b57 260 return 0;
nikapov 0:704c89673b57 261 }
nikapov 0:704c89673b57 262
nikapov 0:704c89673b57 263 /**
nikapov 0:704c89673b57 264 * @brief Read data from LSM6DSL Accelerometer
nikapov 0:704c89673b57 265 * @param pData the pointer where the accelerometer data are stored
nikapov 0:704c89673b57 266 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 267 */
nikapov 0:704c89673b57 268 int LSM6DSLSensor::get_x_axes(int32_t *pData)
nikapov 0:704c89673b57 269 {
nikapov 0:704c89673b57 270 int16_t dataRaw[3];
nikapov 0:704c89673b57 271 float sensitivity = 0;
nikapov 0:704c89673b57 272
nikapov 0:704c89673b57 273 /* Read raw data from LSM6DSL output register. */
nikapov 0:704c89673b57 274 if ( get_x_axes_raw( dataRaw ) == 1 )
nikapov 0:704c89673b57 275 {
nikapov 0:704c89673b57 276 return 1;
nikapov 0:704c89673b57 277 }
nikapov 0:704c89673b57 278
nikapov 0:704c89673b57 279 /* Get LSM6DSL actual sensitivity. */
nikapov 0:704c89673b57 280 if ( get_x_sensitivity( &sensitivity ) == 1 )
nikapov 0:704c89673b57 281 {
nikapov 0:704c89673b57 282 return 1;
nikapov 0:704c89673b57 283 }
nikapov 0:704c89673b57 284
nikapov 0:704c89673b57 285 /* Calculate the data. */
nikapov 0:704c89673b57 286 pData[0] = ( int32_t )( dataRaw[0] * sensitivity );
nikapov 0:704c89673b57 287 pData[1] = ( int32_t )( dataRaw[1] * sensitivity );
nikapov 0:704c89673b57 288 pData[2] = ( int32_t )( dataRaw[2] * sensitivity );
nikapov 0:704c89673b57 289
nikapov 0:704c89673b57 290 return 0;
nikapov 0:704c89673b57 291 }
nikapov 0:704c89673b57 292
nikapov 0:704c89673b57 293 /**
nikapov 0:704c89673b57 294 * @brief Read data from LSM6DSL Gyroscope
nikapov 0:704c89673b57 295 * @param pData the pointer where the gyroscope data are stored
nikapov 0:704c89673b57 296 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 297 */
nikapov 0:704c89673b57 298 int LSM6DSLSensor::get_g_axes(int32_t *pData)
nikapov 0:704c89673b57 299 {
nikapov 0:704c89673b57 300 int16_t dataRaw[3];
nikapov 0:704c89673b57 301 float sensitivity = 0;
nikapov 0:704c89673b57 302
nikapov 0:704c89673b57 303 /* Read raw data from LSM6DSL output register. */
nikapov 0:704c89673b57 304 if ( get_g_axes_raw( dataRaw ) == 1 )
nikapov 0:704c89673b57 305 {
nikapov 0:704c89673b57 306 return 1;
nikapov 0:704c89673b57 307 }
nikapov 0:704c89673b57 308
nikapov 0:704c89673b57 309 /* Get LSM6DSL actual sensitivity. */
nikapov 0:704c89673b57 310 if ( get_g_sensitivity( &sensitivity ) == 1 )
nikapov 0:704c89673b57 311 {
nikapov 0:704c89673b57 312 return 1;
nikapov 0:704c89673b57 313 }
nikapov 0:704c89673b57 314
nikapov 0:704c89673b57 315 /* Calculate the data. */
nikapov 0:704c89673b57 316 pData[0] = ( int32_t )( dataRaw[0] * sensitivity );
nikapov 0:704c89673b57 317 pData[1] = ( int32_t )( dataRaw[1] * sensitivity );
nikapov 0:704c89673b57 318 pData[2] = ( int32_t )( dataRaw[2] * sensitivity );
nikapov 0:704c89673b57 319
nikapov 0:704c89673b57 320 return 0;
nikapov 0:704c89673b57 321 }
nikapov 0:704c89673b57 322
nikapov 0:704c89673b57 323 /**
nikapov 0:704c89673b57 324 * @brief Read Accelerometer Sensitivity
nikapov 0:704c89673b57 325 * @param pfData the pointer where the accelerometer sensitivity is stored
nikapov 0:704c89673b57 326 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 327 */
nikapov 0:704c89673b57 328 int LSM6DSLSensor::get_x_sensitivity(float *pfData)
nikapov 0:704c89673b57 329 {
nikapov 0:704c89673b57 330 LSM6DSL_ACC_GYRO_FS_XL_t fullScale;
nikapov 0:704c89673b57 331
nikapov 0:704c89673b57 332 /* Read actual full scale selection from sensor. */
nikapov 0:704c89673b57 333 if ( LSM6DSL_ACC_GYRO_R_FS_XL( (void *)this, &fullScale ) == MEMS_ERROR )
nikapov 0:704c89673b57 334 {
nikapov 0:704c89673b57 335 return 1;
nikapov 0:704c89673b57 336 }
nikapov 0:704c89673b57 337
nikapov 0:704c89673b57 338 /* Store the sensitivity based on actual full scale. */
nikapov 0:704c89673b57 339 switch( fullScale )
nikapov 0:704c89673b57 340 {
nikapov 0:704c89673b57 341 case LSM6DSL_ACC_GYRO_FS_XL_2g:
nikapov 0:704c89673b57 342 *pfData = ( float )LSM6DSL_ACC_SENSITIVITY_FOR_FS_2G;
nikapov 0:704c89673b57 343 break;
nikapov 0:704c89673b57 344 case LSM6DSL_ACC_GYRO_FS_XL_4g:
nikapov 0:704c89673b57 345 *pfData = ( float )LSM6DSL_ACC_SENSITIVITY_FOR_FS_4G;
nikapov 0:704c89673b57 346 break;
nikapov 0:704c89673b57 347 case LSM6DSL_ACC_GYRO_FS_XL_8g:
nikapov 0:704c89673b57 348 *pfData = ( float )LSM6DSL_ACC_SENSITIVITY_FOR_FS_8G;
nikapov 0:704c89673b57 349 break;
nikapov 0:704c89673b57 350 case LSM6DSL_ACC_GYRO_FS_XL_16g:
nikapov 0:704c89673b57 351 *pfData = ( float )LSM6DSL_ACC_SENSITIVITY_FOR_FS_16G;
nikapov 0:704c89673b57 352 break;
nikapov 0:704c89673b57 353 default:
nikapov 0:704c89673b57 354 *pfData = -1.0f;
nikapov 0:704c89673b57 355 return 1;
nikapov 0:704c89673b57 356 }
nikapov 0:704c89673b57 357
nikapov 0:704c89673b57 358 return 0;
nikapov 0:704c89673b57 359 }
nikapov 0:704c89673b57 360
nikapov 0:704c89673b57 361 /**
nikapov 0:704c89673b57 362 * @brief Read Gyroscope Sensitivity
nikapov 0:704c89673b57 363 * @param pfData the pointer where the gyroscope sensitivity is stored
nikapov 0:704c89673b57 364 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 365 */
nikapov 0:704c89673b57 366 int LSM6DSLSensor::get_g_sensitivity(float *pfData)
nikapov 0:704c89673b57 367 {
nikapov 0:704c89673b57 368 LSM6DSL_ACC_GYRO_FS_125_t fullScale125;
nikapov 0:704c89673b57 369 LSM6DSL_ACC_GYRO_FS_G_t fullScale;
nikapov 0:704c89673b57 370
nikapov 0:704c89673b57 371 /* Read full scale 125 selection from sensor. */
nikapov 0:704c89673b57 372 if ( LSM6DSL_ACC_GYRO_R_FS_125( (void *)this, &fullScale125 ) == MEMS_ERROR )
nikapov 0:704c89673b57 373 {
nikapov 0:704c89673b57 374 return 1;
nikapov 0:704c89673b57 375 }
nikapov 0:704c89673b57 376
nikapov 0:704c89673b57 377 if ( fullScale125 == LSM6DSL_ACC_GYRO_FS_125_ENABLED )
nikapov 0:704c89673b57 378 {
nikapov 0:704c89673b57 379 *pfData = ( float )LSM6DSL_GYRO_SENSITIVITY_FOR_FS_125DPS;
nikapov 0:704c89673b57 380 }
nikapov 0:704c89673b57 381
nikapov 0:704c89673b57 382 else
nikapov 0:704c89673b57 383 {
nikapov 0:704c89673b57 384
nikapov 0:704c89673b57 385 /* Read actual full scale selection from sensor. */
nikapov 0:704c89673b57 386 if ( LSM6DSL_ACC_GYRO_R_FS_G( (void *)this, &fullScale ) == MEMS_ERROR )
nikapov 0:704c89673b57 387 {
nikapov 0:704c89673b57 388 return 1;
nikapov 0:704c89673b57 389 }
nikapov 0:704c89673b57 390
nikapov 0:704c89673b57 391 /* Store the sensitivity based on actual full scale. */
nikapov 0:704c89673b57 392 switch( fullScale )
nikapov 0:704c89673b57 393 {
nikapov 0:704c89673b57 394 case LSM6DSL_ACC_GYRO_FS_G_245dps:
nikapov 0:704c89673b57 395 *pfData = ( float )LSM6DSL_GYRO_SENSITIVITY_FOR_FS_245DPS;
nikapov 0:704c89673b57 396 break;
nikapov 0:704c89673b57 397 case LSM6DSL_ACC_GYRO_FS_G_500dps:
nikapov 0:704c89673b57 398 *pfData = ( float )LSM6DSL_GYRO_SENSITIVITY_FOR_FS_500DPS;
nikapov 0:704c89673b57 399 break;
nikapov 0:704c89673b57 400 case LSM6DSL_ACC_GYRO_FS_G_1000dps:
nikapov 0:704c89673b57 401 *pfData = ( float )LSM6DSL_GYRO_SENSITIVITY_FOR_FS_1000DPS;
nikapov 0:704c89673b57 402 break;
nikapov 0:704c89673b57 403 case LSM6DSL_ACC_GYRO_FS_G_2000dps:
nikapov 0:704c89673b57 404 *pfData = ( float )LSM6DSL_GYRO_SENSITIVITY_FOR_FS_2000DPS;
nikapov 0:704c89673b57 405 break;
nikapov 0:704c89673b57 406 default:
nikapov 0:704c89673b57 407 *pfData = -1.0f;
nikapov 0:704c89673b57 408 return 1;
nikapov 0:704c89673b57 409 }
nikapov 0:704c89673b57 410 }
nikapov 0:704c89673b57 411
nikapov 0:704c89673b57 412 return 0;
nikapov 0:704c89673b57 413 }
nikapov 0:704c89673b57 414
nikapov 0:704c89673b57 415 /**
nikapov 0:704c89673b57 416 * @brief Read raw data from LSM6DSL Accelerometer
nikapov 0:704c89673b57 417 * @param pData the pointer where the accelerometer raw data are stored
nikapov 0:704c89673b57 418 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 419 */
nikapov 0:704c89673b57 420 int LSM6DSLSensor::get_x_axes_raw(int16_t *pData)
nikapov 0:704c89673b57 421 {
nikapov 0:704c89673b57 422 uint8_t regValue[6] = {0, 0, 0, 0, 0, 0};
nikapov 0:704c89673b57 423
nikapov 0:704c89673b57 424 /* Read output registers from LSM6DSL_ACC_GYRO_OUTX_L_XL to LSM6DSL_ACC_GYRO_OUTZ_H_XL. */
nikapov 0:704c89673b57 425 if ( LSM6DSL_ACC_GYRO_GetRawAccData( (void *)this, regValue ) == MEMS_ERROR )
nikapov 0:704c89673b57 426 {
nikapov 0:704c89673b57 427 return 1;
nikapov 0:704c89673b57 428 }
nikapov 0:704c89673b57 429
nikapov 0:704c89673b57 430 /* Format the data. */
nikapov 0:704c89673b57 431 pData[0] = ( ( ( ( int16_t )regValue[1] ) << 8 ) + ( int16_t )regValue[0] );
nikapov 0:704c89673b57 432 pData[1] = ( ( ( ( int16_t )regValue[3] ) << 8 ) + ( int16_t )regValue[2] );
nikapov 0:704c89673b57 433 pData[2] = ( ( ( ( int16_t )regValue[5] ) << 8 ) + ( int16_t )regValue[4] );
nikapov 0:704c89673b57 434
nikapov 0:704c89673b57 435 return 0;
nikapov 0:704c89673b57 436 }
nikapov 0:704c89673b57 437
nikapov 0:704c89673b57 438 /**
nikapov 0:704c89673b57 439 * @brief Read raw data from LSM6DSL Gyroscope
nikapov 0:704c89673b57 440 * @param pData the pointer where the gyroscope raw data are stored
nikapov 0:704c89673b57 441 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 442 */
nikapov 0:704c89673b57 443 int LSM6DSLSensor::get_g_axes_raw(int16_t *pData)
nikapov 0:704c89673b57 444 {
nikapov 0:704c89673b57 445 uint8_t regValue[6] = {0, 0, 0, 0, 0, 0};
nikapov 0:704c89673b57 446
nikapov 0:704c89673b57 447 /* Read output registers from LSM6DSL_ACC_GYRO_OUTX_L_G to LSM6DSL_ACC_GYRO_OUTZ_H_G. */
nikapov 0:704c89673b57 448 if ( LSM6DSL_ACC_GYRO_GetRawGyroData( (void *)this, regValue ) == MEMS_ERROR )
nikapov 0:704c89673b57 449 {
nikapov 0:704c89673b57 450 return 1;
nikapov 0:704c89673b57 451 }
nikapov 0:704c89673b57 452
nikapov 0:704c89673b57 453 /* Format the data. */
nikapov 0:704c89673b57 454 pData[0] = ( ( ( ( int16_t )regValue[1] ) << 8 ) + ( int16_t )regValue[0] );
nikapov 0:704c89673b57 455 pData[1] = ( ( ( ( int16_t )regValue[3] ) << 8 ) + ( int16_t )regValue[2] );
nikapov 0:704c89673b57 456 pData[2] = ( ( ( ( int16_t )regValue[5] ) << 8 ) + ( int16_t )regValue[4] );
nikapov 0:704c89673b57 457
nikapov 0:704c89673b57 458 return 0;
nikapov 0:704c89673b57 459 }
nikapov 0:704c89673b57 460
nikapov 0:704c89673b57 461 /**
nikapov 0:704c89673b57 462 * @brief Read LSM6DSL Accelerometer output data rate
nikapov 0:704c89673b57 463 * @param odr the pointer to the output data rate
nikapov 0:704c89673b57 464 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 465 */
nikapov 0:704c89673b57 466 int LSM6DSLSensor::get_x_odr(float* odr)
nikapov 0:704c89673b57 467 {
nikapov 0:704c89673b57 468 LSM6DSL_ACC_GYRO_ODR_XL_t odr_low_level;
nikapov 0:704c89673b57 469
nikapov 0:704c89673b57 470 if ( LSM6DSL_ACC_GYRO_R_ODR_XL( (void *)this, &odr_low_level ) == MEMS_ERROR )
nikapov 0:704c89673b57 471 {
nikapov 0:704c89673b57 472 return 1;
nikapov 0:704c89673b57 473 }
nikapov 0:704c89673b57 474
nikapov 0:704c89673b57 475 switch( odr_low_level )
nikapov 0:704c89673b57 476 {
nikapov 0:704c89673b57 477 case LSM6DSL_ACC_GYRO_ODR_XL_POWER_DOWN:
nikapov 0:704c89673b57 478 *odr = 0.0f;
nikapov 0:704c89673b57 479 break;
nikapov 0:704c89673b57 480 case LSM6DSL_ACC_GYRO_ODR_XL_13Hz:
nikapov 0:704c89673b57 481 *odr = 13.0f;
nikapov 0:704c89673b57 482 break;
nikapov 0:704c89673b57 483 case LSM6DSL_ACC_GYRO_ODR_XL_26Hz:
nikapov 0:704c89673b57 484 *odr = 26.0f;
nikapov 0:704c89673b57 485 break;
nikapov 0:704c89673b57 486 case LSM6DSL_ACC_GYRO_ODR_XL_52Hz:
nikapov 0:704c89673b57 487 *odr = 52.0f;
nikapov 0:704c89673b57 488 break;
nikapov 0:704c89673b57 489 case LSM6DSL_ACC_GYRO_ODR_XL_104Hz:
nikapov 0:704c89673b57 490 *odr = 104.0f;
nikapov 0:704c89673b57 491 break;
nikapov 0:704c89673b57 492 case LSM6DSL_ACC_GYRO_ODR_XL_208Hz:
nikapov 0:704c89673b57 493 *odr = 208.0f;
nikapov 0:704c89673b57 494 break;
nikapov 0:704c89673b57 495 case LSM6DSL_ACC_GYRO_ODR_XL_416Hz:
nikapov 0:704c89673b57 496 *odr = 416.0f;
nikapov 0:704c89673b57 497 break;
nikapov 0:704c89673b57 498 case LSM6DSL_ACC_GYRO_ODR_XL_833Hz:
nikapov 0:704c89673b57 499 *odr = 833.0f;
nikapov 0:704c89673b57 500 break;
nikapov 0:704c89673b57 501 case LSM6DSL_ACC_GYRO_ODR_XL_1660Hz:
nikapov 0:704c89673b57 502 *odr = 1660.0f;
nikapov 0:704c89673b57 503 break;
nikapov 0:704c89673b57 504 case LSM6DSL_ACC_GYRO_ODR_XL_3330Hz:
nikapov 0:704c89673b57 505 *odr = 3330.0f;
nikapov 0:704c89673b57 506 break;
nikapov 0:704c89673b57 507 case LSM6DSL_ACC_GYRO_ODR_XL_6660Hz:
nikapov 0:704c89673b57 508 *odr = 6660.0f;
nikapov 0:704c89673b57 509 break;
nikapov 0:704c89673b57 510 default:
nikapov 0:704c89673b57 511 *odr = -1.0f;
nikapov 0:704c89673b57 512 return 1;
nikapov 0:704c89673b57 513 }
nikapov 0:704c89673b57 514
nikapov 0:704c89673b57 515 return 0;
nikapov 0:704c89673b57 516 }
nikapov 0:704c89673b57 517
nikapov 0:704c89673b57 518 /**
nikapov 0:704c89673b57 519 * @brief Read LSM6DSL Gyroscope output data rate
nikapov 0:704c89673b57 520 * @param odr the pointer to the output data rate
nikapov 0:704c89673b57 521 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 522 */
nikapov 0:704c89673b57 523 int LSM6DSLSensor::get_g_odr(float* odr)
nikapov 0:704c89673b57 524 {
nikapov 0:704c89673b57 525 LSM6DSL_ACC_GYRO_ODR_G_t odr_low_level;
nikapov 0:704c89673b57 526
nikapov 0:704c89673b57 527 if ( LSM6DSL_ACC_GYRO_R_ODR_G( (void *)this, &odr_low_level ) == MEMS_ERROR )
nikapov 0:704c89673b57 528 {
nikapov 0:704c89673b57 529 return 1;
nikapov 0:704c89673b57 530 }
nikapov 0:704c89673b57 531
nikapov 0:704c89673b57 532 switch( odr_low_level )
nikapov 0:704c89673b57 533 {
nikapov 0:704c89673b57 534 case LSM6DSL_ACC_GYRO_ODR_G_POWER_DOWN:
nikapov 0:704c89673b57 535 *odr = 0.0f;
nikapov 0:704c89673b57 536 break;
nikapov 0:704c89673b57 537 case LSM6DSL_ACC_GYRO_ODR_G_13Hz:
nikapov 0:704c89673b57 538 *odr = 13.0f;
nikapov 0:704c89673b57 539 break;
nikapov 0:704c89673b57 540 case LSM6DSL_ACC_GYRO_ODR_G_26Hz:
nikapov 0:704c89673b57 541 *odr = 26.0f;
nikapov 0:704c89673b57 542 break;
nikapov 0:704c89673b57 543 case LSM6DSL_ACC_GYRO_ODR_G_52Hz:
nikapov 0:704c89673b57 544 *odr = 52.0f;
nikapov 0:704c89673b57 545 break;
nikapov 0:704c89673b57 546 case LSM6DSL_ACC_GYRO_ODR_G_104Hz:
nikapov 0:704c89673b57 547 *odr = 104.0f;
nikapov 0:704c89673b57 548 break;
nikapov 0:704c89673b57 549 case LSM6DSL_ACC_GYRO_ODR_G_208Hz:
nikapov 0:704c89673b57 550 *odr = 208.0f;
nikapov 0:704c89673b57 551 break;
nikapov 0:704c89673b57 552 case LSM6DSL_ACC_GYRO_ODR_G_416Hz:
nikapov 0:704c89673b57 553 *odr = 416.0f;
nikapov 0:704c89673b57 554 break;
nikapov 0:704c89673b57 555 case LSM6DSL_ACC_GYRO_ODR_G_833Hz:
nikapov 0:704c89673b57 556 *odr = 833.0f;
nikapov 0:704c89673b57 557 break;
nikapov 0:704c89673b57 558 case LSM6DSL_ACC_GYRO_ODR_G_1660Hz:
nikapov 0:704c89673b57 559 *odr = 1660.0f;
nikapov 0:704c89673b57 560 break;
nikapov 0:704c89673b57 561 case LSM6DSL_ACC_GYRO_ODR_G_3330Hz:
nikapov 0:704c89673b57 562 *odr = 3330.0f;
nikapov 0:704c89673b57 563 break;
nikapov 0:704c89673b57 564 case LSM6DSL_ACC_GYRO_ODR_G_6660Hz:
nikapov 0:704c89673b57 565 *odr = 6660.0f;
nikapov 0:704c89673b57 566 break;
nikapov 0:704c89673b57 567 default:
nikapov 0:704c89673b57 568 *odr = -1.0f;
nikapov 0:704c89673b57 569 return 1;
nikapov 0:704c89673b57 570 }
nikapov 0:704c89673b57 571
nikapov 0:704c89673b57 572 return 0;
nikapov 0:704c89673b57 573 }
nikapov 0:704c89673b57 574
nikapov 0:704c89673b57 575 /**
nikapov 0:704c89673b57 576 * @brief Set LSM6DSL Accelerometer output data rate
nikapov 0:704c89673b57 577 * @param odr the output data rate to be set
nikapov 0:704c89673b57 578 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 579 */
nikapov 0:704c89673b57 580 int LSM6DSLSensor::set_x_odr(float odr)
nikapov 0:704c89673b57 581 {
nikapov 0:704c89673b57 582 if(_x_is_enabled == 1)
nikapov 0:704c89673b57 583 {
nikapov 0:704c89673b57 584 if(set_x_odr_when_enabled(odr) == 1)
nikapov 0:704c89673b57 585 {
nikapov 0:704c89673b57 586 return 1;
nikapov 0:704c89673b57 587 }
nikapov 0:704c89673b57 588 }
nikapov 0:704c89673b57 589 else
nikapov 0:704c89673b57 590 {
nikapov 0:704c89673b57 591 if(set_x_odr_when_disabled(odr) == 1)
nikapov 0:704c89673b57 592 {
nikapov 0:704c89673b57 593 return 1;
nikapov 0:704c89673b57 594 }
nikapov 0:704c89673b57 595 }
nikapov 0:704c89673b57 596
nikapov 0:704c89673b57 597 return 0;
nikapov 0:704c89673b57 598 }
nikapov 0:704c89673b57 599
nikapov 0:704c89673b57 600 /**
nikapov 0:704c89673b57 601 * @brief Set LSM6DSL Accelerometer output data rate when enabled
nikapov 0:704c89673b57 602 * @param odr the output data rate to be set
nikapov 0:704c89673b57 603 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 604 */
nikapov 0:704c89673b57 605 int LSM6DSLSensor::set_x_odr_when_enabled(float odr)
nikapov 0:704c89673b57 606 {
nikapov 0:704c89673b57 607 LSM6DSL_ACC_GYRO_ODR_XL_t new_odr;
nikapov 0:704c89673b57 608
nikapov 0:704c89673b57 609 new_odr = ( odr <= 13.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_13Hz
nikapov 0:704c89673b57 610 : ( odr <= 26.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_26Hz
nikapov 0:704c89673b57 611 : ( odr <= 52.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_52Hz
nikapov 0:704c89673b57 612 : ( odr <= 104.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_104Hz
nikapov 0:704c89673b57 613 : ( odr <= 208.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_208Hz
nikapov 0:704c89673b57 614 : ( odr <= 416.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_416Hz
nikapov 0:704c89673b57 615 : ( odr <= 833.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_833Hz
nikapov 0:704c89673b57 616 : ( odr <= 1660.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_1660Hz
nikapov 0:704c89673b57 617 : ( odr <= 3330.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_3330Hz
nikapov 0:704c89673b57 618 : LSM6DSL_ACC_GYRO_ODR_XL_6660Hz;
nikapov 0:704c89673b57 619
nikapov 0:704c89673b57 620 if ( LSM6DSL_ACC_GYRO_W_ODR_XL( (void *)this, new_odr ) == MEMS_ERROR )
nikapov 0:704c89673b57 621 {
nikapov 0:704c89673b57 622 return 1;
nikapov 0:704c89673b57 623 }
nikapov 0:704c89673b57 624
nikapov 0:704c89673b57 625 return 0;
nikapov 0:704c89673b57 626 }
nikapov 0:704c89673b57 627
nikapov 0:704c89673b57 628 /**
nikapov 0:704c89673b57 629 * @brief Set LSM6DSL Accelerometer output data rate when disabled
nikapov 0:704c89673b57 630 * @param odr the output data rate to be set
nikapov 0:704c89673b57 631 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 632 */
nikapov 0:704c89673b57 633 int LSM6DSLSensor::set_x_odr_when_disabled(float odr)
nikapov 0:704c89673b57 634 {
nikapov 0:704c89673b57 635 _x_last_odr = ( odr <= 13.0f ) ? 13.0f
nikapov 0:704c89673b57 636 : ( odr <= 26.0f ) ? 26.0f
nikapov 0:704c89673b57 637 : ( odr <= 52.0f ) ? 52.0f
nikapov 0:704c89673b57 638 : ( odr <= 104.0f ) ? 104.0f
nikapov 0:704c89673b57 639 : ( odr <= 208.0f ) ? 208.0f
nikapov 0:704c89673b57 640 : ( odr <= 416.0f ) ? 416.0f
nikapov 0:704c89673b57 641 : ( odr <= 833.0f ) ? 833.0f
nikapov 0:704c89673b57 642 : ( odr <= 1660.0f ) ? 1660.0f
nikapov 0:704c89673b57 643 : ( odr <= 3330.0f ) ? 3330.0f
nikapov 0:704c89673b57 644 : 6660.0f;
nikapov 0:704c89673b57 645
nikapov 0:704c89673b57 646 return 0;
nikapov 0:704c89673b57 647 }
nikapov 0:704c89673b57 648
nikapov 0:704c89673b57 649 /**
nikapov 0:704c89673b57 650 * @brief Set LSM6DSL Gyroscope output data rate
nikapov 0:704c89673b57 651 * @param odr the output data rate to be set
nikapov 0:704c89673b57 652 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 653 */
nikapov 0:704c89673b57 654 int LSM6DSLSensor::set_g_odr(float odr)
nikapov 0:704c89673b57 655 {
nikapov 0:704c89673b57 656 if(_g_is_enabled == 1)
nikapov 0:704c89673b57 657 {
nikapov 0:704c89673b57 658 if(set_g_odr_when_enabled(odr) == 1)
nikapov 0:704c89673b57 659 {
nikapov 0:704c89673b57 660 return 1;
nikapov 0:704c89673b57 661 }
nikapov 0:704c89673b57 662 }
nikapov 0:704c89673b57 663 else
nikapov 0:704c89673b57 664 {
nikapov 0:704c89673b57 665 if(set_g_odr_when_disabled(odr) == 1)
nikapov 0:704c89673b57 666 {
nikapov 0:704c89673b57 667 return 1;
nikapov 0:704c89673b57 668 }
nikapov 0:704c89673b57 669 }
nikapov 0:704c89673b57 670
nikapov 0:704c89673b57 671 return 0;
nikapov 0:704c89673b57 672 }
nikapov 0:704c89673b57 673
nikapov 0:704c89673b57 674 /**
nikapov 0:704c89673b57 675 * @brief Set LSM6DSL Gyroscope output data rate when enabled
nikapov 0:704c89673b57 676 * @param odr the output data rate to be set
nikapov 0:704c89673b57 677 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 678 */
nikapov 0:704c89673b57 679 int LSM6DSLSensor::set_g_odr_when_enabled(float odr)
nikapov 0:704c89673b57 680 {
nikapov 0:704c89673b57 681 LSM6DSL_ACC_GYRO_ODR_G_t new_odr;
nikapov 0:704c89673b57 682
nikapov 0:704c89673b57 683 new_odr = ( odr <= 13.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_13Hz
nikapov 0:704c89673b57 684 : ( odr <= 26.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_26Hz
nikapov 0:704c89673b57 685 : ( odr <= 52.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_52Hz
nikapov 0:704c89673b57 686 : ( odr <= 104.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_104Hz
nikapov 0:704c89673b57 687 : ( odr <= 208.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_208Hz
nikapov 0:704c89673b57 688 : ( odr <= 416.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_416Hz
nikapov 0:704c89673b57 689 : ( odr <= 833.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_833Hz
nikapov 0:704c89673b57 690 : ( odr <= 1660.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_1660Hz
nikapov 0:704c89673b57 691 : ( odr <= 3330.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_3330Hz
nikapov 0:704c89673b57 692 : LSM6DSL_ACC_GYRO_ODR_G_6660Hz;
nikapov 0:704c89673b57 693
nikapov 0:704c89673b57 694 if ( LSM6DSL_ACC_GYRO_W_ODR_G( (void *)this, new_odr ) == MEMS_ERROR )
nikapov 0:704c89673b57 695 {
nikapov 0:704c89673b57 696 return 1;
nikapov 0:704c89673b57 697 }
nikapov 0:704c89673b57 698
nikapov 0:704c89673b57 699 return 0;
nikapov 0:704c89673b57 700 }
nikapov 0:704c89673b57 701
nikapov 0:704c89673b57 702 /**
nikapov 0:704c89673b57 703 * @brief Set LSM6DSL Gyroscope output data rate when disabled
nikapov 0:704c89673b57 704 * @param odr the output data rate to be set
nikapov 0:704c89673b57 705 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 706 */
nikapov 0:704c89673b57 707 int LSM6DSLSensor::set_g_odr_when_disabled(float odr)
nikapov 0:704c89673b57 708 {
nikapov 0:704c89673b57 709 _g_last_odr = ( odr <= 13.0f ) ? 13.0f
nikapov 0:704c89673b57 710 : ( odr <= 26.0f ) ? 26.0f
nikapov 0:704c89673b57 711 : ( odr <= 52.0f ) ? 52.0f
nikapov 0:704c89673b57 712 : ( odr <= 104.0f ) ? 104.0f
nikapov 0:704c89673b57 713 : ( odr <= 208.0f ) ? 208.0f
nikapov 0:704c89673b57 714 : ( odr <= 416.0f ) ? 416.0f
nikapov 0:704c89673b57 715 : ( odr <= 833.0f ) ? 833.0f
nikapov 0:704c89673b57 716 : ( odr <= 1660.0f ) ? 1660.0f
nikapov 0:704c89673b57 717 : ( odr <= 3330.0f ) ? 3330.0f
nikapov 0:704c89673b57 718 : 6660.0f;
nikapov 0:704c89673b57 719
nikapov 0:704c89673b57 720 return 0;
nikapov 0:704c89673b57 721 }
nikapov 0:704c89673b57 722
nikapov 0:704c89673b57 723 /**
nikapov 0:704c89673b57 724 * @brief Read LSM6DSL Accelerometer full scale
nikapov 0:704c89673b57 725 * @param fullScale the pointer to the full scale
nikapov 0:704c89673b57 726 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 727 */
nikapov 0:704c89673b57 728 int LSM6DSLSensor::get_x_fs(float* fullScale)
nikapov 0:704c89673b57 729 {
nikapov 0:704c89673b57 730 LSM6DSL_ACC_GYRO_FS_XL_t fs_low_level;
nikapov 0:704c89673b57 731
nikapov 0:704c89673b57 732 if ( LSM6DSL_ACC_GYRO_R_FS_XL( (void *)this, &fs_low_level ) == MEMS_ERROR )
nikapov 0:704c89673b57 733 {
nikapov 0:704c89673b57 734 return 1;
nikapov 0:704c89673b57 735 }
nikapov 0:704c89673b57 736
nikapov 0:704c89673b57 737 switch( fs_low_level )
nikapov 0:704c89673b57 738 {
nikapov 0:704c89673b57 739 case LSM6DSL_ACC_GYRO_FS_XL_2g:
nikapov 0:704c89673b57 740 *fullScale = 2.0f;
nikapov 0:704c89673b57 741 break;
nikapov 0:704c89673b57 742 case LSM6DSL_ACC_GYRO_FS_XL_4g:
nikapov 0:704c89673b57 743 *fullScale = 4.0f;
nikapov 0:704c89673b57 744 break;
nikapov 0:704c89673b57 745 case LSM6DSL_ACC_GYRO_FS_XL_8g:
nikapov 0:704c89673b57 746 *fullScale = 8.0f;
nikapov 0:704c89673b57 747 break;
nikapov 0:704c89673b57 748 case LSM6DSL_ACC_GYRO_FS_XL_16g:
nikapov 0:704c89673b57 749 *fullScale = 16.0f;
nikapov 0:704c89673b57 750 break;
nikapov 0:704c89673b57 751 default:
nikapov 0:704c89673b57 752 *fullScale = -1.0f;
nikapov 0:704c89673b57 753 return 1;
nikapov 0:704c89673b57 754 }
nikapov 0:704c89673b57 755
nikapov 0:704c89673b57 756 return 0;
nikapov 0:704c89673b57 757 }
nikapov 0:704c89673b57 758
nikapov 0:704c89673b57 759 /**
nikapov 0:704c89673b57 760 * @brief Read LSM6DSL Gyroscope full scale
nikapov 0:704c89673b57 761 * @param fullScale the pointer to the full scale
nikapov 0:704c89673b57 762 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 763 */
nikapov 0:704c89673b57 764 int LSM6DSLSensor::get_g_fs(float* fullScale)
nikapov 0:704c89673b57 765 {
nikapov 0:704c89673b57 766 LSM6DSL_ACC_GYRO_FS_G_t fs_low_level;
nikapov 0:704c89673b57 767 LSM6DSL_ACC_GYRO_FS_125_t fs_125;
nikapov 0:704c89673b57 768
nikapov 0:704c89673b57 769 if ( LSM6DSL_ACC_GYRO_R_FS_125( (void *)this, &fs_125 ) == MEMS_ERROR )
nikapov 0:704c89673b57 770 {
nikapov 0:704c89673b57 771 return 1;
nikapov 0:704c89673b57 772 }
nikapov 0:704c89673b57 773 if ( LSM6DSL_ACC_GYRO_R_FS_G( (void *)this, &fs_low_level ) == MEMS_ERROR )
nikapov 0:704c89673b57 774 {
nikapov 0:704c89673b57 775 return 1;
nikapov 0:704c89673b57 776 }
nikapov 0:704c89673b57 777
nikapov 0:704c89673b57 778 if ( fs_125 == LSM6DSL_ACC_GYRO_FS_125_ENABLED )
nikapov 0:704c89673b57 779 {
nikapov 0:704c89673b57 780 *fullScale = 125.0f;
nikapov 0:704c89673b57 781 }
nikapov 0:704c89673b57 782
nikapov 0:704c89673b57 783 else
nikapov 0:704c89673b57 784 {
nikapov 0:704c89673b57 785 switch( fs_low_level )
nikapov 0:704c89673b57 786 {
nikapov 0:704c89673b57 787 case LSM6DSL_ACC_GYRO_FS_G_245dps:
nikapov 0:704c89673b57 788 *fullScale = 245.0f;
nikapov 0:704c89673b57 789 break;
nikapov 0:704c89673b57 790 case LSM6DSL_ACC_GYRO_FS_G_500dps:
nikapov 0:704c89673b57 791 *fullScale = 500.0f;
nikapov 0:704c89673b57 792 break;
nikapov 0:704c89673b57 793 case LSM6DSL_ACC_GYRO_FS_G_1000dps:
nikapov 0:704c89673b57 794 *fullScale = 1000.0f;
nikapov 0:704c89673b57 795 break;
nikapov 0:704c89673b57 796 case LSM6DSL_ACC_GYRO_FS_G_2000dps:
nikapov 0:704c89673b57 797 *fullScale = 2000.0f;
nikapov 0:704c89673b57 798 break;
nikapov 0:704c89673b57 799 default:
nikapov 0:704c89673b57 800 *fullScale = -1.0f;
nikapov 0:704c89673b57 801 return 1;
nikapov 0:704c89673b57 802 }
nikapov 0:704c89673b57 803 }
nikapov 0:704c89673b57 804
nikapov 0:704c89673b57 805 return 0;
nikapov 0:704c89673b57 806 }
nikapov 0:704c89673b57 807
nikapov 0:704c89673b57 808 /**
nikapov 0:704c89673b57 809 * @brief Set LSM6DSL Accelerometer full scale
nikapov 0:704c89673b57 810 * @param fullScale the full scale to be set
nikapov 0:704c89673b57 811 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 812 */
nikapov 0:704c89673b57 813 int LSM6DSLSensor::set_x_fs(float fullScale)
nikapov 0:704c89673b57 814 {
nikapov 0:704c89673b57 815 LSM6DSL_ACC_GYRO_FS_XL_t new_fs;
nikapov 0:704c89673b57 816
nikapov 0:704c89673b57 817 new_fs = ( fullScale <= 2.0f ) ? LSM6DSL_ACC_GYRO_FS_XL_2g
nikapov 0:704c89673b57 818 : ( fullScale <= 4.0f ) ? LSM6DSL_ACC_GYRO_FS_XL_4g
nikapov 0:704c89673b57 819 : ( fullScale <= 8.0f ) ? LSM6DSL_ACC_GYRO_FS_XL_8g
nikapov 0:704c89673b57 820 : LSM6DSL_ACC_GYRO_FS_XL_16g;
nikapov 0:704c89673b57 821
nikapov 0:704c89673b57 822 if ( LSM6DSL_ACC_GYRO_W_FS_XL( (void *)this, new_fs ) == MEMS_ERROR )
nikapov 0:704c89673b57 823 {
nikapov 0:704c89673b57 824 return 1;
nikapov 0:704c89673b57 825 }
nikapov 0:704c89673b57 826
nikapov 0:704c89673b57 827 return 0;
nikapov 0:704c89673b57 828 }
nikapov 0:704c89673b57 829
nikapov 0:704c89673b57 830 /**
nikapov 0:704c89673b57 831 * @brief Set LSM6DSL Gyroscope full scale
nikapov 0:704c89673b57 832 * @param fullScale the full scale to be set
nikapov 0:704c89673b57 833 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 834 */
nikapov 0:704c89673b57 835 int LSM6DSLSensor::set_g_fs(float fullScale)
nikapov 0:704c89673b57 836 {
nikapov 0:704c89673b57 837 LSM6DSL_ACC_GYRO_FS_G_t new_fs;
nikapov 0:704c89673b57 838
nikapov 0:704c89673b57 839 if ( fullScale <= 125.0f )
nikapov 0:704c89673b57 840 {
nikapov 0:704c89673b57 841 if ( LSM6DSL_ACC_GYRO_W_FS_125( (void *)this, LSM6DSL_ACC_GYRO_FS_125_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 842 {
nikapov 0:704c89673b57 843 return 1;
nikapov 0:704c89673b57 844 }
nikapov 0:704c89673b57 845 }
nikapov 0:704c89673b57 846 else
nikapov 0:704c89673b57 847 {
nikapov 0:704c89673b57 848 new_fs = ( fullScale <= 245.0f ) ? LSM6DSL_ACC_GYRO_FS_G_245dps
nikapov 0:704c89673b57 849 : ( fullScale <= 500.0f ) ? LSM6DSL_ACC_GYRO_FS_G_500dps
nikapov 0:704c89673b57 850 : ( fullScale <= 1000.0f ) ? LSM6DSL_ACC_GYRO_FS_G_1000dps
nikapov 0:704c89673b57 851 : LSM6DSL_ACC_GYRO_FS_G_2000dps;
nikapov 0:704c89673b57 852
nikapov 0:704c89673b57 853 if ( LSM6DSL_ACC_GYRO_W_FS_125( (void *)this, LSM6DSL_ACC_GYRO_FS_125_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 854 {
nikapov 0:704c89673b57 855 return 1;
nikapov 0:704c89673b57 856 }
nikapov 0:704c89673b57 857 if ( LSM6DSL_ACC_GYRO_W_FS_G( (void *)this, new_fs ) == MEMS_ERROR )
nikapov 0:704c89673b57 858 {
nikapov 0:704c89673b57 859 return 1;
nikapov 0:704c89673b57 860 }
nikapov 0:704c89673b57 861 }
nikapov 0:704c89673b57 862
nikapov 0:704c89673b57 863 return 0;
nikapov 0:704c89673b57 864 }
nikapov 0:704c89673b57 865
nikapov 0:704c89673b57 866 /**
nikapov 0:704c89673b57 867 * @brief Enable free fall detection
nikapov 0:704c89673b57 868 * @param pin the interrupt pin to be used
nikapov 0:704c89673b57 869 * @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g
nikapov 0:704c89673b57 870 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 871 */
nikapov 0:704c89673b57 872 int LSM6DSLSensor::enable_free_fall_detection(LSM6DSL_Interrupt_Pin_t pin)
nikapov 0:704c89673b57 873 {
nikapov 0:704c89673b57 874 /* Output Data Rate selection */
nikapov 0:704c89673b57 875 if(set_x_odr(416.0f) == 1)
nikapov 0:704c89673b57 876 {
nikapov 0:704c89673b57 877 return 1;
nikapov 0:704c89673b57 878 }
nikapov 0:704c89673b57 879
nikapov 0:704c89673b57 880 /* Full scale selection */
nikapov 0:704c89673b57 881 if ( LSM6DSL_ACC_GYRO_W_FS_XL( (void *)this, LSM6DSL_ACC_GYRO_FS_XL_2g ) == MEMS_ERROR )
nikapov 0:704c89673b57 882 {
nikapov 0:704c89673b57 883 return 1;
nikapov 0:704c89673b57 884 }
nikapov 0:704c89673b57 885
nikapov 0:704c89673b57 886 /* FF_DUR setting */
nikapov 0:704c89673b57 887 if ( LSM6DSL_ACC_GYRO_W_FF_Duration( (void *)this, 0x06 ) == MEMS_ERROR )
nikapov 0:704c89673b57 888 {
nikapov 0:704c89673b57 889 return 1;
nikapov 0:704c89673b57 890 }
nikapov 0:704c89673b57 891
nikapov 0:704c89673b57 892 /* WAKE_DUR setting */
nikapov 0:704c89673b57 893 if ( LSM6DSL_ACC_GYRO_W_WAKE_DUR( (void *)this, 0x00 ) == MEMS_ERROR )
nikapov 0:704c89673b57 894 {
nikapov 0:704c89673b57 895 return 1;
nikapov 0:704c89673b57 896 }
nikapov 0:704c89673b57 897
nikapov 0:704c89673b57 898 /* TIMER_HR setting */
nikapov 0:704c89673b57 899 if ( LSM6DSL_ACC_GYRO_W_TIMER_HR( (void *)this, LSM6DSL_ACC_GYRO_TIMER_HR_6_4ms ) == MEMS_ERROR )
nikapov 0:704c89673b57 900 {
nikapov 0:704c89673b57 901 return 1;
nikapov 0:704c89673b57 902 }
nikapov 0:704c89673b57 903
nikapov 0:704c89673b57 904 /* SLEEP_DUR setting */
nikapov 0:704c89673b57 905 if ( LSM6DSL_ACC_GYRO_W_SLEEP_DUR( (void *)this, 0x00 ) == MEMS_ERROR )
nikapov 0:704c89673b57 906 {
nikapov 0:704c89673b57 907 return 1;
nikapov 0:704c89673b57 908 }
nikapov 0:704c89673b57 909
nikapov 0:704c89673b57 910 /* FF_THS setting */
nikapov 0:704c89673b57 911 if ( LSM6DSL_ACC_GYRO_W_FF_THS( (void *)this, LSM6DSL_ACC_GYRO_FF_THS_312mg ) == MEMS_ERROR )
nikapov 0:704c89673b57 912 {
nikapov 0:704c89673b57 913 return 1;
nikapov 0:704c89673b57 914 }
nikapov 0:704c89673b57 915
nikapov 0:704c89673b57 916 /* Enable basic Interrupts */
nikapov 0:704c89673b57 917 if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 918 {
nikapov 0:704c89673b57 919 return 1;
nikapov 0:704c89673b57 920 }
nikapov 0:704c89673b57 921
nikapov 0:704c89673b57 922 /* Enable free fall event on either INT1 or INT2 pin */
nikapov 0:704c89673b57 923 switch (pin)
nikapov 0:704c89673b57 924 {
nikapov 0:704c89673b57 925 case LSM6DSL_INT1_PIN:
nikapov 0:704c89673b57 926 if ( LSM6DSL_ACC_GYRO_W_FFEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_FF_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 927 {
nikapov 0:704c89673b57 928 return 1;
nikapov 0:704c89673b57 929 }
nikapov 0:704c89673b57 930 break;
nikapov 0:704c89673b57 931
nikapov 0:704c89673b57 932 case LSM6DSL_INT2_PIN:
nikapov 0:704c89673b57 933 if ( LSM6DSL_ACC_GYRO_W_FFEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_FF_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 934 {
nikapov 0:704c89673b57 935 return 1;
nikapov 0:704c89673b57 936 }
nikapov 0:704c89673b57 937 break;
nikapov 0:704c89673b57 938
nikapov 0:704c89673b57 939 default:
nikapov 0:704c89673b57 940 return 1;
nikapov 0:704c89673b57 941 }
nikapov 0:704c89673b57 942
nikapov 0:704c89673b57 943 return 0;
nikapov 0:704c89673b57 944 }
nikapov 0:704c89673b57 945
nikapov 0:704c89673b57 946 /**
nikapov 0:704c89673b57 947 * @brief Disable free fall detection
nikapov 0:704c89673b57 948 * @param None
nikapov 0:704c89673b57 949 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 950 */
nikapov 0:704c89673b57 951 int LSM6DSLSensor::disable_free_fall_detection(void)
nikapov 0:704c89673b57 952 {
nikapov 0:704c89673b57 953 /* Disable free fall event on INT1 pin */
nikapov 0:704c89673b57 954 if ( LSM6DSL_ACC_GYRO_W_FFEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_FF_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 955 {
nikapov 0:704c89673b57 956 return 1;
nikapov 0:704c89673b57 957 }
nikapov 0:704c89673b57 958
nikapov 0:704c89673b57 959 /* Disable free fall event on INT2 pin */
nikapov 0:704c89673b57 960 if ( LSM6DSL_ACC_GYRO_W_FFEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_FF_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 961 {
nikapov 0:704c89673b57 962 return 1;
nikapov 0:704c89673b57 963 }
nikapov 0:704c89673b57 964
nikapov 0:704c89673b57 965 /* Disable basic Interrupts */
nikapov 0:704c89673b57 966 if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 967 {
nikapov 0:704c89673b57 968 return 1;
nikapov 0:704c89673b57 969 }
nikapov 0:704c89673b57 970
nikapov 0:704c89673b57 971 /* FF_DUR setting */
nikapov 0:704c89673b57 972 if ( LSM6DSL_ACC_GYRO_W_FF_Duration( (void *)this, 0x00 ) == MEMS_ERROR )
nikapov 0:704c89673b57 973 {
nikapov 0:704c89673b57 974 return 1;
nikapov 0:704c89673b57 975 }
nikapov 0:704c89673b57 976
nikapov 0:704c89673b57 977 /* FF_THS setting */
nikapov 0:704c89673b57 978 if ( LSM6DSL_ACC_GYRO_W_FF_THS( (void *)this, LSM6DSL_ACC_GYRO_FF_THS_156mg ) == MEMS_ERROR )
nikapov 0:704c89673b57 979 {
nikapov 0:704c89673b57 980 return 1;
nikapov 0:704c89673b57 981 }
nikapov 0:704c89673b57 982
nikapov 0:704c89673b57 983 return 0;
nikapov 0:704c89673b57 984 }
nikapov 0:704c89673b57 985
nikapov 0:704c89673b57 986 /**
nikapov 0:704c89673b57 987 * @brief Set the free fall detection threshold for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 988 * @param thr the threshold to be set
nikapov 0:704c89673b57 989 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 990 */
nikapov 0:704c89673b57 991 int LSM6DSLSensor::set_free_fall_threshold(uint8_t thr)
nikapov 0:704c89673b57 992 {
nikapov 0:704c89673b57 993
nikapov 0:704c89673b57 994 if ( LSM6DSL_ACC_GYRO_W_FF_THS( (void *)this, (LSM6DSL_ACC_GYRO_FF_THS_t)thr ) == MEMS_ERROR )
nikapov 0:704c89673b57 995 {
nikapov 0:704c89673b57 996 return 1;
nikapov 0:704c89673b57 997 }
nikapov 0:704c89673b57 998
nikapov 0:704c89673b57 999 return 0;
nikapov 0:704c89673b57 1000 }
nikapov 0:704c89673b57 1001
nikapov 0:704c89673b57 1002 /**
nikapov 0:704c89673b57 1003 * @brief Enable the pedometer feature for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1004 * @note This function sets the LSM6DSL accelerometer ODR to 26Hz and the LSM6DSL accelerometer full scale to 2g
nikapov 0:704c89673b57 1005 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1006 */
nikapov 0:704c89673b57 1007 int LSM6DSLSensor::enable_pedometer(void)
nikapov 0:704c89673b57 1008 {
nikapov 0:704c89673b57 1009 /* Output Data Rate selection */
nikapov 0:704c89673b57 1010 if( set_x_odr(26.0f) == 1 )
nikapov 0:704c89673b57 1011 {
nikapov 0:704c89673b57 1012 return 1;
nikapov 0:704c89673b57 1013 }
nikapov 0:704c89673b57 1014
nikapov 0:704c89673b57 1015 /* Full scale selection. */
nikapov 0:704c89673b57 1016 if( set_x_fs(2.0f) == 1 )
nikapov 0:704c89673b57 1017 {
nikapov 0:704c89673b57 1018 return 1;
nikapov 0:704c89673b57 1019 }
nikapov 0:704c89673b57 1020
nikapov 0:704c89673b57 1021 /* Set pedometer threshold. */
nikapov 0:704c89673b57 1022 if ( set_pedometer_threshold(LSM6DSL_PEDOMETER_THRESHOLD_MID_HIGH) == 1 )
nikapov 0:704c89673b57 1023 {
nikapov 0:704c89673b57 1024 return 1;
nikapov 0:704c89673b57 1025 }
nikapov 0:704c89673b57 1026
nikapov 0:704c89673b57 1027 /* Enable embedded functionalities. */
nikapov 0:704c89673b57 1028 if ( LSM6DSL_ACC_GYRO_W_FUNC_EN( (void *)this, LSM6DSL_ACC_GYRO_FUNC_EN_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1029 {
nikapov 0:704c89673b57 1030 return 1;
nikapov 0:704c89673b57 1031 }
nikapov 0:704c89673b57 1032
nikapov 0:704c89673b57 1033 /* Enable pedometer algorithm. */
nikapov 0:704c89673b57 1034 if ( LSM6DSL_ACC_GYRO_W_PEDO( (void *)this, LSM6DSL_ACC_GYRO_PEDO_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1035 {
nikapov 0:704c89673b57 1036 return 1;
nikapov 0:704c89673b57 1037 }
nikapov 0:704c89673b57 1038
nikapov 0:704c89673b57 1039 /* Enable pedometer on INT1. */
nikapov 0:704c89673b57 1040 if ( LSM6DSL_ACC_GYRO_W_STEP_DET_on_INT1( (void *)this, LSM6DSL_ACC_GYRO_INT1_PEDO_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1041 {
nikapov 0:704c89673b57 1042 return 1;
nikapov 0:704c89673b57 1043 }
nikapov 0:704c89673b57 1044
nikapov 0:704c89673b57 1045 return 0;
nikapov 0:704c89673b57 1046 }
nikapov 0:704c89673b57 1047
nikapov 0:704c89673b57 1048 /**
nikapov 0:704c89673b57 1049 * @brief Disable the pedometer feature for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1050 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1051 */
nikapov 0:704c89673b57 1052 int LSM6DSLSensor::disable_pedometer(void)
nikapov 0:704c89673b57 1053 {
nikapov 0:704c89673b57 1054 /* Disable pedometer on INT1. */
nikapov 0:704c89673b57 1055 if ( LSM6DSL_ACC_GYRO_W_STEP_DET_on_INT1( (void *)this, LSM6DSL_ACC_GYRO_INT1_PEDO_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1056 {
nikapov 0:704c89673b57 1057 return 1;
nikapov 0:704c89673b57 1058 }
nikapov 0:704c89673b57 1059
nikapov 0:704c89673b57 1060 /* Disable pedometer algorithm. */
nikapov 0:704c89673b57 1061 if ( LSM6DSL_ACC_GYRO_W_PEDO( (void *)this, LSM6DSL_ACC_GYRO_PEDO_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1062 {
nikapov 0:704c89673b57 1063 return 1;
nikapov 0:704c89673b57 1064 }
nikapov 0:704c89673b57 1065
nikapov 0:704c89673b57 1066 /* Disable embedded functionalities. */
nikapov 0:704c89673b57 1067 if ( LSM6DSL_ACC_GYRO_W_FUNC_EN( (void *)this, LSM6DSL_ACC_GYRO_FUNC_EN_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1068 {
nikapov 0:704c89673b57 1069 return 1;
nikapov 0:704c89673b57 1070 }
nikapov 0:704c89673b57 1071
nikapov 0:704c89673b57 1072 /* Reset pedometer threshold. */
nikapov 0:704c89673b57 1073 if ( set_pedometer_threshold(0x0) == 1 )
nikapov 0:704c89673b57 1074 {
nikapov 0:704c89673b57 1075 return 1;
nikapov 0:704c89673b57 1076 }
nikapov 0:704c89673b57 1077
nikapov 0:704c89673b57 1078 return 0;
nikapov 0:704c89673b57 1079 }
nikapov 0:704c89673b57 1080
nikapov 0:704c89673b57 1081 /**
nikapov 0:704c89673b57 1082 * @brief Get the step counter for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1083 * @param step_count the pointer to the step counter
nikapov 0:704c89673b57 1084 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1085 */
nikapov 0:704c89673b57 1086 int LSM6DSLSensor::get_step_counter(uint16_t *step_count)
nikapov 0:704c89673b57 1087 {
nikapov 0:704c89673b57 1088 if ( LSM6DSL_ACC_GYRO_Get_GetStepCounter( (void *)this, ( uint8_t* )step_count ) == MEMS_ERROR )
nikapov 0:704c89673b57 1089 {
nikapov 0:704c89673b57 1090 return 1;
nikapov 0:704c89673b57 1091 }
nikapov 0:704c89673b57 1092
nikapov 0:704c89673b57 1093 return 0;
nikapov 0:704c89673b57 1094 }
nikapov 0:704c89673b57 1095
nikapov 0:704c89673b57 1096 /**
nikapov 0:704c89673b57 1097 * @brief Reset of the step counter for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1098 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1099 */
nikapov 0:704c89673b57 1100 int LSM6DSLSensor::reset_step_counter(void)
nikapov 0:704c89673b57 1101 {
nikapov 0:704c89673b57 1102 if ( LSM6DSL_ACC_GYRO_W_PedoStepReset( (void *)this, LSM6DSL_ACC_GYRO_PEDO_RST_STEP_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1103 {
nikapov 0:704c89673b57 1104 return 1;
nikapov 0:704c89673b57 1105 }
nikapov 0:704c89673b57 1106
cparata 9:fad44d0eacd4 1107 #if MBED_MAJOR_VERSION == 5
cparata 8:9a1017389cc7 1108 wait_ms(10);
cparata 8:9a1017389cc7 1109 #else
cparata 8:9a1017389cc7 1110 ThisThread::sleep_for(10ms);
cparata 8:9a1017389cc7 1111 #endif
nikapov 0:704c89673b57 1112
nikapov 0:704c89673b57 1113 if ( LSM6DSL_ACC_GYRO_W_PedoStepReset( (void *)this, LSM6DSL_ACC_GYRO_PEDO_RST_STEP_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1114 {
nikapov 0:704c89673b57 1115 return 1;
nikapov 0:704c89673b57 1116 }
nikapov 0:704c89673b57 1117
nikapov 0:704c89673b57 1118 return 0;
nikapov 0:704c89673b57 1119 }
nikapov 0:704c89673b57 1120
nikapov 0:704c89673b57 1121 /**
nikapov 0:704c89673b57 1122 * @brief Set the pedometer threshold for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1123 * @param thr the threshold to be set
nikapov 0:704c89673b57 1124 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1125 */
nikapov 0:704c89673b57 1126 int LSM6DSLSensor::set_pedometer_threshold(uint8_t thr)
nikapov 0:704c89673b57 1127 {
nikapov 0:704c89673b57 1128 if ( LSM6DSL_ACC_GYRO_W_PedoThreshold( (void *)this, thr ) == MEMS_ERROR )
nikapov 0:704c89673b57 1129 {
nikapov 0:704c89673b57 1130 return 1;
nikapov 0:704c89673b57 1131 }
nikapov 0:704c89673b57 1132
nikapov 0:704c89673b57 1133 return 0;
nikapov 0:704c89673b57 1134 }
nikapov 0:704c89673b57 1135
nikapov 0:704c89673b57 1136 /**
nikapov 0:704c89673b57 1137 * @brief Enable the tilt detection for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1138 * @param pin the interrupt pin to be used
nikapov 0:704c89673b57 1139 * @note This function sets the LSM6DSL accelerometer ODR to 26Hz and the LSM6DSL accelerometer full scale to 2g
nikapov 0:704c89673b57 1140 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1141 */
nikapov 0:704c89673b57 1142 int LSM6DSLSensor::enable_tilt_detection(LSM6DSL_Interrupt_Pin_t pin)
nikapov 0:704c89673b57 1143 {
nikapov 0:704c89673b57 1144 /* Output Data Rate selection */
nikapov 0:704c89673b57 1145 if( set_x_odr(26.0f) == 1 )
nikapov 0:704c89673b57 1146 {
nikapov 0:704c89673b57 1147 return 1;
nikapov 0:704c89673b57 1148 }
nikapov 0:704c89673b57 1149
nikapov 0:704c89673b57 1150 /* Full scale selection. */
nikapov 0:704c89673b57 1151 if( set_x_fs(2.0f) == 1 )
nikapov 0:704c89673b57 1152 {
nikapov 0:704c89673b57 1153 return 1;
nikapov 0:704c89673b57 1154 }
nikapov 0:704c89673b57 1155
nikapov 0:704c89673b57 1156 /* Enable embedded functionalities */
nikapov 0:704c89673b57 1157 if ( LSM6DSL_ACC_GYRO_W_FUNC_EN( (void *)this, LSM6DSL_ACC_GYRO_FUNC_EN_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1158 {
nikapov 0:704c89673b57 1159 return 1;
nikapov 0:704c89673b57 1160 }
nikapov 0:704c89673b57 1161
nikapov 0:704c89673b57 1162 /* Enable tilt calculation. */
nikapov 0:704c89673b57 1163 if ( LSM6DSL_ACC_GYRO_W_TILT( (void *)this, LSM6DSL_ACC_GYRO_TILT_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1164 {
nikapov 0:704c89673b57 1165 return 1;
nikapov 0:704c89673b57 1166 }
nikapov 0:704c89673b57 1167
nikapov 0:704c89673b57 1168 /* Enable tilt detection on either INT1 or INT2 pin */
nikapov 0:704c89673b57 1169 switch (pin)
nikapov 0:704c89673b57 1170 {
nikapov 0:704c89673b57 1171 case LSM6DSL_INT1_PIN:
nikapov 0:704c89673b57 1172 if ( LSM6DSL_ACC_GYRO_W_TiltEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_TILT_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1173 {
nikapov 0:704c89673b57 1174 return 1;
nikapov 0:704c89673b57 1175 }
nikapov 0:704c89673b57 1176 break;
nikapov 0:704c89673b57 1177
nikapov 0:704c89673b57 1178 case LSM6DSL_INT2_PIN:
nikapov 0:704c89673b57 1179 if ( LSM6DSL_ACC_GYRO_W_TiltEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_TILT_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1180 {
nikapov 0:704c89673b57 1181 return 1;
nikapov 0:704c89673b57 1182 }
nikapov 0:704c89673b57 1183 break;
nikapov 0:704c89673b57 1184
nikapov 0:704c89673b57 1185 default:
nikapov 0:704c89673b57 1186 return 1;
nikapov 0:704c89673b57 1187 }
nikapov 0:704c89673b57 1188
nikapov 0:704c89673b57 1189 return 0;
nikapov 0:704c89673b57 1190 }
nikapov 0:704c89673b57 1191
nikapov 0:704c89673b57 1192 /**
nikapov 0:704c89673b57 1193 * @brief Disable the tilt detection for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1194 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1195 */
nikapov 0:704c89673b57 1196 int LSM6DSLSensor::disable_tilt_detection(void)
nikapov 0:704c89673b57 1197 {
nikapov 0:704c89673b57 1198 /* Disable tilt event on INT1. */
nikapov 0:704c89673b57 1199 if ( LSM6DSL_ACC_GYRO_W_TiltEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_TILT_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1200 {
nikapov 0:704c89673b57 1201 return 1;
nikapov 0:704c89673b57 1202 }
nikapov 0:704c89673b57 1203
nikapov 0:704c89673b57 1204 /* Disable tilt event on INT2. */
nikapov 0:704c89673b57 1205 if ( LSM6DSL_ACC_GYRO_W_TiltEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_TILT_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1206 {
nikapov 0:704c89673b57 1207 return 1;
nikapov 0:704c89673b57 1208 }
nikapov 0:704c89673b57 1209
nikapov 0:704c89673b57 1210 /* Disable tilt calculation. */
nikapov 0:704c89673b57 1211 if ( LSM6DSL_ACC_GYRO_W_TILT( (void *)this, LSM6DSL_ACC_GYRO_TILT_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1212 {
nikapov 0:704c89673b57 1213 return 1;
nikapov 0:704c89673b57 1214 }
nikapov 0:704c89673b57 1215
nikapov 0:704c89673b57 1216 /* Disable embedded functionalities */
nikapov 0:704c89673b57 1217 if ( LSM6DSL_ACC_GYRO_W_FUNC_EN( (void *)this, LSM6DSL_ACC_GYRO_FUNC_EN_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1218 {
nikapov 0:704c89673b57 1219 return 1;
nikapov 0:704c89673b57 1220 }
nikapov 0:704c89673b57 1221
nikapov 0:704c89673b57 1222 return 0;
nikapov 0:704c89673b57 1223 }
nikapov 0:704c89673b57 1224
nikapov 0:704c89673b57 1225 /**
nikapov 0:704c89673b57 1226 * @brief Enable the wake up detection for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1227 * @param pin the interrupt pin to be used
nikapov 0:704c89673b57 1228 * @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g
nikapov 0:704c89673b57 1229 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1230 */
nikapov 0:704c89673b57 1231 int LSM6DSLSensor::enable_wake_up_detection(LSM6DSL_Interrupt_Pin_t pin)
nikapov 0:704c89673b57 1232 {
nikapov 0:704c89673b57 1233 /* Output Data Rate selection */
nikapov 0:704c89673b57 1234 if( set_x_odr(416.0f) == 1 )
nikapov 0:704c89673b57 1235 {
nikapov 0:704c89673b57 1236 return 1;
nikapov 0:704c89673b57 1237 }
nikapov 0:704c89673b57 1238
nikapov 0:704c89673b57 1239 /* Full scale selection. */
nikapov 0:704c89673b57 1240 if( set_x_fs(2.0f) == 1 )
nikapov 0:704c89673b57 1241 {
nikapov 0:704c89673b57 1242 return 1;
nikapov 0:704c89673b57 1243 }
nikapov 0:704c89673b57 1244
nikapov 0:704c89673b57 1245 /* WAKE_DUR setting */
nikapov 0:704c89673b57 1246 if ( LSM6DSL_ACC_GYRO_W_WAKE_DUR( (void *)this, 0x00 ) == MEMS_ERROR )
nikapov 0:704c89673b57 1247 {
nikapov 0:704c89673b57 1248 return 1;
nikapov 0:704c89673b57 1249 }
nikapov 0:704c89673b57 1250
nikapov 0:704c89673b57 1251 /* Set wake up threshold. */
nikapov 0:704c89673b57 1252 if ( LSM6DSL_ACC_GYRO_W_WK_THS( (void *)this, 0x02 ) == MEMS_ERROR )
nikapov 0:704c89673b57 1253 {
nikapov 0:704c89673b57 1254 return 1;
nikapov 0:704c89673b57 1255 }
nikapov 0:704c89673b57 1256
nikapov 0:704c89673b57 1257 /* Enable basic Interrupts */
nikapov 0:704c89673b57 1258 if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1259 {
nikapov 0:704c89673b57 1260 return 1;
nikapov 0:704c89673b57 1261 }
nikapov 0:704c89673b57 1262
nikapov 0:704c89673b57 1263 /* Enable wake up detection on either INT1 or INT2 pin */
nikapov 0:704c89673b57 1264 switch (pin)
nikapov 0:704c89673b57 1265 {
nikapov 0:704c89673b57 1266 case LSM6DSL_INT1_PIN:
nikapov 0:704c89673b57 1267 if ( LSM6DSL_ACC_GYRO_W_WUEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_WU_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1268 {
nikapov 0:704c89673b57 1269 return 1;
nikapov 0:704c89673b57 1270 }
nikapov 0:704c89673b57 1271 break;
nikapov 0:704c89673b57 1272
nikapov 0:704c89673b57 1273 case LSM6DSL_INT2_PIN:
nikapov 0:704c89673b57 1274 if ( LSM6DSL_ACC_GYRO_W_WUEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_WU_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1275 {
nikapov 0:704c89673b57 1276 return 1;
nikapov 0:704c89673b57 1277 }
nikapov 0:704c89673b57 1278 break;
nikapov 0:704c89673b57 1279
nikapov 0:704c89673b57 1280 default:
nikapov 0:704c89673b57 1281 return 1;
nikapov 0:704c89673b57 1282 }
nikapov 0:704c89673b57 1283
nikapov 0:704c89673b57 1284 return 0;
nikapov 0:704c89673b57 1285 }
nikapov 0:704c89673b57 1286
nikapov 0:704c89673b57 1287 /**
nikapov 0:704c89673b57 1288 * @brief Disable the wake up detection for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1289 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1290 */
nikapov 0:704c89673b57 1291 int LSM6DSLSensor::disable_wake_up_detection(void)
nikapov 0:704c89673b57 1292 {
nikapov 0:704c89673b57 1293 /* Disable wake up event on INT1 */
nikapov 0:704c89673b57 1294 if ( LSM6DSL_ACC_GYRO_W_WUEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_WU_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1295 {
nikapov 0:704c89673b57 1296 return 1;
nikapov 0:704c89673b57 1297 }
nikapov 0:704c89673b57 1298
nikapov 0:704c89673b57 1299 /* Disable wake up event on INT2 */
nikapov 0:704c89673b57 1300 if ( LSM6DSL_ACC_GYRO_W_WUEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_WU_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1301 {
nikapov 0:704c89673b57 1302 return 1;
nikapov 0:704c89673b57 1303 }
nikapov 0:704c89673b57 1304
nikapov 0:704c89673b57 1305 /* Disable basic Interrupts */
nikapov 0:704c89673b57 1306 if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1307 {
nikapov 0:704c89673b57 1308 return 1;
nikapov 0:704c89673b57 1309 }
nikapov 0:704c89673b57 1310
nikapov 0:704c89673b57 1311 /* WU_DUR setting */
nikapov 0:704c89673b57 1312 if ( LSM6DSL_ACC_GYRO_W_WAKE_DUR( (void *)this, 0x00 ) == MEMS_ERROR )
nikapov 0:704c89673b57 1313 {
nikapov 0:704c89673b57 1314 return 1;
nikapov 0:704c89673b57 1315 }
nikapov 0:704c89673b57 1316
nikapov 0:704c89673b57 1317 /* WU_THS setting */
nikapov 0:704c89673b57 1318 if ( LSM6DSL_ACC_GYRO_W_WK_THS( (void *)this, 0x00 ) == MEMS_ERROR )
nikapov 0:704c89673b57 1319 {
nikapov 0:704c89673b57 1320 return 1;
nikapov 0:704c89673b57 1321 }
nikapov 0:704c89673b57 1322
nikapov 0:704c89673b57 1323 return 0;
nikapov 0:704c89673b57 1324 }
nikapov 0:704c89673b57 1325
nikapov 0:704c89673b57 1326 /**
nikapov 0:704c89673b57 1327 * @brief Set the wake up threshold for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1328 * @param thr the threshold to be set
nikapov 0:704c89673b57 1329 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1330 */
nikapov 0:704c89673b57 1331 int LSM6DSLSensor::set_wake_up_threshold(uint8_t thr)
nikapov 0:704c89673b57 1332 {
nikapov 0:704c89673b57 1333 if ( LSM6DSL_ACC_GYRO_W_WK_THS( (void *)this, thr ) == MEMS_ERROR )
nikapov 0:704c89673b57 1334 {
nikapov 0:704c89673b57 1335 return 1;
nikapov 0:704c89673b57 1336 }
nikapov 0:704c89673b57 1337
nikapov 0:704c89673b57 1338 return 0;
nikapov 0:704c89673b57 1339 }
nikapov 0:704c89673b57 1340
nikapov 0:704c89673b57 1341 /**
nikapov 0:704c89673b57 1342 * @brief Enable the single tap detection for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1343 * @param pin the interrupt pin to be used
nikapov 0:704c89673b57 1344 * @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g
nikapov 0:704c89673b57 1345 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1346 */
nikapov 0:704c89673b57 1347 int LSM6DSLSensor::enable_single_tap_detection(LSM6DSL_Interrupt_Pin_t pin)
nikapov 0:704c89673b57 1348 {
nikapov 0:704c89673b57 1349 /* Output Data Rate selection */
nikapov 0:704c89673b57 1350 if( set_x_odr(416.0f) == 1 )
nikapov 0:704c89673b57 1351 {
nikapov 0:704c89673b57 1352 return 1;
nikapov 0:704c89673b57 1353 }
nikapov 0:704c89673b57 1354
nikapov 0:704c89673b57 1355 /* Full scale selection. */
nikapov 0:704c89673b57 1356 if( set_x_fs(2.0f) == 1 )
nikapov 0:704c89673b57 1357 {
nikapov 0:704c89673b57 1358 return 1;
nikapov 0:704c89673b57 1359 }
nikapov 0:704c89673b57 1360
nikapov 0:704c89673b57 1361 /* Enable X direction in tap recognition. */
nikapov 0:704c89673b57 1362 if ( LSM6DSL_ACC_GYRO_W_TAP_X_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_X_EN_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1363 {
nikapov 0:704c89673b57 1364 return 1;
nikapov 0:704c89673b57 1365 }
nikapov 0:704c89673b57 1366
nikapov 0:704c89673b57 1367 /* Enable Y direction in tap recognition. */
nikapov 0:704c89673b57 1368 if ( LSM6DSL_ACC_GYRO_W_TAP_Y_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Y_EN_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1369 {
nikapov 0:704c89673b57 1370 return 1;
nikapov 0:704c89673b57 1371 }
nikapov 0:704c89673b57 1372
nikapov 0:704c89673b57 1373 /* Enable Z direction in tap recognition. */
nikapov 0:704c89673b57 1374 if ( LSM6DSL_ACC_GYRO_W_TAP_Z_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Z_EN_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1375 {
nikapov 0:704c89673b57 1376 return 1;
nikapov 0:704c89673b57 1377 }
nikapov 0:704c89673b57 1378
nikapov 0:704c89673b57 1379 /* Set tap threshold. */
nikapov 0:704c89673b57 1380 if ( set_tap_threshold( LSM6DSL_TAP_THRESHOLD_MID_LOW ) == 1 )
nikapov 0:704c89673b57 1381 {
nikapov 0:704c89673b57 1382 return 1;
nikapov 0:704c89673b57 1383 }
nikapov 0:704c89673b57 1384
nikapov 0:704c89673b57 1385 /* Set tap shock time window. */
nikapov 0:704c89673b57 1386 if ( set_tap_shock_time( LSM6DSL_TAP_SHOCK_TIME_MID_HIGH ) == 1 )
nikapov 0:704c89673b57 1387 {
nikapov 0:704c89673b57 1388 return 1;
nikapov 0:704c89673b57 1389 }
nikapov 0:704c89673b57 1390
nikapov 0:704c89673b57 1391 /* Set tap quiet time window. */
nikapov 0:704c89673b57 1392 if ( set_tap_quiet_time( LSM6DSL_TAP_QUIET_TIME_MID_LOW ) == 1 )
nikapov 0:704c89673b57 1393 {
nikapov 0:704c89673b57 1394 return 1;
nikapov 0:704c89673b57 1395 }
nikapov 0:704c89673b57 1396
nikapov 0:704c89673b57 1397 /* _NOTE_: Tap duration time window - don't care for single tap. */
nikapov 0:704c89673b57 1398
nikapov 0:704c89673b57 1399 /* _NOTE_: Single/Double Tap event - don't care of this flag for single tap. */
nikapov 0:704c89673b57 1400
nikapov 0:704c89673b57 1401 /* Enable basic Interrupts */
nikapov 0:704c89673b57 1402 if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1403 {
nikapov 0:704c89673b57 1404 return 1;
nikapov 0:704c89673b57 1405 }
nikapov 0:704c89673b57 1406
nikapov 0:704c89673b57 1407 /* Enable single tap on either INT1 or INT2 pin */
nikapov 0:704c89673b57 1408 switch (pin)
nikapov 0:704c89673b57 1409 {
nikapov 0:704c89673b57 1410 case LSM6DSL_INT1_PIN:
nikapov 0:704c89673b57 1411 if ( LSM6DSL_ACC_GYRO_W_SingleTapOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_SINGLE_TAP_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1412 {
nikapov 0:704c89673b57 1413 return 1;
nikapov 0:704c89673b57 1414 }
nikapov 0:704c89673b57 1415 break;
nikapov 0:704c89673b57 1416
nikapov 0:704c89673b57 1417 case LSM6DSL_INT2_PIN:
nikapov 0:704c89673b57 1418 if ( LSM6DSL_ACC_GYRO_W_SingleTapOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_SINGLE_TAP_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1419 {
nikapov 0:704c89673b57 1420 return 1;
nikapov 0:704c89673b57 1421 }
nikapov 0:704c89673b57 1422 break;
nikapov 0:704c89673b57 1423
nikapov 0:704c89673b57 1424 default:
nikapov 0:704c89673b57 1425 return 1;
nikapov 0:704c89673b57 1426 }
nikapov 0:704c89673b57 1427
nikapov 0:704c89673b57 1428 return 0;
nikapov 0:704c89673b57 1429 }
nikapov 0:704c89673b57 1430
nikapov 0:704c89673b57 1431 /**
nikapov 0:704c89673b57 1432 * @brief Disable the single tap detection for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1433 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1434 */
nikapov 0:704c89673b57 1435 int LSM6DSLSensor::disable_single_tap_detection(void)
nikapov 0:704c89673b57 1436 {
nikapov 0:704c89673b57 1437 /* Disable single tap interrupt on INT1 pin. */
nikapov 0:704c89673b57 1438 if ( LSM6DSL_ACC_GYRO_W_SingleTapOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_SINGLE_TAP_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1439 {
nikapov 0:704c89673b57 1440 return 1;
nikapov 0:704c89673b57 1441 }
nikapov 0:704c89673b57 1442
nikapov 0:704c89673b57 1443 /* Disable single tap interrupt on INT2 pin. */
nikapov 0:704c89673b57 1444 if ( LSM6DSL_ACC_GYRO_W_SingleTapOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_SINGLE_TAP_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1445 {
nikapov 0:704c89673b57 1446 return 1;
nikapov 0:704c89673b57 1447 }
nikapov 0:704c89673b57 1448
nikapov 0:704c89673b57 1449 /* Disable basic Interrupts */
nikapov 0:704c89673b57 1450 if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1451 {
nikapov 0:704c89673b57 1452 return 1;
nikapov 0:704c89673b57 1453 }
nikapov 0:704c89673b57 1454
nikapov 0:704c89673b57 1455 /* Reset tap threshold. */
nikapov 0:704c89673b57 1456 if ( set_tap_threshold( 0x0 ) == 1 )
nikapov 0:704c89673b57 1457 {
nikapov 0:704c89673b57 1458 return 1;
nikapov 0:704c89673b57 1459 }
nikapov 0:704c89673b57 1460
nikapov 0:704c89673b57 1461 /* Reset tap shock time window. */
nikapov 0:704c89673b57 1462 if ( set_tap_shock_time( 0x0 ) == 1 )
nikapov 0:704c89673b57 1463 {
nikapov 0:704c89673b57 1464 return 1;
nikapov 0:704c89673b57 1465 }
nikapov 0:704c89673b57 1466
nikapov 0:704c89673b57 1467 /* Reset tap quiet time window. */
nikapov 0:704c89673b57 1468 if ( set_tap_quiet_time( 0x0 ) == 1 )
nikapov 0:704c89673b57 1469 {
nikapov 0:704c89673b57 1470 return 1;
nikapov 0:704c89673b57 1471 }
nikapov 0:704c89673b57 1472
nikapov 0:704c89673b57 1473 /* _NOTE_: Tap duration time window - don't care for single tap. */
nikapov 0:704c89673b57 1474
nikapov 0:704c89673b57 1475 /* _NOTE_: Single/Double Tap event - don't care of this flag for single tap. */
nikapov 0:704c89673b57 1476
nikapov 0:704c89673b57 1477 /* Disable Z direction in tap recognition. */
nikapov 0:704c89673b57 1478 if ( LSM6DSL_ACC_GYRO_W_TAP_Z_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Z_EN_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1479 {
nikapov 0:704c89673b57 1480 return 1;
nikapov 0:704c89673b57 1481 }
nikapov 0:704c89673b57 1482
nikapov 0:704c89673b57 1483 /* Disable Y direction in tap recognition. */
nikapov 0:704c89673b57 1484 if ( LSM6DSL_ACC_GYRO_W_TAP_Y_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Y_EN_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1485 {
nikapov 0:704c89673b57 1486 return 1;
nikapov 0:704c89673b57 1487 }
nikapov 0:704c89673b57 1488
nikapov 0:704c89673b57 1489 /* Disable X direction in tap recognition. */
nikapov 0:704c89673b57 1490 if ( LSM6DSL_ACC_GYRO_W_TAP_X_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_X_EN_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1491 {
nikapov 0:704c89673b57 1492 return 1;
nikapov 0:704c89673b57 1493 }
nikapov 0:704c89673b57 1494
nikapov 0:704c89673b57 1495 return 0;
nikapov 0:704c89673b57 1496 }
nikapov 0:704c89673b57 1497
nikapov 0:704c89673b57 1498 /**
nikapov 0:704c89673b57 1499 * @brief Enable the double tap detection for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1500 * @param pin the interrupt pin to be used
nikapov 0:704c89673b57 1501 * @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g
nikapov 0:704c89673b57 1502 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1503 */
nikapov 0:704c89673b57 1504 int LSM6DSLSensor::enable_double_tap_detection(LSM6DSL_Interrupt_Pin_t pin)
nikapov 0:704c89673b57 1505 {
nikapov 0:704c89673b57 1506 /* Output Data Rate selection */
nikapov 0:704c89673b57 1507 if( set_x_odr(416.0f) == 1 )
nikapov 0:704c89673b57 1508 {
nikapov 0:704c89673b57 1509 return 1;
nikapov 0:704c89673b57 1510 }
nikapov 0:704c89673b57 1511
nikapov 0:704c89673b57 1512 /* Full scale selection. */
nikapov 0:704c89673b57 1513 if( set_x_fs(2.0f) == 1 )
nikapov 0:704c89673b57 1514 {
nikapov 0:704c89673b57 1515 return 1;
nikapov 0:704c89673b57 1516 }
nikapov 0:704c89673b57 1517
nikapov 0:704c89673b57 1518 /* Enable X direction in tap recognition. */
nikapov 0:704c89673b57 1519 if ( LSM6DSL_ACC_GYRO_W_TAP_X_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_X_EN_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1520 {
nikapov 0:704c89673b57 1521 return 1;
nikapov 0:704c89673b57 1522 }
nikapov 0:704c89673b57 1523
nikapov 0:704c89673b57 1524 /* Enable Y direction in tap recognition. */
nikapov 0:704c89673b57 1525 if ( LSM6DSL_ACC_GYRO_W_TAP_Y_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Y_EN_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1526 {
nikapov 0:704c89673b57 1527 return 1;
nikapov 0:704c89673b57 1528 }
nikapov 0:704c89673b57 1529
nikapov 0:704c89673b57 1530 /* Enable Z direction in tap recognition. */
nikapov 0:704c89673b57 1531 if ( LSM6DSL_ACC_GYRO_W_TAP_Z_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Z_EN_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1532 {
nikapov 0:704c89673b57 1533 return 1;
nikapov 0:704c89673b57 1534 }
nikapov 0:704c89673b57 1535
nikapov 0:704c89673b57 1536 /* Set tap threshold. */
nikapov 0:704c89673b57 1537 if ( set_tap_threshold( LSM6DSL_TAP_THRESHOLD_MID_LOW ) == 1 )
nikapov 0:704c89673b57 1538 {
nikapov 0:704c89673b57 1539 return 1;
nikapov 0:704c89673b57 1540 }
nikapov 0:704c89673b57 1541
nikapov 0:704c89673b57 1542 /* Set tap shock time window. */
nikapov 0:704c89673b57 1543 if ( set_tap_shock_time( LSM6DSL_TAP_SHOCK_TIME_HIGH ) == 1 )
nikapov 0:704c89673b57 1544 {
nikapov 0:704c89673b57 1545 return 1;
nikapov 0:704c89673b57 1546 }
nikapov 0:704c89673b57 1547
nikapov 0:704c89673b57 1548 /* Set tap quiet time window. */
nikapov 0:704c89673b57 1549 if ( set_tap_quiet_time( LSM6DSL_TAP_QUIET_TIME_HIGH ) == 1 )
nikapov 0:704c89673b57 1550 {
nikapov 0:704c89673b57 1551 return 1;
nikapov 0:704c89673b57 1552 }
nikapov 0:704c89673b57 1553
nikapov 0:704c89673b57 1554 /* Set tap duration time window. */
nikapov 0:704c89673b57 1555 if ( set_tap_duration_time( LSM6DSL_TAP_DURATION_TIME_MID ) == 1 )
nikapov 0:704c89673b57 1556 {
nikapov 0:704c89673b57 1557 return 1;
nikapov 0:704c89673b57 1558 }
nikapov 0:704c89673b57 1559
nikapov 0:704c89673b57 1560 /* Single and double tap enabled. */
nikapov 0:704c89673b57 1561 if ( LSM6DSL_ACC_GYRO_W_SINGLE_DOUBLE_TAP_EV( (void *)this, LSM6DSL_ACC_GYRO_SINGLE_DOUBLE_TAP_DOUBLE_TAP ) == MEMS_ERROR )
nikapov 0:704c89673b57 1562 {
nikapov 0:704c89673b57 1563 return 1;
nikapov 0:704c89673b57 1564 }
nikapov 0:704c89673b57 1565
nikapov 0:704c89673b57 1566 /* Enable basic Interrupts */
nikapov 0:704c89673b57 1567 if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1568 {
nikapov 0:704c89673b57 1569 return 1;
nikapov 0:704c89673b57 1570 }
nikapov 0:704c89673b57 1571
nikapov 0:704c89673b57 1572 /* Enable double tap on either INT1 or INT2 pin */
nikapov 0:704c89673b57 1573 switch (pin)
nikapov 0:704c89673b57 1574 {
nikapov 0:704c89673b57 1575 case LSM6DSL_INT1_PIN:
nikapov 0:704c89673b57 1576 if ( LSM6DSL_ACC_GYRO_W_TapEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_TAP_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1577 {
nikapov 0:704c89673b57 1578 return 1;
nikapov 0:704c89673b57 1579 }
nikapov 0:704c89673b57 1580 break;
nikapov 0:704c89673b57 1581
nikapov 0:704c89673b57 1582 case LSM6DSL_INT2_PIN:
nikapov 0:704c89673b57 1583 if ( LSM6DSL_ACC_GYRO_W_TapEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_TAP_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1584 {
nikapov 0:704c89673b57 1585 return 1;
nikapov 0:704c89673b57 1586 }
nikapov 0:704c89673b57 1587 break;
nikapov 0:704c89673b57 1588
nikapov 0:704c89673b57 1589 default:
nikapov 0:704c89673b57 1590 return 1;
nikapov 0:704c89673b57 1591 }
nikapov 0:704c89673b57 1592
nikapov 0:704c89673b57 1593 return 0;
nikapov 0:704c89673b57 1594 }
nikapov 0:704c89673b57 1595
nikapov 0:704c89673b57 1596 /**
nikapov 0:704c89673b57 1597 * @brief Disable the double tap detection for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1598 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1599 */
nikapov 0:704c89673b57 1600 int LSM6DSLSensor::disable_double_tap_detection(void)
nikapov 0:704c89673b57 1601 {
nikapov 0:704c89673b57 1602 /* Disable double tap interrupt on INT1 pin. */
nikapov 0:704c89673b57 1603 if ( LSM6DSL_ACC_GYRO_W_TapEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_TAP_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1604 {
nikapov 0:704c89673b57 1605 return 1;
nikapov 0:704c89673b57 1606 }
nikapov 0:704c89673b57 1607
nikapov 0:704c89673b57 1608 /* Disable double tap interrupt on INT2 pin. */
nikapov 0:704c89673b57 1609 if ( LSM6DSL_ACC_GYRO_W_TapEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_TAP_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1610 {
nikapov 0:704c89673b57 1611 return 1;
nikapov 0:704c89673b57 1612 }
nikapov 0:704c89673b57 1613
nikapov 0:704c89673b57 1614 /* Disable basic Interrupts */
nikapov 0:704c89673b57 1615 if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1616 {
nikapov 0:704c89673b57 1617 return 1;
nikapov 0:704c89673b57 1618 }
nikapov 0:704c89673b57 1619
nikapov 0:704c89673b57 1620 /* Reset tap threshold. */
nikapov 0:704c89673b57 1621 if ( set_tap_threshold( 0x0 ) == 1 )
nikapov 0:704c89673b57 1622 {
nikapov 0:704c89673b57 1623 return 1;
nikapov 0:704c89673b57 1624 }
nikapov 0:704c89673b57 1625
nikapov 0:704c89673b57 1626 /* Reset tap shock time window. */
nikapov 0:704c89673b57 1627 if ( set_tap_shock_time( 0x0 ) == 1 )
nikapov 0:704c89673b57 1628 {
nikapov 0:704c89673b57 1629 return 1;
nikapov 0:704c89673b57 1630 }
nikapov 0:704c89673b57 1631
nikapov 0:704c89673b57 1632 /* Reset tap quiet time window. */
nikapov 0:704c89673b57 1633 if ( set_tap_quiet_time( 0x0 ) == 1 )
nikapov 0:704c89673b57 1634 {
nikapov 0:704c89673b57 1635 return 1;
nikapov 0:704c89673b57 1636 }
nikapov 0:704c89673b57 1637
nikapov 0:704c89673b57 1638 /* Reset tap duration time window. */
nikapov 0:704c89673b57 1639 if ( set_tap_duration_time( 0x0 ) == 1 )
nikapov 0:704c89673b57 1640 {
nikapov 0:704c89673b57 1641 return 1;
nikapov 0:704c89673b57 1642 }
nikapov 0:704c89673b57 1643
nikapov 0:704c89673b57 1644 /* Only single tap enabled. */
nikapov 0:704c89673b57 1645 if ( LSM6DSL_ACC_GYRO_W_SINGLE_DOUBLE_TAP_EV( (void *)this, LSM6DSL_ACC_GYRO_SINGLE_DOUBLE_TAP_SINGLE_TAP ) == MEMS_ERROR )
nikapov 0:704c89673b57 1646 {
nikapov 0:704c89673b57 1647 return 1;
nikapov 0:704c89673b57 1648 }
nikapov 0:704c89673b57 1649
nikapov 0:704c89673b57 1650 /* Disable Z direction in tap recognition. */
nikapov 0:704c89673b57 1651 if ( LSM6DSL_ACC_GYRO_W_TAP_Z_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Z_EN_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1652 {
nikapov 0:704c89673b57 1653 return 1;
nikapov 0:704c89673b57 1654 }
nikapov 0:704c89673b57 1655
nikapov 0:704c89673b57 1656 /* Disable Y direction in tap recognition. */
nikapov 0:704c89673b57 1657 if ( LSM6DSL_ACC_GYRO_W_TAP_Y_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Y_EN_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1658 {
nikapov 0:704c89673b57 1659 return 1;
nikapov 0:704c89673b57 1660 }
nikapov 0:704c89673b57 1661
nikapov 0:704c89673b57 1662 /* Disable X direction in tap recognition. */
nikapov 0:704c89673b57 1663 if ( LSM6DSL_ACC_GYRO_W_TAP_X_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_X_EN_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1664 {
nikapov 0:704c89673b57 1665 return 1;
nikapov 0:704c89673b57 1666 }
nikapov 0:704c89673b57 1667
nikapov 0:704c89673b57 1668 return 0;
nikapov 0:704c89673b57 1669 }
nikapov 0:704c89673b57 1670
nikapov 0:704c89673b57 1671 /**
nikapov 0:704c89673b57 1672 * @brief Set the tap threshold for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1673 * @param thr the threshold to be set
nikapov 0:704c89673b57 1674 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1675 */
nikapov 0:704c89673b57 1676 int LSM6DSLSensor::set_tap_threshold(uint8_t thr)
nikapov 0:704c89673b57 1677 {
nikapov 0:704c89673b57 1678 if ( LSM6DSL_ACC_GYRO_W_TAP_THS( (void *)this, thr ) == MEMS_ERROR )
nikapov 0:704c89673b57 1679 {
nikapov 0:704c89673b57 1680 return 1;
nikapov 0:704c89673b57 1681 }
nikapov 0:704c89673b57 1682
nikapov 0:704c89673b57 1683 return 0;
nikapov 0:704c89673b57 1684 }
nikapov 0:704c89673b57 1685
nikapov 0:704c89673b57 1686 /**
nikapov 0:704c89673b57 1687 * @brief Set the tap shock time window for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1688 * @param time the shock time window to be set
nikapov 0:704c89673b57 1689 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1690 */
nikapov 0:704c89673b57 1691 int LSM6DSLSensor::set_tap_shock_time(uint8_t time)
nikapov 0:704c89673b57 1692 {
nikapov 0:704c89673b57 1693 if ( LSM6DSL_ACC_GYRO_W_SHOCK_Duration( (void *)this, time ) == MEMS_ERROR )
nikapov 0:704c89673b57 1694 {
nikapov 0:704c89673b57 1695 return 1;
nikapov 0:704c89673b57 1696 }
nikapov 0:704c89673b57 1697
nikapov 0:704c89673b57 1698 return 0;
nikapov 0:704c89673b57 1699 }
nikapov 0:704c89673b57 1700
nikapov 0:704c89673b57 1701 /**
nikapov 0:704c89673b57 1702 * @brief Set the tap quiet time window for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1703 * @param time the quiet time window to be set
nikapov 0:704c89673b57 1704 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1705 */
nikapov 0:704c89673b57 1706 int LSM6DSLSensor::set_tap_quiet_time(uint8_t time)
nikapov 0:704c89673b57 1707 {
nikapov 0:704c89673b57 1708 if ( LSM6DSL_ACC_GYRO_W_QUIET_Duration( (void *)this, time ) == MEMS_ERROR )
nikapov 0:704c89673b57 1709 {
nikapov 0:704c89673b57 1710 return 1;
nikapov 0:704c89673b57 1711 }
nikapov 0:704c89673b57 1712
nikapov 0:704c89673b57 1713 return 0;
nikapov 0:704c89673b57 1714 }
nikapov 0:704c89673b57 1715
nikapov 0:704c89673b57 1716 /**
nikapov 0:704c89673b57 1717 * @brief Set the tap duration of the time window for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1718 * @param time the duration of the time window to be set
nikapov 0:704c89673b57 1719 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1720 */
nikapov 0:704c89673b57 1721 int LSM6DSLSensor::set_tap_duration_time(uint8_t time)
nikapov 0:704c89673b57 1722 {
nikapov 0:704c89673b57 1723 if ( LSM6DSL_ACC_GYRO_W_DUR( (void *)this, time ) == MEMS_ERROR )
nikapov 0:704c89673b57 1724 {
nikapov 0:704c89673b57 1725 return 1;
nikapov 0:704c89673b57 1726 }
nikapov 0:704c89673b57 1727
nikapov 0:704c89673b57 1728 return 0;
nikapov 0:704c89673b57 1729 }
nikapov 0:704c89673b57 1730
nikapov 0:704c89673b57 1731 /**
nikapov 0:704c89673b57 1732 * @brief Enable the 6D orientation detection for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1733 * @param pin the interrupt pin to be used
nikapov 0:704c89673b57 1734 * @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g
nikapov 0:704c89673b57 1735 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1736 */
nikapov 0:704c89673b57 1737 int LSM6DSLSensor::enable_6d_orientation(LSM6DSL_Interrupt_Pin_t pin)
nikapov 0:704c89673b57 1738 {
nikapov 0:704c89673b57 1739 /* Output Data Rate selection */
nikapov 0:704c89673b57 1740 if( set_x_odr(416.0f) == 1 )
nikapov 0:704c89673b57 1741 {
nikapov 0:704c89673b57 1742 return 1;
nikapov 0:704c89673b57 1743 }
nikapov 0:704c89673b57 1744
nikapov 0:704c89673b57 1745 /* Full scale selection. */
nikapov 0:704c89673b57 1746 if( set_x_fs(2.0f) == 1 )
nikapov 0:704c89673b57 1747 {
nikapov 0:704c89673b57 1748 return 1;
nikapov 0:704c89673b57 1749 }
nikapov 0:704c89673b57 1750
nikapov 0:704c89673b57 1751 /* Set 6D threshold. */
nikapov 0:704c89673b57 1752 if ( LSM6DSL_ACC_GYRO_W_SIXD_THS( (void *)this, LSM6DSL_ACC_GYRO_SIXD_THS_60_degree ) == MEMS_ERROR )
nikapov 0:704c89673b57 1753 {
nikapov 0:704c89673b57 1754 return 1;
nikapov 0:704c89673b57 1755 }
nikapov 0:704c89673b57 1756
nikapov 0:704c89673b57 1757 /* Enable basic Interrupts */
nikapov 0:704c89673b57 1758 if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1759 {
nikapov 0:704c89673b57 1760 return 1;
nikapov 0:704c89673b57 1761 }
nikapov 0:704c89673b57 1762
nikapov 0:704c89673b57 1763 /* Enable 6D orientation on either INT1 or INT2 pin */
nikapov 0:704c89673b57 1764 switch (pin)
nikapov 0:704c89673b57 1765 {
nikapov 0:704c89673b57 1766 case LSM6DSL_INT1_PIN:
nikapov 0:704c89673b57 1767 if ( LSM6DSL_ACC_GYRO_W_6DEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_6D_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1768 {
nikapov 0:704c89673b57 1769 return 1;
nikapov 0:704c89673b57 1770 }
nikapov 0:704c89673b57 1771 break;
nikapov 0:704c89673b57 1772
nikapov 0:704c89673b57 1773 case LSM6DSL_INT2_PIN:
nikapov 0:704c89673b57 1774 if ( LSM6DSL_ACC_GYRO_W_6DEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_6D_ENABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1775 {
nikapov 0:704c89673b57 1776 return 1;
nikapov 0:704c89673b57 1777 }
nikapov 0:704c89673b57 1778 break;
nikapov 0:704c89673b57 1779
nikapov 0:704c89673b57 1780 default:
nikapov 0:704c89673b57 1781 return 1;
nikapov 0:704c89673b57 1782 }
nikapov 0:704c89673b57 1783
nikapov 0:704c89673b57 1784 return 0;
nikapov 0:704c89673b57 1785 }
nikapov 0:704c89673b57 1786
nikapov 0:704c89673b57 1787 /**
nikapov 0:704c89673b57 1788 * @brief Disable the 6D orientation detection for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1789 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1790 */
nikapov 0:704c89673b57 1791 int LSM6DSLSensor::disable_6d_orientation(void)
nikapov 0:704c89673b57 1792 {
nikapov 0:704c89673b57 1793 /* Disable 6D orientation interrupt on INT1 pin. */
nikapov 0:704c89673b57 1794 if ( LSM6DSL_ACC_GYRO_W_6DEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_6D_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1795 {
nikapov 0:704c89673b57 1796 return 1;
nikapov 0:704c89673b57 1797 }
nikapov 0:704c89673b57 1798
nikapov 0:704c89673b57 1799 /* Disable 6D orientation interrupt on INT2 pin. */
nikapov 0:704c89673b57 1800 if ( LSM6DSL_ACC_GYRO_W_6DEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_6D_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1801 {
nikapov 0:704c89673b57 1802 return 1;
nikapov 0:704c89673b57 1803 }
nikapov 0:704c89673b57 1804
nikapov 0:704c89673b57 1805 /* Disable basic Interrupts */
nikapov 0:704c89673b57 1806 if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_DISABLED ) == MEMS_ERROR )
nikapov 0:704c89673b57 1807 {
nikapov 0:704c89673b57 1808 return 1;
nikapov 0:704c89673b57 1809 }
nikapov 0:704c89673b57 1810
nikapov 0:704c89673b57 1811 /* Reset 6D threshold. */
nikapov 0:704c89673b57 1812 if ( LSM6DSL_ACC_GYRO_W_SIXD_THS( (void *)this, LSM6DSL_ACC_GYRO_SIXD_THS_80_degree ) == MEMS_ERROR )
nikapov 0:704c89673b57 1813 {
nikapov 0:704c89673b57 1814 return 1;
nikapov 0:704c89673b57 1815 }
nikapov 0:704c89673b57 1816
nikapov 0:704c89673b57 1817 return 0;
nikapov 0:704c89673b57 1818 }
nikapov 0:704c89673b57 1819
nikapov 0:704c89673b57 1820 /**
nikapov 0:704c89673b57 1821 * @brief Get the 6D orientation XL axis for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1822 * @param xl the pointer to the 6D orientation XL axis
nikapov 0:704c89673b57 1823 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1824 */
nikapov 0:704c89673b57 1825 int LSM6DSLSensor::get_6d_orientation_xl(uint8_t *xl)
nikapov 0:704c89673b57 1826 {
nikapov 0:704c89673b57 1827 LSM6DSL_ACC_GYRO_DSD_XL_t xl_raw;
nikapov 0:704c89673b57 1828
nikapov 0:704c89673b57 1829 if ( LSM6DSL_ACC_GYRO_R_DSD_XL( (void *)this, &xl_raw ) == MEMS_ERROR )
nikapov 0:704c89673b57 1830 {
nikapov 0:704c89673b57 1831 return 1;
nikapov 0:704c89673b57 1832 }
nikapov 0:704c89673b57 1833
nikapov 0:704c89673b57 1834 switch( xl_raw )
nikapov 0:704c89673b57 1835 {
nikapov 0:704c89673b57 1836 case LSM6DSL_ACC_GYRO_DSD_XL_DETECTED:
nikapov 0:704c89673b57 1837 *xl = 1;
nikapov 0:704c89673b57 1838 break;
nikapov 0:704c89673b57 1839 case LSM6DSL_ACC_GYRO_DSD_XL_NOT_DETECTED:
nikapov 0:704c89673b57 1840 *xl = 0;
nikapov 0:704c89673b57 1841 break;
nikapov 0:704c89673b57 1842 default:
nikapov 0:704c89673b57 1843 return 1;
nikapov 0:704c89673b57 1844 }
nikapov 0:704c89673b57 1845
nikapov 0:704c89673b57 1846 return 0;
nikapov 0:704c89673b57 1847 }
nikapov 0:704c89673b57 1848
nikapov 0:704c89673b57 1849 /**
nikapov 0:704c89673b57 1850 * @brief Get the 6D orientation XH axis for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1851 * @param xh the pointer to the 6D orientation XH axis
nikapov 0:704c89673b57 1852 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1853 */
nikapov 0:704c89673b57 1854 int LSM6DSLSensor::get_6d_orientation_xh(uint8_t *xh)
nikapov 0:704c89673b57 1855 {
nikapov 0:704c89673b57 1856 LSM6DSL_ACC_GYRO_DSD_XH_t xh_raw;
nikapov 0:704c89673b57 1857
nikapov 0:704c89673b57 1858 if ( LSM6DSL_ACC_GYRO_R_DSD_XH( (void *)this, &xh_raw ) == MEMS_ERROR )
nikapov 0:704c89673b57 1859 {
nikapov 0:704c89673b57 1860 return 1;
nikapov 0:704c89673b57 1861 }
nikapov 0:704c89673b57 1862
nikapov 0:704c89673b57 1863 switch( xh_raw )
nikapov 0:704c89673b57 1864 {
nikapov 0:704c89673b57 1865 case LSM6DSL_ACC_GYRO_DSD_XH_DETECTED:
nikapov 0:704c89673b57 1866 *xh = 1;
nikapov 0:704c89673b57 1867 break;
nikapov 0:704c89673b57 1868 case LSM6DSL_ACC_GYRO_DSD_XH_NOT_DETECTED:
nikapov 0:704c89673b57 1869 *xh = 0;
nikapov 0:704c89673b57 1870 break;
nikapov 0:704c89673b57 1871 default:
nikapov 0:704c89673b57 1872 return 1;
nikapov 0:704c89673b57 1873 }
nikapov 0:704c89673b57 1874
nikapov 0:704c89673b57 1875 return 0;
nikapov 0:704c89673b57 1876 }
nikapov 0:704c89673b57 1877
nikapov 0:704c89673b57 1878 /**
nikapov 0:704c89673b57 1879 * @brief Get the 6D orientation YL axis for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1880 * @param yl the pointer to the 6D orientation YL axis
nikapov 0:704c89673b57 1881 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1882 */
nikapov 0:704c89673b57 1883 int LSM6DSLSensor::get_6d_orientation_yl(uint8_t *yl)
nikapov 0:704c89673b57 1884 {
nikapov 0:704c89673b57 1885 LSM6DSL_ACC_GYRO_DSD_YL_t yl_raw;
nikapov 0:704c89673b57 1886
nikapov 0:704c89673b57 1887 if ( LSM6DSL_ACC_GYRO_R_DSD_YL( (void *)this, &yl_raw ) == MEMS_ERROR )
nikapov 0:704c89673b57 1888 {
nikapov 0:704c89673b57 1889 return 1;
nikapov 0:704c89673b57 1890 }
nikapov 0:704c89673b57 1891
nikapov 0:704c89673b57 1892 switch( yl_raw )
nikapov 0:704c89673b57 1893 {
nikapov 0:704c89673b57 1894 case LSM6DSL_ACC_GYRO_DSD_YL_DETECTED:
nikapov 0:704c89673b57 1895 *yl = 1;
nikapov 0:704c89673b57 1896 break;
nikapov 0:704c89673b57 1897 case LSM6DSL_ACC_GYRO_DSD_YL_NOT_DETECTED:
nikapov 0:704c89673b57 1898 *yl = 0;
nikapov 0:704c89673b57 1899 break;
nikapov 0:704c89673b57 1900 default:
nikapov 0:704c89673b57 1901 return 1;
nikapov 0:704c89673b57 1902 }
nikapov 0:704c89673b57 1903
nikapov 0:704c89673b57 1904 return 0;
nikapov 0:704c89673b57 1905 }
nikapov 0:704c89673b57 1906
nikapov 0:704c89673b57 1907 /**
nikapov 0:704c89673b57 1908 * @brief Get the 6D orientation YH axis for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1909 * @param yh the pointer to the 6D orientation YH axis
nikapov 0:704c89673b57 1910 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1911 */
nikapov 0:704c89673b57 1912 int LSM6DSLSensor::get_6d_orientation_yh(uint8_t *yh)
nikapov 0:704c89673b57 1913 {
nikapov 0:704c89673b57 1914 LSM6DSL_ACC_GYRO_DSD_YH_t yh_raw;
nikapov 0:704c89673b57 1915
nikapov 0:704c89673b57 1916 if ( LSM6DSL_ACC_GYRO_R_DSD_YH( (void *)this, &yh_raw ) == MEMS_ERROR )
nikapov 0:704c89673b57 1917 {
nikapov 0:704c89673b57 1918 return 1;
nikapov 0:704c89673b57 1919 }
nikapov 0:704c89673b57 1920
nikapov 0:704c89673b57 1921 switch( yh_raw )
nikapov 0:704c89673b57 1922 {
nikapov 0:704c89673b57 1923 case LSM6DSL_ACC_GYRO_DSD_YH_DETECTED:
nikapov 0:704c89673b57 1924 *yh = 1;
nikapov 0:704c89673b57 1925 break;
nikapov 0:704c89673b57 1926 case LSM6DSL_ACC_GYRO_DSD_YH_NOT_DETECTED:
nikapov 0:704c89673b57 1927 *yh = 0;
nikapov 0:704c89673b57 1928 break;
nikapov 0:704c89673b57 1929 default:
nikapov 0:704c89673b57 1930 return 1;
nikapov 0:704c89673b57 1931 }
nikapov 0:704c89673b57 1932
nikapov 0:704c89673b57 1933 return 0;
nikapov 0:704c89673b57 1934 }
nikapov 0:704c89673b57 1935
nikapov 0:704c89673b57 1936 /**
nikapov 0:704c89673b57 1937 * @brief Get the 6D orientation ZL axis for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1938 * @param zl the pointer to the 6D orientation ZL axis
nikapov 0:704c89673b57 1939 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1940 */
nikapov 0:704c89673b57 1941 int LSM6DSLSensor::get_6d_orientation_zl(uint8_t *zl)
nikapov 0:704c89673b57 1942 {
nikapov 0:704c89673b57 1943 LSM6DSL_ACC_GYRO_DSD_ZL_t zl_raw;
nikapov 0:704c89673b57 1944
nikapov 0:704c89673b57 1945 if ( LSM6DSL_ACC_GYRO_R_DSD_ZL( (void *)this, &zl_raw ) == MEMS_ERROR )
nikapov 0:704c89673b57 1946 {
nikapov 0:704c89673b57 1947 return 1;
nikapov 0:704c89673b57 1948 }
nikapov 0:704c89673b57 1949
nikapov 0:704c89673b57 1950 switch( zl_raw )
nikapov 0:704c89673b57 1951 {
nikapov 0:704c89673b57 1952 case LSM6DSL_ACC_GYRO_DSD_ZL_DETECTED:
nikapov 0:704c89673b57 1953 *zl = 1;
nikapov 0:704c89673b57 1954 break;
nikapov 0:704c89673b57 1955 case LSM6DSL_ACC_GYRO_DSD_ZL_NOT_DETECTED:
nikapov 0:704c89673b57 1956 *zl = 0;
nikapov 0:704c89673b57 1957 break;
nikapov 0:704c89673b57 1958 default:
nikapov 0:704c89673b57 1959 return 1;
nikapov 0:704c89673b57 1960 }
nikapov 0:704c89673b57 1961
nikapov 0:704c89673b57 1962 return 0;
nikapov 0:704c89673b57 1963 }
nikapov 0:704c89673b57 1964
nikapov 0:704c89673b57 1965 /**
nikapov 0:704c89673b57 1966 * @brief Get the 6D orientation ZH axis for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1967 * @param zh the pointer to the 6D orientation ZH axis
nikapov 0:704c89673b57 1968 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1969 */
nikapov 0:704c89673b57 1970 int LSM6DSLSensor::get_6d_orientation_zh(uint8_t *zh)
nikapov 0:704c89673b57 1971 {
nikapov 0:704c89673b57 1972 LSM6DSL_ACC_GYRO_DSD_ZH_t zh_raw;
nikapov 0:704c89673b57 1973
nikapov 0:704c89673b57 1974 if ( LSM6DSL_ACC_GYRO_R_DSD_ZH( (void *)this, &zh_raw ) == MEMS_ERROR )
nikapov 0:704c89673b57 1975 {
nikapov 0:704c89673b57 1976 return 1;
nikapov 0:704c89673b57 1977 }
nikapov 0:704c89673b57 1978
nikapov 0:704c89673b57 1979 switch( zh_raw )
nikapov 0:704c89673b57 1980 {
nikapov 0:704c89673b57 1981 case LSM6DSL_ACC_GYRO_DSD_ZH_DETECTED:
nikapov 0:704c89673b57 1982 *zh = 1;
nikapov 0:704c89673b57 1983 break;
nikapov 0:704c89673b57 1984 case LSM6DSL_ACC_GYRO_DSD_ZH_NOT_DETECTED:
nikapov 0:704c89673b57 1985 *zh = 0;
nikapov 0:704c89673b57 1986 break;
nikapov 0:704c89673b57 1987 default:
nikapov 0:704c89673b57 1988 return 1;
nikapov 0:704c89673b57 1989 }
nikapov 0:704c89673b57 1990
nikapov 0:704c89673b57 1991 return 0;
nikapov 0:704c89673b57 1992 }
nikapov 0:704c89673b57 1993
nikapov 0:704c89673b57 1994 /**
nikapov 0:704c89673b57 1995 * @brief Get the status of all hardware events for LSM6DSL accelerometer sensor
nikapov 0:704c89673b57 1996 * @param status the pointer to the status of all hardware events
nikapov 0:704c89673b57 1997 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 1998 */
nikapov 0:704c89673b57 1999 int LSM6DSLSensor::get_event_status(LSM6DSL_Event_Status_t *status)
nikapov 0:704c89673b57 2000 {
nikapov 0:704c89673b57 2001 uint8_t Wake_Up_Src = 0, Tap_Src = 0, D6D_Src = 0, Func_Src = 0, Md1_Cfg = 0, Md2_Cfg = 0, Int1_Ctrl = 0;
nikapov 0:704c89673b57 2002
nikapov 0:704c89673b57 2003 memset((void *)status, 0x0, sizeof(LSM6DSL_Event_Status_t));
nikapov 0:704c89673b57 2004
nikapov 0:704c89673b57 2005 if(read_reg(LSM6DSL_ACC_GYRO_WAKE_UP_SRC, &Wake_Up_Src) != 0)
nikapov 0:704c89673b57 2006 {
nikapov 0:704c89673b57 2007 return 1;
nikapov 0:704c89673b57 2008 }
nikapov 0:704c89673b57 2009
nikapov 0:704c89673b57 2010 if(read_reg(LSM6DSL_ACC_GYRO_TAP_SRC, &Tap_Src) != 0)
nikapov 0:704c89673b57 2011 {
nikapov 0:704c89673b57 2012 return 1;
nikapov 0:704c89673b57 2013 }
nikapov 0:704c89673b57 2014
nikapov 0:704c89673b57 2015 if(read_reg(LSM6DSL_ACC_GYRO_D6D_SRC, &D6D_Src) != 0)
nikapov 0:704c89673b57 2016 {
nikapov 0:704c89673b57 2017 return 1;
nikapov 0:704c89673b57 2018 }
nikapov 0:704c89673b57 2019
nikapov 0:704c89673b57 2020 if(read_reg(LSM6DSL_ACC_GYRO_FUNC_SRC, &Func_Src) != 0)
nikapov 0:704c89673b57 2021 {
nikapov 0:704c89673b57 2022 return 1;
nikapov 0:704c89673b57 2023 }
nikapov 0:704c89673b57 2024
nikapov 0:704c89673b57 2025 if(read_reg(LSM6DSL_ACC_GYRO_MD1_CFG, &Md1_Cfg ) != 0 )
nikapov 0:704c89673b57 2026 {
nikapov 0:704c89673b57 2027 return 1;
nikapov 0:704c89673b57 2028 }
nikapov 0:704c89673b57 2029
nikapov 0:704c89673b57 2030 if(read_reg(LSM6DSL_ACC_GYRO_MD2_CFG, &Md2_Cfg ) != 0)
nikapov 0:704c89673b57 2031 {
nikapov 0:704c89673b57 2032 return 1;
nikapov 0:704c89673b57 2033 }
nikapov 0:704c89673b57 2034
nikapov 0:704c89673b57 2035 if(read_reg(LSM6DSL_ACC_GYRO_INT1_CTRL, &Int1_Ctrl ) != 0)
nikapov 0:704c89673b57 2036 {
nikapov 0:704c89673b57 2037 return 1;
nikapov 0:704c89673b57 2038 }
nikapov 0:704c89673b57 2039
nikapov 0:704c89673b57 2040 if((Md1_Cfg & LSM6DSL_ACC_GYRO_INT1_FF_MASK) || (Md2_Cfg & LSM6DSL_ACC_GYRO_INT2_FF_MASK))
nikapov 0:704c89673b57 2041 {
nikapov 0:704c89673b57 2042 if((Wake_Up_Src & LSM6DSL_ACC_GYRO_FF_EV_STATUS_MASK))
nikapov 0:704c89673b57 2043 {
nikapov 0:704c89673b57 2044 status->FreeFallStatus = 1;
nikapov 0:704c89673b57 2045 }
nikapov 0:704c89673b57 2046 }
nikapov 0:704c89673b57 2047
nikapov 0:704c89673b57 2048 if((Md1_Cfg & LSM6DSL_ACC_GYRO_INT1_WU_MASK) || (Md2_Cfg & LSM6DSL_ACC_GYRO_INT2_WU_MASK))
nikapov 0:704c89673b57 2049 {
nikapov 0:704c89673b57 2050 if((Wake_Up_Src & LSM6DSL_ACC_GYRO_WU_EV_STATUS_MASK))
nikapov 0:704c89673b57 2051 {
nikapov 0:704c89673b57 2052 status->WakeUpStatus = 1;
nikapov 0:704c89673b57 2053 }
nikapov 0:704c89673b57 2054 }
nikapov 0:704c89673b57 2055
nikapov 0:704c89673b57 2056 if((Md1_Cfg & LSM6DSL_ACC_GYRO_INT1_SINGLE_TAP_MASK) || (Md2_Cfg & LSM6DSL_ACC_GYRO_INT2_SINGLE_TAP_MASK))
nikapov 0:704c89673b57 2057 {
nikapov 0:704c89673b57 2058 if((Tap_Src & LSM6DSL_ACC_GYRO_SINGLE_TAP_EV_STATUS_MASK))
nikapov 0:704c89673b57 2059 {
nikapov 0:704c89673b57 2060 status->TapStatus = 1;
nikapov 0:704c89673b57 2061 }
nikapov 0:704c89673b57 2062 }
nikapov 0:704c89673b57 2063
nikapov 0:704c89673b57 2064 if((Md1_Cfg & LSM6DSL_ACC_GYRO_INT1_TAP_MASK) || (Md2_Cfg & LSM6DSL_ACC_GYRO_INT2_TAP_MASK))
nikapov 0:704c89673b57 2065 {
nikapov 0:704c89673b57 2066 if((Tap_Src & LSM6DSL_ACC_GYRO_DOUBLE_TAP_EV_STATUS_MASK))
nikapov 0:704c89673b57 2067 {
nikapov 0:704c89673b57 2068 status->DoubleTapStatus = 1;
nikapov 0:704c89673b57 2069 }
nikapov 0:704c89673b57 2070 }
nikapov 0:704c89673b57 2071
nikapov 0:704c89673b57 2072 if((Md1_Cfg & LSM6DSL_ACC_GYRO_INT1_6D_MASK) || (Md2_Cfg & LSM6DSL_ACC_GYRO_INT2_6D_MASK))
nikapov 0:704c89673b57 2073 {
nikapov 0:704c89673b57 2074 if((D6D_Src & LSM6DSL_ACC_GYRO_D6D_EV_STATUS_MASK))
nikapov 0:704c89673b57 2075 {
nikapov 0:704c89673b57 2076 status->D6DOrientationStatus = 1;
nikapov 0:704c89673b57 2077 }
nikapov 0:704c89673b57 2078 }
nikapov 0:704c89673b57 2079
nikapov 0:704c89673b57 2080 if((Int1_Ctrl & LSM6DSL_ACC_GYRO_INT1_PEDO_MASK))
nikapov 0:704c89673b57 2081 {
nikapov 0:704c89673b57 2082 if((Func_Src & LSM6DSL_ACC_GYRO_PEDO_EV_STATUS_MASK))
nikapov 0:704c89673b57 2083 {
nikapov 0:704c89673b57 2084 status->StepStatus = 1;
nikapov 0:704c89673b57 2085 }
nikapov 0:704c89673b57 2086 }
nikapov 0:704c89673b57 2087
nikapov 0:704c89673b57 2088 if((Md1_Cfg & LSM6DSL_ACC_GYRO_INT1_TILT_MASK) || (Md2_Cfg & LSM6DSL_ACC_GYRO_INT2_TILT_MASK))
nikapov 0:704c89673b57 2089 {
nikapov 0:704c89673b57 2090 if((Func_Src & LSM6DSL_ACC_GYRO_TILT_EV_STATUS_MASK))
nikapov 0:704c89673b57 2091 {
nikapov 0:704c89673b57 2092 status->TiltStatus = 1;
nikapov 0:704c89673b57 2093 }
nikapov 0:704c89673b57 2094 }
nikapov 0:704c89673b57 2095
nikapov 0:704c89673b57 2096 return 0;
nikapov 0:704c89673b57 2097 }
nikapov 0:704c89673b57 2098
nikapov 0:704c89673b57 2099 /**
nikapov 0:704c89673b57 2100 * @brief Read the data from register
nikapov 0:704c89673b57 2101 * @param reg register address
nikapov 0:704c89673b57 2102 * @param data register data
nikapov 0:704c89673b57 2103 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 2104 */
nikapov 0:704c89673b57 2105 int LSM6DSLSensor::read_reg( uint8_t reg, uint8_t *data )
nikapov 0:704c89673b57 2106 {
nikapov 0:704c89673b57 2107
nikapov 0:704c89673b57 2108 if ( LSM6DSL_ACC_GYRO_read_reg( (void *)this, reg, data, 1 ) == MEMS_ERROR )
nikapov 0:704c89673b57 2109 {
nikapov 0:704c89673b57 2110 return 1;
nikapov 0:704c89673b57 2111 }
nikapov 0:704c89673b57 2112
nikapov 0:704c89673b57 2113 return 0;
nikapov 0:704c89673b57 2114 }
nikapov 0:704c89673b57 2115
nikapov 0:704c89673b57 2116 /**
nikapov 0:704c89673b57 2117 * @brief Write the data to register
nikapov 0:704c89673b57 2118 * @param reg register address
nikapov 0:704c89673b57 2119 * @param data register data
nikapov 0:704c89673b57 2120 * @retval 0 in case of success, an error code otherwise
nikapov 0:704c89673b57 2121 */
nikapov 0:704c89673b57 2122 int LSM6DSLSensor::write_reg( uint8_t reg, uint8_t data )
nikapov 0:704c89673b57 2123 {
nikapov 0:704c89673b57 2124
nikapov 0:704c89673b57 2125 if ( LSM6DSL_ACC_GYRO_write_reg( (void *)this, reg, &data, 1 ) == MEMS_ERROR )
nikapov 0:704c89673b57 2126 {
nikapov 0:704c89673b57 2127 return 1;
nikapov 0:704c89673b57 2128 }
nikapov 0:704c89673b57 2129
nikapov 0:704c89673b57 2130 return 0;
nikapov 0:704c89673b57 2131 }
nikapov 0:704c89673b57 2132
nikapov 0:704c89673b57 2133
nikapov 0:704c89673b57 2134 uint8_t LSM6DSL_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite )
nikapov 0:704c89673b57 2135 {
nikapov 0:704c89673b57 2136 return ((LSM6DSLSensor *)handle)->io_write(pBuffer, WriteAddr, nBytesToWrite);
nikapov 0:704c89673b57 2137 }
nikapov 0:704c89673b57 2138
nikapov 0:704c89673b57 2139 uint8_t LSM6DSL_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead )
nikapov 0:704c89673b57 2140 {
nikapov 0:704c89673b57 2141 return ((LSM6DSLSensor *)handle)->io_read(pBuffer, ReadAddr, nBytesToRead);
nikapov 0:704c89673b57 2142 }