Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
lsm6ds33_class.h
00001 /** 00002 ****************************************************************************** 00003 * @file lsm6ds3_class.h 00004 * @author AST / EST 00005 * @version V0.0.1 00006 * @date 14-April-2015 00007 * @brief Header file for component LSM6DS33 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2015 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 #ifndef __LSM6DS33_CLASS_H 00039 #define __LSM6DS33_CLASS_H 00040 00041 /* Includes ------------------------------------------------------------------*/ 00042 #include "mbed.h" 00043 #include "DevI2C.h" 00044 #include "lsm6ds33.h" 00045 #include "GyroSensor.h" 00046 #include "MotionSensor.h" 00047 00048 /* Classes -------------------------------------------------------------------*/ 00049 /** Class representing a LSM6DS33 sensor component 00050 */ 00051 class LSM6DS33 : public GyroSensor, public MotionSensor { 00052 public: 00053 /** Constructor 00054 * @param[in] i2c device I2C to be used for communication 00055 * @param[in] irq_pin pin name for free fall detection interrupt 00056 */ 00057 LSM6DS33(DevI2C &i2c) : GyroSensor(), MotionSensor(), dev_i2c(i2c){ } 00058 00059 /** Destructor 00060 */ 00061 virtual ~LSM6DS33() {} 00062 00063 /*** Interface Methods ***/ 00064 virtual int init(void *init_struct) { 00065 return LSM6DS33_Init((IMU_6AXES_InitTypeDef*)init_struct); 00066 } 00067 00068 virtual int read_id(uint8_t *xg_id) { 00069 return LSM6DS33_Read_XG_ID(xg_id); 00070 } 00071 00072 virtual int get_x_axes(int32_t *pData) { 00073 return LSM6DS33_X_GetAxes(pData); 00074 } 00075 00076 virtual int get_x_axes_raw(int16_t *pData) { 00077 return LSM6DS33_X_GetAxesRaw(pData); 00078 } 00079 00080 virtual int get_g_axes(int32_t *pData) { 00081 return LSM6DS33_G_GetAxes(pData); 00082 } 00083 00084 virtual int get_g_axes_raw(int16_t *pData) { 00085 return LSM6DS33_G_GetAxesRaw(pData); 00086 } 00087 00088 virtual int get_x_odr(float *odr) { 00089 return LSM6DS33_X_Get_ODR(odr); 00090 } 00091 00092 virtual int set_x_odr(float odr) { 00093 return LSM6DS33_X_Set_ODR(odr); 00094 } 00095 00096 virtual int get_x_sensitivity(float *pfData) { 00097 return LSM6DS33_X_GetSensitivity(pfData); 00098 } 00099 00100 virtual int get_x_fs(float *fullScale) { 00101 return LSM6DS33_X_Get_FS(fullScale); 00102 } 00103 00104 virtual int set_x_fs(float fullScale) { 00105 return LSM6DS33_X_Set_FS(fullScale); 00106 } 00107 00108 virtual int get_g_odr(float *odr) { 00109 return LSM6DS33_G_Get_ODR(odr); 00110 } 00111 00112 virtual int set_g_odr(float odr) { 00113 return LSM6DS33_G_Set_ODR(odr); 00114 } 00115 00116 virtual int get_g_sensitivity(float *pfData) { 00117 return LSM6DS33_G_GetSensitivity(pfData); 00118 } 00119 00120 virtual int get_g_fs(float *fullScale) { 00121 return LSM6DS33_G_Get_FS(fullScale); 00122 } 00123 00124 virtual int set_g_fs(float fullScale) { 00125 return LSM6DS33_G_Set_FS(fullScale); 00126 } 00127 00128 protected: 00129 /*** Methods ***/ 00130 IMU_6AXES_StatusTypeDef LSM6DS33_Init(IMU_6AXES_InitTypeDef *LSM6DS33_Init); 00131 IMU_6AXES_StatusTypeDef LSM6DS33_Read_XG_ID(uint8_t *xg_id); 00132 IMU_6AXES_StatusTypeDef LSM6DS33_X_GetAxes(int32_t *pData); 00133 IMU_6AXES_StatusTypeDef LSM6DS33_X_GetAxesRaw(int16_t *pData); 00134 IMU_6AXES_StatusTypeDef LSM6DS33_G_GetAxes(int32_t *pData); 00135 IMU_6AXES_StatusTypeDef LSM6DS33_G_GetAxesRaw(int16_t *pData); 00136 IMU_6AXES_StatusTypeDef LSM6DS33_X_Get_ODR( float *odr ); 00137 IMU_6AXES_StatusTypeDef LSM6DS33_X_Set_ODR( float odr ); 00138 IMU_6AXES_StatusTypeDef LSM6DS33_X_GetSensitivity( float *pfData ); 00139 IMU_6AXES_StatusTypeDef LSM6DS33_X_Get_FS( float *fullScale ); 00140 IMU_6AXES_StatusTypeDef LSM6DS33_X_Set_FS( float fullScale ); 00141 IMU_6AXES_StatusTypeDef LSM6DS33_G_Get_ODR( float *odr ); 00142 IMU_6AXES_StatusTypeDef LSM6DS33_G_Set_ODR( float odr ); 00143 IMU_6AXES_StatusTypeDef LSM6DS33_G_GetSensitivity( float *pfData ); 00144 IMU_6AXES_StatusTypeDef LSM6DS33_G_Get_FS( float *fullScale ); 00145 IMU_6AXES_StatusTypeDef LSM6DS33_G_Set_FS( float fullScale ); 00146 IMU_6AXES_StatusTypeDef LSM6DS33_Common_Sensor_Enable(void); 00147 IMU_6AXES_StatusTypeDef LSM6DS33_X_Set_Axes_Status(uint8_t enableX, uint8_t enableY, uint8_t enableZ); 00148 IMU_6AXES_StatusTypeDef LSM6DS33_G_Set_Axes_Status(uint8_t enableX, uint8_t enableY, uint8_t enableZ); 00149 00150 /** 00151 * @brief Configures LSM6DS33 interrupt lines for NUCLEO boards 00152 */ 00153 void LSM6DS33_IO_ITConfig(void) 00154 { 00155 } 00156 00157 /** 00158 * @brief Configures LSM6DS33 I2C interface 00159 * @return IMU_6AXES_OK in case of success, an error code otherwise 00160 */ 00161 IMU_6AXES_StatusTypeDef LSM6DS33_IO_Init(void) 00162 { 00163 return IMU_6AXES_OK; /* done in constructor */ 00164 } 00165 00166 /** 00167 * @brief Utility function to read data from LSM6DS33 00168 * @param[out] pBuffer pointer to the byte-array to read data in to 00169 * @param[in] RegisterAddr specifies internal address register to read from. 00170 * @param[in] NumByteToRead number of bytes to be read. 00171 * @retval IMU_6AXES_OK if ok, 00172 * @retval IMU_6AXES_ERROR if an I2C error has occured 00173 */ 00174 IMU_6AXES_StatusTypeDef LSM6DS33_IO_Read(uint8_t* pBuffer, 00175 uint8_t RegisterAddr, uint16_t NumByteToRead) 00176 { 00177 int ret = dev_i2c.i2c_read(pBuffer, 00178 LSM6DS33_XG_MEMS_ADDRESS, 00179 RegisterAddr, 00180 NumByteToRead); 00181 if(ret != 0) { 00182 return IMU_6AXES_ERROR; 00183 } 00184 return IMU_6AXES_OK; 00185 } 00186 00187 /** 00188 * @brief Utility function to write data to LSM6DS33 00189 * @param[in] pBuffer pointer to the byte-array data to send 00190 * @param[in] RegisterAddr specifies internal address register to read from. 00191 * @param[in] NumByteToWrite number of bytes to write. 00192 * @retval IMU_6AXES_OK if ok, 00193 * @retval IMU_6AXES_ERROR if an I2C error has occured 00194 */ 00195 IMU_6AXES_StatusTypeDef LSM6DS33_IO_Write(uint8_t* pBuffer, 00196 uint8_t RegisterAddr, uint16_t NumByteToWrite) 00197 { 00198 int ret = dev_i2c.i2c_write(pBuffer, 00199 LSM6DS33_XG_MEMS_ADDRESS, 00200 RegisterAddr, 00201 NumByteToWrite); 00202 if(ret != 0) { 00203 return IMU_6AXES_ERROR; 00204 } 00205 return IMU_6AXES_OK; 00206 } 00207 00208 /*** Instance Variables ***/ 00209 /* IO Device */ 00210 DevI2C &dev_i2c; 00211 00212 }; 00213 00214 #endif // __LSM6DS33_CLASS_H
Generated on Tue Jul 12 2022 17:26:53 by
1.7.2