Пример #1
0
/**
  * @brief  Deinitializes the DAC peripheral registers to their default reset values.
  * @param  hdac: pointer to a DAC_HandleTypeDef structure that contains
  *         the configuration information for the specified DAC.
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DAC_DeInit(DAC_HandleTypeDef* hdac)
{
    /* Check DAC handle */
    if(hdac == NULL)
    {
        return HAL_ERROR;
    }

    /* Check the parameters */
    assert_param(IS_DAC_ALL_INSTANCE(hdac->Instance));

    /* Change DAC state */
    hdac->State = HAL_DAC_STATE_BUSY;

    /* DeInit the low level hardware */
    HAL_DAC_MspDeInit(hdac);

    /* Set DAC error code to none */
    hdac->ErrorCode = HAL_DAC_ERROR_NONE;

    /* Change DAC state */
    hdac->State = HAL_DAC_STATE_RESET;

    /* Release Lock */
    __HAL_UNLOCK(hdac);

    /* Return function status */
    return HAL_OK;
}
Пример #2
0
/**
  * @brief  Initializes the DAC peripheral according to the specified parameters
  *         in the DAC_InitStruct.
  * @param  hdac: pointer to a DAC_HandleTypeDef structure that contains
  *         the configuration information for the specified DAC.
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_DAC_Init(DAC_HandleTypeDef* hdac)
{
    /* Check DAC handle */
    if(hdac == NULL)
    {
        return HAL_ERROR;
    }
    /* Check the parameters */
    assert_param(IS_DAC_ALL_INSTANCE(hdac->Instance));

    if(hdac->State == HAL_DAC_STATE_RESET)
    {
        /* Allocate lock resource and initialize it */
        hdac->Lock = HAL_UNLOCKED;
        /* Init the low level hardware */
        HAL_DAC_MspInit(hdac);
    }

    /* Initialize the DAC state*/
    hdac->State = HAL_DAC_STATE_BUSY;

    /* Set DAC error code to none */
    hdac->ErrorCode = HAL_DAC_ERROR_NONE;

    /* Initialize the DAC state*/
    hdac->State = HAL_DAC_STATE_READY;

    /* Return function status */
    return HAL_OK;
}
Пример #3
0
/**
  * @brief  De-initialize registers of the selected DAC instance
  *         to their default reset values.
  * @param  DACx DAC instance
  * @retval An ErrorStatus enumeration value:
  *          - SUCCESS: DAC registers are de-initialized
  *          - ERROR: not applicable
  */
ErrorStatus LL_DAC_DeInit(DAC_TypeDef *DACx)
{
  /* Check the parameters */
  assert_param(IS_DAC_ALL_INSTANCE(DACx));
  
  if(DACx == DAC1)
  {
    /* Force reset of DAC clock */
    LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_DAC1);
    
    /* Release reset of DAC clock */
    LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_DAC1);
  }
#if defined(DAC2)
  else
  {
    /* Force reset of DAC clock */
    LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_DAC2);
    
    /* Release reset of DAC clock */
    LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_DAC2);
  }
#endif
  return SUCCESS;
}
/**
  * @brief  De-initialize registers of the selected DAC instance
  *         to their default reset values.
  * @param  DACx DAC instance
  * @retval An ErrorStatus enumeration value:
  *          - SUCCESS: DAC registers are de-initialized
  *          - ERROR: not applicable
  */
ErrorStatus LL_DAC_DeInit(DAC_TypeDef *DACx)
{
  /* Prevent unused argument(s) compilation warning */
  UNUSED(DACx);

  /* Check the parameters */
  assert_param(IS_DAC_ALL_INSTANCE(DACx));
  
  /* Force reset of DAC1 clock */
  LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_DAC1);
  
  /* Release reset of DAC1 clock */
  LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_DAC1);
  return SUCCESS;
}
Пример #5
0
/**
  * @brief  Initialize some features of DAC instance.
  * @note   The setting of these parameters by function @ref LL_DAC_Init()
  *         is conditioned to DAC state:
  *         DAC instance must be disabled.
  * @param  DACx DAC instance
  * @param  DAC_Channel This parameter can be one of the following values:
  *         @arg @ref LL_DAC_CHANNEL_1
  *         @arg @ref LL_DAC_CHANNEL_2 (1)
  *         
  *         (1) On this STM32 serie, parameter not available on all devices.
  *             Refer to device datasheet for channels availability.
  * @param  DAC_InitStruct Pointer to a @ref LL_DAC_InitTypeDef structure
  * @retval An ErrorStatus enumeration value:
  *          - SUCCESS: DAC registers are initialized
  *          - ERROR: DAC registers are not initialized
  */
ErrorStatus LL_DAC_Init(DAC_TypeDef *DACx, uint32_t DAC_Channel, LL_DAC_InitTypeDef *DAC_InitStruct)
{
  ErrorStatus status = SUCCESS;
  
  /* Check the parameters */
  assert_param(IS_DAC_ALL_INSTANCE(DACx));
  assert_param(IS_LL_DAC_CHANNEL(DACx, DAC_Channel));
  assert_param(IS_LL_DAC_TRIGGER_SOURCE(DAC_InitStruct->TriggerSource));
  assert_param(IS_LL_DAC_OUTPUT_BUFFER(DAC_InitStruct->OutputBuffer));
#if defined(DAC_CR_WAVE1)
  assert_param(IS_LL_DAC_WAVE_AUTO_GENER_MODE(DAC_InitStruct->WaveAutoGeneration));
  if (DAC_InitStruct->WaveAutoGeneration != LL_DAC_WAVE_AUTO_GENERATION_NONE)
  {
    assert_param(IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(DAC_InitStruct->WaveAutoGenerationConfig));
  }
#endif
  
  /* Note: Hardware constraint (refer to description of this function)        */
  /*       DAC instance must be disabled.                                     */
  if(LL_DAC_IsEnabled(DACx, DAC_Channel) == 0U)
  {
    /* Configuration of DAC channel:                                          */
    /*  - TriggerSource                                                       */
#if defined(DAC_CR_WAVE1)
    /*  - WaveAutoGeneration                                                  */
#endif
    /*  - OutputBuffer                                                        */
#if defined(DAC_CR_WAVE1)
    if (DAC_InitStruct->WaveAutoGeneration != LL_DAC_WAVE_AUTO_GENERATION_NONE)
    {
      MODIFY_REG(DACx->CR,
                 (  DAC_CR_TSEL1
                  | DAC_CR_WAVE1
                  | DAC_CR_MAMP1
                  | DAC_CR_BOFF1
                 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
                ,
                 (  DAC_InitStruct->TriggerSource
                  | DAC_InitStruct->WaveAutoGeneration
                  | DAC_InitStruct->WaveAutoGenerationConfig
                  | DAC_InitStruct->OutputBuffer
                 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
                );
    }
    else
    {
      MODIFY_REG(DACx->CR,
                 (  DAC_CR_TSEL1
                  | DAC_CR_WAVE1
                  | DAC_CR_BOFF1
                 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
                ,
                 (  DAC_InitStruct->TriggerSource
                  | LL_DAC_WAVE_AUTO_GENERATION_NONE
                  | DAC_InitStruct->OutputBuffer
                 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
                );
    }
#endif
  }
  else
  {
    /* Initialization error: DAC instance is not disabled.                    */
    status = ERROR;
  }
  return status;
}