Beta
Dependencies: ST_INTERFACES X_NUCLEO_COMMON
Fork of X_NUCLEO_IKS01A2 by
Components/LPS22HBSensor/LPS22HB_driver.c@11:8f4e5789b6b3, 2017-11-02 (annotated)
- Committer:
- Qksalo
- Date:
- Thu Nov 02 10:58:12 2017 +0000
- Revision:
- 11:8f4e5789b6b3
- Parent:
- 9:038121268b07
Beta
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nikapov | 0:cad5dab2b21d | 1 | /** |
nikapov | 0:cad5dab2b21d | 2 | ******************************************************************************* |
davide.aliprandi@st.com | 6:671fd10a51b7 | 3 | * @file LPS22HB_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 LPS22HB driver file |
nikapov | 0:cad5dab2b21d | 8 | ******************************************************************************* |
nikapov | 0:cad5dab2b21d | 9 | * @attention |
nikapov | 0:cad5dab2b21d | 10 | * |
nikapov | 0:cad5dab2b21d | 11 | * <h2><center>© 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 ------------------------------------------------------------------*/ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 39 | #include "LPS22HB_driver.h" |
nikapov | 0:cad5dab2b21d | 40 | #ifdef USE_FULL_ASSERT_LPS22HB |
nikapov | 0:cad5dab2b21d | 41 | #include <stdio.h> |
nikapov | 0:cad5dab2b21d | 42 | #endif |
nikapov | 0:cad5dab2b21d | 43 | |
nikapov | 0:cad5dab2b21d | 44 | /** @addtogroup Environmental_Sensor |
nikapov | 0:cad5dab2b21d | 45 | * @{ |
nikapov | 0:cad5dab2b21d | 46 | */ |
nikapov | 0:cad5dab2b21d | 47 | |
nikapov | 0:cad5dab2b21d | 48 | /** @defgroup LPS22HB_DRIVER |
nikapov | 0:cad5dab2b21d | 49 | * @brief LPS22HB DRIVER |
nikapov | 0:cad5dab2b21d | 50 | * @{ |
nikapov | 0:cad5dab2b21d | 51 | */ |
nikapov | 0:cad5dab2b21d | 52 | |
nikapov | 0:cad5dab2b21d | 53 | /** @defgroup LPS22HB_Imported_Function_Prototypes |
nikapov | 0:cad5dab2b21d | 54 | * @{ |
nikapov | 0:cad5dab2b21d | 55 | */ |
nikapov | 0:cad5dab2b21d | 56 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 57 | extern uint8_t LPS22HB_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ); |
davide.aliprandi@st.com | 6:671fd10a51b7 | 58 | extern uint8_t LPS22HB_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ); |
nikapov | 0:cad5dab2b21d | 59 | |
nikapov | 0:cad5dab2b21d | 60 | /** |
nikapov | 0:cad5dab2b21d | 61 | * @} |
nikapov | 0:cad5dab2b21d | 62 | */ |
nikapov | 0:cad5dab2b21d | 63 | |
nikapov | 0:cad5dab2b21d | 64 | /** @defgroup LPS22HB_Private_Function_Prototypes |
nikapov | 0:cad5dab2b21d | 65 | * @{ |
nikapov | 0:cad5dab2b21d | 66 | */ |
nikapov | 0:cad5dab2b21d | 67 | |
nikapov | 0:cad5dab2b21d | 68 | /** |
nikapov | 0:cad5dab2b21d | 69 | * @} |
nikapov | 0:cad5dab2b21d | 70 | */ |
nikapov | 0:cad5dab2b21d | 71 | |
nikapov | 0:cad5dab2b21d | 72 | /** @defgroup LPS22HB_Private_Functions |
nikapov | 0:cad5dab2b21d | 73 | * @{ |
nikapov | 0:cad5dab2b21d | 74 | */ |
nikapov | 0:cad5dab2b21d | 75 | |
nikapov | 0:cad5dab2b21d | 76 | /** |
nikapov | 0:cad5dab2b21d | 77 | * @} |
nikapov | 0:cad5dab2b21d | 78 | */ |
nikapov | 0:cad5dab2b21d | 79 | |
nikapov | 0:cad5dab2b21d | 80 | /** @defgroup LPS22HB_Public_Functions |
nikapov | 0:cad5dab2b21d | 81 | * @{ |
nikapov | 0:cad5dab2b21d | 82 | */ |
nikapov | 0:cad5dab2b21d | 83 | |
nikapov | 0:cad5dab2b21d | 84 | /******************************************************************************* |
davide.aliprandi@st.com | 6:671fd10a51b7 | 85 | * Function Name : LPS22HB_read_reg |
nikapov | 0:cad5dab2b21d | 86 | * Description : Generic Reading function. It must be fullfilled with either |
nikapov | 0:cad5dab2b21d | 87 | * : I2C or SPI reading functions |
nikapov | 0:cad5dab2b21d | 88 | * Input : Register Address |
nikapov | 0:cad5dab2b21d | 89 | * Output : Data Read |
nikapov | 0:cad5dab2b21d | 90 | * Return : None |
nikapov | 0:cad5dab2b21d | 91 | *******************************************************************************/ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 92 | LPS22HB_Error_et LPS22HB_read_reg( void *handle, uint8_t RegAddr, uint16_t NumByteToRead, uint8_t *Data ) |
nikapov | 0:cad5dab2b21d | 93 | { |
nikapov | 0:cad5dab2b21d | 94 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 95 | if ( LPS22HB_io_read( handle, RegAddr, Data, NumByteToRead ) ) |
nikapov | 0:cad5dab2b21d | 96 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 97 | else |
nikapov | 0:cad5dab2b21d | 98 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 99 | } |
nikapov | 0:cad5dab2b21d | 100 | |
nikapov | 0:cad5dab2b21d | 101 | /******************************************************************************* |
davide.aliprandi@st.com | 6:671fd10a51b7 | 102 | * Function Name : LPS22HB_write_reg |
nikapov | 0:cad5dab2b21d | 103 | * Description : Generic Writing function. It must be fullfilled with either |
nikapov | 0:cad5dab2b21d | 104 | * : I2C or SPI writing function |
nikapov | 0:cad5dab2b21d | 105 | * Input : Register Address, Data to be written |
nikapov | 0:cad5dab2b21d | 106 | * Output : None |
nikapov | 0:cad5dab2b21d | 107 | * Return : None |
nikapov | 0:cad5dab2b21d | 108 | *******************************************************************************/ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 109 | LPS22HB_Error_et LPS22HB_write_reg( void *handle, uint8_t RegAddr, uint16_t NumByteToWrite, uint8_t *Data ) |
nikapov | 0:cad5dab2b21d | 110 | { |
nikapov | 0:cad5dab2b21d | 111 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 112 | if ( LPS22HB_io_write( handle, RegAddr, Data, NumByteToWrite ) ) |
nikapov | 0:cad5dab2b21d | 113 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 114 | else |
nikapov | 0:cad5dab2b21d | 115 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 116 | } |
nikapov | 0:cad5dab2b21d | 117 | |
nikapov | 0:cad5dab2b21d | 118 | /** |
nikapov | 0:cad5dab2b21d | 119 | * @brief Read identification code by WHO_AM_I register |
nikapov | 0:cad5dab2b21d | 120 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 121 | * @param Buffer to empty by Device identification Value. |
nikapov | 0:cad5dab2b21d | 122 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 123 | */ |
nikapov | 0:cad5dab2b21d | 124 | LPS22HB_Error_et LPS22HB_Get_DeviceID(void *handle, uint8_t* deviceid) |
nikapov | 0:cad5dab2b21d | 125 | { |
davide.aliprandi@st.com | 6:671fd10a51b7 | 126 | if(LPS22HB_read_reg(handle, LPS22HB_WHO_AM_I_REG, 1, deviceid)) |
nikapov | 0:cad5dab2b21d | 127 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 128 | |
nikapov | 0:cad5dab2b21d | 129 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 130 | } |
nikapov | 0:cad5dab2b21d | 131 | |
nikapov | 0:cad5dab2b21d | 132 | |
nikapov | 0:cad5dab2b21d | 133 | /** |
nikapov | 0:cad5dab2b21d | 134 | * @brief Get the LPS22HB driver version. |
nikapov | 0:cad5dab2b21d | 135 | * @param None |
nikapov | 0:cad5dab2b21d | 136 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 137 | */ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 138 | LPS22HB_Error_et LPS22HB_Get_DriverVersion(LPS22HB_driverVersion_st *Version) |
nikapov | 0:cad5dab2b21d | 139 | { |
davide.aliprandi@st.com | 6:671fd10a51b7 | 140 | Version->Major = LPS22HB_driverVersion_Major; |
davide.aliprandi@st.com | 6:671fd10a51b7 | 141 | Version->Minor = LPS22HB_driverVersion_Minor; |
davide.aliprandi@st.com | 6:671fd10a51b7 | 142 | Version->Point = LPS22HB_driverVersion_Point; |
nikapov | 0:cad5dab2b21d | 143 | |
nikapov | 0:cad5dab2b21d | 144 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 145 | } |
nikapov | 0:cad5dab2b21d | 146 | |
nikapov | 0:cad5dab2b21d | 147 | |
nikapov | 0:cad5dab2b21d | 148 | /** |
nikapov | 0:cad5dab2b21d | 149 | * @brief Set LPS22HB Low Power or Low Noise Mode Configuration |
nikapov | 0:cad5dab2b21d | 150 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 151 | * @param LPS22HB_LowNoise or LPS22HB_LowPower mode |
nikapov | 0:cad5dab2b21d | 152 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 153 | */ |
nikapov | 0:cad5dab2b21d | 154 | LPS22HB_Error_et LPS22HB_Set_PowerMode(void *handle, LPS22HB_PowerMode_et mode) |
nikapov | 0:cad5dab2b21d | 155 | { |
nikapov | 0:cad5dab2b21d | 156 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 157 | |
nikapov | 0:cad5dab2b21d | 158 | LPS22HB_assert_param(IS_LPS22HB_PowerMode(mode)); |
nikapov | 0:cad5dab2b21d | 159 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 160 | if(LPS22HB_read_reg(handle, LPS22HB_RES_CONF_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 161 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 162 | |
nikapov | 0:cad5dab2b21d | 163 | tmp &= ~LPS22HB_LCEN_MASK; |
nikapov | 0:cad5dab2b21d | 164 | tmp |= (uint8_t)mode; |
nikapov | 0:cad5dab2b21d | 165 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 166 | if(LPS22HB_write_reg(handle, LPS22HB_RES_CONF_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 167 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 168 | |
nikapov | 0:cad5dab2b21d | 169 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 170 | } |
nikapov | 0:cad5dab2b21d | 171 | |
nikapov | 0:cad5dab2b21d | 172 | /** |
nikapov | 0:cad5dab2b21d | 173 | * @brief Get LPS22HB Power Mode |
nikapov | 0:cad5dab2b21d | 174 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 175 | * @param Buffer to empty with Mode: Low Noise or Low Current |
nikapov | 0:cad5dab2b21d | 176 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 177 | */ |
nikapov | 0:cad5dab2b21d | 178 | LPS22HB_Error_et LPS22HB_Get_PowerMode(void *handle, LPS22HB_PowerMode_et* mode) |
nikapov | 0:cad5dab2b21d | 179 | { |
nikapov | 0:cad5dab2b21d | 180 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 181 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 182 | if(LPS22HB_read_reg(handle, LPS22HB_RES_CONF_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 183 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 184 | |
nikapov | 0:cad5dab2b21d | 185 | *mode = (LPS22HB_PowerMode_et)(tmp & LPS22HB_LCEN_MASK); |
nikapov | 0:cad5dab2b21d | 186 | |
nikapov | 0:cad5dab2b21d | 187 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 188 | } |
nikapov | 0:cad5dab2b21d | 189 | |
nikapov | 0:cad5dab2b21d | 190 | |
nikapov | 0:cad5dab2b21d | 191 | /** |
nikapov | 0:cad5dab2b21d | 192 | * @brief Set LPS22HB Output Data Rate |
nikapov | 0:cad5dab2b21d | 193 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 194 | * @param Output Data Rate |
nikapov | 0:cad5dab2b21d | 195 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 196 | */ |
nikapov | 0:cad5dab2b21d | 197 | LPS22HB_Error_et LPS22HB_Set_Odr(void *handle, LPS22HB_Odr_et odr) |
nikapov | 0:cad5dab2b21d | 198 | { |
nikapov | 0:cad5dab2b21d | 199 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 200 | |
nikapov | 0:cad5dab2b21d | 201 | |
nikapov | 0:cad5dab2b21d | 202 | LPS22HB_assert_param(IS_LPS22HB_ODR(odr)); |
nikapov | 0:cad5dab2b21d | 203 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 204 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 205 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 206 | |
nikapov | 0:cad5dab2b21d | 207 | tmp &= ~LPS22HB_ODR_MASK; |
nikapov | 0:cad5dab2b21d | 208 | tmp |= (uint8_t)odr; |
nikapov | 0:cad5dab2b21d | 209 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 210 | if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 211 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 212 | |
nikapov | 0:cad5dab2b21d | 213 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 214 | } |
nikapov | 0:cad5dab2b21d | 215 | |
nikapov | 0:cad5dab2b21d | 216 | /** |
nikapov | 0:cad5dab2b21d | 217 | * @brief Get LPS22HB Output Data Rate |
nikapov | 0:cad5dab2b21d | 218 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 219 | * @param Buffer to empty with Output Data Rate |
nikapov | 0:cad5dab2b21d | 220 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 221 | */ |
nikapov | 0:cad5dab2b21d | 222 | LPS22HB_Error_et LPS22HB_Get_Odr(void *handle, LPS22HB_Odr_et* odr) |
nikapov | 0:cad5dab2b21d | 223 | { |
nikapov | 0:cad5dab2b21d | 224 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 225 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 226 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 227 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 228 | |
nikapov | 0:cad5dab2b21d | 229 | *odr = (LPS22HB_Odr_et)(tmp & LPS22HB_ODR_MASK); |
nikapov | 0:cad5dab2b21d | 230 | |
nikapov | 0:cad5dab2b21d | 231 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 232 | } |
nikapov | 0:cad5dab2b21d | 233 | |
nikapov | 0:cad5dab2b21d | 234 | /** |
nikapov | 0:cad5dab2b21d | 235 | * @brief Enable/Disale low-pass filter on LPS22HB pressure data |
nikapov | 0:cad5dab2b21d | 236 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 237 | * @param state: enable or disable |
nikapov | 0:cad5dab2b21d | 238 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 239 | */ |
nikapov | 0:cad5dab2b21d | 240 | LPS22HB_Error_et LPS22HB_Set_LowPassFilter(void *handle, LPS22HB_State_et state) |
nikapov | 0:cad5dab2b21d | 241 | { |
nikapov | 0:cad5dab2b21d | 242 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 243 | |
nikapov | 0:cad5dab2b21d | 244 | LPS22HB_assert_param(IS_LPS22HB_State(state)); |
nikapov | 0:cad5dab2b21d | 245 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 246 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 247 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 248 | |
nikapov | 0:cad5dab2b21d | 249 | tmp &= ~LPS22HB_LPFP_MASK; |
nikapov | 0:cad5dab2b21d | 250 | tmp |= ((uint8_t)state)<<LPS22HB_LPFP_BIT; |
nikapov | 0:cad5dab2b21d | 251 | |
nikapov | 0:cad5dab2b21d | 252 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 253 | if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 254 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 255 | |
nikapov | 0:cad5dab2b21d | 256 | |
nikapov | 0:cad5dab2b21d | 257 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 258 | } |
nikapov | 0:cad5dab2b21d | 259 | |
nikapov | 0:cad5dab2b21d | 260 | |
nikapov | 0:cad5dab2b21d | 261 | /** |
nikapov | 0:cad5dab2b21d | 262 | * @brief Set low-pass filter cutoff configuration on LPS22HB pressure data |
nikapov | 0:cad5dab2b21d | 263 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 264 | * @param Filter Cutoff ODR/9 or ODR/20 |
nikapov | 0:cad5dab2b21d | 265 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 266 | */ |
nikapov | 0:cad5dab2b21d | 267 | LPS22HB_Error_et LPS22HB_Set_LowPassFilterCutoff(void *handle, LPS22HB_LPF_Cutoff_et cutoff){ |
nikapov | 0:cad5dab2b21d | 268 | |
nikapov | 0:cad5dab2b21d | 269 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 270 | |
nikapov | 0:cad5dab2b21d | 271 | LPS22HB_assert_param(IS_LPS22HB_LPF_Cutoff(cutoff)); |
nikapov | 0:cad5dab2b21d | 272 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 273 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 274 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 275 | |
nikapov | 0:cad5dab2b21d | 276 | tmp &= ~LPS22HB_LPFP_CUTOFF_MASK; |
nikapov | 0:cad5dab2b21d | 277 | tmp |= (uint8_t)cutoff; |
nikapov | 0:cad5dab2b21d | 278 | |
nikapov | 0:cad5dab2b21d | 279 | |
nikapov | 0:cad5dab2b21d | 280 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 281 | if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 282 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 283 | |
nikapov | 0:cad5dab2b21d | 284 | |
nikapov | 0:cad5dab2b21d | 285 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 286 | |
nikapov | 0:cad5dab2b21d | 287 | } |
nikapov | 0:cad5dab2b21d | 288 | |
nikapov | 0:cad5dab2b21d | 289 | /** |
nikapov | 0:cad5dab2b21d | 290 | * @brief Set Block Data Mode |
nikapov | 0:cad5dab2b21d | 291 | * @detail It is recommended to set BDU bit to ‘1’. |
nikapov | 0:cad5dab2b21d | 292 | * @detail This feature avoids reading LSB and MSB related to different samples. |
nikapov | 0:cad5dab2b21d | 293 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 294 | * @param LPS22HB_BDU_CONTINUOUS_UPDATE, LPS22HB_BDU_NO_UPDATE |
nikapov | 0:cad5dab2b21d | 295 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 296 | */ |
nikapov | 0:cad5dab2b21d | 297 | |
nikapov | 0:cad5dab2b21d | 298 | LPS22HB_Error_et LPS22HB_Set_Bdu(void *handle, LPS22HB_Bdu_et bdu) |
nikapov | 0:cad5dab2b21d | 299 | { |
nikapov | 0:cad5dab2b21d | 300 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 301 | |
nikapov | 0:cad5dab2b21d | 302 | |
nikapov | 0:cad5dab2b21d | 303 | LPS22HB_assert_param(IS_LPS22HB_BDUMode(bdu)); |
nikapov | 0:cad5dab2b21d | 304 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 305 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 306 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 307 | |
nikapov | 0:cad5dab2b21d | 308 | tmp &= ~LPS22HB_BDU_MASK; |
nikapov | 0:cad5dab2b21d | 309 | tmp |= ((uint8_t)bdu); |
nikapov | 0:cad5dab2b21d | 310 | |
nikapov | 0:cad5dab2b21d | 311 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 312 | if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 313 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 314 | |
nikapov | 0:cad5dab2b21d | 315 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 316 | } |
nikapov | 0:cad5dab2b21d | 317 | |
nikapov | 0:cad5dab2b21d | 318 | /** |
nikapov | 0:cad5dab2b21d | 319 | * @brief Get Block Data Mode |
nikapov | 0:cad5dab2b21d | 320 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 321 | * @param Buffer to empty whit the bdu mode read from sensor |
nikapov | 0:cad5dab2b21d | 322 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 323 | */ |
nikapov | 0:cad5dab2b21d | 324 | LPS22HB_Error_et LPS22HB_Get_Bdu(void *handle, LPS22HB_Bdu_et* bdu) |
nikapov | 0:cad5dab2b21d | 325 | { |
nikapov | 0:cad5dab2b21d | 326 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 327 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 328 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 329 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 330 | |
nikapov | 0:cad5dab2b21d | 331 | *bdu = (LPS22HB_Bdu_et)(tmp & LPS22HB_BDU_MASK); |
nikapov | 0:cad5dab2b21d | 332 | |
nikapov | 0:cad5dab2b21d | 333 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 334 | } |
nikapov | 0:cad5dab2b21d | 335 | |
nikapov | 0:cad5dab2b21d | 336 | /** |
nikapov | 0:cad5dab2b21d | 337 | * @brief Set SPI mode: 3 Wire Interface or 4 Wire Interface |
nikapov | 0:cad5dab2b21d | 338 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 339 | * @param LPS22HB_SPI_3_WIRE, LPS22HB_SPI_4_WIRE |
nikapov | 0:cad5dab2b21d | 340 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 341 | */ |
nikapov | 0:cad5dab2b21d | 342 | LPS22HB_Error_et LPS22HB_Set_SpiInterface(void *handle, LPS22HB_SPIMode_et spimode) |
nikapov | 0:cad5dab2b21d | 343 | { |
nikapov | 0:cad5dab2b21d | 344 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 345 | |
nikapov | 0:cad5dab2b21d | 346 | |
nikapov | 0:cad5dab2b21d | 347 | LPS22HB_assert_param(IS_LPS22HB_SPIMode(spimode)); |
nikapov | 0:cad5dab2b21d | 348 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 349 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 350 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 351 | |
nikapov | 0:cad5dab2b21d | 352 | tmp &= ~LPS22HB_SIM_MASK; |
nikapov | 0:cad5dab2b21d | 353 | tmp |= (uint8_t)spimode; |
nikapov | 0:cad5dab2b21d | 354 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 355 | if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 356 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 357 | |
nikapov | 0:cad5dab2b21d | 358 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 359 | } |
nikapov | 0:cad5dab2b21d | 360 | |
nikapov | 0:cad5dab2b21d | 361 | /** |
nikapov | 0:cad5dab2b21d | 362 | * @brief Clock Tree Configuration |
nikapov | 0:cad5dab2b21d | 363 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 364 | * @param LPS22HB_CTE_NotBalanced, LPS22HB_CTE_ABalanced |
nikapov | 0:cad5dab2b21d | 365 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 366 | */ |
nikapov | 0:cad5dab2b21d | 367 | LPS22HB_Error_et LPS22HB_Set_ClockTreeConfifuration(void *handle, LPS22HB_CTE_et mode) |
nikapov | 0:cad5dab2b21d | 368 | { |
nikapov | 0:cad5dab2b21d | 369 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 370 | |
nikapov | 0:cad5dab2b21d | 371 | |
nikapov | 0:cad5dab2b21d | 372 | LPS22HB_assert_param(IS_LPS22HB_CTE(mode)); |
nikapov | 0:cad5dab2b21d | 373 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 374 | if(LPS22HB_read_reg(handle, LPS22HB_CLOCK_TREE_CONFIGURATION, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 375 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 376 | |
nikapov | 0:cad5dab2b21d | 377 | tmp &= ~LPS22HB_CTE_MASK; |
nikapov | 0:cad5dab2b21d | 378 | tmp |= (uint8_t)mode; |
nikapov | 0:cad5dab2b21d | 379 | |
nikapov | 0:cad5dab2b21d | 380 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 381 | if(LPS22HB_write_reg(handle, LPS22HB_CLOCK_TREE_CONFIGURATION, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 382 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 383 | |
nikapov | 0:cad5dab2b21d | 384 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 385 | } |
nikapov | 0:cad5dab2b21d | 386 | |
nikapov | 0:cad5dab2b21d | 387 | |
nikapov | 0:cad5dab2b21d | 388 | /** |
nikapov | 0:cad5dab2b21d | 389 | * @brief Get SPI mode: 3 Wire Interface or 4 Wire Interface |
nikapov | 0:cad5dab2b21d | 390 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 391 | * @param Buffet to empty with spi mode read from Sensor |
nikapov | 0:cad5dab2b21d | 392 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 393 | */ |
nikapov | 0:cad5dab2b21d | 394 | LPS22HB_Error_et LPS22HB_Get_SpiInterface(void *handle, LPS22HB_SPIMode_et* spimode) |
nikapov | 0:cad5dab2b21d | 395 | { |
nikapov | 0:cad5dab2b21d | 396 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 397 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 398 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 399 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 400 | |
nikapov | 0:cad5dab2b21d | 401 | *spimode = (LPS22HB_SPIMode_et)(tmp & LPS22HB_SIM_MASK); |
nikapov | 0:cad5dab2b21d | 402 | |
nikapov | 0:cad5dab2b21d | 403 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 404 | } |
nikapov | 0:cad5dab2b21d | 405 | |
nikapov | 0:cad5dab2b21d | 406 | /** |
nikapov | 0:cad5dab2b21d | 407 | * @brief Software Reset. Self-clearing upon completion |
nikapov | 0:cad5dab2b21d | 408 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 409 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 410 | */ |
nikapov | 0:cad5dab2b21d | 411 | LPS22HB_Error_et LPS22HB_SwReset(void *handle) |
nikapov | 0:cad5dab2b21d | 412 | { |
nikapov | 0:cad5dab2b21d | 413 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 414 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 415 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 416 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 417 | |
nikapov | 0:cad5dab2b21d | 418 | tmp |= (0x01<<LPS22HB_SW_RESET_BIT); |
nikapov | 0:cad5dab2b21d | 419 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 420 | if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 421 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 422 | |
nikapov | 0:cad5dab2b21d | 423 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 424 | } |
nikapov | 0:cad5dab2b21d | 425 | |
nikapov | 0:cad5dab2b21d | 426 | /** |
nikapov | 0:cad5dab2b21d | 427 | * @brief Reboot Memory Content |
nikapov | 0:cad5dab2b21d | 428 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 429 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 430 | */ |
nikapov | 0:cad5dab2b21d | 431 | |
nikapov | 0:cad5dab2b21d | 432 | LPS22HB_Error_et LPS22HB_MemoryBoot(void *handle) |
nikapov | 0:cad5dab2b21d | 433 | { |
nikapov | 0:cad5dab2b21d | 434 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 435 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 436 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 437 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 438 | |
nikapov | 0:cad5dab2b21d | 439 | tmp |= (0x01<<LPS22HB_BOOT_BIT); |
nikapov | 0:cad5dab2b21d | 440 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 441 | if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 442 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 443 | |
nikapov | 0:cad5dab2b21d | 444 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 445 | } |
nikapov | 0:cad5dab2b21d | 446 | |
nikapov | 0:cad5dab2b21d | 447 | /** |
nikapov | 0:cad5dab2b21d | 448 | * @brief Software Reset ann Reboot Memory Content. |
nikapov | 0:cad5dab2b21d | 449 | * @detail The device is reset to the power on configuration if the SWRESET bit is set to ‘1’ |
nikapov | 0:cad5dab2b21d | 450 | + and BOOT is set to ‘1’; Self-clearing upon completion. |
nikapov | 0:cad5dab2b21d | 451 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 452 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 453 | */ |
nikapov | 0:cad5dab2b21d | 454 | LPS22HB_Error_et LPS22HB_SwResetAndMemoryBoot(void *handle) |
nikapov | 0:cad5dab2b21d | 455 | { |
nikapov | 0:cad5dab2b21d | 456 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 457 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 458 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 459 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 460 | |
nikapov | 0:cad5dab2b21d | 461 | tmp |= ((0x01<<LPS22HB_SW_RESET_BIT) | (0x01<<LPS22HB_BOOT_BIT)); |
nikapov | 0:cad5dab2b21d | 462 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 463 | if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 464 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 465 | |
nikapov | 0:cad5dab2b21d | 466 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 467 | } |
nikapov | 0:cad5dab2b21d | 468 | |
nikapov | 0:cad5dab2b21d | 469 | |
nikapov | 0:cad5dab2b21d | 470 | /** |
nikapov | 0:cad5dab2b21d | 471 | * @brief Enable/Disable FIFO Mode |
nikapov | 0:cad5dab2b21d | 472 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 473 | * @param LPS22HB_ENABLE/LPS22HB_DISABLE |
nikapov | 0:cad5dab2b21d | 474 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 475 | */ |
nikapov | 0:cad5dab2b21d | 476 | LPS22HB_Error_et LPS22HB_Set_FifoModeUse(void *handle, LPS22HB_State_et status) |
nikapov | 0:cad5dab2b21d | 477 | { |
nikapov | 0:cad5dab2b21d | 478 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 479 | |
nikapov | 0:cad5dab2b21d | 480 | LPS22HB_assert_param(IS_LPS22HB_State(status)); |
nikapov | 0:cad5dab2b21d | 481 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 482 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 483 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 484 | |
nikapov | 0:cad5dab2b21d | 485 | tmp &= ~LPS22HB_FIFO_EN_MASK; |
nikapov | 0:cad5dab2b21d | 486 | tmp |= ((uint8_t)status)<<LPS22HB_FIFO_EN_BIT; |
nikapov | 0:cad5dab2b21d | 487 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 488 | if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 489 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 490 | |
nikapov | 0:cad5dab2b21d | 491 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 492 | } |
nikapov | 0:cad5dab2b21d | 493 | /** |
nikapov | 0:cad5dab2b21d | 494 | * @brief Enable/Disable FIFO Watermark Level Use |
nikapov | 0:cad5dab2b21d | 495 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 496 | * @param LPS22HB_ENABLE/LPS22HB_DISABLE |
nikapov | 0:cad5dab2b21d | 497 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 498 | */ |
nikapov | 0:cad5dab2b21d | 499 | LPS22HB_Error_et LPS22HB_Set_FifoWatermarkLevelUse(void *handle, LPS22HB_State_et status) |
nikapov | 0:cad5dab2b21d | 500 | { |
nikapov | 0:cad5dab2b21d | 501 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 502 | |
nikapov | 0:cad5dab2b21d | 503 | LPS22HB_assert_param(IS_LPS22HB_State(status)); |
nikapov | 0:cad5dab2b21d | 504 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 505 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 506 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 507 | |
nikapov | 0:cad5dab2b21d | 508 | tmp &= ~LPS22HB_WTM_EN_MASK; |
nikapov | 0:cad5dab2b21d | 509 | tmp |= ((uint8_t)status)<<LPS22HB_WTM_EN_BIT; |
nikapov | 0:cad5dab2b21d | 510 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 511 | if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 512 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 513 | |
nikapov | 0:cad5dab2b21d | 514 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 515 | } |
nikapov | 0:cad5dab2b21d | 516 | |
nikapov | 0:cad5dab2b21d | 517 | /** |
nikapov | 0:cad5dab2b21d | 518 | * @brief Enable or Disable the Automatic increment register address during a multiple byte access with a serial interface (I2C or SPI) |
nikapov | 0:cad5dab2b21d | 519 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 520 | * @param LPS22HB_ENABLE/LPS22HB_DISABLE. Default is LPS22HB_ENABLE |
nikapov | 0:cad5dab2b21d | 521 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 522 | */ |
nikapov | 0:cad5dab2b21d | 523 | LPS22HB_Error_et LPS22HB_Set_AutomaticIncrementRegAddress(void *handle, LPS22HB_State_et status){ |
nikapov | 0:cad5dab2b21d | 524 | |
nikapov | 0:cad5dab2b21d | 525 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 526 | |
nikapov | 0:cad5dab2b21d | 527 | LPS22HB_assert_param(IS_LPS22HB_State(status)); |
nikapov | 0:cad5dab2b21d | 528 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 529 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 530 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 531 | |
nikapov | 0:cad5dab2b21d | 532 | tmp &= ~LPS22HB_ADD_INC_MASK; |
nikapov | 0:cad5dab2b21d | 533 | tmp |= (((uint8_t)status)<<LPS22HB_ADD_INC_BIT); |
nikapov | 0:cad5dab2b21d | 534 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 535 | if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 536 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 537 | |
nikapov | 0:cad5dab2b21d | 538 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 539 | |
nikapov | 0:cad5dab2b21d | 540 | } |
nikapov | 0:cad5dab2b21d | 541 | |
nikapov | 0:cad5dab2b21d | 542 | /** |
nikapov | 0:cad5dab2b21d | 543 | * @brief Enable/Disable I2C Interface |
nikapov | 0:cad5dab2b21d | 544 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 545 | * @param State: LPS22HB_ENABLE (reset bit)/ LPS22HB_DISABLE (set bit) |
nikapov | 0:cad5dab2b21d | 546 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 547 | */ |
nikapov | 0:cad5dab2b21d | 548 | LPS22HB_Error_et LPS22HB_Set_I2C(void *handle, LPS22HB_State_et statei2c) |
nikapov | 0:cad5dab2b21d | 549 | { |
nikapov | 0:cad5dab2b21d | 550 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 551 | |
nikapov | 0:cad5dab2b21d | 552 | LPS22HB_assert_param(IS_LPS22HB_State(statei2c)); |
nikapov | 0:cad5dab2b21d | 553 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 554 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 555 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 556 | |
nikapov | 0:cad5dab2b21d | 557 | /*Reset Bit->I2C Enabled*/ |
nikapov | 0:cad5dab2b21d | 558 | tmp &= ~LPS22HB_I2C_MASK; |
nikapov | 0:cad5dab2b21d | 559 | tmp|=((uint8_t)~statei2c)<<LPS22HB_I2C_BIT; |
nikapov | 0:cad5dab2b21d | 560 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 561 | if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 562 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 563 | |
nikapov | 0:cad5dab2b21d | 564 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 565 | } |
nikapov | 0:cad5dab2b21d | 566 | |
nikapov | 0:cad5dab2b21d | 567 | |
nikapov | 0:cad5dab2b21d | 568 | /** |
nikapov | 0:cad5dab2b21d | 569 | * @brief Set the one-shot bit in order to start acquisition when the ONE SHOT mode |
nikapov | 0:cad5dab2b21d | 570 | * has been selected by the ODR configuration. |
nikapov | 0:cad5dab2b21d | 571 | * @detail Once the measurement is done, ONE_SHOT bit will self-clear. |
nikapov | 0:cad5dab2b21d | 572 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 573 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 574 | */ |
nikapov | 0:cad5dab2b21d | 575 | LPS22HB_Error_et LPS22HB_StartOneShotMeasurement(void *handle) |
nikapov | 0:cad5dab2b21d | 576 | { |
nikapov | 0:cad5dab2b21d | 577 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 578 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 579 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 580 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 581 | |
nikapov | 0:cad5dab2b21d | 582 | /* Set the one shot bit */ |
nikapov | 0:cad5dab2b21d | 583 | /* Once the measurement is done, one shot bit will self-clear*/ |
nikapov | 0:cad5dab2b21d | 584 | tmp |= LPS22HB_ONE_SHOT_MASK; |
nikapov | 0:cad5dab2b21d | 585 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 586 | if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 587 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 588 | |
nikapov | 0:cad5dab2b21d | 589 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 590 | |
nikapov | 0:cad5dab2b21d | 591 | } |
nikapov | 0:cad5dab2b21d | 592 | |
nikapov | 0:cad5dab2b21d | 593 | /** |
nikapov | 0:cad5dab2b21d | 594 | * @brief Set Interrupt Active on High or Low Level |
nikapov | 0:cad5dab2b21d | 595 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 596 | * @param LPS22HB_ActiveHigh/LPS22HB_ActiveLow |
nikapov | 0:cad5dab2b21d | 597 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 598 | */ |
nikapov | 0:cad5dab2b21d | 599 | LPS22HB_Error_et LPS22HB_Set_InterruptActiveLevel(void *handle, LPS22HB_InterruptActiveLevel_et mode) |
nikapov | 0:cad5dab2b21d | 600 | { |
nikapov | 0:cad5dab2b21d | 601 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 602 | |
nikapov | 0:cad5dab2b21d | 603 | LPS22HB_assert_param(IS_LPS22HB_InterruptActiveLevel(mode)); |
nikapov | 0:cad5dab2b21d | 604 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 605 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 606 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 607 | |
nikapov | 0:cad5dab2b21d | 608 | tmp &= ~LPS22HB_INT_H_L_MASK; |
nikapov | 0:cad5dab2b21d | 609 | tmp |= ((uint8_t)mode); |
nikapov | 0:cad5dab2b21d | 610 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 611 | if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 612 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 613 | |
nikapov | 0:cad5dab2b21d | 614 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 615 | } |
nikapov | 0:cad5dab2b21d | 616 | |
nikapov | 0:cad5dab2b21d | 617 | |
nikapov | 0:cad5dab2b21d | 618 | /** |
nikapov | 0:cad5dab2b21d | 619 | * @brief Push-pull/open drain selection on interrupt pads. Default tmp: 0 |
nikapov | 0:cad5dab2b21d | 620 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 621 | * @param LPS22HB_PushPull/LPS22HB_OpenDrain |
nikapov | 0:cad5dab2b21d | 622 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 623 | */ |
nikapov | 0:cad5dab2b21d | 624 | LPS22HB_Error_et LPS22HB_Set_InterruptOutputType(void *handle, LPS22HB_OutputType_et output) |
nikapov | 0:cad5dab2b21d | 625 | { |
nikapov | 0:cad5dab2b21d | 626 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 627 | |
nikapov | 0:cad5dab2b21d | 628 | LPS22HB_assert_param(IS_LPS22HB_OutputType(output)); |
nikapov | 0:cad5dab2b21d | 629 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 630 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 631 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 632 | |
nikapov | 0:cad5dab2b21d | 633 | tmp &= ~LPS22HB_PP_OD_MASK; |
nikapov | 0:cad5dab2b21d | 634 | tmp |= (uint8_t)output; |
nikapov | 0:cad5dab2b21d | 635 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 636 | if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 637 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 638 | |
nikapov | 0:cad5dab2b21d | 639 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 640 | } |
nikapov | 0:cad5dab2b21d | 641 | |
nikapov | 0:cad5dab2b21d | 642 | /** |
nikapov | 0:cad5dab2b21d | 643 | * @brief Set Data signal on INT pad control bits. |
nikapov | 0:cad5dab2b21d | 644 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 645 | * @param LPS22HB_DATA,LPS22HB_P_HIGH_LPS22HB_P_LOW,LPS22HB_P_LOW_HIGH |
nikapov | 0:cad5dab2b21d | 646 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 647 | */ |
nikapov | 0:cad5dab2b21d | 648 | LPS22HB_Error_et LPS22HB_Set_InterruptControlConfig(void *handle, LPS22HB_OutputSignalConfig_et config) |
nikapov | 0:cad5dab2b21d | 649 | { |
nikapov | 0:cad5dab2b21d | 650 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 651 | |
nikapov | 0:cad5dab2b21d | 652 | LPS22HB_assert_param(IS_LPS22HB_OutputSignal(config)); |
nikapov | 0:cad5dab2b21d | 653 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 654 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 655 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 656 | |
nikapov | 0:cad5dab2b21d | 657 | tmp &= ~(LPS22HB_INT_S12_MASK); |
nikapov | 0:cad5dab2b21d | 658 | tmp |= (uint8_t)config; |
nikapov | 0:cad5dab2b21d | 659 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 660 | if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 661 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 662 | |
nikapov | 0:cad5dab2b21d | 663 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 664 | } |
nikapov | 0:cad5dab2b21d | 665 | |
nikapov | 0:cad5dab2b21d | 666 | |
nikapov | 0:cad5dab2b21d | 667 | /** |
nikapov | 0:cad5dab2b21d | 668 | * @brief Enable/Disable Data-ready signal on INT_DRDY pin. |
nikapov | 0:cad5dab2b21d | 669 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 670 | * @param LPS22HB_ENABLE/LPS22HB_DISABLE |
nikapov | 0:cad5dab2b21d | 671 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 672 | */ |
nikapov | 0:cad5dab2b21d | 673 | LPS22HB_Error_et LPS22HB_Set_DRDYInterrupt(void *handle, LPS22HB_State_et status) |
nikapov | 0:cad5dab2b21d | 674 | { |
nikapov | 0:cad5dab2b21d | 675 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 676 | |
nikapov | 0:cad5dab2b21d | 677 | |
nikapov | 0:cad5dab2b21d | 678 | LPS22HB_assert_param(IS_LPS22HB_State(status)); |
nikapov | 0:cad5dab2b21d | 679 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 680 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 681 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 682 | |
nikapov | 0:cad5dab2b21d | 683 | tmp &= ~LPS22HB_DRDY_MASK; |
nikapov | 0:cad5dab2b21d | 684 | tmp |= ((uint8_t)status)<<LPS22HB_DRDY_BIT; |
nikapov | 0:cad5dab2b21d | 685 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 686 | if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 687 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 688 | |
nikapov | 0:cad5dab2b21d | 689 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 690 | } |
nikapov | 0:cad5dab2b21d | 691 | |
nikapov | 0:cad5dab2b21d | 692 | /** |
nikapov | 0:cad5dab2b21d | 693 | * @brief Enable/Disable FIFO overrun interrupt on INT_DRDY pin. |
nikapov | 0:cad5dab2b21d | 694 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 695 | * @param LPS22HB_ENABLE/LPS22HB_DISABLE |
nikapov | 0:cad5dab2b21d | 696 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 697 | */ |
nikapov | 0:cad5dab2b21d | 698 | LPS22HB_Error_et LPS22HB_Set_FIFO_OVR_Interrupt(void *handle, LPS22HB_State_et status) |
nikapov | 0:cad5dab2b21d | 699 | { |
nikapov | 0:cad5dab2b21d | 700 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 701 | |
nikapov | 0:cad5dab2b21d | 702 | |
nikapov | 0:cad5dab2b21d | 703 | LPS22HB_assert_param(IS_LPS22HB_State(status)); |
nikapov | 0:cad5dab2b21d | 704 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 705 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 706 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 707 | |
nikapov | 0:cad5dab2b21d | 708 | tmp &= ~LPS22HB_FIFO_OVR_MASK; |
nikapov | 0:cad5dab2b21d | 709 | tmp |= ((uint8_t)status)<<LPS22HB_FIFO_OVR_BIT; |
nikapov | 0:cad5dab2b21d | 710 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 711 | if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 712 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 713 | |
nikapov | 0:cad5dab2b21d | 714 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 715 | } |
nikapov | 0:cad5dab2b21d | 716 | |
nikapov | 0:cad5dab2b21d | 717 | /** |
nikapov | 0:cad5dab2b21d | 718 | * @brief Enable/Disable FIFO threshold (Watermark) interrupt on INT_DRDY pin. |
nikapov | 0:cad5dab2b21d | 719 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 720 | * @param LPS22HB_ENABLE/LPS22HB_DISABLE |
nikapov | 0:cad5dab2b21d | 721 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 722 | */ |
nikapov | 0:cad5dab2b21d | 723 | LPS22HB_Error_et LPS22HB_Set_FIFO_FTH_Interrupt(void *handle, LPS22HB_State_et status) |
nikapov | 0:cad5dab2b21d | 724 | { |
nikapov | 0:cad5dab2b21d | 725 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 726 | |
nikapov | 0:cad5dab2b21d | 727 | LPS22HB_assert_param(IS_LPS22HB_State(status)); |
nikapov | 0:cad5dab2b21d | 728 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 729 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 730 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 731 | |
nikapov | 0:cad5dab2b21d | 732 | tmp &= ~LPS22HB_FIFO_FTH_MASK; |
nikapov | 0:cad5dab2b21d | 733 | tmp |= ((uint8_t)status)<<LPS22HB_FIFO_FTH_BIT; |
nikapov | 0:cad5dab2b21d | 734 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 735 | if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 736 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 737 | |
nikapov | 0:cad5dab2b21d | 738 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 739 | } |
nikapov | 0:cad5dab2b21d | 740 | |
nikapov | 0:cad5dab2b21d | 741 | /** |
nikapov | 0:cad5dab2b21d | 742 | * @brief Enable/Disable FIFO FULL interrupt on INT_DRDY pin. |
nikapov | 0:cad5dab2b21d | 743 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 744 | * @param LPS22HB_ENABLE/LPS22HB_DISABLE |
nikapov | 0:cad5dab2b21d | 745 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 746 | */ |
nikapov | 0:cad5dab2b21d | 747 | LPS22HB_Error_et LPS22HB_Set_FIFO_FULL_Interrupt(void *handle, LPS22HB_State_et status) |
nikapov | 0:cad5dab2b21d | 748 | { |
nikapov | 0:cad5dab2b21d | 749 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 750 | |
nikapov | 0:cad5dab2b21d | 751 | LPS22HB_assert_param(IS_LPS22HB_State(status)); |
nikapov | 0:cad5dab2b21d | 752 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 753 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 754 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 755 | |
nikapov | 0:cad5dab2b21d | 756 | tmp &= ~LPS22HB_FIFO_FULL_MASK; |
nikapov | 0:cad5dab2b21d | 757 | tmp |= ((uint8_t)status)<<LPS22HB_FIFO_FULL_BIT; |
nikapov | 0:cad5dab2b21d | 758 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 759 | if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 760 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 761 | |
nikapov | 0:cad5dab2b21d | 762 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 763 | } |
nikapov | 0:cad5dab2b21d | 764 | |
nikapov | 0:cad5dab2b21d | 765 | |
nikapov | 0:cad5dab2b21d | 766 | |
nikapov | 0:cad5dab2b21d | 767 | /** |
nikapov | 0:cad5dab2b21d | 768 | * @brief Enable AutoRifP function |
nikapov | 0:cad5dab2b21d | 769 | * @detail When this function is enabled, an internal register is set with the current pressure values |
nikapov | 0:cad5dab2b21d | 770 | * and the content is subtracted from the pressure output value and result is used for the interrupt generation. |
nikapov | 0:cad5dab2b21d | 771 | * the AutoRifP is slf creared. |
nikapov | 0:cad5dab2b21d | 772 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 773 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 774 | */ |
nikapov | 0:cad5dab2b21d | 775 | LPS22HB_Error_et LPS22HB_Set_AutoRifP(void *handle) |
nikapov | 0:cad5dab2b21d | 776 | { |
nikapov | 0:cad5dab2b21d | 777 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 778 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 779 | if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 780 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 781 | |
nikapov | 0:cad5dab2b21d | 782 | tmp |= ((uint8_t)LPS22HB_AUTORIFP_MASK); |
nikapov | 0:cad5dab2b21d | 783 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 784 | if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 785 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 786 | |
nikapov | 0:cad5dab2b21d | 787 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 788 | } |
nikapov | 0:cad5dab2b21d | 789 | |
nikapov | 0:cad5dab2b21d | 790 | /** |
nikapov | 0:cad5dab2b21d | 791 | * @brief Disable AutoRifP function |
nikapov | 0:cad5dab2b21d | 792 | * @detail the RESET_ARP bit is used to disable the AUTORIFP function. This bis i is selfdleared |
nikapov | 0:cad5dab2b21d | 793 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 794 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 795 | */ |
nikapov | 0:cad5dab2b21d | 796 | LPS22HB_Error_et LPS22HB_ResetAutoRifP(void *handle) |
nikapov | 0:cad5dab2b21d | 797 | { |
nikapov | 0:cad5dab2b21d | 798 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 799 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 800 | if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 801 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 802 | |
nikapov | 0:cad5dab2b21d | 803 | |
nikapov | 0:cad5dab2b21d | 804 | tmp |= ((uint8_t)LPS22HB_RESET_ARP_MASK); |
nikapov | 0:cad5dab2b21d | 805 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 806 | if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 807 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 808 | |
nikapov | 0:cad5dab2b21d | 809 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 810 | } |
nikapov | 0:cad5dab2b21d | 811 | |
nikapov | 0:cad5dab2b21d | 812 | |
nikapov | 0:cad5dab2b21d | 813 | /* |
nikapov | 0:cad5dab2b21d | 814 | * @brief Set AutoZero Function bit |
nikapov | 0:cad5dab2b21d | 815 | * @detail When set to ‘1’, the actual pressure output is copied in the REF_P reg (@0x15..0x17) |
nikapov | 0:cad5dab2b21d | 816 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 817 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 818 | */ |
nikapov | 0:cad5dab2b21d | 819 | LPS22HB_Error_et LPS22HB_Set_AutoZeroFunction(void *handle) |
nikapov | 0:cad5dab2b21d | 820 | { |
nikapov | 0:cad5dab2b21d | 821 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 822 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 823 | if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 824 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 825 | |
nikapov | 0:cad5dab2b21d | 826 | tmp |= LPS22HB_AUTOZERO_MASK; |
nikapov | 0:cad5dab2b21d | 827 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 828 | if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 829 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 830 | |
nikapov | 0:cad5dab2b21d | 831 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 832 | } |
nikapov | 0:cad5dab2b21d | 833 | |
nikapov | 0:cad5dab2b21d | 834 | |
nikapov | 0:cad5dab2b21d | 835 | /* |
nikapov | 0:cad5dab2b21d | 836 | * @brief Set ResetAutoZero Function bit |
nikapov | 0:cad5dab2b21d | 837 | * @details REF_P reg (@0x015..17) set pressure reference to default value RPDS reg (0x18/19). |
nikapov | 0:cad5dab2b21d | 838 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 839 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 840 | */ |
nikapov | 0:cad5dab2b21d | 841 | LPS22HB_Error_et LPS22HB_ResetAutoZeroFunction(void *handle) |
nikapov | 0:cad5dab2b21d | 842 | { |
nikapov | 0:cad5dab2b21d | 843 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 844 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 845 | if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 846 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 847 | |
nikapov | 0:cad5dab2b21d | 848 | /* Set the RESET_AZ bit*/ |
nikapov | 0:cad5dab2b21d | 849 | /* RESET_AZ is self cleared*/ |
nikapov | 0:cad5dab2b21d | 850 | tmp |= LPS22HB_RESET_AZ_MASK; |
nikapov | 0:cad5dab2b21d | 851 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 852 | if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 853 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 854 | |
nikapov | 0:cad5dab2b21d | 855 | |
nikapov | 0:cad5dab2b21d | 856 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 857 | } |
nikapov | 0:cad5dab2b21d | 858 | |
nikapov | 0:cad5dab2b21d | 859 | |
nikapov | 0:cad5dab2b21d | 860 | /** |
nikapov | 0:cad5dab2b21d | 861 | * @brief Enable/ Disable the computing of differential pressure output (Interrupt Generation) |
nikapov | 0:cad5dab2b21d | 862 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 863 | * @param LPS22HB_ENABLE,LPS22HB_DISABLE |
nikapov | 0:cad5dab2b21d | 864 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 865 | */ |
nikapov | 0:cad5dab2b21d | 866 | LPS22HB_Error_et LPS22HB_Set_InterruptDifferentialGeneration(void *handle, LPS22HB_State_et diff_en) |
nikapov | 0:cad5dab2b21d | 867 | { |
nikapov | 0:cad5dab2b21d | 868 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 869 | |
nikapov | 0:cad5dab2b21d | 870 | LPS22HB_assert_param(IS_LPS22HB_State(diff_en)); |
nikapov | 0:cad5dab2b21d | 871 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 872 | if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 873 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 874 | |
nikapov | 0:cad5dab2b21d | 875 | tmp &= ~LPS22HB_DIFF_EN_MASK; |
nikapov | 0:cad5dab2b21d | 876 | tmp |= ((uint8_t)diff_en)<<LPS22HB_DIFF_EN_BIT; |
nikapov | 0:cad5dab2b21d | 877 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 878 | if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 879 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 880 | |
nikapov | 0:cad5dab2b21d | 881 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 882 | } |
nikapov | 0:cad5dab2b21d | 883 | |
nikapov | 0:cad5dab2b21d | 884 | |
nikapov | 0:cad5dab2b21d | 885 | /** |
nikapov | 0:cad5dab2b21d | 886 | * @brief Get the DIFF_EN bit value |
nikapov | 0:cad5dab2b21d | 887 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 888 | * @param buffer to empty with the read value of DIFF_EN bit |
nikapov | 0:cad5dab2b21d | 889 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 890 | */ |
nikapov | 0:cad5dab2b21d | 891 | LPS22HB_Error_et LPS22HB_Get_InterruptDifferentialGeneration(void *handle, LPS22HB_State_et* diff_en) |
nikapov | 0:cad5dab2b21d | 892 | { |
nikapov | 0:cad5dab2b21d | 893 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 894 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 895 | if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 896 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 897 | |
nikapov | 0:cad5dab2b21d | 898 | *diff_en= (LPS22HB_State_et)((tmp & LPS22HB_DIFF_EN_MASK)>>LPS22HB_DIFF_EN_BIT); |
nikapov | 0:cad5dab2b21d | 899 | |
nikapov | 0:cad5dab2b21d | 900 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 901 | } |
nikapov | 0:cad5dab2b21d | 902 | |
nikapov | 0:cad5dab2b21d | 903 | /** |
nikapov | 0:cad5dab2b21d | 904 | * @brief Latch Interrupt request to the INT_SOURCE register. |
nikapov | 0:cad5dab2b21d | 905 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 906 | * @param LPS22HB_ENABLE/LPS22HB_DISABLE |
nikapov | 0:cad5dab2b21d | 907 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 908 | */ |
nikapov | 0:cad5dab2b21d | 909 | LPS22HB_Error_et LPS22HB_LatchInterruptRequest(void *handle, LPS22HB_State_et status) |
nikapov | 0:cad5dab2b21d | 910 | { |
nikapov | 0:cad5dab2b21d | 911 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 912 | |
nikapov | 0:cad5dab2b21d | 913 | LPS22HB_assert_param(IS_LPS22HB_State(status)); |
nikapov | 0:cad5dab2b21d | 914 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 915 | if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 916 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 917 | |
nikapov | 0:cad5dab2b21d | 918 | tmp &= ~LPS22HB_LIR_MASK; |
nikapov | 0:cad5dab2b21d | 919 | tmp |= (((uint8_t)status)<<LPS22HB_LIR_BIT); |
nikapov | 0:cad5dab2b21d | 920 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 921 | if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 922 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 923 | |
nikapov | 0:cad5dab2b21d | 924 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 925 | } |
nikapov | 0:cad5dab2b21d | 926 | |
nikapov | 0:cad5dab2b21d | 927 | |
nikapov | 0:cad5dab2b21d | 928 | |
nikapov | 0:cad5dab2b21d | 929 | /** |
nikapov | 0:cad5dab2b21d | 930 | * @brief Enable\Disable Interrupt Generation on differential pressure Low event |
nikapov | 0:cad5dab2b21d | 931 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 932 | * @param LPS22HB_ENABLE/LPS22HB_DISABLE |
nikapov | 0:cad5dab2b21d | 933 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 934 | */ |
nikapov | 0:cad5dab2b21d | 935 | LPS22HB_Error_et LPS22HB_Set_PLE(void *handle, LPS22HB_State_et status) |
nikapov | 0:cad5dab2b21d | 936 | { |
nikapov | 0:cad5dab2b21d | 937 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 938 | |
nikapov | 0:cad5dab2b21d | 939 | LPS22HB_assert_param(IS_LPS22HB_State(status)); |
nikapov | 0:cad5dab2b21d | 940 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 941 | if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 942 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 943 | |
nikapov | 0:cad5dab2b21d | 944 | tmp &= ~LPS22HB_PLE_MASK; |
nikapov | 0:cad5dab2b21d | 945 | tmp |= (((uint8_t)status)<<LPS22HB_PLE_BIT); |
nikapov | 0:cad5dab2b21d | 946 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 947 | if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 948 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 949 | |
nikapov | 0:cad5dab2b21d | 950 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 951 | } |
nikapov | 0:cad5dab2b21d | 952 | |
nikapov | 0:cad5dab2b21d | 953 | /** |
nikapov | 0:cad5dab2b21d | 954 | * @brief Enable\Disable Interrupt Generation on differential pressure High event |
nikapov | 0:cad5dab2b21d | 955 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 956 | * @param LPS22HB_ENABLE/LPS22HB_DISABLE |
nikapov | 0:cad5dab2b21d | 957 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 958 | */ |
nikapov | 0:cad5dab2b21d | 959 | LPS22HB_Error_et LPS22HB_Set_PHE(void *handle, LPS22HB_State_et status) |
nikapov | 0:cad5dab2b21d | 960 | { |
nikapov | 0:cad5dab2b21d | 961 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 962 | |
nikapov | 0:cad5dab2b21d | 963 | LPS22HB_assert_param(IS_LPS22HB_State(status)); |
nikapov | 0:cad5dab2b21d | 964 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 965 | if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 966 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 967 | |
nikapov | 0:cad5dab2b21d | 968 | tmp &= ~LPS22HB_PHE_MASK; |
nikapov | 0:cad5dab2b21d | 969 | tmp |= (((uint8_t)status)<<LPS22HB_PHE_BIT); |
nikapov | 0:cad5dab2b21d | 970 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 971 | if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 972 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 973 | |
nikapov | 0:cad5dab2b21d | 974 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 975 | } |
nikapov | 0:cad5dab2b21d | 976 | |
nikapov | 0:cad5dab2b21d | 977 | /** |
nikapov | 0:cad5dab2b21d | 978 | * @brief Get the Interrupt Generation on differential pressure status event and the Boot Status. |
nikapov | 0:cad5dab2b21d | 979 | * @detail The INT_SOURCE register is cleared by reading it. |
nikapov | 0:cad5dab2b21d | 980 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 981 | * @param Status Event Flag: BOOT, PH,PL,IA |
nikapov | 0:cad5dab2b21d | 982 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 983 | */ |
nikapov | 0:cad5dab2b21d | 984 | LPS22HB_Error_et LPS22HB_Get_InterruptDifferentialEventStatus(void *handle, LPS22HB_InterruptDiffStatus_st* interruptsource) |
nikapov | 0:cad5dab2b21d | 985 | { |
nikapov | 0:cad5dab2b21d | 986 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 987 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 988 | if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_SOURCE_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 989 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 990 | |
nikapov | 0:cad5dab2b21d | 991 | interruptsource->PH = (uint8_t)(tmp & LPS22HB_PH_MASK); |
nikapov | 0:cad5dab2b21d | 992 | interruptsource->PL = (uint8_t)((tmp & LPS22HB_PL_MASK)>>LPS22HB_PL_BIT); |
nikapov | 0:cad5dab2b21d | 993 | interruptsource->IA = (uint8_t)((tmp & LPS22HB_IA_MASK)>>LPS22HB_IA_BIT); |
nikapov | 0:cad5dab2b21d | 994 | interruptsource->BOOT= (uint8_t)((tmp & LPS22HB_BOOT_STATUS_MASK)>>LPS22HB_BOOT_STATUS_BIT); |
nikapov | 0:cad5dab2b21d | 995 | |
nikapov | 0:cad5dab2b21d | 996 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 997 | } |
nikapov | 0:cad5dab2b21d | 998 | |
nikapov | 0:cad5dab2b21d | 999 | /** |
nikapov | 0:cad5dab2b21d | 1000 | * @brief Get the status of Pressure and Temperature data |
nikapov | 0:cad5dab2b21d | 1001 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 1002 | * @param Data Status Flag: TempDataAvailable, TempDataOverrun, PressDataAvailable, PressDataOverrun |
nikapov | 0:cad5dab2b21d | 1003 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 1004 | */ |
nikapov | 0:cad5dab2b21d | 1005 | LPS22HB_Error_et LPS22HB_Get_DataStatus(void *handle, LPS22HB_DataStatus_st* datastatus) |
nikapov | 0:cad5dab2b21d | 1006 | { |
nikapov | 0:cad5dab2b21d | 1007 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 1008 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 1009 | if(LPS22HB_read_reg(handle, LPS22HB_STATUS_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 1010 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1011 | |
nikapov | 0:cad5dab2b21d | 1012 | datastatus->PressDataAvailable = (uint8_t)(tmp & LPS22HB_PDA_MASK); |
nikapov | 0:cad5dab2b21d | 1013 | datastatus->TempDataAvailable = (uint8_t)((tmp & LPS22HB_TDA_MASK)>>LPS22HB_PDA_BIT); |
nikapov | 0:cad5dab2b21d | 1014 | datastatus->TempDataOverrun = (uint8_t)((tmp & LPS22HB_TOR_MASK)>>LPS22HB_TOR_BIT); |
nikapov | 0:cad5dab2b21d | 1015 | datastatus->PressDataOverrun = (uint8_t)((tmp & LPS22HB_POR_MASK)>>LPS22HB_POR_BIT); |
nikapov | 0:cad5dab2b21d | 1016 | |
nikapov | 0:cad5dab2b21d | 1017 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 1018 | } |
nikapov | 0:cad5dab2b21d | 1019 | |
nikapov | 0:cad5dab2b21d | 1020 | |
nikapov | 0:cad5dab2b21d | 1021 | |
nikapov | 0:cad5dab2b21d | 1022 | /** |
nikapov | 0:cad5dab2b21d | 1023 | * @brief Get the LPS22HB raw presure value |
nikapov | 0:cad5dab2b21d | 1024 | * @detail The data are expressed as PRESS_OUT_H/_L/_XL in 2’s complement. |
nikapov | 0:cad5dab2b21d | 1025 | Pout(hPA)=PRESS_OUT / 4096 |
nikapov | 0:cad5dab2b21d | 1026 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 1027 | * @param The buffer to empty with the pressure raw value |
nikapov | 0:cad5dab2b21d | 1028 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 1029 | */ |
nikapov | 0:cad5dab2b21d | 1030 | LPS22HB_Error_et LPS22HB_Get_RawPressure(void *handle, int32_t *raw_press) |
nikapov | 0:cad5dab2b21d | 1031 | { |
nikapov | 0:cad5dab2b21d | 1032 | uint8_t buffer[3]; |
nikapov | 0:cad5dab2b21d | 1033 | uint32_t tmp = 0; |
nikapov | 0:cad5dab2b21d | 1034 | uint8_t i; |
nikapov | 0:cad5dab2b21d | 1035 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 1036 | if(LPS22HB_read_reg(handle, LPS22HB_PRESS_OUT_XL_REG, 3, buffer)) |
nikapov | 0:cad5dab2b21d | 1037 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1038 | |
nikapov | 0:cad5dab2b21d | 1039 | /* Build the raw data */ |
nikapov | 0:cad5dab2b21d | 1040 | for(i=0; i<3; i++) |
nikapov | 0:cad5dab2b21d | 1041 | tmp |= (((uint32_t)buffer[i]) << (8*i)); |
nikapov | 0:cad5dab2b21d | 1042 | |
nikapov | 0:cad5dab2b21d | 1043 | /* convert the 2's complement 24 bit to 2's complement 32 bit */ |
nikapov | 0:cad5dab2b21d | 1044 | if(tmp & 0x00800000) |
nikapov | 0:cad5dab2b21d | 1045 | tmp |= 0xFF000000; |
nikapov | 0:cad5dab2b21d | 1046 | |
nikapov | 0:cad5dab2b21d | 1047 | *raw_press = ((int32_t)tmp); |
nikapov | 0:cad5dab2b21d | 1048 | |
nikapov | 0:cad5dab2b21d | 1049 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 1050 | } |
nikapov | 0:cad5dab2b21d | 1051 | |
nikapov | 0:cad5dab2b21d | 1052 | /** |
nikapov | 0:cad5dab2b21d | 1053 | * @brief Get the LPS22HB Pressure value in hPA. |
nikapov | 0:cad5dab2b21d | 1054 | * @detail The data are expressed as PRESS_OUT_H/_L/_XL in 2’s complement. |
nikapov | 0:cad5dab2b21d | 1055 | Pout(hPA)=PRESS_OUT / 4096 |
nikapov | 0:cad5dab2b21d | 1056 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 1057 | * @param The buffer to empty with the pressure value that must be divided by 100 to get the value in hPA |
nikapov | 0:cad5dab2b21d | 1058 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 1059 | */ |
nikapov | 0:cad5dab2b21d | 1060 | LPS22HB_Error_et LPS22HB_Get_Pressure(void *handle, int32_t* Pout) |
nikapov | 0:cad5dab2b21d | 1061 | { |
nikapov | 0:cad5dab2b21d | 1062 | int32_t raw_press; |
nikapov | 0:cad5dab2b21d | 1063 | |
nikapov | 0:cad5dab2b21d | 1064 | if(LPS22HB_Get_RawPressure(handle, &raw_press)) |
nikapov | 0:cad5dab2b21d | 1065 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1066 | |
nikapov | 0:cad5dab2b21d | 1067 | *Pout = (raw_press*100)/4096; |
nikapov | 0:cad5dab2b21d | 1068 | |
nikapov | 0:cad5dab2b21d | 1069 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 1070 | } |
nikapov | 0:cad5dab2b21d | 1071 | |
nikapov | 0:cad5dab2b21d | 1072 | /** |
nikapov | 0:cad5dab2b21d | 1073 | * @brief Get the Raw Temperature value. |
nikapov | 0:cad5dab2b21d | 1074 | * @detail Temperature data are expressed as TEMP_OUT_H&TEMP_OUT_L as 2’s complement number. |
nikapov | 0:cad5dab2b21d | 1075 | * Tout(degC)=TEMP_OUT/100 |
nikapov | 0:cad5dab2b21d | 1076 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 1077 | * @param Buffer to empty with the temperature raw tmp. |
nikapov | 0:cad5dab2b21d | 1078 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 1079 | */ |
nikapov | 0:cad5dab2b21d | 1080 | LPS22HB_Error_et LPS22HB_Get_RawTemperature(void *handle, int16_t* raw_data) |
nikapov | 0:cad5dab2b21d | 1081 | { |
nikapov | 0:cad5dab2b21d | 1082 | uint8_t buffer[2]; |
nikapov | 0:cad5dab2b21d | 1083 | uint16_t tmp; |
nikapov | 0:cad5dab2b21d | 1084 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 1085 | if(LPS22HB_read_reg(handle, LPS22HB_TEMP_OUT_L_REG, 2, buffer)) |
nikapov | 0:cad5dab2b21d | 1086 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1087 | |
nikapov | 0:cad5dab2b21d | 1088 | /* Build the raw tmp */ |
nikapov | 0:cad5dab2b21d | 1089 | tmp = (((uint16_t)buffer[1]) << 8) + (uint16_t)buffer[0]; |
nikapov | 0:cad5dab2b21d | 1090 | |
nikapov | 0:cad5dab2b21d | 1091 | *raw_data = ((int16_t)tmp); |
nikapov | 0:cad5dab2b21d | 1092 | |
nikapov | 0:cad5dab2b21d | 1093 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 1094 | } |
nikapov | 0:cad5dab2b21d | 1095 | |
nikapov | 0:cad5dab2b21d | 1096 | |
nikapov | 0:cad5dab2b21d | 1097 | /** |
nikapov | 0:cad5dab2b21d | 1098 | * @brief Get the Temperature value in °C. |
nikapov | 0:cad5dab2b21d | 1099 | * @detail Temperature data are expressed as TEMP_OUT_H&TEMP_OUT_L as 2’s complement number. |
nikapov | 0:cad5dab2b21d | 1100 | * Tout(degC)=TEMP_OUT/100 |
nikapov | 0:cad5dab2b21d | 1101 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 1102 | * @param Buffer to empty with the temperature value that must be divided by 10 to get the value in °C |
nikapov | 0:cad5dab2b21d | 1103 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 1104 | */ |
nikapov | 0:cad5dab2b21d | 1105 | LPS22HB_Error_et LPS22HB_Get_Temperature(void *handle, int16_t* Tout) |
nikapov | 0:cad5dab2b21d | 1106 | { |
nikapov | 0:cad5dab2b21d | 1107 | int16_t raw_data; |
nikapov | 0:cad5dab2b21d | 1108 | |
nikapov | 0:cad5dab2b21d | 1109 | if(LPS22HB_Get_RawTemperature(handle, &raw_data)) |
nikapov | 0:cad5dab2b21d | 1110 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1111 | |
nikapov | 0:cad5dab2b21d | 1112 | *Tout = (raw_data*10)/100; |
nikapov | 0:cad5dab2b21d | 1113 | |
nikapov | 0:cad5dab2b21d | 1114 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 1115 | } |
nikapov | 0:cad5dab2b21d | 1116 | |
nikapov | 0:cad5dab2b21d | 1117 | /** |
nikapov | 0:cad5dab2b21d | 1118 | * @brief Get the threshold value used for pressure interrupt generation (hPA). |
nikapov | 0:cad5dab2b21d | 1119 | * @detail THS_P=THS_P_H&THS_P_L and is expressed as unsigned number. P_ths(hPA)=(THS_P)/16. |
nikapov | 0:cad5dab2b21d | 1120 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 1121 | * @param Buffer to empty with the pressure threshold in hPA |
nikapov | 0:cad5dab2b21d | 1122 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 1123 | */ |
nikapov | 0:cad5dab2b21d | 1124 | LPS22HB_Error_et LPS22HB_Get_PressureThreshold(void *handle, int16_t* P_ths) |
nikapov | 0:cad5dab2b21d | 1125 | { |
nikapov | 0:cad5dab2b21d | 1126 | uint8_t tempReg[2]; |
nikapov | 0:cad5dab2b21d | 1127 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 1128 | if(LPS22HB_read_reg(handle, LPS22HB_THS_P_LOW_REG, 2, tempReg)) |
nikapov | 0:cad5dab2b21d | 1129 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1130 | |
nikapov | 0:cad5dab2b21d | 1131 | *P_ths= (((((uint16_t)tempReg[1])<<8) + tempReg[0])/16); |
nikapov | 0:cad5dab2b21d | 1132 | |
nikapov | 0:cad5dab2b21d | 1133 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 1134 | } |
nikapov | 0:cad5dab2b21d | 1135 | |
nikapov | 0:cad5dab2b21d | 1136 | /** |
nikapov | 0:cad5dab2b21d | 1137 | * @brief Set the threshold value used for pressure interrupt generation (hPA). |
nikapov | 0:cad5dab2b21d | 1138 | * @detail THS_P=THS_P_H&THS_P_L and is expressed as unsigned number. P_ths(hPA)=(THS_P)/16. |
nikapov | 0:cad5dab2b21d | 1139 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 1140 | * @param Pressure threshold in hPA |
nikapov | 0:cad5dab2b21d | 1141 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 1142 | */ |
nikapov | 0:cad5dab2b21d | 1143 | LPS22HB_Error_et LPS22HB_Set_PressureThreshold(void *handle, int16_t P_ths) |
nikapov | 0:cad5dab2b21d | 1144 | { |
nikapov | 0:cad5dab2b21d | 1145 | uint8_t buffer[2]; |
nikapov | 0:cad5dab2b21d | 1146 | |
nikapov | 0:cad5dab2b21d | 1147 | buffer[0] = (uint8_t)(16 * P_ths); |
nikapov | 0:cad5dab2b21d | 1148 | buffer[1] = (uint8_t)(((uint16_t)(16 * P_ths))>>8); |
nikapov | 0:cad5dab2b21d | 1149 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 1150 | if(LPS22HB_write_reg(handle, LPS22HB_THS_P_LOW_REG, 2, buffer)) |
nikapov | 0:cad5dab2b21d | 1151 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1152 | |
nikapov | 0:cad5dab2b21d | 1153 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 1154 | } |
nikapov | 0:cad5dab2b21d | 1155 | |
nikapov | 0:cad5dab2b21d | 1156 | /** |
nikapov | 0:cad5dab2b21d | 1157 | * @brief Set Fifo Mode. |
nikapov | 0:cad5dab2b21d | 1158 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 1159 | * @param Fifo Mode struct |
nikapov | 0:cad5dab2b21d | 1160 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 1161 | */ |
nikapov | 0:cad5dab2b21d | 1162 | LPS22HB_Error_et LPS22HB_Set_FifoMode(void *handle, LPS22HB_FifoMode_et fifomode) |
nikapov | 0:cad5dab2b21d | 1163 | { |
nikapov | 0:cad5dab2b21d | 1164 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 1165 | |
nikapov | 0:cad5dab2b21d | 1166 | LPS22HB_assert_param(IS_LPS22HB_FifoMode(fifomode)); |
nikapov | 0:cad5dab2b21d | 1167 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 1168 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 1169 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1170 | |
nikapov | 0:cad5dab2b21d | 1171 | tmp &= ~LPS22HB_FIFO_MODE_MASK; |
nikapov | 0:cad5dab2b21d | 1172 | tmp |= (uint8_t)fifomode; |
nikapov | 0:cad5dab2b21d | 1173 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 1174 | if(LPS22HB_write_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 1175 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1176 | |
nikapov | 0:cad5dab2b21d | 1177 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 1178 | } |
nikapov | 0:cad5dab2b21d | 1179 | |
nikapov | 0:cad5dab2b21d | 1180 | /** |
nikapov | 0:cad5dab2b21d | 1181 | * @brief Get Fifo Mode |
nikapov | 0:cad5dab2b21d | 1182 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 1183 | * @param buffer to empty with fifo mode tmp |
nikapov | 0:cad5dab2b21d | 1184 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 1185 | */ |
nikapov | 0:cad5dab2b21d | 1186 | LPS22HB_Error_et LPS22HB_Get_FifoMode(void *handle, LPS22HB_FifoMode_et* fifomode) |
nikapov | 0:cad5dab2b21d | 1187 | { |
nikapov | 0:cad5dab2b21d | 1188 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 1189 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 1190 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 1191 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1192 | |
nikapov | 0:cad5dab2b21d | 1193 | tmp &= LPS22HB_FIFO_MODE_MASK; |
nikapov | 0:cad5dab2b21d | 1194 | *fifomode = (LPS22HB_FifoMode_et)tmp; |
nikapov | 0:cad5dab2b21d | 1195 | |
nikapov | 0:cad5dab2b21d | 1196 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 1197 | } |
nikapov | 0:cad5dab2b21d | 1198 | |
nikapov | 0:cad5dab2b21d | 1199 | /** |
nikapov | 0:cad5dab2b21d | 1200 | * @brief Set Fifo Watermark Level. |
nikapov | 0:cad5dab2b21d | 1201 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 1202 | * @param Watermark level value [0 31] |
nikapov | 0:cad5dab2b21d | 1203 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 1204 | */ |
nikapov | 0:cad5dab2b21d | 1205 | LPS22HB_Error_et LPS22HB_Set_FifoWatermarkLevel(void *handle, uint8_t wtmlevel) |
nikapov | 0:cad5dab2b21d | 1206 | { |
nikapov | 0:cad5dab2b21d | 1207 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 1208 | |
nikapov | 0:cad5dab2b21d | 1209 | LPS22HB_assert_param(IS_LPS22HB_WtmLevel(wtmlevel)); |
nikapov | 0:cad5dab2b21d | 1210 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 1211 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 1212 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1213 | |
nikapov | 0:cad5dab2b21d | 1214 | tmp &= ~LPS22HB_WTM_POINT_MASK; |
nikapov | 0:cad5dab2b21d | 1215 | tmp |= wtmlevel; |
nikapov | 0:cad5dab2b21d | 1216 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 1217 | if(LPS22HB_write_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 1218 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1219 | |
nikapov | 0:cad5dab2b21d | 1220 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 1221 | } |
nikapov | 0:cad5dab2b21d | 1222 | |
nikapov | 0:cad5dab2b21d | 1223 | /** |
nikapov | 0:cad5dab2b21d | 1224 | * @brief Get FIFO Watermark Level |
nikapov | 0:cad5dab2b21d | 1225 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 1226 | * @param buffer to empty with watermak level[0,31] value read from sensor |
nikapov | 0:cad5dab2b21d | 1227 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 1228 | */ |
nikapov | 0:cad5dab2b21d | 1229 | LPS22HB_Error_et LPS22HB_Get_FifoWatermarkLevel(void *handle, uint8_t *wtmlevel) |
nikapov | 0:cad5dab2b21d | 1230 | { |
davide.aliprandi@st.com | 6:671fd10a51b7 | 1231 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, wtmlevel)) |
nikapov | 0:cad5dab2b21d | 1232 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1233 | |
nikapov | 0:cad5dab2b21d | 1234 | *wtmlevel &= LPS22HB_WTM_POINT_MASK; |
nikapov | 0:cad5dab2b21d | 1235 | |
nikapov | 0:cad5dab2b21d | 1236 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 1237 | } |
nikapov | 0:cad5dab2b21d | 1238 | |
nikapov | 0:cad5dab2b21d | 1239 | /** |
nikapov | 0:cad5dab2b21d | 1240 | * @brief Get the Fifo Status |
nikapov | 0:cad5dab2b21d | 1241 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 1242 | * @param Status Flag: FIFO_FTH,FIFO_EMPTY,FIFO_FULL,FIFO_OVR and level of the FIFO->FIFO_LEVEL |
nikapov | 0:cad5dab2b21d | 1243 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 1244 | */ |
nikapov | 0:cad5dab2b21d | 1245 | LPS22HB_Error_et LPS22HB_Get_FifoStatus(void *handle, LPS22HB_FifoStatus_st* status) |
nikapov | 0:cad5dab2b21d | 1246 | { |
nikapov | 0:cad5dab2b21d | 1247 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 1248 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 1249 | if(LPS22HB_read_reg(handle, LPS22HB_STATUS_FIFO_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 1250 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1251 | |
nikapov | 0:cad5dab2b21d | 1252 | status->FIFO_FTH = (uint8_t)((tmp & LPS22HB_FTH_FIFO_MASK)>>LPS22HB_FTH_FIFO_BIT); |
nikapov | 0:cad5dab2b21d | 1253 | status->FIFO_OVR=(uint8_t)((tmp & LPS22HB_OVR_FIFO_MASK)>>LPS22HB_OVR_FIFO_BIT); |
nikapov | 0:cad5dab2b21d | 1254 | status->FIFO_LEVEL = (uint8_t)(tmp & LPS22HB_LEVEL_FIFO_MASK); |
nikapov | 0:cad5dab2b21d | 1255 | |
nikapov | 0:cad5dab2b21d | 1256 | if(status->FIFO_LEVEL ==LPS22HB_FIFO_EMPTY) |
nikapov | 0:cad5dab2b21d | 1257 | status->FIFO_EMPTY=0x01; |
nikapov | 0:cad5dab2b21d | 1258 | else |
nikapov | 0:cad5dab2b21d | 1259 | status->FIFO_EMPTY=0x00; |
nikapov | 0:cad5dab2b21d | 1260 | |
nikapov | 0:cad5dab2b21d | 1261 | if (status->FIFO_LEVEL ==LPS22HB_FIFO_FULL) |
nikapov | 0:cad5dab2b21d | 1262 | status->FIFO_FULL=0x01; |
nikapov | 0:cad5dab2b21d | 1263 | else |
nikapov | 0:cad5dab2b21d | 1264 | status->FIFO_FULL=0x00; |
nikapov | 0:cad5dab2b21d | 1265 | |
nikapov | 0:cad5dab2b21d | 1266 | |
nikapov | 0:cad5dab2b21d | 1267 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 1268 | } |
nikapov | 0:cad5dab2b21d | 1269 | |
nikapov | 0:cad5dab2b21d | 1270 | /** |
nikapov | 0:cad5dab2b21d | 1271 | * @brief Get the reference pressure after soldering for computing differential pressure (hPA) |
nikapov | 0:cad5dab2b21d | 1272 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 1273 | * @param buffer to empty with the he pressure value (hPA) |
nikapov | 0:cad5dab2b21d | 1274 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 1275 | */ |
nikapov | 0:cad5dab2b21d | 1276 | LPS22HB_Error_et LPS22HB_Get_PressureOffsetValue(void *handle, int16_t *pressoffset) |
nikapov | 0:cad5dab2b21d | 1277 | { |
nikapov | 0:cad5dab2b21d | 1278 | uint8_t buffer[2]; |
nikapov | 0:cad5dab2b21d | 1279 | int16_t raw_press; |
nikapov | 0:cad5dab2b21d | 1280 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 1281 | if(LPS22HB_read_reg(handle, LPS22HB_RPDS_L_REG, 2, buffer)) |
nikapov | 0:cad5dab2b21d | 1282 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1283 | |
nikapov | 0:cad5dab2b21d | 1284 | raw_press = (int16_t)((((uint16_t)buffer[1]) << 8) + (uint16_t)buffer[0]); |
nikapov | 0:cad5dab2b21d | 1285 | |
nikapov | 0:cad5dab2b21d | 1286 | *pressoffset = (raw_press*100)/4096; |
nikapov | 0:cad5dab2b21d | 1287 | |
nikapov | 0:cad5dab2b21d | 1288 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 1289 | } |
nikapov | 0:cad5dab2b21d | 1290 | |
nikapov | 0:cad5dab2b21d | 1291 | |
nikapov | 0:cad5dab2b21d | 1292 | /** |
nikapov | 0:cad5dab2b21d | 1293 | * @brief Get the Reference Pressure value |
nikapov | 0:cad5dab2b21d | 1294 | * @detail It is a 24-bit data added to the sensor output measurement to detect a measured pressure beyond programmed limits. |
nikapov | 0:cad5dab2b21d | 1295 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 1296 | * @param Buffer to empty with reference pressure value |
nikapov | 0:cad5dab2b21d | 1297 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 1298 | */ |
nikapov | 0:cad5dab2b21d | 1299 | LPS22HB_Error_et LPS22HB_Get_ReferencePressure(void *handle, int32_t* RefP) |
nikapov | 0:cad5dab2b21d | 1300 | { |
nikapov | 0:cad5dab2b21d | 1301 | uint8_t buffer[3]; |
nikapov | 0:cad5dab2b21d | 1302 | uint32_t tempVal=0; |
nikapov | 0:cad5dab2b21d | 1303 | int32_t raw_press; |
nikapov | 0:cad5dab2b21d | 1304 | uint8_t i; |
nikapov | 0:cad5dab2b21d | 1305 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 1306 | if(LPS22HB_read_reg(handle, LPS22HB_REF_P_XL_REG, 3, buffer)) |
nikapov | 0:cad5dab2b21d | 1307 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1308 | |
nikapov | 0:cad5dab2b21d | 1309 | /* Build the raw data */ |
nikapov | 0:cad5dab2b21d | 1310 | for(i=0; i<3; i++) |
nikapov | 0:cad5dab2b21d | 1311 | tempVal |= (((uint32_t)buffer[i]) << (8*i)); |
nikapov | 0:cad5dab2b21d | 1312 | |
nikapov | 0:cad5dab2b21d | 1313 | /* convert the 2's complement 24 bit to 2's complement 32 bit */ |
nikapov | 0:cad5dab2b21d | 1314 | if(tempVal & 0x00800000) |
nikapov | 0:cad5dab2b21d | 1315 | tempVal |= 0xFF000000; |
nikapov | 0:cad5dab2b21d | 1316 | |
nikapov | 0:cad5dab2b21d | 1317 | raw_press =((int32_t)tempVal); |
nikapov | 0:cad5dab2b21d | 1318 | *RefP = (raw_press*100)/4096; |
nikapov | 0:cad5dab2b21d | 1319 | |
nikapov | 0:cad5dab2b21d | 1320 | |
nikapov | 0:cad5dab2b21d | 1321 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 1322 | } |
nikapov | 0:cad5dab2b21d | 1323 | |
nikapov | 0:cad5dab2b21d | 1324 | |
nikapov | 0:cad5dab2b21d | 1325 | /** |
nikapov | 0:cad5dab2b21d | 1326 | * @brief Check if the single measurement has completed. |
nikapov | 0:cad5dab2b21d | 1327 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 1328 | * @param the returned value is set to 1, when the measurement is completed |
nikapov | 0:cad5dab2b21d | 1329 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 1330 | */ |
nikapov | 0:cad5dab2b21d | 1331 | LPS22HB_Error_et LPS22HB_IsMeasurementCompleted(void *handle, uint8_t* Is_Measurement_Completed) |
nikapov | 0:cad5dab2b21d | 1332 | { |
nikapov | 0:cad5dab2b21d | 1333 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 1334 | LPS22HB_DataStatus_st datastatus; |
nikapov | 0:cad5dab2b21d | 1335 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 1336 | if(LPS22HB_read_reg(handle, LPS22HB_STATUS_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 1337 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1338 | |
nikapov | 0:cad5dab2b21d | 1339 | datastatus.TempDataAvailable=(uint8_t)((tmp&LPS22HB_TDA_MASK)>>LPS22HB_TDA_BIT); |
nikapov | 0:cad5dab2b21d | 1340 | datastatus.PressDataAvailable= (uint8_t)(tmp&LPS22HB_PDA_MASK); |
nikapov | 0:cad5dab2b21d | 1341 | |
nikapov | 0:cad5dab2b21d | 1342 | *Is_Measurement_Completed=(uint8_t)((datastatus.PressDataAvailable) & (datastatus.TempDataAvailable)); |
nikapov | 0:cad5dab2b21d | 1343 | |
nikapov | 0:cad5dab2b21d | 1344 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 1345 | } |
nikapov | 0:cad5dab2b21d | 1346 | |
nikapov | 0:cad5dab2b21d | 1347 | /** |
nikapov | 0:cad5dab2b21d | 1348 | * @brief Get the values of the last single measurement. |
nikapov | 0:cad5dab2b21d | 1349 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 1350 | * @param Pressure and temperature tmp |
nikapov | 0:cad5dab2b21d | 1351 | * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 1352 | */ |
nikapov | 0:cad5dab2b21d | 1353 | LPS22HB_Error_et LPS22HB_Get_Measurement(void *handle, LPS22HB_MeasureTypeDef_st *Measurement_Value) |
nikapov | 0:cad5dab2b21d | 1354 | { |
nikapov | 0:cad5dab2b21d | 1355 | int16_t Tout; |
nikapov | 0:cad5dab2b21d | 1356 | int32_t Pout; |
nikapov | 0:cad5dab2b21d | 1357 | |
nikapov | 0:cad5dab2b21d | 1358 | if(LPS22HB_Get_Temperature(handle, &Tout)) |
nikapov | 0:cad5dab2b21d | 1359 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1360 | |
nikapov | 0:cad5dab2b21d | 1361 | Measurement_Value->Tout=Tout; |
nikapov | 0:cad5dab2b21d | 1362 | |
nikapov | 0:cad5dab2b21d | 1363 | if(LPS22HB_Get_Pressure(handle, &Pout)) |
nikapov | 0:cad5dab2b21d | 1364 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1365 | |
nikapov | 0:cad5dab2b21d | 1366 | Measurement_Value->Pout=Pout; |
nikapov | 0:cad5dab2b21d | 1367 | |
nikapov | 0:cad5dab2b21d | 1368 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 1369 | |
nikapov | 0:cad5dab2b21d | 1370 | } |
nikapov | 0:cad5dab2b21d | 1371 | |
nikapov | 0:cad5dab2b21d | 1372 | /** |
nikapov | 0:cad5dab2b21d | 1373 | * @brief Initialization function for LPS22HB. |
nikapov | 0:cad5dab2b21d | 1374 | * This function make a memory boot. |
nikapov | 0:cad5dab2b21d | 1375 | * Init the sensor with a standard basic confifuration. |
nikapov | 0:cad5dab2b21d | 1376 | * Low Power, ODR 25 Hz, Low Pass Filter disabled; BDU enabled; I2C enabled; |
nikapov | 0:cad5dab2b21d | 1377 | * NO FIFO; NO Interrupt Enabled. |
nikapov | 0:cad5dab2b21d | 1378 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 1379 | * @retval Error code[LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 1380 | */ |
nikapov | 0:cad5dab2b21d | 1381 | LPS22HB_Error_et LPS22HB_Init(void *handle) |
nikapov | 0:cad5dab2b21d | 1382 | { |
nikapov | 0:cad5dab2b21d | 1383 | LPS22HB_ConfigTypeDef_st pLPS22HBInit; |
nikapov | 0:cad5dab2b21d | 1384 | |
nikapov | 0:cad5dab2b21d | 1385 | /* Make LPS22HB Reset and Reboot */ |
nikapov | 0:cad5dab2b21d | 1386 | if(LPS22HB_SwResetAndMemoryBoot(handle)) |
nikapov | 0:cad5dab2b21d | 1387 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1388 | |
nikapov | 0:cad5dab2b21d | 1389 | pLPS22HBInit.PowerMode=LPS22HB_LowPower; |
nikapov | 0:cad5dab2b21d | 1390 | pLPS22HBInit.OutputDataRate=LPS22HB_ODR_25HZ; |
nikapov | 0:cad5dab2b21d | 1391 | pLPS22HBInit.LowPassFilter=LPS22HB_DISABLE; |
nikapov | 0:cad5dab2b21d | 1392 | pLPS22HBInit.LPF_Cutoff=LPS22HB_ODR_9; |
nikapov | 0:cad5dab2b21d | 1393 | pLPS22HBInit.BDU=LPS22HB_BDU_NO_UPDATE; |
nikapov | 0:cad5dab2b21d | 1394 | pLPS22HBInit.IfAddInc=LPS22HB_ENABLE; //default |
nikapov | 0:cad5dab2b21d | 1395 | pLPS22HBInit.Sim= LPS22HB_SPI_4_WIRE; |
nikapov | 0:cad5dab2b21d | 1396 | |
nikapov | 0:cad5dab2b21d | 1397 | /* Set Generic Configuration*/ |
nikapov | 0:cad5dab2b21d | 1398 | if(LPS22HB_Set_GenericConfig(handle, &pLPS22HBInit)) |
nikapov | 0:cad5dab2b21d | 1399 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1400 | |
nikapov | 0:cad5dab2b21d | 1401 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 1402 | } |
nikapov | 0:cad5dab2b21d | 1403 | |
nikapov | 0:cad5dab2b21d | 1404 | /** |
nikapov | 0:cad5dab2b21d | 1405 | * @brief De initialization function for LPS22HB. |
nikapov | 0:cad5dab2b21d | 1406 | * This function make a memory boot and clear the data output flags. |
nikapov | 0:cad5dab2b21d | 1407 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 1408 | * @retval Error code[LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 1409 | */ |
nikapov | 0:cad5dab2b21d | 1410 | LPS22HB_Error_et LPS22HB_DeInit(void *handle) |
nikapov | 0:cad5dab2b21d | 1411 | { |
nikapov | 0:cad5dab2b21d | 1412 | LPS22HB_MeasureTypeDef_st Measurement_Value; |
nikapov | 0:cad5dab2b21d | 1413 | |
nikapov | 0:cad5dab2b21d | 1414 | /* Make LPS22HB Reset and Reboot */ |
nikapov | 0:cad5dab2b21d | 1415 | if(LPS22HB_SwResetAndMemoryBoot(handle)) |
nikapov | 0:cad5dab2b21d | 1416 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1417 | |
nikapov | 0:cad5dab2b21d | 1418 | /* Dump of data output */ |
nikapov | 0:cad5dab2b21d | 1419 | if(LPS22HB_Get_Measurement(handle, &Measurement_Value)) |
nikapov | 0:cad5dab2b21d | 1420 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1421 | |
nikapov | 0:cad5dab2b21d | 1422 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 1423 | } |
nikapov | 0:cad5dab2b21d | 1424 | |
nikapov | 0:cad5dab2b21d | 1425 | |
nikapov | 0:cad5dab2b21d | 1426 | /** |
nikapov | 0:cad5dab2b21d | 1427 | * @brief Set Generic Configuration |
nikapov | 0:cad5dab2b21d | 1428 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 1429 | * @param Struct to empty with the chosen values |
nikapov | 0:cad5dab2b21d | 1430 | * @retval Error code[LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 1431 | */ |
nikapov | 0:cad5dab2b21d | 1432 | LPS22HB_Error_et LPS22HB_Set_GenericConfig(void *handle, LPS22HB_ConfigTypeDef_st* pxLPS22HBInit) |
nikapov | 0:cad5dab2b21d | 1433 | { |
nikapov | 0:cad5dab2b21d | 1434 | |
nikapov | 0:cad5dab2b21d | 1435 | /* Enable Low Current Mode (low Power) or Low Noise Mode*/ |
nikapov | 0:cad5dab2b21d | 1436 | if(LPS22HB_Set_PowerMode(handle, pxLPS22HBInit->PowerMode)) |
nikapov | 0:cad5dab2b21d | 1437 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1438 | |
nikapov | 0:cad5dab2b21d | 1439 | /* Init the Output Data Rate*/ |
nikapov | 0:cad5dab2b21d | 1440 | if(LPS22HB_Set_Odr(handle, pxLPS22HBInit->OutputDataRate)) |
nikapov | 0:cad5dab2b21d | 1441 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1442 | |
nikapov | 0:cad5dab2b21d | 1443 | /* BDU bit is used to inhibit the output registers update between the reading of upper and |
nikapov | 0:cad5dab2b21d | 1444 | lower register parts. In default mode (BDU = ‘0’), the lower and upper register parts are |
nikapov | 0:cad5dab2b21d | 1445 | updated continuously. If it is not sure to read faster than output data rate, it is recommended |
nikapov | 0:cad5dab2b21d | 1446 | to set BDU bit to ‘1’. In this way, after the reading of the lower (upper) register part, the |
nikapov | 0:cad5dab2b21d | 1447 | content of that output registers is not updated until the upper (lower) part is read too. |
nikapov | 0:cad5dab2b21d | 1448 | This feature avoids reading LSB and MSB related to different samples.*/ |
nikapov | 0:cad5dab2b21d | 1449 | |
nikapov | 0:cad5dab2b21d | 1450 | if(LPS22HB_Set_Bdu(handle, pxLPS22HBInit->BDU)) |
nikapov | 0:cad5dab2b21d | 1451 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1452 | |
nikapov | 0:cad5dab2b21d | 1453 | /*Enable/Disale low-pass filter on LPS22HB pressure data*/ |
nikapov | 0:cad5dab2b21d | 1454 | if(LPS22HB_Set_LowPassFilter(handle, pxLPS22HBInit->LowPassFilter)) |
nikapov | 0:cad5dab2b21d | 1455 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1456 | |
nikapov | 0:cad5dab2b21d | 1457 | /* Set low-pass filter cutoff configuration*/ |
nikapov | 0:cad5dab2b21d | 1458 | if(LPS22HB_Set_LowPassFilterCutoff(handle, pxLPS22HBInit->LPF_Cutoff)) |
nikapov | 0:cad5dab2b21d | 1459 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1460 | |
nikapov | 0:cad5dab2b21d | 1461 | /* SIM bit selects the SPI serial interface mode.*/ |
nikapov | 0:cad5dab2b21d | 1462 | /* This feature has effect only if SPI interface is used*/ |
nikapov | 0:cad5dab2b21d | 1463 | |
nikapov | 0:cad5dab2b21d | 1464 | if(LPS22HB_Set_SpiInterface(handle, pxLPS22HBInit->Sim)) |
nikapov | 0:cad5dab2b21d | 1465 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1466 | |
nikapov | 0:cad5dab2b21d | 1467 | /*Enable or Disable the Automatic increment register address during a multiple byte access with a serial interface (I2C or SPI)*/ |
nikapov | 0:cad5dab2b21d | 1468 | if(LPS22HB_Set_AutomaticIncrementRegAddress(handle, pxLPS22HBInit->IfAddInc)) |
nikapov | 0:cad5dab2b21d | 1469 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1470 | |
nikapov | 0:cad5dab2b21d | 1471 | |
nikapov | 0:cad5dab2b21d | 1472 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 1473 | } |
nikapov | 0:cad5dab2b21d | 1474 | |
nikapov | 0:cad5dab2b21d | 1475 | /** |
nikapov | 0:cad5dab2b21d | 1476 | * @brief Get Generic configuration |
nikapov | 0:cad5dab2b21d | 1477 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 1478 | * @param Struct to empty with configuration values |
nikapov | 0:cad5dab2b21d | 1479 | * @retval Error code[LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 1480 | */ |
nikapov | 0:cad5dab2b21d | 1481 | LPS22HB_Error_et LPS22HB_Get_GenericConfig(void *handle, LPS22HB_ConfigTypeDef_st* pxLPS22HBInit) |
nikapov | 0:cad5dab2b21d | 1482 | { |
nikapov | 0:cad5dab2b21d | 1483 | |
nikapov | 0:cad5dab2b21d | 1484 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 1485 | |
nikapov | 0:cad5dab2b21d | 1486 | /*Read LPS22HB_RES_CONF_REG*/ |
nikapov | 0:cad5dab2b21d | 1487 | if(LPS22HB_Get_PowerMode(handle, &pxLPS22HBInit->PowerMode)) |
nikapov | 0:cad5dab2b21d | 1488 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1489 | |
nikapov | 0:cad5dab2b21d | 1490 | /*Read LPS22HB_CTRL_REG1*/ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 1491 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 1492 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1493 | |
nikapov | 0:cad5dab2b21d | 1494 | pxLPS22HBInit->OutputDataRate= (LPS22HB_Odr_et)(tmp & LPS22HB_ODR_MASK); |
nikapov | 0:cad5dab2b21d | 1495 | pxLPS22HBInit->BDU=(LPS22HB_Bdu_et)(tmp & LPS22HB_BDU_MASK); |
nikapov | 0:cad5dab2b21d | 1496 | pxLPS22HBInit->Sim=(LPS22HB_SPIMode_et)(tmp& LPS22HB_SIM_MASK); |
nikapov | 0:cad5dab2b21d | 1497 | pxLPS22HBInit->LowPassFilter=(LPS22HB_State_et)((tmp& LPS22HB_LPFP_MASK)>>LPS22HB_LPFP_BIT); |
nikapov | 0:cad5dab2b21d | 1498 | pxLPS22HBInit->LPF_Cutoff=(LPS22HB_LPF_Cutoff_et)(tmp& LPS22HB_LPFP_CUTOFF_MASK); |
nikapov | 0:cad5dab2b21d | 1499 | |
nikapov | 0:cad5dab2b21d | 1500 | /*Read LPS22HB_CTRL_REG2*/ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 1501 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 1502 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1503 | |
nikapov | 0:cad5dab2b21d | 1504 | pxLPS22HBInit->IfAddInc=(LPS22HB_State_et)((tmp& LPS22HB_ADD_INC_MASK)>>LPS22HB_ADD_INC_BIT); |
nikapov | 0:cad5dab2b21d | 1505 | |
nikapov | 0:cad5dab2b21d | 1506 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 1507 | } |
nikapov | 0:cad5dab2b21d | 1508 | |
nikapov | 0:cad5dab2b21d | 1509 | |
nikapov | 0:cad5dab2b21d | 1510 | /** |
nikapov | 0:cad5dab2b21d | 1511 | * @brief Set Interrupt configuration |
nikapov | 0:cad5dab2b21d | 1512 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 1513 | * @param Struct holding the configuration values |
nikapov | 0:cad5dab2b21d | 1514 | * @retval Error code[LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 1515 | */ |
nikapov | 0:cad5dab2b21d | 1516 | LPS22HB_Error_et LPS22HB_Set_InterruptConfig(void *handle, LPS22HB_InterruptTypeDef_st* pLPS22HBInt) |
nikapov | 0:cad5dab2b21d | 1517 | { |
nikapov | 0:cad5dab2b21d | 1518 | /* Enable Low Current Mode (low Power) or Low Noise Mode*/ |
nikapov | 0:cad5dab2b21d | 1519 | if(LPS22HB_Set_InterruptActiveLevel(handle, pLPS22HBInt->INT_H_L)) |
nikapov | 0:cad5dab2b21d | 1520 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1521 | |
nikapov | 0:cad5dab2b21d | 1522 | /* Push-pull/open drain selection on interrupt pads.*/ |
nikapov | 0:cad5dab2b21d | 1523 | if(LPS22HB_Set_InterruptOutputType(handle, pLPS22HBInt->PP_OD)) |
nikapov | 0:cad5dab2b21d | 1524 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1525 | |
nikapov | 0:cad5dab2b21d | 1526 | /* Set Data signal on INT pad control bits.*/ |
nikapov | 0:cad5dab2b21d | 1527 | if(LPS22HB_Set_InterruptControlConfig(handle, pLPS22HBInt->OutputSignal_INT)) |
nikapov | 0:cad5dab2b21d | 1528 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1529 | |
nikapov | 0:cad5dab2b21d | 1530 | /* Enable/Disable Data-ready signal on INT_DRDY pin. */ |
nikapov | 0:cad5dab2b21d | 1531 | if(LPS22HB_Set_DRDYInterrupt(handle, pLPS22HBInt->DRDY)) |
nikapov | 0:cad5dab2b21d | 1532 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1533 | |
nikapov | 0:cad5dab2b21d | 1534 | /* Enable/Disable FIFO overrun interrupt on INT_DRDY pin. */ |
nikapov | 0:cad5dab2b21d | 1535 | if(LPS22HB_Set_FIFO_OVR_Interrupt(handle, pLPS22HBInt->FIFO_OVR)) |
nikapov | 0:cad5dab2b21d | 1536 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1537 | |
nikapov | 0:cad5dab2b21d | 1538 | /* Enable/Disable FIFO Treshold interrupt on INT_DRDY pin. */ |
nikapov | 0:cad5dab2b21d | 1539 | if(LPS22HB_Set_FIFO_FTH_Interrupt(handle, pLPS22HBInt->FIFO_FTH)) |
nikapov | 0:cad5dab2b21d | 1540 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1541 | |
nikapov | 0:cad5dab2b21d | 1542 | /* Enable/Disable FIFO FULL interrupt on INT_DRDY pin. */ |
nikapov | 0:cad5dab2b21d | 1543 | if(LPS22HB_Set_FIFO_FULL_Interrupt(handle, pLPS22HBInt->FIFO_FULL)) |
nikapov | 0:cad5dab2b21d | 1544 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1545 | |
nikapov | 0:cad5dab2b21d | 1546 | /* Latch Interrupt request to the INT_SOURCE register. */ |
nikapov | 0:cad5dab2b21d | 1547 | if(LPS22HB_LatchInterruptRequest(handle, pLPS22HBInt->LatchIRQ)) |
nikapov | 0:cad5dab2b21d | 1548 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1549 | |
nikapov | 0:cad5dab2b21d | 1550 | /* Set the threshold value used for pressure interrupt generation (hPA). */ |
nikapov | 0:cad5dab2b21d | 1551 | if(LPS22HB_Set_PressureThreshold(handle, pLPS22HBInt->THS_threshold)) |
nikapov | 0:cad5dab2b21d | 1552 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1553 | |
nikapov | 0:cad5dab2b21d | 1554 | /*Enable/Disable AutoRifP function */ |
nikapov | 0:cad5dab2b21d | 1555 | if(pLPS22HBInt->AutoRifP==LPS22HB_ENABLE){ |
nikapov | 0:cad5dab2b21d | 1556 | if(LPS22HB_Set_AutoRifP(handle)) |
nikapov | 0:cad5dab2b21d | 1557 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1558 | } |
nikapov | 0:cad5dab2b21d | 1559 | else{ |
nikapov | 0:cad5dab2b21d | 1560 | if(LPS22HB_ResetAutoRifP(handle)) |
nikapov | 0:cad5dab2b21d | 1561 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1562 | } |
nikapov | 0:cad5dab2b21d | 1563 | |
nikapov | 0:cad5dab2b21d | 1564 | /*Enable/Disable AutoZero function*/ |
nikapov | 0:cad5dab2b21d | 1565 | if(pLPS22HBInt->AutoZero==LPS22HB_ENABLE){ |
nikapov | 0:cad5dab2b21d | 1566 | if(LPS22HB_Set_AutoZeroFunction(handle)) |
nikapov | 0:cad5dab2b21d | 1567 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1568 | } |
nikapov | 0:cad5dab2b21d | 1569 | else{ |
nikapov | 0:cad5dab2b21d | 1570 | if(LPS22HB_ResetAutoZeroFunction(handle)) |
nikapov | 0:cad5dab2b21d | 1571 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1572 | } |
nikapov | 0:cad5dab2b21d | 1573 | |
nikapov | 0:cad5dab2b21d | 1574 | |
nikapov | 0:cad5dab2b21d | 1575 | if(pLPS22HBInt->OutputSignal_INT==LPS22HB_P_HIGH) |
nikapov | 0:cad5dab2b21d | 1576 | { |
nikapov | 0:cad5dab2b21d | 1577 | /* Enable\Disable Interrupt Generation on differential pressure high event*/ |
nikapov | 0:cad5dab2b21d | 1578 | if(LPS22HB_Set_PHE(handle, LPS22HB_ENABLE)) |
nikapov | 0:cad5dab2b21d | 1579 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1580 | if(LPS22HB_Set_InterruptDifferentialGeneration(handle, LPS22HB_ENABLE)) |
nikapov | 0:cad5dab2b21d | 1581 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1582 | } |
nikapov | 0:cad5dab2b21d | 1583 | else if(pLPS22HBInt->OutputSignal_INT==LPS22HB_P_LOW) |
nikapov | 0:cad5dab2b21d | 1584 | { |
nikapov | 0:cad5dab2b21d | 1585 | /* Enable Interrupt Generation on differential pressure Loe event*/ |
nikapov | 0:cad5dab2b21d | 1586 | if(LPS22HB_Set_PLE(handle, LPS22HB_ENABLE)) |
nikapov | 0:cad5dab2b21d | 1587 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1588 | if(LPS22HB_Set_InterruptDifferentialGeneration(handle, LPS22HB_ENABLE)) |
nikapov | 0:cad5dab2b21d | 1589 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1590 | } |
nikapov | 0:cad5dab2b21d | 1591 | else if(pLPS22HBInt->OutputSignal_INT==LPS22HB_P_LOW_HIGH) |
nikapov | 0:cad5dab2b21d | 1592 | { |
nikapov | 0:cad5dab2b21d | 1593 | /* Enable Interrupt Generation on differential pressure high event*/ |
nikapov | 0:cad5dab2b21d | 1594 | if(LPS22HB_Set_PHE(handle, LPS22HB_ENABLE)) |
nikapov | 0:cad5dab2b21d | 1595 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1596 | /* Enable\Disable Interrupt Generation on differential pressure Loe event*/ |
nikapov | 0:cad5dab2b21d | 1597 | if(LPS22HB_Set_PLE(handle, LPS22HB_ENABLE)) |
nikapov | 0:cad5dab2b21d | 1598 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1599 | if(LPS22HB_Set_InterruptDifferentialGeneration(handle, LPS22HB_ENABLE)) |
nikapov | 0:cad5dab2b21d | 1600 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1601 | } |
nikapov | 0:cad5dab2b21d | 1602 | else |
nikapov | 0:cad5dab2b21d | 1603 | { |
nikapov | 0:cad5dab2b21d | 1604 | if(LPS22HB_Set_InterruptDifferentialGeneration(handle, LPS22HB_DISABLE)) |
nikapov | 0:cad5dab2b21d | 1605 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1606 | /* Disable Interrupt Generation on differential pressure High event*/ |
nikapov | 0:cad5dab2b21d | 1607 | if(LPS22HB_Set_PHE(handle, LPS22HB_DISABLE)) |
nikapov | 0:cad5dab2b21d | 1608 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1609 | /* Disable Interrupt Generation on differential pressure Low event*/ |
nikapov | 0:cad5dab2b21d | 1610 | if(LPS22HB_Set_PLE(handle, LPS22HB_DISABLE)) |
nikapov | 0:cad5dab2b21d | 1611 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1612 | } |
nikapov | 0:cad5dab2b21d | 1613 | |
nikapov | 0:cad5dab2b21d | 1614 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 1615 | } |
nikapov | 0:cad5dab2b21d | 1616 | |
nikapov | 0:cad5dab2b21d | 1617 | /** |
nikapov | 0:cad5dab2b21d | 1618 | * @brief LPS22HBGet_InterruptConfig |
nikapov | 0:cad5dab2b21d | 1619 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 1620 | * @param Struct to empty with configuration values |
nikapov | 0:cad5dab2b21d | 1621 | * @retval S Error code[LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 1622 | */ |
nikapov | 0:cad5dab2b21d | 1623 | LPS22HB_Error_et LPS22HB_Get_InterruptConfig(void *handle, LPS22HB_InterruptTypeDef_st* pLPS22HBInt) |
nikapov | 0:cad5dab2b21d | 1624 | { |
nikapov | 0:cad5dab2b21d | 1625 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 1626 | |
nikapov | 0:cad5dab2b21d | 1627 | /*Read LPS22HB_CTRL_REG3*/ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 1628 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 1629 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1630 | |
nikapov | 0:cad5dab2b21d | 1631 | pLPS22HBInt->INT_H_L= (LPS22HB_InterruptActiveLevel_et)(tmp & LPS22HB_INT_H_L_MASK); |
nikapov | 0:cad5dab2b21d | 1632 | pLPS22HBInt->PP_OD=(LPS22HB_OutputType_et)(tmp & LPS22HB_PP_OD_MASK); |
nikapov | 0:cad5dab2b21d | 1633 | pLPS22HBInt->OutputSignal_INT=(LPS22HB_OutputSignalConfig_et)(tmp& LPS22HB_INT_S12_MASK); |
nikapov | 0:cad5dab2b21d | 1634 | pLPS22HBInt->DRDY=(LPS22HB_State_et)((tmp& LPS22HB_DRDY_MASK)>>LPS22HB_DRDY_BIT); |
nikapov | 0:cad5dab2b21d | 1635 | pLPS22HBInt->FIFO_OVR=(LPS22HB_State_et)((tmp& LPS22HB_FIFO_OVR_MASK)>>LPS22HB_FIFO_OVR_BIT); |
nikapov | 0:cad5dab2b21d | 1636 | pLPS22HBInt->FIFO_FTH=(LPS22HB_State_et)((tmp& LPS22HB_FIFO_FTH_MASK)>>LPS22HB_FIFO_FTH_BIT); |
nikapov | 0:cad5dab2b21d | 1637 | pLPS22HBInt->FIFO_FULL=(LPS22HB_State_et)((tmp& LPS22HB_FIFO_FULL_MASK)>>LPS22HB_FIFO_FULL_BIT); |
nikapov | 0:cad5dab2b21d | 1638 | |
nikapov | 0:cad5dab2b21d | 1639 | /*Read LPS22HB_INTERRUPT_CFG_REG*/ |
davide.aliprandi@st.com | 6:671fd10a51b7 | 1640 | if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 1641 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1642 | |
nikapov | 0:cad5dab2b21d | 1643 | pLPS22HBInt->LatchIRQ= (LPS22HB_State_et)((tmp& LPS22HB_LIR_MASK)>>LPS22HB_LIR_BIT); |
nikapov | 0:cad5dab2b21d | 1644 | |
nikapov | 0:cad5dab2b21d | 1645 | if(LPS22HB_Get_PressureThreshold(handle, &pLPS22HBInt->THS_threshold)) |
nikapov | 0:cad5dab2b21d | 1646 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1647 | |
nikapov | 0:cad5dab2b21d | 1648 | //AutoRifP and Autozero are self clear // |
nikapov | 0:cad5dab2b21d | 1649 | pLPS22HBInt->AutoRifP=LPS22HB_DISABLE; |
nikapov | 0:cad5dab2b21d | 1650 | pLPS22HBInt->AutoZero=LPS22HB_DISABLE; |
nikapov | 0:cad5dab2b21d | 1651 | |
nikapov | 0:cad5dab2b21d | 1652 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 1653 | } |
nikapov | 0:cad5dab2b21d | 1654 | |
nikapov | 0:cad5dab2b21d | 1655 | /** |
nikapov | 0:cad5dab2b21d | 1656 | * @brief Set Fifo configuration |
nikapov | 0:cad5dab2b21d | 1657 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 1658 | * @param Struct holding the configuration values |
nikapov | 0:cad5dab2b21d | 1659 | * @retval Error code[LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 1660 | */ |
nikapov | 0:cad5dab2b21d | 1661 | LPS22HB_Error_et LPS22HB_Set_FifoConfig(void *handle, LPS22HB_FIFOTypeDef_st* pLPS22HBFIFO) |
nikapov | 0:cad5dab2b21d | 1662 | { |
nikapov | 0:cad5dab2b21d | 1663 | |
nikapov | 0:cad5dab2b21d | 1664 | if(pLPS22HBFIFO->FIFO_MODE == LPS22HB_FIFO_BYPASS_MODE) { |
nikapov | 0:cad5dab2b21d | 1665 | /* FIFO Disable-> FIFO_EN bit=0 in CTRL_REG2*/ |
nikapov | 0:cad5dab2b21d | 1666 | if(LPS22HB_Set_FifoModeUse(handle, LPS22HB_DISABLE)) |
nikapov | 0:cad5dab2b21d | 1667 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1668 | /* Force->Disable FIFO Watermark Level Use*/ |
nikapov | 0:cad5dab2b21d | 1669 | if(LPS22HB_Set_FifoWatermarkLevelUse(handle, LPS22HB_DISABLE)) |
nikapov | 0:cad5dab2b21d | 1670 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1671 | |
nikapov | 0:cad5dab2b21d | 1672 | /* Force->Disable FIFO Treshold interrupt on INT_DRDY pin. */ |
nikapov | 0:cad5dab2b21d | 1673 | if(LPS22HB_Set_FIFO_FTH_Interrupt(handle, LPS22HB_DISABLE)) |
nikapov | 0:cad5dab2b21d | 1674 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1675 | } |
nikapov | 0:cad5dab2b21d | 1676 | else { |
nikapov | 0:cad5dab2b21d | 1677 | /* FIFO Enable-> FIFO_EN bit=1 in CTRL_REG2*/ |
nikapov | 0:cad5dab2b21d | 1678 | if(LPS22HB_Set_FifoModeUse(handle, LPS22HB_ENABLE)) |
nikapov | 0:cad5dab2b21d | 1679 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1680 | |
nikapov | 0:cad5dab2b21d | 1681 | if (pLPS22HBFIFO->WTM_INT){ |
nikapov | 0:cad5dab2b21d | 1682 | /* Enable FIFO Watermark Level Use*/ |
nikapov | 0:cad5dab2b21d | 1683 | if(LPS22HB_Set_FifoWatermarkLevelUse(handle, LPS22HB_ENABLE)) |
nikapov | 0:cad5dab2b21d | 1684 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1685 | /*Set Fifo Watermark Level*/ |
nikapov | 0:cad5dab2b21d | 1686 | if(LPS22HB_Set_FifoWatermarkLevel(handle, pLPS22HBFIFO->WTM_LEVEL)) |
nikapov | 0:cad5dab2b21d | 1687 | return LPS22HB_ERROR; |
davide.aliprandi@st.com | 6:671fd10a51b7 | 1688 | /* Force->enable FIFO Treshold interrupt on INT_DRDY pin. */ |
nikapov | 0:cad5dab2b21d | 1689 | if(LPS22HB_Set_FIFO_FTH_Interrupt(handle, LPS22HB_ENABLE)) |
nikapov | 0:cad5dab2b21d | 1690 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1691 | } |
nikapov | 0:cad5dab2b21d | 1692 | } |
nikapov | 0:cad5dab2b21d | 1693 | |
nikapov | 0:cad5dab2b21d | 1694 | if(LPS22HB_Set_FifoMode(handle, pLPS22HBFIFO->FIFO_MODE)) |
nikapov | 0:cad5dab2b21d | 1695 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1696 | |
nikapov | 0:cad5dab2b21d | 1697 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 1698 | } |
nikapov | 0:cad5dab2b21d | 1699 | |
nikapov | 0:cad5dab2b21d | 1700 | /** |
nikapov | 0:cad5dab2b21d | 1701 | * @brief Get Fifo configuration |
nikapov | 0:cad5dab2b21d | 1702 | * @param *handle Device handle. |
nikapov | 0:cad5dab2b21d | 1703 | * @param Struct to empty with the configuration values |
nikapov | 0:cad5dab2b21d | 1704 | * @retval Error code[LPS22HB_ERROR, LPS22HB_OK] |
nikapov | 0:cad5dab2b21d | 1705 | */ |
nikapov | 0:cad5dab2b21d | 1706 | LPS22HB_Error_et LPS22HB_Get_FifoConfig(void *handle, LPS22HB_FIFOTypeDef_st* pLPS22HBFIFO) |
nikapov | 0:cad5dab2b21d | 1707 | { |
nikapov | 0:cad5dab2b21d | 1708 | uint8_t tmp; |
nikapov | 0:cad5dab2b21d | 1709 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 1710 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 1711 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1712 | |
nikapov | 0:cad5dab2b21d | 1713 | /*!< Fifo Mode Selection */ |
nikapov | 0:cad5dab2b21d | 1714 | pLPS22HBFIFO->FIFO_MODE= (LPS22HB_FifoMode_et)(tmp& LPS22HB_FIFO_MODE_MASK); |
nikapov | 0:cad5dab2b21d | 1715 | |
nikapov | 0:cad5dab2b21d | 1716 | /*!< FIFO threshold/Watermark level selection*/ |
nikapov | 0:cad5dab2b21d | 1717 | pLPS22HBFIFO->WTM_LEVEL= (uint8_t)(tmp& LPS22HB_WTM_POINT_MASK); |
nikapov | 0:cad5dab2b21d | 1718 | |
davide.aliprandi@st.com | 6:671fd10a51b7 | 1719 | if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) |
nikapov | 0:cad5dab2b21d | 1720 | return LPS22HB_ERROR; |
nikapov | 0:cad5dab2b21d | 1721 | |
nikapov | 0:cad5dab2b21d | 1722 | /*!< Enable/Disable the watermark interrupt*/ |
nikapov | 0:cad5dab2b21d | 1723 | pLPS22HBFIFO->WTM_INT= (LPS22HB_State_et)((tmp& LPS22HB_WTM_EN_MASK)>>LPS22HB_WTM_EN_BIT); |
nikapov | 0:cad5dab2b21d | 1724 | |
nikapov | 0:cad5dab2b21d | 1725 | |
nikapov | 0:cad5dab2b21d | 1726 | return LPS22HB_OK; |
nikapov | 0:cad5dab2b21d | 1727 | } |
nikapov | 0:cad5dab2b21d | 1728 | |
nikapov | 0:cad5dab2b21d | 1729 | #ifdef USE_FULL_ASSERT_LPS22HB |
nikapov | 0:cad5dab2b21d | 1730 | /** |
nikapov | 0:cad5dab2b21d | 1731 | * @brief Reports the name of the source file and the source line number |
nikapov | 0:cad5dab2b21d | 1732 | * where the assert_param error has occurred. |
nikapov | 0:cad5dab2b21d | 1733 | * @param file: pointer to the source file name |
nikapov | 0:cad5dab2b21d | 1734 | * @param line: assert_param error line source number |
nikapov | 0:cad5dab2b21d | 1735 | * @retval : None |
nikapov | 0:cad5dab2b21d | 1736 | */ |
nikapov | 0:cad5dab2b21d | 1737 | void LPS22HB_assert_failed(uint8_t* file, uint32_t line) |
nikapov | 0:cad5dab2b21d | 1738 | { |
nikapov | 0:cad5dab2b21d | 1739 | /* User can add his own implementation to report the file name and line number */ |
nikapov | 0:cad5dab2b21d | 1740 | printf("Wrong parameters tmp: file %s on line %d\r\n", file, (int)line); |
nikapov | 0:cad5dab2b21d | 1741 | |
nikapov | 0:cad5dab2b21d | 1742 | /* Infinite loop */ |
nikapov | 0:cad5dab2b21d | 1743 | while (1) |
nikapov | 0:cad5dab2b21d | 1744 | { |
nikapov | 0:cad5dab2b21d | 1745 | } |
nikapov | 0:cad5dab2b21d | 1746 | } |
nikapov | 0:cad5dab2b21d | 1747 | #endif |
nikapov | 0:cad5dab2b21d | 1748 | |
nikapov | 0:cad5dab2b21d | 1749 | /** |
nikapov | 0:cad5dab2b21d | 1750 | * @} |
nikapov | 0:cad5dab2b21d | 1751 | */ |
nikapov | 0:cad5dab2b21d | 1752 | |
nikapov | 0:cad5dab2b21d | 1753 | /** |
nikapov | 0:cad5dab2b21d | 1754 | * @} |
nikapov | 0:cad5dab2b21d | 1755 | */ |
nikapov | 0:cad5dab2b21d | 1756 | |
nikapov | 0:cad5dab2b21d | 1757 | /** |
nikapov | 0:cad5dab2b21d | 1758 | * @} |
nikapov | 0:cad5dab2b21d | 1759 | */ |
nikapov | 0:cad5dab2b21d | 1760 | |
nikapov | 0:cad5dab2b21d | 1761 | /******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/ |