Beta

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON

Fork of X_NUCLEO_IKS01A2 by ST

Committer:
cparata
Date:
Thu Dec 15 14:03:46 2016 +0000
Revision:
5:63b2b4c21092
Parent:
1:bd2a01e81e6f
Child:
6:671fd10a51b7
Update LSM6DSL library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nikapov 0:cad5dab2b21d 1 /**
nikapov 0:cad5dab2b21d 2 ******************************************************************************
nikapov 0:cad5dab2b21d 3 * @file LSM6DSLSensor.h
cparata 1:bd2a01e81e6f 4 * @author CLab
nikapov 0:cad5dab2b21d 5 * @version V1.0.0
nikapov 0:cad5dab2b21d 6 * @date 5 August 2016
nikapov 0:cad5dab2b21d 7 * @brief Abstract Class of an LSM6DSL Inertial Measurement Unit (IMU) 6 axes
nikapov 0:cad5dab2b21d 8 * sensor.
nikapov 0:cad5dab2b21d 9 ******************************************************************************
nikapov 0:cad5dab2b21d 10 * @attention
nikapov 0:cad5dab2b21d 11 *
nikapov 0:cad5dab2b21d 12 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
nikapov 0:cad5dab2b21d 13 *
nikapov 0:cad5dab2b21d 14 * Redistribution and use in source and binary forms, with or without modification,
nikapov 0:cad5dab2b21d 15 * are permitted provided that the following conditions are met:
nikapov 0:cad5dab2b21d 16 * 1. Redistributions of source code must retain the above copyright notice,
nikapov 0:cad5dab2b21d 17 * this list of conditions and the following disclaimer.
nikapov 0:cad5dab2b21d 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
nikapov 0:cad5dab2b21d 19 * this list of conditions and the following disclaimer in the documentation
nikapov 0:cad5dab2b21d 20 * and/or other materials provided with the distribution.
nikapov 0:cad5dab2b21d 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
nikapov 0:cad5dab2b21d 22 * may be used to endorse or promote products derived from this software
nikapov 0:cad5dab2b21d 23 * without specific prior written permission.
nikapov 0:cad5dab2b21d 24 *
nikapov 0:cad5dab2b21d 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
nikapov 0:cad5dab2b21d 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
nikapov 0:cad5dab2b21d 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
nikapov 0:cad5dab2b21d 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
nikapov 0:cad5dab2b21d 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
nikapov 0:cad5dab2b21d 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
nikapov 0:cad5dab2b21d 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
nikapov 0:cad5dab2b21d 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
nikapov 0:cad5dab2b21d 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
nikapov 0:cad5dab2b21d 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
nikapov 0:cad5dab2b21d 35 *
nikapov 0:cad5dab2b21d 36 ******************************************************************************
nikapov 0:cad5dab2b21d 37 */
nikapov 0:cad5dab2b21d 38
nikapov 0:cad5dab2b21d 39
nikapov 0:cad5dab2b21d 40 /* Prevent recursive inclusion -----------------------------------------------*/
nikapov 0:cad5dab2b21d 41
nikapov 0:cad5dab2b21d 42 #ifndef __LSM6DSLSensor_H__
nikapov 0:cad5dab2b21d 43 #define __LSM6DSLSensor_H__
nikapov 0:cad5dab2b21d 44
nikapov 0:cad5dab2b21d 45
nikapov 0:cad5dab2b21d 46 /* Includes ------------------------------------------------------------------*/
nikapov 0:cad5dab2b21d 47
nikapov 0:cad5dab2b21d 48 #include "DevI2C.h"
nikapov 0:cad5dab2b21d 49 #include "LSM6DSL_ACC_GYRO_driver.h"
nikapov 0:cad5dab2b21d 50 #include "MotionSensor.h"
nikapov 0:cad5dab2b21d 51 #include "GyroSensor.h"
nikapov 0:cad5dab2b21d 52
nikapov 0:cad5dab2b21d 53 /* Defines -------------------------------------------------------------------*/
nikapov 0:cad5dab2b21d 54
nikapov 0:cad5dab2b21d 55 #define LSM6DSL_ACC_SENSITIVITY_FOR_FS_2G 0.061 /**< Sensitivity value for 2 g full scale [mg/LSB] */
nikapov 0:cad5dab2b21d 56 #define LSM6DSL_ACC_SENSITIVITY_FOR_FS_4G 0.122 /**< Sensitivity value for 4 g full scale [mg/LSB] */
nikapov 0:cad5dab2b21d 57 #define LSM6DSL_ACC_SENSITIVITY_FOR_FS_8G 0.244 /**< Sensitivity value for 8 g full scale [mg/LSB] */
nikapov 0:cad5dab2b21d 58 #define LSM6DSL_ACC_SENSITIVITY_FOR_FS_16G 0.488 /**< Sensitivity value for 16 g full scale [mg/LSB] */
nikapov 0:cad5dab2b21d 59
nikapov 0:cad5dab2b21d 60 #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_125DPS 04.375 /**< Sensitivity value for 125 dps full scale [mdps/LSB] */
nikapov 0:cad5dab2b21d 61 #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_245DPS 08.750 /**< Sensitivity value for 245 dps full scale [mdps/LSB] */
nikapov 0:cad5dab2b21d 62 #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_500DPS 17.500 /**< Sensitivity value for 500 dps full scale [mdps/LSB] */
nikapov 0:cad5dab2b21d 63 #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_1000DPS 35.000 /**< Sensitivity value for 1000 dps full scale [mdps/LSB] */
nikapov 0:cad5dab2b21d 64 #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_2000DPS 70.000 /**< Sensitivity value for 2000 dps full scale [mdps/LSB] */
nikapov 0:cad5dab2b21d 65
nikapov 0:cad5dab2b21d 66 #define LSM6DSL_PEDOMETER_THRESHOLD_LOW 0x00 /**< Lowest value of pedometer threshold */
nikapov 0:cad5dab2b21d 67 #define LSM6DSL_PEDOMETER_THRESHOLD_MID_LOW 0x07
nikapov 0:cad5dab2b21d 68 #define LSM6DSL_PEDOMETER_THRESHOLD_MID 0x0F
nikapov 0:cad5dab2b21d 69 #define LSM6DSL_PEDOMETER_THRESHOLD_MID_HIGH 0x17
nikapov 0:cad5dab2b21d 70 #define LSM6DSL_PEDOMETER_THRESHOLD_HIGH 0x1F /**< Highest value of pedometer threshold */
nikapov 0:cad5dab2b21d 71
nikapov 0:cad5dab2b21d 72 #define LSM6DSL_WAKE_UP_THRESHOLD_LOW 0x01 /**< Lowest value of wake up threshold */
nikapov 0:cad5dab2b21d 73 #define LSM6DSL_WAKE_UP_THRESHOLD_MID_LOW 0x0F
nikapov 0:cad5dab2b21d 74 #define LSM6DSL_WAKE_UP_THRESHOLD_MID 0x1F
nikapov 0:cad5dab2b21d 75 #define LSM6DSL_WAKE_UP_THRESHOLD_MID_HIGH 0x2F
nikapov 0:cad5dab2b21d 76 #define LSM6DSL_WAKE_UP_THRESHOLD_HIGH 0x3F /**< Highest value of wake up threshold */
nikapov 0:cad5dab2b21d 77
nikapov 0:cad5dab2b21d 78 #define LSM6DSL_TAP_THRESHOLD_LOW 0x01 /**< Lowest value of wake up threshold */
nikapov 0:cad5dab2b21d 79 #define LSM6DSL_TAP_THRESHOLD_MID_LOW 0x08
nikapov 0:cad5dab2b21d 80 #define LSM6DSL_TAP_THRESHOLD_MID 0x10
nikapov 0:cad5dab2b21d 81 #define LSM6DSL_TAP_THRESHOLD_MID_HIGH 0x18
nikapov 0:cad5dab2b21d 82 #define LSM6DSL_TAP_THRESHOLD_HIGH 0x1F /**< Highest value of wake up threshold */
nikapov 0:cad5dab2b21d 83
nikapov 0:cad5dab2b21d 84 #define LSM6DSL_TAP_SHOCK_TIME_LOW 0x00 /**< Lowest value of wake up threshold */
nikapov 0:cad5dab2b21d 85 #define LSM6DSL_TAP_SHOCK_TIME_MID_LOW 0x01
nikapov 0:cad5dab2b21d 86 #define LSM6DSL_TAP_SHOCK_TIME_MID_HIGH 0x02
nikapov 0:cad5dab2b21d 87 #define LSM6DSL_TAP_SHOCK_TIME_HIGH 0x03 /**< Highest value of wake up threshold */
nikapov 0:cad5dab2b21d 88
nikapov 0:cad5dab2b21d 89 #define LSM6DSL_TAP_QUIET_TIME_LOW 0x00 /**< Lowest value of wake up threshold */
nikapov 0:cad5dab2b21d 90 #define LSM6DSL_TAP_QUIET_TIME_MID_LOW 0x01
nikapov 0:cad5dab2b21d 91 #define LSM6DSL_TAP_QUIET_TIME_MID_HIGH 0x02
nikapov 0:cad5dab2b21d 92 #define LSM6DSL_TAP_QUIET_TIME_HIGH 0x03 /**< Highest value of wake up threshold */
nikapov 0:cad5dab2b21d 93
nikapov 0:cad5dab2b21d 94 #define LSM6DSL_TAP_DURATION_TIME_LOW 0x00 /**< Lowest value of wake up threshold */
nikapov 0:cad5dab2b21d 95 #define LSM6DSL_TAP_DURATION_TIME_MID_LOW 0x04
nikapov 0:cad5dab2b21d 96 #define LSM6DSL_TAP_DURATION_TIME_MID 0x08
nikapov 0:cad5dab2b21d 97 #define LSM6DSL_TAP_DURATION_TIME_MID_HIGH 0x0C
nikapov 0:cad5dab2b21d 98 #define LSM6DSL_TAP_DURATION_TIME_HIGH 0x0F /**< Highest value of wake up threshold */
nikapov 0:cad5dab2b21d 99
nikapov 0:cad5dab2b21d 100 /* Typedefs ------------------------------------------------------------------*/
nikapov 0:cad5dab2b21d 101
nikapov 0:cad5dab2b21d 102 typedef enum
nikapov 0:cad5dab2b21d 103 {
nikapov 0:cad5dab2b21d 104 LSM6DSL_INT1_PIN,
nikapov 0:cad5dab2b21d 105 LSM6DSL_INT2_PIN
nikapov 0:cad5dab2b21d 106 } LSM6DSL_Interrupt_Pin_t;
nikapov 0:cad5dab2b21d 107
nikapov 0:cad5dab2b21d 108 typedef struct
nikapov 0:cad5dab2b21d 109 {
nikapov 0:cad5dab2b21d 110 unsigned int FreeFallStatus : 1;
nikapov 0:cad5dab2b21d 111 unsigned int TapStatus : 1;
nikapov 0:cad5dab2b21d 112 unsigned int DoubleTapStatus : 1;
nikapov 0:cad5dab2b21d 113 unsigned int WakeUpStatus : 1;
nikapov 0:cad5dab2b21d 114 unsigned int StepStatus : 1;
nikapov 0:cad5dab2b21d 115 unsigned int TiltStatus : 1;
nikapov 0:cad5dab2b21d 116 unsigned int D6DOrientationStatus : 1;
nikapov 0:cad5dab2b21d 117 } LSM6DSL_Event_Status_t;
nikapov 0:cad5dab2b21d 118
nikapov 0:cad5dab2b21d 119 /* Class Declaration ---------------------------------------------------------*/
nikapov 0:cad5dab2b21d 120
nikapov 0:cad5dab2b21d 121 /**
nikapov 0:cad5dab2b21d 122 * Abstract class of an LSM6DSL Inertial Measurement Unit (IMU) 6 axes
nikapov 0:cad5dab2b21d 123 * sensor.
nikapov 0:cad5dab2b21d 124 */
nikapov 0:cad5dab2b21d 125 class LSM6DSLSensor : public MotionSensor, public GyroSensor
nikapov 0:cad5dab2b21d 126 {
nikapov 0:cad5dab2b21d 127 public:
nikapov 0:cad5dab2b21d 128 LSM6DSLSensor(DevI2C &i2c, PinName INT1_pin, PinName INT2_pin);
nikapov 0:cad5dab2b21d 129 LSM6DSLSensor(DevI2C &i2c, PinName INT1_pin, PinName INT2_pin, uint8_t address);
nikapov 0:cad5dab2b21d 130 virtual int Init(void *init);
nikapov 0:cad5dab2b21d 131 virtual int ReadID(uint8_t *id);
nikapov 0:cad5dab2b21d 132 virtual int Get_X_Axes(int32_t *pData);
nikapov 0:cad5dab2b21d 133 virtual int Get_G_Axes(int32_t *pData);
nikapov 0:cad5dab2b21d 134 virtual int Get_X_Sensitivity(float *pfData);
nikapov 0:cad5dab2b21d 135 virtual int Get_G_Sensitivity(float *pfData);
nikapov 0:cad5dab2b21d 136 virtual int Get_X_AxesRaw(int16_t *pData);
nikapov 0:cad5dab2b21d 137 virtual int Get_G_AxesRaw(int16_t *pData);
nikapov 0:cad5dab2b21d 138 virtual int Get_X_ODR(float *odr);
nikapov 0:cad5dab2b21d 139 virtual int Get_G_ODR(float *odr);
nikapov 0:cad5dab2b21d 140 virtual int Set_X_ODR(float odr);
nikapov 0:cad5dab2b21d 141 virtual int Set_G_ODR(float odr);
nikapov 0:cad5dab2b21d 142 virtual int Get_X_FS(float *fullScale);
nikapov 0:cad5dab2b21d 143 virtual int Get_G_FS(float *fullScale);
nikapov 0:cad5dab2b21d 144 virtual int Set_X_FS(float fullScale);
nikapov 0:cad5dab2b21d 145 virtual int Set_G_FS(float fullScale);
nikapov 0:cad5dab2b21d 146 int Enable_X(void);
nikapov 0:cad5dab2b21d 147 int Enable_G(void);
nikapov 0:cad5dab2b21d 148 int Disable_X(void);
nikapov 0:cad5dab2b21d 149 int Disable_G(void);
cparata 5:63b2b4c21092 150 int Enable_Free_Fall_Detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN);
nikapov 0:cad5dab2b21d 151 int Disable_Free_Fall_Detection(void);
nikapov 0:cad5dab2b21d 152 int Set_Free_Fall_Threshold(uint8_t thr);
nikapov 0:cad5dab2b21d 153 int Enable_Pedometer(void);
nikapov 0:cad5dab2b21d 154 int Disable_Pedometer(void);
nikapov 0:cad5dab2b21d 155 int Get_Step_Counter(uint16_t *step_count);
nikapov 0:cad5dab2b21d 156 int Reset_Step_Counter(void);
nikapov 0:cad5dab2b21d 157 int Set_Pedometer_Threshold(uint8_t thr);
cparata 5:63b2b4c21092 158 int Enable_Tilt_Detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN);
nikapov 0:cad5dab2b21d 159 int Disable_Tilt_Detection(void);
cparata 5:63b2b4c21092 160 int Enable_Wake_Up_Detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT2_PIN);
nikapov 0:cad5dab2b21d 161 int Disable_Wake_Up_Detection(void);
nikapov 0:cad5dab2b21d 162 int Set_Wake_Up_Threshold(uint8_t thr);
cparata 5:63b2b4c21092 163 int Enable_Single_Tap_Detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN);
nikapov 0:cad5dab2b21d 164 int Disable_Single_Tap_Detection(void);
cparata 5:63b2b4c21092 165 int Enable_Double_Tap_Detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN);
nikapov 0:cad5dab2b21d 166 int Disable_Double_Tap_Detection(void);
nikapov 0:cad5dab2b21d 167 int Set_Tap_Threshold(uint8_t thr);
nikapov 0:cad5dab2b21d 168 int Set_Tap_Shock_Time(uint8_t time);
nikapov 0:cad5dab2b21d 169 int Set_Tap_Quiet_Time(uint8_t time);
nikapov 0:cad5dab2b21d 170 int Set_Tap_Duration_Time(uint8_t time);
cparata 5:63b2b4c21092 171 int Enable_6D_Orientation(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN);
nikapov 0:cad5dab2b21d 172 int Disable_6D_Orientation(void);
nikapov 0:cad5dab2b21d 173 int Get_6D_Orientation_XL(uint8_t *xl);
nikapov 0:cad5dab2b21d 174 int Get_6D_Orientation_XH(uint8_t *xh);
nikapov 0:cad5dab2b21d 175 int Get_6D_Orientation_YL(uint8_t *yl);
nikapov 0:cad5dab2b21d 176 int Get_6D_Orientation_YH(uint8_t *yh);
nikapov 0:cad5dab2b21d 177 int Get_6D_Orientation_ZL(uint8_t *zl);
nikapov 0:cad5dab2b21d 178 int Get_6D_Orientation_ZH(uint8_t *zh);
nikapov 0:cad5dab2b21d 179 int Get_Event_Status(LSM6DSL_Event_Status_t *status);
nikapov 0:cad5dab2b21d 180 int ReadReg(uint8_t reg, uint8_t *data);
nikapov 0:cad5dab2b21d 181 int WriteReg(uint8_t reg, uint8_t data);
nikapov 0:cad5dab2b21d 182
nikapov 0:cad5dab2b21d 183 /**
nikapov 0:cad5dab2b21d 184 * @brief Attaching an interrupt handler to the INT1 interrupt.
nikapov 0:cad5dab2b21d 185 * @param fptr An interrupt handler.
nikapov 0:cad5dab2b21d 186 * @retval None.
nikapov 0:cad5dab2b21d 187 */
nikapov 0:cad5dab2b21d 188 void AttachINT1IRQ(void (*fptr)(void))
nikapov 0:cad5dab2b21d 189 {
nikapov 0:cad5dab2b21d 190 INT1_irq.rise(fptr);
nikapov 0:cad5dab2b21d 191 }
nikapov 0:cad5dab2b21d 192
nikapov 0:cad5dab2b21d 193 /**
nikapov 0:cad5dab2b21d 194 * @brief Enabling the INT1 interrupt handling.
nikapov 0:cad5dab2b21d 195 * @param None.
nikapov 0:cad5dab2b21d 196 * @retval None.
nikapov 0:cad5dab2b21d 197 */
nikapov 0:cad5dab2b21d 198 void EnableINT1IRQ(void)
nikapov 0:cad5dab2b21d 199 {
nikapov 0:cad5dab2b21d 200 INT1_irq.enable_irq();
nikapov 0:cad5dab2b21d 201 }
nikapov 0:cad5dab2b21d 202
nikapov 0:cad5dab2b21d 203 /**
nikapov 0:cad5dab2b21d 204 * @brief Disabling the INT1 interrupt handling.
nikapov 0:cad5dab2b21d 205 * @param None.
nikapov 0:cad5dab2b21d 206 * @retval None.
nikapov 0:cad5dab2b21d 207 */
nikapov 0:cad5dab2b21d 208 void DisableINT1IRQ(void)
nikapov 0:cad5dab2b21d 209 {
nikapov 0:cad5dab2b21d 210 INT1_irq.disable_irq();
nikapov 0:cad5dab2b21d 211 }
nikapov 0:cad5dab2b21d 212
nikapov 0:cad5dab2b21d 213 /**
nikapov 0:cad5dab2b21d 214 * @brief Attaching an interrupt handler to the INT2 interrupt.
nikapov 0:cad5dab2b21d 215 * @param fptr An interrupt handler.
nikapov 0:cad5dab2b21d 216 * @retval None.
nikapov 0:cad5dab2b21d 217 */
nikapov 0:cad5dab2b21d 218 void AttachINT2IRQ(void (*fptr)(void))
nikapov 0:cad5dab2b21d 219 {
nikapov 0:cad5dab2b21d 220 INT2_irq.rise(fptr);
nikapov 0:cad5dab2b21d 221 }
nikapov 0:cad5dab2b21d 222
nikapov 0:cad5dab2b21d 223 /**
nikapov 0:cad5dab2b21d 224 * @brief Enabling the INT2 interrupt handling.
nikapov 0:cad5dab2b21d 225 * @param None.
nikapov 0:cad5dab2b21d 226 * @retval None.
nikapov 0:cad5dab2b21d 227 */
nikapov 0:cad5dab2b21d 228 void EnableINT2IRQ(void)
nikapov 0:cad5dab2b21d 229 {
nikapov 0:cad5dab2b21d 230 INT2_irq.enable_irq();
nikapov 0:cad5dab2b21d 231 }
nikapov 0:cad5dab2b21d 232
nikapov 0:cad5dab2b21d 233 /**
nikapov 0:cad5dab2b21d 234 * @brief Disabling the INT2 interrupt handling.
nikapov 0:cad5dab2b21d 235 * @param None.
nikapov 0:cad5dab2b21d 236 * @retval None.
nikapov 0:cad5dab2b21d 237 */
nikapov 0:cad5dab2b21d 238 void DisableINT2IRQ(void)
nikapov 0:cad5dab2b21d 239 {
nikapov 0:cad5dab2b21d 240 INT2_irq.disable_irq();
nikapov 0:cad5dab2b21d 241 }
nikapov 0:cad5dab2b21d 242
nikapov 0:cad5dab2b21d 243 /**
nikapov 0:cad5dab2b21d 244 * @brief Utility function to read data.
nikapov 0:cad5dab2b21d 245 * @param pBuffer: pointer to data to be read.
nikapov 0:cad5dab2b21d 246 * @param RegisterAddr: specifies internal address register to be read.
nikapov 0:cad5dab2b21d 247 * @param NumByteToRead: number of bytes to be read.
nikapov 0:cad5dab2b21d 248 * @retval 0 if ok, an error code otherwise.
nikapov 0:cad5dab2b21d 249 */
nikapov 0:cad5dab2b21d 250 uint8_t IO_Read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead)
nikapov 0:cad5dab2b21d 251 {
nikapov 0:cad5dab2b21d 252 return (uint8_t) dev_i2c.i2c_read(pBuffer, address, RegisterAddr, NumByteToRead);
nikapov 0:cad5dab2b21d 253 }
nikapov 0:cad5dab2b21d 254
nikapov 0:cad5dab2b21d 255 /**
nikapov 0:cad5dab2b21d 256 * @brief Utility function to write data.
nikapov 0:cad5dab2b21d 257 * @param pBuffer: pointer to data to be written.
nikapov 0:cad5dab2b21d 258 * @param RegisterAddr: specifies internal address register to be written.
nikapov 0:cad5dab2b21d 259 * @param NumByteToWrite: number of bytes to write.
nikapov 0:cad5dab2b21d 260 * @retval 0 if ok, an error code otherwise.
nikapov 0:cad5dab2b21d 261 */
nikapov 0:cad5dab2b21d 262 uint8_t IO_Write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite)
nikapov 0:cad5dab2b21d 263 {
nikapov 0:cad5dab2b21d 264 return (uint8_t) dev_i2c.i2c_write(pBuffer, address, RegisterAddr, NumByteToWrite);
nikapov 0:cad5dab2b21d 265 }
nikapov 0:cad5dab2b21d 266
nikapov 0:cad5dab2b21d 267 private:
nikapov 0:cad5dab2b21d 268 int Set_X_ODR_When_Enabled(float odr);
nikapov 0:cad5dab2b21d 269 int Set_G_ODR_When_Enabled(float odr);
nikapov 0:cad5dab2b21d 270 int Set_X_ODR_When_Disabled(float odr);
nikapov 0:cad5dab2b21d 271 int Set_G_ODR_When_Disabled(float odr);
nikapov 0:cad5dab2b21d 272
nikapov 0:cad5dab2b21d 273 /* Helper classes. */
nikapov 0:cad5dab2b21d 274 DevI2C &dev_i2c;
nikapov 0:cad5dab2b21d 275
nikapov 0:cad5dab2b21d 276 InterruptIn INT1_irq;
nikapov 0:cad5dab2b21d 277 InterruptIn INT2_irq;
nikapov 0:cad5dab2b21d 278
nikapov 0:cad5dab2b21d 279 /* Configuration */
nikapov 0:cad5dab2b21d 280 uint8_t address;
nikapov 0:cad5dab2b21d 281
nikapov 0:cad5dab2b21d 282 uint8_t X_isEnabled;
nikapov 0:cad5dab2b21d 283 float X_Last_ODR;
nikapov 0:cad5dab2b21d 284 uint8_t G_isEnabled;
nikapov 0:cad5dab2b21d 285 float G_Last_ODR;
nikapov 0:cad5dab2b21d 286 };
nikapov 0:cad5dab2b21d 287
nikapov 0:cad5dab2b21d 288 #ifdef __cplusplus
nikapov 0:cad5dab2b21d 289 extern "C" {
nikapov 0:cad5dab2b21d 290 #endif
nikapov 0:cad5dab2b21d 291 uint8_t LSM6DSL_IO_Write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite );
nikapov 0:cad5dab2b21d 292 uint8_t LSM6DSL_IO_Read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead );
nikapov 0:cad5dab2b21d 293 #ifdef __cplusplus
nikapov 0:cad5dab2b21d 294 }
nikapov 0:cad5dab2b21d 295 #endif
nikapov 0:cad5dab2b21d 296
nikapov 0:cad5dab2b21d 297 #endif