Dependencies:   X_NUCLEO_COMMON

Dependents:   Giroscopio_main

Fork of X_NUCLEO_IKS01A1-f2df by Ant Robinson

Committer:
Salvatore94
Date:
Thu Feb 09 16:40:33 2017 +0000
Revision:
1:7f97780b8ad4
Parent:
0:5a49275457c6
Per peppe;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
antseggs 0:5a49275457c6 1 /**
antseggs 0:5a49275457c6 2 ******************************************************************************
antseggs 0:5a49275457c6 3 * @file x_nucleo_iks01a1.h
antseggs 0:5a49275457c6 4 * @author AST / EST
antseggs 0:5a49275457c6 5 * @version V0.0.1
antseggs 0:5a49275457c6 6 * @date 13-April-2015
antseggs 0:5a49275457c6 7 * @brief Header file for class X_NUCLEO_IKS01A1 representing a X-NUCLEO-IKS01A1
antseggs 0:5a49275457c6 8 * expansion board
antseggs 0:5a49275457c6 9 ******************************************************************************
antseggs 0:5a49275457c6 10 * @attention
antseggs 0:5a49275457c6 11 *
antseggs 0:5a49275457c6 12 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
antseggs 0:5a49275457c6 13 *
antseggs 0:5a49275457c6 14 * Redistribution and use in source and binary forms, with or without modification,
antseggs 0:5a49275457c6 15 * are permitted provided that the following conditions are met:
antseggs 0:5a49275457c6 16 * 1. Redistributions of source code must retain the above copyright notice,
antseggs 0:5a49275457c6 17 * this list of conditions and the following disclaimer.
antseggs 0:5a49275457c6 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
antseggs 0:5a49275457c6 19 * this list of conditions and the following disclaimer in the documentation
antseggs 0:5a49275457c6 20 * and/or other materials provided with the distribution.
antseggs 0:5a49275457c6 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
antseggs 0:5a49275457c6 22 * may be used to endorse or promote products derived from this software
antseggs 0:5a49275457c6 23 * without specific prior written permission.
antseggs 0:5a49275457c6 24 *
antseggs 0:5a49275457c6 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
antseggs 0:5a49275457c6 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
antseggs 0:5a49275457c6 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
antseggs 0:5a49275457c6 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
antseggs 0:5a49275457c6 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
antseggs 0:5a49275457c6 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
antseggs 0:5a49275457c6 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
antseggs 0:5a49275457c6 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
antseggs 0:5a49275457c6 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
antseggs 0:5a49275457c6 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
antseggs 0:5a49275457c6 35 *
antseggs 0:5a49275457c6 36 ******************************************************************************
antseggs 0:5a49275457c6 37 */
antseggs 0:5a49275457c6 38
antseggs 0:5a49275457c6 39 /* Define to prevent from recursive inclusion --------------------------------*/
antseggs 0:5a49275457c6 40 #ifndef __X_NUCLEO_IKS01A1_H
antseggs 0:5a49275457c6 41 #define __X_NUCLEO_IKS01A1_H
antseggs 0:5a49275457c6 42
antseggs 0:5a49275457c6 43 /* Includes ------------------------------------------------------------------*/
antseggs 0:5a49275457c6 44 #include "mbed.h"
antseggs 0:5a49275457c6 45 #include "x_nucleo_iks01a1_targets.h"
antseggs 0:5a49275457c6 46 #include "hts221/hts221_class.h"
antseggs 0:5a49275457c6 47 #include "lis3mdl/lis3mdl_class.h"
antseggs 0:5a49275457c6 48 #include "lps25h/lps25h_class.h"
antseggs 0:5a49275457c6 49 #include "lsm6ds0/lsm6ds0_class.h"
antseggs 0:5a49275457c6 50 #include "lsm6ds3/lsm6ds3_class.h"
antseggs 0:5a49275457c6 51 #include "DevI2C.h"
antseggs 0:5a49275457c6 52
antseggs 0:5a49275457c6 53 /* Macros -------------------------------------------------------------------*/
antseggs 0:5a49275457c6 54 #define CALL_METH(obj, meth, param, ret) ((obj == NULL) ? \
antseggs 0:5a49275457c6 55 ((*(param) = (ret)), 0) : \
antseggs 0:5a49275457c6 56 ((obj)->meth(param)) \
antseggs 0:5a49275457c6 57 )
antseggs 0:5a49275457c6 58
antseggs 0:5a49275457c6 59 /* Classes -------------------------------------------------------------------*/
antseggs 0:5a49275457c6 60 /** Class X_NUCLEO_IKS01A1 is intended to represent the MEMS Inertial & Environmental
antseggs 0:5a49275457c6 61 * Nucleo Expansion Board with the same name.
antseggs 0:5a49275457c6 62 *
antseggs 0:5a49275457c6 63 * The expansion board is featuring basically four IPs:\n
antseggs 0:5a49275457c6 64 * -# a HTS221 Relative Humidity and Temperature Sensor\n
antseggs 0:5a49275457c6 65 * -# a LIS3MDL 3-Axis Magnetometer\n
antseggs 0:5a49275457c6 66 * -# a LPS25H MEMS Pressure Sensor (and Temperature Sensor)\n
antseggs 0:5a49275457c6 67 * -# and a LSM6DS0 3D Acceleromenter and 3D Gyroscope\n
antseggs 0:5a49275457c6 68 *
antseggs 0:5a49275457c6 69 * The expansion board features also a DIL 24-pin socket which makes it possible
antseggs 0:5a49275457c6 70 * to add further MEMS adapters and other sensors (e.g. UV index).
antseggs 0:5a49275457c6 71 *
antseggs 0:5a49275457c6 72 * It is intentionally implemented as a singleton because only one
antseggs 0:5a49275457c6 73 * X_NUCLEO_IKS01A1 at a time might be deployed in a HW component stack.\n
antseggs 0:5a49275457c6 74 * In order to get the singleton instance you have to call class method `Instance()`,
antseggs 0:5a49275457c6 75 * e.g.:
antseggs 0:5a49275457c6 76 * @code
antseggs 0:5a49275457c6 77 * // Inertial & Environmental expansion board singleton instance
antseggs 0:5a49275457c6 78 * static X_NUCLEO_IKS01A1 *<TODO>_expansion_board = X_NUCLEO_IKS01A1::Instance();
antseggs 0:5a49275457c6 79 * @endcode
antseggs 0:5a49275457c6 80 */
antseggs 0:5a49275457c6 81 class X_NUCLEO_IKS01A1
antseggs 0:5a49275457c6 82 {
antseggs 0:5a49275457c6 83 protected:
antseggs 0:5a49275457c6 84 X_NUCLEO_IKS01A1(DevI2C *ext_i2c, PinName ff_irq_pin);
antseggs 0:5a49275457c6 85
antseggs 0:5a49275457c6 86 /**
antseggs 0:5a49275457c6 87 * @brief Initialize the singleton's sensors to default settings
antseggs 0:5a49275457c6 88 * @retval true if initialization successful,
antseggs 0:5a49275457c6 89 * @retval false otherwise
antseggs 0:5a49275457c6 90 */
antseggs 0:5a49275457c6 91 bool Init(void) {
antseggs 0:5a49275457c6 92 return (Init_HTS221() &&
antseggs 0:5a49275457c6 93 Init_LIS3MDL() &&
antseggs 0:5a49275457c6 94 Init_LPS25H() &&
antseggs 0:5a49275457c6 95 Init_Gyro());
antseggs 0:5a49275457c6 96 }
antseggs 0:5a49275457c6 97
antseggs 0:5a49275457c6 98 /**
antseggs 0:5a49275457c6 99 * @brief Initialize the singleton's gyroscope
antseggs 0:5a49275457c6 100 * @retval true if initialization successful,
antseggs 0:5a49275457c6 101 * @retval false otherwise
antseggs 0:5a49275457c6 102 * @note only one sensor among LSM6DS3 & LSM6DS0 will be instantiated
antseggs 0:5a49275457c6 103 * with a preference on LSM6DS3 when available
antseggs 0:5a49275457c6 104 */
antseggs 0:5a49275457c6 105 bool Init_Gyro(void) {
antseggs 0:5a49275457c6 106 // Note: order is important!
antseggs 0:5a49275457c6 107 return (Init_LSM6DS3() &&
antseggs 0:5a49275457c6 108 Init_LSM6DS0());
antseggs 0:5a49275457c6 109 }
antseggs 0:5a49275457c6 110
antseggs 0:5a49275457c6 111 bool Init_HTS221(void);
antseggs 0:5a49275457c6 112 bool Init_LIS3MDL(void);
antseggs 0:5a49275457c6 113 bool Init_LPS25H(void);
antseggs 0:5a49275457c6 114 bool Init_LSM6DS0(void);
antseggs 0:5a49275457c6 115 bool Init_LSM6DS3(void);
antseggs 0:5a49275457c6 116
antseggs 0:5a49275457c6 117 public:
antseggs 0:5a49275457c6 118 static X_NUCLEO_IKS01A1* Instance(DevI2C *ext_i2c = NULL,
antseggs 0:5a49275457c6 119 PinName ff_irq_pin = IKS01A1_PIN_FF);
antseggs 0:5a49275457c6 120 static X_NUCLEO_IKS01A1* Instance(PinName sda, PinName scl, PinName ff_irq_pin = NC);
antseggs 0:5a49275457c6 121
antseggs 0:5a49275457c6 122 DevI2C *dev_i2c;
antseggs 0:5a49275457c6 123
antseggs 0:5a49275457c6 124 HTS221 *ht_sensor;
antseggs 0:5a49275457c6 125 LIS3MDL *magnetometer;
antseggs 0:5a49275457c6 126 LPS25H *pt_sensor;
antseggs 0:5a49275457c6 127
antseggs 0:5a49275457c6 128 GyroSensor *GetGyroscope(void) {
antseggs 0:5a49275457c6 129 return ((gyro_lsm6ds3 == NULL) ?
antseggs 0:5a49275457c6 130 (GyroSensor*)gyro_lsm6ds0 : (GyroSensor*)gyro_lsm6ds3);
antseggs 0:5a49275457c6 131 }
antseggs 0:5a49275457c6 132 MotionSensor *GetAccelerometer(void) {
antseggs 0:5a49275457c6 133 return ((gyro_lsm6ds3 == NULL) ?
antseggs 0:5a49275457c6 134 (MotionSensor*)gyro_lsm6ds0 : (MotionSensor*)gyro_lsm6ds3);
antseggs 0:5a49275457c6 135 }
antseggs 0:5a49275457c6 136 LSM6DS0 *gyro_lsm6ds0;
antseggs 0:5a49275457c6 137 LSM6DS3 *gyro_lsm6ds3;
antseggs 0:5a49275457c6 138
antseggs 0:5a49275457c6 139 private:
antseggs 0:5a49275457c6 140 static X_NUCLEO_IKS01A1 *_instance;
antseggs 0:5a49275457c6 141 };
antseggs 0:5a49275457c6 142
antseggs 0:5a49275457c6 143 #endif /* __X_NUCLEO_IKS01A1_H */