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