Firmware Library for X-NUCLEO-IKS01A1 (MEMS Inertial & Environmental Sensors) Expansion Board

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   MultiTech_Dragonfly_2015_ATT_Gov_Solutions_Hackathon_Example HelloWorld_IKS01A1 LoRaWAN-test-10secs ServoMotorDemo ... more

Fork of X_NUCLEO_IKS01A1 by ST Expansion SW Team

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers lsm6ds0_class.h Source File

lsm6ds0_class.h

Go to the documentation of this file.
00001 /**
00002  ******************************************************************************
00003  * @file    lsm6ds0_class.h
00004  * @author  AST / EST
00005  * @version V0.0.1
00006  * @date    14-April-2015
00007  * @brief   Header file for component LSM6DS0
00008  ******************************************************************************
00009  * @attention
00010  *
00011  * <h2><center>&copy; 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 __LSM6DS0_CLASS_H
00039 #define __LSM6DS0_CLASS_H
00040 
00041 /* Includes ------------------------------------------------------------------*/
00042 #include "mbed.h"
00043 #include "DevI2C.h"
00044 #include "lsm6ds0.h"
00045 #include "GyroSensor.h"
00046 #include "MotionSensor.h"
00047 
00048 /* Classes -------------------------------------------------------------------*/
00049 /** Class representing a LSM6DS0 sensor component
00050  */
00051 class LSM6DS0 : public GyroSensor, public MotionSensor {
00052  public:
00053     /** Constructor
00054      * @param[in] i2c device I2C to be used for communication
00055      */
00056         LSM6DS0(DevI2C &i2c) : GyroSensor(), MotionSensor(), dev_i2c(i2c) {
00057     }
00058     
00059     /** Destructor
00060      */
00061         virtual ~LSM6DS0() {}
00062     
00063     /*** Interface Methods ***/
00064     virtual int init(void *init_struct) {
00065         return LSM6DS0_Init((IMU_6AXES_InitTypeDef*)init_struct);
00066     }
00067 
00068     virtual int read_id(uint8_t *xg_id) {
00069         return LSM6DS0_Read_XG_ID(xg_id);
00070     }
00071 
00072     virtual int get_x_axes(int32_t *pData) {
00073         return LSM6DS0_X_GetAxes(pData);
00074     }
00075 
00076     virtual int get_x_axes_raw(int16_t *pData) {
00077         return LSM6DS0_X_GetAxesRaw(pData);
00078     }
00079 
00080     virtual int get_g_axes(int32_t *pData) {
00081         return LSM6DS0_G_GetAxes(pData);
00082     }
00083 
00084     virtual int get_g_axes_raw(int16_t *pData) {
00085         return LSM6DS0_G_GetAxesRaw(pData);
00086     }
00087 
00088     virtual int get_x_odr(float *odr) {
00089         return LSM6DS0_X_Get_ODR(odr);
00090     }
00091 
00092     virtual int set_x_odr(float odr) {
00093         return LSM6DS0_X_Set_ODR(odr);
00094     }
00095 
00096     virtual int get_x_sensitivity(float *pfData) {
00097         return LSM6DS0_X_GetSensitivity(pfData);
00098     }
00099 
00100     virtual int get_x_fs(float *fullScale) {
00101         return LSM6DS0_X_Get_FS(fullScale);
00102     }
00103 
00104     virtual int set_x_fs(float fullScale) {
00105         return LSM6DS0_X_Set_FS(fullScale);
00106     }
00107 
00108     virtual int get_g_odr(float *odr) {
00109         return LSM6DS0_G_Get_ODR(odr);
00110     }
00111 
00112     virtual int set_g_odr(float odr) {
00113         return LSM6DS0_G_Set_ODR(odr);
00114     }
00115 
00116     virtual int get_g_sensitivity(float *pfData) {
00117         return LSM6DS0_G_GetSensitivity(pfData);
00118     }
00119 
00120     virtual int get_g_fs(float *fullScale) {
00121         return LSM6DS0_G_Get_FS(fullScale);
00122     }
00123 
00124     virtual int set_g_fs(float fullScale) {
00125         return LSM6DS0_G_Set_FS(fullScale);
00126     }
00127 
00128  protected:
00129     /*** Methods ***/
00130     IMU_6AXES_StatusTypeDef LSM6DS0_Init(IMU_6AXES_InitTypeDef *LSM6DS0_Init);
00131     IMU_6AXES_StatusTypeDef LSM6DS0_Read_XG_ID(uint8_t *xg_id);
00132     IMU_6AXES_StatusTypeDef LSM6DS0_X_GetAxes(int32_t *pData);
00133     IMU_6AXES_StatusTypeDef LSM6DS0_X_GetAxesRaw(int16_t *pData);
00134     IMU_6AXES_StatusTypeDef LSM6DS0_G_GetAxes(int32_t *pData);
00135     IMU_6AXES_StatusTypeDef LSM6DS0_G_GetAxesRaw(int16_t *pData);
00136     IMU_6AXES_StatusTypeDef LSM6DS0_X_Get_ODR( float *odr );
00137     IMU_6AXES_StatusTypeDef LSM6DS0_X_Set_ODR( float odr );
00138     IMU_6AXES_StatusTypeDef LSM6DS0_X_GetSensitivity( float *pfData );
00139     IMU_6AXES_StatusTypeDef LSM6DS0_X_Get_FS( float *fullScale );
00140     IMU_6AXES_StatusTypeDef LSM6DS0_X_Set_FS( float fullScale );
00141     IMU_6AXES_StatusTypeDef LSM6DS0_G_Get_ODR( float *odr );
00142     IMU_6AXES_StatusTypeDef LSM6DS0_G_Set_ODR( float odr );
00143     IMU_6AXES_StatusTypeDef LSM6DS0_G_GetSensitivity( float *pfData );
00144     IMU_6AXES_StatusTypeDef LSM6DS0_G_Get_FS( float *fullScale );
00145     IMU_6AXES_StatusTypeDef LSM6DS0_G_Set_FS( float fullScale );
00146 
00147     IMU_6AXES_StatusTypeDef LSM6DS0_X_Set_Axes_Status(uint8_t enableX, uint8_t enableY, uint8_t enableZ);
00148     IMU_6AXES_StatusTypeDef LSM6DS0_G_Set_Axes_Status(uint8_t enableX, uint8_t enableY, uint8_t enableZ);
00149 
00150     /**
00151      * @brief  Configures LSM6DS0 interrupt lines for NUCLEO boards
00152      */
00153     void LSM6DS0_IO_ITConfig(void)
00154     {
00155         /* To be implemented */
00156     }
00157 
00158     /**
00159      * @brief  Configures LSM6DS0 I2C interface
00160      * @return IMU_6AXES_OK in case of success, an error code otherwise
00161      */
00162     IMU_6AXES_StatusTypeDef LSM6DS0_IO_Init(void)
00163     {
00164         return IMU_6AXES_OK; /* done in constructor */
00165     }
00166 
00167     /**
00168      * @brief      Utility function to read data from LSM6DS0
00169      * @param[out] pBuffer pointer to the byte-array to read data in to
00170      * @param[in]  RegisterAddr specifies internal address register to read from.
00171      * @param[in]  NumByteToRead number of bytes to be read.
00172      * @retval     IMU_6AXES_OK if ok, 
00173      * @retval     IMU_6AXES_ERROR if an I2C error has occured
00174      */
00175     IMU_6AXES_StatusTypeDef LSM6DS0_IO_Read(uint8_t* pBuffer, 
00176                           uint8_t RegisterAddr, uint16_t NumByteToRead)
00177     {
00178         int ret = dev_i2c.i2c_read(pBuffer,
00179                        LSM6DS0_XG_MEMS_ADDRESS,
00180                        RegisterAddr,
00181                        NumByteToRead);
00182         if(ret != 0) {
00183             return IMU_6AXES_ERROR;
00184         }
00185         return IMU_6AXES_OK;
00186     }
00187     
00188     /**
00189      * @brief      Utility function to write data to LSM6DS0
00190      * @param[in]  pBuffer pointer to the byte-array data to send
00191      * @param[in]  RegisterAddr specifies internal address register to read from.
00192      * @param[in]  NumByteToWrite number of bytes to write.
00193      * @retval     IMU_6AXES_OK if ok, 
00194      * @retval     IMU_6AXES_ERROR if an I2C error has occured
00195      */
00196     IMU_6AXES_StatusTypeDef LSM6DS0_IO_Write(uint8_t* pBuffer, 
00197                            uint8_t RegisterAddr, uint16_t NumByteToWrite)
00198     {
00199         int ret = dev_i2c.i2c_write(pBuffer,
00200                         LSM6DS0_XG_MEMS_ADDRESS,
00201                         RegisterAddr,
00202                         NumByteToWrite);
00203         if(ret != 0) {
00204             return IMU_6AXES_ERROR;
00205         }
00206         return IMU_6AXES_OK;
00207     }
00208     
00209     /*** Instance Variables ***/
00210     /* IO Device */
00211     DevI2C &dev_i2c;
00212 };
00213 
00214 #endif // __LSM6DS0_CLASS_H