Capacitive digital sensor for relative humidity and temperature.

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   X_NUCLEO_IKS01A2 HelloWorld_ST_Sensors MOTENV_Mbed mbed-os-mqtt-client ... more

Committer:
cparata
Date:
Wed Jul 24 14:17:21 2019 +0000
Revision:
5:ccf7f36492ae
Parent:
0:7917d6d00a6e
Format with Astyle

Who changed what in which revision?

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