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