Example of free fall detection for LSM6DSL in X-NUCLEO-IKS01A2

Dependencies:   X_NUCLEO_IKS01A2 mbed

Fork of FreeFall_IKS01A2 by ST Expansion SW Team

Free Fall Detection Demo Application based on sensor expansion board X-NUCLEO-IKS01A2

Main function is to show how to detect the free fall event using the sensor expansion board and send a notification using UART to a connected PC or Desktop and display it on terminal applications like TeraTerm.
After connection has been established:
- the user can try to leave falling the board and then view the notification using an hyper terminal. When the free fall is detected, the LED is switched on for a while.
- the user button can be used to enable/disable the free fall detection feature.

Committer:
cparata
Date:
Fri Aug 12 13:39:06 2016 +0000
Revision:
0:6a670fda63c2
First release of Free Fall for LSM6DSL in IKS01A2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cparata 0:6a670fda63c2 1 /**
cparata 0:6a670fda63c2 2 ******************************************************************************
cparata 0:6a670fda63c2 3 * @file HTS221_Driver.h
cparata 0:6a670fda63c2 4 * @author HESA Application Team
cparata 0:6a670fda63c2 5 * @version V1.1
cparata 0:6a670fda63c2 6 * @date 10-August-2016
cparata 0:6a670fda63c2 7 * @brief HTS221 driver header file
cparata 0:6a670fda63c2 8 ******************************************************************************
cparata 0:6a670fda63c2 9 * @attention
cparata 0:6a670fda63c2 10 *
cparata 0:6a670fda63c2 11 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
cparata 0:6a670fda63c2 12 *
cparata 0:6a670fda63c2 13 * Redistribution and use in source and binary forms, with or without modification,
cparata 0:6a670fda63c2 14 * are permitted provided that the following conditions are met:
cparata 0:6a670fda63c2 15 * 1. Redistributions of source code must retain the above copyright notice,
cparata 0:6a670fda63c2 16 * this list of conditions and the following disclaimer.
cparata 0:6a670fda63c2 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
cparata 0:6a670fda63c2 18 * this list of conditions and the following disclaimer in the documentation
cparata 0:6a670fda63c2 19 * and/or other materials provided with the distribution.
cparata 0:6a670fda63c2 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
cparata 0:6a670fda63c2 21 * may be used to endorse or promote products derived from this software
cparata 0:6a670fda63c2 22 * without specific prior written permission.
cparata 0:6a670fda63c2 23 *
cparata 0:6a670fda63c2 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
cparata 0:6a670fda63c2 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
cparata 0:6a670fda63c2 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
cparata 0:6a670fda63c2 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
cparata 0:6a670fda63c2 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
cparata 0:6a670fda63c2 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
cparata 0:6a670fda63c2 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
cparata 0:6a670fda63c2 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
cparata 0:6a670fda63c2 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
cparata 0:6a670fda63c2 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cparata 0:6a670fda63c2 34 *
cparata 0:6a670fda63c2 35 ******************************************************************************
cparata 0:6a670fda63c2 36 */
cparata 0:6a670fda63c2 37
cparata 0:6a670fda63c2 38 /* Define to prevent recursive inclusion -------------------------------------*/
cparata 0:6a670fda63c2 39 #ifndef __HTS221_DRIVER__H
cparata 0:6a670fda63c2 40 #define __HTS221_DRIVER__H
cparata 0:6a670fda63c2 41
cparata 0:6a670fda63c2 42 #include <stdint.h>
cparata 0:6a670fda63c2 43
cparata 0:6a670fda63c2 44 #ifdef __cplusplus
cparata 0:6a670fda63c2 45 extern "C" {
cparata 0:6a670fda63c2 46 #endif
cparata 0:6a670fda63c2 47
cparata 0:6a670fda63c2 48 /* Uncomment the line below to expanse the "assert_param" macro in the drivers code */
cparata 0:6a670fda63c2 49 #define USE_FULL_ASSERT_HTS221
cparata 0:6a670fda63c2 50
cparata 0:6a670fda63c2 51 /* Exported macro ------------------------------------------------------------*/
cparata 0:6a670fda63c2 52 #ifdef USE_FULL_ASSERT_HTS221
cparata 0:6a670fda63c2 53
cparata 0:6a670fda63c2 54 /**
cparata 0:6a670fda63c2 55 * @brief The assert_param macro is used for function's parameters check.
cparata 0:6a670fda63c2 56 * @param expr: If expr is false, it calls assert_failed function which reports
cparata 0:6a670fda63c2 57 * the name of the source file and the source line number of the call
cparata 0:6a670fda63c2 58 * that failed. If expr is true, it returns no value.
cparata 0:6a670fda63c2 59 * @retval None
cparata 0:6a670fda63c2 60 */
cparata 0:6a670fda63c2 61 #define HTS221_assert_param(expr) ((expr) ? (void)0 : HTS221_assert_failed((uint8_t *)__FILE__, __LINE__))
cparata 0:6a670fda63c2 62 /* Exported functions ------------------------------------------------------- */
cparata 0:6a670fda63c2 63 void HTS221_assert_failed(uint8_t* file, uint32_t line);
cparata 0:6a670fda63c2 64 #else
cparata 0:6a670fda63c2 65 #define HTS221_assert_param(expr) ((void)0)
cparata 0:6a670fda63c2 66 #endif /* USE_FULL_ASSERT_HTS221 */
cparata 0:6a670fda63c2 67
cparata 0:6a670fda63c2 68 /** @addtogroup Environmental_Sensor
cparata 0:6a670fda63c2 69 * @{
cparata 0:6a670fda63c2 70 */
cparata 0:6a670fda63c2 71
cparata 0:6a670fda63c2 72 /** @addtogroup HTS221_DRIVER
cparata 0:6a670fda63c2 73 * @{
cparata 0:6a670fda63c2 74 */
cparata 0:6a670fda63c2 75
cparata 0:6a670fda63c2 76 /* Exported Types -------------------------------------------------------------*/
cparata 0:6a670fda63c2 77 /** @defgroup HTS221_Exported_Types
cparata 0:6a670fda63c2 78 * @{
cparata 0:6a670fda63c2 79 */
cparata 0:6a670fda63c2 80
cparata 0:6a670fda63c2 81
cparata 0:6a670fda63c2 82 /**
cparata 0:6a670fda63c2 83 * @brief Error code type.
cparata 0:6a670fda63c2 84 */
cparata 0:6a670fda63c2 85 typedef enum {HTS221_OK = (uint8_t)0, HTS221_ERROR = !HTS221_OK} HTS221_Error_et;
cparata 0:6a670fda63c2 86
cparata 0:6a670fda63c2 87 /**
cparata 0:6a670fda63c2 88 * @brief State type.
cparata 0:6a670fda63c2 89 */
cparata 0:6a670fda63c2 90 typedef enum {HTS221_DISABLE = (uint8_t)0, HTS221_ENABLE = !HTS221_DISABLE} HTS221_State_et;
cparata 0:6a670fda63c2 91 #define IS_HTS221_State(MODE) ((MODE == HTS221_ENABLE) || (MODE == HTS221_DISABLE))
cparata 0:6a670fda63c2 92
cparata 0:6a670fda63c2 93 /**
cparata 0:6a670fda63c2 94 * @brief Bit status type.
cparata 0:6a670fda63c2 95 */
cparata 0:6a670fda63c2 96 typedef enum {HTS221_RESET = (uint8_t)0, HTS221_SET = !HTS221_RESET} HTS221_BitStatus_et;
cparata 0:6a670fda63c2 97 #define IS_HTS221_BitStatus(MODE) ((MODE == HTS221_RESET) || (MODE == HTS221_SET))
cparata 0:6a670fda63c2 98
cparata 0:6a670fda63c2 99 /**
cparata 0:6a670fda63c2 100 * @brief Humidity average.
cparata 0:6a670fda63c2 101 */
cparata 0:6a670fda63c2 102 typedef enum
cparata 0:6a670fda63c2 103 {
cparata 0:6a670fda63c2 104 HTS221_AVGH_4 = (uint8_t)0x00, /*!< Internal average on 4 samples */
cparata 0:6a670fda63c2 105 HTS221_AVGH_8 = (uint8_t)0x01, /*!< Internal average on 8 samples */
cparata 0:6a670fda63c2 106 HTS221_AVGH_16 = (uint8_t)0x02, /*!< Internal average on 16 samples */
cparata 0:6a670fda63c2 107 HTS221_AVGH_32 = (uint8_t)0x03, /*!< Internal average on 32 samples */
cparata 0:6a670fda63c2 108 HTS221_AVGH_64 = (uint8_t)0x04, /*!< Internal average on 64 samples */
cparata 0:6a670fda63c2 109 HTS221_AVGH_128 = (uint8_t)0x05, /*!< Internal average on 128 samples */
cparata 0:6a670fda63c2 110 HTS221_AVGH_256 = (uint8_t)0x06, /*!< Internal average on 256 samples */
cparata 0:6a670fda63c2 111 HTS221_AVGH_512 = (uint8_t)0x07 /*!< Internal average on 512 samples */
cparata 0:6a670fda63c2 112 } HTS221_Avgh_et;
cparata 0:6a670fda63c2 113 #define IS_HTS221_AVGH(AVGH) ((AVGH == HTS221_AVGH_4) || (AVGH == HTS221_AVGH_8) || \
cparata 0:6a670fda63c2 114 (AVGH == HTS221_AVGH_16) || (AVGH == HTS221_AVGH_32) || \
cparata 0:6a670fda63c2 115 (AVGH == HTS221_AVGH_64) || (AVGH == HTS221_AVGH_128) || \
cparata 0:6a670fda63c2 116 (AVGH == HTS221_AVGH_256) || (AVGH == HTS221_AVGH_512))
cparata 0:6a670fda63c2 117
cparata 0:6a670fda63c2 118 /**
cparata 0:6a670fda63c2 119 * @brief Temperature average.
cparata 0:6a670fda63c2 120 */
cparata 0:6a670fda63c2 121 typedef enum
cparata 0:6a670fda63c2 122 {
cparata 0:6a670fda63c2 123 HTS221_AVGT_2 = (uint8_t)0x00, /*!< Internal average on 2 samples */
cparata 0:6a670fda63c2 124 HTS221_AVGT_4 = (uint8_t)0x08, /*!< Internal average on 4 samples */
cparata 0:6a670fda63c2 125 HTS221_AVGT_8 = (uint8_t)0x10, /*!< Internal average on 8 samples */
cparata 0:6a670fda63c2 126 HTS221_AVGT_16 = (uint8_t)0x18, /*!< Internal average on 16 samples */
cparata 0:6a670fda63c2 127 HTS221_AVGT_32 = (uint8_t)0x20, /*!< Internal average on 32 samples */
cparata 0:6a670fda63c2 128 HTS221_AVGT_64 = (uint8_t)0x28, /*!< Internal average on 64 samples */
cparata 0:6a670fda63c2 129 HTS221_AVGT_128 = (uint8_t)0x30, /*!< Internal average on 128 samples */
cparata 0:6a670fda63c2 130 HTS221_AVGT_256 = (uint8_t)0x38 /*!< Internal average on 256 samples */
cparata 0:6a670fda63c2 131 } HTS221_Avgt_et;
cparata 0:6a670fda63c2 132 #define IS_HTS221_AVGT(AVGT) ((AVGT == HTS221_AVGT_2) || (AVGT == HTS221_AVGT_4) || \
cparata 0:6a670fda63c2 133 (AVGT == HTS221_AVGT_8) || (AVGT == HTS221_AVGT_16) || \
cparata 0:6a670fda63c2 134 (AVGT == HTS221_AVGT_32) || (AVGT == HTS221_AVGT_64) || \
cparata 0:6a670fda63c2 135 (AVGT == HTS221_AVGT_128) || (AVGT == HTS221_AVGT_256))
cparata 0:6a670fda63c2 136
cparata 0:6a670fda63c2 137 /**
cparata 0:6a670fda63c2 138 * @brief Output data rate configuration.
cparata 0:6a670fda63c2 139 */
cparata 0:6a670fda63c2 140 typedef enum
cparata 0:6a670fda63c2 141 {
cparata 0:6a670fda63c2 142 HTS221_ODR_ONE_SHOT = (uint8_t)0x00, /*!< Output Data Rate: one shot */
cparata 0:6a670fda63c2 143 HTS221_ODR_1HZ = (uint8_t)0x01, /*!< Output Data Rate: 1Hz */
cparata 0:6a670fda63c2 144 HTS221_ODR_7HZ = (uint8_t)0x02, /*!< Output Data Rate: 7Hz */
cparata 0:6a670fda63c2 145 HTS221_ODR_12_5HZ = (uint8_t)0x03, /*!< Output Data Rate: 12.5Hz */
cparata 0:6a670fda63c2 146 } HTS221_Odr_et;
cparata 0:6a670fda63c2 147 #define IS_HTS221_ODR(ODR) ((ODR == HTS221_ODR_ONE_SHOT) || (ODR == HTS221_ODR_1HZ) || \
cparata 0:6a670fda63c2 148 (ODR == HTS221_ODR_7HZ) || (ODR == HTS221_ODR_12_5HZ))
cparata 0:6a670fda63c2 149
cparata 0:6a670fda63c2 150
cparata 0:6a670fda63c2 151 /**
cparata 0:6a670fda63c2 152 * @brief Push-pull/Open Drain selection on DRDY pin.
cparata 0:6a670fda63c2 153 */
cparata 0:6a670fda63c2 154 typedef enum
cparata 0:6a670fda63c2 155 {
cparata 0:6a670fda63c2 156 HTS221_PUSHPULL = (uint8_t)0x00, /*!< DRDY pin in push pull */
cparata 0:6a670fda63c2 157 HTS221_OPENDRAIN = (uint8_t)0x40 /*!< DRDY pin in open drain */
cparata 0:6a670fda63c2 158 } HTS221_OutputType_et;
cparata 0:6a670fda63c2 159 #define IS_HTS221_OutputType(MODE) ((MODE == HTS221_PUSHPULL) || (MODE == HTS221_OPENDRAIN))
cparata 0:6a670fda63c2 160
cparata 0:6a670fda63c2 161 /**
cparata 0:6a670fda63c2 162 * @brief Active level of DRDY pin.
cparata 0:6a670fda63c2 163 */
cparata 0:6a670fda63c2 164 typedef enum
cparata 0:6a670fda63c2 165 {
cparata 0:6a670fda63c2 166 HTS221_HIGH_LVL = (uint8_t)0x00, /*!< HIGH state level for DRDY pin */
cparata 0:6a670fda63c2 167 HTS221_LOW_LVL = (uint8_t)0x80 /*!< LOW state level for DRDY pin */
cparata 0:6a670fda63c2 168 } HTS221_DrdyLevel_et;
cparata 0:6a670fda63c2 169 #define IS_HTS221_DrdyLevelType(MODE) ((MODE == HTS221_HIGH_LVL) || (MODE == HTS221_LOW_LVL))
cparata 0:6a670fda63c2 170
cparata 0:6a670fda63c2 171 /**
cparata 0:6a670fda63c2 172 * @brief Driver Version Info structure definition.
cparata 0:6a670fda63c2 173 */
cparata 0:6a670fda63c2 174 typedef struct
cparata 0:6a670fda63c2 175 {
cparata 0:6a670fda63c2 176 uint8_t Major;
cparata 0:6a670fda63c2 177 uint8_t Minor;
cparata 0:6a670fda63c2 178 uint8_t Point;
cparata 0:6a670fda63c2 179 } HTS221_DriverVersion_st;
cparata 0:6a670fda63c2 180
cparata 0:6a670fda63c2 181
cparata 0:6a670fda63c2 182 /**
cparata 0:6a670fda63c2 183 * @brief HTS221 Init structure definition.
cparata 0:6a670fda63c2 184 */
cparata 0:6a670fda63c2 185 typedef struct
cparata 0:6a670fda63c2 186 {
cparata 0:6a670fda63c2 187 HTS221_Avgh_et avg_h; /*!< Humidity average */
cparata 0:6a670fda63c2 188 HTS221_Avgt_et avg_t; /*!< Temperature average */
cparata 0:6a670fda63c2 189 HTS221_Odr_et odr; /*!< Output data rate */
cparata 0:6a670fda63c2 190 HTS221_State_et bdu_status; /*!< HTS221_ENABLE/HTS221_DISABLE the block data update */
cparata 0:6a670fda63c2 191 HTS221_State_et heater_status; /*!< HTS221_ENABLE/HTS221_DISABLE the internal heater */
cparata 0:6a670fda63c2 192
cparata 0:6a670fda63c2 193 HTS221_DrdyLevel_et irq_level; /*!< HTS221_HIGH_LVL/HTS221_LOW_LVL the level for DRDY pin */
cparata 0:6a670fda63c2 194 HTS221_OutputType_et irq_output_type; /*!< Output configuration for DRDY pin */
cparata 0:6a670fda63c2 195 HTS221_State_et irq_enable; /*!< HTS221_ENABLE/HTS221_DISABLE interrupt on DRDY pin */
cparata 0:6a670fda63c2 196 } HTS221_Init_st;
cparata 0:6a670fda63c2 197
cparata 0:6a670fda63c2 198 /**
cparata 0:6a670fda63c2 199 * @}
cparata 0:6a670fda63c2 200 */
cparata 0:6a670fda63c2 201
cparata 0:6a670fda63c2 202
cparata 0:6a670fda63c2 203 /* Exported Constants ---------------------------------------------------------*/
cparata 0:6a670fda63c2 204 /** @defgroup HTS221_Exported_Constants
cparata 0:6a670fda63c2 205 * @{
cparata 0:6a670fda63c2 206 */
cparata 0:6a670fda63c2 207
cparata 0:6a670fda63c2 208 /**
cparata 0:6a670fda63c2 209 * @brief Bitfield positioning.
cparata 0:6a670fda63c2 210 */
cparata 0:6a670fda63c2 211 #define HTS221_BIT(x) ((uint8_t)x)
cparata 0:6a670fda63c2 212
cparata 0:6a670fda63c2 213 /**
cparata 0:6a670fda63c2 214 * @brief I2C address.
cparata 0:6a670fda63c2 215 */
cparata 0:6a670fda63c2 216 #define HTS221_I2C_ADDRESS (uint8_t)0xBE
cparata 0:6a670fda63c2 217
cparata 0:6a670fda63c2 218 /**
cparata 0:6a670fda63c2 219 * @brief Driver version.
cparata 0:6a670fda63c2 220 */
cparata 0:6a670fda63c2 221 #define HTS221_DRIVER_VERSION_MAJOR (uint8_t)1
cparata 0:6a670fda63c2 222 #define HTS221_DRIVER_VERSION_MINOR (uint8_t)1
cparata 0:6a670fda63c2 223 #define HTS221_DRIVER_VERSION_POINT (uint8_t)0
cparata 0:6a670fda63c2 224
cparata 0:6a670fda63c2 225 /**
cparata 0:6a670fda63c2 226 * @addtogroup HTS221_Registers
cparata 0:6a670fda63c2 227 * @{
cparata 0:6a670fda63c2 228 */
cparata 0:6a670fda63c2 229
cparata 0:6a670fda63c2 230
cparata 0:6a670fda63c2 231 /**
cparata 0:6a670fda63c2 232 * @brief Device Identification register.
cparata 0:6a670fda63c2 233 * \code
cparata 0:6a670fda63c2 234 * Read
cparata 0:6a670fda63c2 235 * Default value: 0xBC
cparata 0:6a670fda63c2 236 * 7:0 This read-only register contains the device identifier for HTS221.
cparata 0:6a670fda63c2 237 * \endcode
cparata 0:6a670fda63c2 238 */
cparata 0:6a670fda63c2 239 #define HTS221_WHO_AM_I_REG (uint8_t)0x0F
cparata 0:6a670fda63c2 240
cparata 0:6a670fda63c2 241 /**
cparata 0:6a670fda63c2 242 * @brief Device Identification value.
cparata 0:6a670fda63c2 243 */
cparata 0:6a670fda63c2 244 #define HTS221_WHO_AM_I_VAL (uint8_t)0xBC
cparata 0:6a670fda63c2 245
cparata 0:6a670fda63c2 246
cparata 0:6a670fda63c2 247 /**
cparata 0:6a670fda63c2 248 * @brief Humidity and temperature average mode register.
cparata 0:6a670fda63c2 249 * \code
cparata 0:6a670fda63c2 250 * Read/write
cparata 0:6a670fda63c2 251 * Default value: 0x1B
cparata 0:6a670fda63c2 252 * 7:6 Reserved.
cparata 0:6a670fda63c2 253 * 5:3 AVGT2-AVGT1-AVGT0: Select the temperature internal average.
cparata 0:6a670fda63c2 254 *
cparata 0:6a670fda63c2 255 * AVGT2 | AVGT1 | AVGT0 | Nr. Internal Average
cparata 0:6a670fda63c2 256 * ----------------------------------------------------
cparata 0:6a670fda63c2 257 * 0 | 0 | 0 | 2
cparata 0:6a670fda63c2 258 * 0 | 0 | 1 | 4
cparata 0:6a670fda63c2 259 * 0 | 1 | 0 | 8
cparata 0:6a670fda63c2 260 * 0 | 1 | 1 | 16
cparata 0:6a670fda63c2 261 * 1 | 0 | 0 | 32
cparata 0:6a670fda63c2 262 * 1 | 0 | 1 | 64
cparata 0:6a670fda63c2 263 * 1 | 1 | 0 | 128
cparata 0:6a670fda63c2 264 * 1 | 1 | 1 | 256
cparata 0:6a670fda63c2 265 *
cparata 0:6a670fda63c2 266 * 2:0 AVGH2-AVGH1-AVGH0: Select humidity internal average.
cparata 0:6a670fda63c2 267 * AVGH2 | AVGH1 | AVGH0 | Nr. Internal Average
cparata 0:6a670fda63c2 268 * ------------------------------------------------------
cparata 0:6a670fda63c2 269 * 0 | 0 | 0 | 4
cparata 0:6a670fda63c2 270 * 0 | 0 | 1 | 8
cparata 0:6a670fda63c2 271 * 0 | 1 | 0 | 16
cparata 0:6a670fda63c2 272 * 0 | 1 | 1 | 32
cparata 0:6a670fda63c2 273 * 1 | 0 | 0 | 64
cparata 0:6a670fda63c2 274 * 1 | 0 | 1 | 128
cparata 0:6a670fda63c2 275 * 1 | 1 | 0 | 256
cparata 0:6a670fda63c2 276 * 1 | 1 | 1 | 512
cparata 0:6a670fda63c2 277 *
cparata 0:6a670fda63c2 278 * \endcode
cparata 0:6a670fda63c2 279 */
cparata 0:6a670fda63c2 280 #define HTS221_AV_CONF_REG (uint8_t)0x10
cparata 0:6a670fda63c2 281
cparata 0:6a670fda63c2 282 #define HTS221_AVGT_BIT HTS221_BIT(3)
cparata 0:6a670fda63c2 283 #define HTS221_AVGH_BIT HTS221_BIT(0)
cparata 0:6a670fda63c2 284
cparata 0:6a670fda63c2 285 #define HTS221_AVGH_MASK (uint8_t)0x07
cparata 0:6a670fda63c2 286 #define HTS221_AVGT_MASK (uint8_t)0x38
cparata 0:6a670fda63c2 287
cparata 0:6a670fda63c2 288 /**
cparata 0:6a670fda63c2 289 * @brief Control register 1.
cparata 0:6a670fda63c2 290 * \code
cparata 0:6a670fda63c2 291 * Read/write
cparata 0:6a670fda63c2 292 * Default value: 0x00
cparata 0:6a670fda63c2 293 * 7 PD: power down control. 0 - power down mode; 1 - active mode.
cparata 0:6a670fda63c2 294 * 6:3 Reserved.
cparata 0:6a670fda63c2 295 * 2 BDU: block data update. 0 - continuous update; 1 - output registers not updated until MSB and LSB reading.
cparata 0:6a670fda63c2 296 * 1:0 ODR1, ODR0: output data rate selection.
cparata 0:6a670fda63c2 297 *
cparata 0:6a670fda63c2 298 * ODR1 | ODR0 | Humidity output data-rate(Hz) | Pressure output data-rate(Hz)
cparata 0:6a670fda63c2 299 * ----------------------------------------------------------------------------------
cparata 0:6a670fda63c2 300 * 0 | 0 | one shot | one shot
cparata 0:6a670fda63c2 301 * 0 | 1 | 1 | 1
cparata 0:6a670fda63c2 302 * 1 | 0 | 7 | 7
cparata 0:6a670fda63c2 303 * 1 | 1 | 12.5 | 12.5
cparata 0:6a670fda63c2 304 *
cparata 0:6a670fda63c2 305 * \endcode
cparata 0:6a670fda63c2 306 */
cparata 0:6a670fda63c2 307 #define HTS221_CTRL_REG1 (uint8_t)0x20
cparata 0:6a670fda63c2 308
cparata 0:6a670fda63c2 309 #define HTS221_PD_BIT HTS221_BIT(7)
cparata 0:6a670fda63c2 310 #define HTS221_BDU_BIT HTS221_BIT(2)
cparata 0:6a670fda63c2 311 #define HTS221_ODR_BIT HTS221_BIT(0)
cparata 0:6a670fda63c2 312
cparata 0:6a670fda63c2 313 #define HTS221_PD_MASK (uint8_t)0x80
cparata 0:6a670fda63c2 314 #define HTS221_BDU_MASK (uint8_t)0x04
cparata 0:6a670fda63c2 315 #define HTS221_ODR_MASK (uint8_t)0x03
cparata 0:6a670fda63c2 316
cparata 0:6a670fda63c2 317 /**
cparata 0:6a670fda63c2 318 * @brief Control register 2.
cparata 0:6a670fda63c2 319 * \code
cparata 0:6a670fda63c2 320 * Read/write
cparata 0:6a670fda63c2 321 * Default value: 0x00
cparata 0:6a670fda63c2 322 * 7 BOOT: Reboot memory content. 0: normal mode; 1: reboot memory content. Self-cleared upon completation.
cparata 0:6a670fda63c2 323 * 6:2 Reserved.
cparata 0:6a670fda63c2 324 * 1 HEATHER: 0: heater enable; 1: heater disable.
cparata 0:6a670fda63c2 325 * 0 ONE_SHOT: 0: waiting for start of conversion; 1: start for a new dataset. Self-cleared upon completation.
cparata 0:6a670fda63c2 326 * \endcode
cparata 0:6a670fda63c2 327 */
cparata 0:6a670fda63c2 328 #define HTS221_CTRL_REG2 (uint8_t)0x21
cparata 0:6a670fda63c2 329
cparata 0:6a670fda63c2 330 #define HTS221_BOOT_BIT HTS221_BIT(7)
cparata 0:6a670fda63c2 331 #define HTS221_HEATHER_BIT HTS221_BIT(1)
cparata 0:6a670fda63c2 332 #define HTS221_ONESHOT_BIT HTS221_BIT(0)
cparata 0:6a670fda63c2 333
cparata 0:6a670fda63c2 334 #define HTS221_BOOT_MASK (uint8_t)0x80
cparata 0:6a670fda63c2 335 #define HTS221_HEATHER_MASK (uint8_t)0x02
cparata 0:6a670fda63c2 336 #define HTS221_ONE_SHOT_MASK (uint8_t)0x01
cparata 0:6a670fda63c2 337
cparata 0:6a670fda63c2 338 /**
cparata 0:6a670fda63c2 339 * @brief Control register 3.
cparata 0:6a670fda63c2 340 * \code
cparata 0:6a670fda63c2 341 * Read/write
cparata 0:6a670fda63c2 342 * Default value: 0x00
cparata 0:6a670fda63c2 343 * 7 DRDY_H_L: Interrupt edge. 0: active high, 1: active low.
cparata 0:6a670fda63c2 344 * 6 PP_OD: Push-Pull/OpenDrain selection on interrupt pads. 0: push-pull; 1: open drain.
cparata 0:6a670fda63c2 345 * 5:3 Reserved.
cparata 0:6a670fda63c2 346 * 2 DRDY: interrupt config. 0: disable, 1: enable.
cparata 0:6a670fda63c2 347 * \endcode
cparata 0:6a670fda63c2 348 */
cparata 0:6a670fda63c2 349 #define HTS221_CTRL_REG3 (uint8_t)0x22
cparata 0:6a670fda63c2 350
cparata 0:6a670fda63c2 351 #define HTS221_DRDY_H_L_BIT HTS221_BIT(7)
cparata 0:6a670fda63c2 352 #define HTS221_PP_OD_BIT HTS221_BIT(6)
cparata 0:6a670fda63c2 353 #define HTS221_DRDY_BIT HTS221_BIT(2)
cparata 0:6a670fda63c2 354
cparata 0:6a670fda63c2 355 #define HTS221_DRDY_H_L_MASK (uint8_t)0x80
cparata 0:6a670fda63c2 356 #define HTS221_PP_OD_MASK (uint8_t)0x40
cparata 0:6a670fda63c2 357 #define HTS221_DRDY_MASK (uint8_t)0x04
cparata 0:6a670fda63c2 358
cparata 0:6a670fda63c2 359 /**
cparata 0:6a670fda63c2 360 * @brief Status register.
cparata 0:6a670fda63c2 361 * \code
cparata 0:6a670fda63c2 362 * Read
cparata 0:6a670fda63c2 363 * Default value: 0x00
cparata 0:6a670fda63c2 364 * 7:2 Reserved.
cparata 0:6a670fda63c2 365 * 1 H_DA: Humidity data available. 0: new data for humidity is not yet available; 1: new data for humidity is available.
cparata 0:6a670fda63c2 366 * 0 T_DA: Temperature data available. 0: new data for temperature is not yet available; 1: new data for temperature is available.
cparata 0:6a670fda63c2 367 * \endcode
cparata 0:6a670fda63c2 368 */
cparata 0:6a670fda63c2 369 #define HTS221_STATUS_REG (uint8_t)0x27
cparata 0:6a670fda63c2 370
cparata 0:6a670fda63c2 371 #define HTS221_H_DA_BIT HTS221_BIT(1)
cparata 0:6a670fda63c2 372 #define HTS221_T_DA_BIT HTS221_BIT(0)
cparata 0:6a670fda63c2 373
cparata 0:6a670fda63c2 374 #define HTS221_HDA_MASK (uint8_t)0x02
cparata 0:6a670fda63c2 375 #define HTS221_TDA_MASK (uint8_t)0x01
cparata 0:6a670fda63c2 376
cparata 0:6a670fda63c2 377 /**
cparata 0:6a670fda63c2 378 * @brief Humidity data (LSB).
cparata 0:6a670fda63c2 379 * \code
cparata 0:6a670fda63c2 380 * Read
cparata 0:6a670fda63c2 381 * Default value: 0x00.
cparata 0:6a670fda63c2 382 * HOUT7 - HOUT0: Humidity data LSB (2's complement).
cparata 0:6a670fda63c2 383 * \endcode
cparata 0:6a670fda63c2 384 */
cparata 0:6a670fda63c2 385 #define HTS221_HR_OUT_L_REG (uint8_t)0x28
cparata 0:6a670fda63c2 386
cparata 0:6a670fda63c2 387 /**
cparata 0:6a670fda63c2 388 * @brief Humidity data (MSB).
cparata 0:6a670fda63c2 389 * \code
cparata 0:6a670fda63c2 390 * Read
cparata 0:6a670fda63c2 391 * Default value: 0x00.
cparata 0:6a670fda63c2 392 * HOUT15 - HOUT8: Humidity data MSB (2's complement).
cparata 0:6a670fda63c2 393 * \endcode
cparata 0:6a670fda63c2 394 */
cparata 0:6a670fda63c2 395 #define HTS221_HR_OUT_H_REG (uint8_t)0x29
cparata 0:6a670fda63c2 396
cparata 0:6a670fda63c2 397
cparata 0:6a670fda63c2 398 /**
cparata 0:6a670fda63c2 399 * @brief Temperature data (LSB).
cparata 0:6a670fda63c2 400 * \code
cparata 0:6a670fda63c2 401 * Read
cparata 0:6a670fda63c2 402 * Default value: 0x00.
cparata 0:6a670fda63c2 403 * TOUT7 - TOUT0: temperature data LSB.
cparata 0:6a670fda63c2 404 * \endcode
cparata 0:6a670fda63c2 405 */
cparata 0:6a670fda63c2 406 #define HTS221_TEMP_OUT_L_REG (uint8_t)0x2A
cparata 0:6a670fda63c2 407
cparata 0:6a670fda63c2 408 /**
cparata 0:6a670fda63c2 409 * @brief Temperature data (MSB).
cparata 0:6a670fda63c2 410 * \code
cparata 0:6a670fda63c2 411 * Read
cparata 0:6a670fda63c2 412 * Default value: 0x00.
cparata 0:6a670fda63c2 413 * TOUT15 - TOUT8: temperature data MSB.
cparata 0:6a670fda63c2 414 * \endcode
cparata 0:6a670fda63c2 415 */
cparata 0:6a670fda63c2 416 #define HTS221_TEMP_OUT_H_REG (uint8_t)0x2B
cparata 0:6a670fda63c2 417
cparata 0:6a670fda63c2 418 /**
cparata 0:6a670fda63c2 419 * @brief Calibration registers.
cparata 0:6a670fda63c2 420 * \code
cparata 0:6a670fda63c2 421 * Read
cparata 0:6a670fda63c2 422 * \endcode
cparata 0:6a670fda63c2 423 */
cparata 0:6a670fda63c2 424 #define HTS221_H0_RH_X2 (uint8_t)0x30
cparata 0:6a670fda63c2 425 #define HTS221_H1_RH_X2 (uint8_t)0x31
cparata 0:6a670fda63c2 426 #define HTS221_T0_DEGC_X8 (uint8_t)0x32
cparata 0:6a670fda63c2 427 #define HTS221_T1_DEGC_X8 (uint8_t)0x33
cparata 0:6a670fda63c2 428 #define HTS221_T0_T1_DEGC_H2 (uint8_t)0x35
cparata 0:6a670fda63c2 429 #define HTS221_H0_T0_OUT_L (uint8_t)0x36
cparata 0:6a670fda63c2 430 #define HTS221_H0_T0_OUT_H (uint8_t)0x37
cparata 0:6a670fda63c2 431 #define HTS221_H1_T0_OUT_L (uint8_t)0x3A
cparata 0:6a670fda63c2 432 #define HTS221_H1_T0_OUT_H (uint8_t)0x3B
cparata 0:6a670fda63c2 433 #define HTS221_T0_OUT_L (uint8_t)0x3C
cparata 0:6a670fda63c2 434 #define HTS221_T0_OUT_H (uint8_t)0x3D
cparata 0:6a670fda63c2 435 #define HTS221_T1_OUT_L (uint8_t)0x3E
cparata 0:6a670fda63c2 436 #define HTS221_T1_OUT_H (uint8_t)0x3F
cparata 0:6a670fda63c2 437
cparata 0:6a670fda63c2 438
cparata 0:6a670fda63c2 439 /**
cparata 0:6a670fda63c2 440 * @}
cparata 0:6a670fda63c2 441 */
cparata 0:6a670fda63c2 442
cparata 0:6a670fda63c2 443
cparata 0:6a670fda63c2 444 /**
cparata 0:6a670fda63c2 445 * @}
cparata 0:6a670fda63c2 446 */
cparata 0:6a670fda63c2 447
cparata 0:6a670fda63c2 448
cparata 0:6a670fda63c2 449 /* Exported Functions -------------------------------------------------------------*/
cparata 0:6a670fda63c2 450 /** @defgroup HTS221_Exported_Functions
cparata 0:6a670fda63c2 451 * @{
cparata 0:6a670fda63c2 452 */
cparata 0:6a670fda63c2 453
cparata 0:6a670fda63c2 454 HTS221_Error_et HTS221_ReadReg( void *handle, uint8_t RegAddr, uint16_t NumByteToRead, uint8_t *Data );
cparata 0:6a670fda63c2 455 HTS221_Error_et HTS221_WriteReg( void *handle, uint8_t RegAddr, uint16_t NumByteToWrite, uint8_t *Data );
cparata 0:6a670fda63c2 456
cparata 0:6a670fda63c2 457 HTS221_Error_et HTS221_Get_DriverVersion(HTS221_DriverVersion_st* version);
cparata 0:6a670fda63c2 458 HTS221_Error_et HTS221_Get_DeviceID(void *handle, uint8_t* deviceid);
cparata 0:6a670fda63c2 459
cparata 0:6a670fda63c2 460 HTS221_Error_et HTS221_Set_InitConfig(void *handle, HTS221_Init_st* pxInit);
cparata 0:6a670fda63c2 461 HTS221_Error_et HTS221_Get_InitConfig(void *handle, HTS221_Init_st* pxInit);
cparata 0:6a670fda63c2 462 HTS221_Error_et HTS221_DeInit(void *handle);
cparata 0:6a670fda63c2 463 HTS221_Error_et HTS221_IsMeasurementCompleted(void *handle, HTS221_BitStatus_et* Is_Measurement_Completed);
cparata 0:6a670fda63c2 464
cparata 0:6a670fda63c2 465 HTS221_Error_et HTS221_Get_Measurement(void *handle, uint16_t* humidity, int16_t* temperature);
cparata 0:6a670fda63c2 466 HTS221_Error_et HTS221_Get_RawMeasurement(void *handle, int16_t* humidity, int16_t* temperature);
cparata 0:6a670fda63c2 467 HTS221_Error_et HTS221_Get_Humidity(void *handle, uint16_t* value);
cparata 0:6a670fda63c2 468 HTS221_Error_et HTS221_Get_HumidityRaw(void *handle, int16_t* value);
cparata 0:6a670fda63c2 469 HTS221_Error_et HTS221_Get_TemperatureRaw(void *handle, int16_t* value);
cparata 0:6a670fda63c2 470 HTS221_Error_et HTS221_Get_Temperature(void *handle, int16_t* value);
cparata 0:6a670fda63c2 471 HTS221_Error_et HTS221_Get_DataStatus(void *handle, HTS221_BitStatus_et* humidity, HTS221_BitStatus_et* temperature);
cparata 0:6a670fda63c2 472 HTS221_Error_et HTS221_Activate(void *handle);
cparata 0:6a670fda63c2 473 HTS221_Error_et HTS221_DeActivate(void *handle);
cparata 0:6a670fda63c2 474
cparata 0:6a670fda63c2 475 HTS221_Error_et HTS221_Set_AvgHT(void *handle, HTS221_Avgh_et avgh, HTS221_Avgt_et avgt);
cparata 0:6a670fda63c2 476 HTS221_Error_et HTS221_Set_AvgH(void *handle, HTS221_Avgh_et avgh);
cparata 0:6a670fda63c2 477 HTS221_Error_et HTS221_Set_AvgT(void *handle, HTS221_Avgt_et avgt);
cparata 0:6a670fda63c2 478 HTS221_Error_et HTS221_Get_AvgHT(void *handle, HTS221_Avgh_et* avgh, HTS221_Avgt_et* avgt);
cparata 0:6a670fda63c2 479 HTS221_Error_et HTS221_Set_BduMode(void *handle, HTS221_State_et status);
cparata 0:6a670fda63c2 480 HTS221_Error_et HTS221_Get_BduMode(void *handle, HTS221_State_et* status);
cparata 0:6a670fda63c2 481 HTS221_Error_et HTS221_Set_PowerDownMode(void *handle, HTS221_BitStatus_et status);
cparata 0:6a670fda63c2 482 HTS221_Error_et HTS221_Get_PowerDownMode(void *handle, HTS221_BitStatus_et* status);
cparata 0:6a670fda63c2 483 HTS221_Error_et HTS221_Set_Odr(void *handle, HTS221_Odr_et odr);
cparata 0:6a670fda63c2 484 HTS221_Error_et HTS221_Get_Odr(void *handle, HTS221_Odr_et* odr);
cparata 0:6a670fda63c2 485 HTS221_Error_et HTS221_MemoryBoot(void *handle);
cparata 0:6a670fda63c2 486 HTS221_Error_et HTS221_Set_HeaterState(void *handle, HTS221_State_et status);
cparata 0:6a670fda63c2 487 HTS221_Error_et HTS221_Get_HeaterState(void *handle, HTS221_State_et* status);
cparata 0:6a670fda63c2 488 HTS221_Error_et HTS221_StartOneShotMeasurement(void *handle);
cparata 0:6a670fda63c2 489 HTS221_Error_et HTS221_Set_IrqActiveLevel(void *handle, HTS221_DrdyLevel_et status);
cparata 0:6a670fda63c2 490 HTS221_Error_et HTS221_Get_IrqActiveLevel(void *handle, HTS221_DrdyLevel_et* status);
cparata 0:6a670fda63c2 491 HTS221_Error_et HTS221_Set_IrqOutputType(void *handle, HTS221_OutputType_et value);
cparata 0:6a670fda63c2 492 HTS221_Error_et HTS221_Get_IrqOutputType(void *handle, HTS221_OutputType_et* value);
cparata 0:6a670fda63c2 493 HTS221_Error_et HTS221_Set_IrqEnable(void *handle, HTS221_State_et status);
cparata 0:6a670fda63c2 494 HTS221_Error_et HTS221_Get_IrqEnable(void *handle, HTS221_State_et* status);
cparata 0:6a670fda63c2 495
cparata 0:6a670fda63c2 496 /**
cparata 0:6a670fda63c2 497 * @}
cparata 0:6a670fda63c2 498 */
cparata 0:6a670fda63c2 499
cparata 0:6a670fda63c2 500 /**
cparata 0:6a670fda63c2 501 * @}
cparata 0:6a670fda63c2 502 */
cparata 0:6a670fda63c2 503
cparata 0:6a670fda63c2 504 /**
cparata 0:6a670fda63c2 505 * @}
cparata 0:6a670fda63c2 506 */
cparata 0:6a670fda63c2 507
cparata 0:6a670fda63c2 508 #ifdef __cplusplus
cparata 0:6a670fda63c2 509 }
cparata 0:6a670fda63c2 510 #endif
cparata 0:6a670fda63c2 511
cparata 0:6a670fda63c2 512 #endif /* __HTS221_DRIVER__H */
cparata 0:6a670fda63c2 513
cparata 0:6a670fda63c2 514 /******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/