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