Sailesh Timilsena / Mbed OS Z_IOT_ResearchWork

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LPS22HB_driver.c Source File

LPS22HB_driver.c

Go to the documentation of this file.
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>&copy; 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;  //deft LPS22HB_CTRL_REG1 value
00345 
00346   LPS22HB_assert_param(IS_LPS22HB_SPIMode(spimode));
00347 
00348 /** FIXME could not read before setting SPI mode **/    
00349 //  if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp))
00350 //    return LPS22HB_ERROR;
00351 
00352   tmp &= ~LPS22HB_SIM_MASK;
00353   tmp |= (uint8_t)spimode;
00354 
00355   if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp))
00356     return LPS22HB_ERROR;
00357 
00358   return LPS22HB_OK;
00359 }
00360 
00361 /**
00362 * @brief  Clock Tree Configuration
00363 * @param  *handle Device handle.
00364 * @param  LPS22HB_CTE_NotBalanced, LPS22HB_CTE_ABalanced
00365 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK]
00366 */
00367 LPS22HB_Error_et LPS22HB_Set_ClockTreeConfifuration(void *handle, LPS22HB_CTE_et mode)
00368 {
00369   uint8_t tmp;
00370 
00371 
00372   LPS22HB_assert_param(IS_LPS22HB_CTE(mode));
00373 
00374   if(LPS22HB_read_reg(handle, LPS22HB_CLOCK_TREE_CONFIGURATION, 1, &tmp))
00375     return LPS22HB_ERROR;
00376 
00377   tmp &= ~LPS22HB_CTE_MASK;
00378   tmp |= (uint8_t)mode;
00379 
00380 
00381   if(LPS22HB_write_reg(handle, LPS22HB_CLOCK_TREE_CONFIGURATION, 1, &tmp))
00382     return LPS22HB_ERROR;
00383 
00384   return LPS22HB_OK;
00385 }
00386 
00387 
00388 /**
00389 * @brief  Get SPI mode: 3 Wire Interface or 4 Wire Interface
00390 * @param  *handle Device handle.
00391 * @param Buffet to empty with spi mode read from Sensor
00392 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK]
00393 */
00394 LPS22HB_Error_et LPS22HB_Get_SpiInterface(void *handle, LPS22HB_SPIMode_et* spimode)
00395 {
00396   uint8_t tmp;
00397 
00398   if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp))
00399     return LPS22HB_ERROR;
00400 
00401   *spimode = (LPS22HB_SPIMode_et)(tmp & LPS22HB_SIM_MASK);
00402 
00403   return LPS22HB_OK;
00404 }
00405 
00406   /**
00407 * @brief   Software Reset. Self-clearing upon completion
00408 * @param  *handle Device handle.
00409 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK]
00410 */
00411 LPS22HB_Error_et LPS22HB_SwReset(void *handle)
00412 {
00413   uint8_t tmp;
00414 
00415   if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp))
00416     return LPS22HB_ERROR;
00417 
00418   tmp |= (0x01<<LPS22HB_SW_RESET_BIT);
00419 
00420   if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp))
00421     return LPS22HB_ERROR;
00422 
00423   return LPS22HB_OK;
00424 }
00425 
00426 /**
00427 * @brief  Reboot Memory Content
00428 * @param  *handle Device handle.
00429 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK]
00430 */
00431 
00432 LPS22HB_Error_et LPS22HB_MemoryBoot(void *handle)
00433 {
00434   uint8_t tmp;
00435 
00436   if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp))
00437     return LPS22HB_ERROR;
00438 
00439   tmp |= (0x01<<LPS22HB_BOOT_BIT);
00440 
00441   if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp))
00442     return LPS22HB_ERROR;
00443 
00444   return LPS22HB_OK;
00445 }
00446 
00447 /**
00448 * @brief   Software Reset ann Reboot Memory Content.
00449 * @detail  The device is reset to the power on configuration if the SWRESET bit is set to ‘1’
00450  + and BOOT is set to ‘1’; Self-clearing upon completion.
00451 * @param  *handle Device handle.
00452 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK]
00453 */
00454 LPS22HB_Error_et LPS22HB_SwResetAndMemoryBoot(void *handle)
00455 {
00456   uint8_t tmp;
00457 
00458   if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp))
00459     return LPS22HB_ERROR;
00460 
00461   tmp |= ((0x01<<LPS22HB_SW_RESET_BIT) | (0x01<<LPS22HB_BOOT_BIT));
00462 
00463   if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp))
00464     return LPS22HB_ERROR;
00465 
00466   return LPS22HB_OK;
00467 }
00468 
00469 
00470 /**
00471 * @brief   Enable/Disable FIFO Mode
00472 * @param  *handle Device handle.
00473 * @param LPS22HB_ENABLE/LPS22HB_DISABLE
00474 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK]
00475 */
00476 LPS22HB_Error_et LPS22HB_Set_FifoModeUse(void *handle, LPS22HB_State_et status)
00477 {
00478   uint8_t tmp;
00479 
00480   LPS22HB_assert_param(IS_LPS22HB_State(status));
00481 
00482   if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp))
00483     return LPS22HB_ERROR;
00484 
00485   tmp &= ~LPS22HB_FIFO_EN_MASK;
00486   tmp |= ((uint8_t)status)<<LPS22HB_FIFO_EN_BIT;
00487 
00488   if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp))
00489     return LPS22HB_ERROR;
00490 
00491   return LPS22HB_OK;
00492 }
00493 /**
00494 * @brief   Enable/Disable FIFO Watermark Level Use
00495 * @param  *handle Device handle.
00496 * @param   LPS22HB_ENABLE/LPS22HB_DISABLE
00497 * @retval  Error Code [LPS22HB_ERROR, LPS22HB_OK]
00498 */
00499 LPS22HB_Error_et LPS22HB_Set_FifoWatermarkLevelUse(void *handle, LPS22HB_State_et status)
00500 {
00501   uint8_t tmp;
00502 
00503   LPS22HB_assert_param(IS_LPS22HB_State(status));
00504 
00505   if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp))
00506     return LPS22HB_ERROR;
00507 
00508   tmp &= ~LPS22HB_WTM_EN_MASK;
00509   tmp |= ((uint8_t)status)<<LPS22HB_WTM_EN_BIT;
00510 
00511   if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp))
00512     return LPS22HB_ERROR;
00513 
00514   return LPS22HB_OK;
00515 }
00516 
00517  /**
00518 * @brief  Enable or Disable the Automatic increment register address during a multiple byte access with a serial interface (I2C or SPI)
00519 * @param  *handle Device handle.
00520 * @param  LPS22HB_ENABLE/LPS22HB_DISABLE. Default is LPS22HB_ENABLE
00521 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK]
00522 */
00523 LPS22HB_Error_et LPS22HB_Set_AutomaticIncrementRegAddress(void *handle, LPS22HB_State_et status){
00524 
00525   uint8_t tmp;
00526 
00527  LPS22HB_assert_param(IS_LPS22HB_State(status));
00528 
00529   if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp))
00530     return LPS22HB_ERROR;
00531 
00532   tmp &= ~LPS22HB_ADD_INC_MASK;
00533   tmp |= (((uint8_t)status)<<LPS22HB_ADD_INC_BIT);
00534 
00535   if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp))
00536     return LPS22HB_ERROR;
00537 
00538   return LPS22HB_OK;
00539 
00540 }
00541 
00542 /**
00543 * @brief  Enable/Disable I2C Interface
00544 * @param  *handle Device handle.
00545 * @param State: LPS22HB_ENABLE (reset bit)/ LPS22HB_DISABLE (set bit)
00546 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK]
00547 */
00548 LPS22HB_Error_et LPS22HB_Set_I2C(void *handle, LPS22HB_State_et statei2c)
00549 {
00550   uint8_t tmp;
00551 
00552   LPS22HB_assert_param(IS_LPS22HB_State(statei2c));
00553 
00554   if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp))
00555     return LPS22HB_ERROR;
00556 
00557   /*Reset Bit->I2C Enabled*/
00558   tmp &= ~LPS22HB_I2C_MASK;
00559   tmp|=((uint8_t)~statei2c)<<LPS22HB_I2C_BIT;
00560 
00561   if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp))
00562     return LPS22HB_ERROR;
00563 
00564   return LPS22HB_OK;
00565 }
00566 
00567 
00568 /**
00569 * @brief   Set the one-shot bit in order to start acquisition when the ONE SHOT mode
00570 *          has been selected by the ODR configuration.
00571 * @detail  Once the measurement is done, ONE_SHOT bit will self-clear.
00572 * @param  *handle Device handle.
00573 * @retval  Error Code [LPS22HB_ERROR, LPS22HB_OK]
00574 */
00575 LPS22HB_Error_et LPS22HB_StartOneShotMeasurement(void *handle)
00576 {
00577   uint8_t tmp;
00578 
00579   if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp))
00580     return LPS22HB_ERROR;
00581 
00582   /* Set the one shot bit */
00583   /* Once the measurement is done, one shot bit will self-clear*/
00584   tmp |= LPS22HB_ONE_SHOT_MASK;
00585 
00586   if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp))
00587     return LPS22HB_ERROR;
00588 
00589   return LPS22HB_OK;
00590 
00591 }
00592 
00593 /**
00594 * @brief  Set Interrupt Active on High or Low Level
00595 * @param  *handle Device handle.
00596 * @param  LPS22HB_ActiveHigh/LPS22HB_ActiveLow
00597 * @retval  Error Code [LPS22HB_ERROR, LPS22HB_OK]
00598 */
00599 LPS22HB_Error_et LPS22HB_Set_InterruptActiveLevel(void *handle, LPS22HB_InterruptActiveLevel_et mode)
00600 {
00601   uint8_t tmp;
00602 
00603   LPS22HB_assert_param(IS_LPS22HB_InterruptActiveLevel(mode));
00604 
00605   if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp))
00606     return LPS22HB_ERROR;
00607 
00608   tmp &= ~LPS22HB_INT_H_L_MASK;
00609   tmp |= ((uint8_t)mode);
00610 
00611   if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp))
00612     return LPS22HB_ERROR;
00613 
00614   return LPS22HB_OK;
00615 }
00616 
00617 
00618 /**
00619 * @brief   Push-pull/open drain selection on interrupt pads. Default tmp: 0
00620 * @param  *handle Device handle.
00621 * @param   LPS22HB_PushPull/LPS22HB_OpenDrain
00622 * @retval  Error Code [LPS22HB_ERROR, LPS22HB_OK]
00623 */
00624 LPS22HB_Error_et LPS22HB_Set_InterruptOutputType(void *handle, LPS22HB_OutputType_et output)
00625 {
00626   uint8_t tmp;
00627 
00628   LPS22HB_assert_param(IS_LPS22HB_OutputType(output));
00629 
00630   if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp))
00631     return LPS22HB_ERROR;
00632 
00633   tmp &= ~LPS22HB_PP_OD_MASK;
00634   tmp |= (uint8_t)output;
00635 
00636   if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp))
00637     return LPS22HB_ERROR;
00638 
00639   return LPS22HB_OK;
00640 }
00641 
00642 /**
00643 * @brief  Set Data signal on INT pad control bits.
00644 * @param  *handle Device handle.
00645 * @param  LPS22HB_DATA,LPS22HB_P_HIGH_LPS22HB_P_LOW,LPS22HB_P_LOW_HIGH
00646 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK]
00647 */
00648 LPS22HB_Error_et LPS22HB_Set_InterruptControlConfig(void *handle, LPS22HB_OutputSignalConfig_et config)
00649 {
00650   uint8_t tmp;
00651 
00652   LPS22HB_assert_param(IS_LPS22HB_OutputSignal(config));
00653 
00654   if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp))
00655     return LPS22HB_ERROR;
00656 
00657     tmp &= ~(LPS22HB_INT_S12_MASK);
00658     tmp |= (uint8_t)config;
00659 
00660   if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp))
00661     return LPS22HB_ERROR;
00662 
00663   return LPS22HB_OK;
00664 }
00665 
00666 
00667 /**
00668 * @brief   Enable/Disable Data-ready signal on INT_DRDY pin.
00669 * @param  *handle Device handle.
00670 * @param  LPS22HB_ENABLE/LPS22HB_DISABLE
00671 * @retval  Error Code [LPS22HB_ERROR, LPS22HB_OK]
00672 */
00673 LPS22HB_Error_et LPS22HB_Set_DRDYInterrupt(void *handle, LPS22HB_State_et status)
00674 {
00675   uint8_t tmp;
00676 
00677 
00678   LPS22HB_assert_param(IS_LPS22HB_State(status));
00679 
00680   if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp))
00681     return LPS22HB_ERROR;
00682 
00683   tmp &= ~LPS22HB_DRDY_MASK;
00684   tmp |= ((uint8_t)status)<<LPS22HB_DRDY_BIT;
00685 
00686   if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp))
00687     return LPS22HB_ERROR;
00688 
00689   return LPS22HB_OK;
00690 }
00691 
00692  /**
00693 * @brief   Enable/Disable FIFO overrun interrupt on INT_DRDY pin.
00694 * @param  *handle Device handle.
00695 * @param  LPS22HB_ENABLE/LPS22HB_DISABLE
00696 * @retval  Error Code [LPS22HB_ERROR, LPS22HB_OK]
00697 */
00698 LPS22HB_Error_et LPS22HB_Set_FIFO_OVR_Interrupt(void *handle, LPS22HB_State_et status)
00699 {
00700   uint8_t tmp;
00701 
00702 
00703   LPS22HB_assert_param(IS_LPS22HB_State(status));
00704 
00705   if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp))
00706     return LPS22HB_ERROR;
00707 
00708   tmp &= ~LPS22HB_FIFO_OVR_MASK;
00709   tmp |= ((uint8_t)status)<<LPS22HB_FIFO_OVR_BIT;
00710 
00711   if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp))
00712     return LPS22HB_ERROR;
00713 
00714   return LPS22HB_OK;
00715 }
00716 
00717  /**
00718 * @brief   Enable/Disable FIFO threshold (Watermark) interrupt on INT_DRDY pin.
00719 * @param  *handle Device handle.
00720 * @param  LPS22HB_ENABLE/LPS22HB_DISABLE
00721 * @retval  Error Code [LPS22HB_ERROR, LPS22HB_OK]
00722 */
00723 LPS22HB_Error_et LPS22HB_Set_FIFO_FTH_Interrupt(void *handle, LPS22HB_State_et status)
00724 {
00725   uint8_t tmp;
00726 
00727   LPS22HB_assert_param(IS_LPS22HB_State(status));
00728 
00729   if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp))
00730     return LPS22HB_ERROR;
00731 
00732   tmp &= ~LPS22HB_FIFO_FTH_MASK;
00733   tmp |= ((uint8_t)status)<<LPS22HB_FIFO_FTH_BIT;
00734 
00735   if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp))
00736     return LPS22HB_ERROR;
00737 
00738   return LPS22HB_OK;
00739 }
00740 
00741 /**
00742 * @brief   Enable/Disable FIFO FULL interrupt on INT_DRDY pin.
00743 * @param  *handle Device handle.
00744 * @param  LPS22HB_ENABLE/LPS22HB_DISABLE
00745 * @retval  Error Code [LPS22HB_ERROR, LPS22HB_OK]
00746 */
00747 LPS22HB_Error_et LPS22HB_Set_FIFO_FULL_Interrupt(void *handle, LPS22HB_State_et status)
00748 {
00749   uint8_t tmp;
00750 
00751   LPS22HB_assert_param(IS_LPS22HB_State(status));
00752 
00753   if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp))
00754     return LPS22HB_ERROR;
00755 
00756   tmp &= ~LPS22HB_FIFO_FULL_MASK;
00757   tmp |= ((uint8_t)status)<<LPS22HB_FIFO_FULL_BIT;
00758 
00759   if(LPS22HB_write_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp))
00760     return LPS22HB_ERROR;
00761 
00762   return LPS22HB_OK;
00763 }
00764 
00765 
00766 
00767 /**
00768 * @brief   Enable AutoRifP function
00769 * @detail When this function is enabled, an internal register is set with the current pressure values
00770 *         and the content is subtracted from the pressure output value and result is used for the interrupt generation.
00771 *               the AutoRifP is slf creared.
00772 * @param  *handle Device handle.
00773 * @retval  Error Code [LPS22HB_ERROR, LPS22HB_OK]
00774 */
00775 LPS22HB_Error_et LPS22HB_Set_AutoRifP(void *handle)
00776 {
00777   uint8_t tmp;
00778 
00779   if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp))
00780     return LPS22HB_ERROR;
00781 
00782   tmp |= ((uint8_t)LPS22HB_AUTORIFP_MASK);
00783 
00784   if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp))
00785     return LPS22HB_ERROR;
00786 
00787   return LPS22HB_OK;
00788 }
00789 
00790 /**
00791 * @brief   Disable AutoRifP function
00792 * @detail  the RESET_ARP bit is used to disable the AUTORIFP function. This bis i is selfdleared
00793 * @param  *handle Device handle.
00794 * @retval  Error Code [LPS22HB_ERROR, LPS22HB_OK]
00795 */
00796 LPS22HB_Error_et LPS22HB_ResetAutoRifP(void *handle)
00797 {
00798   uint8_t tmp;
00799 
00800   if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp))
00801     return LPS22HB_ERROR;
00802 
00803 
00804   tmp |= ((uint8_t)LPS22HB_RESET_ARP_MASK);
00805 
00806   if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp))
00807     return LPS22HB_ERROR;
00808 
00809   return LPS22HB_OK;
00810 }
00811 
00812 
00813 /*
00814 * @brief  Set AutoZero Function bit
00815 * @detail When set to ‘1’, the actual pressure output is copied in the REF_P reg (@0x15..0x17)
00816 * @param  *handle Device handle.
00817 * @retval  Error Code [LPS22HB_ERROR, LPS22HB_OK]
00818 */
00819 LPS22HB_Error_et LPS22HB_Set_AutoZeroFunction(void *handle)
00820 {
00821   uint8_t tmp;
00822 
00823   if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp))
00824     return LPS22HB_ERROR;
00825 
00826   tmp |= LPS22HB_AUTOZERO_MASK;
00827 
00828   if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp))
00829     return LPS22HB_ERROR;
00830 
00831   return LPS22HB_OK;
00832 }
00833 
00834 
00835 /*
00836 * @brief  Set ResetAutoZero Function bit
00837 * @details REF_P reg (@0x015..17) set pressure reference to default value RPDS reg (0x18/19).
00838 * @param  *handle Device handle.
00839 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK]
00840 */
00841 LPS22HB_Error_et LPS22HB_ResetAutoZeroFunction(void *handle)
00842 {
00843   uint8_t tmp;
00844 
00845   if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp))
00846     return LPS22HB_ERROR;
00847 
00848   /* Set the RESET_AZ bit*/
00849   /* RESET_AZ is self cleared*/
00850   tmp |= LPS22HB_RESET_AZ_MASK;
00851 
00852   if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp))
00853     return LPS22HB_ERROR;
00854 
00855 
00856   return LPS22HB_OK;
00857 }
00858 
00859 
00860 /**
00861 * @brief  Enable/ Disable the computing of differential pressure output (Interrupt Generation)
00862 * @param  *handle Device handle.
00863 * @param  LPS22HB_ENABLE,LPS22HB_DISABLE
00864 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK]
00865 */
00866 LPS22HB_Error_et LPS22HB_Set_InterruptDifferentialGeneration(void *handle, LPS22HB_State_et diff_en)
00867 {
00868   uint8_t tmp;
00869 
00870   LPS22HB_assert_param(IS_LPS22HB_State(diff_en));
00871 
00872   if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp))
00873     return LPS22HB_ERROR;
00874 
00875   tmp &= ~LPS22HB_DIFF_EN_MASK;
00876   tmp |= ((uint8_t)diff_en)<<LPS22HB_DIFF_EN_BIT;
00877 
00878   if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp))
00879     return LPS22HB_ERROR;
00880 
00881   return LPS22HB_OK;
00882 }
00883 
00884 
00885 /**
00886 * @brief  Get the DIFF_EN bit value
00887 * @param  *handle Device handle.
00888 * @param  buffer to empty with the read value of DIFF_EN bit
00889 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK]
00890 */
00891 LPS22HB_Error_et LPS22HB_Get_InterruptDifferentialGeneration(void *handle, LPS22HB_State_et* diff_en)
00892 {
00893   uint8_t tmp;
00894 
00895   if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp))
00896     return LPS22HB_ERROR;
00897 
00898   *diff_en= (LPS22HB_State_et)((tmp & LPS22HB_DIFF_EN_MASK)>>LPS22HB_DIFF_EN_BIT);
00899 
00900   return LPS22HB_OK;
00901 }
00902 
00903 /**
00904 * @brief  Latch Interrupt request to the INT_SOURCE register.
00905 * @param  *handle Device handle.
00906 * @param  LPS22HB_ENABLE/LPS22HB_DISABLE
00907 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK]
00908 */
00909 LPS22HB_Error_et LPS22HB_LatchInterruptRequest(void *handle, LPS22HB_State_et status)
00910 {
00911   uint8_t tmp;
00912 
00913  LPS22HB_assert_param(IS_LPS22HB_State(status));
00914 
00915   if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp))
00916     return LPS22HB_ERROR;
00917 
00918   tmp &= ~LPS22HB_LIR_MASK;
00919   tmp |= (((uint8_t)status)<<LPS22HB_LIR_BIT);
00920 
00921   if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp))
00922     return LPS22HB_ERROR;
00923 
00924   return LPS22HB_OK;
00925 }
00926 
00927 
00928 
00929   /**
00930 * @brief  Enable\Disable Interrupt Generation on differential pressure Low event
00931 * @param  *handle Device handle.
00932 * @param  LPS22HB_ENABLE/LPS22HB_DISABLE
00933 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK]
00934 */
00935 LPS22HB_Error_et LPS22HB_Set_PLE(void *handle, LPS22HB_State_et status)
00936 {
00937   uint8_t tmp;
00938 
00939   LPS22HB_assert_param(IS_LPS22HB_State(status));
00940 
00941   if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp))
00942     return LPS22HB_ERROR;
00943 
00944   tmp &= ~LPS22HB_PLE_MASK;
00945   tmp |= (((uint8_t)status)<<LPS22HB_PLE_BIT);
00946 
00947   if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp))
00948     return LPS22HB_ERROR;
00949 
00950   return LPS22HB_OK;
00951 }
00952 
00953 /**
00954 * @brief  Enable\Disable Interrupt Generation on differential pressure High event
00955 * @param  *handle Device handle.
00956 * @param  LPS22HB_ENABLE/LPS22HB_DISABLE
00957 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK]
00958 */
00959 LPS22HB_Error_et LPS22HB_Set_PHE(void *handle, LPS22HB_State_et status)
00960 {
00961   uint8_t tmp;
00962 
00963   LPS22HB_assert_param(IS_LPS22HB_State(status));
00964 
00965   if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp))
00966     return LPS22HB_ERROR;
00967 
00968   tmp &= ~LPS22HB_PHE_MASK;
00969   tmp |= (((uint8_t)status)<<LPS22HB_PHE_BIT);
00970 
00971   if(LPS22HB_write_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp))
00972     return LPS22HB_ERROR;
00973 
00974   return LPS22HB_OK;
00975 }
00976 
00977 /**
00978 * @brief   Get the Interrupt Generation on differential pressure status event and the Boot Status.
00979 * @detail  The INT_SOURCE register is cleared by reading it.
00980 * @param  *handle Device handle.
00981 * @param   Status Event Flag: BOOT, PH,PL,IA
00982 * @retval  Error Code [LPS22HB_ERROR, LPS22HB_OK]
00983 */
00984 LPS22HB_Error_et LPS22HB_Get_InterruptDifferentialEventStatus(void *handle, LPS22HB_InterruptDiffStatus_st* interruptsource)
00985 {
00986   uint8_t tmp;
00987 
00988   if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_SOURCE_REG, 1, &tmp))
00989     return LPS22HB_ERROR;
00990 
00991   interruptsource->PH  = (uint8_t)(tmp & LPS22HB_PH_MASK);
00992   interruptsource->PL  = (uint8_t)((tmp & LPS22HB_PL_MASK)>>LPS22HB_PL_BIT);
00993   interruptsource->IA  = (uint8_t)((tmp & LPS22HB_IA_MASK)>>LPS22HB_IA_BIT);
00994   interruptsource->BOOT = (uint8_t)((tmp & LPS22HB_BOOT_STATUS_MASK)>>LPS22HB_BOOT_STATUS_BIT);
00995 
00996   return LPS22HB_OK;
00997 }
00998 
00999 /**
01000 * @brief  Get the status of Pressure and Temperature data
01001 * @param  *handle Device handle.
01002 * @param  Data Status Flag:  TempDataAvailable, TempDataOverrun, PressDataAvailable, PressDataOverrun
01003 * @retval  Error Code [LPS22HB_ERROR, LPS22HB_OK]
01004 */
01005 LPS22HB_Error_et LPS22HB_Get_DataStatus(void *handle, LPS22HB_DataStatus_st* datastatus)
01006 {
01007   uint8_t tmp;
01008 
01009   if(LPS22HB_read_reg(handle, LPS22HB_STATUS_REG, 1, &tmp))
01010     return LPS22HB_ERROR;
01011 
01012   datastatus->PressDataAvailable  = (uint8_t)(tmp & LPS22HB_PDA_MASK);
01013   datastatus->TempDataAvailable  = (uint8_t)((tmp & LPS22HB_TDA_MASK)>>LPS22HB_PDA_BIT);
01014   datastatus->TempDataOverrun  = (uint8_t)((tmp & LPS22HB_TOR_MASK)>>LPS22HB_TOR_BIT);
01015   datastatus->PressDataOverrun  = (uint8_t)((tmp & LPS22HB_POR_MASK)>>LPS22HB_POR_BIT);
01016 
01017   return LPS22HB_OK;
01018 }
01019 
01020 
01021 
01022 /**
01023 * @brief  Get the LPS22HB raw presure value
01024 * @detail   The data are expressed as PRESS_OUT_H/_L/_XL in 2’s complement.
01025             Pout(hPA)=PRESS_OUT / 4096
01026 * @param  *handle Device handle.
01027 * @param  The buffer to empty with the pressure raw value
01028 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK]
01029 */
01030 LPS22HB_Error_et LPS22HB_Get_RawPressure(void *handle, int32_t *raw_press)
01031 {
01032   uint8_t buffer[3];
01033   uint32_t tmp = 0;
01034   uint8_t i;
01035 
01036   if(LPS22HB_read_reg(handle, LPS22HB_PRESS_OUT_XL_REG, 3, buffer))
01037     return LPS22HB_ERROR;
01038 
01039   /* Build the raw data */
01040   for(i=0; i<3; i++)
01041     tmp |= (((uint32_t)buffer[i]) << (8*i));
01042 
01043   /* convert the 2's complement 24 bit to 2's complement 32 bit */
01044   if(tmp & 0x00800000)
01045     tmp |= 0xFF000000;
01046 
01047   *raw_press = ((int32_t)tmp);
01048 
01049   return LPS22HB_OK;
01050 }
01051 
01052 /**
01053 * @brief    Get the LPS22HB Pressure value in hPA.
01054 * @detail   The data are expressed as PRESS_OUT_H/_L/_XL in 2’s complement.
01055             Pout(hPA)=PRESS_OUT / 4096
01056 * @param  *handle Device handle.
01057 * @param      The buffer to empty with the pressure value that must be divided by 100 to get the value in hPA
01058 * @retval   Error Code [LPS22HB_ERROR, LPS22HB_OK]
01059 */
01060 LPS22HB_Error_et LPS22HB_Get_Pressure(void *handle, int32_t* Pout)
01061 {
01062   int32_t raw_press;
01063 
01064   if(LPS22HB_Get_RawPressure(handle, &raw_press))
01065     return LPS22HB_ERROR;
01066 
01067   *Pout = (raw_press*100)/4096;
01068 
01069   return LPS22HB_OK;
01070 }
01071 
01072 /**
01073 * @brief    Get the Raw Temperature value.
01074 * @detail   Temperature data are expressed as TEMP_OUT_H&TEMP_OUT_L as 2’s complement number.
01075 *            Tout(degC)=TEMP_OUT/100
01076 * @param  *handle Device handle.
01077 * @param     Buffer to empty with the temperature raw tmp.
01078 * @retval   Error Code [LPS22HB_ERROR, LPS22HB_OK]
01079 */
01080 LPS22HB_Error_et LPS22HB_Get_RawTemperature(void *handle, int16_t* raw_data)
01081 {
01082   uint8_t buffer[2];
01083   uint16_t tmp;
01084 
01085   if(LPS22HB_read_reg(handle, LPS22HB_TEMP_OUT_L_REG, 2, buffer))
01086     return LPS22HB_ERROR;
01087 
01088   /* Build the raw tmp */
01089   tmp = (((uint16_t)buffer[1]) << 8) + (uint16_t)buffer[0];
01090 
01091   *raw_data = ((int16_t)tmp);
01092 
01093   return LPS22HB_OK;
01094 }
01095 
01096 
01097 /**
01098 * @brief    Get the Temperature value in °C.
01099 * @detail   Temperature data are expressed as TEMP_OUT_H&TEMP_OUT_L as 2’s complement number.
01100 *           Tout(degC)=TEMP_OUT/100
01101 * @param  *handle Device handle.
01102 * @param Buffer to empty with the temperature value that must be divided by 10 to get the value in °C
01103 * @retval  Error Code [LPS22HB_ERROR, LPS22HB_OK]
01104 */
01105 LPS22HB_Error_et LPS22HB_Get_Temperature(void *handle, int16_t* Tout)
01106 {
01107   int16_t raw_data;
01108 
01109   if(LPS22HB_Get_RawTemperature(handle, &raw_data))
01110     return LPS22HB_ERROR;
01111 
01112   *Tout = (raw_data*10)/100;
01113 
01114   return LPS22HB_OK;
01115 }
01116 
01117 /**
01118 * @brief    Get the threshold value used for pressure interrupt generation (hPA).
01119 * @detail   THS_P=THS_P_H&THS_P_L and is expressed as unsigned number. P_ths(hPA)=(THS_P)/16.
01120 * @param  *handle Device handle.
01121 * @param    Buffer to empty with the pressure threshold in hPA
01122 * @retval   Error Code [LPS22HB_ERROR, LPS22HB_OK]
01123 */
01124 LPS22HB_Error_et LPS22HB_Get_PressureThreshold(void *handle, int16_t* P_ths)
01125 {
01126   uint8_t tempReg[2];
01127 
01128   if(LPS22HB_read_reg(handle, LPS22HB_THS_P_LOW_REG, 2, tempReg))
01129     return LPS22HB_ERROR;
01130 
01131   *P_ths= (((((uint16_t)tempReg[1])<<8) + tempReg[0])/16);
01132 
01133   return LPS22HB_OK;
01134 }
01135 
01136 /**
01137 * @brief    Set the threshold value  used for pressure interrupt generation (hPA).
01138 * @detail   THS_P=THS_P_H&THS_P_L and is expressed as unsigned number. P_ths(hPA)=(THS_P)/16.
01139 * @param  *handle Device handle.
01140 * @param      Pressure threshold in hPA
01141 * @retval   Error Code [LPS22HB_ERROR, LPS22HB_OK]
01142 */
01143 LPS22HB_Error_et LPS22HB_Set_PressureThreshold(void *handle, int16_t P_ths)
01144 {
01145   uint8_t buffer[2];
01146 
01147   buffer[0] = (uint8_t)(16 * P_ths);
01148   buffer[1] = (uint8_t)(((uint16_t)(16 * P_ths))>>8);
01149 
01150   if(LPS22HB_write_reg(handle, LPS22HB_THS_P_LOW_REG, 2, buffer))
01151     return LPS22HB_ERROR;
01152 
01153   return LPS22HB_OK;
01154 }
01155 
01156 /**
01157 * @brief  Set Fifo Mode.
01158 * @param  *handle Device handle.
01159 * @param  Fifo Mode struct
01160 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK]
01161 */
01162 LPS22HB_Error_et LPS22HB_Set_FifoMode(void *handle, LPS22HB_FifoMode_et fifomode)
01163 {
01164   uint8_t tmp;
01165 
01166  LPS22HB_assert_param(IS_LPS22HB_FifoMode(fifomode));
01167 
01168   if(LPS22HB_read_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, &tmp))
01169     return LPS22HB_ERROR;
01170 
01171   tmp &= ~LPS22HB_FIFO_MODE_MASK;
01172   tmp |= (uint8_t)fifomode;
01173 
01174   if(LPS22HB_write_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, &tmp))
01175     return LPS22HB_ERROR;
01176 
01177   return LPS22HB_OK;
01178 }
01179 
01180 /**
01181 * @brief    Get Fifo Mode
01182 * @param  *handle Device handle.
01183 * @param   buffer to empty with fifo mode tmp
01184 * @retval   Error Code [LPS22HB_ERROR, LPS22HB_OK]
01185 */
01186 LPS22HB_Error_et LPS22HB_Get_FifoMode(void *handle, LPS22HB_FifoMode_et* fifomode)
01187 {
01188   uint8_t tmp;
01189 
01190   if(LPS22HB_read_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, &tmp))
01191     return LPS22HB_ERROR;
01192 
01193   tmp &= LPS22HB_FIFO_MODE_MASK;
01194   *fifomode = (LPS22HB_FifoMode_et)tmp;
01195 
01196   return LPS22HB_OK;
01197 }
01198 
01199 /**
01200 * @brief    Set Fifo Watermark Level.
01201 * @param  *handle Device handle.
01202 * @param    Watermark level value [0 31]
01203 * @retval   Error Code [LPS22HB_ERROR, LPS22HB_OK]
01204 */
01205 LPS22HB_Error_et LPS22HB_Set_FifoWatermarkLevel(void *handle, uint8_t wtmlevel)
01206 {
01207   uint8_t tmp;
01208 
01209   LPS22HB_assert_param(IS_LPS22HB_WtmLevel(wtmlevel));
01210 
01211   if(LPS22HB_read_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, &tmp))
01212     return LPS22HB_ERROR;
01213 
01214   tmp &= ~LPS22HB_WTM_POINT_MASK;
01215   tmp |= wtmlevel;
01216 
01217   if(LPS22HB_write_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, &tmp))
01218     return LPS22HB_ERROR;
01219 
01220   return LPS22HB_OK;
01221 }
01222 
01223 /**
01224 * @brief   Get FIFO Watermark Level
01225 * @param  *handle Device handle.
01226 * @param   buffer to empty with watermak level[0,31] value read from sensor
01227 * @retval  Error Code [LPS22HB_ERROR, LPS22HB_OK]
01228 */
01229 LPS22HB_Error_et LPS22HB_Get_FifoWatermarkLevel(void *handle, uint8_t *wtmlevel)
01230 {
01231   if(LPS22HB_read_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, wtmlevel))
01232     return LPS22HB_ERROR;
01233 
01234   *wtmlevel &= LPS22HB_WTM_POINT_MASK;
01235 
01236   return LPS22HB_OK;
01237 }
01238 
01239 /**
01240 * @brief    Get the Fifo Status
01241 * @param  *handle Device handle.
01242 * @param    Status Flag: FIFO_FTH,FIFO_EMPTY,FIFO_FULL,FIFO_OVR and level of the FIFO->FIFO_LEVEL
01243 * @retval   Error Code [LPS22HB_ERROR, LPS22HB_OK]
01244 */
01245 LPS22HB_Error_et LPS22HB_Get_FifoStatus(void *handle, LPS22HB_FifoStatus_st* status)
01246 {
01247   uint8_t tmp;
01248 
01249   if(LPS22HB_read_reg(handle, LPS22HB_STATUS_FIFO_REG, 1, &tmp))
01250     return LPS22HB_ERROR;
01251 
01252   status->FIFO_FTH  = (uint8_t)((tmp & LPS22HB_FTH_FIFO_MASK)>>LPS22HB_FTH_FIFO_BIT);
01253   status->FIFO_OVR =(uint8_t)((tmp & LPS22HB_OVR_FIFO_MASK)>>LPS22HB_OVR_FIFO_BIT);
01254   status->FIFO_LEVEL  = (uint8_t)(tmp & LPS22HB_LEVEL_FIFO_MASK);
01255 
01256   if(status->FIFO_LEVEL  ==LPS22HB_FIFO_EMPTY)
01257     status->FIFO_EMPTY =0x01;
01258   else
01259     status->FIFO_EMPTY =0x00;
01260 
01261   if (status->FIFO_LEVEL  ==LPS22HB_FIFO_FULL)
01262      status->FIFO_FULL =0x01;
01263   else
01264     status->FIFO_FULL =0x00;
01265 
01266 
01267   return LPS22HB_OK;
01268 }
01269 
01270 /**
01271 * @brief  Get the reference pressure after soldering for computing differential pressure (hPA)
01272 * @param  *handle Device handle.
01273 * @param buffer to empty with the he pressure value (hPA)
01274 * @retval  Error Code [LPS22HB_ERROR, LPS22HB_OK]
01275 */
01276 LPS22HB_Error_et LPS22HB_Get_PressureOffsetValue(void *handle, int16_t *pressoffset)
01277 {
01278   uint8_t buffer[2];
01279   int16_t raw_press;
01280 
01281   if(LPS22HB_read_reg(handle, LPS22HB_RPDS_L_REG, 2, buffer))
01282     return LPS22HB_ERROR;
01283 
01284   raw_press = (int16_t)((((uint16_t)buffer[1]) << 8) + (uint16_t)buffer[0]);
01285 
01286   *pressoffset = (raw_press*100)/4096;
01287 
01288   return LPS22HB_OK;
01289 }
01290 
01291 
01292 /**
01293 * @brief  Get the Reference Pressure value
01294 * @detail  It is a 24-bit data added to the sensor output measurement to detect a measured pressure beyond programmed limits.
01295 * @param  *handle Device handle.
01296 * @param  Buffer to empty with reference pressure value
01297 * @retval  Error Code [LPS22HB_ERROR, LPS22HB_OK]
01298 */
01299 LPS22HB_Error_et LPS22HB_Get_ReferencePressure(void *handle, int32_t* RefP)
01300 {
01301   uint8_t buffer[3];
01302   uint32_t tempVal=0;
01303   int32_t raw_press;
01304   uint8_t i;
01305 
01306   if(LPS22HB_read_reg(handle, LPS22HB_REF_P_XL_REG, 3, buffer))
01307     return LPS22HB_ERROR;
01308 
01309   /* Build the raw data */
01310   for(i=0; i<3; i++)
01311     tempVal |= (((uint32_t)buffer[i]) << (8*i));
01312 
01313   /* convert the 2's complement 24 bit to 2's complement 32 bit */
01314   if(tempVal & 0x00800000)
01315     tempVal |= 0xFF000000;
01316 
01317   raw_press =((int32_t)tempVal);
01318   *RefP = (raw_press*100)/4096;
01319 
01320 
01321   return LPS22HB_OK;
01322 }
01323 
01324 
01325 /**
01326 * @brief  Check if the single measurement has completed.
01327 * @param  *handle Device handle.
01328 * @param  the returned value is set to 1, when the measurement is completed
01329 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK]
01330 */
01331 LPS22HB_Error_et LPS22HB_IsMeasurementCompleted(void *handle, uint8_t* Is_Measurement_Completed)
01332 {
01333   uint8_t tmp;
01334   LPS22HB_DataStatus_st datastatus;
01335 
01336   if(LPS22HB_read_reg(handle, LPS22HB_STATUS_REG, 1, &tmp))
01337     return LPS22HB_ERROR;
01338 
01339   datastatus.TempDataAvailable =(uint8_t)((tmp&LPS22HB_TDA_MASK)>>LPS22HB_TDA_BIT);
01340   datastatus.PressDataAvailable = (uint8_t)(tmp&LPS22HB_PDA_MASK);
01341 
01342   *Is_Measurement_Completed=(uint8_t)((datastatus.PressDataAvailable ) & (datastatus.TempDataAvailable ));
01343 
01344   return LPS22HB_OK;
01345 }
01346 
01347 /**
01348 * @brief  Get the values of the last single measurement.
01349 * @param  *handle Device handle.
01350 * @param  Pressure and temperature tmp
01351 * @retval Error Code [LPS22HB_ERROR, LPS22HB_OK]
01352 */
01353 LPS22HB_Error_et LPS22HB_Get_Measurement(void *handle, LPS22HB_MeasureTypeDef_st *Measurement_Value)
01354 {
01355   int16_t Tout;
01356   int32_t Pout;
01357 
01358   if(LPS22HB_Get_Temperature(handle, &Tout))
01359     return LPS22HB_ERROR;
01360 
01361   Measurement_Value->Tout=Tout;
01362 
01363   if(LPS22HB_Get_Pressure(handle, &Pout))
01364     return LPS22HB_ERROR;
01365 
01366   Measurement_Value->Pout=Pout;
01367 
01368   return LPS22HB_OK;
01369 
01370 }
01371 
01372 /**
01373 * @brief  Initialization function for LPS22HB.
01374 *         This function make a memory boot.
01375 *         Init the sensor with a standard basic confifuration.
01376 *         Low Power, ODR 25 Hz, Low Pass Filter disabled; BDU enabled; I2C enabled;
01377 *        NO FIFO; NO Interrupt Enabled.
01378 * @param  *handle Device handle.
01379 * @retval Error code[LPS22HB_ERROR, LPS22HB_OK]
01380 */
01381 LPS22HB_Error_et LPS22HB_Init(void *handle)
01382 {
01383   LPS22HB_ConfigTypeDef_st pLPS22HBInit;
01384 
01385   /* Make LPS22HB Reset and Reboot */
01386   if(LPS22HB_SwResetAndMemoryBoot(handle))
01387     return LPS22HB_ERROR;
01388 
01389  pLPS22HBInit.PowerMode =LPS22HB_LowPower ;
01390  pLPS22HBInit.OutputDataRate =LPS22HB_ODR_25HZ ;
01391  pLPS22HBInit.LowPassFilter =LPS22HB_DISABLE;
01392  pLPS22HBInit.LPF_Cutoff =LPS22HB_ODR_9 ;
01393  pLPS22HBInit.BDU =LPS22HB_BDU_NO_UPDATE ;
01394  pLPS22HBInit.IfAddInc =LPS22HB_ENABLE; //default
01395  pLPS22HBInit.Sim = LPS22HB_SPI_4_WIRE;
01396 
01397  /* Set Generic Configuration*/
01398  if(LPS22HB_Set_GenericConfig(handle, &pLPS22HBInit))
01399    return LPS22HB_ERROR;
01400 
01401   return LPS22HB_OK;
01402 }
01403 
01404 /**
01405 * @brief  De initialization function for LPS22HB.
01406 *         This function make a memory boot and clear the data output flags.
01407 * @param  *handle Device handle.
01408 * @retval Error code[LPS22HB_ERROR, LPS22HB_OK]
01409 */
01410 LPS22HB_Error_et LPS22HB_DeInit(void *handle)
01411 {
01412   LPS22HB_MeasureTypeDef_st Measurement_Value;
01413 
01414   /* Make LPS22HB Reset and Reboot */
01415   if(LPS22HB_SwResetAndMemoryBoot(handle))
01416     return LPS22HB_ERROR;
01417 
01418   /* Dump of data output */
01419   if(LPS22HB_Get_Measurement(handle, &Measurement_Value))
01420     return LPS22HB_ERROR;
01421 
01422   return LPS22HB_OK;
01423 }
01424 
01425 
01426 /**
01427 * @brief   Set Generic Configuration
01428 * @param  *handle Device handle.
01429 * @param   Struct to empty with the chosen values
01430 * @retval  Error code[LPS22HB_ERROR, LPS22HB_OK]
01431 */
01432 LPS22HB_Error_et LPS22HB_Set_GenericConfig(void *handle, LPS22HB_ConfigTypeDef_st* pxLPS22HBInit)
01433 {
01434 
01435   /* Enable Low Current Mode (low Power) or Low Noise Mode*/
01436    if(LPS22HB_Set_PowerMode(handle, pxLPS22HBInit->PowerMode ))
01437     return LPS22HB_ERROR;
01438 
01439   /* Init the Output Data Rate*/
01440   if(LPS22HB_Set_Odr(handle, pxLPS22HBInit->OutputDataRate ))
01441     return LPS22HB_ERROR;
01442 
01443   /* BDU bit is used to inhibit the output registers update between the reading of upper and
01444   lower register parts. In default mode (BDU = ‘0’), the lower and upper register parts are
01445   updated continuously. If it is not sure to read faster than output data rate, it is recommended
01446   to set BDU bit to ‘1’. In this way, after the reading of the lower (upper) register part, the
01447   content of that output registers is not updated until the upper (lower) part is read too.
01448   This feature avoids reading LSB and MSB related to different samples.*/
01449 
01450   if(LPS22HB_Set_Bdu(handle, pxLPS22HBInit->BDU ))
01451     return LPS22HB_ERROR;
01452 
01453   /*Enable/Disale low-pass filter on LPS22HB pressure data*/
01454   if(LPS22HB_Set_LowPassFilter(handle, pxLPS22HBInit->LowPassFilter ))
01455     return LPS22HB_ERROR;
01456 
01457    /* Set low-pass filter cutoff configuration*/
01458   if(LPS22HB_Set_LowPassFilterCutoff(handle, pxLPS22HBInit->LPF_Cutoff ))
01459     return LPS22HB_ERROR;
01460 
01461   /* SIM bit selects the SPI serial interface mode.*/
01462   /* This feature has effect only if SPI interface is used*/
01463 
01464     if(LPS22HB_Set_SpiInterface(handle, pxLPS22HBInit->Sim ))
01465     return LPS22HB_ERROR;
01466 
01467   /*Enable or Disable the Automatic increment register address during a multiple byte access with a serial interface (I2C or SPI)*/
01468   if(LPS22HB_Set_AutomaticIncrementRegAddress(handle, pxLPS22HBInit->IfAddInc ))
01469     return LPS22HB_ERROR;
01470 
01471 
01472   return LPS22HB_OK;
01473 }
01474 
01475 /**
01476 * @brief  Get Generic configuration
01477 * @param  *handle Device handle.
01478 * @param  Struct to empty with configuration values
01479 * @retval Error code[LPS22HB_ERROR, LPS22HB_OK]
01480 */
01481 LPS22HB_Error_et LPS22HB_Get_GenericConfig(void *handle, LPS22HB_ConfigTypeDef_st* pxLPS22HBInit)
01482 {
01483 
01484   uint8_t tmp;
01485 
01486   /*Read LPS22HB_RES_CONF_REG*/
01487  if(LPS22HB_Get_PowerMode(handle, &pxLPS22HBInit->PowerMode ))
01488    return LPS22HB_ERROR;
01489 
01490   /*Read LPS22HB_CTRL_REG1*/
01491   if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG1, 1, &tmp))
01492     return LPS22HB_ERROR;
01493 
01494   pxLPS22HBInit->OutputDataRate = (LPS22HB_Odr_et)(tmp & LPS22HB_ODR_MASK);
01495   pxLPS22HBInit->BDU =(LPS22HB_Bdu_et)(tmp & LPS22HB_BDU_MASK);
01496   pxLPS22HBInit->Sim =(LPS22HB_SPIMode_et)(tmp& LPS22HB_SIM_MASK);
01497   pxLPS22HBInit->LowPassFilter =(LPS22HB_State_et)((tmp& LPS22HB_LPFP_MASK)>>LPS22HB_LPFP_BIT);
01498   pxLPS22HBInit->LPF_Cutoff =(LPS22HB_LPF_Cutoff_et)(tmp& LPS22HB_LPFP_CUTOFF_MASK);
01499 
01500   /*Read LPS22HB_CTRL_REG2*/
01501   if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp))
01502     return LPS22HB_ERROR;
01503 
01504   pxLPS22HBInit->IfAddInc =(LPS22HB_State_et)((tmp& LPS22HB_ADD_INC_MASK)>>LPS22HB_ADD_INC_BIT);
01505 
01506   return LPS22HB_OK;
01507 }
01508 
01509 
01510 /**
01511 * @brief  Set Interrupt configuration
01512 * @param  *handle Device handle.
01513 * @param  Struct holding the configuration values
01514 * @retval  Error code[LPS22HB_ERROR, LPS22HB_OK]
01515 */
01516 LPS22HB_Error_et LPS22HB_Set_InterruptConfig(void *handle, LPS22HB_InterruptTypeDef_st* pLPS22HBInt)
01517 {
01518   /* Enable Low Current Mode (low Power) or Low Noise Mode*/
01519    if(LPS22HB_Set_InterruptActiveLevel(handle, pLPS22HBInt->INT_H_L ))
01520     return LPS22HB_ERROR;
01521 
01522    /* Push-pull/open drain selection on interrupt pads.*/
01523    if(LPS22HB_Set_InterruptOutputType(handle, pLPS22HBInt->PP_OD ))
01524     return LPS22HB_ERROR;
01525 
01526    /* Set Data signal on INT pad control bits.*/
01527    if(LPS22HB_Set_InterruptControlConfig(handle, pLPS22HBInt->OutputSignal_INT ))
01528     return LPS22HB_ERROR;
01529 
01530    /* Enable/Disable Data-ready signal on INT_DRDY pin. */
01531    if(LPS22HB_Set_DRDYInterrupt(handle, pLPS22HBInt->DRDY ))
01532     return LPS22HB_ERROR;
01533 
01534     /* Enable/Disable FIFO overrun interrupt on INT_DRDY pin. */
01535    if(LPS22HB_Set_FIFO_OVR_Interrupt(handle, pLPS22HBInt->FIFO_OVR ))
01536     return LPS22HB_ERROR;
01537 
01538    /* Enable/Disable FIFO Treshold interrupt on INT_DRDY pin. */
01539    if(LPS22HB_Set_FIFO_FTH_Interrupt(handle, pLPS22HBInt->FIFO_FTH ))
01540     return LPS22HB_ERROR;
01541 
01542    /* Enable/Disable FIFO FULL interrupt on INT_DRDY pin. */
01543    if(LPS22HB_Set_FIFO_FULL_Interrupt(handle, pLPS22HBInt->FIFO_FULL ))
01544     return LPS22HB_ERROR;
01545 
01546   /* Latch Interrupt request to the INT_SOURCE register. */
01547     if(LPS22HB_LatchInterruptRequest(handle, pLPS22HBInt->LatchIRQ ))
01548       return LPS22HB_ERROR;
01549 
01550     /* Set the threshold value  used for pressure interrupt generation (hPA). */
01551    if(LPS22HB_Set_PressureThreshold(handle, pLPS22HBInt->THS_threshold ))
01552       return LPS22HB_ERROR;
01553 
01554    /*Enable/Disable  AutoRifP function */
01555   if(pLPS22HBInt->AutoRifP ==LPS22HB_ENABLE){
01556     if(LPS22HB_Set_AutoRifP(handle))
01557       return LPS22HB_ERROR;
01558   }
01559   else{
01560     if(LPS22HB_ResetAutoRifP(handle))
01561       return LPS22HB_ERROR;
01562   }
01563 
01564   /*Enable/Disable AutoZero function*/
01565   if(pLPS22HBInt->AutoZero ==LPS22HB_ENABLE){
01566     if(LPS22HB_Set_AutoZeroFunction(handle))
01567       return LPS22HB_ERROR;
01568   }
01569   else{
01570     if(LPS22HB_ResetAutoZeroFunction(handle))
01571       return LPS22HB_ERROR;
01572   }
01573 
01574 
01575    if(pLPS22HBInt->OutputSignal_INT ==LPS22HB_P_HIGH)
01576    {
01577     /* Enable\Disable Interrupt Generation on differential pressure high event*/
01578       if(LPS22HB_Set_PHE(handle, LPS22HB_ENABLE))
01579         return LPS22HB_ERROR;
01580        if(LPS22HB_Set_InterruptDifferentialGeneration(handle, LPS22HB_ENABLE))
01581           return LPS22HB_ERROR;
01582    }
01583    else  if(pLPS22HBInt->OutputSignal_INT ==LPS22HB_P_LOW)
01584       {
01585     /* Enable Interrupt Generation on differential pressure Loe event*/
01586       if(LPS22HB_Set_PLE(handle, LPS22HB_ENABLE))
01587         return LPS22HB_ERROR;
01588        if(LPS22HB_Set_InterruptDifferentialGeneration(handle, LPS22HB_ENABLE))
01589           return LPS22HB_ERROR;
01590    }
01591     else  if(pLPS22HBInt->OutputSignal_INT ==LPS22HB_P_LOW_HIGH)
01592     {
01593       /* Enable Interrupt Generation on differential pressure high event*/
01594       if(LPS22HB_Set_PHE(handle, LPS22HB_ENABLE))
01595         return LPS22HB_ERROR;
01596     /* Enable\Disable Interrupt Generation on differential pressure Loe event*/
01597       if(LPS22HB_Set_PLE(handle, LPS22HB_ENABLE))
01598         return LPS22HB_ERROR;
01599        if(LPS22HB_Set_InterruptDifferentialGeneration(handle, LPS22HB_ENABLE))
01600           return LPS22HB_ERROR;
01601    }
01602    else
01603    {
01604       if(LPS22HB_Set_InterruptDifferentialGeneration(handle, LPS22HB_DISABLE))
01605           return LPS22HB_ERROR;
01606       /* Disable Interrupt Generation on differential pressure High event*/
01607       if(LPS22HB_Set_PHE(handle, LPS22HB_DISABLE))
01608         return LPS22HB_ERROR;
01609      /* Disable Interrupt Generation on differential pressure Low event*/
01610       if(LPS22HB_Set_PLE(handle, LPS22HB_DISABLE))
01611         return LPS22HB_ERROR;
01612    }
01613 
01614   return LPS22HB_OK;
01615 }
01616 
01617 /**
01618 * @brief  LPS22HBGet_InterruptConfig
01619 * @param  *handle Device handle.
01620 * @param  Struct to empty with configuration values
01621 * @retval S Error code[LPS22HB_ERROR, LPS22HB_OK]
01622 */
01623 LPS22HB_Error_et LPS22HB_Get_InterruptConfig(void *handle, LPS22HB_InterruptTypeDef_st* pLPS22HBInt)
01624 {
01625    uint8_t tmp;
01626 
01627   /*Read LPS22HB_CTRL_REG3*/
01628   if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG3, 1, &tmp))
01629     return LPS22HB_ERROR;
01630 
01631   pLPS22HBInt->INT_H_L = (LPS22HB_InterruptActiveLevel_et)(tmp & LPS22HB_INT_H_L_MASK);
01632   pLPS22HBInt->PP_OD =(LPS22HB_OutputType_et)(tmp & LPS22HB_PP_OD_MASK);
01633   pLPS22HBInt->OutputSignal_INT =(LPS22HB_OutputSignalConfig_et)(tmp& LPS22HB_INT_S12_MASK);
01634   pLPS22HBInt->DRDY =(LPS22HB_State_et)((tmp& LPS22HB_DRDY_MASK)>>LPS22HB_DRDY_BIT);
01635   pLPS22HBInt->FIFO_OVR =(LPS22HB_State_et)((tmp& LPS22HB_FIFO_OVR_MASK)>>LPS22HB_FIFO_OVR_BIT);
01636   pLPS22HBInt->FIFO_FTH =(LPS22HB_State_et)((tmp& LPS22HB_FIFO_FTH_MASK)>>LPS22HB_FIFO_FTH_BIT);
01637   pLPS22HBInt->FIFO_FULL =(LPS22HB_State_et)((tmp& LPS22HB_FIFO_FULL_MASK)>>LPS22HB_FIFO_FULL_BIT);
01638 
01639   /*Read LPS22HB_INTERRUPT_CFG_REG*/
01640   if(LPS22HB_read_reg(handle, LPS22HB_INTERRUPT_CFG_REG, 1, &tmp))
01641     return LPS22HB_ERROR;
01642 
01643   pLPS22HBInt->LatchIRQ = (LPS22HB_State_et)((tmp& LPS22HB_LIR_MASK)>>LPS22HB_LIR_BIT);
01644 
01645   if(LPS22HB_Get_PressureThreshold(handle, &pLPS22HBInt->THS_threshold ))
01646     return LPS22HB_ERROR;
01647 
01648   //AutoRifP and Autozero are self clear //
01649   pLPS22HBInt->AutoRifP =LPS22HB_DISABLE;
01650   pLPS22HBInt->AutoZero =LPS22HB_DISABLE;
01651 
01652   return LPS22HB_OK;
01653 }
01654 
01655 /**
01656 * @brief  Set Fifo configuration
01657 * @param  *handle Device handle.
01658 * @param  Struct holding the configuration values
01659 * @retval  Error code[LPS22HB_ERROR, LPS22HB_OK]
01660 */
01661 LPS22HB_Error_et LPS22HB_Set_FifoConfig(void *handle, LPS22HB_FIFOTypeDef_st* pLPS22HBFIFO)
01662 {
01663 
01664    if(pLPS22HBFIFO->FIFO_MODE  == LPS22HB_FIFO_BYPASS_MODE ) {
01665     /* FIFO Disable-> FIFO_EN bit=0 in CTRL_REG2*/
01666     if(LPS22HB_Set_FifoModeUse(handle, LPS22HB_DISABLE))
01667       return LPS22HB_ERROR;
01668     /* Force->Disable FIFO Watermark Level Use*/
01669      if(LPS22HB_Set_FifoWatermarkLevelUse(handle, LPS22HB_DISABLE))
01670           return LPS22HB_ERROR;
01671 
01672     /* Force->Disable FIFO Treshold interrupt on INT_DRDY pin. */
01673      if(LPS22HB_Set_FIFO_FTH_Interrupt(handle, LPS22HB_DISABLE))
01674             return LPS22HB_ERROR;
01675   }
01676   else {
01677     /* FIFO Enable-> FIFO_EN bit=1 in CTRL_REG2*/
01678     if(LPS22HB_Set_FifoModeUse(handle, LPS22HB_ENABLE))
01679       return LPS22HB_ERROR;
01680 
01681       if (pLPS22HBFIFO->WTM_INT ){
01682         /* Enable FIFO Watermark Level Use*/
01683         if(LPS22HB_Set_FifoWatermarkLevelUse(handle, LPS22HB_ENABLE))
01684           return LPS22HB_ERROR;
01685         /*Set Fifo Watermark Level*/
01686         if(LPS22HB_Set_FifoWatermarkLevel(handle, pLPS22HBFIFO->WTM_LEVEL ))
01687           return LPS22HB_ERROR;
01688         /* Force->enable FIFO Treshold interrupt on INT_DRDY pin. */
01689         if(LPS22HB_Set_FIFO_FTH_Interrupt(handle, LPS22HB_ENABLE))
01690             return LPS22HB_ERROR;
01691       }
01692   }
01693 
01694   if(LPS22HB_Set_FifoMode(handle, pLPS22HBFIFO->FIFO_MODE ))
01695     return LPS22HB_ERROR;
01696 
01697   return LPS22HB_OK;
01698 }
01699 
01700 /**
01701 * @brief  Get Fifo configuration
01702 * @param  *handle Device handle.
01703 * @param  Struct to empty with the configuration values
01704 * @retval Error code[LPS22HB_ERROR, LPS22HB_OK]
01705 */
01706 LPS22HB_Error_et LPS22HB_Get_FifoConfig(void *handle, LPS22HB_FIFOTypeDef_st* pLPS22HBFIFO)
01707 {
01708    uint8_t tmp;
01709 
01710   if(LPS22HB_read_reg(handle, LPS22HB_CTRL_FIFO_REG, 1, &tmp))
01711     return LPS22HB_ERROR;
01712 
01713   /*!< Fifo Mode Selection */
01714   pLPS22HBFIFO->FIFO_MODE = (LPS22HB_FifoMode_et)(tmp& LPS22HB_FIFO_MODE_MASK);
01715 
01716   /*!< FIFO threshold/Watermark level selection*/
01717   pLPS22HBFIFO->WTM_LEVEL = (uint8_t)(tmp& LPS22HB_WTM_POINT_MASK);
01718 
01719   if(LPS22HB_read_reg(handle, LPS22HB_CTRL_REG2, 1, &tmp))
01720     return LPS22HB_ERROR;
01721 
01722    /*!< Enable/Disable the watermark interrupt*/
01723   pLPS22HBFIFO->WTM_INT = (LPS22HB_State_et)((tmp& LPS22HB_WTM_EN_MASK)>>LPS22HB_WTM_EN_BIT);
01724 
01725 
01726   return LPS22HB_OK;
01727 }
01728 
01729 #ifdef  USE_FULL_ASSERT_LPS22HB
01730 /**
01731 * @brief  Reports the name of the source file and the source line number
01732 *         where the assert_param error has occurred.
01733 * @param file: pointer to the source file name
01734 * @param line: assert_param error line source number
01735 * @retval : None
01736 */
01737 void LPS22HB_assert_failed(uint8_t* file, uint32_t line)
01738 {
01739   /* User can add his own implementation to report the file name and line number */
01740   printf("Wrong parameters tmp: file %s on line %d\r\n", file, (int)line);
01741 
01742   /* Infinite loop */
01743   while (1)
01744   {
01745   }
01746 }
01747 #endif
01748 
01749 /**
01750 * @}
01751 */
01752 
01753 /**
01754 * @}
01755 */
01756 
01757 /**
01758 * @}
01759 */
01760 
01761 /******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/