LSM6DSO accelerometer and gyroscope sensor library

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   X_NUCLEO_IKS01A3

Committer:
martlefebvre94
Date:
Tue Sep 17 12:29:47 2019 +0000
Revision:
5:213250c75a9e
Parent:
4:bcf0cf6e43a7
Functions to configure the LP and HP filters

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cparata 0:6d69e896ce38 1 /**
cparata 0:6d69e896ce38 2 ******************************************************************************
cparata 0:6d69e896ce38 3 * @file LSM6DSOSensor.h
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 Abstract Class 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>&copy; 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 /* Prevent recursive inclusion -----------------------------------------------*/
cparata 0:6d69e896ce38 41
cparata 0:6d69e896ce38 42 #ifndef __LSM6DSOSensor_H__
cparata 0:6d69e896ce38 43 #define __LSM6DSOSensor_H__
cparata 0:6d69e896ce38 44
cparata 0:6d69e896ce38 45
cparata 0:6d69e896ce38 46 /* Includes ------------------------------------------------------------------*/
cparata 0:6d69e896ce38 47 #include "DevI2C.h"
cparata 0:6d69e896ce38 48 #include "lsm6dso_reg.h"
cparata 0:6d69e896ce38 49 #include "MotionSensor.h"
cparata 0:6d69e896ce38 50 #include "GyroSensor.h"
cparata 0:6d69e896ce38 51 #include <assert.h>
cparata 0:6d69e896ce38 52
cparata 0:6d69e896ce38 53 /* Defines -------------------------------------------------------------------*/
cparata 0:6d69e896ce38 54
cparata 0:6d69e896ce38 55 #define LSM6DSO_ACC_SENSITIVITY_FS_2G 0.061f
cparata 0:6d69e896ce38 56 #define LSM6DSO_ACC_SENSITIVITY_FS_4G 0.122f
cparata 0:6d69e896ce38 57 #define LSM6DSO_ACC_SENSITIVITY_FS_8G 0.244f
cparata 0:6d69e896ce38 58 #define LSM6DSO_ACC_SENSITIVITY_FS_16G 0.488f
cparata 0:6d69e896ce38 59
cparata 0:6d69e896ce38 60 #define LSM6DSO_GYRO_SENSITIVITY_FS_125DPS 4.375f
cparata 0:6d69e896ce38 61 #define LSM6DSO_GYRO_SENSITIVITY_FS_250DPS 8.750f
cparata 0:6d69e896ce38 62 #define LSM6DSO_GYRO_SENSITIVITY_FS_500DPS 17.500f
cparata 0:6d69e896ce38 63 #define LSM6DSO_GYRO_SENSITIVITY_FS_1000DPS 35.000f
cparata 0:6d69e896ce38 64 #define LSM6DSO_GYRO_SENSITIVITY_FS_2000DPS 70.000f
cparata 0:6d69e896ce38 65
cparata 0:6d69e896ce38 66
cparata 0:6d69e896ce38 67 /* Typedefs ------------------------------------------------------------------*/
cparata 0:6d69e896ce38 68
cparata 3:4274d9103f1d 69 typedef enum {
cparata 3:4274d9103f1d 70 LSM6DSO_INT1_PIN,
cparata 3:4274d9103f1d 71 LSM6DSO_INT2_PIN,
cparata 0:6d69e896ce38 72 } LSM6DSO_Interrupt_Pin_t;
cparata 0:6d69e896ce38 73
cparata 3:4274d9103f1d 74 typedef struct {
cparata 3:4274d9103f1d 75 unsigned int FreeFallStatus : 1;
cparata 3:4274d9103f1d 76 unsigned int TapStatus : 1;
cparata 3:4274d9103f1d 77 unsigned int DoubleTapStatus : 1;
cparata 3:4274d9103f1d 78 unsigned int WakeUpStatus : 1;
cparata 3:4274d9103f1d 79 unsigned int StepStatus : 1;
cparata 3:4274d9103f1d 80 unsigned int TiltStatus : 1;
cparata 3:4274d9103f1d 81 unsigned int D6DOrientationStatus : 1;
cparata 3:4274d9103f1d 82 unsigned int SleepStatus : 1;
cparata 0:6d69e896ce38 83 } LSM6DSO_Event_Status_t;
cparata 0:6d69e896ce38 84
cparata 0:6d69e896ce38 85
cparata 0:6d69e896ce38 86 /* Class Declaration ---------------------------------------------------------*/
cparata 3:4274d9103f1d 87
cparata 0:6d69e896ce38 88 /**
cparata 0:6d69e896ce38 89 * Abstract class of an LSM6DSO Inertial Measurement Unit (IMU) 6 axes
cparata 0:6d69e896ce38 90 * sensor.
cparata 0:6d69e896ce38 91 */
cparata 3:4274d9103f1d 92 class LSM6DSOSensor : public MotionSensor, public GyroSensor {
cparata 3:4274d9103f1d 93 public:
cparata 0:6d69e896ce38 94 enum SPI_type_t {SPI3W, SPI4W};
cparata 3:4274d9103f1d 95 LSM6DSOSensor(SPI *spi, PinName cs_pin, PinName int1_pin = NC, PinName int2_pin = NC, SPI_type_t spi_type = SPI4W);
cparata 3:4274d9103f1d 96 LSM6DSOSensor(DevI2C *i2c, uint8_t address = LSM6DSO_I2C_ADD_H, PinName int1_pin = NC, PinName int2_pin = NC);
cparata 0:6d69e896ce38 97 virtual int init(void *init);
cparata 0:6d69e896ce38 98 virtual int read_id(uint8_t *id);
cparata 0:6d69e896ce38 99 virtual int get_x_axes(int32_t *acceleration);
cparata 0:6d69e896ce38 100 virtual int get_g_axes(int32_t *angular_rate);
cparata 0:6d69e896ce38 101 virtual int get_x_sensitivity(float *sensitivity);
cparata 0:6d69e896ce38 102 virtual int get_g_sensitivity(float *sensitivity);
cparata 0:6d69e896ce38 103 virtual int get_x_axes_raw(int16_t *value);
cparata 0:6d69e896ce38 104 virtual int get_g_axes_raw(int16_t *value);
cparata 0:6d69e896ce38 105 virtual int get_x_odr(float *odr);
cparata 0:6d69e896ce38 106 virtual int get_g_odr(float *odr);
cparata 0:6d69e896ce38 107 virtual int set_x_odr(float odr);
cparata 0:6d69e896ce38 108 virtual int set_g_odr(float odr);
cparata 0:6d69e896ce38 109 virtual int get_x_fs(float *full_scale);
cparata 0:6d69e896ce38 110 virtual int get_g_fs(float *full_scale);
cparata 0:6d69e896ce38 111 virtual int set_x_fs(float full_scale);
cparata 0:6d69e896ce38 112 virtual int set_g_fs(float full_scale);
martlefebvre94 4:bcf0cf6e43a7 113 virtual int get_x_power_mode(uint8_t *xl_hm_mode, uint8_t *xl_ulp_en);
martlefebvre94 4:bcf0cf6e43a7 114 virtual int set_x_power_mode(uint8_t xl_hm_mode, uint8_t xl_ulp_en);
martlefebvre94 5:213250c75a9e 115 virtual int get_x_lpf2_en(uint8_t *lpf2_en);
martlefebvre94 5:213250c75a9e 116 virtual int set_x_lpf2_en(uint8_t lpf2_en);
martlefebvre94 5:213250c75a9e 117 virtual int get_x_filter_config(uint8_t *hp_slope_xl_en, uint8_t *hpcf_xl);
martlefebvre94 5:213250c75a9e 118 virtual int set_x_filter_config(uint8_t hp_slope_xl_en, uint8_t hpcf_xl);
martlefebvre94 5:213250c75a9e 119 virtual int get_g_power_mode(uint8_t *g_hm_mode);
martlefebvre94 5:213250c75a9e 120 virtual int set_g_power_mode(uint8_t g_hm_mode);
martlefebvre94 5:213250c75a9e 121 virtual int get_g_lpf_config(uint8_t *lpf1_sel_g, uint8_t *ftype);
martlefebvre94 5:213250c75a9e 122 virtual int set_g_lpf_config(uint8_t lpf1_sel_g, uint8_t ftype);
martlefebvre94 5:213250c75a9e 123 virtual int get_g_hpf_config(uint8_t *hp_en_g, uint8_t *hpm_g);
martlefebvre94 5:213250c75a9e 124 virtual int set_g_hpf_config(uint8_t hp_en_g, uint8_t hpm_g);
cparata 0:6d69e896ce38 125 int enable_x(void);
cparata 0:6d69e896ce38 126 int enable_g(void);
cparata 0:6d69e896ce38 127 int disable_x(void);
cparata 0:6d69e896ce38 128 int disable_g(void);
cparata 0:6d69e896ce38 129 int enable_free_fall_detection(LSM6DSO_Interrupt_Pin_t pin = LSM6DSO_INT1_PIN);
cparata 0:6d69e896ce38 130 int disable_free_fall_detection(void);
cparata 0:6d69e896ce38 131 int set_free_fall_threshold(uint8_t thr);
cparata 0:6d69e896ce38 132 int set_free_fall_duration(uint8_t dur);
cparata 0:6d69e896ce38 133 int enable_pedometer(void);
cparata 0:6d69e896ce38 134 int disable_pedometer(void);
cparata 0:6d69e896ce38 135 int get_step_counter(uint16_t *step_count);
cparata 0:6d69e896ce38 136 int reset_step_counter(void);
cparata 0:6d69e896ce38 137 int enable_tilt_detection(LSM6DSO_Interrupt_Pin_t pin = LSM6DSO_INT1_PIN);
cparata 0:6d69e896ce38 138 int disable_tilt_detection(void);
cparata 1:888ac5f8d970 139 int enable_wake_up_detection(LSM6DSO_Interrupt_Pin_t pin = LSM6DSO_INT1_PIN);
cparata 0:6d69e896ce38 140 int disable_wake_up_detection(void);
cparata 0:6d69e896ce38 141 int set_wake_up_threshold(uint8_t thr);
cparata 0:6d69e896ce38 142 int set_wake_up_duration(uint8_t dur);
cparata 0:6d69e896ce38 143 int enable_single_tap_detection(LSM6DSO_Interrupt_Pin_t pin = LSM6DSO_INT1_PIN);
cparata 0:6d69e896ce38 144 int disable_single_tap_detection(void);
cparata 0:6d69e896ce38 145 int enable_double_tap_detection(LSM6DSO_Interrupt_Pin_t pin = LSM6DSO_INT1_PIN);
cparata 0:6d69e896ce38 146 int disable_double_tap_detection(void);
cparata 0:6d69e896ce38 147 int set_tap_threshold(uint8_t thr);
cparata 0:6d69e896ce38 148 int set_tap_shock_time(uint8_t time);
cparata 0:6d69e896ce38 149 int set_tap_quiet_time(uint8_t time);
cparata 0:6d69e896ce38 150 int set_tap_duration_time(uint8_t time);
cparata 0:6d69e896ce38 151 int enable_6d_orientation(LSM6DSO_Interrupt_Pin_t pin = LSM6DSO_INT1_PIN);
cparata 0:6d69e896ce38 152 int disable_6d_orientation(void);
cparata 0:6d69e896ce38 153 int set_6d_orientation_threshold(uint8_t thr);
cparata 0:6d69e896ce38 154 int get_6d_orientation_xl(uint8_t *xl);
cparata 0:6d69e896ce38 155 int get_6d_orientation_xh(uint8_t *xh);
cparata 0:6d69e896ce38 156 int get_6d_orientation_yl(uint8_t *yl);
cparata 0:6d69e896ce38 157 int get_6d_orientation_yh(uint8_t *yh);
cparata 0:6d69e896ce38 158 int get_6d_orientation_zl(uint8_t *zl);
cparata 0:6d69e896ce38 159 int get_6d_orientation_zh(uint8_t *zh);
cparata 0:6d69e896ce38 160 int get_event_status(LSM6DSO_Event_Status_t *status);
cparata 0:6d69e896ce38 161 int read_reg(uint8_t reg, uint8_t *data);
cparata 0:6d69e896ce38 162 int write_reg(uint8_t reg, uint8_t data);
cparata 0:6d69e896ce38 163 int set_interrupt_latch(uint8_t status);
cparata 0:6d69e896ce38 164 int get_x_drdy_status(uint8_t *status);
cparata 0:6d69e896ce38 165 int set_x_self_test(uint8_t status);
cparata 0:6d69e896ce38 166 int get_g_drdy_status(uint8_t *status);
cparata 0:6d69e896ce38 167 int set_g_self_test(uint8_t status);
cparata 0:6d69e896ce38 168 int get_fifo_num_samples(uint16_t *num_samples);
cparata 0:6d69e896ce38 169 int get_fifo_full_status(uint8_t *status);
cparata 0:6d69e896ce38 170 int set_fifo_int1_fifo_full(uint8_t status);
cparata 0:6d69e896ce38 171 int set_fifo_watermark_level(uint16_t watermark);
cparata 0:6d69e896ce38 172 int set_fifo_stop_on_fth(uint8_t status);
cparata 0:6d69e896ce38 173 int set_fifo_mode(uint8_t mode);
cparata 0:6d69e896ce38 174 int get_fifo_tag(uint8_t *tag);
cparata 0:6d69e896ce38 175 int get_fifo_data(uint8_t *data);
cparata 0:6d69e896ce38 176 int get_fifo_x_axes(int32_t *acceleration);
cparata 0:6d69e896ce38 177 int set_fifo_x_bdr(float bdr);
cparata 0:6d69e896ce38 178 int get_fifo_g_axes(int32_t *angular_velocity);
cparata 0:6d69e896ce38 179 int set_fifo_g_bdr(float bdr);
cparata 3:4274d9103f1d 180
cparata 0:6d69e896ce38 181 /**
cparata 0:6d69e896ce38 182 * @brief Attaching an interrupt handler to the INT1 interrupt.
cparata 0:6d69e896ce38 183 * @param fptr An interrupt handler.
cparata 0:6d69e896ce38 184 * @retval None.
cparata 0:6d69e896ce38 185 */
cparata 0:6d69e896ce38 186 void attach_int1_irq(void (*fptr)(void))
cparata 0:6d69e896ce38 187 {
cparata 0:6d69e896ce38 188 _int1_irq.rise(fptr);
cparata 0:6d69e896ce38 189 }
cparata 0:6d69e896ce38 190
cparata 0:6d69e896ce38 191 /**
cparata 0:6d69e896ce38 192 * @brief Enabling the INT1 interrupt handling.
cparata 0:6d69e896ce38 193 * @param None.
cparata 0:6d69e896ce38 194 * @retval None.
cparata 0:6d69e896ce38 195 */
cparata 0:6d69e896ce38 196 void enable_int1_irq(void)
cparata 0:6d69e896ce38 197 {
cparata 0:6d69e896ce38 198 _int1_irq.enable_irq();
cparata 0:6d69e896ce38 199 }
cparata 3:4274d9103f1d 200
cparata 0:6d69e896ce38 201 /**
cparata 0:6d69e896ce38 202 * @brief Disabling the INT1 interrupt handling.
cparata 0:6d69e896ce38 203 * @param None.
cparata 0:6d69e896ce38 204 * @retval None.
cparata 0:6d69e896ce38 205 */
cparata 0:6d69e896ce38 206 void disable_int1_irq(void)
cparata 0:6d69e896ce38 207 {
cparata 0:6d69e896ce38 208 _int1_irq.disable_irq();
cparata 0:6d69e896ce38 209 }
cparata 3:4274d9103f1d 210
cparata 0:6d69e896ce38 211 /**
cparata 0:6d69e896ce38 212 * @brief Attaching an interrupt handler to the INT2 interrupt.
cparata 0:6d69e896ce38 213 * @param fptr An interrupt handler.
cparata 0:6d69e896ce38 214 * @retval None.
cparata 0:6d69e896ce38 215 */
cparata 0:6d69e896ce38 216 void attach_int2_irq(void (*fptr)(void))
cparata 0:6d69e896ce38 217 {
cparata 0:6d69e896ce38 218 _int2_irq.rise(fptr);
cparata 0:6d69e896ce38 219 }
cparata 0:6d69e896ce38 220
cparata 0:6d69e896ce38 221 /**
cparata 0:6d69e896ce38 222 * @brief Enabling the INT2 interrupt handling.
cparata 0:6d69e896ce38 223 * @param None.
cparata 0:6d69e896ce38 224 * @retval None.
cparata 0:6d69e896ce38 225 */
cparata 0:6d69e896ce38 226 void enable_int2_irq(void)
cparata 0:6d69e896ce38 227 {
cparata 0:6d69e896ce38 228 _int2_irq.enable_irq();
cparata 0:6d69e896ce38 229 }
cparata 3:4274d9103f1d 230
cparata 0:6d69e896ce38 231 /**
cparata 0:6d69e896ce38 232 * @brief Disabling the INT2 interrupt handling.
cparata 0:6d69e896ce38 233 * @param None.
cparata 0:6d69e896ce38 234 * @retval None.
cparata 0:6d69e896ce38 235 */
cparata 0:6d69e896ce38 236 void disable_int2_irq(void)
cparata 0:6d69e896ce38 237 {
cparata 0:6d69e896ce38 238 _int2_irq.disable_irq();
cparata 0:6d69e896ce38 239 }
cparata 3:4274d9103f1d 240
cparata 0:6d69e896ce38 241 /**
cparata 0:6d69e896ce38 242 * @brief Utility function to read data.
cparata 0:6d69e896ce38 243 * @param pBuffer: pointer to data to be read.
cparata 0:6d69e896ce38 244 * @param RegisterAddr: specifies internal address register to be read.
cparata 0:6d69e896ce38 245 * @param NumByteToRead: number of bytes to be read.
cparata 0:6d69e896ce38 246 * @retval 0 if ok, an error code otherwise.
cparata 0:6d69e896ce38 247 */
cparata 3:4274d9103f1d 248 uint8_t io_read(uint8_t *pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead)
cparata 3:4274d9103f1d 249 {
cparata 0:6d69e896ce38 250 if (_dev_spi) {
cparata 0:6d69e896ce38 251 /* Write Reg Address */
cparata 0:6d69e896ce38 252 _dev_spi->lock();
cparata 3:4274d9103f1d 253 _cs_pin = 0;
cparata 3:4274d9103f1d 254 if (_spi_type == SPI4W) {
cparata 0:6d69e896ce38 255 _dev_spi->write(RegisterAddr | 0x80);
cparata 3:4274d9103f1d 256 for (int i = 0; i < NumByteToRead; i++) {
cparata 3:4274d9103f1d 257 *(pBuffer + i) = _dev_spi->write(0x00);
cparata 0:6d69e896ce38 258 }
cparata 3:4274d9103f1d 259 } else if (_spi_type == SPI3W) {
cparata 0:6d69e896ce38 260 /* Write RD Reg Address with RD bit*/
cparata 3:4274d9103f1d 261 uint8_t TxByte = RegisterAddr | 0x80;
cparata 0:6d69e896ce38 262 _dev_spi->write((char *)&TxByte, 1, (char *)pBuffer, (int) NumByteToRead);
cparata 3:4274d9103f1d 263 }
cparata 0:6d69e896ce38 264 _cs_pin = 1;
cparata 3:4274d9103f1d 265 _dev_spi->unlock();
cparata 0:6d69e896ce38 266 return 0;
cparata 3:4274d9103f1d 267 }
cparata 3:4274d9103f1d 268 if (_dev_i2c) {
cparata 3:4274d9103f1d 269 return (uint8_t) _dev_i2c->i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead);
cparata 3:4274d9103f1d 270 }
cparata 0:6d69e896ce38 271 return 1;
cparata 0:6d69e896ce38 272 }
cparata 3:4274d9103f1d 273
cparata 0:6d69e896ce38 274 /**
cparata 0:6d69e896ce38 275 * @brief Utility function to write data.
cparata 0:6d69e896ce38 276 * @param pBuffer: pointer to data to be written.
cparata 0:6d69e896ce38 277 * @param RegisterAddr: specifies internal address register to be written.
cparata 0:6d69e896ce38 278 * @param NumByteToWrite: number of bytes to write.
cparata 0:6d69e896ce38 279 * @retval 0 if ok, an error code otherwise.
cparata 0:6d69e896ce38 280 */
cparata 3:4274d9103f1d 281 uint8_t io_write(uint8_t *pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite)
cparata 0:6d69e896ce38 282 {
cparata 3:4274d9103f1d 283 if (_dev_spi) {
cparata 0:6d69e896ce38 284 _dev_spi->lock();
cparata 0:6d69e896ce38 285 _cs_pin = 0;
cparata 3:4274d9103f1d 286 _dev_spi->write(RegisterAddr);
cparata 3:4274d9103f1d 287 _dev_spi->write((char *)pBuffer, (int) NumByteToWrite, NULL, 0);
cparata 3:4274d9103f1d 288 _cs_pin = 1;
cparata 0:6d69e896ce38 289 _dev_spi->unlock();
cparata 3:4274d9103f1d 290 return 0;
cparata 3:4274d9103f1d 291 }
cparata 3:4274d9103f1d 292 if (_dev_i2c) {
cparata 3:4274d9103f1d 293 return (uint8_t) _dev_i2c->i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite);
cparata 3:4274d9103f1d 294 }
cparata 0:6d69e896ce38 295 return 1;
cparata 0:6d69e896ce38 296 }
cparata 0:6d69e896ce38 297
cparata 3:4274d9103f1d 298 private:
cparata 0:6d69e896ce38 299 int set_x_odr_when_enabled(float odr);
cparata 0:6d69e896ce38 300 int set_g_odr_when_enabled(float odr);
cparata 0:6d69e896ce38 301 int set_x_odr_when_disabled(float odr);
cparata 0:6d69e896ce38 302 int set_g_odr_when_disabled(float odr);
cparata 0:6d69e896ce38 303
cparata 0:6d69e896ce38 304 /* Helper classes. */
cparata 0:6d69e896ce38 305 DevI2C *_dev_i2c;
cparata 0:6d69e896ce38 306 SPI *_dev_spi;
cparata 0:6d69e896ce38 307
cparata 0:6d69e896ce38 308 /* Configuration */
cparata 0:6d69e896ce38 309 uint8_t _address;
cparata 3:4274d9103f1d 310 DigitalOut _cs_pin;
cparata 0:6d69e896ce38 311 InterruptIn _int1_irq;
cparata 0:6d69e896ce38 312 InterruptIn _int2_irq;
cparata 0:6d69e896ce38 313 SPI_type_t _spi_type;
cparata 3:4274d9103f1d 314
cparata 0:6d69e896ce38 315 uint8_t _x_is_enabled;
cparata 0:6d69e896ce38 316 lsm6dso_odr_xl_t _x_last_odr;
cparata 0:6d69e896ce38 317 uint8_t _g_is_enabled;
cparata 0:6d69e896ce38 318 lsm6dso_odr_g_t _g_last_odr;
cparata 0:6d69e896ce38 319
cparata 0:6d69e896ce38 320 lsm6dso_ctx_t _reg_ctx;
cparata 0:6d69e896ce38 321 };
cparata 0:6d69e896ce38 322
cparata 0:6d69e896ce38 323 #ifdef __cplusplus
cparata 3:4274d9103f1d 324 extern "C" {
cparata 0:6d69e896ce38 325 #endif
cparata 3:4274d9103f1d 326 int32_t LSM6DSO_io_write(void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite);
cparata 3:4274d9103f1d 327 int32_t LSM6DSO_io_read(void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead);
cparata 0:6d69e896ce38 328 #ifdef __cplusplus
cparata 3:4274d9103f1d 329 }
cparata 0:6d69e896ce38 330 #endif
cparata 0:6d69e896ce38 331
cparata 0:6d69e896ce38 332 #endif