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