Beta
Dependencies: ST_INTERFACES X_NUCLEO_COMMON
Fork of X_NUCLEO_IKS01A2 by
LSM6DSLSensor.h
00001 /** 00002 ****************************************************************************** 00003 * @file LSM6DSLSensor.h 00004 * @author CLab 00005 * @version V1.0.0 00006 * @date 5 August 2016 00007 * @brief Abstract Class of an LSM6DSL Inertial Measurement Unit (IMU) 6 axes 00008 * sensor. 00009 ****************************************************************************** 00010 * @attention 00011 * 00012 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> 00013 * 00014 * Redistribution and use in source and binary forms, with or without modification, 00015 * are permitted provided that the following conditions are met: 00016 * 1. Redistributions of source code must retain the above copyright notice, 00017 * this list of conditions and the following disclaimer. 00018 * 2. Redistributions in binary form must reproduce the above copyright notice, 00019 * this list of conditions and the following disclaimer in the documentation 00020 * and/or other materials provided with the distribution. 00021 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00022 * may be used to endorse or promote products derived from this software 00023 * without specific prior written permission. 00024 * 00025 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00026 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00028 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00029 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00030 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00031 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00032 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00033 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00034 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 ****************************************************************************** 00037 */ 00038 00039 00040 /* Prevent recursive inclusion -----------------------------------------------*/ 00041 00042 #ifndef __LSM6DSLSensor_H__ 00043 #define __LSM6DSLSensor_H__ 00044 00045 00046 /* Includes ------------------------------------------------------------------*/ 00047 00048 #include "DevI2C.h" 00049 #include "LSM6DSL_acc_gyro_driver.h" 00050 #include "MotionSensor.h" 00051 #include "GyroSensor.h" 00052 00053 /* Defines -------------------------------------------------------------------*/ 00054 00055 #define LSM6DSL_ACC_SENSITIVITY_FOR_FS_2G 0.061 /**< Sensitivity value for 2 g full scale [mg/LSB] */ 00056 #define LSM6DSL_ACC_SENSITIVITY_FOR_FS_4G 0.122 /**< Sensitivity value for 4 g full scale [mg/LSB] */ 00057 #define LSM6DSL_ACC_SENSITIVITY_FOR_FS_8G 0.244 /**< Sensitivity value for 8 g full scale [mg/LSB] */ 00058 #define LSM6DSL_ACC_SENSITIVITY_FOR_FS_16G 0.488 /**< Sensitivity value for 16 g full scale [mg/LSB] */ 00059 00060 #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_125DPS 04.375 /**< Sensitivity value for 125 dps full scale [mdps/LSB] */ 00061 #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_245DPS 08.750 /**< Sensitivity value for 245 dps full scale [mdps/LSB] */ 00062 #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_500DPS 17.500 /**< Sensitivity value for 500 dps full scale [mdps/LSB] */ 00063 #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_1000DPS 35.000 /**< Sensitivity value for 1000 dps full scale [mdps/LSB] */ 00064 #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_2000DPS 70.000 /**< Sensitivity value for 2000 dps full scale [mdps/LSB] */ 00065 00066 #define LSM6DSL_PEDOMETER_THRESHOLD_LOW 0x00 /**< Lowest value of pedometer threshold */ 00067 #define LSM6DSL_PEDOMETER_THRESHOLD_MID_LOW 0x07 00068 #define LSM6DSL_PEDOMETER_THRESHOLD_MID 0x0F 00069 #define LSM6DSL_PEDOMETER_THRESHOLD_MID_HIGH 0x17 00070 #define LSM6DSL_PEDOMETER_THRESHOLD_HIGH 0x1F /**< Highest value of pedometer threshold */ 00071 00072 #define LSM6DSL_WAKE_UP_THRESHOLD_LOW 0x01 /**< Lowest value of wake up threshold */ 00073 #define LSM6DSL_WAKE_UP_THRESHOLD_MID_LOW 0x0F 00074 #define LSM6DSL_WAKE_UP_THRESHOLD_MID 0x1F 00075 #define LSM6DSL_WAKE_UP_THRESHOLD_MID_HIGH 0x2F 00076 #define LSM6DSL_WAKE_UP_THRESHOLD_HIGH 0x3F /**< Highest value of wake up threshold */ 00077 00078 #define LSM6DSL_TAP_THRESHOLD_LOW 0x01 /**< Lowest value of wake up threshold */ 00079 #define LSM6DSL_TAP_THRESHOLD_MID_LOW 0x08 00080 #define LSM6DSL_TAP_THRESHOLD_MID 0x10 00081 #define LSM6DSL_TAP_THRESHOLD_MID_HIGH 0x18 00082 #define LSM6DSL_TAP_THRESHOLD_HIGH 0x1F /**< Highest value of wake up threshold */ 00083 00084 #define LSM6DSL_TAP_SHOCK_TIME_LOW 0x00 /**< Lowest value of wake up threshold */ 00085 #define LSM6DSL_TAP_SHOCK_TIME_MID_LOW 0x01 00086 #define LSM6DSL_TAP_SHOCK_TIME_MID_HIGH 0x02 00087 #define LSM6DSL_TAP_SHOCK_TIME_HIGH 0x03 /**< Highest value of wake up threshold */ 00088 00089 #define LSM6DSL_TAP_QUIET_TIME_LOW 0x00 /**< Lowest value of wake up threshold */ 00090 #define LSM6DSL_TAP_QUIET_TIME_MID_LOW 0x01 00091 #define LSM6DSL_TAP_QUIET_TIME_MID_HIGH 0x02 00092 #define LSM6DSL_TAP_QUIET_TIME_HIGH 0x03 /**< Highest value of wake up threshold */ 00093 00094 #define LSM6DSL_TAP_DURATION_TIME_LOW 0x00 /**< Lowest value of wake up threshold */ 00095 #define LSM6DSL_TAP_DURATION_TIME_MID_LOW 0x04 00096 #define LSM6DSL_TAP_DURATION_TIME_MID 0x08 00097 #define LSM6DSL_TAP_DURATION_TIME_MID_HIGH 0x0C 00098 #define LSM6DSL_TAP_DURATION_TIME_HIGH 0x0F /**< Highest value of wake up threshold */ 00099 00100 /* Typedefs ------------------------------------------------------------------*/ 00101 00102 typedef enum 00103 { 00104 LSM6DSL_INT1_PIN, 00105 LSM6DSL_INT2_PIN 00106 } LSM6DSL_Interrupt_Pin_t; 00107 00108 typedef struct 00109 { 00110 unsigned int FreeFallStatus : 1; 00111 unsigned int TapStatus : 1; 00112 unsigned int DoubleTapStatus : 1; 00113 unsigned int WakeUpStatus : 1; 00114 unsigned int StepStatus : 1; 00115 unsigned int TiltStatus : 1; 00116 unsigned int D6DOrientationStatus : 1; 00117 } LSM6DSL_Event_Status_t; 00118 00119 /* Class Declaration ---------------------------------------------------------*/ 00120 00121 /** 00122 * Abstract class of an LSM6DSL Inertial Measurement Unit (IMU) 6 axes 00123 * sensor. 00124 */ 00125 class LSM6DSLSensor : public MotionSensor, public GyroSensor 00126 { 00127 public: 00128 LSM6DSLSensor(DevI2C &i2c, PinName INT1_pin, PinName INT2_pin); 00129 LSM6DSLSensor(DevI2C &i2c, PinName INT1_pin, PinName INT2_pin, uint8_t address); 00130 virtual int init(void *init); 00131 virtual int read_id(uint8_t *id); 00132 virtual int get_x_axes(int32_t *pData); 00133 virtual int get_g_axes(int32_t *pData); 00134 virtual int get_x_sensitivity(float *pfData); 00135 virtual int get_g_sensitivity(float *pfData); 00136 virtual int get_x_axes_raw(int16_t *pData); 00137 virtual int get_g_axes_raw(int16_t *pData); 00138 virtual int get_x_odr(float *odr); 00139 virtual int get_g_odr(float *odr); 00140 virtual int set_x_odr(float odr); 00141 virtual int set_g_odr(float odr); 00142 virtual int get_x_fs(float *fullScale); 00143 virtual int get_g_fs(float *fullScale); 00144 virtual int set_x_fs(float fullScale); 00145 virtual int set_g_fs(float fullScale); 00146 int enable_x(void); 00147 int enable_g(void); 00148 int disable_x(void); 00149 int disable_g(void); 00150 int enable_free_fall_detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN); 00151 int disable_free_fall_detection(void); 00152 int set_free_fall_threshold(uint8_t thr); 00153 int enable_pedometer(void); 00154 int disable_pedometer(void); 00155 int get_step_counter(uint16_t *step_count); 00156 int reset_step_counter(void); 00157 int set_pedometer_threshold(uint8_t thr); 00158 int enable_tilt_detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN); 00159 int disable_tilt_detection(void); 00160 int enable_wake_up_detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT2_PIN); 00161 int disable_wake_up_detection(void); 00162 int set_wake_up_threshold(uint8_t thr); 00163 int enable_single_tap_detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN); 00164 int disable_single_tap_detection(void); 00165 int enable_double_tap_detection(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN); 00166 int disable_double_tap_detection(void); 00167 int set_tap_threshold(uint8_t thr); 00168 int set_tap_shock_time(uint8_t time); 00169 int set_tap_quiet_time(uint8_t time); 00170 int set_tap_duration_time(uint8_t time); 00171 int enable_6d_orientation(LSM6DSL_Interrupt_Pin_t pin = LSM6DSL_INT1_PIN); 00172 int disable_6d_orientation(void); 00173 int get_6d_orientation_xl(uint8_t *xl); 00174 int get_6d_orientation_xh(uint8_t *xh); 00175 int get_6d_orientation_yl(uint8_t *yl); 00176 int get_6d_orientation_yh(uint8_t *yh); 00177 int get_6d_orientation_zl(uint8_t *zl); 00178 int get_6d_orientation_zh(uint8_t *zh); 00179 int get_event_status(LSM6DSL_Event_Status_t *status); 00180 int read_reg(uint8_t reg, uint8_t *data); 00181 int write_reg(uint8_t reg, uint8_t data); 00182 00183 /** 00184 * @brief Attaching an interrupt handler to the INT1 interrupt. 00185 * @param fptr An interrupt handler. 00186 * @retval None. 00187 */ 00188 void attach_int1_irq(void (*fptr)(void)) 00189 { 00190 _int1_irq.rise(fptr); 00191 } 00192 00193 /** 00194 * @brief Enabling the INT1 interrupt handling. 00195 * @param None. 00196 * @retval None. 00197 */ 00198 void enable_int1_irq(void) 00199 { 00200 _int1_irq.enable_irq(); 00201 } 00202 00203 /** 00204 * @brief Disabling the INT1 interrupt handling. 00205 * @param None. 00206 * @retval None. 00207 */ 00208 void disable_int1_irq(void) 00209 { 00210 _int1_irq.disable_irq(); 00211 } 00212 00213 /** 00214 * @brief Attaching an interrupt handler to the INT2 interrupt. 00215 * @param fptr An interrupt handler. 00216 * @retval None. 00217 */ 00218 void attach_int2_irq(void (*fptr)(void)) 00219 { 00220 _int2_irq.rise(fptr); 00221 } 00222 00223 /** 00224 * @brief Enabling the INT2 interrupt handling. 00225 * @param None. 00226 * @retval None. 00227 */ 00228 void enable_int2_irq(void) 00229 { 00230 _int2_irq.enable_irq(); 00231 } 00232 00233 /** 00234 * @brief Disabling the INT2 interrupt handling. 00235 * @param None. 00236 * @retval None. 00237 */ 00238 void disable_int2_irq(void) 00239 { 00240 _int2_irq.disable_irq(); 00241 } 00242 00243 /** 00244 * @brief Utility function to read data. 00245 * @param pBuffer: pointer to data to be read. 00246 * @param RegisterAddr: specifies internal address register to be read. 00247 * @param NumByteToRead: number of bytes to be read. 00248 * @retval 0 if ok, an error code otherwise. 00249 */ 00250 uint8_t io_read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead) 00251 { 00252 return (uint8_t) _dev_i2c.i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead); 00253 } 00254 00255 /** 00256 * @brief Utility function to write data. 00257 * @param pBuffer: pointer to data to be written. 00258 * @param RegisterAddr: specifies internal address register to be written. 00259 * @param NumByteToWrite: number of bytes to write. 00260 * @retval 0 if ok, an error code otherwise. 00261 */ 00262 uint8_t io_write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite) 00263 { 00264 return (uint8_t) _dev_i2c.i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite); 00265 } 00266 00267 private: 00268 int set_x_odr_when_enabled(float odr); 00269 int set_g_odr_when_enabled(float odr); 00270 int set_x_odr_when_disabled(float odr); 00271 int set_g_odr_when_disabled(float odr); 00272 00273 /* Helper classes. */ 00274 DevI2C &_dev_i2c; 00275 00276 InterruptIn _int1_irq; 00277 InterruptIn _int2_irq; 00278 00279 /* Configuration */ 00280 uint8_t _address; 00281 00282 uint8_t _x_is_enabled; 00283 float _x_last_odr; 00284 uint8_t _g_is_enabled; 00285 float _g_last_odr; 00286 }; 00287 00288 #ifdef __cplusplus 00289 extern "C" { 00290 #endif 00291 uint8_t LSM6DSL_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ); 00292 uint8_t LSM6DSL_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ); 00293 #ifdef __cplusplus 00294 } 00295 #endif 00296 00297 #endif
Generated on Wed Jul 13 2022 13:21:41 by
1.7.2
