Firmware Library for X-NUCLEO-IKS01A1 (MEMS Inertial & Environmental Sensors) Expansion Board

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   MultiTech_Dragonfly_2015_ATT_Gov_Solutions_Hackathon_Example HelloWorld_IKS01A1 LoRaWAN-test-10secs ServoMotorDemo ... more

Fork of X_NUCLEO_IKS01A1 by ST Expansion SW Team

X-NUCLEO-IKS01A1 MEMS Inertial & Environmental Sensor Nucleo Expansion Board Firmware Package

Introduction

This firmware package includes Components Device Drivers and Board Support Package for STMicroelectronics' X-NUCLEO-IKS01A1 MEMS Inertial & Environmental Sensors Nucleo Expansion Board.

Firmware Library

Class X_NUCLEO_IKS01A1 is intended to represent the MEMS inertial & environmental sensors expansion board with the same name.

The expansion board is basically featuring four IPs:

  1. a HTS221 Relative Humidity and Temperature Sensor,
  2. a LIS3MDL 3-Axis Magnetometer,
  3. a LPS25H MEMS Pressure Sensor, and
  4. a LSM6DS0 3D Accelerometer and 3D Gyroscope

The expansion board features also a DIL 24-pin socket which makes it possible to add further MEMS adapters and other sensors (e.g. UV index).

It is intentionally implemented as a singleton because only one X_NUCLEO_IKS01A1 at a time might be deployed in a HW component stack. In order to get the singleton instance you have to call class method `Instance()`, e.g.:

// Sensors expansion board singleton instance
static X_NUCLEO_IKS01A1 *sensors_expansion_board = X_NUCLEO_IKS01A1::Instance();


Furthermore, library ST_INTERFACES contains all abstract classes which together constitute the common API to which all existing and future ST components will adhere to.

Example Applications

Committer:
Wolfgang Betz
Date:
Fri Mar 24 10:57:29 2017 +0100
Revision:
92:d1c67d482bad
Parent:
87:f4fa3dad9ec4
Align to latest `ST_INTERFACES`

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wolfgang Betz 0:0feaa2a2d9ff 1 /**
Wolfgang Betz 0:0feaa2a2d9ff 2 ******************************************************************************
Wolfgang Betz 0:0feaa2a2d9ff 3 * @file x_nucleo_iks01a1.h
Wolfgang Betz 0:0feaa2a2d9ff 4 * @author AST / EST
Wolfgang Betz 0:0feaa2a2d9ff 5 * @version V0.0.1
Wolfgang Betz 0:0feaa2a2d9ff 6 * @date 13-April-2015
Wolfgang Betz 3:088aa5839e0d 7 * @brief Header file for class X_NUCLEO_IKS01A1 representing a X-NUCLEO-IKS01A1
Wolfgang Betz 0:0feaa2a2d9ff 8 * expansion board
Wolfgang Betz 0:0feaa2a2d9ff 9 ******************************************************************************
Wolfgang Betz 0:0feaa2a2d9ff 10 * @attention
Wolfgang Betz 0:0feaa2a2d9ff 11 *
Wolfgang Betz 3:088aa5839e0d 12 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
Wolfgang Betz 0:0feaa2a2d9ff 13 *
Wolfgang Betz 0:0feaa2a2d9ff 14 * Redistribution and use in source and binary forms, with or without modification,
Wolfgang Betz 0:0feaa2a2d9ff 15 * are permitted provided that the following conditions are met:
Wolfgang Betz 0:0feaa2a2d9ff 16 * 1. Redistributions of source code must retain the above copyright notice,
Wolfgang Betz 0:0feaa2a2d9ff 17 * this list of conditions and the following disclaimer.
Wolfgang Betz 0:0feaa2a2d9ff 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
Wolfgang Betz 0:0feaa2a2d9ff 19 * this list of conditions and the following disclaimer in the documentation
Wolfgang Betz 0:0feaa2a2d9ff 20 * and/or other materials provided with the distribution.
Wolfgang Betz 0:0feaa2a2d9ff 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Wolfgang Betz 0:0feaa2a2d9ff 22 * may be used to endorse or promote products derived from this software
Wolfgang Betz 0:0feaa2a2d9ff 23 * without specific prior written permission.
Wolfgang Betz 0:0feaa2a2d9ff 24 *
Wolfgang Betz 0:0feaa2a2d9ff 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Wolfgang Betz 0:0feaa2a2d9ff 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Wolfgang Betz 0:0feaa2a2d9ff 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Wolfgang Betz 0:0feaa2a2d9ff 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Wolfgang Betz 0:0feaa2a2d9ff 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Wolfgang Betz 0:0feaa2a2d9ff 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Wolfgang Betz 0:0feaa2a2d9ff 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Wolfgang Betz 0:0feaa2a2d9ff 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Wolfgang Betz 0:0feaa2a2d9ff 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Wolfgang Betz 0:0feaa2a2d9ff 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wolfgang Betz 0:0feaa2a2d9ff 35 *
Wolfgang Betz 0:0feaa2a2d9ff 36 ******************************************************************************
Wolfgang Betz 0:0feaa2a2d9ff 37 */
Wolfgang Betz 0:0feaa2a2d9ff 38
Wolfgang Betz 0:0feaa2a2d9ff 39 /* Define to prevent from recursive inclusion --------------------------------*/
Wolfgang Betz 0:0feaa2a2d9ff 40 #ifndef __X_NUCLEO_IKS01A1_H
Wolfgang Betz 0:0feaa2a2d9ff 41 #define __X_NUCLEO_IKS01A1_H
Wolfgang Betz 0:0feaa2a2d9ff 42
Wolfgang Betz 0:0feaa2a2d9ff 43 /* Includes ------------------------------------------------------------------*/
Wolfgang Betz 0:0feaa2a2d9ff 44 #include "mbed.h"
Wolfgang Betz 0:0feaa2a2d9ff 45 #include "x_nucleo_iks01a1_targets.h"
Wolfgang Betz 15:472cf58b9c11 46 #include "hts221/hts221_class.h"
Wolfgang Betz 15:472cf58b9c11 47 #include "lis3mdl/lis3mdl_class.h"
Wolfgang Betz 15:472cf58b9c11 48 #include "lps25h/lps25h_class.h"
Wolfgang Betz 15:472cf58b9c11 49 #include "lsm6ds0/lsm6ds0_class.h"
Wolfgang Betz 44:d757094f6229 50 #include "lsm6ds3/lsm6ds3_class.h"
Wolfgang Betz 0:0feaa2a2d9ff 51 #include "DevI2C.h"
Wolfgang Betz 0:0feaa2a2d9ff 52
Wolfgang Betz 42:5490ac2d0a10 53 /* Macros -------------------------------------------------------------------*/
Wolfgang Betz 42:5490ac2d0a10 54 #define CALL_METH(obj, meth, param, ret) ((obj == NULL) ? \
Wolfgang Betz 42:5490ac2d0a10 55 ((*(param) = (ret)), 0) : \
Wolfgang Betz 42:5490ac2d0a10 56 ((obj)->meth(param)) \
Wolfgang Betz 42:5490ac2d0a10 57 )
Wolfgang Betz 42:5490ac2d0a10 58
Wolfgang Betz 0:0feaa2a2d9ff 59 /* Classes -------------------------------------------------------------------*/
Wolfgang Betz 4:566f2c41dc1d 60 /** Class X_NUCLEO_IKS01A1 is intended to represent the MEMS Inertial & Environmental
Wolfgang Betz 4:566f2c41dc1d 61 * Nucleo Expansion Board with the same name.
Wolfgang Betz 0:0feaa2a2d9ff 62 *
Wolfgang Betz 3:088aa5839e0d 63 * The expansion board is featuring basically four IPs:\n
Wolfgang Betz 3:088aa5839e0d 64 * -# a HTS221 Relative Humidity and Temperature Sensor\n
Wolfgang Betz 3:088aa5839e0d 65 * -# a LIS3MDL 3-Axis Magnetometer\n
Wolfgang Betz 71:78164ec41ad2 66 * -# a LPS25H MEMS Pressure Sensor (and Temperature Sensor)\n
Wolfgang Betz 3:088aa5839e0d 67 * -# and a LSM6DS0 3D Acceleromenter and 3D Gyroscope\n
Wolfgang Betz 0:0feaa2a2d9ff 68 *
Wolfgang Betz 44:d757094f6229 69 * The expansion board features also a DIL 24-pin socket which makes it possible
Wolfgang Betz 44:d757094f6229 70 * to add further MEMS adapters and other sensors (e.g. UV index).
Wolfgang Betz 44:d757094f6229 71 *
Wolfgang Betz 0:0feaa2a2d9ff 72 * It is intentionally implemented as a singleton because only one
Wolfgang Betz 0:0feaa2a2d9ff 73 * X_NUCLEO_IKS01A1 at a time might be deployed in a HW component stack.\n
Wolfgang Betz 0:0feaa2a2d9ff 74 * In order to get the singleton instance you have to call class method `Instance()`,
Wolfgang Betz 0:0feaa2a2d9ff 75 * e.g.:
Wolfgang Betz 0:0feaa2a2d9ff 76 * @code
Wolfgang Betz 3:088aa5839e0d 77 * // Inertial & Environmental expansion board singleton instance
Wolfgang Betz 0:0feaa2a2d9ff 78 * static X_NUCLEO_IKS01A1 *<TODO>_expansion_board = X_NUCLEO_IKS01A1::Instance();
Wolfgang Betz 0:0feaa2a2d9ff 79 * @endcode
Wolfgang Betz 0:0feaa2a2d9ff 80 */
Wolfgang Betz 0:0feaa2a2d9ff 81 class X_NUCLEO_IKS01A1
Wolfgang Betz 0:0feaa2a2d9ff 82 {
Wolfgang Betz 0:0feaa2a2d9ff 83 protected:
Wolfgang Betz 72:79a2a64c9b2f 84 X_NUCLEO_IKS01A1(DevI2C *ext_i2c, PinName ff_irq_pin);
Wolfgang Betz 0:0feaa2a2d9ff 85
Wolfgang Betz 85:cb636b531652 86 ~X_NUCLEO_IKS01A1(void) {
Wolfgang Betz 85:cb636b531652 87 /* should never be called */
Wolfgang Betz 85:cb636b531652 88 error("Trial to delete X_NUCLEO_IKS01A1 singleton!\n");
Wolfgang Betz 85:cb636b531652 89 }
Wolfgang Betz 85:cb636b531652 90
Wolfgang Betz 44:d757094f6229 91 /**
Wolfgang Betz 44:d757094f6229 92 * @brief Initialize the singleton's sensors to default settings
Wolfgang Betz 44:d757094f6229 93 * @retval true if initialization successful,
Wolfgang Betz 44:d757094f6229 94 * @retval false otherwise
Wolfgang Betz 44:d757094f6229 95 */
Wolfgang Betz 44:d757094f6229 96 bool Init(void) {
Wolfgang Betz 44:d757094f6229 97 return (Init_HTS221() &&
Wolfgang Betz 44:d757094f6229 98 Init_LIS3MDL() &&
Wolfgang Betz 44:d757094f6229 99 Init_LPS25H() &&
Wolfgang Betz 44:d757094f6229 100 Init_Gyro());
Wolfgang Betz 44:d757094f6229 101 }
Wolfgang Betz 44:d757094f6229 102
Wolfgang Betz 44:d757094f6229 103 /**
Wolfgang Betz 44:d757094f6229 104 * @brief Initialize the singleton's gyroscope
Wolfgang Betz 44:d757094f6229 105 * @retval true if initialization successful,
Wolfgang Betz 44:d757094f6229 106 * @retval false otherwise
Wolfgang Betz 44:d757094f6229 107 * @note only one sensor among LSM6DS3 & LSM6DS0 will be instantiated
Wolfgang Betz 44:d757094f6229 108 * with a preference on LSM6DS3 when available
Wolfgang Betz 44:d757094f6229 109 */
Wolfgang Betz 44:d757094f6229 110 bool Init_Gyro(void) {
Wolfgang Betz 44:d757094f6229 111 // Note: order is important!
Wolfgang Betz 44:d757094f6229 112 return (Init_LSM6DS3() &&
Wolfgang Betz 44:d757094f6229 113 Init_LSM6DS0());
Wolfgang Betz 44:d757094f6229 114 }
Wolfgang Betz 44:d757094f6229 115
Wolfgang Betz 42:5490ac2d0a10 116 bool Init_HTS221(void);
Wolfgang Betz 42:5490ac2d0a10 117 bool Init_LIS3MDL(void);
Wolfgang Betz 42:5490ac2d0a10 118 bool Init_LPS25H(void);
Wolfgang Betz 42:5490ac2d0a10 119 bool Init_LSM6DS0(void);
Wolfgang Betz 44:d757094f6229 120 bool Init_LSM6DS3(void);
Wolfgang Betz 8:d49db2c9d9c1 121
Wolfgang Betz 0:0feaa2a2d9ff 122 public:
Wolfgang Betz 72:79a2a64c9b2f 123 static X_NUCLEO_IKS01A1* Instance(DevI2C *ext_i2c = NULL,
Wolfgang Betz 72:79a2a64c9b2f 124 PinName ff_irq_pin = IKS01A1_PIN_FF);
Wolfgang Betz 72:79a2a64c9b2f 125 static X_NUCLEO_IKS01A1* Instance(PinName sda, PinName scl, PinName ff_irq_pin = NC);
Wolfgang Betz 0:0feaa2a2d9ff 126
Wolfgang Betz 42:5490ac2d0a10 127 DevI2C *dev_i2c;
Wolfgang Betz 0:0feaa2a2d9ff 128
Wolfgang Betz 42:5490ac2d0a10 129 HTS221 *ht_sensor;
Wolfgang Betz 42:5490ac2d0a10 130 LIS3MDL *magnetometer;
Wolfgang Betz 71:78164ec41ad2 131 LPS25H *pt_sensor;
Wolfgang Betz 44:d757094f6229 132
Wolfgang Betz 44:d757094f6229 133 GyroSensor *GetGyroscope(void) {
Wolfgang Betz 44:d757094f6229 134 return ((gyro_lsm6ds3 == NULL) ?
Wolfgang Betz 44:d757094f6229 135 (GyroSensor*)gyro_lsm6ds0 : (GyroSensor*)gyro_lsm6ds3);
Wolfgang Betz 44:d757094f6229 136 }
Wolfgang Betz 44:d757094f6229 137 MotionSensor *GetAccelerometer(void) {
Wolfgang Betz 44:d757094f6229 138 return ((gyro_lsm6ds3 == NULL) ?
Wolfgang Betz 44:d757094f6229 139 (MotionSensor*)gyro_lsm6ds0 : (MotionSensor*)gyro_lsm6ds3);
Wolfgang Betz 44:d757094f6229 140 }
Wolfgang Betz 44:d757094f6229 141 LSM6DS0 *gyro_lsm6ds0;
Wolfgang Betz 44:d757094f6229 142 LSM6DS3 *gyro_lsm6ds3;
Wolfgang Betz 3:088aa5839e0d 143
Wolfgang Betz 0:0feaa2a2d9ff 144 private:
Wolfgang Betz 0:0feaa2a2d9ff 145 static X_NUCLEO_IKS01A1 *_instance;
Wolfgang Betz 0:0feaa2a2d9ff 146 };
Wolfgang Betz 0:0feaa2a2d9ff 147
Wolfgang Betz 0:0feaa2a2d9ff 148 #endif /* __X_NUCLEO_IKS01A1_H */