Beta

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON

Fork of X_NUCLEO_IKS01A2 by ST

Committer:
nikapov
Date:
Mon Nov 28 13:16:22 2016 +0000
Revision:
0:cad5dab2b21d
Child:
6:671fd10a51b7
X_NUCLEO_IKS01A2 lib created.

Who changed what in which revision?

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