Beta
Dependencies: ST_INTERFACES X_NUCLEO_COMMON
Fork of X_NUCLEO_IKS01A2 by
Components/LSM6DSLSensor/LSM6DSLSensor.h@6:671fd10a51b7, 2017-03-14 (annotated)
- Committer:
- davide.aliprandi@st.com
- Date:
- Tue Mar 14 13:41:32 2017 +0100
- Revision:
- 6:671fd10a51b7
- Parent:
- 5:63b2b4c21092
- Child:
- 9:038121268b07
Aligning to ARM mbed coding style.
Who changed what in which revision?
User | Revision | Line number | New 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>© 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" |
davide.aliprandi@st.com | 6:671fd10a51b7 | 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); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 130 | virtual int init(void *init); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 131 | virtual int read_id(uint8_t *id); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 132 | virtual int get_x_axes(int32_t *pData); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 133 | virtual int get_g_axes(int32_t *pData); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 134 | virtual int get_x_sensitivity(float *pfData); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 135 | virtual int get_g_sensitivity(float *pfData); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 136 | virtual int get_x_axesRaw(int16_t *pData); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 137 | virtual int get_g_axesRaw(int16_t *pData); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 138 | virtual int get_x_odr(float *odr); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 139 | virtual int get_g_odr(float *odr); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 140 | virtual int set_x_odr(float odr); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 141 | virtual int set_g_odr(float odr); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 142 | virtual int get_x_fs(float *fullScale); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 143 | virtual int get_g_fs(float *fullScale); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 144 | virtual int set_x_fs(float fullScale); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 145 | virtual int set_g_fs(float fullScale); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 146 | int enable_x(void); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 147 | int enable_g(void); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 148 | int disable_x(void); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 149 | int disable_g(void); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 150 | int enable_free_fall_detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 151 | int disable_free_fall_detection(void); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 152 | int set_free_fall_threshold(uint8_t thr); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 153 | int enable_pedometer(void); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 154 | int disable_pedometer(void); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 155 | int get_step_counter(uint16_t *step_count); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 156 | int reset_step_counter(void); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 157 | int set_pedometer_threshold(uint8_t thr); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 158 | int enable_tilt_detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 159 | int disable_tilt_detection(void); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 160 | int enable_wake_up_detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT2_PIN); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 161 | int disable_wake_up_detection(void); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 162 | int set_wake_up_threshold(uint8_t thr); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 163 | int enable_single_tap_detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 164 | int disable_single_tap_detection(void); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 165 | int enable_double_tap_detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 166 | int disable_double_tap_detection(void); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 167 | int set_tap_threshold(uint8_t thr); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 168 | int set_tap_shock_time(uint8_t time); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 169 | int set_tap_quiet_time(uint8_t time); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 170 | int set_tap_duration_time(uint8_t time); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 171 | int enable_6d_orientation(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 172 | int disable_6d_orientation(void); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 173 | int get_6d_orientation_xl(uint8_t *xl); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 174 | int get_6d_orientation_xh(uint8_t *xh); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 175 | int get_6d_orientation_yl(uint8_t *yl); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 176 | int get_6d_orientation_yh(uint8_t *yh); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 177 | int get_6d_orientation_zl(uint8_t *zl); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 178 | int get_6d_orientation_zh(uint8_t *zh); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 179 | int get_event_status(LSM6DSL_Event_Status_t *status); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 180 | int read_reg(uint8_t reg, uint8_t *data); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 181 | int write_reg(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 | */ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 188 | void attach_int1_irq(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 | */ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 198 | void enable_int1_irq(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 | */ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 208 | void disable_int1_irq(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 | */ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 218 | void attach_int2_irq(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 | */ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 228 | void enable_int2_irq(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 | */ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 238 | void disable_int2_irq(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 | */ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 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 | */ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 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: |
davide.aliprandi@st.com | 6:671fd10a51b7 | 268 | int set_x_odr_when_enabled(float odr); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 269 | int set_g_odr_when_enabled(float odr); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 270 | int set_x_odr_when_disabled(float odr); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 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 |
davide.aliprandi@st.com | 6:671fd10a51b7 | 291 | uint8_t LSM6DSL_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 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 |