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.
Dependencies: ST_INTERFACES X_NUCLEO_COMMON_SPI3W
Fork of X_NUCLEO_IKS01A2 by
LPS22HB_driver.c
00001 /** 00002 ******************************************************************************* 00003 * @file LPS22HB_driver.c 00004 * @author HESA Application Team 00005 * @version V1.1 00006 * @date 10-August-2016 00007 * @brief LPS22HB driver file 00008 ******************************************************************************* 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * 1. Redistributions of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00021 * may be used to endorse or promote products derived from this software 00022 * without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00028 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00029 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 ****************************************************************************** 00036 */ 00037 00038 /* Includes ------------------------------------------------------------------*/ 00039 #include "LPS22HB_driver.h" 00040 #ifdef USE_FULL_ASSERT_LPS22HB 00041 #include <stdio.h> 00042 #endif 00043 00044 /** @addtogroup Environmental_Sensor 00045 * @{ 00046 */ 00047 00048 /** @defgroup LPS22HB_DRIVER 00049 * @brief LPS22HB DRIVER 00050 * @{ 00051 */ 00052 00053 /** @defgroup LPS22HB_Imported_Function_Prototypes 00054 * @{ 00055 */ 00056 00057 extern uint8_t LPS22HB_io_write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite ); 00058 extern uint8_t LPS22HB_io_read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead ); 00059 00060 /** 00061 * @} 00062 */ 00063 00064 /** @defgroup LPS22HB_Private_Function_Prototypes 00065 * @{ 00066 */ 00067 00068 /** 00069 * @} 00070 */ 00071 00072 /** @defgroup LPS22HB_Private_Functions 00073 * @{ 00074 */ 00075 00076 /** 00077 * @} 00078 */ 00079 00080 /** @defgroup LPS22HB_Public_Functions 00081 * @{ 00082 */ 00083 00084 /******************************************************************************* 00085 * Function Name : LPS22HB_read_reg 00086 * Description : Generic Reading function. It must be fullfilled with either 00087 * : I2C or SPI reading functions 00088 * Input : Register Address 00089 * Output : Data Read 00090 * Return : None 00091 *******************************************************************************/ 00092 LPS22HB_Error_et LPS22HB_read_reg( void *handle, uint8_t RegAddr, uint16_t NumByteToRead, uint8_t *Data ) 00093 { 00094 00095 if ( LPS22HB_io_read( handle, RegAddr, Data, NumByteToRead ) ) 00096 return LPS22HB_ERROR; 00097 else 00098 return LPS22HB_OK; 00099 } 00100 00101 /******************************************************************************* 00102 * Function Name : LPS22HB_write_reg 00103 * Description : Generic Writing function. It must be fullfilled with either 00104 * : I2C or SPI writing function 00105 * Input : Register Address, Data to be written 00106 * Output : None 00107 * Return : None 00108 *******************************************************************************/ 00109 LPS22HB_Error_et LPS22HB_write_reg( void *handle, uint8_t RegAddr, uint16_t NumByteToWrite, uint8_t *Data ) 00110 { 00111 00112 if ( LPS22HB_io_write( handle, RegAddr, Data, NumByteToWrite ) ) 00113 return LPS22HB_ERROR; 00114 else 00115 return LPS22HB_OK; 00116 } 00117 00118 /** 00119 * @brief Read identification code by WHO_AM_I register 00120 * @param *handle Device handle. 00121 * @param Buffer to empty by Device identification Value. 00122 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00123 */ 00124 LPS22HB_Error_et LPS22HB_Get_DeviceID(void *handle, uint8_t* deviceid) 00125 { 00126 if(LPS22HB_read_reg(handle, LPS22HB_WHO_AM_I_REG, 1, deviceid)) 00127 return LPS22HB_ERROR; 00128 00129 return LPS22HB_OK; 00130 } 00131 00132 00133 /** 00134 * @brief Get the LPS22HB driver version. 00135 * @param None 00136 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00137 */ 00138 LPS22HB_Error_et LPS22HB_Get_DriverVersion(LPS22HB_driverVersion_st *Version) 00139 { 00140 Version->Major = LPS22HB_driverVersion_Major; 00141 Version->Minor = LPS22HB_driverVersion_Minor; 00142 Version->Point = LPS22HB_driverVersion_Point; 00143 00144 return LPS22HB_OK; 00145 } 00146 00147 00148 /** 00149 * @brief Set LPS22HB Low Power or Low Noise Mode Configuration 00150 * @param *handle Device handle. 00151 * @param LPS22HB_LowNoise or LPS22HB_LowPower mode 00152 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00153 */ 00154 LPS22HB_Error_et LPS22HB_Set_PowerMode(void *handle, LPS22HB_PowerMode_et mode) 00155 { 00156 uint8_t tmp; 00157 00158 LPS22HB_assert_param(IS_LPS22HB_PowerMode(mode)); 00159 00160 if(LPS22HB_read_reg(handle, LPS22HB_RES_CONF_REG, 1, &tmp)) 00161 return LPS22HB_ERROR; 00162 00163 tmp &= ~LPS22HB_LCEN_MASK; 00164 tmp |= (uint8_t)mode; 00165 00166 if(LPS22HB_write_reg(handle, LPS22HB_RES_CONF_REG, 1, &tmp)) 00167 return LPS22HB_ERROR; 00168 00169 return LPS22HB_OK; 00170 } 00171 00172 /** 00173 * @brief Get LPS22HB Power Mode 00174 * @param *handle Device handle. 00175 * @param Buffer to empty with Mode: Low Noise or Low Current 00176 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00177 */ 00178 LPS22HB_Error_et LPS22HB_Get_PowerMode(void *handle, LPS22HB_PowerMode_et* mode) 00179 { 00180 uint8_t tmp; 00181 00182 if(LPS22HB_read_reg(handle, LPS22HB_RES_CONF_REG, 1, &tmp)) 00183 return LPS22HB_ERROR; 00184 00185 *mode = (LPS22HB_PowerMode_et)(tmp & LPS22HB_LCEN_MASK); 00186 00187 return LPS22HB_OK; 00188 } 00189 00190 00191 /** 00192 * @brief Set LPS22HB Output Data Rate 00193 * @param *handle Device handle. 00194 * @param Output Data Rate 00195 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00196 */ 00197 LPS22HB_Error_et LPS22HB_Set_Odr(void *handle, LPS22HB_Odr_et odr) 00198 { 00199 uint8_t tmp; 00200 00201 00202 LPS22HB_assert_param(IS_LPS22HB_ODR(odr)); 00203 00204 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) 00205 return LPS22HB_ERROR; 00206 00207 tmp &= ~LPS22HB_ODR_MASK; 00208 tmp |= (uint8_t)odr; 00209 00210 if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) 00211 return LPS22HB_ERROR; 00212 00213 return LPS22HB_OK; 00214 } 00215 00216 /** 00217 * @brief Get LPS22HB Output Data Rate 00218 * @param *handle Device handle. 00219 * @param Buffer to empty with Output Data Rate 00220 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00221 */ 00222 LPS22HB_Error_et LPS22HB_Get_Odr(void *handle, LPS22HB_Odr_et* odr) 00223 { 00224 uint8_t tmp; 00225 00226 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) 00227 return LPS22HB_ERROR; 00228 00229 *odr = (LPS22HB_Odr_et)(tmp & LPS22HB_ODR_MASK); 00230 00231 return LPS22HB_OK; 00232 } 00233 00234 /** 00235 * @brief Enable/Disale low-pass filter on LPS22HB pressure data 00236 * @param *handle Device handle. 00237 * @param state: enable or disable 00238 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00239 */ 00240 LPS22HB_Error_et LPS22HB_Set_LowPassFilter(void *handle, LPS22HB_State_et state) 00241 { 00242 uint8_t tmp; 00243 00244 LPS22HB_assert_param(IS_LPS22HB_State(state)); 00245 00246 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) 00247 return LPS22HB_ERROR; 00248 00249 tmp &= ~LPS22HB_LPFP_MASK; 00250 tmp |= ((uint8_t)state)<<LPS22HB_LPFP_BIT; 00251 00252 00253 if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) 00254 return LPS22HB_ERROR; 00255 00256 00257 return LPS22HB_OK; 00258 } 00259 00260 00261 /** 00262 * @brief Set low-pass filter cutoff configuration on LPS22HB pressure data 00263 * @param *handle Device handle. 00264 * @param Filter Cutoff ODR/9 or ODR/20 00265 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00266 */ 00267 LPS22HB_Error_et LPS22HB_Set_LowPassFilterCutoff(void *handle, LPS22HB_LPF_Cutoff_et cutoff){ 00268 00269 uint8_t tmp; 00270 00271 LPS22HB_assert_param(IS_LPS22HB_LPF_Cutoff(cutoff)); 00272 00273 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) 00274 return LPS22HB_ERROR; 00275 00276 tmp &= ~LPS22HB_LPFP_CUTOFF_MASK; 00277 tmp |= (uint8_t)cutoff; 00278 00279 00280 00281 if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) 00282 return LPS22HB_ERROR; 00283 00284 00285 return LPS22HB_OK; 00286 00287 } 00288 00289 /** 00290 * @brief Set Block Data Mode 00291 * @detail It is recommended to set BDU bit to ‘1’. 00292 * @detail This feature avoids reading LSB and MSB related to different samples. 00293 * @param *handle Device handle. 00294 * @param LPS22HB_BDU_CONTINUOUS_UPDATE, LPS22HB_BDU_NO_UPDATE 00295 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00296 */ 00297 00298 LPS22HB_Error_et LPS22HB_Set_Bdu(void *handle, LPS22HB_Bdu_et bdu) 00299 { 00300 uint8_t tmp; 00301 00302 00303 LPS22HB_assert_param(IS_LPS22HB_BDUMode(bdu)); 00304 00305 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) 00306 return LPS22HB_ERROR; 00307 00308 tmp &= ~LPS22HB_BDU_MASK; 00309 tmp |= ((uint8_t)bdu); 00310 00311 00312 if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) 00313 return LPS22HB_OK; 00314 00315 return LPS22HB_OK; 00316 } 00317 00318 /** 00319 * @brief Get Block Data Mode 00320 * @param *handle Device handle. 00321 * @param Buffer to empty whit the bdu mode read from sensor 00322 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00323 */ 00324 LPS22HB_Error_et LPS22HB_Get_Bdu(void *handle, LPS22HB_Bdu_et* bdu) 00325 { 00326 uint8_t tmp; 00327 00328 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) 00329 return LPS22HB_ERROR; 00330 00331 *bdu = (LPS22HB_Bdu_et)(tmp & LPS22HB_BDU_MASK); 00332 00333 return LPS22HB_OK; 00334 } 00335 00336 /** 00337 * @brief Set SPI mode: 3 Wire Interface or 4 Wire Interface 00338 * @param *handle Device handle. 00339 * @param LPS22HB_SPI_3_WIRE, LPS22HB_SPI_4_WIRE 00340 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00341 */ 00342 LPS22HB_Error_et LPS22HB_Set_SpiInterface(void *handle, LPS22HB_SPIMode_et spimode) 00343 { 00344 uint8_t tmp=0; 00345 00346 00347 LPS22HB_assert_param(IS_LPS22HB_SPIMode(spimode)); 00348 00349 /** FIXME could not read before setting SPI mode **/ 00350 // if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) 00351 // return LPS22HB_ERROR; 00352 00353 tmp &= ~LPS22HB_SIM_MASK; 00354 tmp |= (uint8_t)spimode; 00355 00356 if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) 00357 return LPS22HB_ERROR; 00358 00359 return LPS22HB_OK; 00360 } 00361 00362 /** 00363 * @brief Clock Tree Configuration 00364 * @param *handle Device handle. 00365 * @param LPS22HB_CTE_NotBalanced, LPS22HB_CTE_ABalanced 00366 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00367 */ 00368 LPS22HB_Error_et LPS22HB_Set_ClockTreeConfifuration(void *handle, LPS22HB_CTE_et mode) 00369 { 00370 uint8_t tmp; 00371 00372 00373 LPS22HB_assert_param(IS_LPS22HB_CTE(mode)); 00374 00375 if(LPS22HB_read_reg(handle, LPS22HB_CLOCK_TREE_CONFIGURATION, 1, &tmp)) 00376 return LPS22HB_ERROR; 00377 00378 tmp &= ~LPS22HB_CTE_MASK; 00379 tmp |= (uint8_t)mode; 00380 00381 00382 if(LPS22HB_write_reg(handle, LPS22HB_CLOCK_TREE_CONFIGURATION, 1, &tmp)) 00383 return LPS22HB_ERROR; 00384 00385 return LPS22HB_OK; 00386 } 00387 00388 00389 /** 00390 * @brief Get SPI mode: 3 Wire Interface or 4 Wire Interface 00391 * @param *handle Device handle. 00392 * @param Buffet to empty with spi mode read from Sensor 00393 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00394 */ 00395 LPS22HB_Error_et LPS22HB_Get_SpiInterface(void *handle, LPS22HB_SPIMode_et* spimode) 00396 { 00397 uint8_t tmp; 00398 00399 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) 00400 return LPS22HB_ERROR; 00401 00402 *spimode = (LPS22HB_SPIMode_et)(tmp & LPS22HB_SIM_MASK); 00403 00404 return LPS22HB_OK; 00405 } 00406 00407 /** 00408 * @brief Software Reset. Self-clearing upon completion 00409 * @param *handle Device handle. 00410 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00411 */ 00412 LPS22HB_Error_et LPS22HB_SwReset(void *handle) 00413 { 00414 uint8_t tmp; 00415 00416 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) 00417 return LPS22HB_ERROR; 00418 00419 tmp |= (0x01<<LPS22HB_SW_RESET_BIT); 00420 00421 if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) 00422 return LPS22HB_ERROR; 00423 00424 return LPS22HB_OK; 00425 } 00426 00427 /** 00428 * @brief Reboot Memory Content 00429 * @param *handle Device handle. 00430 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00431 */ 00432 00433 LPS22HB_Error_et LPS22HB_MemoryBoot(void *handle) 00434 { 00435 uint8_t tmp; 00436 00437 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) 00438 return LPS22HB_ERROR; 00439 00440 tmp |= (0x01<<LPS22HB_BOOT_BIT); 00441 00442 if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) 00443 return LPS22HB_ERROR; 00444 00445 return LPS22HB_OK; 00446 } 00447 00448 /** 00449 * @brief Software Reset ann Reboot Memory Content. 00450 * @detail The device is reset to the power on configuration if the SWRESET bit is set to ‘1’ 00451 + and BOOT is set to ‘1’; Self-clearing upon completion. 00452 * @param *handle Device handle. 00453 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00454 */ 00455 LPS22HB_Error_et LPS22HB_SwResetAndMemoryBoot(void *handle) 00456 { 00457 uint8_t tmp; 00458 00459 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) 00460 return LPS22HB_ERROR; 00461 00462 tmp |= ((0x01<<LPS22HB_SW_RESET_BIT) | (0x01<<LPS22HB_BOOT_BIT)); 00463 00464 if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) 00465 return LPS22HB_ERROR; 00466 00467 return LPS22HB_OK; 00468 } 00469 00470 00471 /** 00472 * @brief Enable/Disable FIFO Mode 00473 * @param *handle Device handle. 00474 * @param LPS22HB_ENABLE/LPS22HB_DISABLE 00475 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00476 */ 00477 LPS22HB_Error_et LPS22HB_Set_FifoModeUse(void *handle, LPS22HB_State_et status) 00478 { 00479 uint8_t tmp; 00480 00481 LPS22HB_assert_param(IS_LPS22HB_State(status)); 00482 00483 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) 00484 return LPS22HB_ERROR; 00485 00486 tmp &= ~LPS22HB_FIFO_EN_MASK; 00487 tmp |= ((uint8_t)status)<<LPS22HB_FIFO_EN_BIT; 00488 00489 if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) 00490 return LPS22HB_ERROR; 00491 00492 return LPS22HB_OK; 00493 } 00494 /** 00495 * @brief Enable/Disable FIFO Watermark Level Use 00496 * @param *handle Device handle. 00497 * @param LPS22HB_ENABLE/LPS22HB_DISABLE 00498 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00499 */ 00500 LPS22HB_Error_et LPS22HB_Set_FifoWatermarkLevelUse(void *handle, LPS22HB_State_et status) 00501 { 00502 uint8_t tmp; 00503 00504 LPS22HB_assert_param(IS_LPS22HB_State(status)); 00505 00506 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) 00507 return LPS22HB_ERROR; 00508 00509 tmp &= ~LPS22HB_WTM_EN_MASK; 00510 tmp |= ((uint8_t)status)<<LPS22HB_WTM_EN_BIT; 00511 00512 if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) 00513 return LPS22HB_ERROR; 00514 00515 return LPS22HB_OK; 00516 } 00517 00518 /** 00519 * @brief Enable or Disable the Automatic increment register address during a multiple byte access with a serial interface (I2C or SPI) 00520 * @param *handle Device handle. 00521 * @param LPS22HB_ENABLE/LPS22HB_DISABLE. Default is LPS22HB_ENABLE 00522 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00523 */ 00524 LPS22HB_Error_et LPS22HB_Set_AutomaticIncrementRegAddress(void *handle, LPS22HB_State_et status){ 00525 00526 uint8_t tmp; 00527 00528 LPS22HB_assert_param(IS_LPS22HB_State(status)); 00529 00530 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) 00531 return LPS22HB_ERROR; 00532 00533 tmp &= ~LPS22HB_ADD_INC_MASK; 00534 tmp |= (((uint8_t)status)<<LPS22HB_ADD_INC_BIT); 00535 00536 if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) 00537 return LPS22HB_ERROR; 00538 00539 return LPS22HB_OK; 00540 00541 } 00542 00543 /** 00544 * @brief Enable/Disable I2C Interface 00545 * @param *handle Device handle. 00546 * @param State: LPS22HB_ENABLE (reset bit)/ LPS22HB_DISABLE (set bit) 00547 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00548 */ 00549 LPS22HB_Error_et LPS22HB_Set_I2C(void *handle, LPS22HB_State_et statei2c) 00550 { 00551 uint8_t tmp; 00552 00553 LPS22HB_assert_param(IS_LPS22HB_State(statei2c)); 00554 00555 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) 00556 return LPS22HB_ERROR; 00557 00558 /*Reset Bit->I2C Enabled*/ 00559 tmp &= ~LPS22HB_I2C_MASK; 00560 tmp|=((uint8_t)~statei2c)<<LPS22HB_I2C_BIT; 00561 00562 if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) 00563 return LPS22HB_ERROR; 00564 00565 return LPS22HB_OK; 00566 } 00567 00568 00569 /** 00570 * @brief Set the one-shot bit in order to start acquisition when the ONE SHOT mode 00571 * has been selected by the ODR configuration. 00572 * @detail Once the measurement is done, ONE_SHOT bit will self-clear. 00573 * @param *handle Device handle. 00574 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00575 */ 00576 LPS22HB_Error_et LPS22HB_StartOneShotMeasurement(void *handle) 00577 { 00578 uint8_t tmp; 00579 00580 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) 00581 return LPS22HB_ERROR; 00582 00583 /* Set the one shot bit */ 00584 /* Once the measurement is done, one shot bit will self-clear*/ 00585 tmp |= LPS22HB_ONE_SHOT_MASK; 00586 00587 if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) 00588 return LPS22HB_ERROR; 00589 00590 return LPS22HB_OK; 00591 00592 } 00593 00594 /** 00595 * @brief Set Interrupt Active on High or Low Level 00596 * @param *handle Device handle. 00597 * @param LPS22HB_ActiveHigh/LPS22HB_ActiveLow 00598 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00599 */ 00600 LPS22HB_Error_et LPS22HB_Set_InterruptActiveLevel(void *handle, LPS22HB_InterruptActiveLevel_et mode) 00601 { 00602 uint8_t tmp; 00603 00604 LPS22HB_assert_param(IS_LPS22HB_InterruptActiveLevel(mode)); 00605 00606 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) 00607 return LPS22HB_ERROR; 00608 00609 tmp &= ~LPS22HB_INT_H_L_MASK; 00610 tmp |= ((uint8_t)mode); 00611 00612 if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) 00613 return LPS22HB_ERROR; 00614 00615 return LPS22HB_OK; 00616 } 00617 00618 00619 /** 00620 * @brief Push-pull/open drain selection on interrupt pads. Default tmp: 0 00621 * @param *handle Device handle. 00622 * @param LPS22HB_PushPull/LPS22HB_OpenDrain 00623 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00624 */ 00625 LPS22HB_Error_et LPS22HB_Set_InterruptOutputType(void *handle, LPS22HB_OutputType_et output) 00626 { 00627 uint8_t tmp; 00628 00629 LPS22HB_assert_param(IS_LPS22HB_OutputType(output)); 00630 00631 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) 00632 return LPS22HB_ERROR; 00633 00634 tmp &= ~LPS22HB_PP_OD_MASK; 00635 tmp |= (uint8_t)output; 00636 00637 if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) 00638 return LPS22HB_ERROR; 00639 00640 return LPS22HB_OK; 00641 } 00642 00643 /** 00644 * @brief Set Data signal on INT pad control bits. 00645 * @param *handle Device handle. 00646 * @param LPS22HB_DATA,LPS22HB_P_HIGH_LPS22HB_P_LOW,LPS22HB_P_LOW_HIGH 00647 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00648 */ 00649 LPS22HB_Error_et LPS22HB_Set_InterruptControlConfig(void *handle, LPS22HB_OutputSignalConfig_et config) 00650 { 00651 uint8_t tmp; 00652 00653 LPS22HB_assert_param(IS_LPS22HB_OutputSignal(config)); 00654 00655 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) 00656 return LPS22HB_ERROR; 00657 00658 tmp &= ~(LPS22HB_INT_S12_MASK); 00659 tmp |= (uint8_t)config; 00660 00661 if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) 00662 return LPS22HB_ERROR; 00663 00664 return LPS22HB_OK; 00665 } 00666 00667 00668 /** 00669 * @brief Enable/Disable Data-ready signal on INT_DRDY pin. 00670 * @param *handle Device handle. 00671 * @param LPS22HB_ENABLE/LPS22HB_DISABLE 00672 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00673 */ 00674 LPS22HB_Error_et LPS22HB_Set_DRDYInterrupt(void *handle, LPS22HB_State_et status) 00675 { 00676 uint8_t tmp; 00677 00678 00679 LPS22HB_assert_param(IS_LPS22HB_State(status)); 00680 00681 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) 00682 return LPS22HB_ERROR; 00683 00684 tmp &= ~LPS22HB_DRDY_MASK; 00685 tmp |= ((uint8_t)status)<<LPS22HB_DRDY_BIT; 00686 00687 if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) 00688 return LPS22HB_ERROR; 00689 00690 return LPS22HB_OK; 00691 } 00692 00693 /** 00694 * @brief Enable/Disable FIFO overrun interrupt on INT_DRDY pin. 00695 * @param *handle Device handle. 00696 * @param LPS22HB_ENABLE/LPS22HB_DISABLE 00697 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00698 */ 00699 LPS22HB_Error_et LPS22HB_Set_FIFO_OVR_Interrupt(void *handle, LPS22HB_State_et status) 00700 { 00701 uint8_t tmp; 00702 00703 00704 LPS22HB_assert_param(IS_LPS22HB_State(status)); 00705 00706 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) 00707 return LPS22HB_ERROR; 00708 00709 tmp &= ~LPS22HB_FIFO_OVR_MASK; 00710 tmp |= ((uint8_t)status)<<LPS22HB_FIFO_OVR_BIT; 00711 00712 if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) 00713 return LPS22HB_ERROR; 00714 00715 return LPS22HB_OK; 00716 } 00717 00718 /** 00719 * @brief Enable/Disable FIFO threshold (Watermark) interrupt on INT_DRDY pin. 00720 * @param *handle Device handle. 00721 * @param LPS22HB_ENABLE/LPS22HB_DISABLE 00722 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00723 */ 00724 LPS22HB_Error_et LPS22HB_Set_FIFO_FTH_Interrupt(void *handle, LPS22HB_State_et status) 00725 { 00726 uint8_t tmp; 00727 00728 LPS22HB_assert_param(IS_LPS22HB_State(status)); 00729 00730 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) 00731 return LPS22HB_ERROR; 00732 00733 tmp &= ~LPS22HB_FIFO_FTH_MASK; 00734 tmp |= ((uint8_t)status)<<LPS22HB_FIFO_FTH_BIT; 00735 00736 if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) 00737 return LPS22HB_ERROR; 00738 00739 return LPS22HB_OK; 00740 } 00741 00742 /** 00743 * @brief Enable/Disable FIFO FULL interrupt on INT_DRDY pin. 00744 * @param *handle Device handle. 00745 * @param LPS22HB_ENABLE/LPS22HB_DISABLE 00746 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00747 */ 00748 LPS22HB_Error_et LPS22HB_Set_FIFO_FULL_Interrupt(void *handle, LPS22HB_State_et status) 00749 { 00750 uint8_t tmp; 00751 00752 LPS22HB_assert_param(IS_LPS22HB_State(status)); 00753 00754 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) 00755 return LPS22HB_ERROR; 00756 00757 tmp &= ~LPS22HB_FIFO_FULL_MASK; 00758 tmp |= ((uint8_t)status)<<LPS22HB_FIFO_FULL_BIT; 00759 00760 if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) 00761 return LPS22HB_ERROR; 00762 00763 return LPS22HB_OK; 00764 } 00765 00766 00767 00768 /** 00769 * @brief Enable AutoRifP function 00770 * @detail When this function is enabled, an internal register is set with the current pressure values 00771 * and the content is subtracted from the pressure output value and result is used for the interrupt generation. 00772 * the AutoRifP is slf creared. 00773 * @param *handle Device handle. 00774 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00775 */ 00776 LPS22HB_Error_et LPS22HB_Set_AutoRifP(void *handle) 00777 { 00778 uint8_t tmp; 00779 00780 if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) 00781 return LPS22HB_ERROR; 00782 00783 tmp |= ((uint8_t)LPS22HB_AUTORIFP_MASK); 00784 00785 if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) 00786 return LPS22HB_ERROR; 00787 00788 return LPS22HB_OK; 00789 } 00790 00791 /** 00792 * @brief Disable AutoRifP function 00793 * @detail the RESET_ARP bit is used to disable the AUTORIFP function. This bis i is selfdleared 00794 * @param *handle Device handle. 00795 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00796 */ 00797 LPS22HB_Error_et LPS22HB_ResetAutoRifP(void *handle) 00798 { 00799 uint8_t tmp; 00800 00801 if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) 00802 return LPS22HB_ERROR; 00803 00804 00805 tmp |= ((uint8_t)LPS22HB_RESET_ARP_MASK); 00806 00807 if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) 00808 return LPS22HB_ERROR; 00809 00810 return LPS22HB_OK; 00811 } 00812 00813 00814 /* 00815 * @brief Set AutoZero Function bit 00816 * @detail When set to ‘1’, the actual pressure output is copied in the REF_P reg (@0x15..0x17) 00817 * @param *handle Device handle. 00818 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00819 */ 00820 LPS22HB_Error_et LPS22HB_Set_AutoZeroFunction(void *handle) 00821 { 00822 uint8_t tmp; 00823 00824 if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) 00825 return LPS22HB_ERROR; 00826 00827 tmp |= LPS22HB_AUTOZERO_MASK; 00828 00829 if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) 00830 return LPS22HB_ERROR; 00831 00832 return LPS22HB_OK; 00833 } 00834 00835 00836 /* 00837 * @brief Set ResetAutoZero Function bit 00838 * @details REF_P reg (@0x015..17) set pressure reference to default value RPDS reg (0x18/19). 00839 * @param *handle Device handle. 00840 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00841 */ 00842 LPS22HB_Error_et LPS22HB_ResetAutoZeroFunction(void *handle) 00843 { 00844 uint8_t tmp; 00845 00846 if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) 00847 return LPS22HB_ERROR; 00848 00849 /* Set the RESET_AZ bit*/ 00850 /* RESET_AZ is self cleared*/ 00851 tmp |= LPS22HB_RESET_AZ_MASK; 00852 00853 if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) 00854 return LPS22HB_ERROR; 00855 00856 00857 return LPS22HB_OK; 00858 } 00859 00860 00861 /** 00862 * @brief Enable/ Disable the computing of differential pressure output (Interrupt Generation) 00863 * @param *handle Device handle. 00864 * @param LPS22HB_ENABLE,LPS22HB_DISABLE 00865 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00866 */ 00867 LPS22HB_Error_et LPS22HB_Set_InterruptDifferentialGeneration(void *handle, LPS22HB_State_et diff_en) 00868 { 00869 uint8_t tmp; 00870 00871 LPS22HB_assert_param(IS_LPS22HB_State(diff_en)); 00872 00873 if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) 00874 return LPS22HB_ERROR; 00875 00876 tmp &= ~LPS22HB_DIFF_EN_MASK; 00877 tmp |= ((uint8_t)diff_en)<<LPS22HB_DIFF_EN_BIT; 00878 00879 if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) 00880 return LPS22HB_ERROR; 00881 00882 return LPS22HB_OK; 00883 } 00884 00885 00886 /** 00887 * @brief Get the DIFF_EN bit value 00888 * @param *handle Device handle. 00889 * @param buffer to empty with the read value of DIFF_EN bit 00890 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00891 */ 00892 LPS22HB_Error_et LPS22HB_Get_InterruptDifferentialGeneration(void *handle, LPS22HB_State_et* diff_en) 00893 { 00894 uint8_t tmp; 00895 00896 if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) 00897 return LPS22HB_ERROR; 00898 00899 *diff_en= (LPS22HB_State_et)((tmp & LPS22HB_DIFF_EN_MASK)>>LPS22HB_DIFF_EN_BIT); 00900 00901 return LPS22HB_OK; 00902 } 00903 00904 /** 00905 * @brief Latch Interrupt request to the INT_SOURCE register. 00906 * @param *handle Device handle. 00907 * @param LPS22HB_ENABLE/LPS22HB_DISABLE 00908 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00909 */ 00910 LPS22HB_Error_et LPS22HB_LatchInterruptRequest(void *handle, LPS22HB_State_et status) 00911 { 00912 uint8_t tmp; 00913 00914 LPS22HB_assert_param(IS_LPS22HB_State(status)); 00915 00916 if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) 00917 return LPS22HB_ERROR; 00918 00919 tmp &= ~LPS22HB_LIR_MASK; 00920 tmp |= (((uint8_t)status)<<LPS22HB_LIR_BIT); 00921 00922 if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) 00923 return LPS22HB_ERROR; 00924 00925 return LPS22HB_OK; 00926 } 00927 00928 00929 00930 /** 00931 * @brief Enable\Disable Interrupt Generation on differential pressure Low event 00932 * @param *handle Device handle. 00933 * @param LPS22HB_ENABLE/LPS22HB_DISABLE 00934 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00935 */ 00936 LPS22HB_Error_et LPS22HB_Set_PLE(void *handle, LPS22HB_State_et status) 00937 { 00938 uint8_t tmp; 00939 00940 LPS22HB_assert_param(IS_LPS22HB_State(status)); 00941 00942 if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) 00943 return LPS22HB_ERROR; 00944 00945 tmp &= ~LPS22HB_PLE_MASK; 00946 tmp |= (((uint8_t)status)<<LPS22HB_PLE_BIT); 00947 00948 if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) 00949 return LPS22HB_ERROR; 00950 00951 return LPS22HB_OK; 00952 } 00953 00954 /** 00955 * @brief Enable\Disable Interrupt Generation on differential pressure High event 00956 * @param *handle Device handle. 00957 * @param LPS22HB_ENABLE/LPS22HB_DISABLE 00958 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00959 */ 00960 LPS22HB_Error_et LPS22HB_Set_PHE(void *handle, LPS22HB_State_et status) 00961 { 00962 uint8_t tmp; 00963 00964 LPS22HB_assert_param(IS_LPS22HB_State(status)); 00965 00966 if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) 00967 return LPS22HB_ERROR; 00968 00969 tmp &= ~LPS22HB_PHE_MASK; 00970 tmp |= (((uint8_t)status)<<LPS22HB_PHE_BIT); 00971 00972 if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) 00973 return LPS22HB_ERROR; 00974 00975 return LPS22HB_OK; 00976 } 00977 00978 /** 00979 * @brief Get the Interrupt Generation on differential pressure status event and the Boot Status. 00980 * @detail The INT_SOURCE register is cleared by reading it. 00981 * @param *handle Device handle. 00982 * @param Status Event Flag: BOOT, PH,PL,IA 00983 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 00984 */ 00985 LPS22HB_Error_et LPS22HB_Get_InterruptDifferentialEventStatus(void *handle, LPS22HB_InterruptDiffStatus_st* interruptsource) 00986 { 00987 uint8_t tmp; 00988 00989 if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_SOURCE_REG, 1, &tmp)) 00990 return LPS22HB_ERROR; 00991 00992 interruptsource->PH = (uint8_t)(tmp & LPS22HB_PH_MASK); 00993 interruptsource->PL = (uint8_t)((tmp & LPS22HB_PL_MASK)>>LPS22HB_PL_BIT); 00994 interruptsource->IA = (uint8_t)((tmp & LPS22HB_IA_MASK)>>LPS22HB_IA_BIT); 00995 interruptsource->BOOT = (uint8_t)((tmp & LPS22HB_BOOT_STATUS_MASK)>>LPS22HB_BOOT_STATUS_BIT); 00996 00997 return LPS22HB_OK; 00998 } 00999 01000 /** 01001 * @brief Get the status of Pressure and Temperature data 01002 * @param *handle Device handle. 01003 * @param Data Status Flag: TempDataAvailable, TempDataOverrun, PressDataAvailable, PressDataOverrun 01004 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 01005 */ 01006 LPS22HB_Error_et LPS22HB_Get_DataStatus(void *handle, LPS22HB_DataStatus_st* datastatus) 01007 { 01008 uint8_t tmp; 01009 01010 if(LPS22HB_read_reg(handle, LPS22HB_STATUS_REG, 1, &tmp)) 01011 return LPS22HB_ERROR; 01012 01013 datastatus->PressDataAvailable = (uint8_t)(tmp & LPS22HB_PDA_MASK); 01014 datastatus->TempDataAvailable = (uint8_t)((tmp & LPS22HB_TDA_MASK)>>LPS22HB_PDA_BIT); 01015 datastatus->TempDataOverrun = (uint8_t)((tmp & LPS22HB_TOR_MASK)>>LPS22HB_TOR_BIT); 01016 datastatus->PressDataOverrun = (uint8_t)((tmp & LPS22HB_POR_MASK)>>LPS22HB_POR_BIT); 01017 01018 return LPS22HB_OK; 01019 } 01020 01021 01022 01023 /** 01024 * @brief Get the LPS22HB raw presure value 01025 * @detail The data are expressed as PRESS_OUT_H/_L/_XL in 2’s complement. 01026 Pout(hPA)=PRESS_OUT / 4096 01027 * @param *handle Device handle. 01028 * @param The buffer to empty with the pressure raw value 01029 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 01030 */ 01031 LPS22HB_Error_et LPS22HB_Get_RawPressure(void *handle, int32_t *raw_press) 01032 { 01033 uint8_t buffer[3]; 01034 uint32_t tmp = 0; 01035 uint8_t i; 01036 01037 if(LPS22HB_read_reg(handle, LPS22HB_PRESS_OUT_XL_REG, 3, buffer)) 01038 return LPS22HB_ERROR; 01039 01040 /* Build the raw data */ 01041 for(i=0; i<3; i++) 01042 tmp |= (((uint32_t)buffer[i]) << (8*i)); 01043 01044 /* convert the 2's complement 24 bit to 2's complement 32 bit */ 01045 if(tmp & 0x00800000) 01046 tmp |= 0xFF000000; 01047 01048 *raw_press = ((int32_t)tmp); 01049 01050 return LPS22HB_OK; 01051 } 01052 01053 /** 01054 * @brief Get the LPS22HB Pressure value in hPA. 01055 * @detail The data are expressed as PRESS_OUT_H/_L/_XL in 2’s complement. 01056 Pout(hPA)=PRESS_OUT / 4096 01057 * @param *handle Device handle. 01058 * @param The buffer to empty with the pressure value that must be divided by 100 to get the value in hPA 01059 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 01060 */ 01061 LPS22HB_Error_et LPS22HB_Get_Pressure(void *handle, int32_t* Pout) 01062 { 01063 int32_t raw_press; 01064 01065 if(LPS22HB_Get_RawPressure(handle, &raw_press)) 01066 return LPS22HB_ERROR; 01067 01068 *Pout = (raw_press*100)/4096; 01069 01070 return LPS22HB_OK; 01071 } 01072 01073 /** 01074 * @brief Get the Raw Temperature value. 01075 * @detail Temperature data are expressed as TEMP_OUT_H&TEMP_OUT_L as 2’s complement number. 01076 * Tout(degC)=TEMP_OUT/100 01077 * @param *handle Device handle. 01078 * @param Buffer to empty with the temperature raw tmp. 01079 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 01080 */ 01081 LPS22HB_Error_et LPS22HB_Get_RawTemperature(void *handle, int16_t* raw_data) 01082 { 01083 uint8_t buffer[2]; 01084 uint16_t tmp; 01085 01086 if(LPS22HB_read_reg(handle, LPS22HB_TEMP_OUT_L_REG, 2, buffer)) 01087 return LPS22HB_ERROR; 01088 01089 /* Build the raw tmp */ 01090 tmp = (((uint16_t)buffer[1]) << 8) + (uint16_t)buffer[0]; 01091 01092 *raw_data = ((int16_t)tmp); 01093 01094 return LPS22HB_OK; 01095 } 01096 01097 01098 /** 01099 * @brief Get the Temperature value in °C. 01100 * @detail Temperature data are expressed as TEMP_OUT_H&TEMP_OUT_L as 2’s complement number. 01101 * Tout(degC)=TEMP_OUT/100 01102 * @param *handle Device handle. 01103 * @param Buffer to empty with the temperature value that must be divided by 10 to get the value in °C 01104 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 01105 */ 01106 LPS22HB_Error_et LPS22HB_Get_Temperature(void *handle, int16_t* Tout) 01107 { 01108 int16_t raw_data; 01109 01110 if(LPS22HB_Get_RawTemperature(handle, &raw_data)) 01111 return LPS22HB_ERROR; 01112 01113 *Tout = (raw_data*10)/100; 01114 01115 return LPS22HB_OK; 01116 } 01117 01118 /** 01119 * @brief Get the threshold value used for pressure interrupt generation (hPA). 01120 * @detail THS_P=THS_P_H&THS_P_L and is expressed as unsigned number. P_ths(hPA)=(THS_P)/16. 01121 * @param *handle Device handle. 01122 * @param Buffer to empty with the pressure threshold in hPA 01123 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 01124 */ 01125 LPS22HB_Error_et LPS22HB_Get_PressureThreshold(void *handle, int16_t* P_ths) 01126 { 01127 uint8_t tempReg[2]; 01128 01129 if(LPS22HB_read_reg(handle, LPS22HB_THS_P_LOW_REG, 2, tempReg)) 01130 return LPS22HB_ERROR; 01131 01132 *P_ths= (((((uint16_t)tempReg[1])<<8) + tempReg[0])/16); 01133 01134 return LPS22HB_OK; 01135 } 01136 01137 /** 01138 * @brief Set the threshold value used for pressure interrupt generation (hPA). 01139 * @detail THS_P=THS_P_H&THS_P_L and is expressed as unsigned number. P_ths(hPA)=(THS_P)/16. 01140 * @param *handle Device handle. 01141 * @param Pressure threshold in hPA 01142 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 01143 */ 01144 LPS22HB_Error_et LPS22HB_Set_PressureThreshold(void *handle, int16_t P_ths) 01145 { 01146 uint8_t buffer[2]; 01147 01148 buffer[0] = (uint8_t)(16 * P_ths); 01149 buffer[1] = (uint8_t)(((uint16_t)(16 * P_ths))>>8); 01150 01151 if(LPS22HB_write_reg(handle, LPS22HB_THS_P_LOW_REG, 2, buffer)) 01152 return LPS22HB_ERROR; 01153 01154 return LPS22HB_OK; 01155 } 01156 01157 /** 01158 * @brief Set Fifo Mode. 01159 * @param *handle Device handle. 01160 * @param Fifo Mode struct 01161 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 01162 */ 01163 LPS22HB_Error_et LPS22HB_Set_FifoMode(void *handle, LPS22HB_FifoMode_et fifomode) 01164 { 01165 uint8_t tmp; 01166 01167 LPS22HB_assert_param(IS_LPS22HB_FifoMode(fifomode)); 01168 01169 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, &tmp)) 01170 return LPS22HB_ERROR; 01171 01172 tmp &= ~LPS22HB_FIFO_MODE_MASK; 01173 tmp |= (uint8_t)fifomode; 01174 01175 if(LPS22HB_write_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, &tmp)) 01176 return LPS22HB_ERROR; 01177 01178 return LPS22HB_OK; 01179 } 01180 01181 /** 01182 * @brief Get Fifo Mode 01183 * @param *handle Device handle. 01184 * @param buffer to empty with fifo mode tmp 01185 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 01186 */ 01187 LPS22HB_Error_et LPS22HB_Get_FifoMode(void *handle, LPS22HB_FifoMode_et* fifomode) 01188 { 01189 uint8_t tmp; 01190 01191 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, &tmp)) 01192 return LPS22HB_ERROR; 01193 01194 tmp &= LPS22HB_FIFO_MODE_MASK; 01195 *fifomode = (LPS22HB_FifoMode_et)tmp; 01196 01197 return LPS22HB_OK; 01198 } 01199 01200 /** 01201 * @brief Set Fifo Watermark Level. 01202 * @param *handle Device handle. 01203 * @param Watermark level value [0 31] 01204 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 01205 */ 01206 LPS22HB_Error_et LPS22HB_Set_FifoWatermarkLevel(void *handle, uint8_t wtmlevel) 01207 { 01208 uint8_t tmp; 01209 01210 LPS22HB_assert_param(IS_LPS22HB_WtmLevel(wtmlevel)); 01211 01212 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, &tmp)) 01213 return LPS22HB_ERROR; 01214 01215 tmp &= ~LPS22HB_WTM_POINT_MASK; 01216 tmp |= wtmlevel; 01217 01218 if(LPS22HB_write_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, &tmp)) 01219 return LPS22HB_ERROR; 01220 01221 return LPS22HB_OK; 01222 } 01223 01224 /** 01225 * @brief Get FIFO Watermark Level 01226 * @param *handle Device handle. 01227 * @param buffer to empty with watermak level[0,31] value read from sensor 01228 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 01229 */ 01230 LPS22HB_Error_et LPS22HB_Get_FifoWatermarkLevel(void *handle, uint8_t *wtmlevel) 01231 { 01232 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, wtmlevel)) 01233 return LPS22HB_ERROR; 01234 01235 *wtmlevel &= LPS22HB_WTM_POINT_MASK; 01236 01237 return LPS22HB_OK; 01238 } 01239 01240 /** 01241 * @brief Get the Fifo Status 01242 * @param *handle Device handle. 01243 * @param Status Flag: FIFO_FTH,FIFO_EMPTY,FIFO_FULL,FIFO_OVR and level of the FIFO->FIFO_LEVEL 01244 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 01245 */ 01246 LPS22HB_Error_et LPS22HB_Get_FifoStatus(void *handle, LPS22HB_FifoStatus_st* status) 01247 { 01248 uint8_t tmp; 01249 01250 if(LPS22HB_read_reg(handle, LPS22HB_STATUS_FIFO_REG, 1, &tmp)) 01251 return LPS22HB_ERROR; 01252 01253 status->FIFO_FTH = (uint8_t)((tmp & LPS22HB_FTH_FIFO_MASK)>>LPS22HB_FTH_FIFO_BIT); 01254 status->FIFO_OVR =(uint8_t)((tmp & LPS22HB_OVR_FIFO_MASK)>>LPS22HB_OVR_FIFO_BIT); 01255 status->FIFO_LEVEL = (uint8_t)(tmp & LPS22HB_LEVEL_FIFO_MASK); 01256 01257 if(status->FIFO_LEVEL ==LPS22HB_FIFO_EMPTY) 01258 status->FIFO_EMPTY =0x01; 01259 else 01260 status->FIFO_EMPTY =0x00; 01261 01262 if (status->FIFO_LEVEL ==LPS22HB_FIFO_FULL) 01263 status->FIFO_FULL =0x01; 01264 else 01265 status->FIFO_FULL =0x00; 01266 01267 01268 return LPS22HB_OK; 01269 } 01270 01271 /** 01272 * @brief Get the reference pressure after soldering for computing differential pressure (hPA) 01273 * @param *handle Device handle. 01274 * @param buffer to empty with the he pressure value (hPA) 01275 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 01276 */ 01277 LPS22HB_Error_et LPS22HB_Get_PressureOffsetValue(void *handle, int16_t *pressoffset) 01278 { 01279 uint8_t buffer[2]; 01280 int16_t raw_press; 01281 01282 if(LPS22HB_read_reg(handle, LPS22HB_RPDS_L_REG, 2, buffer)) 01283 return LPS22HB_ERROR; 01284 01285 raw_press = (int16_t)((((uint16_t)buffer[1]) << 8) + (uint16_t)buffer[0]); 01286 01287 *pressoffset = (raw_press*100)/4096; 01288 01289 return LPS22HB_OK; 01290 } 01291 01292 01293 /** 01294 * @brief Get the Reference Pressure value 01295 * @detail It is a 24-bit data added to the sensor output measurement to detect a measured pressure beyond programmed limits. 01296 * @param *handle Device handle. 01297 * @param Buffer to empty with reference pressure value 01298 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 01299 */ 01300 LPS22HB_Error_et LPS22HB_Get_ReferencePressure(void *handle, int32_t* RefP) 01301 { 01302 uint8_t buffer[3]; 01303 uint32_t tempVal=0; 01304 int32_t raw_press; 01305 uint8_t i; 01306 01307 if(LPS22HB_read_reg(handle, LPS22HB_REF_P_XL_REG, 3, buffer)) 01308 return LPS22HB_ERROR; 01309 01310 /* Build the raw data */ 01311 for(i=0; i<3; i++) 01312 tempVal |= (((uint32_t)buffer[i]) << (8*i)); 01313 01314 /* convert the 2's complement 24 bit to 2's complement 32 bit */ 01315 if(tempVal & 0x00800000) 01316 tempVal |= 0xFF000000; 01317 01318 raw_press =((int32_t)tempVal); 01319 *RefP = (raw_press*100)/4096; 01320 01321 01322 return LPS22HB_OK; 01323 } 01324 01325 01326 /** 01327 * @brief Check if the single measurement has completed. 01328 * @param *handle Device handle. 01329 * @param the returned value is set to 1, when the measurement is completed 01330 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 01331 */ 01332 LPS22HB_Error_et LPS22HB_IsMeasurementCompleted(void *handle, uint8_t* Is_Measurement_Completed) 01333 { 01334 uint8_t tmp; 01335 LPS22HB_DataStatus_st datastatus; 01336 01337 if(LPS22HB_read_reg(handle, LPS22HB_STATUS_REG, 1, &tmp)) 01338 return LPS22HB_ERROR; 01339 01340 datastatus.TempDataAvailable =(uint8_t)((tmp&LPS22HB_TDA_MASK)>>LPS22HB_TDA_BIT); 01341 datastatus.PressDataAvailable = (uint8_t)(tmp&LPS22HB_PDA_MASK); 01342 01343 *Is_Measurement_Completed=(uint8_t)((datastatus.PressDataAvailable ) & (datastatus.TempDataAvailable )); 01344 01345 return LPS22HB_OK; 01346 } 01347 01348 /** 01349 * @brief Get the values of the last single measurement. 01350 * @param *handle Device handle. 01351 * @param Pressure and temperature tmp 01352 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK] 01353 */ 01354 LPS22HB_Error_et LPS22HB_Get_Measurement(void *handle, LPS22HB_MeasureTypeDef_st *Measurement_Value) 01355 { 01356 int16_t Tout; 01357 int32_t Pout; 01358 01359 if(LPS22HB_Get_Temperature(handle, &Tout)) 01360 return LPS22HB_ERROR; 01361 01362 Measurement_Value->Tout=Tout; 01363 01364 if(LPS22HB_Get_Pressure(handle, &Pout)) 01365 return LPS22HB_ERROR; 01366 01367 Measurement_Value->Pout=Pout; 01368 01369 return LPS22HB_OK; 01370 01371 } 01372 01373 /** 01374 * @brief Initialization function for LPS22HB. 01375 * This function make a memory boot. 01376 * Init the sensor with a standard basic confifuration. 01377 * Low Power, ODR 25 Hz, Low Pass Filter disabled; BDU enabled; I2C enabled; 01378 * NO FIFO; NO Interrupt Enabled. 01379 * @param *handle Device handle. 01380 * @retval Error code[LPS22HB_ERROR, LPS22HB_OK] 01381 */ 01382 LPS22HB_Error_et LPS22HB_Init(void *handle) 01383 { 01384 LPS22HB_ConfigTypeDef_st pLPS22HBInit; 01385 01386 /* Make LPS22HB Reset and Reboot */ 01387 if(LPS22HB_SwResetAndMemoryBoot(handle)) 01388 return LPS22HB_ERROR; 01389 01390 pLPS22HBInit.PowerMode =LPS22HB_LowPower ; 01391 pLPS22HBInit.OutputDataRate =LPS22HB_ODR_25HZ ; 01392 pLPS22HBInit.LowPassFilter =LPS22HB_DISABLE; 01393 pLPS22HBInit.LPF_Cutoff =LPS22HB_ODR_9 ; 01394 pLPS22HBInit.BDU =LPS22HB_BDU_NO_UPDATE ; 01395 pLPS22HBInit.IfAddInc =LPS22HB_ENABLE; //default 01396 pLPS22HBInit.Sim = LPS22HB_SPI_4_WIRE; 01397 01398 /* Set Generic Configuration*/ 01399 if(LPS22HB_Set_GenericConfig(handle, &pLPS22HBInit)) 01400 return LPS22HB_ERROR; 01401 01402 return LPS22HB_OK; 01403 } 01404 01405 /** 01406 * @brief De initialization function for LPS22HB. 01407 * This function make a memory boot and clear the data output flags. 01408 * @param *handle Device handle. 01409 * @retval Error code[LPS22HB_ERROR, LPS22HB_OK] 01410 */ 01411 LPS22HB_Error_et LPS22HB_DeInit(void *handle) 01412 { 01413 LPS22HB_MeasureTypeDef_st Measurement_Value; 01414 01415 /* Make LPS22HB Reset and Reboot */ 01416 if(LPS22HB_SwResetAndMemoryBoot(handle)) 01417 return LPS22HB_ERROR; 01418 01419 /* Dump of data output */ 01420 if(LPS22HB_Get_Measurement(handle, &Measurement_Value)) 01421 return LPS22HB_ERROR; 01422 01423 return LPS22HB_OK; 01424 } 01425 01426 01427 /** 01428 * @brief Set Generic Configuration 01429 * @param *handle Device handle. 01430 * @param Struct to empty with the chosen values 01431 * @retval Error code[LPS22HB_ERROR, LPS22HB_OK] 01432 */ 01433 LPS22HB_Error_et LPS22HB_Set_GenericConfig(void *handle, LPS22HB_ConfigTypeDef_st* pxLPS22HBInit) 01434 { 01435 01436 /* Enable Low Current Mode (low Power) or Low Noise Mode*/ 01437 if(LPS22HB_Set_PowerMode(handle, pxLPS22HBInit->PowerMode )) 01438 return LPS22HB_ERROR; 01439 01440 /* Init the Output Data Rate*/ 01441 if(LPS22HB_Set_Odr(handle, pxLPS22HBInit->OutputDataRate )) 01442 return LPS22HB_ERROR; 01443 01444 /* BDU bit is used to inhibit the output registers update between the reading of upper and 01445 lower register parts. In default mode (BDU = ‘0’), the lower and upper register parts are 01446 updated continuously. If it is not sure to read faster than output data rate, it is recommended 01447 to set BDU bit to ‘1’. In this way, after the reading of the lower (upper) register part, the 01448 content of that output registers is not updated until the upper (lower) part is read too. 01449 This feature avoids reading LSB and MSB related to different samples.*/ 01450 01451 if(LPS22HB_Set_Bdu(handle, pxLPS22HBInit->BDU )) 01452 return LPS22HB_ERROR; 01453 01454 /*Enable/Disale low-pass filter on LPS22HB pressure data*/ 01455 if(LPS22HB_Set_LowPassFilter(handle, pxLPS22HBInit->LowPassFilter )) 01456 return LPS22HB_ERROR; 01457 01458 /* Set low-pass filter cutoff configuration*/ 01459 if(LPS22HB_Set_LowPassFilterCutoff(handle, pxLPS22HBInit->LPF_Cutoff )) 01460 return LPS22HB_ERROR; 01461 01462 /* SIM bit selects the SPI serial interface mode.*/ 01463 /* This feature has effect only if SPI interface is used*/ 01464 01465 if(LPS22HB_Set_SpiInterface(handle, pxLPS22HBInit->Sim )) 01466 return LPS22HB_ERROR; 01467 01468 /*Enable or Disable the Automatic increment register address during a multiple byte access with a serial interface (I2C or SPI)*/ 01469 if(LPS22HB_Set_AutomaticIncrementRegAddress(handle, pxLPS22HBInit->IfAddInc )) 01470 return LPS22HB_ERROR; 01471 01472 01473 return LPS22HB_OK; 01474 } 01475 01476 /** 01477 * @brief Get Generic configuration 01478 * @param *handle Device handle. 01479 * @param Struct to empty with configuration values 01480 * @retval Error code[LPS22HB_ERROR, LPS22HB_OK] 01481 */ 01482 LPS22HB_Error_et LPS22HB_Get_GenericConfig(void *handle, LPS22HB_ConfigTypeDef_st* pxLPS22HBInit) 01483 { 01484 01485 uint8_t tmp; 01486 01487 /*Read LPS22HB_RES_CONF_REG*/ 01488 if(LPS22HB_Get_PowerMode(handle, &pxLPS22HBInit->PowerMode )) 01489 return LPS22HB_ERROR; 01490 01491 /*Read LPS22HB_CTRL_REG1*/ 01492 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp)) 01493 return LPS22HB_ERROR; 01494 01495 pxLPS22HBInit->OutputDataRate = (LPS22HB_Odr_et)(tmp & LPS22HB_ODR_MASK); 01496 pxLPS22HBInit->BDU =(LPS22HB_Bdu_et)(tmp & LPS22HB_BDU_MASK); 01497 pxLPS22HBInit->Sim =(LPS22HB_SPIMode_et)(tmp& LPS22HB_SIM_MASK); 01498 pxLPS22HBInit->LowPassFilter =(LPS22HB_State_et)((tmp& LPS22HB_LPFP_MASK)>>LPS22HB_LPFP_BIT); 01499 pxLPS22HBInit->LPF_Cutoff =(LPS22HB_LPF_Cutoff_et)(tmp& LPS22HB_LPFP_CUTOFF_MASK); 01500 01501 /*Read LPS22HB_CTRL_REG2*/ 01502 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) 01503 return LPS22HB_ERROR; 01504 01505 pxLPS22HBInit->IfAddInc =(LPS22HB_State_et)((tmp& LPS22HB_ADD_INC_MASK)>>LPS22HB_ADD_INC_BIT); 01506 01507 return LPS22HB_OK; 01508 } 01509 01510 01511 /** 01512 * @brief Set Interrupt configuration 01513 * @param *handle Device handle. 01514 * @param Struct holding the configuration values 01515 * @retval Error code[LPS22HB_ERROR, LPS22HB_OK] 01516 */ 01517 LPS22HB_Error_et LPS22HB_Set_InterruptConfig(void *handle, LPS22HB_InterruptTypeDef_st* pLPS22HBInt) 01518 { 01519 /* Enable Low Current Mode (low Power) or Low Noise Mode*/ 01520 if(LPS22HB_Set_InterruptActiveLevel(handle, pLPS22HBInt->INT_H_L )) 01521 return LPS22HB_ERROR; 01522 01523 /* Push-pull/open drain selection on interrupt pads.*/ 01524 if(LPS22HB_Set_InterruptOutputType(handle, pLPS22HBInt->PP_OD )) 01525 return LPS22HB_ERROR; 01526 01527 /* Set Data signal on INT pad control bits.*/ 01528 if(LPS22HB_Set_InterruptControlConfig(handle, pLPS22HBInt->OutputSignal_INT )) 01529 return LPS22HB_ERROR; 01530 01531 /* Enable/Disable Data-ready signal on INT_DRDY pin. */ 01532 if(LPS22HB_Set_DRDYInterrupt(handle, pLPS22HBInt->DRDY )) 01533 return LPS22HB_ERROR; 01534 01535 /* Enable/Disable FIFO overrun interrupt on INT_DRDY pin. */ 01536 if(LPS22HB_Set_FIFO_OVR_Interrupt(handle, pLPS22HBInt->FIFO_OVR )) 01537 return LPS22HB_ERROR; 01538 01539 /* Enable/Disable FIFO Treshold interrupt on INT_DRDY pin. */ 01540 if(LPS22HB_Set_FIFO_FTH_Interrupt(handle, pLPS22HBInt->FIFO_FTH )) 01541 return LPS22HB_ERROR; 01542 01543 /* Enable/Disable FIFO FULL interrupt on INT_DRDY pin. */ 01544 if(LPS22HB_Set_FIFO_FULL_Interrupt(handle, pLPS22HBInt->FIFO_FULL )) 01545 return LPS22HB_ERROR; 01546 01547 /* Latch Interrupt request to the INT_SOURCE register. */ 01548 if(LPS22HB_LatchInterruptRequest(handle, pLPS22HBInt->LatchIRQ )) 01549 return LPS22HB_ERROR; 01550 01551 /* Set the threshold value used for pressure interrupt generation (hPA). */ 01552 if(LPS22HB_Set_PressureThreshold(handle, pLPS22HBInt->THS_threshold )) 01553 return LPS22HB_ERROR; 01554 01555 /*Enable/Disable AutoRifP function */ 01556 if(pLPS22HBInt->AutoRifP ==LPS22HB_ENABLE){ 01557 if(LPS22HB_Set_AutoRifP(handle)) 01558 return LPS22HB_ERROR; 01559 } 01560 else{ 01561 if(LPS22HB_ResetAutoRifP(handle)) 01562 return LPS22HB_ERROR; 01563 } 01564 01565 /*Enable/Disable AutoZero function*/ 01566 if(pLPS22HBInt->AutoZero ==LPS22HB_ENABLE){ 01567 if(LPS22HB_Set_AutoZeroFunction(handle)) 01568 return LPS22HB_ERROR; 01569 } 01570 else{ 01571 if(LPS22HB_ResetAutoZeroFunction(handle)) 01572 return LPS22HB_ERROR; 01573 } 01574 01575 01576 if(pLPS22HBInt->OutputSignal_INT ==LPS22HB_P_HIGH) 01577 { 01578 /* Enable\Disable Interrupt Generation on differential pressure high event*/ 01579 if(LPS22HB_Set_PHE(handle, LPS22HB_ENABLE)) 01580 return LPS22HB_ERROR; 01581 if(LPS22HB_Set_InterruptDifferentialGeneration(handle, LPS22HB_ENABLE)) 01582 return LPS22HB_ERROR; 01583 } 01584 else if(pLPS22HBInt->OutputSignal_INT ==LPS22HB_P_LOW) 01585 { 01586 /* Enable Interrupt Generation on differential pressure Loe event*/ 01587 if(LPS22HB_Set_PLE(handle, LPS22HB_ENABLE)) 01588 return LPS22HB_ERROR; 01589 if(LPS22HB_Set_InterruptDifferentialGeneration(handle, LPS22HB_ENABLE)) 01590 return LPS22HB_ERROR; 01591 } 01592 else if(pLPS22HBInt->OutputSignal_INT ==LPS22HB_P_LOW_HIGH) 01593 { 01594 /* Enable Interrupt Generation on differential pressure high event*/ 01595 if(LPS22HB_Set_PHE(handle, LPS22HB_ENABLE)) 01596 return LPS22HB_ERROR; 01597 /* Enable\Disable Interrupt Generation on differential pressure Loe event*/ 01598 if(LPS22HB_Set_PLE(handle, LPS22HB_ENABLE)) 01599 return LPS22HB_ERROR; 01600 if(LPS22HB_Set_InterruptDifferentialGeneration(handle, LPS22HB_ENABLE)) 01601 return LPS22HB_ERROR; 01602 } 01603 else 01604 { 01605 if(LPS22HB_Set_InterruptDifferentialGeneration(handle, LPS22HB_DISABLE)) 01606 return LPS22HB_ERROR; 01607 /* Disable Interrupt Generation on differential pressure High event*/ 01608 if(LPS22HB_Set_PHE(handle, LPS22HB_DISABLE)) 01609 return LPS22HB_ERROR; 01610 /* Disable Interrupt Generation on differential pressure Low event*/ 01611 if(LPS22HB_Set_PLE(handle, LPS22HB_DISABLE)) 01612 return LPS22HB_ERROR; 01613 } 01614 01615 return LPS22HB_OK; 01616 } 01617 01618 /** 01619 * @brief LPS22HBGet_InterruptConfig 01620 * @param *handle Device handle. 01621 * @param Struct to empty with configuration values 01622 * @retval S Error code[LPS22HB_ERROR, LPS22HB_OK] 01623 */ 01624 LPS22HB_Error_et LPS22HB_Get_InterruptConfig(void *handle, LPS22HB_InterruptTypeDef_st* pLPS22HBInt) 01625 { 01626 uint8_t tmp; 01627 01628 /*Read LPS22HB_CTRL_REG3*/ 01629 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp)) 01630 return LPS22HB_ERROR; 01631 01632 pLPS22HBInt->INT_H_L = (LPS22HB_InterruptActiveLevel_et)(tmp & LPS22HB_INT_H_L_MASK); 01633 pLPS22HBInt->PP_OD =(LPS22HB_OutputType_et)(tmp & LPS22HB_PP_OD_MASK); 01634 pLPS22HBInt->OutputSignal_INT =(LPS22HB_OutputSignalConfig_et)(tmp& LPS22HB_INT_S12_MASK); 01635 pLPS22HBInt->DRDY =(LPS22HB_State_et)((tmp& LPS22HB_DRDY_MASK)>>LPS22HB_DRDY_BIT); 01636 pLPS22HBInt->FIFO_OVR =(LPS22HB_State_et)((tmp& LPS22HB_FIFO_OVR_MASK)>>LPS22HB_FIFO_OVR_BIT); 01637 pLPS22HBInt->FIFO_FTH =(LPS22HB_State_et)((tmp& LPS22HB_FIFO_FTH_MASK)>>LPS22HB_FIFO_FTH_BIT); 01638 pLPS22HBInt->FIFO_FULL =(LPS22HB_State_et)((tmp& LPS22HB_FIFO_FULL_MASK)>>LPS22HB_FIFO_FULL_BIT); 01639 01640 /*Read LPS22HB_INTERRUPT_CFG_REG*/ 01641 if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp)) 01642 return LPS22HB_ERROR; 01643 01644 pLPS22HBInt->LatchIRQ = (LPS22HB_State_et)((tmp& LPS22HB_LIR_MASK)>>LPS22HB_LIR_BIT); 01645 01646 if(LPS22HB_Get_PressureThreshold(handle, &pLPS22HBInt->THS_threshold )) 01647 return LPS22HB_ERROR; 01648 01649 //AutoRifP and Autozero are self clear // 01650 pLPS22HBInt->AutoRifP =LPS22HB_DISABLE; 01651 pLPS22HBInt->AutoZero =LPS22HB_DISABLE; 01652 01653 return LPS22HB_OK; 01654 } 01655 01656 /** 01657 * @brief Set Fifo configuration 01658 * @param *handle Device handle. 01659 * @param Struct holding the configuration values 01660 * @retval Error code[LPS22HB_ERROR, LPS22HB_OK] 01661 */ 01662 LPS22HB_Error_et LPS22HB_Set_FifoConfig(void *handle, LPS22HB_FIFOTypeDef_st* pLPS22HBFIFO) 01663 { 01664 01665 if(pLPS22HBFIFO->FIFO_MODE == LPS22HB_FIFO_BYPASS_MODE ) { 01666 /* FIFO Disable-> FIFO_EN bit=0 in CTRL_REG2*/ 01667 if(LPS22HB_Set_FifoModeUse(handle, LPS22HB_DISABLE)) 01668 return LPS22HB_ERROR; 01669 /* Force->Disable FIFO Watermark Level Use*/ 01670 if(LPS22HB_Set_FifoWatermarkLevelUse(handle, LPS22HB_DISABLE)) 01671 return LPS22HB_ERROR; 01672 01673 /* Force->Disable FIFO Treshold interrupt on INT_DRDY pin. */ 01674 if(LPS22HB_Set_FIFO_FTH_Interrupt(handle, LPS22HB_DISABLE)) 01675 return LPS22HB_ERROR; 01676 } 01677 else { 01678 /* FIFO Enable-> FIFO_EN bit=1 in CTRL_REG2*/ 01679 if(LPS22HB_Set_FifoModeUse(handle, LPS22HB_ENABLE)) 01680 return LPS22HB_ERROR; 01681 01682 if (pLPS22HBFIFO->WTM_INT ){ 01683 /* Enable FIFO Watermark Level Use*/ 01684 if(LPS22HB_Set_FifoWatermarkLevelUse(handle, LPS22HB_ENABLE)) 01685 return LPS22HB_ERROR; 01686 /*Set Fifo Watermark Level*/ 01687 if(LPS22HB_Set_FifoWatermarkLevel(handle, pLPS22HBFIFO->WTM_LEVEL )) 01688 return LPS22HB_ERROR; 01689 /* Force->enable FIFO Treshold interrupt on INT_DRDY pin. */ 01690 if(LPS22HB_Set_FIFO_FTH_Interrupt(handle, LPS22HB_ENABLE)) 01691 return LPS22HB_ERROR; 01692 } 01693 } 01694 01695 if(LPS22HB_Set_FifoMode(handle, pLPS22HBFIFO->FIFO_MODE )) 01696 return LPS22HB_ERROR; 01697 01698 return LPS22HB_OK; 01699 } 01700 01701 /** 01702 * @brief Get Fifo configuration 01703 * @param *handle Device handle. 01704 * @param Struct to empty with the configuration values 01705 * @retval Error code[LPS22HB_ERROR, LPS22HB_OK] 01706 */ 01707 LPS22HB_Error_et LPS22HB_Get_FifoConfig(void *handle, LPS22HB_FIFOTypeDef_st* pLPS22HBFIFO) 01708 { 01709 uint8_t tmp; 01710 01711 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, &tmp)) 01712 return LPS22HB_ERROR; 01713 01714 /*!< Fifo Mode Selection */ 01715 pLPS22HBFIFO->FIFO_MODE = (LPS22HB_FifoMode_et)(tmp& LPS22HB_FIFO_MODE_MASK); 01716 01717 /*!< FIFO threshold/Watermark level selection*/ 01718 pLPS22HBFIFO->WTM_LEVEL = (uint8_t)(tmp& LPS22HB_WTM_POINT_MASK); 01719 01720 if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp)) 01721 return LPS22HB_ERROR; 01722 01723 /*!< Enable/Disable the watermark interrupt*/ 01724 pLPS22HBFIFO->WTM_INT = (LPS22HB_State_et)((tmp& LPS22HB_WTM_EN_MASK)>>LPS22HB_WTM_EN_BIT); 01725 01726 01727 return LPS22HB_OK; 01728 } 01729 01730 #ifdef USE_FULL_ASSERT_LPS22HB 01731 /** 01732 * @brief Reports the name of the source file and the source line number 01733 * where the assert_param error has occurred. 01734 * @param file: pointer to the source file name 01735 * @param line: assert_param error line source number 01736 * @retval : None 01737 */ 01738 void LPS22HB_assert_failed(uint8_t* file, uint32_t line) 01739 { 01740 /* User can add his own implementation to report the file name and line number */ 01741 printf("Wrong parameters tmp: file %s on line %d\r\n", file, (int)line); 01742 01743 /* Infinite loop */ 01744 while (1) 01745 { 01746 } 01747 } 01748 #endif 01749 01750 /** 01751 * @} 01752 */ 01753 01754 /** 01755 * @} 01756 */ 01757 01758 /** 01759 * @} 01760 */ 01761 01762 /******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/
Generated on Wed Jul 13 2022 22:58:05 by
