Beta
Dependencies: ST_INTERFACES X_NUCLEO_COMMON
Fork of X_NUCLEO_IKS01A2 by
LSM303AGRAccSensor.h
00001 /** 00002 ****************************************************************************** 00003 * @file LSM303AGRAccSensor.h 00004 * @author CLab 00005 * @version V1.0.0 00006 * @date 5 August 2016 00007 * @brief Abstract Class of an LSM303AGR accelerometer sensor. 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * 1. Redistributions of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00021 * may be used to endorse or promote products derived from this software 00022 * without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00028 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00029 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 ****************************************************************************** 00036 */ 00037 00038 00039 /* Prevent recursive inclusion -----------------------------------------------*/ 00040 00041 #ifndef __LSM303AGRAccSensor_H__ 00042 #define __LSM303AGRAccSensor_H__ 00043 00044 00045 /* Includes ------------------------------------------------------------------*/ 00046 00047 #include "DevI2C.h" 00048 #include "LSM303AGR_acc_driver.h" 00049 #include "MotionSensor.h" 00050 00051 /* Defines -------------------------------------------------------------------*/ 00052 #define LSM303AGR_ACC_SENSITIVITY_FOR_FS_2G_NORMAL_MODE 3.900f /**< Sensitivity value for 2 g full scale and normal mode [mg/LSB] */ 00053 #define LSM303AGR_ACC_SENSITIVITY_FOR_FS_2G_HIGH_RESOLUTION_MODE 0.980f /**< Sensitivity value for 2 g full scale and high resolution mode [mg/LSB] */ 00054 #define LSM303AGR_ACC_SENSITIVITY_FOR_FS_2G_LOW_POWER_MODE 15.630f /**< Sensitivity value for 2 g full scale and low power mode [mg/LSB] */ 00055 #define LSM303AGR_ACC_SENSITIVITY_FOR_FS_4G_NORMAL_MODE 7.820f /**< Sensitivity value for 4 g full scale and normal mode [mg/LSB] */ 00056 #define LSM303AGR_ACC_SENSITIVITY_FOR_FS_4G_HIGH_RESOLUTION_MODE 1.950f /**< Sensitivity value for 4 g full scale and high resolution mode [mg/LSB] */ 00057 #define LSM303AGR_ACC_SENSITIVITY_FOR_FS_4G_LOW_POWER_MODE 31.260f /**< Sensitivity value for 4 g full scale and low power mode [mg/LSB] */ 00058 #define LSM303AGR_ACC_SENSITIVITY_FOR_FS_8G_NORMAL_MODE 15.630f /**< Sensitivity value for 8 g full scale and normal mode [mg/LSB] */ 00059 #define LSM303AGR_ACC_SENSITIVITY_FOR_FS_8G_HIGH_RESOLUTION_MODE 3.900f /**< Sensitivity value for 8 g full scale and high resolution mode [mg/LSB] */ 00060 #define LSM303AGR_ACC_SENSITIVITY_FOR_FS_8G_LOW_POWER_MODE 62.520f /**< Sensitivity value for 8 g full scale and low power mode [mg/LSB] */ 00061 #define LSM303AGR_ACC_SENSITIVITY_FOR_FS_16G_NORMAL_MODE 46.900f /**< Sensitivity value for 16 g full scale and normal mode [mg/LSB] */ 00062 #define LSM303AGR_ACC_SENSITIVITY_FOR_FS_16G_HIGH_RESOLUTION_MODE 11.720f /**< Sensitivity value for 16 g full scale and high resolution mode [mg/LSB] */ 00063 #define LSM303AGR_ACC_SENSITIVITY_FOR_FS_16G_LOW_POWER_MODE 187.580f /**< Sensitivity value for 16 g full scale and low power mode [mg/LSB] */ 00064 00065 /* Class Declaration ---------------------------------------------------------*/ 00066 00067 /** 00068 * Abstract class of an LSM303AGR Inertial Measurement Unit (IMU) 6 axes 00069 * sensor. 00070 */ 00071 class LSM303AGRAccSensor : public MotionSensor 00072 { 00073 public: 00074 LSM303AGRAccSensor(DevI2C &i2c); 00075 LSM303AGRAccSensor(DevI2C &i2c, uint8_t address); 00076 virtual int init(void *init); 00077 virtual int read_id(uint8_t *id); 00078 virtual int get_x_axes(int32_t *pData); 00079 virtual int get_x_axes_raw(int16_t *pData); 00080 virtual int get_x_sensitivity(float *pfData); 00081 virtual int get_x_odr(float *odr); 00082 virtual int set_x_odr(float odr); 00083 virtual int get_x_fs(float *fullScale); 00084 virtual int set_x_fs(float fullScale); 00085 int enable(void); 00086 int disable(void); 00087 int read_reg(uint8_t reg, uint8_t *data); 00088 int write_reg(uint8_t reg, uint8_t data); 00089 00090 /** 00091 * @brief Utility function to read data. 00092 * @param pBuffer: pointer to data to be read. 00093 * @param RegisterAddr: specifies internal address register to be read. 00094 * @param NumByteToRead: number of bytes to be read. 00095 * @retval 0 if ok, an error code otherwise. 00096 */ 00097 uint8_t io_read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead) 00098 { 00099 return (uint8_t) _dev_i2c.i2c_read(pBuffer, _address, RegisterAddr, NumByteToRead); 00100 } 00101 00102 /** 00103 * @brief Utility function to write data. 00104 * @param pBuffer: pointer to data to be written. 00105 * @param RegisterAddr: specifies internal address register to be written. 00106 * @param NumByteToWrite: number of bytes to write. 00107 * @retval 0 if ok, an error code otherwise. 00108 */ 00109 uint8_t io_write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite) 00110 { 00111 return (uint8_t) _dev_i2c.i2c_write(pBuffer, _address, RegisterAddr, NumByteToWrite); 00112 } 00113 00114 private: 00115 int set_x_odr_when_enabled(float odr); 00116 int set_x_odr_when_disabled(float odr); 00117 int get_x_sensitivity_normal_mode(float *sensitivity ); 00118 int get_x_sensitivity_lp_mode(float *sensitivity ); 00119 int get_x_sensitivity_hr_mode(float *sensitivity ); 00120 00121 /* Helper classes. */ 00122 DevI2C &_dev_i2c; 00123 00124 /* Configuration */ 00125 uint8_t _address; 00126 00127 uint8_t _is_enabled; 00128 float _last_odr; 00129 }; 00130 00131 #ifdef __cplusplus 00132 extern "C" { 00133 #endif 00134 uint8_t LSM303AGR_ACC_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ); 00135 uint8_t LSM303AGR_ACC_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ); 00136 #ifdef __cplusplus 00137 } 00138 #endif 00139 00140 #endif
Generated on Wed Jul 13 2022 13:21:41 by
1.7.2
