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:
Tue Apr 14 15:32:06 2015 +0200
Revision:
4:566f2c41dc1d
Child:
6:8d2abd695c52
X_NUCLEO_IKS01A1: first version of main & hts221 component

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wolfgang Betz 4:566f2c41dc1d 1 /**
Wolfgang Betz 4:566f2c41dc1d 2 ******************************************************************************
Wolfgang Betz 4:566f2c41dc1d 3 * @file hts221_class.h
Wolfgang Betz 4:566f2c41dc1d 4 * @author AST / EST
Wolfgang Betz 4:566f2c41dc1d 5 * @version V0.0.1
Wolfgang Betz 4:566f2c41dc1d 6 * @date 14-April-2015
Wolfgang Betz 4:566f2c41dc1d 7 * @brief Header file for component HTS221
Wolfgang Betz 4:566f2c41dc1d 8 ******************************************************************************
Wolfgang Betz 4:566f2c41dc1d 9 * @attention
Wolfgang Betz 4:566f2c41dc1d 10 *
Wolfgang Betz 4:566f2c41dc1d 11 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
Wolfgang Betz 4:566f2c41dc1d 12 *
Wolfgang Betz 4:566f2c41dc1d 13 * Redistribution and use in source and binary forms, with or without modification,
Wolfgang Betz 4:566f2c41dc1d 14 * are permitted provided that the following conditions are met:
Wolfgang Betz 4:566f2c41dc1d 15 * 1. Redistributions of source code must retain the above copyright notice,
Wolfgang Betz 4:566f2c41dc1d 16 * this list of conditions and the following disclaimer.
Wolfgang Betz 4:566f2c41dc1d 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
Wolfgang Betz 4:566f2c41dc1d 18 * this list of conditions and the following disclaimer in the documentation
Wolfgang Betz 4:566f2c41dc1d 19 * and/or other materials provided with the distribution.
Wolfgang Betz 4:566f2c41dc1d 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Wolfgang Betz 4:566f2c41dc1d 21 * may be used to endorse or promote products derived from this software
Wolfgang Betz 4:566f2c41dc1d 22 * without specific prior written permission.
Wolfgang Betz 4:566f2c41dc1d 23 *
Wolfgang Betz 4:566f2c41dc1d 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Wolfgang Betz 4:566f2c41dc1d 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Wolfgang Betz 4:566f2c41dc1d 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Wolfgang Betz 4:566f2c41dc1d 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Wolfgang Betz 4:566f2c41dc1d 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Wolfgang Betz 4:566f2c41dc1d 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Wolfgang Betz 4:566f2c41dc1d 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Wolfgang Betz 4:566f2c41dc1d 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Wolfgang Betz 4:566f2c41dc1d 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Wolfgang Betz 4:566f2c41dc1d 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wolfgang Betz 4:566f2c41dc1d 34 *
Wolfgang Betz 4:566f2c41dc1d 35 ******************************************************************************
Wolfgang Betz 4:566f2c41dc1d 36 */
Wolfgang Betz 4:566f2c41dc1d 37
Wolfgang Betz 4:566f2c41dc1d 38 #ifndef __HTS221_CLASS_H
Wolfgang Betz 4:566f2c41dc1d 39 #define __HTS221_CLASS_H
Wolfgang Betz 4:566f2c41dc1d 40
Wolfgang Betz 4:566f2c41dc1d 41 /* Includes ------------------------------------------------------------------*/
Wolfgang Betz 4:566f2c41dc1d 42 #include "mbed.h"
Wolfgang Betz 4:566f2c41dc1d 43 #include "DevI2C.h"
Wolfgang Betz 4:566f2c41dc1d 44 #include "../Common/HumTemp.h"
Wolfgang Betz 4:566f2c41dc1d 45 #include "hts221.h"
Wolfgang Betz 4:566f2c41dc1d 46
Wolfgang Betz 4:566f2c41dc1d 47 /* Classes -------------------------------------------------------------------*/
Wolfgang Betz 4:566f2c41dc1d 48 /** Class representing a HTS221 sensor component
Wolfgang Betz 4:566f2c41dc1d 49 */
Wolfgang Betz 4:566f2c41dc1d 50 class HTS221 : public HumTemp {
Wolfgang Betz 4:566f2c41dc1d 51 public:
Wolfgang Betz 4:566f2c41dc1d 52 /** Constructor
Wolfgang Betz 4:566f2c41dc1d 53 * @param i2c device I2C to be used for communication
Wolfgang Betz 4:566f2c41dc1d 54 */
Wolfgang Betz 4:566f2c41dc1d 55 HTS221(DevI2C &i2c) : HumTemp(), dev_i2c(i2c) {
Wolfgang Betz 4:566f2c41dc1d 56 T0_degC = T1_degC = H0_rh = H1_rh = 0.0;
Wolfgang Betz 4:566f2c41dc1d 57 T0_out = T1_out = H0_T0_out = H1_T0_out = 0;
Wolfgang Betz 4:566f2c41dc1d 58 }
Wolfgang Betz 4:566f2c41dc1d 59
Wolfgang Betz 4:566f2c41dc1d 60 /*** Interface Methods ***/
Wolfgang Betz 4:566f2c41dc1d 61 virtual HUM_TEMP_StatusTypeDef Init(HUM_TEMP_InitTypeDef *init_struct) {
Wolfgang Betz 4:566f2c41dc1d 62 return HTS221_Init(init_struct);
Wolfgang Betz 4:566f2c41dc1d 63 }
Wolfgang Betz 4:566f2c41dc1d 64
Wolfgang Betz 4:566f2c41dc1d 65 virtual HUM_TEMP_StatusTypeDef PowerOFF(void) {
Wolfgang Betz 4:566f2c41dc1d 66 return HTS221_Power_OFF();
Wolfgang Betz 4:566f2c41dc1d 67 }
Wolfgang Betz 4:566f2c41dc1d 68
Wolfgang Betz 4:566f2c41dc1d 69 virtual HUM_TEMP_StatusTypeDef ReadID(uint8_t *ht_id) {
Wolfgang Betz 4:566f2c41dc1d 70 return HTS221_ReadID(ht_id);
Wolfgang Betz 4:566f2c41dc1d 71 }
Wolfgang Betz 4:566f2c41dc1d 72
Wolfgang Betz 4:566f2c41dc1d 73 virtual HUM_TEMP_StatusTypeDef Reset(void) {
Wolfgang Betz 4:566f2c41dc1d 74 return HTS221_RebootCmd();
Wolfgang Betz 4:566f2c41dc1d 75 }
Wolfgang Betz 4:566f2c41dc1d 76
Wolfgang Betz 4:566f2c41dc1d 77 virtual void ConfigIT(uint16_t) { /* not yet implemented */ }
Wolfgang Betz 4:566f2c41dc1d 78 virtual void EnableIT(uint8_t) { /* not yet implemented */ }
Wolfgang Betz 4:566f2c41dc1d 79 virtual void DisableIT(uint8_t) { /* not yet implemented */ }
Wolfgang Betz 4:566f2c41dc1d 80 virtual uint8_t ITStatus(uint16_t, uint16_t) { /* not yet implemented */ return 0; }
Wolfgang Betz 4:566f2c41dc1d 81 virtual void ClearIT(uint16_t, uint16_t) { /* not yet implemented */ }
Wolfgang Betz 4:566f2c41dc1d 82
Wolfgang Betz 4:566f2c41dc1d 83 virtual HUM_TEMP_StatusTypeDef GetHumidity(float *pfData) {
Wolfgang Betz 4:566f2c41dc1d 84 return HTS221_GetHumidity(pfData);
Wolfgang Betz 4:566f2c41dc1d 85 }
Wolfgang Betz 4:566f2c41dc1d 86
Wolfgang Betz 4:566f2c41dc1d 87 virtual HUM_TEMP_StatusTypeDef GetTemperature(float *pfData) {
Wolfgang Betz 4:566f2c41dc1d 88 return HTS221_GetTemperature(pfData);
Wolfgang Betz 4:566f2c41dc1d 89 }
Wolfgang Betz 4:566f2c41dc1d 90
Wolfgang Betz 4:566f2c41dc1d 91 virtual void AttachIT(void (*fptr)(void)) { /* not yet implemented */ }
Wolfgang Betz 4:566f2c41dc1d 92
Wolfgang Betz 4:566f2c41dc1d 93 protected:
Wolfgang Betz 4:566f2c41dc1d 94 /*** Methods ***/
Wolfgang Betz 4:566f2c41dc1d 95 HUM_TEMP_StatusTypeDef HTS221_Init(HUM_TEMP_InitTypeDef *HTS221_Init);
Wolfgang Betz 4:566f2c41dc1d 96 HUM_TEMP_StatusTypeDef HTS221_Power_OFF(void);
Wolfgang Betz 4:566f2c41dc1d 97 HUM_TEMP_StatusTypeDef HTS221_ReadID(uint8_t *ht_id);
Wolfgang Betz 4:566f2c41dc1d 98 HUM_TEMP_StatusTypeDef HTS221_RebootCmd(void);
Wolfgang Betz 4:566f2c41dc1d 99 HUM_TEMP_StatusTypeDef HTS221_GetHumidity(float* pfData);
Wolfgang Betz 4:566f2c41dc1d 100 HUM_TEMP_StatusTypeDef HTS221_GetTemperature(float* pfData);
Wolfgang Betz 4:566f2c41dc1d 101 HUM_TEMP_StatusTypeDef HTS221_Power_On(void);
Wolfgang Betz 4:566f2c41dc1d 102 HUM_TEMP_StatusTypeDef HTS221_Calibration(void);
Wolfgang Betz 4:566f2c41dc1d 103
Wolfgang Betz 4:566f2c41dc1d 104 /**
Wolfgang Betz 4:566f2c41dc1d 105 * @brief Configures HTS221 interrupt lines for NUCLEO boards
Wolfgang Betz 4:566f2c41dc1d 106 * @param None
Wolfgang Betz 4:566f2c41dc1d 107 * @retval None
Wolfgang Betz 4:566f2c41dc1d 108 */
Wolfgang Betz 4:566f2c41dc1d 109 void HTS221_IO_ITConfig(void)
Wolfgang Betz 4:566f2c41dc1d 110 {
Wolfgang Betz 4:566f2c41dc1d 111 /* To be implemented */
Wolfgang Betz 4:566f2c41dc1d 112 }
Wolfgang Betz 4:566f2c41dc1d 113
Wolfgang Betz 4:566f2c41dc1d 114 /**
Wolfgang Betz 4:566f2c41dc1d 115 * @brief Configures HTS221 I2C interface
Wolfgang Betz 4:566f2c41dc1d 116 * @param None
Wolfgang Betz 4:566f2c41dc1d 117 * @retval HUM_TEMP_OK in case of success, an error code otherwise
Wolfgang Betz 4:566f2c41dc1d 118 */
Wolfgang Betz 4:566f2c41dc1d 119 HUM_TEMP_StatusTypeDef HTS221_IO_Init(void)
Wolfgang Betz 4:566f2c41dc1d 120 {
Wolfgang Betz 4:566f2c41dc1d 121 return HUM_TEMP_OK; /* done in constructor */
Wolfgang Betz 4:566f2c41dc1d 122 }
Wolfgang Betz 4:566f2c41dc1d 123
Wolfgang Betz 4:566f2c41dc1d 124 /**
Wolfgang Betz 4:566f2c41dc1d 125 * @brief utility function to read data from STC3115
Wolfgang Betz 4:566f2c41dc1d 126 * @param pBuffer: pointer to data to be read.
Wolfgang Betz 4:566f2c41dc1d 127 * @param RegisterAddr: specifies internal address register to read from.
Wolfgang Betz 4:566f2c41dc1d 128 * @param NumByteToRead: number of bytes to be read.
Wolfgang Betz 4:566f2c41dc1d 129 * @retval HUM_TEMP_OK if ok, HUM_TEMP_ERROR if an I2C error has occured
Wolfgang Betz 4:566f2c41dc1d 130 */
Wolfgang Betz 4:566f2c41dc1d 131 HUM_TEMP_StatusTypeDef HTS221_IO_Read(uint8_t* pBuffer,
Wolfgang Betz 4:566f2c41dc1d 132 uint8_t RegisterAddr, uint16_t NumByteToRead)
Wolfgang Betz 4:566f2c41dc1d 133 {
Wolfgang Betz 4:566f2c41dc1d 134 int ret = dev_i2c.i2c_read(pBuffer,
Wolfgang Betz 4:566f2c41dc1d 135 HTS221_ADDRESS,
Wolfgang Betz 4:566f2c41dc1d 136 RegisterAddr,
Wolfgang Betz 4:566f2c41dc1d 137 NumByteToRead);
Wolfgang Betz 4:566f2c41dc1d 138 if(ret != 0) {
Wolfgang Betz 4:566f2c41dc1d 139 return HUM_TEMP_ERROR;
Wolfgang Betz 4:566f2c41dc1d 140 }
Wolfgang Betz 4:566f2c41dc1d 141 return HUM_TEMP_OK;
Wolfgang Betz 4:566f2c41dc1d 142 }
Wolfgang Betz 4:566f2c41dc1d 143
Wolfgang Betz 4:566f2c41dc1d 144 /**
Wolfgang Betz 4:566f2c41dc1d 145 * @brief utility function to write data to STC3115
Wolfgang Betz 4:566f2c41dc1d 146 * @param pBuffer: pointer to buffer to be filled.
Wolfgang Betz 4:566f2c41dc1d 147 * @param RegisterAddr: specifies internal address register to read from.
Wolfgang Betz 4:566f2c41dc1d 148 * @param NumByteToWrite: number of bytes to write.
Wolfgang Betz 4:566f2c41dc1d 149 * @retval 0 if ok, -1 if an I2C error has occured
Wolfgang Betz 4:566f2c41dc1d 150 */
Wolfgang Betz 4:566f2c41dc1d 151 HUM_TEMP_StatusTypeDef HTS221_IO_Write(uint8_t* pBuffer,
Wolfgang Betz 4:566f2c41dc1d 152 uint8_t RegisterAddr, uint16_t NumByteToWrite)
Wolfgang Betz 4:566f2c41dc1d 153 {
Wolfgang Betz 4:566f2c41dc1d 154 int ret = dev_i2c.i2c_write(pBuffer,
Wolfgang Betz 4:566f2c41dc1d 155 HTS221_ADDRESS,
Wolfgang Betz 4:566f2c41dc1d 156 RegisterAddr,
Wolfgang Betz 4:566f2c41dc1d 157 NumByteToWrite);
Wolfgang Betz 4:566f2c41dc1d 158 if(ret != 0) {
Wolfgang Betz 4:566f2c41dc1d 159 return HUM_TEMP_ERROR;
Wolfgang Betz 4:566f2c41dc1d 160 }
Wolfgang Betz 4:566f2c41dc1d 161 return HUM_TEMP_OK;
Wolfgang Betz 4:566f2c41dc1d 162 }
Wolfgang Betz 4:566f2c41dc1d 163
Wolfgang Betz 4:566f2c41dc1d 164 /*** Instance Variables ***/
Wolfgang Betz 4:566f2c41dc1d 165 /* IO Device */
Wolfgang Betz 4:566f2c41dc1d 166 DevI2C &dev_i2c;
Wolfgang Betz 4:566f2c41dc1d 167
Wolfgang Betz 4:566f2c41dc1d 168 /* Temperature in degree for calibration */
Wolfgang Betz 4:566f2c41dc1d 169 float T0_degC, T1_degC;
Wolfgang Betz 4:566f2c41dc1d 170
Wolfgang Betz 4:566f2c41dc1d 171 /* Output temperature value for calibration */
Wolfgang Betz 4:566f2c41dc1d 172 int16_t T0_out, T1_out;
Wolfgang Betz 4:566f2c41dc1d 173
Wolfgang Betz 4:566f2c41dc1d 174 /* Humidity for calibration */
Wolfgang Betz 4:566f2c41dc1d 175 float H0_rh, H1_rh;
Wolfgang Betz 4:566f2c41dc1d 176
Wolfgang Betz 4:566f2c41dc1d 177 /* Output Humidity value for calibration */
Wolfgang Betz 4:566f2c41dc1d 178 int16_t H0_T0_out, H1_T0_out;
Wolfgang Betz 4:566f2c41dc1d 179 };
Wolfgang Betz 4:566f2c41dc1d 180
Wolfgang Betz 4:566f2c41dc1d 181 #endif // __HTS221_CLASS_H