LSM6DSO accelerometer and gyroscope sensor library
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
LSM6DSOSensor.cpp@3:4274d9103f1d, 2019-07-24 (annotated)
- Committer:
- cparata
- Date:
- Wed Jul 24 14:19:35 2019 +0000
- Revision:
- 3:4274d9103f1d
- Parent:
- 2:4d14e9edf37e
- Child:
- 4:bcf0cf6e43a7
Format with Astyle
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cparata | 0:6d69e896ce38 | 1 | /** |
cparata | 0:6d69e896ce38 | 2 | ****************************************************************************** |
cparata | 0:6d69e896ce38 | 3 | * @file LSM6DSOSensor.cpp |
cparata | 0:6d69e896ce38 | 4 | * @author SRA |
cparata | 0:6d69e896ce38 | 5 | * @version V1.0.0 |
cparata | 0:6d69e896ce38 | 6 | * @date February 2019 |
cparata | 0:6d69e896ce38 | 7 | * @brief Implementation of an LSM6DSO Inertial Measurement Unit (IMU) 6 axes |
cparata | 0:6d69e896ce38 | 8 | * sensor. |
cparata | 0:6d69e896ce38 | 9 | ****************************************************************************** |
cparata | 0:6d69e896ce38 | 10 | * @attention |
cparata | 0:6d69e896ce38 | 11 | * |
cparata | 0:6d69e896ce38 | 12 | * <h2><center>© COPYRIGHT(c) 2019 STMicroelectronics</center></h2> |
cparata | 0:6d69e896ce38 | 13 | * |
cparata | 0:6d69e896ce38 | 14 | * Redistribution and use in source and binary forms, with or without modification, |
cparata | 0:6d69e896ce38 | 15 | * are permitted provided that the following conditions are met: |
cparata | 0:6d69e896ce38 | 16 | * 1. Redistributions of source code must retain the above copyright notice, |
cparata | 0:6d69e896ce38 | 17 | * this list of conditions and the following disclaimer. |
cparata | 0:6d69e896ce38 | 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
cparata | 0:6d69e896ce38 | 19 | * this list of conditions and the following disclaimer in the documentation |
cparata | 0:6d69e896ce38 | 20 | * and/or other materials provided with the distribution. |
cparata | 0:6d69e896ce38 | 21 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
cparata | 0:6d69e896ce38 | 22 | * may be used to endorse or promote products derived from this software |
cparata | 0:6d69e896ce38 | 23 | * without specific prior written permission. |
cparata | 0:6d69e896ce38 | 24 | * |
cparata | 0:6d69e896ce38 | 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
cparata | 0:6d69e896ce38 | 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
cparata | 0:6d69e896ce38 | 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
cparata | 0:6d69e896ce38 | 28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
cparata | 0:6d69e896ce38 | 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
cparata | 0:6d69e896ce38 | 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
cparata | 0:6d69e896ce38 | 31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
cparata | 0:6d69e896ce38 | 32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
cparata | 0:6d69e896ce38 | 33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
cparata | 0:6d69e896ce38 | 34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
cparata | 0:6d69e896ce38 | 35 | * |
cparata | 0:6d69e896ce38 | 36 | ****************************************************************************** |
cparata | 0:6d69e896ce38 | 37 | */ |
cparata | 0:6d69e896ce38 | 38 | |
cparata | 0:6d69e896ce38 | 39 | |
cparata | 0:6d69e896ce38 | 40 | /* Includes ------------------------------------------------------------------*/ |
cparata | 0:6d69e896ce38 | 41 | |
cparata | 0:6d69e896ce38 | 42 | #include "LSM6DSOSensor.h" |
cparata | 0:6d69e896ce38 | 43 | |
cparata | 0:6d69e896ce38 | 44 | |
cparata | 0:6d69e896ce38 | 45 | /* Class Implementation ------------------------------------------------------*/ |
cparata | 0:6d69e896ce38 | 46 | |
cparata | 0:6d69e896ce38 | 47 | /** Constructor |
cparata | 0:6d69e896ce38 | 48 | * @param spi object of an helper class which handles the SPI peripheral |
cparata | 0:6d69e896ce38 | 49 | * @param cs_pin the chip select pin |
cparata | 0:6d69e896ce38 | 50 | * @param int1_pin the interrupt 1 pin |
cparata | 0:6d69e896ce38 | 51 | * @param int2_pin the interrupt 2 pin |
cparata | 0:6d69e896ce38 | 52 | * @param spi_type the SPI type |
cparata | 0:6d69e896ce38 | 53 | */ |
cparata | 0:6d69e896ce38 | 54 | LSM6DSOSensor::LSM6DSOSensor(SPI *spi, PinName cs_pin, PinName int1_pin, PinName int2_pin, SPI_type_t spi_type) : _dev_spi(spi), _cs_pin(cs_pin), _int1_irq(int1_pin), _int2_irq(int2_pin), _spi_type(spi_type) |
cparata | 0:6d69e896ce38 | 55 | { |
cparata | 3:4274d9103f1d | 56 | assert(spi); |
cparata | 3:4274d9103f1d | 57 | if (cs_pin == NC) { |
cparata | 3:4274d9103f1d | 58 | printf("ERROR LSM6DSO CS MUST NOT BE NC\n\r"); |
cparata | 3:4274d9103f1d | 59 | _dev_spi = NULL; |
cparata | 3:4274d9103f1d | 60 | _dev_i2c = NULL; |
cparata | 3:4274d9103f1d | 61 | return; |
cparata | 3:4274d9103f1d | 62 | } |
cparata | 3:4274d9103f1d | 63 | |
cparata | 3:4274d9103f1d | 64 | _reg_ctx.write_reg = LSM6DSO_io_write; |
cparata | 3:4274d9103f1d | 65 | _reg_ctx.read_reg = LSM6DSO_io_read; |
cparata | 3:4274d9103f1d | 66 | _reg_ctx.handle = (void *)this; |
cparata | 3:4274d9103f1d | 67 | _cs_pin = 1; |
cparata | 0:6d69e896ce38 | 68 | _dev_i2c = NULL; |
cparata | 3:4274d9103f1d | 69 | _address = 0; |
cparata | 3:4274d9103f1d | 70 | |
cparata | 3:4274d9103f1d | 71 | if (_spi_type == SPI3W) { |
cparata | 3:4274d9103f1d | 72 | /* Enable SPI 3-Wires on the component */ |
cparata | 3:4274d9103f1d | 73 | uint8_t data = 0x0C; |
cparata | 3:4274d9103f1d | 74 | lsm6dso_write_reg(&_reg_ctx, LSM6DSO_CTRL3_C, &data, 1); |
cparata | 3:4274d9103f1d | 75 | } |
cparata | 0:6d69e896ce38 | 76 | } |
cparata | 0:6d69e896ce38 | 77 | |
cparata | 0:6d69e896ce38 | 78 | |
cparata | 0:6d69e896ce38 | 79 | /** Constructor |
cparata | 0:6d69e896ce38 | 80 | * @param i2c object of an helper class which handles the I2C peripheral |
cparata | 0:6d69e896ce38 | 81 | * @param address the address of the component's instance |
cparata | 0:6d69e896ce38 | 82 | * @param int1_pin the interrupt 1 pin |
cparata | 0:6d69e896ce38 | 83 | * @param int2_pin the interrupt 2 pin |
cparata | 0:6d69e896ce38 | 84 | */ |
cparata | 0:6d69e896ce38 | 85 | LSM6DSOSensor::LSM6DSOSensor(DevI2C *i2c, uint8_t address, PinName int1_pin, PinName int2_pin) : _dev_i2c(i2c), _address(address), _cs_pin(NC), _int1_irq(int1_pin), _int2_irq(int2_pin) |
cparata | 0:6d69e896ce38 | 86 | { |
cparata | 3:4274d9103f1d | 87 | assert(i2c); |
cparata | 3:4274d9103f1d | 88 | _dev_spi = NULL; |
cparata | 3:4274d9103f1d | 89 | _reg_ctx.write_reg = LSM6DSO_io_write; |
cparata | 3:4274d9103f1d | 90 | _reg_ctx.read_reg = LSM6DSO_io_read; |
cparata | 3:4274d9103f1d | 91 | _reg_ctx.handle = (void *)this; |
cparata | 0:6d69e896ce38 | 92 | } |
cparata | 0:6d69e896ce38 | 93 | |
cparata | 0:6d69e896ce38 | 94 | /** |
cparata | 0:6d69e896ce38 | 95 | * @brief Initializing the component |
cparata | 0:6d69e896ce38 | 96 | * @param init pointer to device specific initalization structure |
cparata | 0:6d69e896ce38 | 97 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 98 | */ |
cparata | 0:6d69e896ce38 | 99 | int LSM6DSOSensor::init(void *init) |
cparata | 0:6d69e896ce38 | 100 | { |
cparata | 3:4274d9103f1d | 101 | /* Disable I3C */ |
cparata | 3:4274d9103f1d | 102 | if (lsm6dso_i3c_disable_set(&_reg_ctx, LSM6DSO_I3C_DISABLE) != 0) { |
cparata | 3:4274d9103f1d | 103 | return 1; |
cparata | 3:4274d9103f1d | 104 | } |
cparata | 3:4274d9103f1d | 105 | |
cparata | 3:4274d9103f1d | 106 | /* Enable register address automatically incremented during a multiple byte |
cparata | 3:4274d9103f1d | 107 | access with a serial interface. */ |
cparata | 3:4274d9103f1d | 108 | if (lsm6dso_auto_increment_set(&_reg_ctx, PROPERTY_ENABLE) != 0) { |
cparata | 3:4274d9103f1d | 109 | return 1; |
cparata | 3:4274d9103f1d | 110 | } |
cparata | 3:4274d9103f1d | 111 | |
cparata | 3:4274d9103f1d | 112 | /* Enable BDU */ |
cparata | 3:4274d9103f1d | 113 | if (lsm6dso_block_data_update_set(&_reg_ctx, PROPERTY_ENABLE) != 0) { |
cparata | 3:4274d9103f1d | 114 | return 1; |
cparata | 3:4274d9103f1d | 115 | } |
cparata | 3:4274d9103f1d | 116 | |
cparata | 3:4274d9103f1d | 117 | /* FIFO mode selection */ |
cparata | 3:4274d9103f1d | 118 | if (lsm6dso_fifo_mode_set(&_reg_ctx, LSM6DSO_BYPASS_MODE) != 0) { |
cparata | 3:4274d9103f1d | 119 | return 1; |
cparata | 3:4274d9103f1d | 120 | } |
cparata | 3:4274d9103f1d | 121 | |
cparata | 3:4274d9103f1d | 122 | /* Output data rate selection - power down. */ |
cparata | 3:4274d9103f1d | 123 | if (lsm6dso_xl_data_rate_set(&_reg_ctx, LSM6DSO_XL_ODR_OFF) != 0) { |
cparata | 3:4274d9103f1d | 124 | return 1; |
cparata | 3:4274d9103f1d | 125 | } |
cparata | 3:4274d9103f1d | 126 | |
cparata | 3:4274d9103f1d | 127 | /* Full scale selection. */ |
cparata | 3:4274d9103f1d | 128 | if (lsm6dso_xl_full_scale_set(&_reg_ctx, LSM6DSO_2g) != 0) { |
cparata | 3:4274d9103f1d | 129 | return 1; |
cparata | 3:4274d9103f1d | 130 | } |
cparata | 3:4274d9103f1d | 131 | |
cparata | 3:4274d9103f1d | 132 | /* Output data rate selection - power down. */ |
cparata | 3:4274d9103f1d | 133 | if (lsm6dso_gy_data_rate_set(&_reg_ctx, LSM6DSO_GY_ODR_OFF) != 0) { |
cparata | 3:4274d9103f1d | 134 | return 1; |
cparata | 3:4274d9103f1d | 135 | } |
cparata | 3:4274d9103f1d | 136 | |
cparata | 3:4274d9103f1d | 137 | /* Full scale selection. */ |
cparata | 3:4274d9103f1d | 138 | if (lsm6dso_gy_full_scale_set(&_reg_ctx, LSM6DSO_2000dps) != 0) { |
cparata | 3:4274d9103f1d | 139 | return 1; |
cparata | 3:4274d9103f1d | 140 | } |
cparata | 3:4274d9103f1d | 141 | |
cparata | 3:4274d9103f1d | 142 | /* Select default output data rate. */ |
cparata | 3:4274d9103f1d | 143 | _x_last_odr = LSM6DSO_XL_ODR_104Hz; |
cparata | 3:4274d9103f1d | 144 | |
cparata | 3:4274d9103f1d | 145 | /* Select default output data rate. */ |
cparata | 3:4274d9103f1d | 146 | _g_last_odr = LSM6DSO_GY_ODR_104Hz; |
cparata | 3:4274d9103f1d | 147 | |
cparata | 3:4274d9103f1d | 148 | _x_is_enabled = 0; |
cparata | 3:4274d9103f1d | 149 | |
cparata | 3:4274d9103f1d | 150 | _g_is_enabled = 0; |
cparata | 3:4274d9103f1d | 151 | |
cparata | 3:4274d9103f1d | 152 | return 0; |
cparata | 0:6d69e896ce38 | 153 | } |
cparata | 0:6d69e896ce38 | 154 | |
cparata | 0:6d69e896ce38 | 155 | /** |
cparata | 0:6d69e896ce38 | 156 | * @brief Read component ID |
cparata | 0:6d69e896ce38 | 157 | * @param id the WHO_AM_I value |
cparata | 0:6d69e896ce38 | 158 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 159 | */ |
cparata | 0:6d69e896ce38 | 160 | int LSM6DSOSensor::read_id(uint8_t *id) |
cparata | 0:6d69e896ce38 | 161 | { |
cparata | 3:4274d9103f1d | 162 | if (lsm6dso_device_id_get(&_reg_ctx, id) != 0) { |
cparata | 3:4274d9103f1d | 163 | return 1; |
cparata | 3:4274d9103f1d | 164 | } |
cparata | 3:4274d9103f1d | 165 | |
cparata | 3:4274d9103f1d | 166 | return 0; |
cparata | 0:6d69e896ce38 | 167 | } |
cparata | 0:6d69e896ce38 | 168 | |
cparata | 0:6d69e896ce38 | 169 | /** |
cparata | 0:6d69e896ce38 | 170 | * @brief Enable the LSM6DSO accelerometer sensor |
cparata | 0:6d69e896ce38 | 171 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 172 | */ |
cparata | 0:6d69e896ce38 | 173 | int LSM6DSOSensor::enable_x() |
cparata | 0:6d69e896ce38 | 174 | { |
cparata | 3:4274d9103f1d | 175 | /* Check if the component is already enabled */ |
cparata | 3:4274d9103f1d | 176 | if (_x_is_enabled == 1U) { |
cparata | 3:4274d9103f1d | 177 | return 0; |
cparata | 3:4274d9103f1d | 178 | } |
cparata | 3:4274d9103f1d | 179 | |
cparata | 3:4274d9103f1d | 180 | /* Output data rate selection. */ |
cparata | 3:4274d9103f1d | 181 | if (lsm6dso_xl_data_rate_set(&_reg_ctx, _x_last_odr) != 0) { |
cparata | 3:4274d9103f1d | 182 | return 1; |
cparata | 3:4274d9103f1d | 183 | } |
cparata | 3:4274d9103f1d | 184 | |
cparata | 3:4274d9103f1d | 185 | _x_is_enabled = 1; |
cparata | 3:4274d9103f1d | 186 | |
cparata | 0:6d69e896ce38 | 187 | return 0; |
cparata | 0:6d69e896ce38 | 188 | } |
cparata | 0:6d69e896ce38 | 189 | |
cparata | 0:6d69e896ce38 | 190 | /** |
cparata | 0:6d69e896ce38 | 191 | * @brief Disable the LSM6DSO accelerometer sensor |
cparata | 0:6d69e896ce38 | 192 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 193 | */ |
cparata | 0:6d69e896ce38 | 194 | int LSM6DSOSensor::disable_x() |
cparata | 0:6d69e896ce38 | 195 | { |
cparata | 3:4274d9103f1d | 196 | /* Check if the component is already disabled */ |
cparata | 3:4274d9103f1d | 197 | if (_x_is_enabled == 0U) { |
cparata | 3:4274d9103f1d | 198 | return 0; |
cparata | 3:4274d9103f1d | 199 | } |
cparata | 3:4274d9103f1d | 200 | |
cparata | 3:4274d9103f1d | 201 | /* Get current output data rate. */ |
cparata | 3:4274d9103f1d | 202 | if (lsm6dso_xl_data_rate_get(&_reg_ctx, &_x_last_odr) != 0) { |
cparata | 3:4274d9103f1d | 203 | return 1; |
cparata | 3:4274d9103f1d | 204 | } |
cparata | 3:4274d9103f1d | 205 | |
cparata | 3:4274d9103f1d | 206 | /* Output data rate selection - power down. */ |
cparata | 3:4274d9103f1d | 207 | if (lsm6dso_xl_data_rate_set(&_reg_ctx, LSM6DSO_XL_ODR_OFF) != 0) { |
cparata | 3:4274d9103f1d | 208 | return 1; |
cparata | 3:4274d9103f1d | 209 | } |
cparata | 3:4274d9103f1d | 210 | |
cparata | 3:4274d9103f1d | 211 | _x_is_enabled = 0; |
cparata | 3:4274d9103f1d | 212 | |
cparata | 0:6d69e896ce38 | 213 | return 0; |
cparata | 0:6d69e896ce38 | 214 | } |
cparata | 0:6d69e896ce38 | 215 | |
cparata | 0:6d69e896ce38 | 216 | /** |
cparata | 0:6d69e896ce38 | 217 | * @brief Get the LSM6DSO accelerometer sensor sensitivity |
cparata | 0:6d69e896ce38 | 218 | * @param sensitivity pointer where the sensitivity is written |
cparata | 0:6d69e896ce38 | 219 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 220 | */ |
cparata | 0:6d69e896ce38 | 221 | int LSM6DSOSensor::get_x_sensitivity(float *sensitivity) |
cparata | 0:6d69e896ce38 | 222 | { |
cparata | 3:4274d9103f1d | 223 | int ret = 0; |
cparata | 3:4274d9103f1d | 224 | lsm6dso_fs_xl_t full_scale; |
cparata | 3:4274d9103f1d | 225 | |
cparata | 3:4274d9103f1d | 226 | /* Read actual full scale selection from sensor. */ |
cparata | 3:4274d9103f1d | 227 | if (lsm6dso_xl_full_scale_get(&_reg_ctx, &full_scale) != 0) { |
cparata | 3:4274d9103f1d | 228 | return 1; |
cparata | 3:4274d9103f1d | 229 | } |
cparata | 3:4274d9103f1d | 230 | |
cparata | 3:4274d9103f1d | 231 | /* Store the sensitivity based on actual full scale. */ |
cparata | 3:4274d9103f1d | 232 | switch (full_scale) { |
cparata | 3:4274d9103f1d | 233 | case LSM6DSO_2g: |
cparata | 3:4274d9103f1d | 234 | *sensitivity = LSM6DSO_ACC_SENSITIVITY_FS_2G; |
cparata | 3:4274d9103f1d | 235 | break; |
cparata | 3:4274d9103f1d | 236 | |
cparata | 3:4274d9103f1d | 237 | case LSM6DSO_4g: |
cparata | 3:4274d9103f1d | 238 | *sensitivity = LSM6DSO_ACC_SENSITIVITY_FS_4G; |
cparata | 3:4274d9103f1d | 239 | break; |
cparata | 3:4274d9103f1d | 240 | |
cparata | 3:4274d9103f1d | 241 | case LSM6DSO_8g: |
cparata | 3:4274d9103f1d | 242 | *sensitivity = LSM6DSO_ACC_SENSITIVITY_FS_8G; |
cparata | 3:4274d9103f1d | 243 | break; |
cparata | 3:4274d9103f1d | 244 | |
cparata | 3:4274d9103f1d | 245 | case LSM6DSO_16g: |
cparata | 3:4274d9103f1d | 246 | *sensitivity = LSM6DSO_ACC_SENSITIVITY_FS_16G; |
cparata | 3:4274d9103f1d | 247 | break; |
cparata | 3:4274d9103f1d | 248 | |
cparata | 3:4274d9103f1d | 249 | default: |
cparata | 3:4274d9103f1d | 250 | ret = 1; |
cparata | 3:4274d9103f1d | 251 | break; |
cparata | 3:4274d9103f1d | 252 | } |
cparata | 3:4274d9103f1d | 253 | |
cparata | 3:4274d9103f1d | 254 | return ret; |
cparata | 0:6d69e896ce38 | 255 | } |
cparata | 0:6d69e896ce38 | 256 | |
cparata | 0:6d69e896ce38 | 257 | /** |
cparata | 0:6d69e896ce38 | 258 | * @brief Get the LSM6DSO accelerometer sensor output data rate |
cparata | 0:6d69e896ce38 | 259 | * @param odr pointer where the output data rate is written |
cparata | 0:6d69e896ce38 | 260 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 261 | */ |
cparata | 0:6d69e896ce38 | 262 | int LSM6DSOSensor::get_x_odr(float *odr) |
cparata | 0:6d69e896ce38 | 263 | { |
cparata | 3:4274d9103f1d | 264 | int ret = 0; |
cparata | 3:4274d9103f1d | 265 | lsm6dso_odr_xl_t odr_low_level; |
cparata | 3:4274d9103f1d | 266 | |
cparata | 3:4274d9103f1d | 267 | /* Get current output data rate. */ |
cparata | 3:4274d9103f1d | 268 | if (lsm6dso_xl_data_rate_get(&_reg_ctx, &odr_low_level) != 0) { |
cparata | 3:4274d9103f1d | 269 | return 1; |
cparata | 3:4274d9103f1d | 270 | } |
cparata | 3:4274d9103f1d | 271 | |
cparata | 3:4274d9103f1d | 272 | switch (odr_low_level) { |
cparata | 3:4274d9103f1d | 273 | case LSM6DSO_XL_ODR_OFF: |
cparata | 3:4274d9103f1d | 274 | *odr = 0.0f; |
cparata | 3:4274d9103f1d | 275 | break; |
cparata | 3:4274d9103f1d | 276 | |
cparata | 3:4274d9103f1d | 277 | case LSM6DSO_XL_ODR_6Hz5: |
cparata | 3:4274d9103f1d | 278 | *odr = 6.5f; |
cparata | 3:4274d9103f1d | 279 | break; |
cparata | 3:4274d9103f1d | 280 | |
cparata | 3:4274d9103f1d | 281 | case LSM6DSO_XL_ODR_12Hz5: |
cparata | 3:4274d9103f1d | 282 | *odr = 12.5f; |
cparata | 3:4274d9103f1d | 283 | break; |
cparata | 3:4274d9103f1d | 284 | |
cparata | 3:4274d9103f1d | 285 | case LSM6DSO_XL_ODR_26Hz: |
cparata | 3:4274d9103f1d | 286 | *odr = 26.0f; |
cparata | 3:4274d9103f1d | 287 | break; |
cparata | 3:4274d9103f1d | 288 | |
cparata | 3:4274d9103f1d | 289 | case LSM6DSO_XL_ODR_52Hz: |
cparata | 3:4274d9103f1d | 290 | *odr = 52.0f; |
cparata | 3:4274d9103f1d | 291 | break; |
cparata | 3:4274d9103f1d | 292 | |
cparata | 3:4274d9103f1d | 293 | case LSM6DSO_XL_ODR_104Hz: |
cparata | 3:4274d9103f1d | 294 | *odr = 104.0f; |
cparata | 3:4274d9103f1d | 295 | break; |
cparata | 3:4274d9103f1d | 296 | |
cparata | 3:4274d9103f1d | 297 | case LSM6DSO_XL_ODR_208Hz: |
cparata | 3:4274d9103f1d | 298 | *odr = 208.0f; |
cparata | 3:4274d9103f1d | 299 | break; |
cparata | 3:4274d9103f1d | 300 | |
cparata | 3:4274d9103f1d | 301 | case LSM6DSO_XL_ODR_417Hz: |
cparata | 3:4274d9103f1d | 302 | *odr = 417.0f; |
cparata | 3:4274d9103f1d | 303 | break; |
cparata | 3:4274d9103f1d | 304 | |
cparata | 3:4274d9103f1d | 305 | case LSM6DSO_XL_ODR_833Hz: |
cparata | 3:4274d9103f1d | 306 | *odr = 833.0f; |
cparata | 3:4274d9103f1d | 307 | break; |
cparata | 3:4274d9103f1d | 308 | |
cparata | 3:4274d9103f1d | 309 | case LSM6DSO_XL_ODR_1667Hz: |
cparata | 3:4274d9103f1d | 310 | *odr = 1667.0f; |
cparata | 3:4274d9103f1d | 311 | break; |
cparata | 3:4274d9103f1d | 312 | |
cparata | 3:4274d9103f1d | 313 | case LSM6DSO_XL_ODR_3333Hz: |
cparata | 3:4274d9103f1d | 314 | *odr = 3333.0f; |
cparata | 3:4274d9103f1d | 315 | break; |
cparata | 3:4274d9103f1d | 316 | |
cparata | 3:4274d9103f1d | 317 | case LSM6DSO_XL_ODR_6667Hz: |
cparata | 3:4274d9103f1d | 318 | *odr = 6667.0f; |
cparata | 3:4274d9103f1d | 319 | break; |
cparata | 3:4274d9103f1d | 320 | |
cparata | 3:4274d9103f1d | 321 | default: |
cparata | 3:4274d9103f1d | 322 | ret = 1; |
cparata | 3:4274d9103f1d | 323 | break; |
cparata | 3:4274d9103f1d | 324 | } |
cparata | 3:4274d9103f1d | 325 | |
cparata | 3:4274d9103f1d | 326 | return ret; |
cparata | 0:6d69e896ce38 | 327 | } |
cparata | 0:6d69e896ce38 | 328 | |
cparata | 0:6d69e896ce38 | 329 | /** |
cparata | 0:6d69e896ce38 | 330 | * @brief Set the LSM6DSO accelerometer sensor output data rate |
cparata | 0:6d69e896ce38 | 331 | * @param odr the output data rate value to be set |
cparata | 0:6d69e896ce38 | 332 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 333 | */ |
cparata | 0:6d69e896ce38 | 334 | int LSM6DSOSensor::set_x_odr(float odr) |
cparata | 0:6d69e896ce38 | 335 | { |
cparata | 3:4274d9103f1d | 336 | /* Check if the component is enabled */ |
cparata | 3:4274d9103f1d | 337 | if (_x_is_enabled == 1U) { |
cparata | 3:4274d9103f1d | 338 | return set_x_odr_when_enabled(odr); |
cparata | 3:4274d9103f1d | 339 | } else { |
cparata | 3:4274d9103f1d | 340 | return set_x_odr_when_disabled(odr); |
cparata | 3:4274d9103f1d | 341 | } |
cparata | 0:6d69e896ce38 | 342 | } |
cparata | 0:6d69e896ce38 | 343 | |
cparata | 0:6d69e896ce38 | 344 | /** |
cparata | 0:6d69e896ce38 | 345 | * @brief Set the LSM6DSO accelerometer sensor output data rate when enabled |
cparata | 0:6d69e896ce38 | 346 | * @param odr the functional output data rate to be set |
cparata | 0:6d69e896ce38 | 347 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 348 | */ |
cparata | 0:6d69e896ce38 | 349 | int LSM6DSOSensor::set_x_odr_when_enabled(float odr) |
cparata | 0:6d69e896ce38 | 350 | { |
cparata | 3:4274d9103f1d | 351 | lsm6dso_odr_xl_t new_odr; |
cparata | 3:4274d9103f1d | 352 | |
cparata | 3:4274d9103f1d | 353 | new_odr = (odr <= 12.5f) ? LSM6DSO_XL_ODR_12Hz5 |
cparata | 3:4274d9103f1d | 354 | : (odr <= 26.0f) ? LSM6DSO_XL_ODR_26Hz |
cparata | 3:4274d9103f1d | 355 | : (odr <= 52.0f) ? LSM6DSO_XL_ODR_52Hz |
cparata | 3:4274d9103f1d | 356 | : (odr <= 104.0f) ? LSM6DSO_XL_ODR_104Hz |
cparata | 3:4274d9103f1d | 357 | : (odr <= 208.0f) ? LSM6DSO_XL_ODR_208Hz |
cparata | 3:4274d9103f1d | 358 | : (odr <= 417.0f) ? LSM6DSO_XL_ODR_417Hz |
cparata | 3:4274d9103f1d | 359 | : (odr <= 833.0f) ? LSM6DSO_XL_ODR_833Hz |
cparata | 3:4274d9103f1d | 360 | : (odr <= 1667.0f) ? LSM6DSO_XL_ODR_1667Hz |
cparata | 3:4274d9103f1d | 361 | : (odr <= 3333.0f) ? LSM6DSO_XL_ODR_3333Hz |
cparata | 3:4274d9103f1d | 362 | : LSM6DSO_XL_ODR_6667Hz; |
cparata | 3:4274d9103f1d | 363 | |
cparata | 3:4274d9103f1d | 364 | /* Output data rate selection. */ |
cparata | 3:4274d9103f1d | 365 | if (lsm6dso_xl_data_rate_set(&_reg_ctx, new_odr) != 0) { |
cparata | 3:4274d9103f1d | 366 | return 1; |
cparata | 3:4274d9103f1d | 367 | } |
cparata | 3:4274d9103f1d | 368 | |
cparata | 3:4274d9103f1d | 369 | return 0; |
cparata | 0:6d69e896ce38 | 370 | } |
cparata | 0:6d69e896ce38 | 371 | |
cparata | 0:6d69e896ce38 | 372 | /** |
cparata | 0:6d69e896ce38 | 373 | * @brief Set the LSM6DSO accelerometer sensor output data rate when disabled |
cparata | 0:6d69e896ce38 | 374 | * @param odr the functional output data rate to be set |
cparata | 0:6d69e896ce38 | 375 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 376 | */ |
cparata | 0:6d69e896ce38 | 377 | int LSM6DSOSensor::set_x_odr_when_disabled(float odr) |
cparata | 0:6d69e896ce38 | 378 | { |
cparata | 3:4274d9103f1d | 379 | _x_last_odr = (odr <= 12.5f) ? LSM6DSO_XL_ODR_12Hz5 |
cparata | 3:4274d9103f1d | 380 | : (odr <= 26.0f) ? LSM6DSO_XL_ODR_26Hz |
cparata | 3:4274d9103f1d | 381 | : (odr <= 52.0f) ? LSM6DSO_XL_ODR_52Hz |
cparata | 3:4274d9103f1d | 382 | : (odr <= 104.0f) ? LSM6DSO_XL_ODR_104Hz |
cparata | 3:4274d9103f1d | 383 | : (odr <= 208.0f) ? LSM6DSO_XL_ODR_208Hz |
cparata | 3:4274d9103f1d | 384 | : (odr <= 417.0f) ? LSM6DSO_XL_ODR_417Hz |
cparata | 3:4274d9103f1d | 385 | : (odr <= 833.0f) ? LSM6DSO_XL_ODR_833Hz |
cparata | 3:4274d9103f1d | 386 | : (odr <= 1667.0f) ? LSM6DSO_XL_ODR_1667Hz |
cparata | 3:4274d9103f1d | 387 | : (odr <= 3333.0f) ? LSM6DSO_XL_ODR_3333Hz |
cparata | 3:4274d9103f1d | 388 | : LSM6DSO_XL_ODR_6667Hz; |
cparata | 3:4274d9103f1d | 389 | |
cparata | 3:4274d9103f1d | 390 | return 0; |
cparata | 0:6d69e896ce38 | 391 | } |
cparata | 0:6d69e896ce38 | 392 | |
cparata | 0:6d69e896ce38 | 393 | |
cparata | 0:6d69e896ce38 | 394 | /** |
cparata | 0:6d69e896ce38 | 395 | * @brief Get the LSM6DSO accelerometer sensor full scale |
cparata | 0:6d69e896ce38 | 396 | * @param full_scale pointer where the full scale is written |
cparata | 0:6d69e896ce38 | 397 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 398 | */ |
cparata | 0:6d69e896ce38 | 399 | int LSM6DSOSensor::get_x_fs(float *full_scale) |
cparata | 0:6d69e896ce38 | 400 | { |
cparata | 3:4274d9103f1d | 401 | int ret = 0; |
cparata | 3:4274d9103f1d | 402 | lsm6dso_fs_xl_t fs_low_level; |
cparata | 3:4274d9103f1d | 403 | |
cparata | 3:4274d9103f1d | 404 | /* Read actual full scale selection from sensor. */ |
cparata | 3:4274d9103f1d | 405 | if (lsm6dso_xl_full_scale_get(&_reg_ctx, &fs_low_level) != 0) { |
cparata | 3:4274d9103f1d | 406 | return 1; |
cparata | 3:4274d9103f1d | 407 | } |
cparata | 3:4274d9103f1d | 408 | |
cparata | 3:4274d9103f1d | 409 | switch (fs_low_level) { |
cparata | 3:4274d9103f1d | 410 | case LSM6DSO_2g: |
cparata | 3:4274d9103f1d | 411 | *full_scale = 2.0f; |
cparata | 3:4274d9103f1d | 412 | break; |
cparata | 3:4274d9103f1d | 413 | |
cparata | 3:4274d9103f1d | 414 | case LSM6DSO_4g: |
cparata | 3:4274d9103f1d | 415 | *full_scale = 4.0f; |
cparata | 3:4274d9103f1d | 416 | break; |
cparata | 3:4274d9103f1d | 417 | |
cparata | 3:4274d9103f1d | 418 | case LSM6DSO_8g: |
cparata | 3:4274d9103f1d | 419 | *full_scale = 8.0f; |
cparata | 3:4274d9103f1d | 420 | break; |
cparata | 3:4274d9103f1d | 421 | |
cparata | 3:4274d9103f1d | 422 | case LSM6DSO_16g: |
cparata | 3:4274d9103f1d | 423 | *full_scale = 16.0f; |
cparata | 3:4274d9103f1d | 424 | break; |
cparata | 3:4274d9103f1d | 425 | |
cparata | 3:4274d9103f1d | 426 | default: |
cparata | 3:4274d9103f1d | 427 | ret = 1; |
cparata | 3:4274d9103f1d | 428 | break; |
cparata | 3:4274d9103f1d | 429 | } |
cparata | 3:4274d9103f1d | 430 | |
cparata | 3:4274d9103f1d | 431 | return ret; |
cparata | 0:6d69e896ce38 | 432 | } |
cparata | 0:6d69e896ce38 | 433 | |
cparata | 0:6d69e896ce38 | 434 | /** |
cparata | 0:6d69e896ce38 | 435 | * @brief Set the LSM6DSO accelerometer sensor full scale |
cparata | 0:6d69e896ce38 | 436 | * @param full_scale the functional full scale to be set |
cparata | 0:6d69e896ce38 | 437 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 438 | */ |
cparata | 0:6d69e896ce38 | 439 | int LSM6DSOSensor::set_x_fs(float full_scale) |
cparata | 0:6d69e896ce38 | 440 | { |
cparata | 3:4274d9103f1d | 441 | lsm6dso_fs_xl_t new_fs; |
cparata | 3:4274d9103f1d | 442 | |
cparata | 3:4274d9103f1d | 443 | /* Seems like MISRA C-2012 rule 14.3a violation but only from single file statical analysis point of view because |
cparata | 3:4274d9103f1d | 444 | the parameter passed to the function is not known at the moment of analysis */ |
cparata | 3:4274d9103f1d | 445 | new_fs = (full_scale <= 2.0f) ? LSM6DSO_2g |
cparata | 3:4274d9103f1d | 446 | : (full_scale <= 4.0f) ? LSM6DSO_4g |
cparata | 3:4274d9103f1d | 447 | : (full_scale <= 8.0f) ? LSM6DSO_8g |
cparata | 3:4274d9103f1d | 448 | : LSM6DSO_16g; |
cparata | 3:4274d9103f1d | 449 | |
cparata | 3:4274d9103f1d | 450 | if (lsm6dso_xl_full_scale_set(&_reg_ctx, new_fs) != 0) { |
cparata | 3:4274d9103f1d | 451 | return 1; |
cparata | 3:4274d9103f1d | 452 | } |
cparata | 3:4274d9103f1d | 453 | |
cparata | 3:4274d9103f1d | 454 | return 0; |
cparata | 0:6d69e896ce38 | 455 | } |
cparata | 0:6d69e896ce38 | 456 | |
cparata | 0:6d69e896ce38 | 457 | /** |
cparata | 0:6d69e896ce38 | 458 | * @brief Get the LSM6DSO accelerometer sensor raw axes |
cparata | 0:6d69e896ce38 | 459 | * @param value pointer where the raw values of the axes are written |
cparata | 0:6d69e896ce38 | 460 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 461 | */ |
cparata | 0:6d69e896ce38 | 462 | int LSM6DSOSensor::get_x_axes_raw(int16_t *value) |
cparata | 0:6d69e896ce38 | 463 | { |
cparata | 3:4274d9103f1d | 464 | axis3bit16_t data_raw; |
cparata | 3:4274d9103f1d | 465 | |
cparata | 3:4274d9103f1d | 466 | /* Read raw data values. */ |
cparata | 3:4274d9103f1d | 467 | if (lsm6dso_acceleration_raw_get(&_reg_ctx, data_raw.u8bit) != 0) { |
cparata | 3:4274d9103f1d | 468 | return 1; |
cparata | 3:4274d9103f1d | 469 | } |
cparata | 3:4274d9103f1d | 470 | |
cparata | 3:4274d9103f1d | 471 | /* Format the data. */ |
cparata | 3:4274d9103f1d | 472 | value[0] = data_raw.i16bit[0]; |
cparata | 3:4274d9103f1d | 473 | value[1] = data_raw.i16bit[1]; |
cparata | 3:4274d9103f1d | 474 | value[2] = data_raw.i16bit[2]; |
cparata | 3:4274d9103f1d | 475 | |
cparata | 3:4274d9103f1d | 476 | return 0; |
cparata | 0:6d69e896ce38 | 477 | } |
cparata | 0:6d69e896ce38 | 478 | |
cparata | 0:6d69e896ce38 | 479 | |
cparata | 0:6d69e896ce38 | 480 | /** |
cparata | 0:6d69e896ce38 | 481 | * @brief Get the LSM6DSO accelerometer sensor axes |
cparata | 0:6d69e896ce38 | 482 | * @param acceleration pointer where the values of the axes are written |
cparata | 0:6d69e896ce38 | 483 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 484 | */ |
cparata | 0:6d69e896ce38 | 485 | int LSM6DSOSensor::get_x_axes(int32_t *acceleration) |
cparata | 0:6d69e896ce38 | 486 | { |
cparata | 3:4274d9103f1d | 487 | axis3bit16_t data_raw; |
cparata | 3:4274d9103f1d | 488 | float sensitivity = 0.0f; |
cparata | 3:4274d9103f1d | 489 | |
cparata | 3:4274d9103f1d | 490 | /* Read raw data values. */ |
cparata | 3:4274d9103f1d | 491 | if (lsm6dso_acceleration_raw_get(&_reg_ctx, data_raw.u8bit) != 0) { |
cparata | 3:4274d9103f1d | 492 | return 1; |
cparata | 3:4274d9103f1d | 493 | } |
cparata | 3:4274d9103f1d | 494 | |
cparata | 3:4274d9103f1d | 495 | /* Get LSM6DSO actual sensitivity. */ |
cparata | 3:4274d9103f1d | 496 | if (get_x_sensitivity(&sensitivity) != 0) { |
cparata | 3:4274d9103f1d | 497 | return 1; |
cparata | 3:4274d9103f1d | 498 | } |
cparata | 3:4274d9103f1d | 499 | |
cparata | 3:4274d9103f1d | 500 | /* Calculate the data. */ |
cparata | 3:4274d9103f1d | 501 | acceleration[0] = (int32_t)((float)((float)data_raw.i16bit[0] * sensitivity)); |
cparata | 3:4274d9103f1d | 502 | acceleration[1] = (int32_t)((float)((float)data_raw.i16bit[1] * sensitivity)); |
cparata | 3:4274d9103f1d | 503 | acceleration[2] = (int32_t)((float)((float)data_raw.i16bit[2] * sensitivity)); |
cparata | 3:4274d9103f1d | 504 | |
cparata | 3:4274d9103f1d | 505 | return 0; |
cparata | 0:6d69e896ce38 | 506 | } |
cparata | 0:6d69e896ce38 | 507 | |
cparata | 0:6d69e896ce38 | 508 | |
cparata | 0:6d69e896ce38 | 509 | /** |
cparata | 0:6d69e896ce38 | 510 | * @brief Enable the LSM6DSO gyroscope sensor |
cparata | 0:6d69e896ce38 | 511 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 512 | */ |
cparata | 0:6d69e896ce38 | 513 | int LSM6DSOSensor::enable_g() |
cparata | 0:6d69e896ce38 | 514 | { |
cparata | 3:4274d9103f1d | 515 | /* Check if the component is already enabled */ |
cparata | 3:4274d9103f1d | 516 | if (_g_is_enabled == 1U) { |
cparata | 3:4274d9103f1d | 517 | return 0; |
cparata | 3:4274d9103f1d | 518 | } |
cparata | 3:4274d9103f1d | 519 | |
cparata | 3:4274d9103f1d | 520 | /* Output data rate selection. */ |
cparata | 3:4274d9103f1d | 521 | if (lsm6dso_gy_data_rate_set(&_reg_ctx, _g_last_odr) != 0) { |
cparata | 3:4274d9103f1d | 522 | return 1; |
cparata | 3:4274d9103f1d | 523 | } |
cparata | 3:4274d9103f1d | 524 | |
cparata | 3:4274d9103f1d | 525 | _g_is_enabled = 1; |
cparata | 3:4274d9103f1d | 526 | |
cparata | 0:6d69e896ce38 | 527 | return 0; |
cparata | 0:6d69e896ce38 | 528 | } |
cparata | 0:6d69e896ce38 | 529 | |
cparata | 0:6d69e896ce38 | 530 | |
cparata | 0:6d69e896ce38 | 531 | /** |
cparata | 0:6d69e896ce38 | 532 | * @brief Disable the LSM6DSO gyroscope sensor |
cparata | 0:6d69e896ce38 | 533 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 534 | */ |
cparata | 0:6d69e896ce38 | 535 | int LSM6DSOSensor::disable_g() |
cparata | 0:6d69e896ce38 | 536 | { |
cparata | 3:4274d9103f1d | 537 | /* Check if the component is already disabled */ |
cparata | 3:4274d9103f1d | 538 | if (_g_is_enabled == 0U) { |
cparata | 3:4274d9103f1d | 539 | return 0; |
cparata | 3:4274d9103f1d | 540 | } |
cparata | 3:4274d9103f1d | 541 | |
cparata | 3:4274d9103f1d | 542 | /* Get current output data rate. */ |
cparata | 3:4274d9103f1d | 543 | if (lsm6dso_gy_data_rate_get(&_reg_ctx, &_g_last_odr) != 0) { |
cparata | 3:4274d9103f1d | 544 | return 1; |
cparata | 3:4274d9103f1d | 545 | } |
cparata | 3:4274d9103f1d | 546 | |
cparata | 3:4274d9103f1d | 547 | /* Output data rate selection - power down. */ |
cparata | 3:4274d9103f1d | 548 | if (lsm6dso_gy_data_rate_set(&_reg_ctx, LSM6DSO_GY_ODR_OFF) != 0) { |
cparata | 3:4274d9103f1d | 549 | return 1; |
cparata | 3:4274d9103f1d | 550 | } |
cparata | 3:4274d9103f1d | 551 | |
cparata | 3:4274d9103f1d | 552 | _g_is_enabled = 0; |
cparata | 3:4274d9103f1d | 553 | |
cparata | 0:6d69e896ce38 | 554 | return 0; |
cparata | 0:6d69e896ce38 | 555 | } |
cparata | 0:6d69e896ce38 | 556 | |
cparata | 0:6d69e896ce38 | 557 | /** |
cparata | 0:6d69e896ce38 | 558 | * @brief Get the LSM6DSO gyroscope sensor sensitivity |
cparata | 0:6d69e896ce38 | 559 | * @param sensitivity pointer where the sensitivity is written |
cparata | 0:6d69e896ce38 | 560 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 561 | */ |
cparata | 0:6d69e896ce38 | 562 | int LSM6DSOSensor::get_g_sensitivity(float *sensitivity) |
cparata | 0:6d69e896ce38 | 563 | { |
cparata | 3:4274d9103f1d | 564 | int ret = 0; |
cparata | 3:4274d9103f1d | 565 | lsm6dso_fs_g_t full_scale; |
cparata | 3:4274d9103f1d | 566 | |
cparata | 3:4274d9103f1d | 567 | /* Read actual full scale selection from sensor. */ |
cparata | 3:4274d9103f1d | 568 | if (lsm6dso_gy_full_scale_get(&_reg_ctx, &full_scale) != 0) { |
cparata | 3:4274d9103f1d | 569 | return 1; |
cparata | 3:4274d9103f1d | 570 | } |
cparata | 3:4274d9103f1d | 571 | |
cparata | 3:4274d9103f1d | 572 | /* Store the sensitivity based on actual full scale. */ |
cparata | 3:4274d9103f1d | 573 | switch (full_scale) { |
cparata | 3:4274d9103f1d | 574 | case LSM6DSO_125dps: |
cparata | 3:4274d9103f1d | 575 | *sensitivity = LSM6DSO_GYRO_SENSITIVITY_FS_125DPS; |
cparata | 3:4274d9103f1d | 576 | break; |
cparata | 3:4274d9103f1d | 577 | |
cparata | 3:4274d9103f1d | 578 | case LSM6DSO_250dps: |
cparata | 3:4274d9103f1d | 579 | *sensitivity = LSM6DSO_GYRO_SENSITIVITY_FS_250DPS; |
cparata | 3:4274d9103f1d | 580 | break; |
cparata | 3:4274d9103f1d | 581 | |
cparata | 3:4274d9103f1d | 582 | case LSM6DSO_500dps: |
cparata | 3:4274d9103f1d | 583 | *sensitivity = LSM6DSO_GYRO_SENSITIVITY_FS_500DPS; |
cparata | 3:4274d9103f1d | 584 | break; |
cparata | 3:4274d9103f1d | 585 | |
cparata | 3:4274d9103f1d | 586 | case LSM6DSO_1000dps: |
cparata | 3:4274d9103f1d | 587 | *sensitivity = LSM6DSO_GYRO_SENSITIVITY_FS_1000DPS; |
cparata | 3:4274d9103f1d | 588 | break; |
cparata | 3:4274d9103f1d | 589 | |
cparata | 3:4274d9103f1d | 590 | case LSM6DSO_2000dps: |
cparata | 3:4274d9103f1d | 591 | *sensitivity = LSM6DSO_GYRO_SENSITIVITY_FS_2000DPS; |
cparata | 3:4274d9103f1d | 592 | break; |
cparata | 3:4274d9103f1d | 593 | |
cparata | 3:4274d9103f1d | 594 | default: |
cparata | 3:4274d9103f1d | 595 | ret = 1; |
cparata | 3:4274d9103f1d | 596 | break; |
cparata | 3:4274d9103f1d | 597 | } |
cparata | 3:4274d9103f1d | 598 | |
cparata | 3:4274d9103f1d | 599 | return ret; |
cparata | 0:6d69e896ce38 | 600 | } |
cparata | 0:6d69e896ce38 | 601 | |
cparata | 0:6d69e896ce38 | 602 | /** |
cparata | 0:6d69e896ce38 | 603 | * @brief Get the LSM6DSO gyroscope sensor output data rate |
cparata | 0:6d69e896ce38 | 604 | * @param odr pointer where the output data rate is written |
cparata | 0:6d69e896ce38 | 605 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 606 | */ |
cparata | 0:6d69e896ce38 | 607 | int LSM6DSOSensor::get_g_odr(float *odr) |
cparata | 0:6d69e896ce38 | 608 | { |
cparata | 3:4274d9103f1d | 609 | int ret = 0; |
cparata | 3:4274d9103f1d | 610 | lsm6dso_odr_g_t odr_low_level; |
cparata | 3:4274d9103f1d | 611 | |
cparata | 3:4274d9103f1d | 612 | /* Get current output data rate. */ |
cparata | 3:4274d9103f1d | 613 | if (lsm6dso_gy_data_rate_get(&_reg_ctx, &odr_low_level) != 0) { |
cparata | 3:4274d9103f1d | 614 | return 1; |
cparata | 3:4274d9103f1d | 615 | } |
cparata | 3:4274d9103f1d | 616 | |
cparata | 3:4274d9103f1d | 617 | switch (odr_low_level) { |
cparata | 3:4274d9103f1d | 618 | case LSM6DSO_GY_ODR_OFF: |
cparata | 3:4274d9103f1d | 619 | *odr = 0.0f; |
cparata | 3:4274d9103f1d | 620 | break; |
cparata | 3:4274d9103f1d | 621 | |
cparata | 3:4274d9103f1d | 622 | case LSM6DSO_GY_ODR_12Hz5: |
cparata | 3:4274d9103f1d | 623 | *odr = 12.5f; |
cparata | 3:4274d9103f1d | 624 | break; |
cparata | 3:4274d9103f1d | 625 | |
cparata | 3:4274d9103f1d | 626 | case LSM6DSO_GY_ODR_26Hz: |
cparata | 3:4274d9103f1d | 627 | *odr = 26.0f; |
cparata | 3:4274d9103f1d | 628 | break; |
cparata | 3:4274d9103f1d | 629 | |
cparata | 3:4274d9103f1d | 630 | case LSM6DSO_GY_ODR_52Hz: |
cparata | 3:4274d9103f1d | 631 | *odr = 52.0f; |
cparata | 3:4274d9103f1d | 632 | break; |
cparata | 3:4274d9103f1d | 633 | |
cparata | 3:4274d9103f1d | 634 | case LSM6DSO_GY_ODR_104Hz: |
cparata | 3:4274d9103f1d | 635 | *odr = 104.0f; |
cparata | 3:4274d9103f1d | 636 | break; |
cparata | 3:4274d9103f1d | 637 | |
cparata | 3:4274d9103f1d | 638 | case LSM6DSO_GY_ODR_208Hz: |
cparata | 3:4274d9103f1d | 639 | *odr = 208.0f; |
cparata | 3:4274d9103f1d | 640 | break; |
cparata | 3:4274d9103f1d | 641 | |
cparata | 3:4274d9103f1d | 642 | case LSM6DSO_GY_ODR_417Hz: |
cparata | 3:4274d9103f1d | 643 | *odr = 417.0f; |
cparata | 3:4274d9103f1d | 644 | break; |
cparata | 3:4274d9103f1d | 645 | |
cparata | 3:4274d9103f1d | 646 | case LSM6DSO_GY_ODR_833Hz: |
cparata | 3:4274d9103f1d | 647 | *odr = 833.0f; |
cparata | 3:4274d9103f1d | 648 | break; |
cparata | 3:4274d9103f1d | 649 | |
cparata | 3:4274d9103f1d | 650 | case LSM6DSO_GY_ODR_1667Hz: |
cparata | 3:4274d9103f1d | 651 | *odr = 1667.0f; |
cparata | 3:4274d9103f1d | 652 | break; |
cparata | 3:4274d9103f1d | 653 | |
cparata | 3:4274d9103f1d | 654 | case LSM6DSO_GY_ODR_3333Hz: |
cparata | 3:4274d9103f1d | 655 | *odr = 3333.0f; |
cparata | 3:4274d9103f1d | 656 | break; |
cparata | 3:4274d9103f1d | 657 | |
cparata | 3:4274d9103f1d | 658 | case LSM6DSO_GY_ODR_6667Hz: |
cparata | 3:4274d9103f1d | 659 | *odr = 6667.0f; |
cparata | 3:4274d9103f1d | 660 | break; |
cparata | 3:4274d9103f1d | 661 | |
cparata | 3:4274d9103f1d | 662 | default: |
cparata | 3:4274d9103f1d | 663 | ret = 1; |
cparata | 3:4274d9103f1d | 664 | break; |
cparata | 3:4274d9103f1d | 665 | } |
cparata | 3:4274d9103f1d | 666 | |
cparata | 3:4274d9103f1d | 667 | return ret; |
cparata | 0:6d69e896ce38 | 668 | } |
cparata | 0:6d69e896ce38 | 669 | |
cparata | 0:6d69e896ce38 | 670 | /** |
cparata | 0:6d69e896ce38 | 671 | * @brief Set the LSM6DSO gyroscope sensor output data rate |
cparata | 0:6d69e896ce38 | 672 | * @param odr the output data rate value to be set |
cparata | 0:6d69e896ce38 | 673 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 674 | */ |
cparata | 0:6d69e896ce38 | 675 | int LSM6DSOSensor::set_g_odr(float odr) |
cparata | 0:6d69e896ce38 | 676 | { |
cparata | 3:4274d9103f1d | 677 | /* Check if the component is enabled */ |
cparata | 3:4274d9103f1d | 678 | if (_g_is_enabled == 1U) { |
cparata | 3:4274d9103f1d | 679 | return set_g_odr_when_enabled(odr); |
cparata | 3:4274d9103f1d | 680 | } else { |
cparata | 3:4274d9103f1d | 681 | return set_g_odr_when_disabled(odr); |
cparata | 3:4274d9103f1d | 682 | } |
cparata | 0:6d69e896ce38 | 683 | } |
cparata | 0:6d69e896ce38 | 684 | |
cparata | 0:6d69e896ce38 | 685 | /** |
cparata | 0:6d69e896ce38 | 686 | * @brief Set the LSM6DSO gyroscope sensor output data rate when enabled |
cparata | 0:6d69e896ce38 | 687 | * @param odr the functional output data rate to be set |
cparata | 0:6d69e896ce38 | 688 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 689 | */ |
cparata | 0:6d69e896ce38 | 690 | int LSM6DSOSensor::set_g_odr_when_enabled(float odr) |
cparata | 0:6d69e896ce38 | 691 | { |
cparata | 3:4274d9103f1d | 692 | lsm6dso_odr_g_t new_odr; |
cparata | 3:4274d9103f1d | 693 | |
cparata | 3:4274d9103f1d | 694 | new_odr = (odr <= 12.5f) ? LSM6DSO_GY_ODR_12Hz5 |
cparata | 3:4274d9103f1d | 695 | : (odr <= 26.0f) ? LSM6DSO_GY_ODR_26Hz |
cparata | 3:4274d9103f1d | 696 | : (odr <= 52.0f) ? LSM6DSO_GY_ODR_52Hz |
cparata | 3:4274d9103f1d | 697 | : (odr <= 104.0f) ? LSM6DSO_GY_ODR_104Hz |
cparata | 3:4274d9103f1d | 698 | : (odr <= 208.0f) ? LSM6DSO_GY_ODR_208Hz |
cparata | 3:4274d9103f1d | 699 | : (odr <= 417.0f) ? LSM6DSO_GY_ODR_417Hz |
cparata | 3:4274d9103f1d | 700 | : (odr <= 833.0f) ? LSM6DSO_GY_ODR_833Hz |
cparata | 3:4274d9103f1d | 701 | : (odr <= 1667.0f) ? LSM6DSO_GY_ODR_1667Hz |
cparata | 3:4274d9103f1d | 702 | : (odr <= 3333.0f) ? LSM6DSO_GY_ODR_3333Hz |
cparata | 3:4274d9103f1d | 703 | : LSM6DSO_GY_ODR_6667Hz; |
cparata | 3:4274d9103f1d | 704 | |
cparata | 3:4274d9103f1d | 705 | /* Output data rate selection. */ |
cparata | 3:4274d9103f1d | 706 | if (lsm6dso_gy_data_rate_set(&_reg_ctx, new_odr) != 0) { |
cparata | 3:4274d9103f1d | 707 | return 1; |
cparata | 3:4274d9103f1d | 708 | } |
cparata | 3:4274d9103f1d | 709 | |
cparata | 3:4274d9103f1d | 710 | return 0; |
cparata | 0:6d69e896ce38 | 711 | } |
cparata | 0:6d69e896ce38 | 712 | |
cparata | 0:6d69e896ce38 | 713 | /** |
cparata | 0:6d69e896ce38 | 714 | * @brief Set the LSM6DSO gyroscope sensor output data rate when disabled |
cparata | 0:6d69e896ce38 | 715 | * @param odr the functional output data rate to be set |
cparata | 0:6d69e896ce38 | 716 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 717 | */ |
cparata | 0:6d69e896ce38 | 718 | int LSM6DSOSensor::set_g_odr_when_disabled(float odr) |
cparata | 0:6d69e896ce38 | 719 | { |
cparata | 3:4274d9103f1d | 720 | _g_last_odr = (odr <= 12.5f) ? LSM6DSO_GY_ODR_12Hz5 |
cparata | 3:4274d9103f1d | 721 | : (odr <= 26.0f) ? LSM6DSO_GY_ODR_26Hz |
cparata | 3:4274d9103f1d | 722 | : (odr <= 52.0f) ? LSM6DSO_GY_ODR_52Hz |
cparata | 3:4274d9103f1d | 723 | : (odr <= 104.0f) ? LSM6DSO_GY_ODR_104Hz |
cparata | 3:4274d9103f1d | 724 | : (odr <= 208.0f) ? LSM6DSO_GY_ODR_208Hz |
cparata | 3:4274d9103f1d | 725 | : (odr <= 417.0f) ? LSM6DSO_GY_ODR_417Hz |
cparata | 3:4274d9103f1d | 726 | : (odr <= 833.0f) ? LSM6DSO_GY_ODR_833Hz |
cparata | 3:4274d9103f1d | 727 | : (odr <= 1667.0f) ? LSM6DSO_GY_ODR_1667Hz |
cparata | 3:4274d9103f1d | 728 | : (odr <= 3333.0f) ? LSM6DSO_GY_ODR_3333Hz |
cparata | 3:4274d9103f1d | 729 | : LSM6DSO_GY_ODR_6667Hz; |
cparata | 3:4274d9103f1d | 730 | |
cparata | 3:4274d9103f1d | 731 | return 0; |
cparata | 0:6d69e896ce38 | 732 | } |
cparata | 0:6d69e896ce38 | 733 | |
cparata | 0:6d69e896ce38 | 734 | |
cparata | 0:6d69e896ce38 | 735 | /** |
cparata | 0:6d69e896ce38 | 736 | * @brief Get the LSM6DSO gyroscope sensor full scale |
cparata | 0:6d69e896ce38 | 737 | * @param full_scale pointer where the full scale is written |
cparata | 0:6d69e896ce38 | 738 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 739 | */ |
cparata | 0:6d69e896ce38 | 740 | int LSM6DSOSensor::get_g_fs(float *full_scale) |
cparata | 0:6d69e896ce38 | 741 | { |
cparata | 3:4274d9103f1d | 742 | int ret = 0; |
cparata | 3:4274d9103f1d | 743 | lsm6dso_fs_g_t fs_low_level; |
cparata | 3:4274d9103f1d | 744 | |
cparata | 3:4274d9103f1d | 745 | /* Read actual full scale selection from sensor. */ |
cparata | 3:4274d9103f1d | 746 | if (lsm6dso_gy_full_scale_get(&_reg_ctx, &fs_low_level) != 0) { |
cparata | 3:4274d9103f1d | 747 | return 1; |
cparata | 3:4274d9103f1d | 748 | } |
cparata | 3:4274d9103f1d | 749 | |
cparata | 3:4274d9103f1d | 750 | switch (fs_low_level) { |
cparata | 3:4274d9103f1d | 751 | case LSM6DSO_125dps: |
cparata | 3:4274d9103f1d | 752 | *full_scale = 125.0f; |
cparata | 3:4274d9103f1d | 753 | break; |
cparata | 3:4274d9103f1d | 754 | |
cparata | 3:4274d9103f1d | 755 | case LSM6DSO_250dps: |
cparata | 3:4274d9103f1d | 756 | *full_scale = 250.0f; |
cparata | 3:4274d9103f1d | 757 | break; |
cparata | 3:4274d9103f1d | 758 | |
cparata | 3:4274d9103f1d | 759 | case LSM6DSO_500dps: |
cparata | 3:4274d9103f1d | 760 | *full_scale = 500.0f; |
cparata | 3:4274d9103f1d | 761 | break; |
cparata | 3:4274d9103f1d | 762 | |
cparata | 3:4274d9103f1d | 763 | case LSM6DSO_1000dps: |
cparata | 3:4274d9103f1d | 764 | *full_scale = 1000.0f; |
cparata | 3:4274d9103f1d | 765 | break; |
cparata | 3:4274d9103f1d | 766 | |
cparata | 3:4274d9103f1d | 767 | case LSM6DSO_2000dps: |
cparata | 3:4274d9103f1d | 768 | *full_scale = 2000.0f; |
cparata | 3:4274d9103f1d | 769 | break; |
cparata | 3:4274d9103f1d | 770 | |
cparata | 3:4274d9103f1d | 771 | default: |
cparata | 3:4274d9103f1d | 772 | ret = 1; |
cparata | 3:4274d9103f1d | 773 | break; |
cparata | 3:4274d9103f1d | 774 | } |
cparata | 3:4274d9103f1d | 775 | |
cparata | 3:4274d9103f1d | 776 | return ret; |
cparata | 0:6d69e896ce38 | 777 | } |
cparata | 0:6d69e896ce38 | 778 | |
cparata | 0:6d69e896ce38 | 779 | /** |
cparata | 0:6d69e896ce38 | 780 | * @brief Set the LSM6DSO gyroscope sensor full scale |
cparata | 0:6d69e896ce38 | 781 | * @param full_scale the functional full scale to be set |
cparata | 0:6d69e896ce38 | 782 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 783 | */ |
cparata | 0:6d69e896ce38 | 784 | int LSM6DSOSensor::set_g_fs(float full_scale) |
cparata | 0:6d69e896ce38 | 785 | { |
cparata | 3:4274d9103f1d | 786 | lsm6dso_fs_g_t new_fs; |
cparata | 3:4274d9103f1d | 787 | |
cparata | 3:4274d9103f1d | 788 | new_fs = (full_scale <= 125.0f) ? LSM6DSO_125dps |
cparata | 3:4274d9103f1d | 789 | : (full_scale <= 250.0f) ? LSM6DSO_250dps |
cparata | 3:4274d9103f1d | 790 | : (full_scale <= 500.0f) ? LSM6DSO_500dps |
cparata | 3:4274d9103f1d | 791 | : (full_scale <= 1000.0f) ? LSM6DSO_1000dps |
cparata | 3:4274d9103f1d | 792 | : LSM6DSO_2000dps; |
cparata | 3:4274d9103f1d | 793 | |
cparata | 3:4274d9103f1d | 794 | if (lsm6dso_gy_full_scale_set(&_reg_ctx, new_fs) != 0) { |
cparata | 3:4274d9103f1d | 795 | return 1; |
cparata | 3:4274d9103f1d | 796 | } |
cparata | 3:4274d9103f1d | 797 | |
cparata | 3:4274d9103f1d | 798 | return 0; |
cparata | 0:6d69e896ce38 | 799 | } |
cparata | 0:6d69e896ce38 | 800 | |
cparata | 0:6d69e896ce38 | 801 | /** |
cparata | 0:6d69e896ce38 | 802 | * @brief Get the LSM6DSO gyroscope sensor raw axes |
cparata | 0:6d69e896ce38 | 803 | * @param value pointer where the raw values of the axes are written |
cparata | 0:6d69e896ce38 | 804 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 805 | */ |
cparata | 0:6d69e896ce38 | 806 | int LSM6DSOSensor::get_g_axes_raw(int16_t *value) |
cparata | 0:6d69e896ce38 | 807 | { |
cparata | 3:4274d9103f1d | 808 | axis3bit16_t data_raw; |
cparata | 3:4274d9103f1d | 809 | |
cparata | 3:4274d9103f1d | 810 | /* Read raw data values. */ |
cparata | 3:4274d9103f1d | 811 | if (lsm6dso_angular_rate_raw_get(&_reg_ctx, data_raw.u8bit) != 0) { |
cparata | 3:4274d9103f1d | 812 | return 1; |
cparata | 3:4274d9103f1d | 813 | } |
cparata | 3:4274d9103f1d | 814 | |
cparata | 3:4274d9103f1d | 815 | /* Format the data. */ |
cparata | 3:4274d9103f1d | 816 | value[0] = data_raw.i16bit[0]; |
cparata | 3:4274d9103f1d | 817 | value[1] = data_raw.i16bit[1]; |
cparata | 3:4274d9103f1d | 818 | value[2] = data_raw.i16bit[2]; |
cparata | 3:4274d9103f1d | 819 | |
cparata | 3:4274d9103f1d | 820 | return 0; |
cparata | 0:6d69e896ce38 | 821 | } |
cparata | 0:6d69e896ce38 | 822 | |
cparata | 0:6d69e896ce38 | 823 | |
cparata | 0:6d69e896ce38 | 824 | /** |
cparata | 0:6d69e896ce38 | 825 | * @brief Get the LSM6DSO gyroscope sensor axes |
cparata | 0:6d69e896ce38 | 826 | * @param angular_rate pointer where the values of the axes are written |
cparata | 0:6d69e896ce38 | 827 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 828 | */ |
cparata | 0:6d69e896ce38 | 829 | int LSM6DSOSensor::get_g_axes(int32_t *angular_rate) |
cparata | 0:6d69e896ce38 | 830 | { |
cparata | 3:4274d9103f1d | 831 | axis3bit16_t data_raw; |
cparata | 3:4274d9103f1d | 832 | float sensitivity; |
cparata | 3:4274d9103f1d | 833 | |
cparata | 3:4274d9103f1d | 834 | /* Read raw data values. */ |
cparata | 3:4274d9103f1d | 835 | if (lsm6dso_angular_rate_raw_get(&_reg_ctx, data_raw.u8bit) != 0) { |
cparata | 3:4274d9103f1d | 836 | return 1; |
cparata | 3:4274d9103f1d | 837 | } |
cparata | 3:4274d9103f1d | 838 | |
cparata | 3:4274d9103f1d | 839 | /* Get LSM6DSO actual sensitivity. */ |
cparata | 3:4274d9103f1d | 840 | if (get_g_sensitivity(&sensitivity) != 0) { |
cparata | 3:4274d9103f1d | 841 | return 1; |
cparata | 3:4274d9103f1d | 842 | } |
cparata | 3:4274d9103f1d | 843 | |
cparata | 3:4274d9103f1d | 844 | /* Calculate the data. */ |
cparata | 3:4274d9103f1d | 845 | angular_rate[0] = (int32_t)((float)((float)data_raw.i16bit[0] * sensitivity)); |
cparata | 3:4274d9103f1d | 846 | angular_rate[1] = (int32_t)((float)((float)data_raw.i16bit[1] * sensitivity)); |
cparata | 3:4274d9103f1d | 847 | angular_rate[2] = (int32_t)((float)((float)data_raw.i16bit[2] * sensitivity)); |
cparata | 3:4274d9103f1d | 848 | |
cparata | 3:4274d9103f1d | 849 | return 0; |
cparata | 0:6d69e896ce38 | 850 | } |
cparata | 0:6d69e896ce38 | 851 | |
cparata | 0:6d69e896ce38 | 852 | |
cparata | 0:6d69e896ce38 | 853 | /** |
cparata | 0:6d69e896ce38 | 854 | * @brief Get the LSM6DSO register value |
cparata | 0:6d69e896ce38 | 855 | * @param reg address to be read |
cparata | 0:6d69e896ce38 | 856 | * @param data pointer where the value is written |
cparata | 0:6d69e896ce38 | 857 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 858 | */ |
cparata | 0:6d69e896ce38 | 859 | int LSM6DSOSensor::read_reg(uint8_t reg, uint8_t *data) |
cparata | 0:6d69e896ce38 | 860 | { |
cparata | 3:4274d9103f1d | 861 | if (lsm6dso_read_reg(&_reg_ctx, reg, data, 1) != 0) { |
cparata | 3:4274d9103f1d | 862 | return 1; |
cparata | 3:4274d9103f1d | 863 | } |
cparata | 3:4274d9103f1d | 864 | |
cparata | 3:4274d9103f1d | 865 | return 0; |
cparata | 0:6d69e896ce38 | 866 | } |
cparata | 0:6d69e896ce38 | 867 | |
cparata | 0:6d69e896ce38 | 868 | |
cparata | 0:6d69e896ce38 | 869 | /** |
cparata | 0:6d69e896ce38 | 870 | * @brief Set the LSM6DSO register value |
cparata | 0:6d69e896ce38 | 871 | * @param reg address to be written |
cparata | 0:6d69e896ce38 | 872 | * @param data value to be written |
cparata | 0:6d69e896ce38 | 873 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 874 | */ |
cparata | 0:6d69e896ce38 | 875 | int LSM6DSOSensor::write_reg(uint8_t reg, uint8_t data) |
cparata | 0:6d69e896ce38 | 876 | { |
cparata | 3:4274d9103f1d | 877 | if (lsm6dso_write_reg(&_reg_ctx, reg, &data, 1) != 0) { |
cparata | 3:4274d9103f1d | 878 | return 1; |
cparata | 3:4274d9103f1d | 879 | } |
cparata | 3:4274d9103f1d | 880 | |
cparata | 3:4274d9103f1d | 881 | return 0; |
cparata | 0:6d69e896ce38 | 882 | } |
cparata | 0:6d69e896ce38 | 883 | |
cparata | 0:6d69e896ce38 | 884 | /** |
cparata | 0:6d69e896ce38 | 885 | * @brief Set the interrupt latch |
cparata | 0:6d69e896ce38 | 886 | * @param status value to be written |
cparata | 0:6d69e896ce38 | 887 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 888 | */ |
cparata | 0:6d69e896ce38 | 889 | int LSM6DSOSensor::set_interrupt_latch(uint8_t status) |
cparata | 0:6d69e896ce38 | 890 | { |
cparata | 3:4274d9103f1d | 891 | if (status > 1U) { |
cparata | 3:4274d9103f1d | 892 | return 1; |
cparata | 3:4274d9103f1d | 893 | } |
cparata | 3:4274d9103f1d | 894 | |
cparata | 3:4274d9103f1d | 895 | if (lsm6dso_int_notification_set(&_reg_ctx, (lsm6dso_lir_t)status) != 0) { |
cparata | 3:4274d9103f1d | 896 | return 1; |
cparata | 3:4274d9103f1d | 897 | } |
cparata | 3:4274d9103f1d | 898 | |
cparata | 3:4274d9103f1d | 899 | return 0; |
cparata | 0:6d69e896ce38 | 900 | } |
cparata | 0:6d69e896ce38 | 901 | |
cparata | 0:6d69e896ce38 | 902 | /** |
cparata | 0:6d69e896ce38 | 903 | * @brief Enable free fall detection |
cparata | 0:6d69e896ce38 | 904 | * @param int_pin interrupt pin line to be used |
cparata | 0:6d69e896ce38 | 905 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 906 | */ |
cparata | 0:6d69e896ce38 | 907 | int LSM6DSOSensor::enable_free_fall_detection(LSM6DSO_Interrupt_Pin_t int_pin) |
cparata | 0:6d69e896ce38 | 908 | { |
cparata | 3:4274d9103f1d | 909 | int ret = 0; |
cparata | 3:4274d9103f1d | 910 | lsm6dso_pin_int1_route_t val1; |
cparata | 3:4274d9103f1d | 911 | lsm6dso_pin_int2_route_t val2; |
cparata | 3:4274d9103f1d | 912 | |
cparata | 3:4274d9103f1d | 913 | /* Output Data Rate selection */ |
cparata | 3:4274d9103f1d | 914 | if (set_x_odr(416.0f) != 0) { |
cparata | 3:4274d9103f1d | 915 | return 1; |
cparata | 3:4274d9103f1d | 916 | } |
cparata | 3:4274d9103f1d | 917 | |
cparata | 3:4274d9103f1d | 918 | /* Full scale selection */ |
cparata | 3:4274d9103f1d | 919 | if (set_x_fs(2.0f) != 0) { |
cparata | 3:4274d9103f1d | 920 | return 1; |
cparata | 3:4274d9103f1d | 921 | } |
cparata | 3:4274d9103f1d | 922 | |
cparata | 3:4274d9103f1d | 923 | /* FF_DUR setting */ |
cparata | 3:4274d9103f1d | 924 | if (lsm6dso_ff_dur_set(&_reg_ctx, 0x06) != 0) { |
cparata | 3:4274d9103f1d | 925 | return 1; |
cparata | 3:4274d9103f1d | 926 | } |
cparata | 3:4274d9103f1d | 927 | |
cparata | 3:4274d9103f1d | 928 | /* WAKE_DUR setting */ |
cparata | 3:4274d9103f1d | 929 | if (lsm6dso_wkup_dur_set(&_reg_ctx, 0x00) != 0) { |
cparata | 3:4274d9103f1d | 930 | return 1; |
cparata | 3:4274d9103f1d | 931 | } |
cparata | 3:4274d9103f1d | 932 | |
cparata | 3:4274d9103f1d | 933 | /* SLEEP_DUR setting */ |
cparata | 3:4274d9103f1d | 934 | if (lsm6dso_act_sleep_dur_set(&_reg_ctx, 0x00) != 0) { |
cparata | 3:4274d9103f1d | 935 | return 1; |
cparata | 3:4274d9103f1d | 936 | } |
cparata | 3:4274d9103f1d | 937 | |
cparata | 3:4274d9103f1d | 938 | /* FF_THS setting */ |
cparata | 3:4274d9103f1d | 939 | if (lsm6dso_ff_threshold_set(&_reg_ctx, LSM6DSO_FF_TSH_312mg) != 0) { |
cparata | 0:6d69e896ce38 | 940 | return 1; |
cparata | 3:4274d9103f1d | 941 | } |
cparata | 3:4274d9103f1d | 942 | |
cparata | 3:4274d9103f1d | 943 | /* Enable free fall event on either INT1 or INT2 pin */ |
cparata | 3:4274d9103f1d | 944 | switch (int_pin) { |
cparata | 3:4274d9103f1d | 945 | case LSM6DSO_INT1_PIN: |
cparata | 3:4274d9103f1d | 946 | if (lsm6dso_pin_int1_route_get(&_reg_ctx, &val1) != 0) { |
cparata | 3:4274d9103f1d | 947 | return 1; |
cparata | 3:4274d9103f1d | 948 | } |
cparata | 3:4274d9103f1d | 949 | |
cparata | 3:4274d9103f1d | 950 | val1.md1_cfg.int1_ff = PROPERTY_ENABLE; |
cparata | 3:4274d9103f1d | 951 | |
cparata | 3:4274d9103f1d | 952 | if (lsm6dso_pin_int1_route_set(&_reg_ctx, &val1) != 0) { |
cparata | 3:4274d9103f1d | 953 | return 1; |
cparata | 3:4274d9103f1d | 954 | } |
cparata | 3:4274d9103f1d | 955 | break; |
cparata | 3:4274d9103f1d | 956 | |
cparata | 3:4274d9103f1d | 957 | case LSM6DSO_INT2_PIN: |
cparata | 3:4274d9103f1d | 958 | if (lsm6dso_pin_int2_route_get(&_reg_ctx, &val2) != 0) { |
cparata | 3:4274d9103f1d | 959 | return 1; |
cparata | 3:4274d9103f1d | 960 | } |
cparata | 3:4274d9103f1d | 961 | |
cparata | 3:4274d9103f1d | 962 | val2.md2_cfg.int2_ff = PROPERTY_ENABLE; |
cparata | 3:4274d9103f1d | 963 | |
cparata | 3:4274d9103f1d | 964 | if (lsm6dso_pin_int2_route_set(&_reg_ctx, &val2) != 0) { |
cparata | 3:4274d9103f1d | 965 | return 1; |
cparata | 3:4274d9103f1d | 966 | } |
cparata | 3:4274d9103f1d | 967 | break; |
cparata | 3:4274d9103f1d | 968 | |
cparata | 3:4274d9103f1d | 969 | default: |
cparata | 3:4274d9103f1d | 970 | ret = 1; |
cparata | 3:4274d9103f1d | 971 | break; |
cparata | 3:4274d9103f1d | 972 | } |
cparata | 3:4274d9103f1d | 973 | |
cparata | 3:4274d9103f1d | 974 | return ret; |
cparata | 0:6d69e896ce38 | 975 | } |
cparata | 0:6d69e896ce38 | 976 | |
cparata | 0:6d69e896ce38 | 977 | /** |
cparata | 0:6d69e896ce38 | 978 | * @brief Disable free fall detection |
cparata | 0:6d69e896ce38 | 979 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 980 | */ |
cparata | 0:6d69e896ce38 | 981 | int LSM6DSOSensor::disable_free_fall_detection() |
cparata | 0:6d69e896ce38 | 982 | { |
cparata | 3:4274d9103f1d | 983 | lsm6dso_pin_int1_route_t val1; |
cparata | 3:4274d9103f1d | 984 | lsm6dso_pin_int2_route_t val2; |
cparata | 3:4274d9103f1d | 985 | |
cparata | 3:4274d9103f1d | 986 | /* Disable free fall event on both INT1 and INT2 pins */ |
cparata | 3:4274d9103f1d | 987 | if (lsm6dso_pin_int1_route_get(&_reg_ctx, &val1) != 0) { |
cparata | 3:4274d9103f1d | 988 | return 1; |
cparata | 3:4274d9103f1d | 989 | } |
cparata | 3:4274d9103f1d | 990 | |
cparata | 3:4274d9103f1d | 991 | val1.md1_cfg.int1_ff = PROPERTY_DISABLE; |
cparata | 3:4274d9103f1d | 992 | |
cparata | 3:4274d9103f1d | 993 | if (lsm6dso_pin_int1_route_set(&_reg_ctx, &val1) != 0) { |
cparata | 3:4274d9103f1d | 994 | return 1; |
cparata | 3:4274d9103f1d | 995 | } |
cparata | 3:4274d9103f1d | 996 | |
cparata | 3:4274d9103f1d | 997 | if (lsm6dso_pin_int2_route_get(&_reg_ctx, &val2) != 0) { |
cparata | 3:4274d9103f1d | 998 | return 1; |
cparata | 3:4274d9103f1d | 999 | } |
cparata | 3:4274d9103f1d | 1000 | |
cparata | 3:4274d9103f1d | 1001 | val2.md2_cfg.int2_ff = PROPERTY_DISABLE; |
cparata | 3:4274d9103f1d | 1002 | |
cparata | 3:4274d9103f1d | 1003 | if (lsm6dso_pin_int2_route_set(&_reg_ctx, &val2) != 0) { |
cparata | 3:4274d9103f1d | 1004 | return 1; |
cparata | 3:4274d9103f1d | 1005 | } |
cparata | 3:4274d9103f1d | 1006 | |
cparata | 3:4274d9103f1d | 1007 | /* FF_DUR setting */ |
cparata | 3:4274d9103f1d | 1008 | if (lsm6dso_ff_dur_set(&_reg_ctx, 0x00) != 0) { |
cparata | 3:4274d9103f1d | 1009 | return 1; |
cparata | 3:4274d9103f1d | 1010 | } |
cparata | 3:4274d9103f1d | 1011 | |
cparata | 3:4274d9103f1d | 1012 | /* FF_THS setting */ |
cparata | 3:4274d9103f1d | 1013 | if (lsm6dso_ff_threshold_set(&_reg_ctx, LSM6DSO_FF_TSH_156mg) != 0) { |
cparata | 3:4274d9103f1d | 1014 | return 1; |
cparata | 3:4274d9103f1d | 1015 | } |
cparata | 3:4274d9103f1d | 1016 | |
cparata | 3:4274d9103f1d | 1017 | return 0; |
cparata | 0:6d69e896ce38 | 1018 | } |
cparata | 0:6d69e896ce38 | 1019 | |
cparata | 0:6d69e896ce38 | 1020 | /** |
cparata | 0:6d69e896ce38 | 1021 | * @brief Set free fall threshold |
cparata | 0:6d69e896ce38 | 1022 | * @param thr free fall detection threshold |
cparata | 0:6d69e896ce38 | 1023 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1024 | */ |
cparata | 0:6d69e896ce38 | 1025 | int LSM6DSOSensor::set_free_fall_threshold(uint8_t thr) |
cparata | 0:6d69e896ce38 | 1026 | { |
cparata | 3:4274d9103f1d | 1027 | if (lsm6dso_ff_threshold_set(&_reg_ctx, (lsm6dso_ff_ths_t)thr) != 0) { |
cparata | 3:4274d9103f1d | 1028 | return 1; |
cparata | 3:4274d9103f1d | 1029 | } |
cparata | 3:4274d9103f1d | 1030 | |
cparata | 3:4274d9103f1d | 1031 | return 0; |
cparata | 0:6d69e896ce38 | 1032 | } |
cparata | 0:6d69e896ce38 | 1033 | |
cparata | 0:6d69e896ce38 | 1034 | |
cparata | 0:6d69e896ce38 | 1035 | /** |
cparata | 0:6d69e896ce38 | 1036 | * @brief Set free fall duration |
cparata | 0:6d69e896ce38 | 1037 | * @param dur free fall detection duration |
cparata | 0:6d69e896ce38 | 1038 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1039 | */ |
cparata | 0:6d69e896ce38 | 1040 | int LSM6DSOSensor::set_free_fall_duration(uint8_t dur) |
cparata | 0:6d69e896ce38 | 1041 | { |
cparata | 3:4274d9103f1d | 1042 | if (lsm6dso_ff_dur_set(&_reg_ctx, dur) != 0) { |
cparata | 3:4274d9103f1d | 1043 | return 1; |
cparata | 3:4274d9103f1d | 1044 | } |
cparata | 3:4274d9103f1d | 1045 | |
cparata | 3:4274d9103f1d | 1046 | return 0; |
cparata | 0:6d69e896ce38 | 1047 | } |
cparata | 0:6d69e896ce38 | 1048 | |
cparata | 0:6d69e896ce38 | 1049 | |
cparata | 0:6d69e896ce38 | 1050 | /** |
cparata | 0:6d69e896ce38 | 1051 | * @brief Enable pedometer |
cparata | 0:6d69e896ce38 | 1052 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1053 | */ |
cparata | 0:6d69e896ce38 | 1054 | int LSM6DSOSensor::enable_pedometer() |
cparata | 0:6d69e896ce38 | 1055 | { |
cparata | 0:6d69e896ce38 | 1056 | lsm6dso_pin_int1_route_t val; |
cparata | 0:6d69e896ce38 | 1057 | |
cparata | 3:4274d9103f1d | 1058 | /* Output Data Rate selection */ |
cparata | 3:4274d9103f1d | 1059 | if (set_x_odr(26.0f) != 0) { |
cparata | 3:4274d9103f1d | 1060 | return 1; |
cparata | 3:4274d9103f1d | 1061 | } |
cparata | 3:4274d9103f1d | 1062 | |
cparata | 3:4274d9103f1d | 1063 | /* Full scale selection */ |
cparata | 3:4274d9103f1d | 1064 | if (set_x_fs(2.0f) != 0) { |
cparata | 3:4274d9103f1d | 1065 | return 1; |
cparata | 3:4274d9103f1d | 1066 | } |
cparata | 3:4274d9103f1d | 1067 | |
cparata | 3:4274d9103f1d | 1068 | /* Enable pedometer algorithm. */ |
cparata | 3:4274d9103f1d | 1069 | if (lsm6dso_pedo_sens_set(&_reg_ctx, LSM6DSO_PEDO_BASE_MODE) != 0) { |
cparata | 3:4274d9103f1d | 1070 | return 1; |
cparata | 3:4274d9103f1d | 1071 | } |
cparata | 3:4274d9103f1d | 1072 | |
cparata | 3:4274d9103f1d | 1073 | /* Enable step detector on INT1 pin */ |
cparata | 3:4274d9103f1d | 1074 | if (lsm6dso_pin_int1_route_get(&_reg_ctx, &val) != 0) { |
cparata | 3:4274d9103f1d | 1075 | return 1; |
cparata | 3:4274d9103f1d | 1076 | } |
cparata | 3:4274d9103f1d | 1077 | |
cparata | 3:4274d9103f1d | 1078 | val.emb_func_int1.int1_step_detector = PROPERTY_ENABLE; |
cparata | 3:4274d9103f1d | 1079 | |
cparata | 3:4274d9103f1d | 1080 | if (lsm6dso_pin_int1_route_set(&_reg_ctx, &val) != 0) { |
cparata | 3:4274d9103f1d | 1081 | return 1; |
cparata | 3:4274d9103f1d | 1082 | } |
cparata | 3:4274d9103f1d | 1083 | |
cparata | 3:4274d9103f1d | 1084 | return 0; |
cparata | 0:6d69e896ce38 | 1085 | } |
cparata | 0:6d69e896ce38 | 1086 | |
cparata | 0:6d69e896ce38 | 1087 | /** |
cparata | 0:6d69e896ce38 | 1088 | * @brief Disable pedometer |
cparata | 0:6d69e896ce38 | 1089 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1090 | */ |
cparata | 0:6d69e896ce38 | 1091 | int LSM6DSOSensor::disable_pedometer() |
cparata | 0:6d69e896ce38 | 1092 | { |
cparata | 3:4274d9103f1d | 1093 | lsm6dso_pin_int1_route_t val1; |
cparata | 3:4274d9103f1d | 1094 | |
cparata | 3:4274d9103f1d | 1095 | /* Disable step detector on INT1 pin */ |
cparata | 3:4274d9103f1d | 1096 | if (lsm6dso_pin_int1_route_get(&_reg_ctx, &val1) != 0) { |
cparata | 3:4274d9103f1d | 1097 | return 1; |
cparata | 3:4274d9103f1d | 1098 | } |
cparata | 3:4274d9103f1d | 1099 | |
cparata | 3:4274d9103f1d | 1100 | val1.emb_func_int1.int1_step_detector = PROPERTY_DISABLE; |
cparata | 3:4274d9103f1d | 1101 | |
cparata | 3:4274d9103f1d | 1102 | if (lsm6dso_pin_int1_route_set(&_reg_ctx, &val1) != 0) { |
cparata | 3:4274d9103f1d | 1103 | return 1; |
cparata | 3:4274d9103f1d | 1104 | } |
cparata | 3:4274d9103f1d | 1105 | |
cparata | 3:4274d9103f1d | 1106 | /* Disable pedometer algorithm. */ |
cparata | 3:4274d9103f1d | 1107 | if (lsm6dso_pedo_sens_set(&_reg_ctx, LSM6DSO_PEDO_DISABLE) != 0) { |
cparata | 3:4274d9103f1d | 1108 | return 1; |
cparata | 3:4274d9103f1d | 1109 | } |
cparata | 3:4274d9103f1d | 1110 | |
cparata | 3:4274d9103f1d | 1111 | return 0; |
cparata | 0:6d69e896ce38 | 1112 | } |
cparata | 0:6d69e896ce38 | 1113 | |
cparata | 0:6d69e896ce38 | 1114 | /** |
cparata | 0:6d69e896ce38 | 1115 | * @brief Get step count |
cparata | 0:6d69e896ce38 | 1116 | * @param step_count step counter |
cparata | 0:6d69e896ce38 | 1117 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1118 | */ |
cparata | 0:6d69e896ce38 | 1119 | int LSM6DSOSensor::get_step_counter(uint16_t *step_count) |
cparata | 0:6d69e896ce38 | 1120 | { |
cparata | 3:4274d9103f1d | 1121 | if (lsm6dso_number_of_steps_get(&_reg_ctx, (uint8_t *)step_count) != 0) { |
cparata | 3:4274d9103f1d | 1122 | return 1; |
cparata | 3:4274d9103f1d | 1123 | } |
cparata | 3:4274d9103f1d | 1124 | |
cparata | 3:4274d9103f1d | 1125 | return 0; |
cparata | 0:6d69e896ce38 | 1126 | } |
cparata | 0:6d69e896ce38 | 1127 | |
cparata | 0:6d69e896ce38 | 1128 | /** |
cparata | 0:6d69e896ce38 | 1129 | * @brief Enable step counter reset |
cparata | 0:6d69e896ce38 | 1130 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1131 | */ |
cparata | 0:6d69e896ce38 | 1132 | int LSM6DSOSensor::reset_step_counter() |
cparata | 0:6d69e896ce38 | 1133 | { |
cparata | 3:4274d9103f1d | 1134 | if (lsm6dso_steps_reset(&_reg_ctx) != 0) { |
cparata | 3:4274d9103f1d | 1135 | return 1; |
cparata | 3:4274d9103f1d | 1136 | } |
cparata | 3:4274d9103f1d | 1137 | |
cparata | 3:4274d9103f1d | 1138 | return 0; |
cparata | 0:6d69e896ce38 | 1139 | } |
cparata | 0:6d69e896ce38 | 1140 | |
cparata | 0:6d69e896ce38 | 1141 | /** |
cparata | 0:6d69e896ce38 | 1142 | * @brief Enable tilt detection |
cparata | 0:6d69e896ce38 | 1143 | * @param int_pin interrupt pin line to be used |
cparata | 0:6d69e896ce38 | 1144 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1145 | */ |
cparata | 0:6d69e896ce38 | 1146 | int LSM6DSOSensor::enable_tilt_detection(LSM6DSO_Interrupt_Pin_t int_pin) |
cparata | 0:6d69e896ce38 | 1147 | { |
cparata | 3:4274d9103f1d | 1148 | int ret = 0; |
cparata | 3:4274d9103f1d | 1149 | lsm6dso_pin_int1_route_t val1; |
cparata | 3:4274d9103f1d | 1150 | lsm6dso_pin_int2_route_t val2; |
cparata | 3:4274d9103f1d | 1151 | |
cparata | 3:4274d9103f1d | 1152 | /* Output Data Rate selection */ |
cparata | 3:4274d9103f1d | 1153 | if (set_x_odr(26.0f) != 0) { |
cparata | 3:4274d9103f1d | 1154 | return 1; |
cparata | 3:4274d9103f1d | 1155 | } |
cparata | 3:4274d9103f1d | 1156 | |
cparata | 3:4274d9103f1d | 1157 | /* Full scale selection */ |
cparata | 3:4274d9103f1d | 1158 | if (set_x_fs(2.0f) != 0) { |
cparata | 3:4274d9103f1d | 1159 | return 1; |
cparata | 3:4274d9103f1d | 1160 | } |
cparata | 3:4274d9103f1d | 1161 | |
cparata | 3:4274d9103f1d | 1162 | /* Enable tilt calculation. */ |
cparata | 3:4274d9103f1d | 1163 | if (lsm6dso_tilt_sens_set(&_reg_ctx, PROPERTY_ENABLE) != 0) { |
cparata | 0:6d69e896ce38 | 1164 | return 1; |
cparata | 3:4274d9103f1d | 1165 | } |
cparata | 3:4274d9103f1d | 1166 | |
cparata | 3:4274d9103f1d | 1167 | /* Enable tilt event on either INT1 or INT2 pin */ |
cparata | 3:4274d9103f1d | 1168 | switch (int_pin) { |
cparata | 3:4274d9103f1d | 1169 | case LSM6DSO_INT1_PIN: |
cparata | 3:4274d9103f1d | 1170 | if (lsm6dso_pin_int1_route_get(&_reg_ctx, &val1) != 0) { |
cparata | 3:4274d9103f1d | 1171 | return 1; |
cparata | 3:4274d9103f1d | 1172 | } |
cparata | 3:4274d9103f1d | 1173 | |
cparata | 3:4274d9103f1d | 1174 | val1.emb_func_int1.int1_tilt = PROPERTY_ENABLE; |
cparata | 3:4274d9103f1d | 1175 | |
cparata | 3:4274d9103f1d | 1176 | if (lsm6dso_pin_int1_route_set(&_reg_ctx, &val1) != 0) { |
cparata | 3:4274d9103f1d | 1177 | return 1; |
cparata | 3:4274d9103f1d | 1178 | } |
cparata | 3:4274d9103f1d | 1179 | break; |
cparata | 3:4274d9103f1d | 1180 | |
cparata | 3:4274d9103f1d | 1181 | case LSM6DSO_INT2_PIN: |
cparata | 3:4274d9103f1d | 1182 | if (lsm6dso_pin_int2_route_get(&_reg_ctx, &val2) != 0) { |
cparata | 3:4274d9103f1d | 1183 | return 1; |
cparata | 3:4274d9103f1d | 1184 | } |
cparata | 3:4274d9103f1d | 1185 | |
cparata | 3:4274d9103f1d | 1186 | val2.emb_func_int2.int2_tilt = PROPERTY_ENABLE; |
cparata | 3:4274d9103f1d | 1187 | |
cparata | 3:4274d9103f1d | 1188 | if (lsm6dso_pin_int2_route_set(&_reg_ctx, &val2) != 0) { |
cparata | 3:4274d9103f1d | 1189 | return 1; |
cparata | 3:4274d9103f1d | 1190 | } |
cparata | 3:4274d9103f1d | 1191 | break; |
cparata | 3:4274d9103f1d | 1192 | |
cparata | 3:4274d9103f1d | 1193 | default: |
cparata | 3:4274d9103f1d | 1194 | ret = 1; |
cparata | 3:4274d9103f1d | 1195 | break; |
cparata | 3:4274d9103f1d | 1196 | } |
cparata | 3:4274d9103f1d | 1197 | |
cparata | 3:4274d9103f1d | 1198 | return ret; |
cparata | 0:6d69e896ce38 | 1199 | } |
cparata | 0:6d69e896ce38 | 1200 | |
cparata | 0:6d69e896ce38 | 1201 | /** |
cparata | 0:6d69e896ce38 | 1202 | * @brief Disable tilt detection |
cparata | 0:6d69e896ce38 | 1203 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1204 | */ |
cparata | 0:6d69e896ce38 | 1205 | int LSM6DSOSensor::disable_tilt_detection() |
cparata | 0:6d69e896ce38 | 1206 | { |
cparata | 3:4274d9103f1d | 1207 | lsm6dso_pin_int1_route_t val1; |
cparata | 3:4274d9103f1d | 1208 | lsm6dso_pin_int2_route_t val2; |
cparata | 3:4274d9103f1d | 1209 | |
cparata | 3:4274d9103f1d | 1210 | /* Disable tilt event on both INT1 and INT2 pins */ |
cparata | 3:4274d9103f1d | 1211 | if (lsm6dso_pin_int1_route_get(&_reg_ctx, &val1) != 0) { |
cparata | 3:4274d9103f1d | 1212 | return 1; |
cparata | 3:4274d9103f1d | 1213 | } |
cparata | 3:4274d9103f1d | 1214 | |
cparata | 3:4274d9103f1d | 1215 | val1.emb_func_int1.int1_tilt = PROPERTY_DISABLE; |
cparata | 3:4274d9103f1d | 1216 | |
cparata | 3:4274d9103f1d | 1217 | if (lsm6dso_pin_int1_route_set(&_reg_ctx, &val1) != 0) { |
cparata | 3:4274d9103f1d | 1218 | return 1; |
cparata | 3:4274d9103f1d | 1219 | } |
cparata | 3:4274d9103f1d | 1220 | |
cparata | 3:4274d9103f1d | 1221 | if (lsm6dso_pin_int2_route_get(&_reg_ctx, &val2) != 0) { |
cparata | 3:4274d9103f1d | 1222 | return 1; |
cparata | 3:4274d9103f1d | 1223 | } |
cparata | 3:4274d9103f1d | 1224 | |
cparata | 3:4274d9103f1d | 1225 | val2.emb_func_int2.int2_tilt = PROPERTY_DISABLE; |
cparata | 3:4274d9103f1d | 1226 | |
cparata | 3:4274d9103f1d | 1227 | if (lsm6dso_pin_int2_route_set(&_reg_ctx, &val2) != 0) { |
cparata | 3:4274d9103f1d | 1228 | return 1; |
cparata | 3:4274d9103f1d | 1229 | } |
cparata | 3:4274d9103f1d | 1230 | |
cparata | 3:4274d9103f1d | 1231 | /* Disable tilt calculation. */ |
cparata | 3:4274d9103f1d | 1232 | if (lsm6dso_tilt_sens_set(&_reg_ctx, PROPERTY_DISABLE) != 0) { |
cparata | 3:4274d9103f1d | 1233 | return 1; |
cparata | 3:4274d9103f1d | 1234 | } |
cparata | 3:4274d9103f1d | 1235 | |
cparata | 3:4274d9103f1d | 1236 | return 0; |
cparata | 0:6d69e896ce38 | 1237 | } |
cparata | 0:6d69e896ce38 | 1238 | |
cparata | 0:6d69e896ce38 | 1239 | /** |
cparata | 0:6d69e896ce38 | 1240 | * @brief Enable wake up detection |
cparata | 0:6d69e896ce38 | 1241 | * @param int_pin interrupt pin line to be used |
cparata | 0:6d69e896ce38 | 1242 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1243 | */ |
cparata | 0:6d69e896ce38 | 1244 | int LSM6DSOSensor::enable_wake_up_detection(LSM6DSO_Interrupt_Pin_t int_pin) |
cparata | 0:6d69e896ce38 | 1245 | { |
cparata | 3:4274d9103f1d | 1246 | int ret = 0; |
cparata | 3:4274d9103f1d | 1247 | lsm6dso_pin_int1_route_t val1; |
cparata | 3:4274d9103f1d | 1248 | lsm6dso_pin_int2_route_t val2; |
cparata | 3:4274d9103f1d | 1249 | |
cparata | 3:4274d9103f1d | 1250 | /* Output Data Rate selection */ |
cparata | 3:4274d9103f1d | 1251 | if (set_x_odr(416.0f) != 0) { |
cparata | 3:4274d9103f1d | 1252 | return 1; |
cparata | 3:4274d9103f1d | 1253 | } |
cparata | 3:4274d9103f1d | 1254 | |
cparata | 3:4274d9103f1d | 1255 | /* Full scale selection */ |
cparata | 3:4274d9103f1d | 1256 | if (set_x_fs(2.0f) != 0) { |
cparata | 3:4274d9103f1d | 1257 | return 1; |
cparata | 3:4274d9103f1d | 1258 | } |
cparata | 3:4274d9103f1d | 1259 | |
cparata | 3:4274d9103f1d | 1260 | /* WAKE_DUR setting */ |
cparata | 3:4274d9103f1d | 1261 | if (lsm6dso_wkup_dur_set(&_reg_ctx, 0x00) != 0) { |
cparata | 3:4274d9103f1d | 1262 | return 1; |
cparata | 3:4274d9103f1d | 1263 | } |
cparata | 3:4274d9103f1d | 1264 | |
cparata | 3:4274d9103f1d | 1265 | /* Set wake up threshold. */ |
cparata | 3:4274d9103f1d | 1266 | if (lsm6dso_wkup_threshold_set(&_reg_ctx, 0x02) != 0) { |
cparata | 0:6d69e896ce38 | 1267 | return 1; |
cparata | 3:4274d9103f1d | 1268 | } |
cparata | 3:4274d9103f1d | 1269 | |
cparata | 3:4274d9103f1d | 1270 | /* Enable wake up event on either INT1 or INT2 pin */ |
cparata | 3:4274d9103f1d | 1271 | switch (int_pin) { |
cparata | 3:4274d9103f1d | 1272 | case LSM6DSO_INT1_PIN: |
cparata | 3:4274d9103f1d | 1273 | if (lsm6dso_pin_int1_route_get(&_reg_ctx, &val1) != 0) { |
cparata | 3:4274d9103f1d | 1274 | return 1; |
cparata | 3:4274d9103f1d | 1275 | } |
cparata | 3:4274d9103f1d | 1276 | |
cparata | 3:4274d9103f1d | 1277 | val1.md1_cfg.int1_wu = PROPERTY_ENABLE; |
cparata | 3:4274d9103f1d | 1278 | |
cparata | 3:4274d9103f1d | 1279 | if (lsm6dso_pin_int1_route_set(&_reg_ctx, &val1) != 0) { |
cparata | 3:4274d9103f1d | 1280 | return 1; |
cparata | 3:4274d9103f1d | 1281 | } |
cparata | 3:4274d9103f1d | 1282 | break; |
cparata | 3:4274d9103f1d | 1283 | |
cparata | 3:4274d9103f1d | 1284 | case LSM6DSO_INT2_PIN: |
cparata | 3:4274d9103f1d | 1285 | if (lsm6dso_pin_int2_route_get(&_reg_ctx, &val2) != 0) { |
cparata | 3:4274d9103f1d | 1286 | return 1; |
cparata | 3:4274d9103f1d | 1287 | } |
cparata | 3:4274d9103f1d | 1288 | |
cparata | 3:4274d9103f1d | 1289 | val2.md2_cfg.int2_wu = PROPERTY_ENABLE; |
cparata | 3:4274d9103f1d | 1290 | |
cparata | 3:4274d9103f1d | 1291 | if (lsm6dso_pin_int2_route_set(&_reg_ctx, &val2) != 0) { |
cparata | 3:4274d9103f1d | 1292 | return 1; |
cparata | 3:4274d9103f1d | 1293 | } |
cparata | 3:4274d9103f1d | 1294 | break; |
cparata | 3:4274d9103f1d | 1295 | |
cparata | 3:4274d9103f1d | 1296 | default: |
cparata | 3:4274d9103f1d | 1297 | ret = 1; |
cparata | 3:4274d9103f1d | 1298 | break; |
cparata | 3:4274d9103f1d | 1299 | } |
cparata | 3:4274d9103f1d | 1300 | |
cparata | 3:4274d9103f1d | 1301 | return ret; |
cparata | 0:6d69e896ce38 | 1302 | } |
cparata | 0:6d69e896ce38 | 1303 | |
cparata | 0:6d69e896ce38 | 1304 | |
cparata | 0:6d69e896ce38 | 1305 | /** |
cparata | 0:6d69e896ce38 | 1306 | * @brief Disable wake up detection |
cparata | 0:6d69e896ce38 | 1307 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1308 | */ |
cparata | 0:6d69e896ce38 | 1309 | int LSM6DSOSensor::disable_wake_up_detection() |
cparata | 0:6d69e896ce38 | 1310 | { |
cparata | 0:6d69e896ce38 | 1311 | lsm6dso_pin_int1_route_t val1; |
cparata | 0:6d69e896ce38 | 1312 | lsm6dso_pin_int2_route_t val2; |
cparata | 0:6d69e896ce38 | 1313 | |
cparata | 3:4274d9103f1d | 1314 | /* Disable wake up event on both INT1 and INT2 pins */ |
cparata | 3:4274d9103f1d | 1315 | if (lsm6dso_pin_int1_route_get(&_reg_ctx, &val1) != 0) { |
cparata | 3:4274d9103f1d | 1316 | return 1; |
cparata | 3:4274d9103f1d | 1317 | } |
cparata | 3:4274d9103f1d | 1318 | |
cparata | 3:4274d9103f1d | 1319 | val1.md1_cfg.int1_wu = PROPERTY_DISABLE; |
cparata | 3:4274d9103f1d | 1320 | |
cparata | 3:4274d9103f1d | 1321 | if (lsm6dso_pin_int1_route_set(&_reg_ctx, &val1) != 0) { |
cparata | 3:4274d9103f1d | 1322 | return 1; |
cparata | 3:4274d9103f1d | 1323 | } |
cparata | 3:4274d9103f1d | 1324 | |
cparata | 3:4274d9103f1d | 1325 | if (lsm6dso_pin_int2_route_get(&_reg_ctx, &val2) != 0) { |
cparata | 3:4274d9103f1d | 1326 | return 1; |
cparata | 3:4274d9103f1d | 1327 | } |
cparata | 3:4274d9103f1d | 1328 | |
cparata | 3:4274d9103f1d | 1329 | val2.md2_cfg.int2_wu = PROPERTY_DISABLE; |
cparata | 3:4274d9103f1d | 1330 | |
cparata | 3:4274d9103f1d | 1331 | if (lsm6dso_pin_int2_route_set(&_reg_ctx, &val2) != 0) { |
cparata | 3:4274d9103f1d | 1332 | return 1; |
cparata | 3:4274d9103f1d | 1333 | } |
cparata | 3:4274d9103f1d | 1334 | |
cparata | 3:4274d9103f1d | 1335 | /* Reset wake up threshold. */ |
cparata | 3:4274d9103f1d | 1336 | if (lsm6dso_wkup_threshold_set(&_reg_ctx, 0x00) != 0) { |
cparata | 3:4274d9103f1d | 1337 | return 1; |
cparata | 3:4274d9103f1d | 1338 | } |
cparata | 3:4274d9103f1d | 1339 | |
cparata | 3:4274d9103f1d | 1340 | /* WAKE_DUR setting */ |
cparata | 3:4274d9103f1d | 1341 | if (lsm6dso_wkup_dur_set(&_reg_ctx, 0x00) != 0) { |
cparata | 3:4274d9103f1d | 1342 | return 1; |
cparata | 3:4274d9103f1d | 1343 | } |
cparata | 3:4274d9103f1d | 1344 | |
cparata | 3:4274d9103f1d | 1345 | return 0; |
cparata | 0:6d69e896ce38 | 1346 | } |
cparata | 0:6d69e896ce38 | 1347 | |
cparata | 0:6d69e896ce38 | 1348 | /** |
cparata | 0:6d69e896ce38 | 1349 | * @brief Set wake up threshold |
cparata | 0:6d69e896ce38 | 1350 | * @param thr wake up detection threshold |
cparata | 0:6d69e896ce38 | 1351 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1352 | */ |
cparata | 0:6d69e896ce38 | 1353 | int LSM6DSOSensor::set_wake_up_threshold(uint8_t thr) |
cparata | 0:6d69e896ce38 | 1354 | { |
cparata | 3:4274d9103f1d | 1355 | /* Set wake up threshold. */ |
cparata | 3:4274d9103f1d | 1356 | if (lsm6dso_wkup_threshold_set(&_reg_ctx, thr) != 0) { |
cparata | 3:4274d9103f1d | 1357 | return 1; |
cparata | 3:4274d9103f1d | 1358 | } |
cparata | 3:4274d9103f1d | 1359 | |
cparata | 3:4274d9103f1d | 1360 | return 0; |
cparata | 0:6d69e896ce38 | 1361 | } |
cparata | 0:6d69e896ce38 | 1362 | |
cparata | 0:6d69e896ce38 | 1363 | /** |
cparata | 0:6d69e896ce38 | 1364 | * @brief Set wake up duration |
cparata | 0:6d69e896ce38 | 1365 | * @param dur wake up detection duration |
cparata | 0:6d69e896ce38 | 1366 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1367 | */ |
cparata | 0:6d69e896ce38 | 1368 | int LSM6DSOSensor::set_wake_up_duration(uint8_t dur) |
cparata | 0:6d69e896ce38 | 1369 | { |
cparata | 3:4274d9103f1d | 1370 | /* Set wake up duration. */ |
cparata | 3:4274d9103f1d | 1371 | if (lsm6dso_wkup_dur_set(&_reg_ctx, dur) != 0) { |
cparata | 3:4274d9103f1d | 1372 | return 1; |
cparata | 3:4274d9103f1d | 1373 | } |
cparata | 3:4274d9103f1d | 1374 | |
cparata | 3:4274d9103f1d | 1375 | return 0; |
cparata | 0:6d69e896ce38 | 1376 | } |
cparata | 0:6d69e896ce38 | 1377 | |
cparata | 0:6d69e896ce38 | 1378 | /** |
cparata | 0:6d69e896ce38 | 1379 | * @brief Enable single tap detection |
cparata | 0:6d69e896ce38 | 1380 | * @param int_pin interrupt pin line to be used |
cparata | 0:6d69e896ce38 | 1381 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1382 | */ |
cparata | 0:6d69e896ce38 | 1383 | int LSM6DSOSensor::enable_single_tap_detection(LSM6DSO_Interrupt_Pin_t int_pin) |
cparata | 0:6d69e896ce38 | 1384 | { |
cparata | 3:4274d9103f1d | 1385 | int ret = 0; |
cparata | 3:4274d9103f1d | 1386 | lsm6dso_pin_int1_route_t val1; |
cparata | 3:4274d9103f1d | 1387 | lsm6dso_pin_int2_route_t val2; |
cparata | 3:4274d9103f1d | 1388 | |
cparata | 3:4274d9103f1d | 1389 | /* Output Data Rate selection */ |
cparata | 3:4274d9103f1d | 1390 | if (set_x_odr(416.0f) != 0) { |
cparata | 3:4274d9103f1d | 1391 | return 1; |
cparata | 3:4274d9103f1d | 1392 | } |
cparata | 3:4274d9103f1d | 1393 | |
cparata | 3:4274d9103f1d | 1394 | /* Full scale selection */ |
cparata | 3:4274d9103f1d | 1395 | if (set_x_fs(2.0f) != 0) { |
cparata | 3:4274d9103f1d | 1396 | return 1; |
cparata | 3:4274d9103f1d | 1397 | } |
cparata | 3:4274d9103f1d | 1398 | |
cparata | 3:4274d9103f1d | 1399 | /* Enable X direction in tap recognition. */ |
cparata | 3:4274d9103f1d | 1400 | if (lsm6dso_tap_detection_on_x_set(&_reg_ctx, PROPERTY_ENABLE) != 0) { |
cparata | 3:4274d9103f1d | 1401 | return 1; |
cparata | 3:4274d9103f1d | 1402 | } |
cparata | 3:4274d9103f1d | 1403 | |
cparata | 3:4274d9103f1d | 1404 | /* Enable Y direction in tap recognition. */ |
cparata | 3:4274d9103f1d | 1405 | if (lsm6dso_tap_detection_on_y_set(&_reg_ctx, PROPERTY_ENABLE) != 0) { |
cparata | 3:4274d9103f1d | 1406 | return 1; |
cparata | 3:4274d9103f1d | 1407 | } |
cparata | 3:4274d9103f1d | 1408 | |
cparata | 3:4274d9103f1d | 1409 | /* Enable Z direction in tap recognition. */ |
cparata | 3:4274d9103f1d | 1410 | if (lsm6dso_tap_detection_on_z_set(&_reg_ctx, PROPERTY_ENABLE) != 0) { |
cparata | 3:4274d9103f1d | 1411 | return 1; |
cparata | 3:4274d9103f1d | 1412 | } |
cparata | 3:4274d9103f1d | 1413 | |
cparata | 3:4274d9103f1d | 1414 | /* Set tap threshold. */ |
cparata | 3:4274d9103f1d | 1415 | if (lsm6dso_tap_threshold_x_set(&_reg_ctx, 0x08) != 0) { |
cparata | 3:4274d9103f1d | 1416 | return 1; |
cparata | 3:4274d9103f1d | 1417 | } |
cparata | 3:4274d9103f1d | 1418 | |
cparata | 3:4274d9103f1d | 1419 | /* Set tap shock time window. */ |
cparata | 3:4274d9103f1d | 1420 | if (lsm6dso_tap_shock_set(&_reg_ctx, 0x02) != 0) { |
cparata | 0:6d69e896ce38 | 1421 | return 1; |
cparata | 3:4274d9103f1d | 1422 | } |
cparata | 3:4274d9103f1d | 1423 | |
cparata | 3:4274d9103f1d | 1424 | /* Set tap quiet time window. */ |
cparata | 3:4274d9103f1d | 1425 | if (lsm6dso_tap_quiet_set(&_reg_ctx, 0x01) != 0) { |
cparata | 0:6d69e896ce38 | 1426 | return 1; |
cparata | 3:4274d9103f1d | 1427 | } |
cparata | 3:4274d9103f1d | 1428 | |
cparata | 3:4274d9103f1d | 1429 | /* _NOTE_: Tap duration time window - don't care for single tap. */ |
cparata | 3:4274d9103f1d | 1430 | |
cparata | 3:4274d9103f1d | 1431 | /* _NOTE_: Single/Double Tap event - don't care of this flag for single tap. */ |
cparata | 3:4274d9103f1d | 1432 | |
cparata | 3:4274d9103f1d | 1433 | /* Enable single tap event on either INT1 or INT2 pin */ |
cparata | 3:4274d9103f1d | 1434 | switch (int_pin) { |
cparata | 3:4274d9103f1d | 1435 | case LSM6DSO_INT1_PIN: |
cparata | 3:4274d9103f1d | 1436 | if (lsm6dso_pin_int1_route_get(&_reg_ctx, &val1) != 0) { |
cparata | 3:4274d9103f1d | 1437 | return 1; |
cparata | 3:4274d9103f1d | 1438 | } |
cparata | 3:4274d9103f1d | 1439 | |
cparata | 3:4274d9103f1d | 1440 | val1.md1_cfg.int1_single_tap = PROPERTY_ENABLE; |
cparata | 3:4274d9103f1d | 1441 | |
cparata | 3:4274d9103f1d | 1442 | if (lsm6dso_pin_int1_route_set(&_reg_ctx, &val1) != 0) { |
cparata | 3:4274d9103f1d | 1443 | return 1; |
cparata | 3:4274d9103f1d | 1444 | } |
cparata | 3:4274d9103f1d | 1445 | break; |
cparata | 3:4274d9103f1d | 1446 | |
cparata | 3:4274d9103f1d | 1447 | case LSM6DSO_INT2_PIN: |
cparata | 3:4274d9103f1d | 1448 | if (lsm6dso_pin_int2_route_get(&_reg_ctx, &val2) != 0) { |
cparata | 3:4274d9103f1d | 1449 | return 1; |
cparata | 3:4274d9103f1d | 1450 | } |
cparata | 3:4274d9103f1d | 1451 | |
cparata | 3:4274d9103f1d | 1452 | val2.md2_cfg.int2_single_tap = PROPERTY_ENABLE; |
cparata | 3:4274d9103f1d | 1453 | |
cparata | 3:4274d9103f1d | 1454 | if (lsm6dso_pin_int2_route_set(&_reg_ctx, &val2) != 0) { |
cparata | 3:4274d9103f1d | 1455 | return 1; |
cparata | 3:4274d9103f1d | 1456 | } |
cparata | 3:4274d9103f1d | 1457 | break; |
cparata | 3:4274d9103f1d | 1458 | |
cparata | 3:4274d9103f1d | 1459 | default: |
cparata | 3:4274d9103f1d | 1460 | ret = 1; |
cparata | 3:4274d9103f1d | 1461 | break; |
cparata | 3:4274d9103f1d | 1462 | } |
cparata | 3:4274d9103f1d | 1463 | |
cparata | 3:4274d9103f1d | 1464 | return ret; |
cparata | 0:6d69e896ce38 | 1465 | } |
cparata | 0:6d69e896ce38 | 1466 | |
cparata | 0:6d69e896ce38 | 1467 | /** |
cparata | 0:6d69e896ce38 | 1468 | * @brief Disable single tap detection |
cparata | 0:6d69e896ce38 | 1469 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1470 | */ |
cparata | 0:6d69e896ce38 | 1471 | int LSM6DSOSensor::disable_single_tap_detection() |
cparata | 0:6d69e896ce38 | 1472 | { |
cparata | 0:6d69e896ce38 | 1473 | lsm6dso_pin_int1_route_t val1; |
cparata | 0:6d69e896ce38 | 1474 | lsm6dso_pin_int2_route_t val2; |
cparata | 0:6d69e896ce38 | 1475 | |
cparata | 3:4274d9103f1d | 1476 | /* Disable single tap event on both INT1 and INT2 pins */ |
cparata | 3:4274d9103f1d | 1477 | if (lsm6dso_pin_int1_route_get(&_reg_ctx, &val1) != 0) { |
cparata | 3:4274d9103f1d | 1478 | return 1; |
cparata | 3:4274d9103f1d | 1479 | } |
cparata | 3:4274d9103f1d | 1480 | |
cparata | 3:4274d9103f1d | 1481 | val1.md1_cfg.int1_single_tap = PROPERTY_DISABLE; |
cparata | 3:4274d9103f1d | 1482 | |
cparata | 3:4274d9103f1d | 1483 | if (lsm6dso_pin_int1_route_set(&_reg_ctx, &val1) != 0) { |
cparata | 3:4274d9103f1d | 1484 | return 1; |
cparata | 3:4274d9103f1d | 1485 | } |
cparata | 3:4274d9103f1d | 1486 | |
cparata | 3:4274d9103f1d | 1487 | if (lsm6dso_pin_int2_route_get(&_reg_ctx, &val2) != 0) { |
cparata | 3:4274d9103f1d | 1488 | return 1; |
cparata | 3:4274d9103f1d | 1489 | } |
cparata | 3:4274d9103f1d | 1490 | |
cparata | 3:4274d9103f1d | 1491 | val2.md2_cfg.int2_single_tap = PROPERTY_DISABLE; |
cparata | 3:4274d9103f1d | 1492 | |
cparata | 3:4274d9103f1d | 1493 | if (lsm6dso_pin_int2_route_set(&_reg_ctx, &val2) != 0) { |
cparata | 3:4274d9103f1d | 1494 | return 1; |
cparata | 3:4274d9103f1d | 1495 | } |
cparata | 3:4274d9103f1d | 1496 | |
cparata | 3:4274d9103f1d | 1497 | /* Reset tap quiet time window. */ |
cparata | 3:4274d9103f1d | 1498 | if (lsm6dso_tap_quiet_set(&_reg_ctx, 0x00) != 0) { |
cparata | 3:4274d9103f1d | 1499 | return 1; |
cparata | 3:4274d9103f1d | 1500 | } |
cparata | 3:4274d9103f1d | 1501 | |
cparata | 3:4274d9103f1d | 1502 | /* Reset tap shock time window. */ |
cparata | 3:4274d9103f1d | 1503 | if (lsm6dso_tap_shock_set(&_reg_ctx, 0x00) != 0) { |
cparata | 3:4274d9103f1d | 1504 | return 1; |
cparata | 3:4274d9103f1d | 1505 | } |
cparata | 3:4274d9103f1d | 1506 | |
cparata | 3:4274d9103f1d | 1507 | /* Reset tap threshold. */ |
cparata | 3:4274d9103f1d | 1508 | if (lsm6dso_tap_threshold_x_set(&_reg_ctx, 0x00) != 0) { |
cparata | 3:4274d9103f1d | 1509 | return 1; |
cparata | 3:4274d9103f1d | 1510 | } |
cparata | 3:4274d9103f1d | 1511 | |
cparata | 3:4274d9103f1d | 1512 | /* Disable Z direction in tap recognition. */ |
cparata | 3:4274d9103f1d | 1513 | if (lsm6dso_tap_detection_on_z_set(&_reg_ctx, PROPERTY_DISABLE) != 0) { |
cparata | 3:4274d9103f1d | 1514 | return 1; |
cparata | 3:4274d9103f1d | 1515 | } |
cparata | 3:4274d9103f1d | 1516 | |
cparata | 3:4274d9103f1d | 1517 | /* Disable Y direction in tap recognition. */ |
cparata | 3:4274d9103f1d | 1518 | if (lsm6dso_tap_detection_on_y_set(&_reg_ctx, PROPERTY_DISABLE) != 0) { |
cparata | 3:4274d9103f1d | 1519 | return 1; |
cparata | 3:4274d9103f1d | 1520 | } |
cparata | 3:4274d9103f1d | 1521 | |
cparata | 3:4274d9103f1d | 1522 | /* Disable X direction in tap recognition. */ |
cparata | 3:4274d9103f1d | 1523 | if (lsm6dso_tap_detection_on_x_set(&_reg_ctx, PROPERTY_DISABLE) != 0) { |
cparata | 3:4274d9103f1d | 1524 | return 1; |
cparata | 3:4274d9103f1d | 1525 | } |
cparata | 3:4274d9103f1d | 1526 | |
cparata | 3:4274d9103f1d | 1527 | return 0; |
cparata | 0:6d69e896ce38 | 1528 | } |
cparata | 0:6d69e896ce38 | 1529 | |
cparata | 0:6d69e896ce38 | 1530 | /** |
cparata | 0:6d69e896ce38 | 1531 | * @brief Enable double tap detection |
cparata | 0:6d69e896ce38 | 1532 | * @param int_pin interrupt pin line to be used |
cparata | 0:6d69e896ce38 | 1533 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1534 | */ |
cparata | 0:6d69e896ce38 | 1535 | int LSM6DSOSensor::enable_double_tap_detection(LSM6DSO_Interrupt_Pin_t int_pin) |
cparata | 0:6d69e896ce38 | 1536 | { |
cparata | 3:4274d9103f1d | 1537 | int ret = 0; |
cparata | 3:4274d9103f1d | 1538 | lsm6dso_pin_int1_route_t val1; |
cparata | 3:4274d9103f1d | 1539 | lsm6dso_pin_int2_route_t val2; |
cparata | 3:4274d9103f1d | 1540 | |
cparata | 3:4274d9103f1d | 1541 | /* Output Data Rate selection */ |
cparata | 3:4274d9103f1d | 1542 | if (set_x_odr(416.0f) != 0) { |
cparata | 3:4274d9103f1d | 1543 | return 1; |
cparata | 3:4274d9103f1d | 1544 | } |
cparata | 3:4274d9103f1d | 1545 | |
cparata | 3:4274d9103f1d | 1546 | /* Full scale selection */ |
cparata | 3:4274d9103f1d | 1547 | if (set_x_fs(2.0f) != 0) { |
cparata | 3:4274d9103f1d | 1548 | return 1; |
cparata | 3:4274d9103f1d | 1549 | } |
cparata | 3:4274d9103f1d | 1550 | |
cparata | 3:4274d9103f1d | 1551 | /* Enable X direction in tap recognition. */ |
cparata | 3:4274d9103f1d | 1552 | if (lsm6dso_tap_detection_on_x_set(&_reg_ctx, PROPERTY_ENABLE) != 0) { |
cparata | 3:4274d9103f1d | 1553 | return 1; |
cparata | 3:4274d9103f1d | 1554 | } |
cparata | 3:4274d9103f1d | 1555 | |
cparata | 3:4274d9103f1d | 1556 | /* Enable Y direction in tap recognition. */ |
cparata | 3:4274d9103f1d | 1557 | if (lsm6dso_tap_detection_on_y_set(&_reg_ctx, PROPERTY_ENABLE) != 0) { |
cparata | 3:4274d9103f1d | 1558 | return 1; |
cparata | 3:4274d9103f1d | 1559 | } |
cparata | 3:4274d9103f1d | 1560 | |
cparata | 3:4274d9103f1d | 1561 | /* Enable Z direction in tap recognition. */ |
cparata | 3:4274d9103f1d | 1562 | if (lsm6dso_tap_detection_on_z_set(&_reg_ctx, PROPERTY_ENABLE) != 0) { |
cparata | 3:4274d9103f1d | 1563 | return 1; |
cparata | 3:4274d9103f1d | 1564 | } |
cparata | 3:4274d9103f1d | 1565 | |
cparata | 3:4274d9103f1d | 1566 | /* Set tap threshold. */ |
cparata | 3:4274d9103f1d | 1567 | if (lsm6dso_tap_threshold_x_set(&_reg_ctx, 0x08) != 0) { |
cparata | 3:4274d9103f1d | 1568 | return 1; |
cparata | 3:4274d9103f1d | 1569 | } |
cparata | 3:4274d9103f1d | 1570 | |
cparata | 3:4274d9103f1d | 1571 | /* Set tap shock time window. */ |
cparata | 3:4274d9103f1d | 1572 | if (lsm6dso_tap_shock_set(&_reg_ctx, 0x03) != 0) { |
cparata | 3:4274d9103f1d | 1573 | return 1; |
cparata | 3:4274d9103f1d | 1574 | } |
cparata | 3:4274d9103f1d | 1575 | |
cparata | 3:4274d9103f1d | 1576 | /* Set tap quiet time window. */ |
cparata | 3:4274d9103f1d | 1577 | if (lsm6dso_tap_quiet_set(&_reg_ctx, 0x03) != 0) { |
cparata | 0:6d69e896ce38 | 1578 | return 1; |
cparata | 3:4274d9103f1d | 1579 | } |
cparata | 3:4274d9103f1d | 1580 | |
cparata | 3:4274d9103f1d | 1581 | /* Set tap duration time window. */ |
cparata | 3:4274d9103f1d | 1582 | if (lsm6dso_tap_dur_set(&_reg_ctx, 0x08) != 0) { |
cparata | 0:6d69e896ce38 | 1583 | return 1; |
cparata | 3:4274d9103f1d | 1584 | } |
cparata | 3:4274d9103f1d | 1585 | |
cparata | 3:4274d9103f1d | 1586 | /* Single and double tap enabled. */ |
cparata | 3:4274d9103f1d | 1587 | if (lsm6dso_tap_mode_set(&_reg_ctx, LSM6DSO_BOTH_SINGLE_DOUBLE) != 0) { |
cparata | 0:6d69e896ce38 | 1588 | return 1; |
cparata | 3:4274d9103f1d | 1589 | } |
cparata | 3:4274d9103f1d | 1590 | |
cparata | 3:4274d9103f1d | 1591 | /* Enable double tap event on either INT1 or INT2 pin */ |
cparata | 3:4274d9103f1d | 1592 | switch (int_pin) { |
cparata | 3:4274d9103f1d | 1593 | case LSM6DSO_INT1_PIN: |
cparata | 3:4274d9103f1d | 1594 | if (lsm6dso_pin_int1_route_get(&_reg_ctx, &val1) != 0) { |
cparata | 3:4274d9103f1d | 1595 | return 1; |
cparata | 3:4274d9103f1d | 1596 | } |
cparata | 3:4274d9103f1d | 1597 | |
cparata | 3:4274d9103f1d | 1598 | val1.md1_cfg.int1_double_tap = PROPERTY_ENABLE; |
cparata | 3:4274d9103f1d | 1599 | |
cparata | 3:4274d9103f1d | 1600 | if (lsm6dso_pin_int1_route_set(&_reg_ctx, &val1) != 0) { |
cparata | 3:4274d9103f1d | 1601 | return 1; |
cparata | 3:4274d9103f1d | 1602 | } |
cparata | 3:4274d9103f1d | 1603 | break; |
cparata | 3:4274d9103f1d | 1604 | |
cparata | 3:4274d9103f1d | 1605 | case LSM6DSO_INT2_PIN: |
cparata | 3:4274d9103f1d | 1606 | if (lsm6dso_pin_int2_route_get(&_reg_ctx, &val2) != 0) { |
cparata | 3:4274d9103f1d | 1607 | return 1; |
cparata | 3:4274d9103f1d | 1608 | } |
cparata | 3:4274d9103f1d | 1609 | |
cparata | 3:4274d9103f1d | 1610 | val2.md2_cfg.int2_double_tap = PROPERTY_ENABLE; |
cparata | 3:4274d9103f1d | 1611 | |
cparata | 3:4274d9103f1d | 1612 | if (lsm6dso_pin_int2_route_set(&_reg_ctx, &val2) != 0) { |
cparata | 3:4274d9103f1d | 1613 | return 1; |
cparata | 3:4274d9103f1d | 1614 | } |
cparata | 3:4274d9103f1d | 1615 | break; |
cparata | 3:4274d9103f1d | 1616 | |
cparata | 3:4274d9103f1d | 1617 | default: |
cparata | 3:4274d9103f1d | 1618 | ret = 1; |
cparata | 3:4274d9103f1d | 1619 | break; |
cparata | 3:4274d9103f1d | 1620 | } |
cparata | 3:4274d9103f1d | 1621 | |
cparata | 3:4274d9103f1d | 1622 | return ret; |
cparata | 0:6d69e896ce38 | 1623 | } |
cparata | 0:6d69e896ce38 | 1624 | |
cparata | 0:6d69e896ce38 | 1625 | /** |
cparata | 0:6d69e896ce38 | 1626 | * @brief Disable double tap detection |
cparata | 0:6d69e896ce38 | 1627 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1628 | */ |
cparata | 0:6d69e896ce38 | 1629 | int LSM6DSOSensor::disable_double_tap_detection() |
cparata | 0:6d69e896ce38 | 1630 | { |
cparata | 3:4274d9103f1d | 1631 | lsm6dso_pin_int1_route_t val1; |
cparata | 3:4274d9103f1d | 1632 | lsm6dso_pin_int2_route_t val2; |
cparata | 3:4274d9103f1d | 1633 | |
cparata | 3:4274d9103f1d | 1634 | /* Disable double tap event on both INT1 and INT2 pins */ |
cparata | 3:4274d9103f1d | 1635 | if (lsm6dso_pin_int1_route_get(&_reg_ctx, &val1) != 0) { |
cparata | 3:4274d9103f1d | 1636 | return 1; |
cparata | 3:4274d9103f1d | 1637 | } |
cparata | 3:4274d9103f1d | 1638 | |
cparata | 3:4274d9103f1d | 1639 | val1.md1_cfg.int1_double_tap = PROPERTY_DISABLE; |
cparata | 3:4274d9103f1d | 1640 | |
cparata | 3:4274d9103f1d | 1641 | if (lsm6dso_pin_int1_route_set(&_reg_ctx, &val1) != 0) { |
cparata | 3:4274d9103f1d | 1642 | return 1; |
cparata | 3:4274d9103f1d | 1643 | } |
cparata | 3:4274d9103f1d | 1644 | |
cparata | 3:4274d9103f1d | 1645 | if (lsm6dso_pin_int2_route_get(&_reg_ctx, &val2) != 0) { |
cparata | 3:4274d9103f1d | 1646 | return 1; |
cparata | 3:4274d9103f1d | 1647 | } |
cparata | 3:4274d9103f1d | 1648 | |
cparata | 3:4274d9103f1d | 1649 | val2.md2_cfg.int2_double_tap = PROPERTY_DISABLE; |
cparata | 3:4274d9103f1d | 1650 | |
cparata | 3:4274d9103f1d | 1651 | if (lsm6dso_pin_int2_route_set(&_reg_ctx, &val2) != 0) { |
cparata | 3:4274d9103f1d | 1652 | return 1; |
cparata | 3:4274d9103f1d | 1653 | } |
cparata | 3:4274d9103f1d | 1654 | |
cparata | 3:4274d9103f1d | 1655 | /* Only single tap enabled. */ |
cparata | 3:4274d9103f1d | 1656 | if (lsm6dso_tap_mode_set(&_reg_ctx, LSM6DSO_ONLY_SINGLE) != 0) { |
cparata | 3:4274d9103f1d | 1657 | return 1; |
cparata | 3:4274d9103f1d | 1658 | } |
cparata | 3:4274d9103f1d | 1659 | |
cparata | 3:4274d9103f1d | 1660 | /* Reset tap duration time window. */ |
cparata | 3:4274d9103f1d | 1661 | if (lsm6dso_tap_dur_set(&_reg_ctx, 0x00) != 0) { |
cparata | 3:4274d9103f1d | 1662 | return 1; |
cparata | 3:4274d9103f1d | 1663 | } |
cparata | 3:4274d9103f1d | 1664 | |
cparata | 3:4274d9103f1d | 1665 | /* Reset tap quiet time window. */ |
cparata | 3:4274d9103f1d | 1666 | if (lsm6dso_tap_quiet_set(&_reg_ctx, 0x00) != 0) { |
cparata | 3:4274d9103f1d | 1667 | return 1; |
cparata | 3:4274d9103f1d | 1668 | } |
cparata | 3:4274d9103f1d | 1669 | |
cparata | 3:4274d9103f1d | 1670 | /* Reset tap shock time window. */ |
cparata | 3:4274d9103f1d | 1671 | if (lsm6dso_tap_shock_set(&_reg_ctx, 0x00) != 0) { |
cparata | 3:4274d9103f1d | 1672 | return 1; |
cparata | 3:4274d9103f1d | 1673 | } |
cparata | 3:4274d9103f1d | 1674 | |
cparata | 3:4274d9103f1d | 1675 | /* Reset tap threshold. */ |
cparata | 3:4274d9103f1d | 1676 | if (lsm6dso_tap_threshold_x_set(&_reg_ctx, 0x00) != 0) { |
cparata | 3:4274d9103f1d | 1677 | return 1; |
cparata | 3:4274d9103f1d | 1678 | } |
cparata | 3:4274d9103f1d | 1679 | |
cparata | 3:4274d9103f1d | 1680 | /* Disable Z direction in tap recognition. */ |
cparata | 3:4274d9103f1d | 1681 | if (lsm6dso_tap_detection_on_z_set(&_reg_ctx, PROPERTY_DISABLE) != 0) { |
cparata | 3:4274d9103f1d | 1682 | return 1; |
cparata | 3:4274d9103f1d | 1683 | } |
cparata | 3:4274d9103f1d | 1684 | |
cparata | 3:4274d9103f1d | 1685 | /* Disable Y direction in tap recognition. */ |
cparata | 3:4274d9103f1d | 1686 | if (lsm6dso_tap_detection_on_y_set(&_reg_ctx, PROPERTY_DISABLE) != 0) { |
cparata | 3:4274d9103f1d | 1687 | return 1; |
cparata | 3:4274d9103f1d | 1688 | } |
cparata | 3:4274d9103f1d | 1689 | |
cparata | 3:4274d9103f1d | 1690 | /* Disable X direction in tap recognition. */ |
cparata | 3:4274d9103f1d | 1691 | if (lsm6dso_tap_detection_on_x_set(&_reg_ctx, PROPERTY_DISABLE) != 0) { |
cparata | 3:4274d9103f1d | 1692 | return 1; |
cparata | 3:4274d9103f1d | 1693 | } |
cparata | 3:4274d9103f1d | 1694 | |
cparata | 3:4274d9103f1d | 1695 | return 0; |
cparata | 0:6d69e896ce38 | 1696 | } |
cparata | 0:6d69e896ce38 | 1697 | |
cparata | 0:6d69e896ce38 | 1698 | /** |
cparata | 0:6d69e896ce38 | 1699 | * @brief Set tap threshold |
cparata | 0:6d69e896ce38 | 1700 | * @param thr tap threshold |
cparata | 0:6d69e896ce38 | 1701 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1702 | */ |
cparata | 0:6d69e896ce38 | 1703 | int LSM6DSOSensor::set_tap_threshold(uint8_t thr) |
cparata | 0:6d69e896ce38 | 1704 | { |
cparata | 3:4274d9103f1d | 1705 | /* Set tap threshold. */ |
cparata | 3:4274d9103f1d | 1706 | if (lsm6dso_tap_threshold_x_set(&_reg_ctx, thr) != 0) { |
cparata | 3:4274d9103f1d | 1707 | return 1; |
cparata | 3:4274d9103f1d | 1708 | } |
cparata | 3:4274d9103f1d | 1709 | |
cparata | 3:4274d9103f1d | 1710 | return 0; |
cparata | 0:6d69e896ce38 | 1711 | } |
cparata | 0:6d69e896ce38 | 1712 | |
cparata | 0:6d69e896ce38 | 1713 | /** |
cparata | 0:6d69e896ce38 | 1714 | * @brief Set tap shock time |
cparata | 0:6d69e896ce38 | 1715 | * @param time tap shock time |
cparata | 0:6d69e896ce38 | 1716 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1717 | */ |
cparata | 0:6d69e896ce38 | 1718 | int LSM6DSOSensor::set_tap_shock_time(uint8_t time) |
cparata | 0:6d69e896ce38 | 1719 | { |
cparata | 3:4274d9103f1d | 1720 | /* Set tap shock time window. */ |
cparata | 3:4274d9103f1d | 1721 | if (lsm6dso_tap_shock_set(&_reg_ctx, time) != 0) { |
cparata | 3:4274d9103f1d | 1722 | return 1; |
cparata | 3:4274d9103f1d | 1723 | } |
cparata | 3:4274d9103f1d | 1724 | |
cparata | 3:4274d9103f1d | 1725 | return 0; |
cparata | 0:6d69e896ce38 | 1726 | } |
cparata | 0:6d69e896ce38 | 1727 | |
cparata | 0:6d69e896ce38 | 1728 | /** |
cparata | 0:6d69e896ce38 | 1729 | * @brief Set tap quiet time |
cparata | 0:6d69e896ce38 | 1730 | * @param time tap quiet time |
cparata | 0:6d69e896ce38 | 1731 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1732 | */ |
cparata | 0:6d69e896ce38 | 1733 | int LSM6DSOSensor::set_tap_quiet_time(uint8_t time) |
cparata | 0:6d69e896ce38 | 1734 | { |
cparata | 3:4274d9103f1d | 1735 | /* Set tap quiet time window. */ |
cparata | 3:4274d9103f1d | 1736 | if (lsm6dso_tap_quiet_set(&_reg_ctx, time) != 0) { |
cparata | 3:4274d9103f1d | 1737 | return 1; |
cparata | 3:4274d9103f1d | 1738 | } |
cparata | 3:4274d9103f1d | 1739 | |
cparata | 3:4274d9103f1d | 1740 | return 0; |
cparata | 0:6d69e896ce38 | 1741 | } |
cparata | 0:6d69e896ce38 | 1742 | |
cparata | 0:6d69e896ce38 | 1743 | /** |
cparata | 0:6d69e896ce38 | 1744 | * @brief Set tap duration time |
cparata | 0:6d69e896ce38 | 1745 | * @param time tap duration time |
cparata | 0:6d69e896ce38 | 1746 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1747 | */ |
cparata | 0:6d69e896ce38 | 1748 | int LSM6DSOSensor::set_tap_duration_time(uint8_t time) |
cparata | 0:6d69e896ce38 | 1749 | { |
cparata | 3:4274d9103f1d | 1750 | /* Set tap duration time window. */ |
cparata | 3:4274d9103f1d | 1751 | if (lsm6dso_tap_dur_set(&_reg_ctx, time) != 0) { |
cparata | 3:4274d9103f1d | 1752 | return 1; |
cparata | 3:4274d9103f1d | 1753 | } |
cparata | 3:4274d9103f1d | 1754 | |
cparata | 3:4274d9103f1d | 1755 | return 0; |
cparata | 0:6d69e896ce38 | 1756 | } |
cparata | 0:6d69e896ce38 | 1757 | |
cparata | 0:6d69e896ce38 | 1758 | /** |
cparata | 0:6d69e896ce38 | 1759 | * @brief Enable 6D orientation detection |
cparata | 0:6d69e896ce38 | 1760 | * @param int_pin interrupt pin line to be used |
cparata | 0:6d69e896ce38 | 1761 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1762 | */ |
cparata | 0:6d69e896ce38 | 1763 | int LSM6DSOSensor::enable_6d_orientation(LSM6DSO_Interrupt_Pin_t int_pin) |
cparata | 0:6d69e896ce38 | 1764 | { |
cparata | 3:4274d9103f1d | 1765 | int ret = 0; |
cparata | 3:4274d9103f1d | 1766 | lsm6dso_pin_int1_route_t val1; |
cparata | 3:4274d9103f1d | 1767 | lsm6dso_pin_int2_route_t val2; |
cparata | 3:4274d9103f1d | 1768 | |
cparata | 3:4274d9103f1d | 1769 | /* Output Data Rate selection */ |
cparata | 3:4274d9103f1d | 1770 | if (set_x_odr(416.0f) != 0) { |
cparata | 3:4274d9103f1d | 1771 | return 1; |
cparata | 3:4274d9103f1d | 1772 | } |
cparata | 3:4274d9103f1d | 1773 | |
cparata | 3:4274d9103f1d | 1774 | /* Full scale selection */ |
cparata | 3:4274d9103f1d | 1775 | if (set_x_fs(2.0f) != 0) { |
cparata | 3:4274d9103f1d | 1776 | return 1; |
cparata | 3:4274d9103f1d | 1777 | } |
cparata | 3:4274d9103f1d | 1778 | |
cparata | 3:4274d9103f1d | 1779 | /* 6D orientation enabled. */ |
cparata | 3:4274d9103f1d | 1780 | if (lsm6dso_6d_threshold_set(&_reg_ctx, LSM6DSO_DEG_60) != 0) { |
cparata | 0:6d69e896ce38 | 1781 | return 1; |
cparata | 3:4274d9103f1d | 1782 | } |
cparata | 3:4274d9103f1d | 1783 | |
cparata | 3:4274d9103f1d | 1784 | /* Enable 6D orientation event on either INT1 or INT2 pin */ |
cparata | 3:4274d9103f1d | 1785 | switch (int_pin) { |
cparata | 3:4274d9103f1d | 1786 | case LSM6DSO_INT1_PIN: |
cparata | 3:4274d9103f1d | 1787 | if (lsm6dso_pin_int1_route_get(&_reg_ctx, &val1) != 0) { |
cparata | 3:4274d9103f1d | 1788 | return 1; |
cparata | 3:4274d9103f1d | 1789 | } |
cparata | 3:4274d9103f1d | 1790 | |
cparata | 3:4274d9103f1d | 1791 | val1.md1_cfg.int1_6d = PROPERTY_ENABLE; |
cparata | 3:4274d9103f1d | 1792 | |
cparata | 3:4274d9103f1d | 1793 | if (lsm6dso_pin_int1_route_set(&_reg_ctx, &val1) != 0) { |
cparata | 3:4274d9103f1d | 1794 | return 1; |
cparata | 3:4274d9103f1d | 1795 | } |
cparata | 3:4274d9103f1d | 1796 | break; |
cparata | 3:4274d9103f1d | 1797 | |
cparata | 3:4274d9103f1d | 1798 | case LSM6DSO_INT2_PIN: |
cparata | 3:4274d9103f1d | 1799 | if (lsm6dso_pin_int2_route_get(&_reg_ctx, &val2) != 0) { |
cparata | 3:4274d9103f1d | 1800 | return 1; |
cparata | 3:4274d9103f1d | 1801 | } |
cparata | 3:4274d9103f1d | 1802 | |
cparata | 3:4274d9103f1d | 1803 | val2.md2_cfg.int2_6d = PROPERTY_ENABLE; |
cparata | 3:4274d9103f1d | 1804 | |
cparata | 3:4274d9103f1d | 1805 | if (lsm6dso_pin_int2_route_set(&_reg_ctx, &val2) != 0) { |
cparata | 3:4274d9103f1d | 1806 | return 1; |
cparata | 3:4274d9103f1d | 1807 | } |
cparata | 3:4274d9103f1d | 1808 | break; |
cparata | 3:4274d9103f1d | 1809 | |
cparata | 3:4274d9103f1d | 1810 | default: |
cparata | 3:4274d9103f1d | 1811 | ret = 1; |
cparata | 3:4274d9103f1d | 1812 | break; |
cparata | 3:4274d9103f1d | 1813 | } |
cparata | 3:4274d9103f1d | 1814 | |
cparata | 3:4274d9103f1d | 1815 | return ret; |
cparata | 0:6d69e896ce38 | 1816 | } |
cparata | 0:6d69e896ce38 | 1817 | |
cparata | 0:6d69e896ce38 | 1818 | /** |
cparata | 0:6d69e896ce38 | 1819 | * @brief Disable 6D orientation detection |
cparata | 0:6d69e896ce38 | 1820 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1821 | */ |
cparata | 0:6d69e896ce38 | 1822 | int LSM6DSOSensor::disable_6d_orientation() |
cparata | 0:6d69e896ce38 | 1823 | { |
cparata | 3:4274d9103f1d | 1824 | lsm6dso_pin_int1_route_t val1; |
cparata | 3:4274d9103f1d | 1825 | lsm6dso_pin_int2_route_t val2; |
cparata | 3:4274d9103f1d | 1826 | |
cparata | 3:4274d9103f1d | 1827 | /* Disable 6D orientation event on both INT1 and INT2 pins */ |
cparata | 3:4274d9103f1d | 1828 | if (lsm6dso_pin_int1_route_get(&_reg_ctx, &val1) != 0) { |
cparata | 3:4274d9103f1d | 1829 | return 1; |
cparata | 3:4274d9103f1d | 1830 | } |
cparata | 3:4274d9103f1d | 1831 | |
cparata | 3:4274d9103f1d | 1832 | val1.md1_cfg.int1_6d = PROPERTY_DISABLE; |
cparata | 3:4274d9103f1d | 1833 | |
cparata | 3:4274d9103f1d | 1834 | if (lsm6dso_pin_int1_route_set(&_reg_ctx, &val1) != 0) { |
cparata | 3:4274d9103f1d | 1835 | return 1; |
cparata | 3:4274d9103f1d | 1836 | } |
cparata | 3:4274d9103f1d | 1837 | |
cparata | 3:4274d9103f1d | 1838 | if (lsm6dso_pin_int2_route_get(&_reg_ctx, &val2) != 0) { |
cparata | 3:4274d9103f1d | 1839 | return 1; |
cparata | 3:4274d9103f1d | 1840 | } |
cparata | 3:4274d9103f1d | 1841 | |
cparata | 3:4274d9103f1d | 1842 | val2.md2_cfg.int2_6d = PROPERTY_DISABLE; |
cparata | 3:4274d9103f1d | 1843 | |
cparata | 3:4274d9103f1d | 1844 | if (lsm6dso_pin_int2_route_set(&_reg_ctx, &val2) != 0) { |
cparata | 3:4274d9103f1d | 1845 | return 1; |
cparata | 3:4274d9103f1d | 1846 | } |
cparata | 3:4274d9103f1d | 1847 | |
cparata | 3:4274d9103f1d | 1848 | /* Reset 6D orientation. */ |
cparata | 3:4274d9103f1d | 1849 | if (lsm6dso_6d_threshold_set(&_reg_ctx, LSM6DSO_DEG_80) != 0) { |
cparata | 3:4274d9103f1d | 1850 | return 1; |
cparata | 3:4274d9103f1d | 1851 | } |
cparata | 3:4274d9103f1d | 1852 | |
cparata | 3:4274d9103f1d | 1853 | return 0; |
cparata | 0:6d69e896ce38 | 1854 | } |
cparata | 0:6d69e896ce38 | 1855 | |
cparata | 0:6d69e896ce38 | 1856 | /** |
cparata | 0:6d69e896ce38 | 1857 | * @brief Set 6D orientation threshold |
cparata | 0:6d69e896ce38 | 1858 | * @param thr 6D Orientation detection threshold |
cparata | 0:6d69e896ce38 | 1859 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1860 | */ |
cparata | 0:6d69e896ce38 | 1861 | int LSM6DSOSensor::set_6d_orientation_threshold(uint8_t thr) |
cparata | 0:6d69e896ce38 | 1862 | { |
cparata | 3:4274d9103f1d | 1863 | if (lsm6dso_6d_threshold_set(&_reg_ctx, (lsm6dso_sixd_ths_t)thr) != 0) { |
cparata | 3:4274d9103f1d | 1864 | return 1; |
cparata | 3:4274d9103f1d | 1865 | } |
cparata | 3:4274d9103f1d | 1866 | |
cparata | 3:4274d9103f1d | 1867 | return 0; |
cparata | 0:6d69e896ce38 | 1868 | } |
cparata | 0:6d69e896ce38 | 1869 | |
cparata | 0:6d69e896ce38 | 1870 | /** |
cparata | 0:6d69e896ce38 | 1871 | * @brief Get the status of XLow orientation |
cparata | 0:6d69e896ce38 | 1872 | * @param xl the status of XLow orientation |
cparata | 0:6d69e896ce38 | 1873 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1874 | */ |
cparata | 0:6d69e896ce38 | 1875 | int LSM6DSOSensor::get_6d_orientation_xl(uint8_t *xl) |
cparata | 0:6d69e896ce38 | 1876 | { |
cparata | 3:4274d9103f1d | 1877 | lsm6dso_d6d_src_t data; |
cparata | 3:4274d9103f1d | 1878 | |
cparata | 3:4274d9103f1d | 1879 | if (lsm6dso_read_reg(&_reg_ctx, LSM6DSO_D6D_SRC, (uint8_t *)&data, 1) != 0) { |
cparata | 3:4274d9103f1d | 1880 | return 1; |
cparata | 3:4274d9103f1d | 1881 | } |
cparata | 3:4274d9103f1d | 1882 | |
cparata | 3:4274d9103f1d | 1883 | *xl = data.xl; |
cparata | 3:4274d9103f1d | 1884 | |
cparata | 3:4274d9103f1d | 1885 | return 0; |
cparata | 0:6d69e896ce38 | 1886 | } |
cparata | 0:6d69e896ce38 | 1887 | |
cparata | 0:6d69e896ce38 | 1888 | /** |
cparata | 0:6d69e896ce38 | 1889 | * @brief Get the status of XHigh orientation |
cparata | 0:6d69e896ce38 | 1890 | * @param xh the status of XHigh orientation |
cparata | 0:6d69e896ce38 | 1891 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1892 | */ |
cparata | 0:6d69e896ce38 | 1893 | int LSM6DSOSensor::get_6d_orientation_xh(uint8_t *xh) |
cparata | 0:6d69e896ce38 | 1894 | { |
cparata | 3:4274d9103f1d | 1895 | lsm6dso_d6d_src_t data; |
cparata | 3:4274d9103f1d | 1896 | |
cparata | 3:4274d9103f1d | 1897 | if (lsm6dso_read_reg(&_reg_ctx, LSM6DSO_D6D_SRC, (uint8_t *)&data, 1) != 0) { |
cparata | 3:4274d9103f1d | 1898 | return 1; |
cparata | 3:4274d9103f1d | 1899 | } |
cparata | 3:4274d9103f1d | 1900 | |
cparata | 3:4274d9103f1d | 1901 | *xh = data.xh; |
cparata | 3:4274d9103f1d | 1902 | |
cparata | 3:4274d9103f1d | 1903 | return 0; |
cparata | 0:6d69e896ce38 | 1904 | } |
cparata | 0:6d69e896ce38 | 1905 | |
cparata | 0:6d69e896ce38 | 1906 | /** |
cparata | 0:6d69e896ce38 | 1907 | * @brief Get the status of YLow orientation |
cparata | 0:6d69e896ce38 | 1908 | * @param yl the status of YLow orientation |
cparata | 0:6d69e896ce38 | 1909 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1910 | */ |
cparata | 0:6d69e896ce38 | 1911 | int LSM6DSOSensor::get_6d_orientation_yl(uint8_t *yl) |
cparata | 0:6d69e896ce38 | 1912 | { |
cparata | 3:4274d9103f1d | 1913 | lsm6dso_d6d_src_t data; |
cparata | 3:4274d9103f1d | 1914 | |
cparata | 3:4274d9103f1d | 1915 | if (lsm6dso_read_reg(&_reg_ctx, LSM6DSO_D6D_SRC, (uint8_t *)&data, 1) != 0) { |
cparata | 3:4274d9103f1d | 1916 | return 1; |
cparata | 3:4274d9103f1d | 1917 | } |
cparata | 3:4274d9103f1d | 1918 | |
cparata | 3:4274d9103f1d | 1919 | *yl = data.yl; |
cparata | 3:4274d9103f1d | 1920 | |
cparata | 3:4274d9103f1d | 1921 | return 0; |
cparata | 0:6d69e896ce38 | 1922 | } |
cparata | 0:6d69e896ce38 | 1923 | |
cparata | 0:6d69e896ce38 | 1924 | /** |
cparata | 0:6d69e896ce38 | 1925 | * @brief Get the status of YHigh orientation |
cparata | 0:6d69e896ce38 | 1926 | * @param yh the status of YHigh orientation |
cparata | 0:6d69e896ce38 | 1927 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1928 | */ |
cparata | 0:6d69e896ce38 | 1929 | int LSM6DSOSensor::get_6d_orientation_yh(uint8_t *yh) |
cparata | 0:6d69e896ce38 | 1930 | { |
cparata | 3:4274d9103f1d | 1931 | lsm6dso_d6d_src_t data; |
cparata | 3:4274d9103f1d | 1932 | |
cparata | 3:4274d9103f1d | 1933 | if (lsm6dso_read_reg(&_reg_ctx, LSM6DSO_D6D_SRC, (uint8_t *)&data, 1) != 0) { |
cparata | 3:4274d9103f1d | 1934 | return 1; |
cparata | 3:4274d9103f1d | 1935 | } |
cparata | 3:4274d9103f1d | 1936 | |
cparata | 3:4274d9103f1d | 1937 | *yh = data.yh; |
cparata | 3:4274d9103f1d | 1938 | |
cparata | 3:4274d9103f1d | 1939 | return 0; |
cparata | 0:6d69e896ce38 | 1940 | } |
cparata | 0:6d69e896ce38 | 1941 | |
cparata | 0:6d69e896ce38 | 1942 | /** |
cparata | 0:6d69e896ce38 | 1943 | * @brief Get the status of ZLow orientation |
cparata | 0:6d69e896ce38 | 1944 | * @param zl the status of ZLow orientation |
cparata | 0:6d69e896ce38 | 1945 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1946 | */ |
cparata | 0:6d69e896ce38 | 1947 | int LSM6DSOSensor::get_6d_orientation_zl(uint8_t *zl) |
cparata | 0:6d69e896ce38 | 1948 | { |
cparata | 3:4274d9103f1d | 1949 | lsm6dso_d6d_src_t data; |
cparata | 3:4274d9103f1d | 1950 | |
cparata | 3:4274d9103f1d | 1951 | if (lsm6dso_read_reg(&_reg_ctx, LSM6DSO_D6D_SRC, (uint8_t *)&data, 1) != 0) { |
cparata | 3:4274d9103f1d | 1952 | return 1; |
cparata | 3:4274d9103f1d | 1953 | } |
cparata | 3:4274d9103f1d | 1954 | |
cparata | 3:4274d9103f1d | 1955 | *zl = data.zl; |
cparata | 3:4274d9103f1d | 1956 | |
cparata | 3:4274d9103f1d | 1957 | return 0; |
cparata | 0:6d69e896ce38 | 1958 | } |
cparata | 0:6d69e896ce38 | 1959 | |
cparata | 0:6d69e896ce38 | 1960 | /** |
cparata | 0:6d69e896ce38 | 1961 | * @brief Get the status of ZHigh orientation |
cparata | 0:6d69e896ce38 | 1962 | * @param zh the status of ZHigh orientation |
cparata | 0:6d69e896ce38 | 1963 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1964 | */ |
cparata | 0:6d69e896ce38 | 1965 | int LSM6DSOSensor::get_6d_orientation_zh(uint8_t *zh) |
cparata | 0:6d69e896ce38 | 1966 | { |
cparata | 3:4274d9103f1d | 1967 | lsm6dso_d6d_src_t data; |
cparata | 3:4274d9103f1d | 1968 | |
cparata | 3:4274d9103f1d | 1969 | if (lsm6dso_read_reg(&_reg_ctx, LSM6DSO_D6D_SRC, (uint8_t *)&data, 1) != 0) { |
cparata | 3:4274d9103f1d | 1970 | return 1; |
cparata | 3:4274d9103f1d | 1971 | } |
cparata | 3:4274d9103f1d | 1972 | |
cparata | 3:4274d9103f1d | 1973 | *zh = data.zh; |
cparata | 3:4274d9103f1d | 1974 | |
cparata | 3:4274d9103f1d | 1975 | return 0; |
cparata | 0:6d69e896ce38 | 1976 | } |
cparata | 0:6d69e896ce38 | 1977 | |
cparata | 0:6d69e896ce38 | 1978 | /** |
cparata | 0:6d69e896ce38 | 1979 | * @brief Get the LSM6DSO ACC data ready bit value |
cparata | 0:6d69e896ce38 | 1980 | * @param status the status of data ready bit |
cparata | 0:6d69e896ce38 | 1981 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1982 | */ |
cparata | 0:6d69e896ce38 | 1983 | int LSM6DSOSensor::get_x_drdy_status(uint8_t *status) |
cparata | 0:6d69e896ce38 | 1984 | { |
cparata | 3:4274d9103f1d | 1985 | if (lsm6dso_xl_flag_data_ready_get(&_reg_ctx, status) != 0) { |
cparata | 3:4274d9103f1d | 1986 | return 1; |
cparata | 3:4274d9103f1d | 1987 | } |
cparata | 3:4274d9103f1d | 1988 | |
cparata | 3:4274d9103f1d | 1989 | return 0; |
cparata | 0:6d69e896ce38 | 1990 | } |
cparata | 0:6d69e896ce38 | 1991 | |
cparata | 0:6d69e896ce38 | 1992 | /** |
cparata | 0:6d69e896ce38 | 1993 | * @brief Get the status of all hardware events |
cparata | 0:6d69e896ce38 | 1994 | * @param status the status of all hardware events |
cparata | 0:6d69e896ce38 | 1995 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 1996 | */ |
cparata | 0:6d69e896ce38 | 1997 | int LSM6DSOSensor::get_event_status(LSM6DSO_Event_Status_t *status) |
cparata | 0:6d69e896ce38 | 1998 | { |
cparata | 3:4274d9103f1d | 1999 | uint8_t tilt_ia = 0U; |
cparata | 3:4274d9103f1d | 2000 | lsm6dso_wake_up_src_t wake_up_src; |
cparata | 3:4274d9103f1d | 2001 | lsm6dso_tap_src_t tap_src; |
cparata | 3:4274d9103f1d | 2002 | lsm6dso_d6d_src_t d6d_src; |
cparata | 3:4274d9103f1d | 2003 | lsm6dso_emb_func_src_t func_src; |
cparata | 3:4274d9103f1d | 2004 | lsm6dso_md1_cfg_t md1_cfg; |
cparata | 3:4274d9103f1d | 2005 | lsm6dso_md2_cfg_t md2_cfg; |
cparata | 3:4274d9103f1d | 2006 | lsm6dso_emb_func_int1_t int1_ctrl; |
cparata | 3:4274d9103f1d | 2007 | lsm6dso_emb_func_int2_t int2_ctrl; |
cparata | 3:4274d9103f1d | 2008 | |
cparata | 3:4274d9103f1d | 2009 | (void)memset((void *)status, 0x0, sizeof(LSM6DSO_Event_Status_t)); |
cparata | 3:4274d9103f1d | 2010 | |
cparata | 3:4274d9103f1d | 2011 | if (lsm6dso_read_reg(&_reg_ctx, LSM6DSO_WAKE_UP_SRC, (uint8_t *)&wake_up_src, 1) != 0) { |
cparata | 3:4274d9103f1d | 2012 | return 1; |
cparata | 3:4274d9103f1d | 2013 | } |
cparata | 3:4274d9103f1d | 2014 | |
cparata | 3:4274d9103f1d | 2015 | if (lsm6dso_read_reg(&_reg_ctx, LSM6DSO_TAP_SRC, (uint8_t *)&tap_src, 1) != 0) { |
cparata | 3:4274d9103f1d | 2016 | return 1; |
cparata | 3:4274d9103f1d | 2017 | } |
cparata | 3:4274d9103f1d | 2018 | |
cparata | 3:4274d9103f1d | 2019 | if (lsm6dso_read_reg(&_reg_ctx, LSM6DSO_D6D_SRC, (uint8_t *)&d6d_src, 1) != 0) { |
cparata | 3:4274d9103f1d | 2020 | return 1; |
cparata | 3:4274d9103f1d | 2021 | } |
cparata | 3:4274d9103f1d | 2022 | |
cparata | 3:4274d9103f1d | 2023 | if (lsm6dso_mem_bank_set(&_reg_ctx, LSM6DSO_EMBEDDED_FUNC_BANK) != 0) { |
cparata | 3:4274d9103f1d | 2024 | return 1; |
cparata | 3:4274d9103f1d | 2025 | } |
cparata | 3:4274d9103f1d | 2026 | |
cparata | 3:4274d9103f1d | 2027 | if (lsm6dso_read_reg(&_reg_ctx, LSM6DSO_EMB_FUNC_SRC, (uint8_t *)&func_src, 1) != 0) { |
cparata | 3:4274d9103f1d | 2028 | return 1; |
cparata | 3:4274d9103f1d | 2029 | } |
cparata | 3:4274d9103f1d | 2030 | |
cparata | 3:4274d9103f1d | 2031 | if (lsm6dso_read_reg(&_reg_ctx, LSM6DSO_EMB_FUNC_INT1, (uint8_t *)&int1_ctrl, 1) != 0) { |
cparata | 3:4274d9103f1d | 2032 | return 1; |
cparata | 3:4274d9103f1d | 2033 | } |
cparata | 3:4274d9103f1d | 2034 | |
cparata | 3:4274d9103f1d | 2035 | if (lsm6dso_read_reg(&_reg_ctx, LSM6DSO_EMB_FUNC_INT2, (uint8_t *)&int2_ctrl, 1) != 0) { |
cparata | 3:4274d9103f1d | 2036 | return 1; |
cparata | 3:4274d9103f1d | 2037 | } |
cparata | 3:4274d9103f1d | 2038 | |
cparata | 3:4274d9103f1d | 2039 | if (lsm6dso_mem_bank_set(&_reg_ctx, LSM6DSO_USER_BANK) != 0) { |
cparata | 3:4274d9103f1d | 2040 | return 1; |
cparata | 3:4274d9103f1d | 2041 | } |
cparata | 3:4274d9103f1d | 2042 | |
cparata | 3:4274d9103f1d | 2043 | if (lsm6dso_read_reg(&_reg_ctx, LSM6DSO_MD1_CFG, (uint8_t *)&md1_cfg, 1) != 0) { |
cparata | 3:4274d9103f1d | 2044 | return 1; |
cparata | 0:6d69e896ce38 | 2045 | } |
cparata | 3:4274d9103f1d | 2046 | |
cparata | 3:4274d9103f1d | 2047 | if (lsm6dso_read_reg(&_reg_ctx, LSM6DSO_MD2_CFG, (uint8_t *)&md2_cfg, 1) != 0) { |
cparata | 3:4274d9103f1d | 2048 | return 1; |
cparata | 3:4274d9103f1d | 2049 | } |
cparata | 3:4274d9103f1d | 2050 | |
cparata | 3:4274d9103f1d | 2051 | if (lsm6dso_tilt_flag_data_ready_get(&_reg_ctx, &tilt_ia) != 0) { |
cparata | 3:4274d9103f1d | 2052 | return 1; |
cparata | 0:6d69e896ce38 | 2053 | } |
cparata | 3:4274d9103f1d | 2054 | |
cparata | 3:4274d9103f1d | 2055 | if ((md1_cfg.int1_ff == 1U) || (md2_cfg.int2_ff == 1U)) { |
cparata | 3:4274d9103f1d | 2056 | if (wake_up_src.ff_ia == 1U) { |
cparata | 3:4274d9103f1d | 2057 | status->FreeFallStatus = 1; |
cparata | 3:4274d9103f1d | 2058 | } |
cparata | 0:6d69e896ce38 | 2059 | } |
cparata | 3:4274d9103f1d | 2060 | |
cparata | 3:4274d9103f1d | 2061 | if ((md1_cfg.int1_wu == 1U) || (md2_cfg.int2_wu == 1U)) { |
cparata | 3:4274d9103f1d | 2062 | if (wake_up_src.wu_ia == 1U) { |
cparata | 3:4274d9103f1d | 2063 | status->WakeUpStatus = 1; |
cparata | 3:4274d9103f1d | 2064 | } |
cparata | 3:4274d9103f1d | 2065 | } |
cparata | 3:4274d9103f1d | 2066 | |
cparata | 3:4274d9103f1d | 2067 | if ((md1_cfg.int1_single_tap == 1U) || (md2_cfg.int2_single_tap == 1U)) { |
cparata | 3:4274d9103f1d | 2068 | if (tap_src.single_tap == 1U) { |
cparata | 3:4274d9103f1d | 2069 | status->TapStatus = 1; |
cparata | 3:4274d9103f1d | 2070 | } |
cparata | 0:6d69e896ce38 | 2071 | } |
cparata | 3:4274d9103f1d | 2072 | |
cparata | 3:4274d9103f1d | 2073 | if ((md1_cfg.int1_double_tap == 1U) || (md2_cfg.int2_double_tap == 1U)) { |
cparata | 3:4274d9103f1d | 2074 | if (tap_src.double_tap == 1U) { |
cparata | 3:4274d9103f1d | 2075 | status->DoubleTapStatus = 1; |
cparata | 3:4274d9103f1d | 2076 | } |
cparata | 3:4274d9103f1d | 2077 | } |
cparata | 3:4274d9103f1d | 2078 | |
cparata | 3:4274d9103f1d | 2079 | if ((md1_cfg.int1_6d == 1U) || (md2_cfg.int2_6d == 1U)) { |
cparata | 3:4274d9103f1d | 2080 | if (d6d_src.d6d_ia == 1U) { |
cparata | 3:4274d9103f1d | 2081 | status->D6DOrientationStatus = 1; |
cparata | 3:4274d9103f1d | 2082 | } |
cparata | 0:6d69e896ce38 | 2083 | } |
cparata | 3:4274d9103f1d | 2084 | |
cparata | 3:4274d9103f1d | 2085 | if (int1_ctrl.int1_step_detector == 1U) { |
cparata | 3:4274d9103f1d | 2086 | if (func_src.step_detected == 1U) { |
cparata | 3:4274d9103f1d | 2087 | status->StepStatus = 1; |
cparata | 3:4274d9103f1d | 2088 | } |
cparata | 0:6d69e896ce38 | 2089 | } |
cparata | 3:4274d9103f1d | 2090 | |
cparata | 3:4274d9103f1d | 2091 | if ((int1_ctrl.int1_tilt == 1U) || (int2_ctrl.int2_tilt == 1U)) { |
cparata | 3:4274d9103f1d | 2092 | if (tilt_ia == 1U) { |
cparata | 3:4274d9103f1d | 2093 | status->TiltStatus = 1; |
cparata | 3:4274d9103f1d | 2094 | } |
cparata | 0:6d69e896ce38 | 2095 | } |
cparata | 3:4274d9103f1d | 2096 | |
cparata | 3:4274d9103f1d | 2097 | return 0; |
cparata | 0:6d69e896ce38 | 2098 | } |
cparata | 0:6d69e896ce38 | 2099 | |
cparata | 0:6d69e896ce38 | 2100 | /** |
cparata | 0:6d69e896ce38 | 2101 | * @brief Set self test |
cparata | 0:6d69e896ce38 | 2102 | * @param val the value of st_xl in reg CTRL5_C |
cparata | 0:6d69e896ce38 | 2103 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 2104 | */ |
cparata | 0:6d69e896ce38 | 2105 | int LSM6DSOSensor::set_x_self_test(uint8_t val) |
cparata | 0:6d69e896ce38 | 2106 | { |
cparata | 3:4274d9103f1d | 2107 | lsm6dso_st_xl_t reg; |
cparata | 3:4274d9103f1d | 2108 | |
cparata | 3:4274d9103f1d | 2109 | reg = (val == 0U) ? LSM6DSO_XL_ST_DISABLE |
cparata | 3:4274d9103f1d | 2110 | : (val == 1U) ? LSM6DSO_XL_ST_POSITIVE |
cparata | 3:4274d9103f1d | 2111 | : (val == 2U) ? LSM6DSO_XL_ST_NEGATIVE |
cparata | 3:4274d9103f1d | 2112 | : LSM6DSO_XL_ST_DISABLE; |
cparata | 3:4274d9103f1d | 2113 | |
cparata | 3:4274d9103f1d | 2114 | if (lsm6dso_xl_self_test_set(&_reg_ctx, reg) != 0) { |
cparata | 3:4274d9103f1d | 2115 | return 1; |
cparata | 3:4274d9103f1d | 2116 | } |
cparata | 3:4274d9103f1d | 2117 | |
cparata | 3:4274d9103f1d | 2118 | return 0; |
cparata | 0:6d69e896ce38 | 2119 | } |
cparata | 0:6d69e896ce38 | 2120 | |
cparata | 0:6d69e896ce38 | 2121 | /** |
cparata | 0:6d69e896ce38 | 2122 | * @brief Get the LSM6DSO GYRO data ready bit value |
cparata | 0:6d69e896ce38 | 2123 | * @param status the status of data ready bit |
cparata | 0:6d69e896ce38 | 2124 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 2125 | */ |
cparata | 0:6d69e896ce38 | 2126 | int LSM6DSOSensor::get_g_drdy_status(uint8_t *status) |
cparata | 0:6d69e896ce38 | 2127 | { |
cparata | 3:4274d9103f1d | 2128 | if (lsm6dso_gy_flag_data_ready_get(&_reg_ctx, status) != 0) { |
cparata | 3:4274d9103f1d | 2129 | return 1; |
cparata | 3:4274d9103f1d | 2130 | } |
cparata | 3:4274d9103f1d | 2131 | |
cparata | 3:4274d9103f1d | 2132 | return 0; |
cparata | 0:6d69e896ce38 | 2133 | } |
cparata | 0:6d69e896ce38 | 2134 | |
cparata | 0:6d69e896ce38 | 2135 | /** |
cparata | 0:6d69e896ce38 | 2136 | * @brief Set self test |
cparata | 0:6d69e896ce38 | 2137 | * @param val the value of st_xl in reg CTRL5_C |
cparata | 0:6d69e896ce38 | 2138 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 2139 | */ |
cparata | 0:6d69e896ce38 | 2140 | int LSM6DSOSensor::set_g_self_test(uint8_t val) |
cparata | 0:6d69e896ce38 | 2141 | { |
cparata | 3:4274d9103f1d | 2142 | lsm6dso_st_g_t reg; |
cparata | 3:4274d9103f1d | 2143 | |
cparata | 3:4274d9103f1d | 2144 | reg = (val == 0U) ? LSM6DSO_GY_ST_DISABLE |
cparata | 3:4274d9103f1d | 2145 | : (val == 1U) ? LSM6DSO_GY_ST_POSITIVE |
cparata | 3:4274d9103f1d | 2146 | : (val == 2U) ? LSM6DSO_GY_ST_NEGATIVE |
cparata | 3:4274d9103f1d | 2147 | : LSM6DSO_GY_ST_DISABLE; |
cparata | 3:4274d9103f1d | 2148 | |
cparata | 3:4274d9103f1d | 2149 | |
cparata | 3:4274d9103f1d | 2150 | if (lsm6dso_gy_self_test_set(&_reg_ctx, reg) != 0) { |
cparata | 3:4274d9103f1d | 2151 | return 1; |
cparata | 3:4274d9103f1d | 2152 | } |
cparata | 3:4274d9103f1d | 2153 | |
cparata | 3:4274d9103f1d | 2154 | return 0; |
cparata | 0:6d69e896ce38 | 2155 | } |
cparata | 0:6d69e896ce38 | 2156 | |
cparata | 0:6d69e896ce38 | 2157 | /** |
cparata | 0:6d69e896ce38 | 2158 | * @brief Get the LSM6DSO FIFO number of samples |
cparata | 0:6d69e896ce38 | 2159 | * @param num_samples number of samples |
cparata | 0:6d69e896ce38 | 2160 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 2161 | */ |
cparata | 0:6d69e896ce38 | 2162 | int LSM6DSOSensor::get_fifo_num_samples(uint16_t *num_samples) |
cparata | 0:6d69e896ce38 | 2163 | { |
cparata | 3:4274d9103f1d | 2164 | if (lsm6dso_fifo_data_level_get(&_reg_ctx, num_samples) != 0) { |
cparata | 3:4274d9103f1d | 2165 | return 1; |
cparata | 3:4274d9103f1d | 2166 | } |
cparata | 3:4274d9103f1d | 2167 | |
cparata | 3:4274d9103f1d | 2168 | return 0; |
cparata | 0:6d69e896ce38 | 2169 | } |
cparata | 0:6d69e896ce38 | 2170 | |
cparata | 0:6d69e896ce38 | 2171 | /** |
cparata | 0:6d69e896ce38 | 2172 | * @brief Get the LSM6DSO FIFO full status |
cparata | 0:6d69e896ce38 | 2173 | * @param status FIFO full status |
cparata | 0:6d69e896ce38 | 2174 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 2175 | */ |
cparata | 0:6d69e896ce38 | 2176 | int LSM6DSOSensor::get_fifo_full_status(uint8_t *status) |
cparata | 0:6d69e896ce38 | 2177 | { |
cparata | 3:4274d9103f1d | 2178 | lsm6dso_reg_t reg; |
cparata | 3:4274d9103f1d | 2179 | |
cparata | 3:4274d9103f1d | 2180 | if (lsm6dso_read_reg(&_reg_ctx, LSM6DSO_FIFO_STATUS2, ®.byte, 1) != 0) { |
cparata | 3:4274d9103f1d | 2181 | return 1; |
cparata | 3:4274d9103f1d | 2182 | } |
cparata | 3:4274d9103f1d | 2183 | |
cparata | 3:4274d9103f1d | 2184 | *status = reg.fifo_status2.fifo_full_ia; |
cparata | 3:4274d9103f1d | 2185 | |
cparata | 3:4274d9103f1d | 2186 | return 0; |
cparata | 0:6d69e896ce38 | 2187 | } |
cparata | 0:6d69e896ce38 | 2188 | |
cparata | 0:6d69e896ce38 | 2189 | /** |
cparata | 0:6d69e896ce38 | 2190 | * @brief Set the LSM6DSO FIFO full interrupt on INT1 pin |
cparata | 0:6d69e896ce38 | 2191 | * @param status FIFO full interrupt on INT1 pin status |
cparata | 0:6d69e896ce38 | 2192 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 2193 | */ |
cparata | 0:6d69e896ce38 | 2194 | int LSM6DSOSensor::set_fifo_int1_fifo_full(uint8_t status) |
cparata | 0:6d69e896ce38 | 2195 | { |
cparata | 3:4274d9103f1d | 2196 | lsm6dso_reg_t reg; |
cparata | 3:4274d9103f1d | 2197 | |
cparata | 3:4274d9103f1d | 2198 | if (lsm6dso_read_reg(&_reg_ctx, LSM6DSO_INT1_CTRL, ®.byte, 1) != 0) { |
cparata | 3:4274d9103f1d | 2199 | return 1; |
cparata | 3:4274d9103f1d | 2200 | } |
cparata | 3:4274d9103f1d | 2201 | |
cparata | 3:4274d9103f1d | 2202 | reg.int1_ctrl.int1_fifo_full = status; |
cparata | 3:4274d9103f1d | 2203 | |
cparata | 3:4274d9103f1d | 2204 | if (lsm6dso_write_reg(&_reg_ctx, LSM6DSO_INT1_CTRL, ®.byte, 1) != 0) { |
cparata | 3:4274d9103f1d | 2205 | return 1; |
cparata | 3:4274d9103f1d | 2206 | } |
cparata | 3:4274d9103f1d | 2207 | |
cparata | 3:4274d9103f1d | 2208 | return 0; |
cparata | 0:6d69e896ce38 | 2209 | } |
cparata | 0:6d69e896ce38 | 2210 | |
cparata | 0:6d69e896ce38 | 2211 | /** |
cparata | 0:6d69e896ce38 | 2212 | * @brief Set the LSM6DSO FIFO watermark level |
cparata | 0:6d69e896ce38 | 2213 | * @param watermark FIFO watermark level |
cparata | 0:6d69e896ce38 | 2214 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 2215 | */ |
cparata | 0:6d69e896ce38 | 2216 | int LSM6DSOSensor::set_fifo_watermark_level(uint16_t watermark) |
cparata | 0:6d69e896ce38 | 2217 | { |
cparata | 3:4274d9103f1d | 2218 | if (lsm6dso_fifo_watermark_set(&_reg_ctx, watermark) != 0) { |
cparata | 3:4274d9103f1d | 2219 | return 1; |
cparata | 3:4274d9103f1d | 2220 | } |
cparata | 3:4274d9103f1d | 2221 | |
cparata | 3:4274d9103f1d | 2222 | return 0; |
cparata | 0:6d69e896ce38 | 2223 | } |
cparata | 0:6d69e896ce38 | 2224 | |
cparata | 0:6d69e896ce38 | 2225 | /** |
cparata | 0:6d69e896ce38 | 2226 | * @brief Set the LSM6DSO FIFO stop on watermark |
cparata | 0:6d69e896ce38 | 2227 | * @param status FIFO stop on watermark status |
cparata | 0:6d69e896ce38 | 2228 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 2229 | */ |
cparata | 0:6d69e896ce38 | 2230 | int LSM6DSOSensor::set_fifo_stop_on_fth(uint8_t status) |
cparata | 0:6d69e896ce38 | 2231 | { |
cparata | 3:4274d9103f1d | 2232 | if (lsm6dso_fifo_stop_on_wtm_set(&_reg_ctx, status) != 0) { |
cparata | 3:4274d9103f1d | 2233 | return 1; |
cparata | 3:4274d9103f1d | 2234 | } |
cparata | 3:4274d9103f1d | 2235 | |
cparata | 3:4274d9103f1d | 2236 | return 0; |
cparata | 0:6d69e896ce38 | 2237 | } |
cparata | 0:6d69e896ce38 | 2238 | |
cparata | 0:6d69e896ce38 | 2239 | /** |
cparata | 0:6d69e896ce38 | 2240 | * @brief Set the LSM6DSO FIFO mode |
cparata | 0:6d69e896ce38 | 2241 | * @param mode FIFO mode |
cparata | 0:6d69e896ce38 | 2242 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 2243 | */ |
cparata | 0:6d69e896ce38 | 2244 | int LSM6DSOSensor::set_fifo_mode(uint8_t mode) |
cparata | 0:6d69e896ce38 | 2245 | { |
cparata | 3:4274d9103f1d | 2246 | int ret = 0; |
cparata | 3:4274d9103f1d | 2247 | |
cparata | 3:4274d9103f1d | 2248 | /* Verify that the passed parameter contains one of the valid values. */ |
cparata | 3:4274d9103f1d | 2249 | switch ((lsm6dso_fifo_mode_t)mode) { |
cparata | 3:4274d9103f1d | 2250 | case LSM6DSO_BYPASS_MODE: |
cparata | 3:4274d9103f1d | 2251 | case LSM6DSO_FIFO_MODE: |
cparata | 3:4274d9103f1d | 2252 | case LSM6DSO_STREAM_TO_FIFO_MODE: |
cparata | 3:4274d9103f1d | 2253 | case LSM6DSO_BYPASS_TO_STREAM_MODE: |
cparata | 3:4274d9103f1d | 2254 | case LSM6DSO_STREAM_MODE: |
cparata | 3:4274d9103f1d | 2255 | break; |
cparata | 3:4274d9103f1d | 2256 | |
cparata | 3:4274d9103f1d | 2257 | default: |
cparata | 3:4274d9103f1d | 2258 | ret = 1; |
cparata | 3:4274d9103f1d | 2259 | break; |
cparata | 3:4274d9103f1d | 2260 | } |
cparata | 3:4274d9103f1d | 2261 | |
cparata | 3:4274d9103f1d | 2262 | if (ret == 1) { |
cparata | 3:4274d9103f1d | 2263 | return ret; |
cparata | 3:4274d9103f1d | 2264 | } |
cparata | 3:4274d9103f1d | 2265 | |
cparata | 3:4274d9103f1d | 2266 | if (lsm6dso_fifo_mode_set(&_reg_ctx, (lsm6dso_fifo_mode_t)mode) != 0) { |
cparata | 3:4274d9103f1d | 2267 | return 1; |
cparata | 3:4274d9103f1d | 2268 | } |
cparata | 3:4274d9103f1d | 2269 | |
cparata | 0:6d69e896ce38 | 2270 | return ret; |
cparata | 0:6d69e896ce38 | 2271 | } |
cparata | 0:6d69e896ce38 | 2272 | |
cparata | 0:6d69e896ce38 | 2273 | /** |
cparata | 0:6d69e896ce38 | 2274 | * @brief Get the LSM6DSO FIFO tag |
cparata | 0:6d69e896ce38 | 2275 | * @param tag FIFO tag |
cparata | 0:6d69e896ce38 | 2276 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 2277 | */ |
cparata | 0:6d69e896ce38 | 2278 | int LSM6DSOSensor::get_fifo_tag(uint8_t *tag) |
cparata | 0:6d69e896ce38 | 2279 | { |
cparata | 3:4274d9103f1d | 2280 | lsm6dso_fifo_tag_t tag_local; |
cparata | 3:4274d9103f1d | 2281 | |
cparata | 3:4274d9103f1d | 2282 | if (lsm6dso_fifo_sensor_tag_get(&_reg_ctx, &tag_local) != 0) { |
cparata | 3:4274d9103f1d | 2283 | return 1; |
cparata | 3:4274d9103f1d | 2284 | } |
cparata | 3:4274d9103f1d | 2285 | |
cparata | 3:4274d9103f1d | 2286 | *tag = (uint8_t)tag_local; |
cparata | 3:4274d9103f1d | 2287 | |
cparata | 3:4274d9103f1d | 2288 | return 0; |
cparata | 0:6d69e896ce38 | 2289 | } |
cparata | 0:6d69e896ce38 | 2290 | |
cparata | 0:6d69e896ce38 | 2291 | /** |
cparata | 0:6d69e896ce38 | 2292 | * @brief Get the LSM6DSO FIFO raw data |
cparata | 0:6d69e896ce38 | 2293 | * @param data FIFO raw data array [6] |
cparata | 0:6d69e896ce38 | 2294 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 2295 | */ |
cparata | 0:6d69e896ce38 | 2296 | int LSM6DSOSensor::get_fifo_data(uint8_t *data) |
cparata | 0:6d69e896ce38 | 2297 | { |
cparata | 3:4274d9103f1d | 2298 | if (lsm6dso_read_reg(&_reg_ctx, LSM6DSO_FIFO_DATA_OUT_X_L, data, 6) != 0) { |
cparata | 3:4274d9103f1d | 2299 | return 1; |
cparata | 3:4274d9103f1d | 2300 | } |
cparata | 3:4274d9103f1d | 2301 | |
cparata | 3:4274d9103f1d | 2302 | return 0; |
cparata | 0:6d69e896ce38 | 2303 | } |
cparata | 0:6d69e896ce38 | 2304 | |
cparata | 0:6d69e896ce38 | 2305 | /** |
cparata | 0:6d69e896ce38 | 2306 | * @brief Get the LSM6DSO FIFO accelero single sample (16-bit data per 3 axes) and calculate acceleration [mg] |
cparata | 0:6d69e896ce38 | 2307 | * @param acceleration FIFO accelero axes [mg] |
cparata | 0:6d69e896ce38 | 2308 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 2309 | */ |
cparata | 0:6d69e896ce38 | 2310 | int LSM6DSOSensor::get_fifo_x_axes(int32_t *acceleration) |
cparata | 0:6d69e896ce38 | 2311 | { |
cparata | 3:4274d9103f1d | 2312 | uint8_t data[6]; |
cparata | 3:4274d9103f1d | 2313 | int16_t data_raw[3]; |
cparata | 3:4274d9103f1d | 2314 | float sensitivity = 0.0f; |
cparata | 3:4274d9103f1d | 2315 | float acceleration_float[3]; |
cparata | 3:4274d9103f1d | 2316 | |
cparata | 3:4274d9103f1d | 2317 | if (get_fifo_data(data) != 0) { |
cparata | 3:4274d9103f1d | 2318 | return 1; |
cparata | 3:4274d9103f1d | 2319 | } |
cparata | 3:4274d9103f1d | 2320 | |
cparata | 3:4274d9103f1d | 2321 | data_raw[0] = ((int16_t)data[1] << 8) | data[0]; |
cparata | 3:4274d9103f1d | 2322 | data_raw[1] = ((int16_t)data[3] << 8) | data[2]; |
cparata | 3:4274d9103f1d | 2323 | data_raw[2] = ((int16_t)data[5] << 8) | data[4]; |
cparata | 3:4274d9103f1d | 2324 | |
cparata | 3:4274d9103f1d | 2325 | if (get_x_sensitivity(&sensitivity) != 0) { |
cparata | 3:4274d9103f1d | 2326 | return 1; |
cparata | 3:4274d9103f1d | 2327 | } |
cparata | 3:4274d9103f1d | 2328 | |
cparata | 3:4274d9103f1d | 2329 | acceleration_float[0] = (float)data_raw[0] * sensitivity; |
cparata | 3:4274d9103f1d | 2330 | acceleration_float[1] = (float)data_raw[1] * sensitivity; |
cparata | 3:4274d9103f1d | 2331 | acceleration_float[2] = (float)data_raw[2] * sensitivity; |
cparata | 3:4274d9103f1d | 2332 | |
cparata | 3:4274d9103f1d | 2333 | acceleration[0] = (int32_t)acceleration_float[0]; |
cparata | 3:4274d9103f1d | 2334 | acceleration[1] = (int32_t)acceleration_float[1]; |
cparata | 3:4274d9103f1d | 2335 | acceleration[2] = (int32_t)acceleration_float[2]; |
cparata | 3:4274d9103f1d | 2336 | |
cparata | 3:4274d9103f1d | 2337 | return 0; |
cparata | 0:6d69e896ce38 | 2338 | } |
cparata | 0:6d69e896ce38 | 2339 | |
cparata | 0:6d69e896ce38 | 2340 | /** |
cparata | 0:6d69e896ce38 | 2341 | * @brief Set the LSM6DSO FIFO accelero BDR value |
cparata | 0:6d69e896ce38 | 2342 | * @param bdr FIFO accelero BDR value |
cparata | 0:6d69e896ce38 | 2343 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 2344 | */ |
cparata | 0:6d69e896ce38 | 2345 | int LSM6DSOSensor::set_fifo_x_bdr(float bdr) |
cparata | 0:6d69e896ce38 | 2346 | { |
cparata | 3:4274d9103f1d | 2347 | lsm6dso_bdr_xl_t new_bdr; |
cparata | 3:4274d9103f1d | 2348 | |
cparata | 3:4274d9103f1d | 2349 | new_bdr = (bdr <= 0.0f) ? LSM6DSO_XL_NOT_BATCHED |
cparata | 3:4274d9103f1d | 2350 | : (bdr <= 12.5f) ? LSM6DSO_XL_BATCHED_AT_12Hz5 |
cparata | 3:4274d9103f1d | 2351 | : (bdr <= 26.0f) ? LSM6DSO_XL_BATCHED_AT_26Hz |
cparata | 3:4274d9103f1d | 2352 | : (bdr <= 52.0f) ? LSM6DSO_XL_BATCHED_AT_52Hz |
cparata | 3:4274d9103f1d | 2353 | : (bdr <= 104.0f) ? LSM6DSO_XL_BATCHED_AT_104Hz |
cparata | 3:4274d9103f1d | 2354 | : (bdr <= 208.0f) ? LSM6DSO_XL_BATCHED_AT_208Hz |
cparata | 3:4274d9103f1d | 2355 | : (bdr <= 416.0f) ? LSM6DSO_XL_BATCHED_AT_417Hz |
cparata | 3:4274d9103f1d | 2356 | : (bdr <= 833.0f) ? LSM6DSO_XL_BATCHED_AT_833Hz |
cparata | 3:4274d9103f1d | 2357 | : (bdr <= 1660.0f) ? LSM6DSO_XL_BATCHED_AT_1667Hz |
cparata | 3:4274d9103f1d | 2358 | : (bdr <= 3330.0f) ? LSM6DSO_XL_BATCHED_AT_3333Hz |
cparata | 3:4274d9103f1d | 2359 | : LSM6DSO_XL_BATCHED_AT_6667Hz; |
cparata | 3:4274d9103f1d | 2360 | |
cparata | 3:4274d9103f1d | 2361 | if (lsm6dso_fifo_xl_batch_set(&_reg_ctx, new_bdr) != 0) { |
cparata | 3:4274d9103f1d | 2362 | return 1; |
cparata | 3:4274d9103f1d | 2363 | } |
cparata | 3:4274d9103f1d | 2364 | |
cparata | 3:4274d9103f1d | 2365 | return 0; |
cparata | 0:6d69e896ce38 | 2366 | } |
cparata | 0:6d69e896ce38 | 2367 | |
cparata | 0:6d69e896ce38 | 2368 | /** |
cparata | 0:6d69e896ce38 | 2369 | * @brief Get the LSM6DSO FIFO gyro single sample (16-bit data per 3 axes) and calculate angular velocity [mDPS] |
cparata | 0:6d69e896ce38 | 2370 | * @param angular_velocity FIFO gyro axes [mDPS] |
cparata | 0:6d69e896ce38 | 2371 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 2372 | */ |
cparata | 0:6d69e896ce38 | 2373 | int LSM6DSOSensor::get_fifo_g_axes(int32_t *angular_velocity) |
cparata | 0:6d69e896ce38 | 2374 | { |
cparata | 3:4274d9103f1d | 2375 | uint8_t data[6]; |
cparata | 3:4274d9103f1d | 2376 | int16_t data_raw[3]; |
cparata | 3:4274d9103f1d | 2377 | float sensitivity = 0.0f; |
cparata | 3:4274d9103f1d | 2378 | float angular_velocity_float[3]; |
cparata | 3:4274d9103f1d | 2379 | |
cparata | 3:4274d9103f1d | 2380 | if (get_fifo_data(data) != 0) { |
cparata | 3:4274d9103f1d | 2381 | return 1; |
cparata | 3:4274d9103f1d | 2382 | } |
cparata | 3:4274d9103f1d | 2383 | |
cparata | 3:4274d9103f1d | 2384 | data_raw[0] = ((int16_t)data[1] << 8) | data[0]; |
cparata | 3:4274d9103f1d | 2385 | data_raw[1] = ((int16_t)data[3] << 8) | data[2]; |
cparata | 3:4274d9103f1d | 2386 | data_raw[2] = ((int16_t)data[5] << 8) | data[4]; |
cparata | 3:4274d9103f1d | 2387 | |
cparata | 3:4274d9103f1d | 2388 | if (get_g_sensitivity(&sensitivity) != 0) { |
cparata | 3:4274d9103f1d | 2389 | return 1; |
cparata | 3:4274d9103f1d | 2390 | } |
cparata | 3:4274d9103f1d | 2391 | |
cparata | 3:4274d9103f1d | 2392 | angular_velocity_float[0] = (float)data_raw[0] * sensitivity; |
cparata | 3:4274d9103f1d | 2393 | angular_velocity_float[1] = (float)data_raw[1] * sensitivity; |
cparata | 3:4274d9103f1d | 2394 | angular_velocity_float[2] = (float)data_raw[2] * sensitivity; |
cparata | 3:4274d9103f1d | 2395 | |
cparata | 3:4274d9103f1d | 2396 | angular_velocity[0] = (int32_t)angular_velocity_float[0]; |
cparata | 3:4274d9103f1d | 2397 | angular_velocity[1] = (int32_t)angular_velocity_float[1]; |
cparata | 3:4274d9103f1d | 2398 | angular_velocity[2] = (int32_t)angular_velocity_float[2]; |
cparata | 3:4274d9103f1d | 2399 | |
cparata | 3:4274d9103f1d | 2400 | return 0; |
cparata | 0:6d69e896ce38 | 2401 | } |
cparata | 0:6d69e896ce38 | 2402 | |
cparata | 0:6d69e896ce38 | 2403 | /** |
cparata | 0:6d69e896ce38 | 2404 | * @brief Set the LSM6DSO FIFO gyro BDR value |
cparata | 0:6d69e896ce38 | 2405 | * @param bdr FIFO gyro BDR value |
cparata | 0:6d69e896ce38 | 2406 | * @retval 0 in case of success, an error code otherwise |
cparata | 0:6d69e896ce38 | 2407 | */ |
cparata | 0:6d69e896ce38 | 2408 | int LSM6DSOSensor::set_fifo_g_bdr(float bdr) |
cparata | 0:6d69e896ce38 | 2409 | { |
cparata | 3:4274d9103f1d | 2410 | lsm6dso_bdr_gy_t new_bdr; |
cparata | 3:4274d9103f1d | 2411 | |
cparata | 3:4274d9103f1d | 2412 | new_bdr = (bdr <= 0.0f) ? LSM6DSO_GY_NOT_BATCHED |
cparata | 3:4274d9103f1d | 2413 | : (bdr <= 12.5f) ? LSM6DSO_GY_BATCHED_AT_12Hz5 |
cparata | 3:4274d9103f1d | 2414 | : (bdr <= 26.0f) ? LSM6DSO_GY_BATCHED_AT_26Hz |
cparata | 3:4274d9103f1d | 2415 | : (bdr <= 52.0f) ? LSM6DSO_GY_BATCHED_AT_52Hz |
cparata | 3:4274d9103f1d | 2416 | : (bdr <= 104.0f) ? LSM6DSO_GY_BATCHED_AT_104Hz |
cparata | 3:4274d9103f1d | 2417 | : (bdr <= 208.0f) ? LSM6DSO_GY_BATCHED_AT_208Hz |
cparata | 3:4274d9103f1d | 2418 | : (bdr <= 416.0f) ? LSM6DSO_GY_BATCHED_AT_417Hz |
cparata | 3:4274d9103f1d | 2419 | : (bdr <= 833.0f) ? LSM6DSO_GY_BATCHED_AT_833Hz |
cparata | 3:4274d9103f1d | 2420 | : (bdr <= 1660.0f) ? LSM6DSO_GY_BATCHED_AT_1667Hz |
cparata | 3:4274d9103f1d | 2421 | : (bdr <= 3330.0f) ? LSM6DSO_GY_BATCHED_AT_3333Hz |
cparata | 3:4274d9103f1d | 2422 | : LSM6DSO_GY_BATCHED_AT_6667Hz; |
cparata | 3:4274d9103f1d | 2423 | |
cparata | 3:4274d9103f1d | 2424 | if (lsm6dso_fifo_gy_batch_set(&_reg_ctx, new_bdr) != 0) { |
cparata | 3:4274d9103f1d | 2425 | return 1; |
cparata | 3:4274d9103f1d | 2426 | } |
cparata | 3:4274d9103f1d | 2427 | |
cparata | 3:4274d9103f1d | 2428 | return 0; |
cparata | 0:6d69e896ce38 | 2429 | } |
cparata | 0:6d69e896ce38 | 2430 | |
cparata | 0:6d69e896ce38 | 2431 | |
cparata | 0:6d69e896ce38 | 2432 | |
cparata | 0:6d69e896ce38 | 2433 | int32_t LSM6DSO_io_write(void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite) |
cparata | 0:6d69e896ce38 | 2434 | { |
cparata | 3:4274d9103f1d | 2435 | return ((LSM6DSOSensor *)handle)->io_write(pBuffer, WriteAddr, nBytesToWrite); |
cparata | 0:6d69e896ce38 | 2436 | } |
cparata | 0:6d69e896ce38 | 2437 | |
cparata | 0:6d69e896ce38 | 2438 | int32_t LSM6DSO_io_read(void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead) |
cparata | 0:6d69e896ce38 | 2439 | { |
cparata | 3:4274d9103f1d | 2440 | return ((LSM6DSOSensor *)handle)->io_read(pBuffer, ReadAddr, nBytesToRead); |
cparata | 0:6d69e896ce38 | 2441 | } |