HAHA
Dependencies: ST_INTERFACES X_NUCLEO_COMMON
Dependents: b_NYP_humanoid a_NYP_humanoid_copy
Fork of LSM6DSL by
LSM6DSLSensor.h@0:704c89673b57, 2017-09-04 (annotated)
- Committer:
- nikapov
- Date:
- Mon Sep 04 16:08:00 2017 +0000
- Revision:
- 0:704c89673b57
- Child:
- 1:c583f32fe272
First version.
Who changed what in which revision?
User | Revision | Line number | New 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>© 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" |
nikapov | 0:704c89673b57 | 52 | |
nikapov | 0:704c89673b57 | 53 | /* Defines -------------------------------------------------------------------*/ |
nikapov | 0:704c89673b57 | 54 | |
nikapov | 0:704c89673b57 | 55 | #define LSM6DSL_ACC_SENSITIVITY_FOR_FS_2G 0.061 /**< Sensitivity value for 2 g full scale [mg/LSB] */ |
nikapov | 0:704c89673b57 | 56 | #define LSM6DSL_ACC_SENSITIVITY_FOR_FS_4G 0.122 /**< Sensitivity value for 4 g full scale [mg/LSB] */ |
nikapov | 0:704c89673b57 | 57 | #define LSM6DSL_ACC_SENSITIVITY_FOR_FS_8G 0.244 /**< Sensitivity value for 8 g full scale [mg/LSB] */ |
nikapov | 0:704c89673b57 | 58 | #define LSM6DSL_ACC_SENSITIVITY_FOR_FS_16G 0.488 /**< Sensitivity value for 16 g full scale [mg/LSB] */ |
nikapov | 0:704c89673b57 | 59 | |
nikapov | 0:704c89673b57 | 60 | #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_125DPS 04.375 /**< Sensitivity value for 125 dps full scale [mdps/LSB] */ |
nikapov | 0:704c89673b57 | 61 | #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_245DPS 08.750 /**< Sensitivity value for 245 dps full scale [mdps/LSB] */ |
nikapov | 0:704c89673b57 | 62 | #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_500DPS 17.500 /**< Sensitivity value for 500 dps full scale [mdps/LSB] */ |
nikapov | 0:704c89673b57 | 63 | #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_1000DPS 35.000 /**< Sensitivity value for 1000 dps full scale [mdps/LSB] */ |
nikapov | 0:704c89673b57 | 64 | #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_2000DPS 70.000 /**< Sensitivity value for 2000 dps full scale [mdps/LSB] */ |
nikapov | 0:704c89673b57 | 65 | |
nikapov | 0:704c89673b57 | 66 | #define LSM6DSL_PEDOMETER_THRESHOLD_LOW 0x00 /**< Lowest value of pedometer threshold */ |
nikapov | 0:704c89673b57 | 67 | #define LSM6DSL_PEDOMETER_THRESHOLD_MID_LOW 0x07 |
nikapov | 0:704c89673b57 | 68 | #define LSM6DSL_PEDOMETER_THRESHOLD_MID 0x0F |
nikapov | 0:704c89673b57 | 69 | #define LSM6DSL_PEDOMETER_THRESHOLD_MID_HIGH 0x17 |
nikapov | 0:704c89673b57 | 70 | #define LSM6DSL_PEDOMETER_THRESHOLD_HIGH 0x1F /**< Highest value of pedometer threshold */ |
nikapov | 0:704c89673b57 | 71 | |
nikapov | 0:704c89673b57 | 72 | #define LSM6DSL_WAKE_UP_THRESHOLD_LOW 0x01 /**< Lowest value of wake up threshold */ |
nikapov | 0:704c89673b57 | 73 | #define LSM6DSL_WAKE_UP_THRESHOLD_MID_LOW 0x0F |
nikapov | 0:704c89673b57 | 74 | #define LSM6DSL_WAKE_UP_THRESHOLD_MID 0x1F |
nikapov | 0:704c89673b57 | 75 | #define LSM6DSL_WAKE_UP_THRESHOLD_MID_HIGH 0x2F |
nikapov | 0:704c89673b57 | 76 | #define LSM6DSL_WAKE_UP_THRESHOLD_HIGH 0x3F /**< Highest value of wake up threshold */ |
nikapov | 0:704c89673b57 | 77 | |
nikapov | 0:704c89673b57 | 78 | #define LSM6DSL_TAP_THRESHOLD_LOW 0x01 /**< Lowest value of wake up threshold */ |
nikapov | 0:704c89673b57 | 79 | #define LSM6DSL_TAP_THRESHOLD_MID_LOW 0x08 |
nikapov | 0:704c89673b57 | 80 | #define LSM6DSL_TAP_THRESHOLD_MID 0x10 |
nikapov | 0:704c89673b57 | 81 | #define LSM6DSL_TAP_THRESHOLD_MID_HIGH 0x18 |
nikapov | 0:704c89673b57 | 82 | #define LSM6DSL_TAP_THRESHOLD_HIGH 0x1F /**< Highest value of wake up threshold */ |
nikapov | 0:704c89673b57 | 83 | |
nikapov | 0:704c89673b57 | 84 | #define LSM6DSL_TAP_SHOCK_TIME_LOW 0x00 /**< Lowest value of wake up threshold */ |
nikapov | 0:704c89673b57 | 85 | #define LSM6DSL_TAP_SHOCK_TIME_MID_LOW 0x01 |
nikapov | 0:704c89673b57 | 86 | #define LSM6DSL_TAP_SHOCK_TIME_MID_HIGH 0x02 |
nikapov | 0:704c89673b57 | 87 | #define LSM6DSL_TAP_SHOCK_TIME_HIGH 0x03 /**< Highest value of wake up threshold */ |
nikapov | 0:704c89673b57 | 88 | |
nikapov | 0:704c89673b57 | 89 | #define LSM6DSL_TAP_QUIET_TIME_LOW 0x00 /**< Lowest value of wake up threshold */ |
nikapov | 0:704c89673b57 | 90 | #define LSM6DSL_TAP_QUIET_TIME_MID_LOW 0x01 |
nikapov | 0:704c89673b57 | 91 | #define LSM6DSL_TAP_QUIET_TIME_MID_HIGH 0x02 |
nikapov | 0:704c89673b57 | 92 | #define LSM6DSL_TAP_QUIET_TIME_HIGH 0x03 /**< Highest value of wake up threshold */ |
nikapov | 0:704c89673b57 | 93 | |
nikapov | 0:704c89673b57 | 94 | #define LSM6DSL_TAP_DURATION_TIME_LOW 0x00 /**< Lowest value of wake up threshold */ |
nikapov | 0:704c89673b57 | 95 | #define LSM6DSL_TAP_DURATION_TIME_MID_LOW 0x04 |
nikapov | 0:704c89673b57 | 96 | #define LSM6DSL_TAP_DURATION_TIME_MID 0x08 |
nikapov | 0:704c89673b57 | 97 | #define LSM6DSL_TAP_DURATION_TIME_MID_HIGH 0x0C |
nikapov | 0:704c89673b57 | 98 | #define LSM6DSL_TAP_DURATION_TIME_HIGH 0x0F /**< Highest value of wake up threshold */ |
nikapov | 0:704c89673b57 | 99 | |
nikapov | 0:704c89673b57 | 100 | /* Typedefs ------------------------------------------------------------------*/ |
nikapov | 0:704c89673b57 | 101 | |
nikapov | 0:704c89673b57 | 102 | typedef enum |
nikapov | 0:704c89673b57 | 103 | { |
nikapov | 0:704c89673b57 | 104 | LSM6DSL_INT1_PIN, |
nikapov | 0:704c89673b57 | 105 | LSM6DSL_INT2_PIN |
nikapov | 0:704c89673b57 | 106 | } LSM6DSL_Interrupt_Pin_t; |
nikapov | 0:704c89673b57 | 107 | |
nikapov | 0:704c89673b57 | 108 | typedef struct |
nikapov | 0:704c89673b57 | 109 | { |
nikapov | 0:704c89673b57 | 110 | unsigned int FreeFallStatus : 1; |
nikapov | 0:704c89673b57 | 111 | unsigned int TapStatus : 1; |
nikapov | 0:704c89673b57 | 112 | unsigned int DoubleTapStatus : 1; |
nikapov | 0:704c89673b57 | 113 | unsigned int WakeUpStatus : 1; |
nikapov | 0:704c89673b57 | 114 | unsigned int StepStatus : 1; |
nikapov | 0:704c89673b57 | 115 | unsigned int TiltStatus : 1; |
nikapov | 0:704c89673b57 | 116 | unsigned int D6DOrientationStatus : 1; |
nikapov | 0:704c89673b57 | 117 | } LSM6DSL_Event_Status_t; |
nikapov | 0:704c89673b57 | 118 | |
nikapov | 0:704c89673b57 | 119 | /* Class Declaration ---------------------------------------------------------*/ |
nikapov | 0:704c89673b57 | 120 | |
nikapov | 0:704c89673b57 | 121 | /** |
nikapov | 0:704c89673b57 | 122 | * Abstract class of an LSM6DSL Inertial Measurement Unit (IMU) 6 axes |
nikapov | 0:704c89673b57 | 123 | * sensor. |
nikapov | 0:704c89673b57 | 124 | */ |
nikapov | 0:704c89673b57 | 125 | class LSM6DSLSensor : public MotionSensor, public GyroSensor |
nikapov | 0:704c89673b57 | 126 | { |
nikapov | 0:704c89673b57 | 127 | public: |
nikapov | 0:704c89673b57 | 128 | LSM6DSLSensor(DevI2C &i2c, PinName INT1_pin, PinName INT2_pin); |
nikapov | 0:704c89673b57 | 129 | LSM6DSLSensor(DevI2C &i2c, PinName INT1_pin, PinName INT2_pin, uint8_t address); |
nikapov | 0:704c89673b57 | 130 | virtual int init(void *init); |
nikapov | 0:704c89673b57 | 131 | virtual int read_id(uint8_t *id); |
nikapov | 0:704c89673b57 | 132 | virtual int get_x_axes(int32_t *pData); |
nikapov | 0:704c89673b57 | 133 | virtual int get_g_axes(int32_t *pData); |
nikapov | 0:704c89673b57 | 134 | virtual int get_x_sensitivity(float *pfData); |
nikapov | 0:704c89673b57 | 135 | virtual int get_g_sensitivity(float *pfData); |
nikapov | 0:704c89673b57 | 136 | virtual int get_x_axes_raw(int16_t *pData); |
nikapov | 0:704c89673b57 | 137 | virtual int get_g_axes_raw(int16_t *pData); |
nikapov | 0:704c89673b57 | 138 | virtual int get_x_odr(float *odr); |
nikapov | 0:704c89673b57 | 139 | virtual int get_g_odr(float *odr); |
nikapov | 0:704c89673b57 | 140 | virtual int set_x_odr(float odr); |
nikapov | 0:704c89673b57 | 141 | virtual int set_g_odr(float odr); |
nikapov | 0:704c89673b57 | 142 | virtual int get_x_fs(float *fullScale); |
nikapov | 0:704c89673b57 | 143 | virtual int get_g_fs(float *fullScale); |
nikapov | 0:704c89673b57 | 144 | virtual int set_x_fs(float fullScale); |
nikapov | 0:704c89673b57 | 145 | virtual int set_g_fs(float fullScale); |
nikapov | 0:704c89673b57 | 146 | int enable_x(void); |
nikapov | 0:704c89673b57 | 147 | int enable_g(void); |
nikapov | 0:704c89673b57 | 148 | int disable_x(void); |
nikapov | 0:704c89673b57 | 149 | int disable_g(void); |
nikapov | 0:704c89673b57 | 150 | int enable_free_fall_detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN); |
nikapov | 0:704c89673b57 | 151 | int disable_free_fall_detection(void); |
nikapov | 0:704c89673b57 | 152 | int set_free_fall_threshold(uint8_t thr); |
nikapov | 0:704c89673b57 | 153 | int enable_pedometer(void); |
nikapov | 0:704c89673b57 | 154 | int disable_pedometer(void); |
nikapov | 0:704c89673b57 | 155 | int get_step_counter(uint16_t *step_count); |
nikapov | 0:704c89673b57 | 156 | int reset_step_counter(void); |
nikapov | 0:704c89673b57 | 157 | int set_pedometer_threshold(uint8_t thr); |
nikapov | 0:704c89673b57 | 158 | int enable_tilt_detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN); |
nikapov | 0:704c89673b57 | 159 | int disable_tilt_detection(void); |
nikapov | 0:704c89673b57 | 160 | int enable_wake_up_detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT2_PIN); |
nikapov | 0:704c89673b57 | 161 | int disable_wake_up_detection(void); |
nikapov | 0:704c89673b57 | 162 | int set_wake_up_threshold(uint8_t thr); |
nikapov | 0:704c89673b57 | 163 | int enable_single_tap_detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN); |
nikapov | 0:704c89673b57 | 164 | int disable_single_tap_detection(void); |
nikapov | 0:704c89673b57 | 165 | int enable_double_tap_detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN); |
nikapov | 0:704c89673b57 | 166 | int disable_double_tap_detection(void); |
nikapov | 0:704c89673b57 | 167 | int set_tap_threshold(uint8_t thr); |
nikapov | 0:704c89673b57 | 168 | int set_tap_shock_time(uint8_t time); |
nikapov | 0:704c89673b57 | 169 | int set_tap_quiet_time(uint8_t time); |
nikapov | 0:704c89673b57 | 170 | int set_tap_duration_time(uint8_t time); |
nikapov | 0:704c89673b57 | 171 | int enable_6d_orientation(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN); |
nikapov | 0:704c89673b57 | 172 | int disable_6d_orientation(void); |
nikapov | 0:704c89673b57 | 173 | int get_6d_orientation_xl(uint8_t *xl); |
nikapov | 0:704c89673b57 | 174 | int get_6d_orientation_xh(uint8_t *xh); |
nikapov | 0:704c89673b57 | 175 | int get_6d_orientation_yl(uint8_t *yl); |
nikapov | 0:704c89673b57 | 176 | int get_6d_orientation_yh(uint8_t *yh); |
nikapov | 0:704c89673b57 | 177 | int get_6d_orientation_zl(uint8_t *zl); |
nikapov | 0:704c89673b57 | 178 | int get_6d_orientation_zh(uint8_t *zh); |
nikapov | 0:704c89673b57 | 179 | int get_event_status(LSM6DSL_Event_Status_t *status); |
nikapov | 0:704c89673b57 | 180 | int read_reg(uint8_t reg, uint8_t *data); |
nikapov | 0:704c89673b57 | 181 | int write_reg(uint8_t reg, uint8_t data); |
nikapov | 0:704c89673b57 | 182 | |
nikapov | 0:704c89673b57 | 183 | /** |
nikapov | 0:704c89673b57 | 184 | * @brief Attaching an interrupt handler to the INT1 interrupt. |
nikapov | 0:704c89673b57 | 185 | * @param fptr An interrupt handler. |
nikapov | 0:704c89673b57 | 186 | * @retval None. |
nikapov | 0:704c89673b57 | 187 | */ |
nikapov | 0:704c89673b57 | 188 | void attach_int1_irq(void (*fptr)(void)) |
nikapov | 0:704c89673b57 | 189 | { |
nikapov | 0:704c89673b57 | 190 | _int1_irq.rise(fptr); |
nikapov | 0:704c89673b57 | 191 | } |
nikapov | 0:704c89673b57 | 192 | |
nikapov | 0:704c89673b57 | 193 | /** |
nikapov | 0:704c89673b57 | 194 | * @brief Enabling the INT1 interrupt handling. |
nikapov | 0:704c89673b57 | 195 | * @param None. |
nikapov | 0:704c89673b57 | 196 | * @retval None. |
nikapov | 0:704c89673b57 | 197 | */ |
nikapov | 0:704c89673b57 | 198 | void enable_int1_irq(void) |
nikapov | 0:704c89673b57 | 199 | { |
nikapov | 0:704c89673b57 | 200 | _int1_irq.enable_irq(); |
nikapov | 0:704c89673b57 | 201 | } |
nikapov | 0:704c89673b57 | 202 | |
nikapov | 0:704c89673b57 | 203 | /** |
nikapov | 0:704c89673b57 | 204 | * @brief Disabling the INT1 interrupt handling. |
nikapov | 0:704c89673b57 | 205 | * @param None. |
nikapov | 0:704c89673b57 | 206 | * @retval None. |
nikapov | 0:704c89673b57 | 207 | */ |
nikapov | 0:704c89673b57 | 208 | void disable_int1_irq(void) |
nikapov | 0:704c89673b57 | 209 | { |
nikapov | 0:704c89673b57 | 210 | _int1_irq.disable_irq(); |
nikapov | 0:704c89673b57 | 211 | } |
nikapov | 0:704c89673b57 | 212 | |
nikapov | 0:704c89673b57 | 213 | /** |
nikapov | 0:704c89673b57 | 214 | * @brief Attaching an interrupt handler to the INT2 interrupt. |
nikapov | 0:704c89673b57 | 215 | * @param fptr An interrupt handler. |
nikapov | 0:704c89673b57 | 216 | * @retval None. |
nikapov | 0:704c89673b57 | 217 | */ |
nikapov | 0:704c89673b57 | 218 | void attach_int2_irq(void (*fptr)(void)) |
nikapov | 0:704c89673b57 | 219 | { |
nikapov | 0:704c89673b57 | 220 | _int2_irq.rise(fptr); |
nikapov | 0:704c89673b57 | 221 | } |
nikapov | 0:704c89673b57 | 222 | |
nikapov | 0:704c89673b57 | 223 | /** |
nikapov | 0:704c89673b57 | 224 | * @brief Enabling the INT2 interrupt handling. |
nikapov | 0:704c89673b57 | 225 | * @param None. |
nikapov | 0:704c89673b57 | 226 | * @retval None. |
nikapov | 0:704c89673b57 | 227 | */ |
nikapov | 0:704c89673b57 | 228 | void enable_int2_irq(void) |
nikapov | 0:704c89673b57 | 229 | { |
nikapov | 0:704c89673b57 | 230 | _int2_irq.enable_irq(); |
nikapov | 0:704c89673b57 | 231 | } |
nikapov | 0:704c89673b57 | 232 | |
nikapov | 0:704c89673b57 | 233 | /** |
nikapov | 0:704c89673b57 | 234 | * @brief Disabling the INT2 interrupt handling. |
nikapov | 0:704c89673b57 | 235 | * @param None. |
nikapov | 0:704c89673b57 | 236 | * @retval None. |
nikapov | 0:704c89673b57 | 237 | */ |
nikapov | 0:704c89673b57 | 238 | void disable_int2_irq(void) |
nikapov | 0:704c89673b57 | 239 | { |
nikapov | 0:704c89673b57 | 240 | _int2_irq.disable_irq(); |
nikapov | 0:704c89673b57 | 241 | } |
nikapov | 0:704c89673b57 | 242 | |
nikapov | 0:704c89673b57 | 243 | /** |
nikapov | 0:704c89673b57 | 244 | * @brief Utility function to read data. |
nikapov | 0:704c89673b57 | 245 | * @param pBuffer: pointer to data to be read. |
nikapov | 0:704c89673b57 | 246 | * @param RegisterAddr: specifies internal address register to be read. |
nikapov | 0:704c89673b57 | 247 | * @param NumByteToRead: number of bytes to be read. |
nikapov | 0:704c89673b57 | 248 | * @retval 0 if ok, an error code otherwise. |
nikapov | 0:704c89673b57 | 249 | */ |
nikapov | 0:704c89673b57 | 250 | uint8_t io_read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead) |
nikapov | 0:704c89673b57 | 251 | { |
nikapov | 0:704c89673b57 | 252 | return (uint8_t) _dev_i2c.i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead); |
nikapov | 0:704c89673b57 | 253 | } |
nikapov | 0:704c89673b57 | 254 | |
nikapov | 0:704c89673b57 | 255 | /** |
nikapov | 0:704c89673b57 | 256 | * @brief Utility function to write data. |
nikapov | 0:704c89673b57 | 257 | * @param pBuffer: pointer to data to be written. |
nikapov | 0:704c89673b57 | 258 | * @param RegisterAddr: specifies internal address register to be written. |
nikapov | 0:704c89673b57 | 259 | * @param NumByteToWrite: number of bytes to write. |
nikapov | 0:704c89673b57 | 260 | * @retval 0 if ok, an error code otherwise. |
nikapov | 0:704c89673b57 | 261 | */ |
nikapov | 0:704c89673b57 | 262 | uint8_t io_write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite) |
nikapov | 0:704c89673b57 | 263 | { |
nikapov | 0:704c89673b57 | 264 | return (uint8_t) _dev_i2c.i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite); |
nikapov | 0:704c89673b57 | 265 | } |
nikapov | 0:704c89673b57 | 266 | |
nikapov | 0:704c89673b57 | 267 | private: |
nikapov | 0:704c89673b57 | 268 | int set_x_odr_when_enabled(float odr); |
nikapov | 0:704c89673b57 | 269 | int set_g_odr_when_enabled(float odr); |
nikapov | 0:704c89673b57 | 270 | int set_x_odr_when_disabled(float odr); |
nikapov | 0:704c89673b57 | 271 | int set_g_odr_when_disabled(float odr); |
nikapov | 0:704c89673b57 | 272 | |
nikapov | 0:704c89673b57 | 273 | /* Helper classes. */ |
nikapov | 0:704c89673b57 | 274 | DevI2C &_dev_i2c; |
nikapov | 0:704c89673b57 | 275 | |
nikapov | 0:704c89673b57 | 276 | InterruptIn _int1_irq; |
nikapov | 0:704c89673b57 | 277 | InterruptIn _int2_irq; |
nikapov | 0:704c89673b57 | 278 | |
nikapov | 0:704c89673b57 | 279 | /* Configuration */ |
nikapov | 0:704c89673b57 | 280 | uint8_t _address; |
nikapov | 0:704c89673b57 | 281 | |
nikapov | 0:704c89673b57 | 282 | uint8_t _x_is_enabled; |
nikapov | 0:704c89673b57 | 283 | float _x_last_odr; |
nikapov | 0:704c89673b57 | 284 | uint8_t _g_is_enabled; |
nikapov | 0:704c89673b57 | 285 | float _g_last_odr; |
nikapov | 0:704c89673b57 | 286 | }; |
nikapov | 0:704c89673b57 | 287 | |
nikapov | 0:704c89673b57 | 288 | #ifdef __cplusplus |
nikapov | 0:704c89673b57 | 289 | extern "C" { |
nikapov | 0:704c89673b57 | 290 | #endif |
nikapov | 0:704c89673b57 | 291 | uint8_t LSM6DSL_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ); |
nikapov | 0:704c89673b57 | 292 | uint8_t LSM6DSL_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ); |
nikapov | 0:704c89673b57 | 293 | #ifdef __cplusplus |
nikapov | 0:704c89673b57 | 294 | } |
nikapov | 0:704c89673b57 | 295 | #endif |
nikapov | 0:704c89673b57 | 296 | |
nikapov | 0:704c89673b57 | 297 | #endif |