HAHA

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON

Dependents:   b_NYP_humanoid a_NYP_humanoid_copy

Fork of LSM6DSL by ST

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