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.c
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 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 /* Includes ------------------------------------------------------------------*/
nikapov 0:7917d6d00a6e 39 #include "HTS221_driver.h"
nikapov 0:7917d6d00a6e 40
nikapov 0:7917d6d00a6e 41 #ifdef __cplusplus
cparata 5:ccf7f36492ae 42 extern "C" {
nikapov 0:7917d6d00a6e 43 #endif
nikapov 0:7917d6d00a6e 44
nikapov 0:7917d6d00a6e 45 #ifdef USE_FULL_ASSERT_HTS221
nikapov 0:7917d6d00a6e 46 #include <stdio.h>
nikapov 0:7917d6d00a6e 47 #endif
nikapov 0:7917d6d00a6e 48
nikapov 0:7917d6d00a6e 49
nikapov 0:7917d6d00a6e 50 /** @addtogroup Environmental_Sensor
nikapov 0:7917d6d00a6e 51 * @{
nikapov 0:7917d6d00a6e 52 */
nikapov 0:7917d6d00a6e 53
nikapov 0:7917d6d00a6e 54 /** @defgroup HTS221_DRIVER
nikapov 0:7917d6d00a6e 55 * @brief HTS221 DRIVER
nikapov 0:7917d6d00a6e 56 * @{
nikapov 0:7917d6d00a6e 57 */
nikapov 0:7917d6d00a6e 58
nikapov 0:7917d6d00a6e 59 /** @defgroup HTS221_Imported_Function_Prototypes
nikapov 0:7917d6d00a6e 60 * @{
nikapov 0:7917d6d00a6e 61 */
nikapov 0:7917d6d00a6e 62
cparata 5:ccf7f36492ae 63 extern uint8_t HTS221_io_write(void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite);
cparata 5:ccf7f36492ae 64 extern uint8_t HTS221_io_read(void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead);
nikapov 0:7917d6d00a6e 65
nikapov 0:7917d6d00a6e 66 /**
nikapov 0:7917d6d00a6e 67 * @}
nikapov 0:7917d6d00a6e 68 */
nikapov 0:7917d6d00a6e 69
nikapov 0:7917d6d00a6e 70 /** @defgroup HTS221_Private_Function_Prototypes
nikapov 0:7917d6d00a6e 71 * @{
nikapov 0:7917d6d00a6e 72 */
nikapov 0:7917d6d00a6e 73
nikapov 0:7917d6d00a6e 74 /**
nikapov 0:7917d6d00a6e 75 * @}
nikapov 0:7917d6d00a6e 76 */
nikapov 0:7917d6d00a6e 77
nikapov 0:7917d6d00a6e 78 /** @defgroup HTS221_Private_Functions
nikapov 0:7917d6d00a6e 79 * @{
nikapov 0:7917d6d00a6e 80 */
nikapov 0:7917d6d00a6e 81
nikapov 0:7917d6d00a6e 82 /**
nikapov 0:7917d6d00a6e 83 * @}
nikapov 0:7917d6d00a6e 84 */
nikapov 0:7917d6d00a6e 85
nikapov 0:7917d6d00a6e 86 /** @defgroup HTS221_Public_Functions
nikapov 0:7917d6d00a6e 87 * @{
nikapov 0:7917d6d00a6e 88 */
nikapov 0:7917d6d00a6e 89
nikapov 0:7917d6d00a6e 90 /*******************************************************************************
nikapov 0:7917d6d00a6e 91 * Function Name : HTS221_read_reg
nikapov 0:7917d6d00a6e 92 * Description : Generic Reading function. It must be fullfilled with either
nikapov 0:7917d6d00a6e 93 * : I2C or SPI reading functions
nikapov 0:7917d6d00a6e 94 * Input : Register Address
nikapov 0:7917d6d00a6e 95 * Output : Data Read
nikapov 0:7917d6d00a6e 96 * Return : None
nikapov 0:7917d6d00a6e 97 *******************************************************************************/
cparata 5:ccf7f36492ae 98 HTS221_Error_et HTS221_read_reg(void *handle, uint8_t RegAddr, uint16_t NumByteToRead, uint8_t *Data)
nikapov 0:7917d6d00a6e 99 {
nikapov 0:7917d6d00a6e 100
cparata 5:ccf7f36492ae 101 if (NumByteToRead > 1) {
cparata 5:ccf7f36492ae 102 RegAddr |= 0x80;
cparata 5:ccf7f36492ae 103 }
nikapov 0:7917d6d00a6e 104
cparata 5:ccf7f36492ae 105 if (HTS221_io_read(handle, RegAddr, Data, NumByteToRead)) {
cparata 5:ccf7f36492ae 106 return HTS221_ERROR;
cparata 5:ccf7f36492ae 107 } else {
cparata 5:ccf7f36492ae 108 return HTS221_OK;
cparata 5:ccf7f36492ae 109 }
nikapov 0:7917d6d00a6e 110 }
nikapov 0:7917d6d00a6e 111
nikapov 0:7917d6d00a6e 112 /*******************************************************************************
nikapov 0:7917d6d00a6e 113 * Function Name : HTS221_write_reg
nikapov 0:7917d6d00a6e 114 * Description : Generic Writing function. It must be fullfilled with either
nikapov 0:7917d6d00a6e 115 * : I2C or SPI writing function
nikapov 0:7917d6d00a6e 116 * Input : Register Address, Data to be written
nikapov 0:7917d6d00a6e 117 * Output : None
nikapov 0:7917d6d00a6e 118 * Return : None
nikapov 0:7917d6d00a6e 119 *******************************************************************************/
cparata 5:ccf7f36492ae 120 HTS221_Error_et HTS221_write_reg(void *handle, uint8_t RegAddr, uint16_t NumByteToWrite, uint8_t *Data)
nikapov 0:7917d6d00a6e 121 {
nikapov 0:7917d6d00a6e 122
cparata 5:ccf7f36492ae 123 if (NumByteToWrite > 1) {
cparata 5:ccf7f36492ae 124 RegAddr |= 0x80;
cparata 5:ccf7f36492ae 125 }
nikapov 0:7917d6d00a6e 126
cparata 5:ccf7f36492ae 127 if (HTS221_io_write(handle, RegAddr, Data, NumByteToWrite)) {
cparata 5:ccf7f36492ae 128 return HTS221_ERROR;
cparata 5:ccf7f36492ae 129 } else {
cparata 5:ccf7f36492ae 130 return HTS221_OK;
cparata 5:ccf7f36492ae 131 }
nikapov 0:7917d6d00a6e 132 }
nikapov 0:7917d6d00a6e 133
nikapov 0:7917d6d00a6e 134 /**
nikapov 0:7917d6d00a6e 135 * @brief Get the version of this driver.
nikapov 0:7917d6d00a6e 136 * @param pxVersion pointer to a HTS221_DriverVersion_st structure that contains the version information.
nikapov 0:7917d6d00a6e 137 * This parameter is a pointer to @ref HTS221_DriverVersion_st.
nikapov 0:7917d6d00a6e 138 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 139 */
cparata 5:ccf7f36492ae 140 HTS221_Error_et HTS221_Get_DriverVersion(HTS221_DriverVersion_st *version)
nikapov 0:7917d6d00a6e 141 {
cparata 5:ccf7f36492ae 142 version->Major = HTS221_DRIVER_VERSION_MAJOR;
cparata 5:ccf7f36492ae 143 version->Minor = HTS221_DRIVER_VERSION_MINOR;
cparata 5:ccf7f36492ae 144 version->Point = HTS221_DRIVER_VERSION_POINT;
nikapov 0:7917d6d00a6e 145
cparata 5:ccf7f36492ae 146 return HTS221_OK;
nikapov 0:7917d6d00a6e 147 }
nikapov 0:7917d6d00a6e 148
nikapov 0:7917d6d00a6e 149 /**
nikapov 0:7917d6d00a6e 150 * @brief Get device type ID.
nikapov 0:7917d6d00a6e 151 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 152 * @param deviceid pointer to the returned device type ID.
nikapov 0:7917d6d00a6e 153 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 154 */
cparata 5:ccf7f36492ae 155 HTS221_Error_et HTS221_Get_DeviceID(void *handle, uint8_t *deviceid)
nikapov 0:7917d6d00a6e 156 {
cparata 5:ccf7f36492ae 157 if (HTS221_read_reg(handle, HTS221_WHO_AM_I_REG, 1, deviceid)) {
cparata 5:ccf7f36492ae 158 return HTS221_ERROR;
cparata 5:ccf7f36492ae 159 }
nikapov 0:7917d6d00a6e 160
cparata 5:ccf7f36492ae 161 return HTS221_OK;
nikapov 0:7917d6d00a6e 162 }
nikapov 0:7917d6d00a6e 163
nikapov 0:7917d6d00a6e 164 /**
nikapov 0:7917d6d00a6e 165 * @brief Initializes the HTS221 with the specified parameters in HTS221_Init_st struct.
nikapov 0:7917d6d00a6e 166 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 167 * @param pxInit pointer to a HTS221_Init_st structure that contains the configuration.
nikapov 0:7917d6d00a6e 168 * This parameter is a pointer to @ref HTS221_Init_st.
nikapov 0:7917d6d00a6e 169 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 170 */
cparata 5:ccf7f36492ae 171 HTS221_Error_et HTS221_Set_InitConfig(void *handle, HTS221_Init_st *pxInit)
nikapov 0:7917d6d00a6e 172 {
cparata 5:ccf7f36492ae 173 uint8_t buffer[3];
nikapov 0:7917d6d00a6e 174
cparata 5:ccf7f36492ae 175 HTS221_assert_param(IS_HTS221_AVGH(pxInit->avg_h));
cparata 5:ccf7f36492ae 176 HTS221_assert_param(IS_HTS221_AVGT(pxInit->avg_t));
cparata 5:ccf7f36492ae 177 HTS221_assert_param(IS_HTS221_ODR(pxInit->odr));
cparata 5:ccf7f36492ae 178 HTS221_assert_param(IS_HTS221_State(pxInit->bdu_status));
cparata 5:ccf7f36492ae 179 HTS221_assert_param(IS_HTS221_State(pxInit->heater_status));
nikapov 0:7917d6d00a6e 180
cparata 5:ccf7f36492ae 181 HTS221_assert_param(IS_HTS221_DrdyLevelType(pxInit->irq_level));
cparata 5:ccf7f36492ae 182 HTS221_assert_param(IS_HTS221_OutputType(pxInit->irq_output_type));
cparata 5:ccf7f36492ae 183 HTS221_assert_param(IS_HTS221_State(pxInit->irq_enable));
nikapov 0:7917d6d00a6e 184
cparata 5:ccf7f36492ae 185 if (HTS221_read_reg(handle, HTS221_AV_CONF_REG, 1, buffer)) {
cparata 5:ccf7f36492ae 186 return HTS221_ERROR;
cparata 5:ccf7f36492ae 187 }
nikapov 0:7917d6d00a6e 188
cparata 5:ccf7f36492ae 189 buffer[0] &= ~(HTS221_AVGH_MASK | HTS221_AVGT_MASK);
cparata 5:ccf7f36492ae 190 buffer[0] |= (uint8_t)pxInit->avg_h;
cparata 5:ccf7f36492ae 191 buffer[0] |= (uint8_t)pxInit->avg_t;
nikapov 0:7917d6d00a6e 192
cparata 5:ccf7f36492ae 193 if (HTS221_write_reg(handle, HTS221_AV_CONF_REG, 1, buffer)) {
cparata 5:ccf7f36492ae 194 return HTS221_ERROR;
cparata 5:ccf7f36492ae 195 }
nikapov 0:7917d6d00a6e 196
cparata 5:ccf7f36492ae 197 if (HTS221_read_reg(handle, HTS221_CTRL_REG1, 3, buffer)) {
cparata 5:ccf7f36492ae 198 return HTS221_ERROR;
cparata 5:ccf7f36492ae 199 }
nikapov 0:7917d6d00a6e 200
cparata 5:ccf7f36492ae 201 buffer[0] &= ~(HTS221_BDU_MASK | HTS221_ODR_MASK);
cparata 5:ccf7f36492ae 202 buffer[0] |= (uint8_t)pxInit->odr;
cparata 5:ccf7f36492ae 203 buffer[0] |= ((uint8_t)pxInit->bdu_status) << HTS221_BDU_BIT;
nikapov 0:7917d6d00a6e 204
cparata 5:ccf7f36492ae 205 buffer[1] &= ~HTS221_HEATHER_BIT;
cparata 5:ccf7f36492ae 206 buffer[1] |= ((uint8_t)pxInit->heater_status) << HTS221_HEATHER_BIT;
nikapov 0:7917d6d00a6e 207
cparata 5:ccf7f36492ae 208 buffer[2] &= ~(HTS221_DRDY_H_L_MASK | HTS221_PP_OD_MASK | HTS221_DRDY_MASK);
cparata 5:ccf7f36492ae 209 buffer[2] |= ((uint8_t)pxInit->irq_level) << HTS221_DRDY_H_L_BIT;
cparata 5:ccf7f36492ae 210 buffer[2] |= (uint8_t)pxInit->irq_output_type;
cparata 5:ccf7f36492ae 211 buffer[2] |= ((uint8_t)pxInit->irq_enable) << HTS221_DRDY_BIT;
nikapov 0:7917d6d00a6e 212
cparata 5:ccf7f36492ae 213 if (HTS221_write_reg(handle, HTS221_CTRL_REG1, 3, buffer)) {
cparata 5:ccf7f36492ae 214 return HTS221_ERROR;
cparata 5:ccf7f36492ae 215 }
nikapov 0:7917d6d00a6e 216
cparata 5:ccf7f36492ae 217 return HTS221_OK;
nikapov 0:7917d6d00a6e 218 }
nikapov 0:7917d6d00a6e 219
nikapov 0:7917d6d00a6e 220 /**
nikapov 0:7917d6d00a6e 221 * @brief Returns a HTS221_Init_st struct with the actual configuration.
nikapov 0:7917d6d00a6e 222 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 223 * @param pxInit pointer to a HTS221_Init_st structure.
nikapov 0:7917d6d00a6e 224 * This parameter is a pointer to @ref HTS221_Init_st.
nikapov 0:7917d6d00a6e 225 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 226 */
cparata 5:ccf7f36492ae 227 HTS221_Error_et HTS221_Get_InitConfig(void *handle, HTS221_Init_st *pxInit)
nikapov 0:7917d6d00a6e 228 {
cparata 5:ccf7f36492ae 229 uint8_t buffer[3];
nikapov 0:7917d6d00a6e 230
cparata 5:ccf7f36492ae 231 if (HTS221_read_reg(handle, HTS221_AV_CONF_REG, 1, buffer)) {
cparata 5:ccf7f36492ae 232 return HTS221_ERROR;
cparata 5:ccf7f36492ae 233 }
nikapov 0:7917d6d00a6e 234
cparata 5:ccf7f36492ae 235 pxInit->avg_h = (HTS221_Avgh_et)(buffer[0] & HTS221_AVGH_MASK);
cparata 5:ccf7f36492ae 236 pxInit->avg_t = (HTS221_Avgt_et)(buffer[0] & HTS221_AVGT_MASK);
nikapov 0:7917d6d00a6e 237
cparata 5:ccf7f36492ae 238 if (HTS221_read_reg(handle, HTS221_CTRL_REG1, 3, buffer)) {
cparata 5:ccf7f36492ae 239 return HTS221_ERROR;
cparata 5:ccf7f36492ae 240 }
nikapov 0:7917d6d00a6e 241
cparata 5:ccf7f36492ae 242 pxInit->odr = (HTS221_Odr_et)(buffer[0] & HTS221_ODR_MASK);
cparata 5:ccf7f36492ae 243 pxInit->bdu_status = (HTS221_State_et)((buffer[0] & HTS221_BDU_MASK) >> HTS221_BDU_BIT);
cparata 5:ccf7f36492ae 244 pxInit->heater_status = (HTS221_State_et)((buffer[1] & HTS221_HEATHER_MASK) >> HTS221_HEATHER_BIT);
nikapov 0:7917d6d00a6e 245
cparata 5:ccf7f36492ae 246 pxInit->irq_level = (HTS221_DrdyLevel_et)(buffer[2] & HTS221_DRDY_H_L_MASK);
cparata 5:ccf7f36492ae 247 pxInit->irq_output_type = (HTS221_OutputType_et)(buffer[2] & HTS221_PP_OD_MASK);
cparata 5:ccf7f36492ae 248 pxInit->irq_enable = (HTS221_State_et)((buffer[2] & HTS221_DRDY_MASK) >> HTS221_DRDY_BIT);
nikapov 0:7917d6d00a6e 249
cparata 5:ccf7f36492ae 250 return HTS221_OK;
nikapov 0:7917d6d00a6e 251 }
nikapov 0:7917d6d00a6e 252
nikapov 0:7917d6d00a6e 253 /**
nikapov 0:7917d6d00a6e 254 * @brief De initialization function for HTS221.
nikapov 0:7917d6d00a6e 255 * This function put the HTS221 in power down, make a memory boot and clear the data output flags.
nikapov 0:7917d6d00a6e 256 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 257 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 258 */
nikapov 0:7917d6d00a6e 259 HTS221_Error_et HTS221_DeInit(void *handle)
nikapov 0:7917d6d00a6e 260 {
cparata 5:ccf7f36492ae 261 uint8_t buffer[4];
nikapov 0:7917d6d00a6e 262
cparata 5:ccf7f36492ae 263 if (HTS221_read_reg(handle, HTS221_CTRL_REG1, 2, buffer)) {
cparata 5:ccf7f36492ae 264 return HTS221_ERROR;
cparata 5:ccf7f36492ae 265 }
nikapov 0:7917d6d00a6e 266
cparata 5:ccf7f36492ae 267 /* HTS221 in power down */
cparata 5:ccf7f36492ae 268 buffer[0] |= 0x01 << HTS221_PD_BIT;
nikapov 0:7917d6d00a6e 269
cparata 5:ccf7f36492ae 270 /* Make HTS221 boot */
cparata 5:ccf7f36492ae 271 buffer[1] |= 0x01 << HTS221_BOOT_BIT;
nikapov 0:7917d6d00a6e 272
cparata 5:ccf7f36492ae 273 if (HTS221_write_reg(handle, HTS221_CTRL_REG1, 2, buffer)) {
cparata 5:ccf7f36492ae 274 return HTS221_ERROR;
cparata 5:ccf7f36492ae 275 }
nikapov 0:7917d6d00a6e 276
cparata 5:ccf7f36492ae 277 /* Dump of data output */
cparata 5:ccf7f36492ae 278 if (HTS221_read_reg(handle, HTS221_HR_OUT_L_REG, 4, buffer)) {
cparata 5:ccf7f36492ae 279 return HTS221_ERROR;
cparata 5:ccf7f36492ae 280 }
nikapov 0:7917d6d00a6e 281
cparata 5:ccf7f36492ae 282 return HTS221_OK;
nikapov 0:7917d6d00a6e 283 }
nikapov 0:7917d6d00a6e 284
nikapov 0:7917d6d00a6e 285 /**
nikapov 0:7917d6d00a6e 286 * @brief Read HTS221 output registers, and calculate humidity and temperature.
nikapov 0:7917d6d00a6e 287 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 288 * @param humidity pointer to the returned humidity value that must be divided by 10 to get the value in [%].
nikapov 0:7917d6d00a6e 289 * @param temperature pointer to the returned temperature value that must be divided by 10 to get the value in ['C].
nikapov 0:7917d6d00a6e 290 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 291 */
cparata 5:ccf7f36492ae 292 HTS221_Error_et HTS221_Get_Measurement(void *handle, uint16_t *humidity, int16_t *temperature)
nikapov 0:7917d6d00a6e 293 {
cparata 5:ccf7f36492ae 294 if (HTS221_Get_Temperature(handle, temperature) == HTS221_ERROR) {
cparata 5:ccf7f36492ae 295 return HTS221_ERROR;
cparata 5:ccf7f36492ae 296 }
cparata 5:ccf7f36492ae 297 if (HTS221_Get_Humidity(handle, humidity) == HTS221_ERROR) {
cparata 5:ccf7f36492ae 298 return HTS221_ERROR;
cparata 5:ccf7f36492ae 299 }
nikapov 0:7917d6d00a6e 300
cparata 5:ccf7f36492ae 301 return HTS221_OK;
nikapov 0:7917d6d00a6e 302 }
nikapov 0:7917d6d00a6e 303
nikapov 0:7917d6d00a6e 304 /**
nikapov 0:7917d6d00a6e 305 * @brief Read HTS221 output registers. Humidity and temperature.
nikapov 0:7917d6d00a6e 306 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 307 * @param humidity pointer to the returned humidity raw value.
nikapov 0:7917d6d00a6e 308 * @param temperature pointer to the returned temperature raw value.
nikapov 0:7917d6d00a6e 309 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 310 */
cparata 5:ccf7f36492ae 311 HTS221_Error_et HTS221_Get_RawMeasurement(void *handle, int16_t *humidity, int16_t *temperature)
nikapov 0:7917d6d00a6e 312 {
cparata 5:ccf7f36492ae 313 uint8_t buffer[4];
nikapov 0:7917d6d00a6e 314
cparata 5:ccf7f36492ae 315 if (HTS221_read_reg(handle, HTS221_HR_OUT_L_REG, 4, buffer)) {
cparata 5:ccf7f36492ae 316 return HTS221_ERROR;
cparata 5:ccf7f36492ae 317 }
nikapov 0:7917d6d00a6e 318
cparata 5:ccf7f36492ae 319 *humidity = (int16_t)((((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0]);
cparata 5:ccf7f36492ae 320 *temperature = (int16_t)((((uint16_t)buffer[3]) << 8) | (uint16_t)buffer[2]);
nikapov 0:7917d6d00a6e 321
cparata 5:ccf7f36492ae 322 return HTS221_OK;
nikapov 0:7917d6d00a6e 323 }
nikapov 0:7917d6d00a6e 324
nikapov 0:7917d6d00a6e 325 /**
nikapov 0:7917d6d00a6e 326 * @brief Read HTS221 Humidity output registers, and calculate humidity.
nikapov 0:7917d6d00a6e 327 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 328 * @param Pointer to the returned humidity value that must be divided by 10 to get the value in [%].
nikapov 0:7917d6d00a6e 329 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 330 */
cparata 5:ccf7f36492ae 331 HTS221_Error_et HTS221_Get_Humidity(void *handle, uint16_t *value)
nikapov 0:7917d6d00a6e 332 {
cparata 5:ccf7f36492ae 333 int16_t H0_T0_out, H1_T0_out, H_T_out;
cparata 5:ccf7f36492ae 334 int16_t H0_rh, H1_rh;
cparata 5:ccf7f36492ae 335 uint8_t buffer[2];
cparata 5:ccf7f36492ae 336 float tmp_f;
nikapov 0:7917d6d00a6e 337
cparata 5:ccf7f36492ae 338 if (HTS221_read_reg(handle, HTS221_H0_RH_X2, 2, buffer)) {
cparata 5:ccf7f36492ae 339 return HTS221_ERROR;
cparata 5:ccf7f36492ae 340 }
cparata 5:ccf7f36492ae 341 H0_rh = buffer[0] >> 1;
cparata 5:ccf7f36492ae 342 H1_rh = buffer[1] >> 1;
nikapov 0:7917d6d00a6e 343
cparata 5:ccf7f36492ae 344 if (HTS221_read_reg(handle, HTS221_H0_T0_OUT_L, 2, buffer)) {
cparata 5:ccf7f36492ae 345 return HTS221_ERROR;
cparata 5:ccf7f36492ae 346 }
cparata 5:ccf7f36492ae 347 H0_T0_out = (((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0];
nikapov 0:7917d6d00a6e 348
cparata 5:ccf7f36492ae 349 if (HTS221_read_reg(handle, HTS221_H1_T0_OUT_L, 2, buffer)) {
cparata 5:ccf7f36492ae 350 return HTS221_ERROR;
cparata 5:ccf7f36492ae 351 }
cparata 5:ccf7f36492ae 352 H1_T0_out = (((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0];
nikapov 0:7917d6d00a6e 353
cparata 5:ccf7f36492ae 354 if (HTS221_read_reg(handle, HTS221_HR_OUT_L_REG, 2, buffer)) {
cparata 5:ccf7f36492ae 355 return HTS221_ERROR;
cparata 5:ccf7f36492ae 356 }
cparata 5:ccf7f36492ae 357 H_T_out = (((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0];
nikapov 0:7917d6d00a6e 358
cparata 5:ccf7f36492ae 359 tmp_f = (float)(H_T_out - H0_T0_out) * (float)(H1_rh - H0_rh) / (float)(H1_T0_out - H0_T0_out) + H0_rh;
cparata 5:ccf7f36492ae 360 tmp_f *= 10.0f;
nikapov 0:7917d6d00a6e 361
cparata 5:ccf7f36492ae 362 *value = (tmp_f > 1000.0f) ? 1000
cparata 5:ccf7f36492ae 363 : (tmp_f < 0.0f) ? 0
cparata 5:ccf7f36492ae 364 : (uint16_t)tmp_f;
cparata 5:ccf7f36492ae 365
cparata 5:ccf7f36492ae 366 return HTS221_OK;
nikapov 0:7917d6d00a6e 367 }
nikapov 0:7917d6d00a6e 368
nikapov 0:7917d6d00a6e 369 /**
nikapov 0:7917d6d00a6e 370 * @brief Read HTS221 humidity output registers.
nikapov 0:7917d6d00a6e 371 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 372 * @param Pointer to the returned humidity raw value.
nikapov 0:7917d6d00a6e 373 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 374 */
cparata 5:ccf7f36492ae 375 HTS221_Error_et HTS221_Get_HumidityRaw(void *handle, int16_t *value)
nikapov 0:7917d6d00a6e 376 {
cparata 5:ccf7f36492ae 377 uint8_t buffer[2];
nikapov 0:7917d6d00a6e 378
cparata 5:ccf7f36492ae 379 if (HTS221_read_reg(handle, HTS221_HR_OUT_L_REG, 2, buffer)) {
cparata 5:ccf7f36492ae 380 return HTS221_ERROR;
cparata 5:ccf7f36492ae 381 }
nikapov 0:7917d6d00a6e 382
cparata 5:ccf7f36492ae 383 *value = (int16_t)((((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0]);
nikapov 0:7917d6d00a6e 384
cparata 5:ccf7f36492ae 385 return HTS221_OK;
nikapov 0:7917d6d00a6e 386 }
nikapov 0:7917d6d00a6e 387
nikapov 0:7917d6d00a6e 388 /**
nikapov 0:7917d6d00a6e 389 * @brief Read HTS221 temperature output registers, and calculate temperature.
nikapov 0:7917d6d00a6e 390 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 391 * @param Pointer to the returned temperature value that must be divided by 10 to get the value in ['C].
nikapov 0:7917d6d00a6e 392 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 393 */
nikapov 0:7917d6d00a6e 394 HTS221_Error_et HTS221_Get_Temperature(void *handle, int16_t *value)
nikapov 0:7917d6d00a6e 395 {
cparata 5:ccf7f36492ae 396 int16_t T0_out, T1_out, T_out, T0_degC_x8_u16, T1_degC_x8_u16;
cparata 5:ccf7f36492ae 397 int16_t T0_degC, T1_degC;
cparata 5:ccf7f36492ae 398 uint8_t buffer[4], tmp;
cparata 5:ccf7f36492ae 399 float tmp_f;
nikapov 0:7917d6d00a6e 400
cparata 5:ccf7f36492ae 401 if (HTS221_read_reg(handle, HTS221_T0_DEGC_X8, 2, buffer)) {
cparata 5:ccf7f36492ae 402 return HTS221_ERROR;
cparata 5:ccf7f36492ae 403 }
cparata 5:ccf7f36492ae 404 if (HTS221_read_reg(handle, HTS221_T0_T1_DEGC_H2, 1, &tmp)) {
cparata 5:ccf7f36492ae 405 return HTS221_ERROR;
cparata 5:ccf7f36492ae 406 }
nikapov 0:7917d6d00a6e 407
cparata 5:ccf7f36492ae 408 T0_degC_x8_u16 = (((uint16_t)(tmp & 0x03)) << 8) | ((uint16_t)buffer[0]);
cparata 5:ccf7f36492ae 409 T1_degC_x8_u16 = (((uint16_t)(tmp & 0x0C)) << 6) | ((uint16_t)buffer[1]);
cparata 5:ccf7f36492ae 410 T0_degC = T0_degC_x8_u16 >> 3;
cparata 5:ccf7f36492ae 411 T1_degC = T1_degC_x8_u16 >> 3;
nikapov 0:7917d6d00a6e 412
cparata 5:ccf7f36492ae 413 if (HTS221_read_reg(handle, HTS221_T0_OUT_L, 4, buffer)) {
cparata 5:ccf7f36492ae 414 return HTS221_ERROR;
cparata 5:ccf7f36492ae 415 }
nikapov 0:7917d6d00a6e 416
cparata 5:ccf7f36492ae 417 T0_out = (((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0];
cparata 5:ccf7f36492ae 418 T1_out = (((uint16_t)buffer[3]) << 8) | (uint16_t)buffer[2];
nikapov 0:7917d6d00a6e 419
cparata 5:ccf7f36492ae 420 if (HTS221_read_reg(handle, HTS221_TEMP_OUT_L_REG, 2, buffer)) {
cparata 5:ccf7f36492ae 421 return HTS221_ERROR;
cparata 5:ccf7f36492ae 422 }
cparata 5:ccf7f36492ae 423
cparata 5:ccf7f36492ae 424 T_out = (((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0];
nikapov 0:7917d6d00a6e 425
cparata 5:ccf7f36492ae 426 tmp_f = (float)(T_out - T0_out) * (float)(T1_degC - T0_degC) / (float)(T1_out - T0_out) + T0_degC;
cparata 5:ccf7f36492ae 427 tmp_f *= 10.0f;
nikapov 0:7917d6d00a6e 428
cparata 5:ccf7f36492ae 429 *value = (int16_t)tmp_f;
nikapov 0:7917d6d00a6e 430
cparata 5:ccf7f36492ae 431 return HTS221_OK;
nikapov 0:7917d6d00a6e 432 }
nikapov 0:7917d6d00a6e 433
nikapov 0:7917d6d00a6e 434 /**
nikapov 0:7917d6d00a6e 435 * @brief Read HTS221 temperature output registers.
nikapov 0:7917d6d00a6e 436 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 437 * @param Pointer to the returned temperature raw value.
nikapov 0:7917d6d00a6e 438 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 439 */
cparata 5:ccf7f36492ae 440 HTS221_Error_et HTS221_Get_TemperatureRaw(void *handle, int16_t *value)
nikapov 0:7917d6d00a6e 441 {
cparata 5:ccf7f36492ae 442 uint8_t buffer[2];
nikapov 0:7917d6d00a6e 443
cparata 5:ccf7f36492ae 444 if (HTS221_read_reg(handle, HTS221_TEMP_OUT_L_REG, 2, buffer)) {
cparata 5:ccf7f36492ae 445 return HTS221_ERROR;
cparata 5:ccf7f36492ae 446 }
nikapov 0:7917d6d00a6e 447
cparata 5:ccf7f36492ae 448 *value = (int16_t)((((uint16_t)buffer[1]) << 8) | (uint16_t)buffer[0]);
nikapov 0:7917d6d00a6e 449
cparata 5:ccf7f36492ae 450 return HTS221_OK;
nikapov 0:7917d6d00a6e 451 }
nikapov 0:7917d6d00a6e 452
nikapov 0:7917d6d00a6e 453 /**
nikapov 0:7917d6d00a6e 454 * @brief Get the availability of new data for humidity and temperature.
nikapov 0:7917d6d00a6e 455 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 456 * @param humidity pointer to the returned humidity data status [HTS221_SET/HTS221_RESET].
nikapov 0:7917d6d00a6e 457 * @param temperature pointer to the returned temperature data status [HTS221_SET/HTS221_RESET].
nikapov 0:7917d6d00a6e 458 * This parameter is a pointer to @ref HTS221_BitStatus_et.
nikapov 0:7917d6d00a6e 459 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 460 */
cparata 5:ccf7f36492ae 461 HTS221_Error_et HTS221_Get_DataStatus(void *handle, HTS221_BitStatus_et *humidity, HTS221_BitStatus_et *temperature)
nikapov 0:7917d6d00a6e 462 {
cparata 5:ccf7f36492ae 463 uint8_t tmp;
nikapov 0:7917d6d00a6e 464
cparata 5:ccf7f36492ae 465 if (HTS221_read_reg(handle, HTS221_STATUS_REG, 1, &tmp)) {
cparata 5:ccf7f36492ae 466 return HTS221_ERROR;
cparata 5:ccf7f36492ae 467 }
nikapov 0:7917d6d00a6e 468
cparata 5:ccf7f36492ae 469 *humidity = (HTS221_BitStatus_et)((tmp & HTS221_HDA_MASK) >> HTS221_H_DA_BIT);
cparata 5:ccf7f36492ae 470 *temperature = (HTS221_BitStatus_et)(tmp & HTS221_TDA_MASK);
nikapov 0:7917d6d00a6e 471
cparata 5:ccf7f36492ae 472 return HTS221_OK;
nikapov 0:7917d6d00a6e 473 }
nikapov 0:7917d6d00a6e 474
nikapov 0:7917d6d00a6e 475 /**
nikapov 0:7917d6d00a6e 476 * @brief Exit from power down mode.
nikapov 0:7917d6d00a6e 477 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 478 * @param void.
nikapov 0:7917d6d00a6e 479 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 480 */
nikapov 0:7917d6d00a6e 481 HTS221_Error_et HTS221_Activate(void *handle)
nikapov 0:7917d6d00a6e 482 {
cparata 5:ccf7f36492ae 483 uint8_t tmp;
nikapov 0:7917d6d00a6e 484
cparata 5:ccf7f36492ae 485 if (HTS221_read_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) {
cparata 5:ccf7f36492ae 486 return HTS221_ERROR;
cparata 5:ccf7f36492ae 487 }
nikapov 0:7917d6d00a6e 488
cparata 5:ccf7f36492ae 489 tmp |= HTS221_PD_MASK;
nikapov 0:7917d6d00a6e 490
cparata 5:ccf7f36492ae 491 if (HTS221_write_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) {
cparata 5:ccf7f36492ae 492 return HTS221_ERROR;
cparata 5:ccf7f36492ae 493 }
nikapov 0:7917d6d00a6e 494
cparata 5:ccf7f36492ae 495 return HTS221_OK;
nikapov 0:7917d6d00a6e 496 }
nikapov 0:7917d6d00a6e 497
nikapov 0:7917d6d00a6e 498 /**
nikapov 0:7917d6d00a6e 499 * @brief Put the sensor in power down mode.
nikapov 0:7917d6d00a6e 500 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 501 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 502 */
nikapov 0:7917d6d00a6e 503 HTS221_Error_et HTS221_DeActivate(void *handle)
nikapov 0:7917d6d00a6e 504 {
cparata 5:ccf7f36492ae 505 uint8_t tmp;
nikapov 0:7917d6d00a6e 506
cparata 5:ccf7f36492ae 507 if (HTS221_read_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) {
cparata 5:ccf7f36492ae 508 return HTS221_ERROR;
cparata 5:ccf7f36492ae 509 }
nikapov 0:7917d6d00a6e 510
cparata 5:ccf7f36492ae 511 tmp &= ~HTS221_PD_MASK;
nikapov 0:7917d6d00a6e 512
cparata 5:ccf7f36492ae 513 if (HTS221_write_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) {
cparata 5:ccf7f36492ae 514 return HTS221_ERROR;
cparata 5:ccf7f36492ae 515 }
nikapov 0:7917d6d00a6e 516
cparata 5:ccf7f36492ae 517 return HTS221_OK;
nikapov 0:7917d6d00a6e 518 }
nikapov 0:7917d6d00a6e 519
nikapov 0:7917d6d00a6e 520
nikapov 0:7917d6d00a6e 521
nikapov 0:7917d6d00a6e 522 /**
nikapov 0:7917d6d00a6e 523 * @brief Check if the single measurement has completed.
nikapov 0:7917d6d00a6e 524 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 525 * @param tmp is set to 1, when the measure is completed
nikapov 0:7917d6d00a6e 526 * @retval Status [HTS221_ERROR, HTS221_OK]
nikapov 0:7917d6d00a6e 527 */
cparata 5:ccf7f36492ae 528 HTS221_Error_et HTS221_IsMeasurementCompleted(void *handle, HTS221_BitStatus_et *Is_Measurement_Completed)
nikapov 0:7917d6d00a6e 529 {
cparata 5:ccf7f36492ae 530 uint8_t tmp;
nikapov 0:7917d6d00a6e 531
cparata 5:ccf7f36492ae 532 if (HTS221_read_reg(handle, HTS221_STATUS_REG, 1, &tmp)) {
cparata 5:ccf7f36492ae 533 return HTS221_ERROR;
cparata 5:ccf7f36492ae 534 }
nikapov 0:7917d6d00a6e 535
cparata 5:ccf7f36492ae 536 if ((tmp & (uint8_t)(HTS221_HDA_MASK | HTS221_TDA_MASK)) == (uint8_t)(HTS221_HDA_MASK | HTS221_TDA_MASK)) {
cparata 5:ccf7f36492ae 537 *Is_Measurement_Completed = HTS221_SET;
cparata 5:ccf7f36492ae 538 } else {
cparata 5:ccf7f36492ae 539 *Is_Measurement_Completed = HTS221_RESET;
cparata 5:ccf7f36492ae 540 }
nikapov 0:7917d6d00a6e 541
cparata 5:ccf7f36492ae 542 return HTS221_OK;
nikapov 0:7917d6d00a6e 543 }
nikapov 0:7917d6d00a6e 544
nikapov 0:7917d6d00a6e 545
nikapov 0:7917d6d00a6e 546 /**
nikapov 0:7917d6d00a6e 547 * @brief Set_ humidity and temperature average mode.
nikapov 0:7917d6d00a6e 548 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 549 * @param avgh is the average mode for humidity, this parameter is @ref HTS221_Avgh_et.
nikapov 0:7917d6d00a6e 550 * @param avgt is the average mode for temperature, this parameter is @ref HTS221_Avgt_et.
nikapov 0:7917d6d00a6e 551 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 552 */
nikapov 0:7917d6d00a6e 553 HTS221_Error_et HTS221_Set_AvgHT(void *handle, HTS221_Avgh_et avgh, HTS221_Avgt_et avgt)
nikapov 0:7917d6d00a6e 554 {
cparata 5:ccf7f36492ae 555 uint8_t tmp;
nikapov 0:7917d6d00a6e 556
cparata 5:ccf7f36492ae 557 HTS221_assert_param(IS_HTS221_AVGH(avgh));
cparata 5:ccf7f36492ae 558 HTS221_assert_param(IS_HTS221_AVGT(avgt));
nikapov 0:7917d6d00a6e 559
cparata 5:ccf7f36492ae 560 if (HTS221_read_reg(handle, HTS221_AV_CONF_REG, 1, &tmp)) {
cparata 5:ccf7f36492ae 561 return HTS221_ERROR;
cparata 5:ccf7f36492ae 562 }
nikapov 0:7917d6d00a6e 563
cparata 5:ccf7f36492ae 564 tmp &= ~(HTS221_AVGH_MASK | HTS221_AVGT_MASK);
cparata 5:ccf7f36492ae 565 tmp |= (uint8_t)avgh;
cparata 5:ccf7f36492ae 566 tmp |= (uint8_t)avgt;
nikapov 0:7917d6d00a6e 567
cparata 5:ccf7f36492ae 568 if (HTS221_write_reg(handle, HTS221_AV_CONF_REG, 1, &tmp)) {
cparata 5:ccf7f36492ae 569 return HTS221_ERROR;
cparata 5:ccf7f36492ae 570 }
nikapov 0:7917d6d00a6e 571
cparata 5:ccf7f36492ae 572 return HTS221_OK;
nikapov 0:7917d6d00a6e 573 }
nikapov 0:7917d6d00a6e 574
nikapov 0:7917d6d00a6e 575 /**
nikapov 0:7917d6d00a6e 576 * @brief Set humidity average mode.
nikapov 0:7917d6d00a6e 577 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 578 * @param avgh is the average mode for humidity, this parameter is @ref HTS221_Avgh_et.
nikapov 0:7917d6d00a6e 579 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 580 */
nikapov 0:7917d6d00a6e 581 HTS221_Error_et HTS221_Set_AvgH(void *handle, HTS221_Avgh_et avgh)
nikapov 0:7917d6d00a6e 582 {
cparata 5:ccf7f36492ae 583 uint8_t tmp;
cparata 5:ccf7f36492ae 584
cparata 5:ccf7f36492ae 585 HTS221_assert_param(IS_HTS221_AVGH(avgh));
nikapov 0:7917d6d00a6e 586
cparata 5:ccf7f36492ae 587 if (HTS221_read_reg(handle, HTS221_AV_CONF_REG, 1, &tmp)) {
cparata 5:ccf7f36492ae 588 return HTS221_ERROR;
cparata 5:ccf7f36492ae 589 }
nikapov 0:7917d6d00a6e 590
cparata 5:ccf7f36492ae 591 tmp &= ~HTS221_AVGH_MASK;
cparata 5:ccf7f36492ae 592 tmp |= (uint8_t)avgh;
nikapov 0:7917d6d00a6e 593
cparata 5:ccf7f36492ae 594 if (HTS221_write_reg(handle, HTS221_AV_CONF_REG, 1, &tmp)) {
cparata 5:ccf7f36492ae 595 return HTS221_ERROR;
cparata 5:ccf7f36492ae 596 }
nikapov 0:7917d6d00a6e 597
cparata 5:ccf7f36492ae 598 return HTS221_OK;
nikapov 0:7917d6d00a6e 599 }
nikapov 0:7917d6d00a6e 600
nikapov 0:7917d6d00a6e 601 /**
nikapov 0:7917d6d00a6e 602 * @brief Set temperature average mode.
nikapov 0:7917d6d00a6e 603 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 604 * @param avgt is the average mode for temperature, this parameter is @ref HTS221_Avgt_et.
nikapov 0:7917d6d00a6e 605 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 606 */
nikapov 0:7917d6d00a6e 607 HTS221_Error_et HTS221_Set_AvgT(void *handle, HTS221_Avgt_et avgt)
nikapov 0:7917d6d00a6e 608 {
cparata 5:ccf7f36492ae 609 uint8_t tmp;
cparata 5:ccf7f36492ae 610
cparata 5:ccf7f36492ae 611 HTS221_assert_param(IS_HTS221_AVGT(avgt));
nikapov 0:7917d6d00a6e 612
cparata 5:ccf7f36492ae 613 if (HTS221_read_reg(handle, HTS221_AV_CONF_REG, 1, &tmp)) {
cparata 5:ccf7f36492ae 614 return HTS221_ERROR;
cparata 5:ccf7f36492ae 615 }
nikapov 0:7917d6d00a6e 616
cparata 5:ccf7f36492ae 617 tmp &= ~HTS221_AVGT_MASK;
cparata 5:ccf7f36492ae 618 tmp |= (uint8_t)avgt;
nikapov 0:7917d6d00a6e 619
cparata 5:ccf7f36492ae 620 if (HTS221_write_reg(handle, HTS221_AV_CONF_REG, 1, &tmp)) {
cparata 5:ccf7f36492ae 621 return HTS221_ERROR;
cparata 5:ccf7f36492ae 622 }
nikapov 0:7917d6d00a6e 623
cparata 5:ccf7f36492ae 624 return HTS221_OK;
nikapov 0:7917d6d00a6e 625 }
nikapov 0:7917d6d00a6e 626
nikapov 0:7917d6d00a6e 627 /**
nikapov 0:7917d6d00a6e 628 * @brief Get humidity and temperature average mode.
nikapov 0:7917d6d00a6e 629 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 630 * @param avgh pointer to the returned value with the humidity average mode.
nikapov 0:7917d6d00a6e 631 * @param avgt pointer to the returned value with the temperature average mode.
nikapov 0:7917d6d00a6e 632 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 633 */
cparata 5:ccf7f36492ae 634 HTS221_Error_et HTS221_Get_AvgHT(void *handle, HTS221_Avgh_et *avgh, HTS221_Avgt_et *avgt)
nikapov 0:7917d6d00a6e 635 {
cparata 5:ccf7f36492ae 636 uint8_t tmp;
nikapov 0:7917d6d00a6e 637
cparata 5:ccf7f36492ae 638 if (HTS221_read_reg(handle, HTS221_AV_CONF_REG, 1, &tmp)) {
cparata 5:ccf7f36492ae 639 return HTS221_ERROR;
cparata 5:ccf7f36492ae 640 }
nikapov 0:7917d6d00a6e 641
cparata 5:ccf7f36492ae 642 *avgh = (HTS221_Avgh_et)(tmp & HTS221_AVGH_MASK);
cparata 5:ccf7f36492ae 643 *avgt = (HTS221_Avgt_et)(tmp & HTS221_AVGT_MASK);
nikapov 0:7917d6d00a6e 644
cparata 5:ccf7f36492ae 645 return HTS221_OK;
nikapov 0:7917d6d00a6e 646 }
nikapov 0:7917d6d00a6e 647
nikapov 0:7917d6d00a6e 648 /**
nikapov 0:7917d6d00a6e 649 * @brief Set block data update mode.
nikapov 0:7917d6d00a6e 650 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 651 * @param status can be HTS221_ENABLE: enable the block data update, output data registers are updated once both MSB and LSB are read.
nikapov 0:7917d6d00a6e 652 * @param status can be HTS221_DISABLE: output data registers are continuously updated.
nikapov 0:7917d6d00a6e 653 * This parameter is a @ref HTS221_BitStatus_et.
nikapov 0:7917d6d00a6e 654 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 655 */
nikapov 0:7917d6d00a6e 656 HTS221_Error_et HTS221_Set_BduMode(void *handle, HTS221_State_et status)
nikapov 0:7917d6d00a6e 657 {
cparata 5:ccf7f36492ae 658 uint8_t tmp;
cparata 5:ccf7f36492ae 659
cparata 5:ccf7f36492ae 660 HTS221_assert_param(IS_HTS221_State(status));
nikapov 0:7917d6d00a6e 661
cparata 5:ccf7f36492ae 662 if (HTS221_read_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) {
cparata 5:ccf7f36492ae 663 return HTS221_ERROR;
cparata 5:ccf7f36492ae 664 }
nikapov 0:7917d6d00a6e 665
cparata 5:ccf7f36492ae 666 tmp &= ~HTS221_BDU_MASK;
cparata 5:ccf7f36492ae 667 tmp |= ((uint8_t)status) << HTS221_BDU_BIT;
nikapov 0:7917d6d00a6e 668
cparata 5:ccf7f36492ae 669 if (HTS221_write_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) {
cparata 5:ccf7f36492ae 670 return HTS221_ERROR;
cparata 5:ccf7f36492ae 671 }
nikapov 0:7917d6d00a6e 672
cparata 5:ccf7f36492ae 673 return HTS221_OK;
nikapov 0:7917d6d00a6e 674 }
nikapov 0:7917d6d00a6e 675
nikapov 0:7917d6d00a6e 676 /**
nikapov 0:7917d6d00a6e 677 * @brief Get block data update mode.
nikapov 0:7917d6d00a6e 678 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 679 * @param Pointer to the returned value with block data update mode status.
nikapov 0:7917d6d00a6e 680 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 681 */
cparata 5:ccf7f36492ae 682 HTS221_Error_et HTS221_Get_BduMode(void *handle, HTS221_State_et *status)
nikapov 0:7917d6d00a6e 683 {
cparata 5:ccf7f36492ae 684 uint8_t tmp;
nikapov 0:7917d6d00a6e 685
cparata 5:ccf7f36492ae 686 if (HTS221_read_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) {
cparata 5:ccf7f36492ae 687 return HTS221_ERROR;
cparata 5:ccf7f36492ae 688 }
nikapov 0:7917d6d00a6e 689
cparata 5:ccf7f36492ae 690 *status = (HTS221_State_et)((tmp & HTS221_BDU_MASK) >> HTS221_BDU_BIT);
nikapov 0:7917d6d00a6e 691
cparata 5:ccf7f36492ae 692 return HTS221_OK;
nikapov 0:7917d6d00a6e 693 }
nikapov 0:7917d6d00a6e 694
nikapov 0:7917d6d00a6e 695 /**
nikapov 0:7917d6d00a6e 696 * @brief Enter or exit from power down mode.
nikapov 0:7917d6d00a6e 697 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 698 * @param status can be HTS221_SET: HTS221 in power down mode.
nikapov 0:7917d6d00a6e 699 * @param status can be HTS221_REET: HTS221 in active mode.
nikapov 0:7917d6d00a6e 700 * This parameter is a @ref HTS221_BitStatus_et.
nikapov 0:7917d6d00a6e 701 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 702 */
nikapov 0:7917d6d00a6e 703 HTS221_Error_et HTS221_Set_PowerDownMode(void *handle, HTS221_BitStatus_et status)
nikapov 0:7917d6d00a6e 704 {
cparata 5:ccf7f36492ae 705 uint8_t tmp;
cparata 5:ccf7f36492ae 706
cparata 5:ccf7f36492ae 707 HTS221_assert_param(IS_HTS221_BitStatus(status));
nikapov 0:7917d6d00a6e 708
cparata 5:ccf7f36492ae 709 if (HTS221_read_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) {
cparata 5:ccf7f36492ae 710 return HTS221_ERROR;
cparata 5:ccf7f36492ae 711 }
nikapov 0:7917d6d00a6e 712
cparata 5:ccf7f36492ae 713 tmp &= ~HTS221_PD_MASK;
cparata 5:ccf7f36492ae 714 tmp |= ((uint8_t)status) << HTS221_PD_BIT;
nikapov 0:7917d6d00a6e 715
cparata 5:ccf7f36492ae 716 if (HTS221_write_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) {
cparata 5:ccf7f36492ae 717 return HTS221_ERROR;
cparata 5:ccf7f36492ae 718 }
nikapov 0:7917d6d00a6e 719
cparata 5:ccf7f36492ae 720 return HTS221_OK;
nikapov 0:7917d6d00a6e 721 }
nikapov 0:7917d6d00a6e 722
nikapov 0:7917d6d00a6e 723 /**
nikapov 0:7917d6d00a6e 724 * @brief Get if HTS221 is in active mode or in power down mode.
nikapov 0:7917d6d00a6e 725 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 726 * @param Pointer to the returned value with HTS221 status.
nikapov 0:7917d6d00a6e 727 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 728 */
cparata 5:ccf7f36492ae 729 HTS221_Error_et HTS221_Get_PowerDownMode(void *handle, HTS221_BitStatus_et *status)
nikapov 0:7917d6d00a6e 730 {
cparata 5:ccf7f36492ae 731 uint8_t tmp;
nikapov 0:7917d6d00a6e 732
cparata 5:ccf7f36492ae 733 if (HTS221_read_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) {
cparata 5:ccf7f36492ae 734 return HTS221_ERROR;
cparata 5:ccf7f36492ae 735 }
nikapov 0:7917d6d00a6e 736
cparata 5:ccf7f36492ae 737 *status = (HTS221_BitStatus_et)((tmp & HTS221_PD_MASK) >> HTS221_PD_BIT);
nikapov 0:7917d6d00a6e 738
cparata 5:ccf7f36492ae 739 return HTS221_OK;
nikapov 0:7917d6d00a6e 740 }
nikapov 0:7917d6d00a6e 741
nikapov 0:7917d6d00a6e 742 /**
nikapov 0:7917d6d00a6e 743 * @brief Set the output data rate mode.
nikapov 0:7917d6d00a6e 744 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 745 * @param odr is the output data rate mode.
nikapov 0:7917d6d00a6e 746 * This parameter is a @ref HTS221_Odr_et.
nikapov 0:7917d6d00a6e 747 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 748 */
nikapov 0:7917d6d00a6e 749 HTS221_Error_et HTS221_Set_Odr(void *handle, HTS221_Odr_et odr)
nikapov 0:7917d6d00a6e 750 {
cparata 5:ccf7f36492ae 751 uint8_t tmp;
cparata 5:ccf7f36492ae 752
cparata 5:ccf7f36492ae 753 HTS221_assert_param(IS_HTS221_ODR(odr));
nikapov 0:7917d6d00a6e 754
cparata 5:ccf7f36492ae 755 if (HTS221_read_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) {
cparata 5:ccf7f36492ae 756 return HTS221_ERROR;
cparata 5:ccf7f36492ae 757 }
nikapov 0:7917d6d00a6e 758
cparata 5:ccf7f36492ae 759 tmp &= ~HTS221_ODR_MASK;
cparata 5:ccf7f36492ae 760 tmp |= (uint8_t)odr;
nikapov 0:7917d6d00a6e 761
cparata 5:ccf7f36492ae 762 if (HTS221_write_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) {
cparata 5:ccf7f36492ae 763 return HTS221_ERROR;
cparata 5:ccf7f36492ae 764 }
nikapov 0:7917d6d00a6e 765
cparata 5:ccf7f36492ae 766 return HTS221_OK;
nikapov 0:7917d6d00a6e 767 }
nikapov 0:7917d6d00a6e 768
nikapov 0:7917d6d00a6e 769 /**
nikapov 0:7917d6d00a6e 770 * @brief Get the output data rate mode.
nikapov 0:7917d6d00a6e 771 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 772 * @param Pointer to the returned value with output data rate mode.
nikapov 0:7917d6d00a6e 773 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 774 */
cparata 5:ccf7f36492ae 775 HTS221_Error_et HTS221_Get_Odr(void *handle, HTS221_Odr_et *odr)
nikapov 0:7917d6d00a6e 776 {
cparata 5:ccf7f36492ae 777 uint8_t tmp;
nikapov 0:7917d6d00a6e 778
cparata 5:ccf7f36492ae 779 if (HTS221_read_reg(handle, HTS221_CTRL_REG1, 1, &tmp)) {
cparata 5:ccf7f36492ae 780 return HTS221_ERROR;
cparata 5:ccf7f36492ae 781 }
nikapov 0:7917d6d00a6e 782
cparata 5:ccf7f36492ae 783 tmp &= HTS221_ODR_MASK;
cparata 5:ccf7f36492ae 784 *odr = (HTS221_Odr_et)tmp;
nikapov 0:7917d6d00a6e 785
cparata 5:ccf7f36492ae 786 return HTS221_OK;
nikapov 0:7917d6d00a6e 787 }
nikapov 0:7917d6d00a6e 788
nikapov 0:7917d6d00a6e 789 /**
nikapov 0:7917d6d00a6e 790 * @brief Reboot Memory Content.
nikapov 0:7917d6d00a6e 791 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 792 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 793 */
nikapov 0:7917d6d00a6e 794 HTS221_Error_et HTS221_MemoryBoot(void *handle)
nikapov 0:7917d6d00a6e 795 {
cparata 5:ccf7f36492ae 796 uint8_t tmp;
nikapov 0:7917d6d00a6e 797
cparata 5:ccf7f36492ae 798 if (HTS221_read_reg(handle, HTS221_CTRL_REG2, 1, &tmp)) {
cparata 5:ccf7f36492ae 799 return HTS221_ERROR;
cparata 5:ccf7f36492ae 800 }
nikapov 0:7917d6d00a6e 801
cparata 5:ccf7f36492ae 802 tmp |= HTS221_BOOT_MASK;
nikapov 0:7917d6d00a6e 803
cparata 5:ccf7f36492ae 804 if (HTS221_write_reg(handle, HTS221_CTRL_REG2, 1, &tmp)) {
cparata 5:ccf7f36492ae 805 return HTS221_ERROR;
cparata 5:ccf7f36492ae 806 }
nikapov 0:7917d6d00a6e 807
cparata 5:ccf7f36492ae 808 return HTS221_OK;
nikapov 0:7917d6d00a6e 809 }
nikapov 0:7917d6d00a6e 810
nikapov 0:7917d6d00a6e 811 /**
nikapov 0:7917d6d00a6e 812 * @brief Configure the internal heater.
nikapov 0:7917d6d00a6e 813 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 814 * @param The status of the internal heater [HTS221_ENABLE/HTS221_DISABLE].
nikapov 0:7917d6d00a6e 815 * This parameter is a @ref HTS221_State_et.
nikapov 0:7917d6d00a6e 816 * @retval Error code [HTS221_OK, HTS221_ERROR]
nikapov 0:7917d6d00a6e 817 */
nikapov 0:7917d6d00a6e 818 HTS221_Error_et HTS221_Set_HeaterState(void *handle, HTS221_State_et status)
nikapov 0:7917d6d00a6e 819 {
cparata 5:ccf7f36492ae 820 uint8_t tmp;
cparata 5:ccf7f36492ae 821
cparata 5:ccf7f36492ae 822 HTS221_assert_param(IS_HTS221_State(status));
nikapov 0:7917d6d00a6e 823
cparata 5:ccf7f36492ae 824 if (HTS221_read_reg(handle, HTS221_CTRL_REG2, 1, &tmp)) {
cparata 5:ccf7f36492ae 825 return HTS221_ERROR;
cparata 5:ccf7f36492ae 826 }
nikapov 0:7917d6d00a6e 827
cparata 5:ccf7f36492ae 828 tmp &= ~HTS221_HEATHER_MASK;
cparata 5:ccf7f36492ae 829 tmp |= ((uint8_t)status) << HTS221_HEATHER_BIT;
nikapov 0:7917d6d00a6e 830
cparata 5:ccf7f36492ae 831 if (HTS221_write_reg(handle, HTS221_CTRL_REG2, 1, &tmp)) {
cparata 5:ccf7f36492ae 832 return HTS221_ERROR;
cparata 5:ccf7f36492ae 833 }
nikapov 0:7917d6d00a6e 834
cparata 5:ccf7f36492ae 835 return HTS221_OK;
nikapov 0:7917d6d00a6e 836 }
nikapov 0:7917d6d00a6e 837
nikapov 0:7917d6d00a6e 838 /**
nikapov 0:7917d6d00a6e 839 * @brief Get the internal heater.
nikapov 0:7917d6d00a6e 840 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 841 * @param Pointer to the returned status of the internal heater [HTS221_ENABLE/HTS221_DISABLE].
nikapov 0:7917d6d00a6e 842 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 843 */
cparata 5:ccf7f36492ae 844 HTS221_Error_et HTS221_Get_HeaterState(void *handle, HTS221_State_et *status)
nikapov 0:7917d6d00a6e 845 {
cparata 5:ccf7f36492ae 846 uint8_t tmp;
nikapov 0:7917d6d00a6e 847
cparata 5:ccf7f36492ae 848 if (HTS221_read_reg(handle, HTS221_CTRL_REG2, 1, &tmp)) {
cparata 5:ccf7f36492ae 849 return HTS221_ERROR;
cparata 5:ccf7f36492ae 850 }
nikapov 0:7917d6d00a6e 851
cparata 5:ccf7f36492ae 852 *status = (HTS221_State_et)((tmp & HTS221_HEATHER_MASK) >> HTS221_HEATHER_BIT);
nikapov 0:7917d6d00a6e 853
cparata 5:ccf7f36492ae 854 return HTS221_OK;
nikapov 0:7917d6d00a6e 855 }
nikapov 0:7917d6d00a6e 856
nikapov 0:7917d6d00a6e 857 /**
nikapov 0:7917d6d00a6e 858 * @brief Set ONE_SHOT bit to start a new conversion (ODR mode has to be 00).
nikapov 0:7917d6d00a6e 859 * Once the measurement is done, ONE_SHOT bit is self-cleared.
nikapov 0:7917d6d00a6e 860 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 861 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 862 */
nikapov 0:7917d6d00a6e 863 HTS221_Error_et HTS221_StartOneShotMeasurement(void *handle)
nikapov 0:7917d6d00a6e 864 {
cparata 5:ccf7f36492ae 865 uint8_t tmp;
nikapov 0:7917d6d00a6e 866
cparata 5:ccf7f36492ae 867 if (HTS221_read_reg(handle, HTS221_CTRL_REG2, 1, &tmp)) {
cparata 5:ccf7f36492ae 868 return HTS221_ERROR;
cparata 5:ccf7f36492ae 869 }
nikapov 0:7917d6d00a6e 870
cparata 5:ccf7f36492ae 871 tmp |= HTS221_ONE_SHOT_MASK;
nikapov 0:7917d6d00a6e 872
cparata 5:ccf7f36492ae 873 if (HTS221_write_reg(handle, HTS221_CTRL_REG2, 1, &tmp)) {
cparata 5:ccf7f36492ae 874 return HTS221_ERROR;
cparata 5:ccf7f36492ae 875 }
nikapov 0:7917d6d00a6e 876
cparata 5:ccf7f36492ae 877 return HTS221_OK;
nikapov 0:7917d6d00a6e 878
nikapov 0:7917d6d00a6e 879 }
nikapov 0:7917d6d00a6e 880
nikapov 0:7917d6d00a6e 881 /**
nikapov 0:7917d6d00a6e 882 * @brief Set level configuration of the interrupt pin DRDY.
nikapov 0:7917d6d00a6e 883 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 884 * @param status can be HTS221_LOW_LVL: active level is LOW.
nikapov 0:7917d6d00a6e 885 * @param status can be HTS221_HIGH_LVL: active level is HIGH.
nikapov 0:7917d6d00a6e 886 * This parameter is a @ref HTS221_State_et.
nikapov 0:7917d6d00a6e 887 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 888 */
nikapov 0:7917d6d00a6e 889 HTS221_Error_et HTS221_Set_IrqActiveLevel(void *handle, HTS221_DrdyLevel_et value)
nikapov 0:7917d6d00a6e 890 {
cparata 5:ccf7f36492ae 891 uint8_t tmp;
cparata 5:ccf7f36492ae 892
cparata 5:ccf7f36492ae 893 HTS221_assert_param(IS_HTS221_DrdyLevelType(value));
nikapov 0:7917d6d00a6e 894
cparata 5:ccf7f36492ae 895 if (HTS221_read_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) {
cparata 5:ccf7f36492ae 896 return HTS221_ERROR;
cparata 5:ccf7f36492ae 897 }
nikapov 0:7917d6d00a6e 898
cparata 5:ccf7f36492ae 899 tmp &= ~HTS221_DRDY_H_L_MASK;
cparata 5:ccf7f36492ae 900 tmp |= (uint8_t)value;
nikapov 0:7917d6d00a6e 901
cparata 5:ccf7f36492ae 902 if (HTS221_write_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) {
cparata 5:ccf7f36492ae 903 return HTS221_ERROR;
cparata 5:ccf7f36492ae 904 }
nikapov 0:7917d6d00a6e 905
cparata 5:ccf7f36492ae 906 return HTS221_OK;
nikapov 0:7917d6d00a6e 907 }
nikapov 0:7917d6d00a6e 908
nikapov 0:7917d6d00a6e 909 /**
nikapov 0:7917d6d00a6e 910 * @brief Get level configuration of the interrupt pin DRDY.
nikapov 0:7917d6d00a6e 911 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 912 * @param Pointer to the returned status of the level configuration [HTS221_ENABLE/HTS221_DISABLE].
nikapov 0:7917d6d00a6e 913 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 914 */
cparata 5:ccf7f36492ae 915 HTS221_Error_et HTS221_Get_IrqActiveLevel(void *handle, HTS221_DrdyLevel_et *value)
nikapov 0:7917d6d00a6e 916 {
cparata 5:ccf7f36492ae 917 uint8_t tmp;
nikapov 0:7917d6d00a6e 918
cparata 5:ccf7f36492ae 919 if (HTS221_read_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) {
cparata 5:ccf7f36492ae 920 return HTS221_ERROR;
cparata 5:ccf7f36492ae 921 }
nikapov 0:7917d6d00a6e 922
cparata 5:ccf7f36492ae 923 *value = (HTS221_DrdyLevel_et)(tmp & HTS221_DRDY_H_L_MASK);
nikapov 0:7917d6d00a6e 924
cparata 5:ccf7f36492ae 925 return HTS221_OK;
nikapov 0:7917d6d00a6e 926 }
nikapov 0:7917d6d00a6e 927
nikapov 0:7917d6d00a6e 928 /**
nikapov 0:7917d6d00a6e 929 * @brief Set Push-pull/open drain configuration for the interrupt pin DRDY.
nikapov 0:7917d6d00a6e 930 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 931 * @param value is the output type configuration.
nikapov 0:7917d6d00a6e 932 * This parameter is a @ref HTS221_OutputType_et.
nikapov 0:7917d6d00a6e 933 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 934 */
nikapov 0:7917d6d00a6e 935 HTS221_Error_et HTS221_Set_IrqOutputType(void *handle, HTS221_OutputType_et value)
nikapov 0:7917d6d00a6e 936 {
cparata 5:ccf7f36492ae 937 uint8_t tmp;
cparata 5:ccf7f36492ae 938
cparata 5:ccf7f36492ae 939 HTS221_assert_param(IS_HTS221_OutputType(value));
nikapov 0:7917d6d00a6e 940
cparata 5:ccf7f36492ae 941 if (HTS221_read_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) {
cparata 5:ccf7f36492ae 942 return HTS221_ERROR;
cparata 5:ccf7f36492ae 943 }
nikapov 0:7917d6d00a6e 944
cparata 5:ccf7f36492ae 945 tmp &= ~HTS221_PP_OD_MASK;
cparata 5:ccf7f36492ae 946 tmp |= (uint8_t)value;
nikapov 0:7917d6d00a6e 947
cparata 5:ccf7f36492ae 948 if (HTS221_write_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) {
cparata 5:ccf7f36492ae 949 return HTS221_ERROR;
cparata 5:ccf7f36492ae 950 }
nikapov 0:7917d6d00a6e 951
cparata 5:ccf7f36492ae 952 return HTS221_OK;
nikapov 0:7917d6d00a6e 953 }
nikapov 0:7917d6d00a6e 954
nikapov 0:7917d6d00a6e 955 /**
nikapov 0:7917d6d00a6e 956 * @brief Get the configuration for the interrupt pin DRDY.
nikapov 0:7917d6d00a6e 957 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 958 * @param Pointer to the returned value with output type configuration.
nikapov 0:7917d6d00a6e 959 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 960 */
cparata 5:ccf7f36492ae 961 HTS221_Error_et HTS221_Get_IrqOutputType(void *handle, HTS221_OutputType_et *value)
nikapov 0:7917d6d00a6e 962 {
cparata 5:ccf7f36492ae 963 uint8_t tmp;
nikapov 0:7917d6d00a6e 964
cparata 5:ccf7f36492ae 965 if (HTS221_read_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) {
cparata 5:ccf7f36492ae 966 return HTS221_ERROR;
cparata 5:ccf7f36492ae 967 }
nikapov 0:7917d6d00a6e 968
cparata 5:ccf7f36492ae 969 *value = (HTS221_OutputType_et)(tmp & HTS221_PP_OD_MASK);
nikapov 0:7917d6d00a6e 970
cparata 5:ccf7f36492ae 971 return HTS221_OK;
nikapov 0:7917d6d00a6e 972 }
nikapov 0:7917d6d00a6e 973
nikapov 0:7917d6d00a6e 974 /**
nikapov 0:7917d6d00a6e 975 * @brief Enable/disable the interrupt mode.
nikapov 0:7917d6d00a6e 976 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 977 * @param status is the enable/disable for the interrupt mode.
nikapov 0:7917d6d00a6e 978 * This parameter is a @ref HTS221_State_et.
nikapov 0:7917d6d00a6e 979 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 980 */
nikapov 0:7917d6d00a6e 981 HTS221_Error_et HTS221_Set_IrqEnable(void *handle, HTS221_State_et status)
nikapov 0:7917d6d00a6e 982 {
cparata 5:ccf7f36492ae 983 uint8_t tmp;
cparata 5:ccf7f36492ae 984
cparata 5:ccf7f36492ae 985 HTS221_assert_param(IS_HTS221_State(status));
nikapov 0:7917d6d00a6e 986
cparata 5:ccf7f36492ae 987 if (HTS221_read_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) {
cparata 5:ccf7f36492ae 988 return HTS221_ERROR;
cparata 5:ccf7f36492ae 989 }
nikapov 0:7917d6d00a6e 990
cparata 5:ccf7f36492ae 991 tmp &= ~HTS221_DRDY_MASK;
cparata 5:ccf7f36492ae 992 tmp |= ((uint8_t)status) << HTS221_DRDY_BIT;
nikapov 0:7917d6d00a6e 993
cparata 5:ccf7f36492ae 994 if (HTS221_write_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) {
cparata 5:ccf7f36492ae 995 return HTS221_ERROR;
cparata 5:ccf7f36492ae 996 }
nikapov 0:7917d6d00a6e 997
cparata 5:ccf7f36492ae 998 return HTS221_OK;
nikapov 0:7917d6d00a6e 999 }
nikapov 0:7917d6d00a6e 1000
nikapov 0:7917d6d00a6e 1001 /**
nikapov 0:7917d6d00a6e 1002 * @brief Get the interrupt mode.
nikapov 0:7917d6d00a6e 1003 * @param *handle Device handle.
nikapov 0:7917d6d00a6e 1004 * @param Pointer to the returned status of the interrupt mode configuration [HTS221_ENABLE/HTS221_DISABLE].
nikapov 0:7917d6d00a6e 1005 * @retval Error code [HTS221_OK, HTS221_ERROR].
nikapov 0:7917d6d00a6e 1006 */
cparata 5:ccf7f36492ae 1007 HTS221_Error_et HTS221_Get_IrqEnable(void *handle, HTS221_State_et *status)
nikapov 0:7917d6d00a6e 1008 {
cparata 5:ccf7f36492ae 1009 uint8_t tmp;
nikapov 0:7917d6d00a6e 1010
cparata 5:ccf7f36492ae 1011 if (HTS221_read_reg(handle, HTS221_CTRL_REG3, 1, &tmp)) {
cparata 5:ccf7f36492ae 1012 return HTS221_ERROR;
cparata 5:ccf7f36492ae 1013 }
nikapov 0:7917d6d00a6e 1014
cparata 5:ccf7f36492ae 1015 *status = (HTS221_State_et)((tmp & HTS221_DRDY_MASK) >> HTS221_DRDY_BIT);
nikapov 0:7917d6d00a6e 1016
cparata 5:ccf7f36492ae 1017 return HTS221_OK;
nikapov 0:7917d6d00a6e 1018 }
nikapov 0:7917d6d00a6e 1019
nikapov 0:7917d6d00a6e 1020
nikapov 0:7917d6d00a6e 1021 #ifdef USE_FULL_ASSERT_HTS221
nikapov 0:7917d6d00a6e 1022 /**
nikapov 0:7917d6d00a6e 1023 * @brief Reports the name of the source file and the source line number
nikapov 0:7917d6d00a6e 1024 * where the assert_param error has occurred.
nikapov 0:7917d6d00a6e 1025 * @param file: pointer to the source file name
nikapov 0:7917d6d00a6e 1026 * @param line: assert_param error line source number
nikapov 0:7917d6d00a6e 1027 * @retval : None
nikapov 0:7917d6d00a6e 1028 */
cparata 5:ccf7f36492ae 1029 void HTS221_assert_failed(uint8_t *file, uint32_t line)
nikapov 0:7917d6d00a6e 1030 {
cparata 5:ccf7f36492ae 1031 /* User can add his own implementation to report the file name and line number */
cparata 5:ccf7f36492ae 1032 printf("Wrong parameters value: file %s on line %d\r\n", file, (int)line);
nikapov 0:7917d6d00a6e 1033
cparata 5:ccf7f36492ae 1034 /* Infinite loop */
cparata 5:ccf7f36492ae 1035 while (1) {
cparata 5:ccf7f36492ae 1036 }
nikapov 0:7917d6d00a6e 1037 }
nikapov 0:7917d6d00a6e 1038 #endif
nikapov 0:7917d6d00a6e 1039
nikapov 0:7917d6d00a6e 1040 #ifdef __cplusplus
cparata 5:ccf7f36492ae 1041 }
nikapov 0:7917d6d00a6e 1042 #endif
nikapov 0:7917d6d00a6e 1043
nikapov 0:7917d6d00a6e 1044 /**
nikapov 0:7917d6d00a6e 1045 * @}
nikapov 0:7917d6d00a6e 1046 */
nikapov 0:7917d6d00a6e 1047
nikapov 0:7917d6d00a6e 1048 /**
nikapov 0:7917d6d00a6e 1049 * @}
nikapov 0:7917d6d00a6e 1050 */
nikapov 0:7917d6d00a6e 1051
nikapov 0:7917d6d00a6e 1052 /**
nikapov 0:7917d6d00a6e 1053 * @}
nikapov 0:7917d6d00a6e 1054 */
nikapov 0:7917d6d00a6e 1055
nikapov 0:7917d6d00a6e 1056 /******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/