Exemple #1
0
/**
  * @brief  DeInitialize the COMP peripheral.
  * @note   Deinitialization cannot be performed if the COMP configuration is locked.
  *         To unlock the configuration, perform a system reset.
  * @param  hcomp  COMP handle
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef *hcomp)
{
  HAL_StatusTypeDef status = HAL_OK;

  /* Check the COMP handle allocation and lock status */
  if((hcomp == NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET))
  {
    status = HAL_ERROR;
  }
  else
  {
    /* Check the parameter */
    assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));

    /* Set COMP_CSR register to reset value */
    WRITE_REG(hcomp->Instance->CSR, COMP_CSR_RESET_VALUE);

    /* DeInit the low level hardware: SYSCFG, GPIO, CLOCK and NVIC */
    HAL_COMP_MspDeInit(hcomp);

    hcomp->State = HAL_COMP_STATE_RESET;
    
    /* Release Lock */
    __HAL_UNLOCK(hcomp);
  }
  
  return status;
}
/**
  * @brief  DeInitializes the COMP peripheral 
  * @note   Deinitialization can't be performed if the COMP configuration is locked.
  *         To unlock the configuration, perform a system reset.
  * @param  hcomp: COMP handle
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef *hcomp)
{
  HAL_StatusTypeDef status = HAL_OK;
  uint32_t regshift = COMP_CSR_COMP1_SHIFT;

  /* Check the COMP handle allocation and lock status */
  if((hcomp == NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET))
  {
    status = HAL_ERROR;
  }
  else
  {
    /* Check the parameter */
    assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));

    /* Set COMP_CSR register to reset value for the corresponding COMP instance */
    if(hcomp->Instance == COMP2)
    {
      regshift = COMP_CSR_COMP2_SHIFT;
    }
    MODIFY_REG(COMP->CSR, 
               COMP_CSR_RESET_PARAMETERS_MASK << regshift, 
               COMP_CSR_RESET_VALUE << regshift);
    
    /* DeInit the low level hardware: SYSCFG, GPIO, CLOCK and NVIC */
    HAL_COMP_MspDeInit(hcomp);

    hcomp->State = HAL_COMP_STATE_RESET;
  }
  
  return status;
}
/**
  * @brief  DeInitializes the COMP peripheral 
  * @note   Deinitialization can't be performed if the COMP configuration is locked.
  *         To unlock the configuration, perform a system reset.
  * @param  hcomp: COMP handle
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef *hcomp)
{
  HAL_StatusTypeDef status = HAL_OK;

  /* Check the COMP handle allocation and lock status */
  if((hcomp == NULL) || ((hcomp->State & COMP_STATE_BIT_LOCK) != RESET))
  {
    status = HAL_ERROR;
  }
  else
  {
    /* Check the parameter */
    assert_param(IS_COMP_ALL_INSTANCE(hcomp->Instance));
    
    /* Reset configuration depending on comparator instance */
    if (hcomp->Instance == COMP1)
    {
      CLEAR_BIT(COMP->CSR , COMP_CSR_400KPD | COMP_CSR_10KPD | COMP_CSR_400KPU | COMP_CSR_10KPU);
    }
    else /* if (hcomp->Instance == COMP2) */
    {
      CLEAR_BIT(COMP->CSR , COMP_CSR_OUTSEL |
                            COMP_CSR_WNDWE  |
                            COMP_CSR_INSEL  |
                            COMP_CSR_SPEED   );
    }
    
    
    /* Restore default state of Routing Interface (RI) switches for           */
    /* comparator non-inverting input.                                        */
    if (hcomp->Init.NonInvertingInput != COMP_NONINVERTINGINPUT_NONE)
    {
      /* Open the I/O analog switch corresponding to comparator               */
      /* non-inverting input selected.                                        */
      __HAL_RI_IOSWITCH_OPEN(hcomp->Init.NonInvertingInput);
    }
    if (hcomp->Instance == COMP1)
    {
      /* Open the analog switch of ADC switch matrix to COMP1 (ADC            */
      /* channel 26: Vcomp)                                                   */
      __HAL_RI_IOSWITCH_OPEN(RI_IOSWITCH_VCOMP);
      
      /* Disable the switch control mode */
      __HAL_RI_SWITCHCONTROLMODE_DISABLE();
    }
  
    
    /* DeInit the low level hardware: SYSCFG, GPIO, CLOCK and NVIC */
    HAL_COMP_MspDeInit(hcomp);

    hcomp->State = HAL_COMP_STATE_RESET;
    
    /* Process unlocked */
    __HAL_UNLOCK(hcomp);
  }
  
  return status;
}