Version with sensors supporting SPI 3-wires
Dependencies: ST_INTERFACES X_NUCLEO_COMMON_SPI3W
Fork of X_NUCLEO_IKS01A2 by
XNucleoIKS01A2.h@24:17e674bd19c8, 2017-09-07 (annotated)
- Committer:
- mapellil
- Date:
- Thu Sep 07 14:22:17 2017 +0000
- Revision:
- 24:17e674bd19c8
- Parent:
- 6:671fd10a51b7
Code cleanup
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
davide.aliprandi@st.com | 6:671fd10a51b7 | 1 | /** |
davide.aliprandi@st.com | 6:671fd10a51b7 | 2 | ****************************************************************************** |
davide.aliprandi@st.com | 6:671fd10a51b7 | 3 | * @file XNucleoIKS01A2.h |
davide.aliprandi@st.com | 6:671fd10a51b7 | 4 | * @author CLab |
davide.aliprandi@st.com | 6:671fd10a51b7 | 5 | * @version V1.0.0 |
davide.aliprandi@st.com | 6:671fd10a51b7 | 6 | * @date 9-August-2016 |
davide.aliprandi@st.com | 6:671fd10a51b7 | 7 | * @brief Header file for class XNucleoIKS01A2 representing a X-NUCLEO-IKS01A2 |
davide.aliprandi@st.com | 6:671fd10a51b7 | 8 | * expansion board |
davide.aliprandi@st.com | 6:671fd10a51b7 | 9 | ****************************************************************************** |
davide.aliprandi@st.com | 6:671fd10a51b7 | 10 | * @attention |
davide.aliprandi@st.com | 6:671fd10a51b7 | 11 | * |
davide.aliprandi@st.com | 6:671fd10a51b7 | 12 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
davide.aliprandi@st.com | 6:671fd10a51b7 | 13 | * |
davide.aliprandi@st.com | 6:671fd10a51b7 | 14 | * Redistribution and use in source and binary forms, with or without modification, |
davide.aliprandi@st.com | 6:671fd10a51b7 | 15 | * are permitted provided that the following conditions are met: |
davide.aliprandi@st.com | 6:671fd10a51b7 | 16 | * 1. Redistributions of source code must retain the above copyright notice, |
davide.aliprandi@st.com | 6:671fd10a51b7 | 17 | * this list of conditions and the following disclaimer. |
davide.aliprandi@st.com | 6:671fd10a51b7 | 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
davide.aliprandi@st.com | 6:671fd10a51b7 | 19 | * this list of conditions and the following disclaimer in the documentation |
davide.aliprandi@st.com | 6:671fd10a51b7 | 20 | * and/or other materials provided with the distribution. |
davide.aliprandi@st.com | 6:671fd10a51b7 | 21 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
davide.aliprandi@st.com | 6:671fd10a51b7 | 22 | * may be used to endorse or promote products derived from this software |
davide.aliprandi@st.com | 6:671fd10a51b7 | 23 | * without specific prior written permission. |
davide.aliprandi@st.com | 6:671fd10a51b7 | 24 | * |
davide.aliprandi@st.com | 6:671fd10a51b7 | 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
davide.aliprandi@st.com | 6:671fd10a51b7 | 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
davide.aliprandi@st.com | 6:671fd10a51b7 | 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
davide.aliprandi@st.com | 6:671fd10a51b7 | 28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
davide.aliprandi@st.com | 6:671fd10a51b7 | 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
davide.aliprandi@st.com | 6:671fd10a51b7 | 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
davide.aliprandi@st.com | 6:671fd10a51b7 | 31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
davide.aliprandi@st.com | 6:671fd10a51b7 | 32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
davide.aliprandi@st.com | 6:671fd10a51b7 | 33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
davide.aliprandi@st.com | 6:671fd10a51b7 | 34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
davide.aliprandi@st.com | 6:671fd10a51b7 | 35 | * |
davide.aliprandi@st.com | 6:671fd10a51b7 | 36 | ****************************************************************************** |
davide.aliprandi@st.com | 6:671fd10a51b7 | 37 | */ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 38 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 39 | /* Define to prevent from recursive inclusion --------------------------------*/ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 40 | #ifndef __X_NUCLEO_IKS01A2_H |
davide.aliprandi@st.com | 6:671fd10a51b7 | 41 | #define __X_NUCLEO_IKS01A2_H |
davide.aliprandi@st.com | 6:671fd10a51b7 | 42 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 43 | /* Includes ------------------------------------------------------------------*/ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 44 | #include "mbed.h" |
davide.aliprandi@st.com | 6:671fd10a51b7 | 45 | #include "x_nucleo_iks01a2_targets.h" |
davide.aliprandi@st.com | 6:671fd10a51b7 | 46 | #include "HTS221Sensor/HTS221Sensor.h" |
davide.aliprandi@st.com | 6:671fd10a51b7 | 47 | #include "LSM303AGRSensor/LSM303AGRAccSensor.h" |
davide.aliprandi@st.com | 6:671fd10a51b7 | 48 | #include "LSM303AGRSensor/LSM303AGRMagSensor.h" |
davide.aliprandi@st.com | 6:671fd10a51b7 | 49 | #include "LPS22HBSensor/LPS22HBSensor.h" |
davide.aliprandi@st.com | 6:671fd10a51b7 | 50 | #include "LSM6DSLSensor/LSM6DSLSensor.h" |
davide.aliprandi@st.com | 6:671fd10a51b7 | 51 | #include "DevI2C.h" |
davide.aliprandi@st.com | 6:671fd10a51b7 | 52 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 53 | /* Macros -------------------------------------------------------------------*/ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 54 | #define CALL_METH(obj, meth, param, ret) ((obj == NULL) ? \ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 55 | ((*(param) = (ret)), 0) : \ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 56 | ((obj)->meth(param)) \ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 57 | ) |
davide.aliprandi@st.com | 6:671fd10a51b7 | 58 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 59 | /* Classes -------------------------------------------------------------------*/ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 60 | /** Class XNucleoIKS01A2 is intended to represent the MEMS Inertial & Environmental |
davide.aliprandi@st.com | 6:671fd10a51b7 | 61 | * Nucleo Expansion Board with the same name. |
davide.aliprandi@st.com | 6:671fd10a51b7 | 62 | * |
davide.aliprandi@st.com | 6:671fd10a51b7 | 63 | * The expansion board is featuring basically four IPs:\n |
davide.aliprandi@st.com | 6:671fd10a51b7 | 64 | * -# a HTS221 Relative Humidity and Temperature Sensor\n |
davide.aliprandi@st.com | 6:671fd10a51b7 | 65 | * -# a LSM303AGR 3-Axis Magnetometer and 3D Acceleromenter\n |
davide.aliprandi@st.com | 6:671fd10a51b7 | 66 | * -# a LPS22HB MEMS Pressure Sensor (and Temperature Sensor)\n |
davide.aliprandi@st.com | 6:671fd10a51b7 | 67 | * -# and a LSM6DSL 3D Acceleromenter and 3D Gyroscope\n |
davide.aliprandi@st.com | 6:671fd10a51b7 | 68 | * |
davide.aliprandi@st.com | 6:671fd10a51b7 | 69 | * The expansion board features also a DIL 24-pin socket which makes it possible |
davide.aliprandi@st.com | 6:671fd10a51b7 | 70 | * to add further MEMS adapters and other sensors (e.g. UV index). |
davide.aliprandi@st.com | 6:671fd10a51b7 | 71 | * |
davide.aliprandi@st.com | 6:671fd10a51b7 | 72 | * It is intentionally implemented as a singleton because only one |
davide.aliprandi@st.com | 6:671fd10a51b7 | 73 | * X_NUCLEO_IKS01A2 at a time might be deployed in a HW component stack.\n |
davide.aliprandi@st.com | 6:671fd10a51b7 | 74 | * In order to get the singleton instance you have to call class method `Instance()`, |
davide.aliprandi@st.com | 6:671fd10a51b7 | 75 | * e.g.: |
davide.aliprandi@st.com | 6:671fd10a51b7 | 76 | * @code |
davide.aliprandi@st.com | 6:671fd10a51b7 | 77 | * // Inertial & Environmental expansion board singleton instance |
davide.aliprandi@st.com | 6:671fd10a51b7 | 78 | * static X_NUCLEO_IKS01A2 *<TODO>_expansion_board = X_NUCLEO_IKS01A2::Instance(); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 79 | * @endcode |
davide.aliprandi@st.com | 6:671fd10a51b7 | 80 | */ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 81 | class XNucleoIKS01A2 |
davide.aliprandi@st.com | 6:671fd10a51b7 | 82 | { |
davide.aliprandi@st.com | 6:671fd10a51b7 | 83 | protected: |
davide.aliprandi@st.com | 6:671fd10a51b7 | 84 | XNucleoIKS01A2(DevI2C *ext_i2c, PinName int1, PinName int2); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 85 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 86 | ~XNucleoIKS01A2(void) { |
davide.aliprandi@st.com | 6:671fd10a51b7 | 87 | /* should never be called */ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 88 | error("Trial to delete XNucleoIKS01A2 singleton!\n"); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 89 | } |
davide.aliprandi@st.com | 6:671fd10a51b7 | 90 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 91 | public: |
davide.aliprandi@st.com | 6:671fd10a51b7 | 92 | static XNucleoIKS01A2* instance(DevI2C *ext_i2c = NULL, PinName int1 = IKS01A2_PIN_LSM6DSL_INT1, PinName int2 = IKS01A2_PIN_LSM6DSL_INT2); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 93 | static XNucleoIKS01A2* instance(PinName sda, PinName scl, PinName int1 = IKS01A2_PIN_LSM6DSL_INT1, PinName int2 = IKS01A2_PIN_LSM6DSL_INT2); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 94 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 95 | DevI2C *dev_i2c; |
davide.aliprandi@st.com | 6:671fd10a51b7 | 96 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 97 | HTS221Sensor *ht_sensor; |
davide.aliprandi@st.com | 6:671fd10a51b7 | 98 | LSM303AGRMagSensor *magnetometer; |
davide.aliprandi@st.com | 6:671fd10a51b7 | 99 | LSM303AGRAccSensor *accelerometer; |
davide.aliprandi@st.com | 6:671fd10a51b7 | 100 | LPS22HBSensor *pt_sensor; |
davide.aliprandi@st.com | 6:671fd10a51b7 | 101 | LSM6DSLSensor *acc_gyro; |
davide.aliprandi@st.com | 6:671fd10a51b7 | 102 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 103 | private: |
davide.aliprandi@st.com | 6:671fd10a51b7 | 104 | static XNucleoIKS01A2 *_instance; |
davide.aliprandi@st.com | 6:671fd10a51b7 | 105 | }; |
davide.aliprandi@st.com | 6:671fd10a51b7 | 106 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 107 | #endif /* __X_NUCLEO_IKS01A2_H */ |