Exemple #1
0
/**
 * @brief Initialize the LPS25HB sensor
 * @param handle the device handle
 * @retval COMPONENT_OK in case of success
 * @retval COMPONENT_ERROR in case of failure
 */
static DrvStatusTypeDef LPS25HB_Init( DrvContextTypeDef *handle )
{

  if ( LPS25HB_Check_WhoAmI( handle ) == COMPONENT_ERROR )
  {
    return COMPONENT_ERROR;
  }
  
  /* Power down the device */
  if ( LPS25HB_DeActivate( (void *)handle ) == LPS25HB_ERROR )
  {
    return COMPONENT_ERROR;
  }
  
  if ( LPS25HB_Set_ODR( handle, ODR_LOW ) == COMPONENT_ERROR )
  {
    return COMPONENT_ERROR;
  }
  
  /* Enable interrupt circuit */
  if ( LPS25HB_Set_InterruptCircuitEnable( (void *)handle, LPS25HB_ENABLE ) == LPS25HB_ERROR )
  {
    return COMPONENT_ERROR;
  }
  
  /* Set block data update mode */
  if ( LPS25HB_Set_Bdu( (void *)handle, LPS25HB_BDU_NO_UPDATE ) == LPS25HB_ERROR )
  {
    return COMPONENT_ERROR;
  }
  
  /* Set SPI mode */
  if ( LPS25HB_Set_SpiInterface( (void *)handle, LPS25HB_SPI_3_WIRE ) == LPS25HB_ERROR )
  {
    return COMPONENT_ERROR;
  }
  
  /* Set internal averaging sample counts for pressure and temperature */
  if ( LPS25HB_Set_Avg( (void *)handle, LPS25HB_AVGP_32, LPS25HB_AVGT_16 ) == LPS25HB_ERROR )
  {
    return COMPONENT_ERROR;
  }
  
  return COMPONENT_OK;
}
/**
* @brief   Enable\Disable Interrupt Generation on differential pressure low and/or high event
* @param  *handle Device handle.
* @param  LPS25HB_DISABLE_INT, LPS25HB_PHE,LPS25HB_PLE,LPS25HB_PLE_PHE
* @retval  Status [LPS25HB_ERROR, LPS25HB_OK]
*/
LPS25HB_Error_et LPS25HB_Set_InterruptDifferentialConfig(void *handle, LPS25HB_InterruptDiffConfig_et config)
{
  uint8_t tmp;
  
  LPS25HB_assert_param(IS_LPS25HB_InterruptDiff(config));
  
  if(LPS25HB_ReadReg(handle, LPS25HB_INTERRUPT_CFG_REG, 1, &tmp))
    return LPS25HB_ERROR;
    
  tmp &= ~(LPS25HB_PL_E_MASK | LPS25HB_PH_E_MASK);
  tmp |= (uint8_t)config;
  if(config != LPS25HB_DISABLE_INT)
  {
    /* Enable DIFF_EN bit in CTRL_REG1 */
    if(LPS25HB_Set_InterruptCircuitEnable(handle, LPS25HB_ENABLE))
      return LPS25HB_ERROR;
  }
  
  if(LPS25HB_WriteReg(handle, LPS25HB_INTERRUPT_CFG_REG, 1, &tmp))
    return LPS25HB_ERROR;
    
  return LPS25HB_OK;
}