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.
Fork of X_NUCLEO_IKS01A1 by
x_nucleo_iks01a1.h
00001 /** 00002 ****************************************************************************** 00003 * @file x_nucleo_iks01a1.h 00004 * @author AST / EST 00005 * @version V0.0.1 00006 * @date 13-April-2015 00007 * @brief Header file for class X_NUCLEO_IKS01A1 representing a X-NUCLEO-IKS01A1 00008 * expansion board 00009 ****************************************************************************** 00010 * @attention 00011 * 00012 * <h2><center>© 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 __X_NUCLEO_IKS01A1_H 00041 #define __X_NUCLEO_IKS01A1_H 00042 00043 /* Includes ------------------------------------------------------------------*/ 00044 #include "mbed.h" 00045 #include "x_nucleo_iks01a1_targets.h" 00046 #include "hts221/hts221_class.h" 00047 #include "lis3mdl/lis3mdl_class.h" 00048 #include "lps25h/lps25h_class.h" 00049 #include "lsm6ds0/lsm6ds0_class.h" 00050 #include "lsm6ds3/lsm6ds3_class.h" 00051 #include "DevI2C.h" 00052 00053 /* Macros -------------------------------------------------------------------*/ 00054 #define CALL_METH(obj, meth, param, ret) ((obj == NULL) ? \ 00055 ((*(param) = (ret)), 0) : \ 00056 ((obj)->meth(param)) \ 00057 ) 00058 00059 /* Classes -------------------------------------------------------------------*/ 00060 /** Class X_NUCLEO_IKS01A1 is intended to represent the MEMS Inertial & Environmental 00061 * Nucleo Expansion Board with the same name. 00062 * 00063 * The expansion board is featuring basically four IPs:\n 00064 * -# a HTS221 Relative Humidity and Temperature Sensor\n 00065 * -# a LIS3MDL 3-Axis Magnetometer\n 00066 * -# a LPS25H MEMS Pressure Sensor (and Temperature Sensor)\n 00067 * -# and a LSM6DS0 3D Acceleromenter and 3D Gyroscope\n 00068 * 00069 * The expansion board features also a DIL 24-pin socket which makes it possible 00070 * to add further MEMS adapters and other sensors (e.g. UV index). 00071 * 00072 * It is intentionally implemented as a singleton because only one 00073 * X_NUCLEO_IKS01A1 at a time might be deployed in a HW component stack.\n 00074 * In order to get the singleton instance you have to call class method `Instance()`, 00075 * e.g.: 00076 * @code 00077 * // Inertial & Environmental expansion board singleton instance 00078 * static X_NUCLEO_IKS01A1 *<TODO>_expansion_board = X_NUCLEO_IKS01A1::Instance(); 00079 * @endcode 00080 */ 00081 class X_NUCLEO_IKS01A1 00082 { 00083 protected: 00084 X_NUCLEO_IKS01A1(DevI2C *ext_i2c, PinName ff_irq_pin); 00085 00086 /** 00087 * @brief Initialize the singleton's sensors to default settings 00088 * @retval true if initialization successful, 00089 * @retval false otherwise 00090 */ 00091 bool Init(void) { 00092 return (Init_HTS221() && 00093 Init_LIS3MDL() && 00094 Init_LPS25H() && 00095 Init_Gyro()); 00096 } 00097 00098 /** 00099 * @brief Initialize the singleton's gyroscope 00100 * @retval true if initialization successful, 00101 * @retval false otherwise 00102 * @note only one sensor among LSM6DS3 & LSM6DS0 will be instantiated 00103 * with a preference on LSM6DS3 when available 00104 */ 00105 bool Init_Gyro(void) { 00106 // Note: order is important! 00107 return (Init_LSM6DS3() && 00108 Init_LSM6DS0()); 00109 } 00110 00111 bool Init_HTS221(void); 00112 bool Init_LIS3MDL(void); 00113 bool Init_LPS25H(void); 00114 bool Init_LSM6DS0(void); 00115 bool Init_LSM6DS3(void); 00116 00117 public: 00118 static X_NUCLEO_IKS01A1* Instance(DevI2C *ext_i2c = NULL, 00119 PinName ff_irq_pin = IKS01A1_PIN_FF); 00120 static X_NUCLEO_IKS01A1* Instance(PinName sda, PinName scl, PinName ff_irq_pin = NC); 00121 00122 DevI2C *dev_i2c; 00123 00124 HTS221 *ht_sensor; 00125 LIS3MDL *magnetometer; 00126 LPS25H *pt_sensor; 00127 00128 GyroSensor *GetGyroscope(void) { 00129 return ((gyro_lsm6ds3 == NULL) ? 00130 (GyroSensor*)gyro_lsm6ds0 : (GyroSensor*)gyro_lsm6ds3); 00131 } 00132 MotionSensor *GetAccelerometer(void) { 00133 return ((gyro_lsm6ds3 == NULL) ? 00134 (MotionSensor*)gyro_lsm6ds0 : (MotionSensor*)gyro_lsm6ds3); 00135 } 00136 LSM6DS0 *gyro_lsm6ds0; 00137 LSM6DS3 *gyro_lsm6ds3; 00138 00139 private: 00140 static X_NUCLEO_IKS01A1 *_instance; 00141 }; 00142 00143 #endif /* __X_NUCLEO_IKS01A1_H */
Generated on Tue Jul 12 2022 18:58:33 by
