Shih-Ho Hsieh / Mbed 2 deprecated pololu5mag_with_platform

Dependencies:   mbed

Fork of Motor_XYZ_UI_SPI_I2C_5mag by Shih-Ho Hsieh

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers altimu_10_v5.h Source File

altimu_10_v5.h

Go to the documentation of this file.
00001 /**
00002  ******************************************************************************
00003  * @file    altimu_10_v5.h
00004  * @author  AST / EST
00005  * @version V0.0.1
00006  * @date    13-April-2015
00007  * @brief   Header file for class AltIMU_10_v5 representing a AltIMU-10 v5
00008  *          expansion board
00009  ******************************************************************************
00010  * @attention
00011  *
00012  * <h2><center>&copy; COPYRIGHT(c) 2015 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 /* Define to prevent from recursive inclusion --------------------------------*/
00040 #ifndef __ALTIMU_10_V5_H
00041 #define __ALTIMU_10_V5_H
00042 
00043 /* Includes ------------------------------------------------------------------*/
00044 #include "mbed.h"
00045 #include "altimu_10_v5_targets.h"
00046 #include "lis3mdl/lis3mdl_class.h"
00047 #include "lps25h/lps25h_class.h"
00048 #include "lsm6ds33/lsm6ds33_class.h"
00049 #include "DevI2C.h"
00050 
00051 /* Macros -------------------------------------------------------------------*/
00052 #define CALL_METH(obj, meth, param, ret) ((obj == NULL) ?       \
00053                       ((*(param) = (ret)), 0) : \
00054                       ((obj)->meth(param))      \
00055                       )
00056 
00057 /* Classes -------------------------------------------------------------------*/
00058 /** Class AltIMU_10_v5 is intended to represent the MEMS Inertial & Environmental 
00059  *  Nucleo Expansion Board with the same name.
00060  *
00061  *  The expansion board is featuring basically four IPs:\n
00062  *  -# a HTS221 Relative Humidity and Temperature Sensor\n
00063  *  -# a LIS3MDL 3-Axis Magnetometer\n
00064  *  -# a LPS25H MEMS Pressure Sensor (and Temperature Sensor)\n
00065  *  -# and a LSM6DS33 3D Acceleromenter and 3D Gyroscope\n
00066  *
00067  * The expansion board features also a DIL 24-pin socket which makes it possible
00068  * to add further MEMS adapters and other sensors (e.g. UV index). 
00069  *
00070  * It is intentionally implemented as a singleton because only one
00071  * AltIMU_10_v5 at a time might be deployed in a HW component stack.\n
00072  * In order to get the singleton instance you have to call class method `Instance()`, 
00073  * e.g.:
00074  * @code
00075  * // Inertial & Environmental expansion board singleton instance
00076  * static AltIMU_10_v5 *<TODO>_expansion_board = AltIMU_10_v5::Instance();
00077  * @endcode
00078  */
00079 class AltIMU_10_v5
00080 {
00081  protected:
00082     AltIMU_10_v5(DevI2C *ext_i2c, uint8_t SA0=1);
00083 
00084     ~AltIMU_10_v5(void) {
00085         /* should never be called */
00086         error("Trial to delete AltIMU_10_v5 singleton!\n");
00087     }
00088 
00089     /**
00090      * @brief  Initialize the singleton's sensors to default settings
00091      * @retval true if initialization successful, 
00092      * @retval false otherwise
00093      */
00094     bool Init(void) {
00095         return (Init_LIS3MDL() &&
00096             Init_LPS25H() &&
00097             Init_LSM6DS33());
00098     }
00099 
00100     bool Init_LIS3MDL(void);
00101     bool Init_LPS25H(void);
00102     bool Init_LSM6DS33(void);
00103 
00104  public:
00105     static AltIMU_10_v5* Instance(DevI2C *ext_i2c = NULL, uint8_t SA0 = 1);
00106     static AltIMU_10_v5* Instance(PinName sda, PinName scl, uint8_t SA0 = 1);
00107 
00108     DevI2C  *dev_i2c;
00109 
00110     LIS3MDL *magnetometer;
00111     LPS25H  *pt_sensor;
00112 
00113     GyroSensor *GetGyroscope(void) {
00114         return gyro_lsm6ds33;
00115     }
00116     MotionSensor *GetAccelerometer(void) {
00117         return gyro_lsm6ds33;
00118     }
00119     LSM6DS33 *gyro_lsm6ds33;
00120     
00121     
00122     void setI2cFrequency(int hz){ dev_i2c->frequency(hz); }
00123 
00124  private:
00125     static AltIMU_10_v5 *_instance0;
00126     static AltIMU_10_v5 *_instance1;
00127 };
00128 
00129 #endif /* __ALTIMU_10_V5_H */