STM Imu acquisition setup using ethernet
Dependencies: F7_Ethernet mbed HTS221 LPS22HB LSM303AGR LSM6DSL
Fork of Nucleo_F746ZG_Ethernet by
X_NUCLEO_IKS01A2/XNucleoIKS01A2.cpp@9:45a96c88754d, 2018-10-15 (annotated)
- Committer:
- nirnakern
- Date:
- Mon Oct 15 14:41:19 2018 +0000
- Revision:
- 9:45a96c88754d
- Parent:
- 3:758e8ed30819
First Commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nirnakern | 3:758e8ed30819 | 1 | /** |
nirnakern | 3:758e8ed30819 | 2 | ****************************************************************************** |
nirnakern | 3:758e8ed30819 | 3 | * @file XNucleoIKS01A2.cpp |
nirnakern | 3:758e8ed30819 | 4 | * @author CLab |
nirnakern | 3:758e8ed30819 | 5 | * @version V1.0.0 |
nirnakern | 3:758e8ed30819 | 6 | * @date 9-August-2016 |
nirnakern | 3:758e8ed30819 | 7 | * @brief Implementation file for the X_NUCLEO_IKS01A2 singleton class |
nirnakern | 3:758e8ed30819 | 8 | ****************************************************************************** |
nirnakern | 3:758e8ed30819 | 9 | * @attention |
nirnakern | 3:758e8ed30819 | 10 | * |
nirnakern | 3:758e8ed30819 | 11 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
nirnakern | 3:758e8ed30819 | 12 | * |
nirnakern | 3:758e8ed30819 | 13 | * Redistribution and use in source and binary forms, with or without modification, |
nirnakern | 3:758e8ed30819 | 14 | * are permitted provided that the following conditions are met: |
nirnakern | 3:758e8ed30819 | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
nirnakern | 3:758e8ed30819 | 16 | * this list of conditions and the following disclaimer. |
nirnakern | 3:758e8ed30819 | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
nirnakern | 3:758e8ed30819 | 18 | * this list of conditions and the following disclaimer in the documentation |
nirnakern | 3:758e8ed30819 | 19 | * and/or other materials provided with the distribution. |
nirnakern | 3:758e8ed30819 | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
nirnakern | 3:758e8ed30819 | 21 | * may be used to endorse or promote products derived from this software |
nirnakern | 3:758e8ed30819 | 22 | * without specific prior written permission. |
nirnakern | 3:758e8ed30819 | 23 | * |
nirnakern | 3:758e8ed30819 | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
nirnakern | 3:758e8ed30819 | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
nirnakern | 3:758e8ed30819 | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
nirnakern | 3:758e8ed30819 | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
nirnakern | 3:758e8ed30819 | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
nirnakern | 3:758e8ed30819 | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
nirnakern | 3:758e8ed30819 | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
nirnakern | 3:758e8ed30819 | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
nirnakern | 3:758e8ed30819 | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
nirnakern | 3:758e8ed30819 | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
nirnakern | 3:758e8ed30819 | 34 | * |
nirnakern | 3:758e8ed30819 | 35 | ****************************************************************************** |
nirnakern | 3:758e8ed30819 | 36 | */ |
nirnakern | 3:758e8ed30819 | 37 | |
nirnakern | 3:758e8ed30819 | 38 | /* Includes ------------------------------------------------------------------*/ |
nirnakern | 3:758e8ed30819 | 39 | #include "mbed.h" |
nirnakern | 3:758e8ed30819 | 40 | #include "XNucleoIKS01A2.h" |
nirnakern | 3:758e8ed30819 | 41 | |
nirnakern | 3:758e8ed30819 | 42 | /* Static variables ----------------------------------------------------------*/ |
nirnakern | 3:758e8ed30819 | 43 | XNucleoIKS01A2 *XNucleoIKS01A2::_instance = NULL; |
nirnakern | 3:758e8ed30819 | 44 | |
nirnakern | 3:758e8ed30819 | 45 | |
nirnakern | 3:758e8ed30819 | 46 | /* Methods -------------------------------------------------------------------*/ |
nirnakern | 3:758e8ed30819 | 47 | /** |
nirnakern | 3:758e8ed30819 | 48 | * @brief Constructor |
nirnakern | 3:758e8ed30819 | 49 | */ |
nirnakern | 3:758e8ed30819 | 50 | XNucleoIKS01A2::XNucleoIKS01A2(DevI2C *ext_i2c, PinName int1, PinName int2) : dev_i2c(ext_i2c), |
nirnakern | 3:758e8ed30819 | 51 | ht_sensor(new HTS221Sensor(dev_i2c)), |
nirnakern | 3:758e8ed30819 | 52 | magnetometer(new LSM303AGRMagSensor(dev_i2c)), |
nirnakern | 3:758e8ed30819 | 53 | accelerometer(new LSM303AGRAccSensor(dev_i2c)), |
nirnakern | 3:758e8ed30819 | 54 | pt_sensor(new LPS22HBSensor(dev_i2c)), |
nirnakern | 3:758e8ed30819 | 55 | acc_gyro(new LSM6DSLSensor(dev_i2c, LSM6DSL_ACC_GYRO_I2C_ADDRESS_HIGH, int1, int2)) |
nirnakern | 3:758e8ed30819 | 56 | { |
nirnakern | 3:758e8ed30819 | 57 | ht_sensor->init(NULL); |
nirnakern | 3:758e8ed30819 | 58 | magnetometer->init(NULL); |
nirnakern | 3:758e8ed30819 | 59 | accelerometer->init(NULL); |
nirnakern | 3:758e8ed30819 | 60 | pt_sensor->init(NULL); |
nirnakern | 3:758e8ed30819 | 61 | acc_gyro->init(NULL); |
nirnakern | 3:758e8ed30819 | 62 | } |
nirnakern | 3:758e8ed30819 | 63 | |
nirnakern | 3:758e8ed30819 | 64 | /** |
nirnakern | 3:758e8ed30819 | 65 | * @brief Get singleton instance |
nirnakern | 3:758e8ed30819 | 66 | * @return a pointer to the initialized singleton instance of class XNucleoIKS01A2. |
nirnakern | 3:758e8ed30819 | 67 | * A return value of NULL indicates an out of memory situation. |
nirnakern | 3:758e8ed30819 | 68 | * @param[in] ext_i2c (optional) pointer to an instance of DevI2C to be used |
nirnakern | 3:758e8ed30819 | 69 | * for communication on the expansion board. |
nirnakern | 3:758e8ed30819 | 70 | * Defaults to NULL. |
nirnakern | 3:758e8ed30819 | 71 | * Taken into account only on the very first call of one of the 'Instance' functions. |
nirnakern | 3:758e8ed30819 | 72 | * If not provided a new DevI2C will be created with standard |
nirnakern | 3:758e8ed30819 | 73 | * configuration parameters. |
nirnakern | 3:758e8ed30819 | 74 | * The used DevI2C object gets saved in instance variable dev_i2c. |
nirnakern | 3:758e8ed30819 | 75 | * @param[in] int1 LSM6DSL INT1 pin. |
nirnakern | 3:758e8ed30819 | 76 | * Taken into account only on the very first call of one of the 'Instance' functions. |
nirnakern | 3:758e8ed30819 | 77 | * It maps the INT1 pin for LSM6DSL. Defaults to IKS01A2_PIN_LSM6DSL_INT1. |
nirnakern | 3:758e8ed30819 | 78 | * @param[in] int2 LSM6DSL INT1 pin. |
nirnakern | 3:758e8ed30819 | 79 | * Taken into account only on the very first call of one of the 'Instance' functions. |
nirnakern | 3:758e8ed30819 | 80 | * It maps the INT2 pin for LSM6DSL. Defaults to IKS01A2_PIN_LSM6DSL_INT2. |
nirnakern | 3:758e8ed30819 | 81 | */ |
nirnakern | 3:758e8ed30819 | 82 | XNucleoIKS01A2 *XNucleoIKS01A2::instance(DevI2C *ext_i2c, PinName int1, PinName int2) { |
nirnakern | 3:758e8ed30819 | 83 | if(_instance == NULL) { |
nirnakern | 3:758e8ed30819 | 84 | if(ext_i2c == NULL) |
nirnakern | 3:758e8ed30819 | 85 | ext_i2c = new DevI2C(IKS01A2_PIN_I2C_SDA, IKS01A2_PIN_I2C_SCL); |
nirnakern | 3:758e8ed30819 | 86 | |
nirnakern | 3:758e8ed30819 | 87 | if(ext_i2c != NULL) |
nirnakern | 3:758e8ed30819 | 88 | _instance = new XNucleoIKS01A2(ext_i2c, int1, int2); |
nirnakern | 3:758e8ed30819 | 89 | } |
nirnakern | 3:758e8ed30819 | 90 | |
nirnakern | 3:758e8ed30819 | 91 | return _instance; |
nirnakern | 3:758e8ed30819 | 92 | } |
nirnakern | 3:758e8ed30819 | 93 | |
nirnakern | 3:758e8ed30819 | 94 | /** |
nirnakern | 3:758e8ed30819 | 95 | * @brief Get singleton instance |
nirnakern | 3:758e8ed30819 | 96 | * @return a pointer to the initialized singleton instance of class X_NUCLEO_IKS01A1. |
nirnakern | 3:758e8ed30819 | 97 | * A return value of NULL indicates an out of memory situation. |
nirnakern | 3:758e8ed30819 | 98 | * @param[in] sda I2C data line pin. |
nirnakern | 3:758e8ed30819 | 99 | * Taken into account only on the very first call of one of the 'Instance' functions. |
nirnakern | 3:758e8ed30819 | 100 | * A new DevI2C will be created based on parameters 'sda' and 'scl'. |
nirnakern | 3:758e8ed30819 | 101 | * The used DevI2C object gets saved in instance variable dev_i2c. |
nirnakern | 3:758e8ed30819 | 102 | * @param[in] scl I2C clock line pin. |
nirnakern | 3:758e8ed30819 | 103 | * Taken into account only on the very first call of one of the 'Instance' functions. |
nirnakern | 3:758e8ed30819 | 104 | * A new DevI2C will be created based on parameters 'sda' and 'scl'. |
nirnakern | 3:758e8ed30819 | 105 | * The used DevI2C object gets saved in instance variable dev_i2c. |
nirnakern | 3:758e8ed30819 | 106 | * @param[in] int1 LSM6DSL INT1 pin. |
nirnakern | 3:758e8ed30819 | 107 | * Taken into account only on the very first call of one of the 'Instance' functions. |
nirnakern | 3:758e8ed30819 | 108 | * It maps the INT1 pin for LSM6DSL. Defaults to IKS01A2_PIN_LSM6DSL_INT1. |
nirnakern | 3:758e8ed30819 | 109 | * @param[in] int2 LSM6DSL INT1 pin. |
nirnakern | 3:758e8ed30819 | 110 | * Taken into account only on the very first call of one of the 'Instance' functions. |
nirnakern | 3:758e8ed30819 | 111 | * It maps the INT2 pin for LSM6DSL. Defaults to IKS01A2_PIN_LSM6DSL_INT2. |
nirnakern | 3:758e8ed30819 | 112 | */ |
nirnakern | 3:758e8ed30819 | 113 | XNucleoIKS01A2 *XNucleoIKS01A2::instance(PinName sda, PinName scl, PinName int1, PinName int2) { |
nirnakern | 3:758e8ed30819 | 114 | if(_instance == NULL) { |
nirnakern | 3:758e8ed30819 | 115 | DevI2C *ext_i2c = new DevI2C(sda, scl); |
nirnakern | 3:758e8ed30819 | 116 | |
nirnakern | 3:758e8ed30819 | 117 | if(ext_i2c != NULL) |
nirnakern | 3:758e8ed30819 | 118 | _instance = new XNucleoIKS01A2(ext_i2c, int1, int2); |
nirnakern | 3:758e8ed30819 | 119 | } |
nirnakern | 3:758e8ed30819 | 120 | |
nirnakern | 3:758e8ed30819 | 121 | return _instance; |
nirnakern | 3:758e8ed30819 | 122 | } |