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