iNEMO inertial module: 3D accelerometer and 3D gyroscope.

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   HelloWorld_ST_Sensors MOTENV_Mbed mbed-os-mqtt-client LSM6DSL_JS ... more

Committer:
cparata
Date:
Mon Mar 04 13:51:21 2019 +0000
Revision:
5:77ec4781b110
Parent:
4:a00b29ed17c3
Fix warnings

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nikapov 0:704c89673b57 1 /**
nikapov 0:704c89673b57 2 ******************************************************************************
nikapov 0:704c89673b57 3 * @file LSM6DSLSensor.h
nikapov 0:704c89673b57 4 * @author CLab
nikapov 0:704c89673b57 5 * @version V1.0.0
nikapov 0:704c89673b57 6 * @date 5 August 2016
nikapov 0:704c89673b57 7 * @brief Abstract Class of an LSM6DSL Inertial Measurement Unit (IMU) 6 axes
nikapov 0:704c89673b57 8 * sensor.
nikapov 0:704c89673b57 9 ******************************************************************************
nikapov 0:704c89673b57 10 * @attention
nikapov 0:704c89673b57 11 *
nikapov 0:704c89673b57 12 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
nikapov 0:704c89673b57 13 *
nikapov 0:704c89673b57 14 * Redistribution and use in source and binary forms, with or without modification,
nikapov 0:704c89673b57 15 * are permitted provided that the following conditions are met:
nikapov 0:704c89673b57 16 * 1. Redistributions of source code must retain the above copyright notice,
nikapov 0:704c89673b57 17 * this list of conditions and the following disclaimer.
nikapov 0:704c89673b57 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
nikapov 0:704c89673b57 19 * this list of conditions and the following disclaimer in the documentation
nikapov 0:704c89673b57 20 * and/or other materials provided with the distribution.
nikapov 0:704c89673b57 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
nikapov 0:704c89673b57 22 * may be used to endorse or promote products derived from this software
nikapov 0:704c89673b57 23 * without specific prior written permission.
nikapov 0:704c89673b57 24 *
nikapov 0:704c89673b57 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
nikapov 0:704c89673b57 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
nikapov 0:704c89673b57 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
nikapov 0:704c89673b57 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
nikapov 0:704c89673b57 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
nikapov 0:704c89673b57 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
nikapov 0:704c89673b57 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
nikapov 0:704c89673b57 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
nikapov 0:704c89673b57 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
nikapov 0:704c89673b57 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
nikapov 0:704c89673b57 35 *
nikapov 0:704c89673b57 36 ******************************************************************************
nikapov 0:704c89673b57 37 */
nikapov 0:704c89673b57 38
nikapov 0:704c89673b57 39
nikapov 0:704c89673b57 40 /* Prevent recursive inclusion -----------------------------------------------*/
nikapov 0:704c89673b57 41
nikapov 0:704c89673b57 42 #ifndef __LSM6DSLSensor_H__
nikapov 0:704c89673b57 43 #define __LSM6DSLSensor_H__
nikapov 0:704c89673b57 44
nikapov 0:704c89673b57 45
nikapov 0:704c89673b57 46 /* Includes ------------------------------------------------------------------*/
nikapov 0:704c89673b57 47
nikapov 0:704c89673b57 48 #include "DevI2C.h"
nikapov 0:704c89673b57 49 #include "LSM6DSL_acc_gyro_driver.h"
nikapov 0:704c89673b57 50 #include "MotionSensor.h"
nikapov 0:704c89673b57 51 #include "GyroSensor.h"
mapellil 1:c583f32fe272 52 #include <assert.h>
nikapov 0:704c89673b57 53
nikapov 0:704c89673b57 54 /* Defines -------------------------------------------------------------------*/
nikapov 0:704c89673b57 55
nikapov 0:704c89673b57 56 #define LSM6DSL_ACC_SENSITIVITY_FOR_FS_2G 0.061 /**< Sensitivity value for 2 g full scale [mg/LSB] */
nikapov 0:704c89673b57 57 #define LSM6DSL_ACC_SENSITIVITY_FOR_FS_4G 0.122 /**< Sensitivity value for 4 g full scale [mg/LSB] */
nikapov 0:704c89673b57 58 #define LSM6DSL_ACC_SENSITIVITY_FOR_FS_8G 0.244 /**< Sensitivity value for 8 g full scale [mg/LSB] */
nikapov 0:704c89673b57 59 #define LSM6DSL_ACC_SENSITIVITY_FOR_FS_16G 0.488 /**< Sensitivity value for 16 g full scale [mg/LSB] */
nikapov 0:704c89673b57 60
nikapov 0:704c89673b57 61 #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_125DPS 04.375 /**< Sensitivity value for 125 dps full scale [mdps/LSB] */
nikapov 0:704c89673b57 62 #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_245DPS 08.750 /**< Sensitivity value for 245 dps full scale [mdps/LSB] */
nikapov 0:704c89673b57 63 #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_500DPS 17.500 /**< Sensitivity value for 500 dps full scale [mdps/LSB] */
nikapov 0:704c89673b57 64 #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_1000DPS 35.000 /**< Sensitivity value for 1000 dps full scale [mdps/LSB] */
nikapov 0:704c89673b57 65 #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_2000DPS 70.000 /**< Sensitivity value for 2000 dps full scale [mdps/LSB] */
nikapov 0:704c89673b57 66
nikapov 0:704c89673b57 67 #define LSM6DSL_PEDOMETER_THRESHOLD_LOW 0x00 /**< Lowest value of pedometer threshold */
nikapov 0:704c89673b57 68 #define LSM6DSL_PEDOMETER_THRESHOLD_MID_LOW 0x07
nikapov 0:704c89673b57 69 #define LSM6DSL_PEDOMETER_THRESHOLD_MID 0x0F
nikapov 0:704c89673b57 70 #define LSM6DSL_PEDOMETER_THRESHOLD_MID_HIGH 0x17
nikapov 0:704c89673b57 71 #define LSM6DSL_PEDOMETER_THRESHOLD_HIGH 0x1F /**< Highest value of pedometer threshold */
nikapov 0:704c89673b57 72
nikapov 0:704c89673b57 73 #define LSM6DSL_WAKE_UP_THRESHOLD_LOW 0x01 /**< Lowest value of wake up threshold */
nikapov 0:704c89673b57 74 #define LSM6DSL_WAKE_UP_THRESHOLD_MID_LOW 0x0F
nikapov 0:704c89673b57 75 #define LSM6DSL_WAKE_UP_THRESHOLD_MID 0x1F
nikapov 0:704c89673b57 76 #define LSM6DSL_WAKE_UP_THRESHOLD_MID_HIGH 0x2F
nikapov 0:704c89673b57 77 #define LSM6DSL_WAKE_UP_THRESHOLD_HIGH 0x3F /**< Highest value of wake up threshold */
nikapov 0:704c89673b57 78
nikapov 0:704c89673b57 79 #define LSM6DSL_TAP_THRESHOLD_LOW 0x01 /**< Lowest value of wake up threshold */
nikapov 0:704c89673b57 80 #define LSM6DSL_TAP_THRESHOLD_MID_LOW 0x08
nikapov 0:704c89673b57 81 #define LSM6DSL_TAP_THRESHOLD_MID 0x10
nikapov 0:704c89673b57 82 #define LSM6DSL_TAP_THRESHOLD_MID_HIGH 0x18
nikapov 0:704c89673b57 83 #define LSM6DSL_TAP_THRESHOLD_HIGH 0x1F /**< Highest value of wake up threshold */
nikapov 0:704c89673b57 84
nikapov 0:704c89673b57 85 #define LSM6DSL_TAP_SHOCK_TIME_LOW 0x00 /**< Lowest value of wake up threshold */
nikapov 0:704c89673b57 86 #define LSM6DSL_TAP_SHOCK_TIME_MID_LOW 0x01
nikapov 0:704c89673b57 87 #define LSM6DSL_TAP_SHOCK_TIME_MID_HIGH 0x02
nikapov 0:704c89673b57 88 #define LSM6DSL_TAP_SHOCK_TIME_HIGH 0x03 /**< Highest value of wake up threshold */
nikapov 0:704c89673b57 89
nikapov 0:704c89673b57 90 #define LSM6DSL_TAP_QUIET_TIME_LOW 0x00 /**< Lowest value of wake up threshold */
nikapov 0:704c89673b57 91 #define LSM6DSL_TAP_QUIET_TIME_MID_LOW 0x01
nikapov 0:704c89673b57 92 #define LSM6DSL_TAP_QUIET_TIME_MID_HIGH 0x02
nikapov 0:704c89673b57 93 #define LSM6DSL_TAP_QUIET_TIME_HIGH 0x03 /**< Highest value of wake up threshold */
nikapov 0:704c89673b57 94
nikapov 0:704c89673b57 95 #define LSM6DSL_TAP_DURATION_TIME_LOW 0x00 /**< Lowest value of wake up threshold */
nikapov 0:704c89673b57 96 #define LSM6DSL_TAP_DURATION_TIME_MID_LOW 0x04
nikapov 0:704c89673b57 97 #define LSM6DSL_TAP_DURATION_TIME_MID 0x08
nikapov 0:704c89673b57 98 #define LSM6DSL_TAP_DURATION_TIME_MID_HIGH 0x0C
nikapov 0:704c89673b57 99 #define LSM6DSL_TAP_DURATION_TIME_HIGH 0x0F /**< Highest value of wake up threshold */
nikapov 0:704c89673b57 100
nikapov 0:704c89673b57 101 /* Typedefs ------------------------------------------------------------------*/
nikapov 0:704c89673b57 102
nikapov 0:704c89673b57 103 typedef enum
nikapov 0:704c89673b57 104 {
nikapov 0:704c89673b57 105 LSM6DSL_INT1_PIN,
nikapov 0:704c89673b57 106 LSM6DSL_INT2_PIN
nikapov 0:704c89673b57 107 } LSM6DSL_Interrupt_Pin_t;
nikapov 0:704c89673b57 108
nikapov 0:704c89673b57 109 typedef struct
nikapov 0:704c89673b57 110 {
nikapov 0:704c89673b57 111 unsigned int FreeFallStatus : 1;
nikapov 0:704c89673b57 112 unsigned int TapStatus : 1;
nikapov 0:704c89673b57 113 unsigned int DoubleTapStatus : 1;
nikapov 0:704c89673b57 114 unsigned int WakeUpStatus : 1;
nikapov 0:704c89673b57 115 unsigned int StepStatus : 1;
nikapov 0:704c89673b57 116 unsigned int TiltStatus : 1;
nikapov 0:704c89673b57 117 unsigned int D6DOrientationStatus : 1;
nikapov 0:704c89673b57 118 } LSM6DSL_Event_Status_t;
nikapov 0:704c89673b57 119
nikapov 0:704c89673b57 120 /* Class Declaration ---------------------------------------------------------*/
mapellil 2:578a45c4dad5 121
nikapov 0:704c89673b57 122 /**
nikapov 0:704c89673b57 123 * Abstract class of an LSM6DSL Inertial Measurement Unit (IMU) 6 axes
nikapov 0:704c89673b57 124 * sensor.
nikapov 0:704c89673b57 125 */
nikapov 0:704c89673b57 126 class LSM6DSLSensor : public MotionSensor, public GyroSensor
nikapov 0:704c89673b57 127 {
nikapov 0:704c89673b57 128 public:
mapellil 2:578a45c4dad5 129 enum SPI_type_t {SPI3W, SPI4W};
mapellil 2:578a45c4dad5 130 LSM6DSLSensor(SPI *spi, PinName cs_pin, PinName INT1_pin=NC, PinName INT2_pin=NC, SPI_type_t spi_type=SPI4W);
mapellil 1:c583f32fe272 131 LSM6DSLSensor(DevI2C *i2c, uint8_t address=LSM6DSL_ACC_GYRO_I2C_ADDRESS_HIGH, PinName INT1_pin=NC, PinName INT2_pin=NC);
nikapov 0:704c89673b57 132 virtual int init(void *init);
nikapov 0:704c89673b57 133 virtual int read_id(uint8_t *id);
nikapov 0:704c89673b57 134 virtual int get_x_axes(int32_t *pData);
nikapov 0:704c89673b57 135 virtual int get_g_axes(int32_t *pData);
nikapov 0:704c89673b57 136 virtual int get_x_sensitivity(float *pfData);
nikapov 0:704c89673b57 137 virtual int get_g_sensitivity(float *pfData);
nikapov 0:704c89673b57 138 virtual int get_x_axes_raw(int16_t *pData);
nikapov 0:704c89673b57 139 virtual int get_g_axes_raw(int16_t *pData);
nikapov 0:704c89673b57 140 virtual int get_x_odr(float *odr);
nikapov 0:704c89673b57 141 virtual int get_g_odr(float *odr);
nikapov 0:704c89673b57 142 virtual int set_x_odr(float odr);
nikapov 0:704c89673b57 143 virtual int set_g_odr(float odr);
nikapov 0:704c89673b57 144 virtual int get_x_fs(float *fullScale);
nikapov 0:704c89673b57 145 virtual int get_g_fs(float *fullScale);
nikapov 0:704c89673b57 146 virtual int set_x_fs(float fullScale);
nikapov 0:704c89673b57 147 virtual int set_g_fs(float fullScale);
nikapov 0:704c89673b57 148 int enable_x(void);
nikapov 0:704c89673b57 149 int enable_g(void);
nikapov 0:704c89673b57 150 int disable_x(void);
nikapov 0:704c89673b57 151 int disable_g(void);
nikapov 0:704c89673b57 152 int enable_free_fall_detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN);
nikapov 0:704c89673b57 153 int disable_free_fall_detection(void);
nikapov 0:704c89673b57 154 int set_free_fall_threshold(uint8_t thr);
nikapov 0:704c89673b57 155 int enable_pedometer(void);
nikapov 0:704c89673b57 156 int disable_pedometer(void);
nikapov 0:704c89673b57 157 int get_step_counter(uint16_t *step_count);
nikapov 0:704c89673b57 158 int reset_step_counter(void);
nikapov 0:704c89673b57 159 int set_pedometer_threshold(uint8_t thr);
nikapov 0:704c89673b57 160 int enable_tilt_detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN);
nikapov 0:704c89673b57 161 int disable_tilt_detection(void);
nikapov 0:704c89673b57 162 int enable_wake_up_detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT2_PIN);
nikapov 0:704c89673b57 163 int disable_wake_up_detection(void);
nikapov 0:704c89673b57 164 int set_wake_up_threshold(uint8_t thr);
nikapov 0:704c89673b57 165 int enable_single_tap_detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN);
nikapov 0:704c89673b57 166 int disable_single_tap_detection(void);
nikapov 0:704c89673b57 167 int enable_double_tap_detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN);
nikapov 0:704c89673b57 168 int disable_double_tap_detection(void);
nikapov 0:704c89673b57 169 int set_tap_threshold(uint8_t thr);
nikapov 0:704c89673b57 170 int set_tap_shock_time(uint8_t time);
nikapov 0:704c89673b57 171 int set_tap_quiet_time(uint8_t time);
nikapov 0:704c89673b57 172 int set_tap_duration_time(uint8_t time);
nikapov 0:704c89673b57 173 int enable_6d_orientation(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN);
nikapov 0:704c89673b57 174 int disable_6d_orientation(void);
nikapov 0:704c89673b57 175 int get_6d_orientation_xl(uint8_t *xl);
nikapov 0:704c89673b57 176 int get_6d_orientation_xh(uint8_t *xh);
nikapov 0:704c89673b57 177 int get_6d_orientation_yl(uint8_t *yl);
nikapov 0:704c89673b57 178 int get_6d_orientation_yh(uint8_t *yh);
nikapov 0:704c89673b57 179 int get_6d_orientation_zl(uint8_t *zl);
nikapov 0:704c89673b57 180 int get_6d_orientation_zh(uint8_t *zh);
nikapov 0:704c89673b57 181 int get_event_status(LSM6DSL_Event_Status_t *status);
nikapov 0:704c89673b57 182 int read_reg(uint8_t reg, uint8_t *data);
nikapov 0:704c89673b57 183 int write_reg(uint8_t reg, uint8_t data);
nikapov 0:704c89673b57 184
nikapov 0:704c89673b57 185 /**
nikapov 0:704c89673b57 186 * @brief Attaching an interrupt handler to the INT1 interrupt.
nikapov 0:704c89673b57 187 * @param fptr An interrupt handler.
nikapov 0:704c89673b57 188 * @retval None.
nikapov 0:704c89673b57 189 */
nikapov 0:704c89673b57 190 void attach_int1_irq(void (*fptr)(void))
nikapov 0:704c89673b57 191 {
nikapov 0:704c89673b57 192 _int1_irq.rise(fptr);
nikapov 0:704c89673b57 193 }
nikapov 0:704c89673b57 194
nikapov 0:704c89673b57 195 /**
nikapov 0:704c89673b57 196 * @brief Enabling the INT1 interrupt handling.
nikapov 0:704c89673b57 197 * @param None.
nikapov 0:704c89673b57 198 * @retval None.
nikapov 0:704c89673b57 199 */
nikapov 0:704c89673b57 200 void enable_int1_irq(void)
nikapov 0:704c89673b57 201 {
nikapov 0:704c89673b57 202 _int1_irq.enable_irq();
nikapov 0:704c89673b57 203 }
nikapov 0:704c89673b57 204
nikapov 0:704c89673b57 205 /**
nikapov 0:704c89673b57 206 * @brief Disabling the INT1 interrupt handling.
nikapov 0:704c89673b57 207 * @param None.
nikapov 0:704c89673b57 208 * @retval None.
nikapov 0:704c89673b57 209 */
nikapov 0:704c89673b57 210 void disable_int1_irq(void)
nikapov 0:704c89673b57 211 {
nikapov 0:704c89673b57 212 _int1_irq.disable_irq();
nikapov 0:704c89673b57 213 }
nikapov 0:704c89673b57 214
nikapov 0:704c89673b57 215 /**
nikapov 0:704c89673b57 216 * @brief Attaching an interrupt handler to the INT2 interrupt.
nikapov 0:704c89673b57 217 * @param fptr An interrupt handler.
nikapov 0:704c89673b57 218 * @retval None.
nikapov 0:704c89673b57 219 */
nikapov 0:704c89673b57 220 void attach_int2_irq(void (*fptr)(void))
nikapov 0:704c89673b57 221 {
nikapov 0:704c89673b57 222 _int2_irq.rise(fptr);
nikapov 0:704c89673b57 223 }
nikapov 0:704c89673b57 224
nikapov 0:704c89673b57 225 /**
nikapov 0:704c89673b57 226 * @brief Enabling the INT2 interrupt handling.
nikapov 0:704c89673b57 227 * @param None.
nikapov 0:704c89673b57 228 * @retval None.
nikapov 0:704c89673b57 229 */
nikapov 0:704c89673b57 230 void enable_int2_irq(void)
nikapov 0:704c89673b57 231 {
nikapov 0:704c89673b57 232 _int2_irq.enable_irq();
nikapov 0:704c89673b57 233 }
nikapov 0:704c89673b57 234
nikapov 0:704c89673b57 235 /**
nikapov 0:704c89673b57 236 * @brief Disabling the INT2 interrupt handling.
nikapov 0:704c89673b57 237 * @param None.
nikapov 0:704c89673b57 238 * @retval None.
nikapov 0:704c89673b57 239 */
nikapov 0:704c89673b57 240 void disable_int2_irq(void)
nikapov 0:704c89673b57 241 {
nikapov 0:704c89673b57 242 _int2_irq.disable_irq();
nikapov 0:704c89673b57 243 }
nikapov 0:704c89673b57 244
nikapov 0:704c89673b57 245 /**
nikapov 0:704c89673b57 246 * @brief Utility function to read data.
nikapov 0:704c89673b57 247 * @param pBuffer: pointer to data to be read.
nikapov 0:704c89673b57 248 * @param RegisterAddr: specifies internal address register to be read.
nikapov 0:704c89673b57 249 * @param NumByteToRead: number of bytes to be read.
nikapov 0:704c89673b57 250 * @retval 0 if ok, an error code otherwise.
nikapov 0:704c89673b57 251 */
nikapov 0:704c89673b57 252 uint8_t io_read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead)
mapellil 2:578a45c4dad5 253 {
mapellil 2:578a45c4dad5 254 if (_dev_spi) {
mapellil 2:578a45c4dad5 255 /* Write Reg Address */
mapellil 2:578a45c4dad5 256 _dev_spi->lock();
mapellil 2:578a45c4dad5 257 _cs_pin = 0;
mapellil 2:578a45c4dad5 258 if (_spi_type == SPI4W) {
mapellil 2:578a45c4dad5 259 _dev_spi->write(RegisterAddr | 0x80);
mapellil 2:578a45c4dad5 260 for (int i=0; i<NumByteToRead; i++) {
mapellil 2:578a45c4dad5 261 *(pBuffer+i) = _dev_spi->write(0x00);
mapellil 2:578a45c4dad5 262 }
mapellil 2:578a45c4dad5 263 } else if (_spi_type == SPI3W){
mapellil 2:578a45c4dad5 264 /* Write RD Reg Address with RD bit*/
mapellil 2:578a45c4dad5 265 uint8_t TxByte = RegisterAddr | 0x80;
mapellil 2:578a45c4dad5 266 _dev_spi->write((char *)&TxByte, 1, (char *)pBuffer, (int) NumByteToRead);
mapellil 2:578a45c4dad5 267 }
mapellil 2:578a45c4dad5 268 _cs_pin = 1;
mapellil 2:578a45c4dad5 269 _dev_spi->unlock();
mapellil 2:578a45c4dad5 270 return 0;
mapellil 2:578a45c4dad5 271 }
mapellil 2:578a45c4dad5 272 if (_dev_i2c) return (uint8_t) _dev_i2c->i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead);
mapellil 2:578a45c4dad5 273 return 1;
nikapov 0:704c89673b57 274 }
nikapov 0:704c89673b57 275
nikapov 0:704c89673b57 276 /**
nikapov 0:704c89673b57 277 * @brief Utility function to write data.
nikapov 0:704c89673b57 278 * @param pBuffer: pointer to data to be written.
nikapov 0:704c89673b57 279 * @param RegisterAddr: specifies internal address register to be written.
nikapov 0:704c89673b57 280 * @param NumByteToWrite: number of bytes to write.
nikapov 0:704c89673b57 281 * @retval 0 if ok, an error code otherwise.
nikapov 0:704c89673b57 282 */
nikapov 0:704c89673b57 283 uint8_t io_write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite)
nikapov 0:704c89673b57 284 {
mapellil 2:578a45c4dad5 285 if (_dev_spi) {
mapellil 2:578a45c4dad5 286 _dev_spi->lock();
mapellil 2:578a45c4dad5 287 _cs_pin = 0;
cparata 4:a00b29ed17c3 288 _dev_spi->write(RegisterAddr);
mapellil 2:578a45c4dad5 289 _dev_spi->write((char *)pBuffer, (int) NumByteToWrite, NULL, 0);
mapellil 2:578a45c4dad5 290 _cs_pin = 1;
mapellil 2:578a45c4dad5 291 _dev_spi->unlock();
cparata 4:a00b29ed17c3 292 return 0;
mapellil 2:578a45c4dad5 293 }
mapellil 2:578a45c4dad5 294 if (_dev_i2c) return (uint8_t) _dev_i2c->i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite);
mapellil 2:578a45c4dad5 295 return 1;
nikapov 0:704c89673b57 296 }
nikapov 0:704c89673b57 297
nikapov 0:704c89673b57 298 private:
nikapov 0:704c89673b57 299 int set_x_odr_when_enabled(float odr);
nikapov 0:704c89673b57 300 int set_g_odr_when_enabled(float odr);
nikapov 0:704c89673b57 301 int set_x_odr_when_disabled(float odr);
nikapov 0:704c89673b57 302 int set_g_odr_when_disabled(float odr);
nikapov 0:704c89673b57 303
nikapov 0:704c89673b57 304 /* Helper classes. */
mapellil 1:c583f32fe272 305 DevI2C *_dev_i2c;
mapellil 2:578a45c4dad5 306 SPI *_dev_spi;
cparata 5:77ec4781b110 307
nikapov 0:704c89673b57 308 /* Configuration */
nikapov 0:704c89673b57 309 uint8_t _address;
mapellil 1:c583f32fe272 310 DigitalOut _cs_pin;
mapellil 1:c583f32fe272 311 InterruptIn _int1_irq;
mapellil 1:c583f32fe272 312 InterruptIn _int2_irq;
cparata 5:77ec4781b110 313 SPI_type_t _spi_type;
nikapov 0:704c89673b57 314
nikapov 0:704c89673b57 315 uint8_t _x_is_enabled;
nikapov 0:704c89673b57 316 float _x_last_odr;
nikapov 0:704c89673b57 317 uint8_t _g_is_enabled;
nikapov 0:704c89673b57 318 float _g_last_odr;
nikapov 0:704c89673b57 319 };
nikapov 0:704c89673b57 320
nikapov 0:704c89673b57 321 #ifdef __cplusplus
nikapov 0:704c89673b57 322 extern "C" {
nikapov 0:704c89673b57 323 #endif
nikapov 0:704c89673b57 324 uint8_t LSM6DSL_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite );
nikapov 0:704c89673b57 325 uint8_t LSM6DSL_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead );
nikapov 0:704c89673b57 326 #ifdef __cplusplus
nikapov 0:704c89673b57 327 }
nikapov 0:704c89673b57 328 #endif
nikapov 0:704c89673b57 329
nikapov 0:704c89673b57 330 #endif