Example of tilt detection for LSM6DSL in X-NUCLEO-IKS01A2

Dependencies:   X_NUCLEO_IKS01A2 mbed

Fork of Tilt_IKS01A2 by ST Expansion SW Team

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

Main function is to show how to detect the tilt 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 tilt the board and then view the notification using an hyper terminal. When the tilt event is detected, the LED is switched on for a while.
- the user button can be used to enable/disable the tilt detection feature.

Committer:
cparata
Date:
Fri Aug 12 13:42:49 2016 +0000
Revision:
0:489965565a0d
First release of Tilt Detection for LSM6DSL in IKS01A2

Who changed what in which revision?

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