Exemplo n.º 1
0
/**
 * @brief Set the LPS25HB sensor output data rate
 * @param handle the device handle
 * @param odr the functional output data rate to be set
 * @retval COMPONENT_OK in case of success
 * @retval COMPONENT_ERROR in case of failure
 */
static DrvStatusTypeDef LPS25HB_Set_ODR( DrvContextTypeDef *handle, SensorOdr_t odr )
{

  LPS25HB_Odr_et new_odr;
  
  switch( odr )
  {
    case ODR_LOW:
      new_odr = LPS25HB_ODR_1HZ;
      break;
    case ODR_MID_LOW:
      new_odr = LPS25HB_ODR_12_5HZ;
      break;
    case ODR_MID:
      new_odr = LPS25HB_ODR_25HZ;
      break;
    case ODR_MID_HIGH:
      new_odr = LPS25HB_ODR_25HZ;
      break;
    case ODR_HIGH:
      new_odr = LPS25HB_ODR_25HZ;
      break;
    default:
      return COMPONENT_ERROR;
  }
  
  if ( LPS25HB_Set_Odr( (void *)handle, new_odr ) == LPS25HB_ERROR )
  {
    return COMPONENT_ERROR;
  }
  
  return COMPONENT_OK;
}
Exemplo n.º 2
0
/**
 * @brief Set the LPS25HB sensor output data rate
 * @param handle the device handle
 * @param odr the output data rate value to be set
 * @retval COMPONENT_OK in case of success
 * @retval COMPONENT_ERROR in case of failure
 */
static DrvStatusTypeDef LPS25HB_Set_ODR_Value( DrvContextTypeDef *handle, float odr )
{

  LPS25HB_Odr_et new_odr;
  
  new_odr = ( odr <=  1.0f ) ? LPS25HB_ODR_1HZ
            : ( odr <=  7.0f ) ? LPS25HB_ODR_7HZ
            : ( odr <= 12.5f ) ? LPS25HB_ODR_12_5HZ
            :                    LPS25HB_ODR_25HZ;
            
  if ( LPS25HB_Set_Odr( (void *)handle, new_odr ) == LPS25HB_ERROR )
  {
    return COMPONENT_ERROR;
  }
  
  return COMPONENT_OK;
}
/**
* @brief   Set Generic Configuration
* @param  *handle Device handle.
* @param  LPS25HB Configuration structure
* @retval  Status [LPS25HB_ERROR, LPS25HB_OK]
*/
LPS25HB_Error_et LPS25HB_Set_GenericConfig(void *handle, LPS25HB_ConfigTypeDef_st* pxLPS25HBInit)
{
  /* Step 1. Init REF_P register*/
  /* The REF_P is the Reference Pressure. Its reset tmp is 0x00*/
  /* The REF_P will be set to the defualt RPDS (0x39h) tmp  if Reset_AZ is enabled.*/
  /* The REF_P will be set the actual pressure output if AutoZero is enabled*/
  
  if((pxLPS25HBInit->Reset_AZ) == LPS25HB_ENABLE)
  {
    if(LPS25HB_ResetAZ(handle))
      return LPS25HB_ERROR;
  }
  else if((pxLPS25HBInit->AutoZero) == LPS25HB_ENABLE)
  {
    if(LPS25HB_Set_AutoZeroFunction(handle, LPS25HB_SET))
      return LPS25HB_ERROR;
  }
  
  /* Step 2. Init the Pressure and Temperature Resolution*/
  if(LPS25HB_Set_Avg(handle, pxLPS25HBInit->PressResolution, pxLPS25HBInit->TempResolution))
    return LPS25HB_ERROR;
    
  /* Step 3. Init the Output Data Rate*/
  if(LPS25HB_Set_Odr(handle, pxLPS25HBInit->OutputDataRate))
    return LPS25HB_ERROR;
    
  /*Step 4. BDU bit is used to inhibit the output registers update between the reading of upper and
  lower register parts. In default mode (BDU = ‘0’), the lower and upper register parts are
  updated continuously. If it is not sure to read faster than output data rate, it is recommended
  to set BDU bit to ‘1’. In this way, after the reading of the lower (upper) register part, the
  content of that output registers is not updated until the upper (lower) part is read too.
  This feature avoids reading LSB and MSB related to different samples.*/
  
  if(LPS25HB_Set_Bdu(handle, pxLPS25HBInit->BDU))
    return LPS25HB_ERROR;
    
  /*Step 5. SIM bit selects the SPI serial interface mode.*/
  /* This feature has effect only if SPI interface is used*/
  
  if(LPS25HB_Set_SpiInterface(handle, pxLPS25HBInit->Sim))
    return LPS25HB_ERROR;
    
  return LPS25HB_OK;
}