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 ReferredCoursework2016 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 ~X_NUCLEO_IKS01A1(void) { 00087 /* should never be called */ 00088 error("Trial to delete X_NUCLEO_IKS01A1 singleton!\n"); 00089 } 00090 00091 /** 00092 * @brief Initialize the singleton's sensors to default settings 00093 * @retval true if initialization successful, 00094 * @retval false otherwise 00095 */ 00096 bool Init(void) { 00097 return (Init_HTS221() && 00098 Init_LIS3MDL() && 00099 Init_LPS25H() && 00100 Init_Gyro()); 00101 } 00102 00103 /** 00104 * @brief Initialize the singleton's gyroscope 00105 * @retval true if initialization successful, 00106 * @retval false otherwise 00107 * @note only one sensor among LSM6DS3 & LSM6DS0 will be instantiated 00108 * with a preference on LSM6DS3 when available 00109 */ 00110 bool Init_Gyro(void) { 00111 // Note: order is important! 00112 return (Init_LSM6DS3() && 00113 Init_LSM6DS0()); 00114 } 00115 00116 bool Init_HTS221(void); 00117 bool Init_LIS3MDL(void); 00118 bool Init_LPS25H(void); 00119 bool Init_LSM6DS0(void); 00120 bool Init_LSM6DS3(void); 00121 00122 public: 00123 static X_NUCLEO_IKS01A1* Instance(DevI2C *ext_i2c = NULL, 00124 PinName ff_irq_pin = IKS01A1_PIN_FF); 00125 static X_NUCLEO_IKS01A1* Instance(PinName sda, PinName scl, PinName ff_irq_pin = NC); 00126 00127 DevI2C *dev_i2c; 00128 00129 HTS221 *ht_sensor; 00130 LIS3MDL *magnetometer; 00131 LPS25H *pt_sensor; 00132 00133 GyroSensor *GetGyroscope(void) { 00134 return ((gyro_lsm6ds3 == NULL) ? 00135 (GyroSensor*)gyro_lsm6ds0 : (GyroSensor*)gyro_lsm6ds3); 00136 } 00137 MotionSensor *GetAccelerometer(void) { 00138 return ((gyro_lsm6ds3 == NULL) ? 00139 (MotionSensor*)gyro_lsm6ds0 : (MotionSensor*)gyro_lsm6ds3); 00140 } 00141 LSM6DS0 *gyro_lsm6ds0; 00142 LSM6DS3 *gyro_lsm6ds3; 00143 00144 private: 00145 static X_NUCLEO_IKS01A1 *_instance; 00146 }; 00147 00148 #endif /* __X_NUCLEO_IKS01A1_H */
Generated on Sat Jul 16 2022 05:47:21 by
