Subversion Repositories dashGPS

Rev

Rev 2 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /**
  2.   ******************************************************************************
  3.   * @file    stm32f1xx_ll_dac.c
  4.   * @author  MCD Application Team
  5.   * @brief   DAC LL module driver
  6.   ******************************************************************************
  7.   * @attention
  8.   *
  9.   * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  10.   * All rights reserved.</center></h2>
  11.   *
  12.   * This software component is licensed by ST under BSD 3-Clause license,
  13.   * the "License"; You may not use this file except in compliance with the
  14.   * License. You may obtain a copy of the License at:
  15.   *                        opensource.org/licenses/BSD-3-Clause
  16.   *
  17.   ******************************************************************************
  18.   */
  19. #if defined(USE_FULL_LL_DRIVER)
  20.  
  21. /* Includes ------------------------------------------------------------------*/
  22. #include "stm32f1xx_ll_dac.h"
  23. #include "stm32f1xx_ll_bus.h"
  24.  
  25. #ifdef USE_FULL_ASSERT
  26. #include "stm32_assert.h"
  27. #else
  28. #define assert_param(expr) ((void)0U)
  29. #endif
  30.  
  31. /** @addtogroup STM32F1xx_LL_Driver
  32.   * @{
  33.   */
  34.  
  35. #if defined(DAC)
  36.  
  37. /** @addtogroup DAC_LL DAC
  38.   * @{
  39.   */
  40.  
  41. /* Private types -------------------------------------------------------------*/
  42. /* Private variables ---------------------------------------------------------*/
  43. /* Private constants ---------------------------------------------------------*/
  44. /* Private macros ------------------------------------------------------------*/
  45.  
  46. /** @addtogroup DAC_LL_Private_Macros
  47.   * @{
  48.   */
  49. #define IS_LL_DAC_CHANNEL(__DAC_CHANNEL__)                                     \
  50.   (                                                                            \
  51.       ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_1)                                  \
  52.    || ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_2)                                  \
  53.   )
  54.  
  55. #define IS_LL_DAC_TRIGGER_SOURCE(__TRIGGER_SOURCE__)                           \
  56.   (   ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_SOFTWARE)                           \
  57.    || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM3_TRGO)                      \
  58.    || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM15_TRGO)                     \
  59.    || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM2_TRGO)                      \
  60.    || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM4_TRGO)                      \
  61.    || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM5_TRGO)                      \
  62.    || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM6_TRGO)                      \
  63.    || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM7_TRGO)                      \
  64.    || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM8_TRGO)                      \
  65.    || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_EXTI_LINE9)                     \
  66.   )
  67.  
  68. #define IS_LL_DAC_WAVE_AUTO_GENER_MODE(__WAVE_AUTO_GENERATION_MODE__)           \
  69.   (   ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NONE)     \
  70.    || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NOISE)    \
  71.    || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE) \
  72.   )
  73.  
  74. #define IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(__WAVE_AUTO_GENERATION_MODE__, __WAVE_AUTO_GENERATION_CONFIG__)  \
  75.   ( (((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NOISE)                               \
  76.     && (  ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BIT0)                            \
  77.        || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS1_0)                         \
  78.        || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS2_0)                         \
  79.        || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS3_0)                         \
  80.        || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS4_0)                         \
  81.        || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS5_0)                         \
  82.        || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS6_0)                         \
  83.        || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS7_0)                         \
  84.        || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS8_0)                         \
  85.        || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS9_0)                         \
  86.        || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS10_0)                        \
  87.        || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS11_0))                       \
  88.     )                                                                                                     \
  89.   ||(((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE)                            \
  90.     && (  ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1)                              \
  91.        || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_3)                              \
  92.        || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_7)                              \
  93.        || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_15)                             \
  94.        || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_31)                             \
  95.        || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_63)                             \
  96.        || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_127)                            \
  97.        || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_255)                            \
  98.        || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_511)                            \
  99.        || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1023)                           \
  100.        || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_2047)                           \
  101.        || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_4095))                          \
  102.     )                                                                                                     \
  103.   )
  104.  
  105. #define IS_LL_DAC_OUTPUT_BUFFER(__OUTPUT_BUFFER__)                             \
  106.   (   ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_ENABLE)                     \
  107.    || ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_DISABLE)                    \
  108.   )
  109.  
  110. /**
  111.   * @}
  112.   */
  113.  
  114.  
  115. /* Private function prototypes -----------------------------------------------*/
  116.  
  117. /* Exported functions --------------------------------------------------------*/
  118. /** @addtogroup DAC_LL_Exported_Functions
  119.   * @{
  120.   */
  121.  
  122. /** @addtogroup DAC_LL_EF_Init
  123.   * @{
  124.   */
  125.  
  126. /**
  127.   * @brief  De-initialize registers of the selected DAC instance
  128.   *         to their default reset values.
  129.   * @param  DACx DAC instance
  130.   * @retval An ErrorStatus enumeration value:
  131.   *          - SUCCESS: DAC registers are de-initialized
  132.   *          - ERROR: not applicable
  133.   */
  134. ErrorStatus LL_DAC_DeInit(DAC_TypeDef *DACx)
  135. {
  136.   /* Check the parameters */
  137.   assert_param(IS_DAC_ALL_INSTANCE(DACx));
  138.  
  139.   /* Force reset of DAC clock */
  140.   LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_DAC1);
  141.  
  142.   /* Release reset of DAC clock */
  143.   LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_DAC1);
  144.  
  145.   return SUCCESS;
  146. }
  147.  
  148. /**
  149.   * @brief  Initialize some features of DAC channel.
  150.   * @note   @ref LL_DAC_Init() aims to ease basic configuration of a DAC channel.
  151.   *         Leaving it ready to be enabled and output:
  152.   *         a level by calling one of
  153.   *           @ref LL_DAC_ConvertData12RightAligned
  154.   *           @ref LL_DAC_ConvertData12LeftAligned
  155.   *           @ref LL_DAC_ConvertData8RightAligned
  156.   *         or one of the supported autogenerated wave.
  157.   * @note   This function allows configuration of:
  158.   *          - Output mode
  159.   *          - Trigger
  160.   *          - Wave generation
  161.   * @note   The setting of these parameters by function @ref LL_DAC_Init()
  162.   *         is conditioned to DAC state:
  163.   *         DAC channel must be disabled.
  164.   * @param  DACx DAC instance
  165.   * @param  DAC_Channel This parameter can be one of the following values:
  166.   *         @arg @ref LL_DAC_CHANNEL_1
  167.   *         @arg @ref LL_DAC_CHANNEL_2
  168.   * @param  DAC_InitStruct Pointer to a @ref LL_DAC_InitTypeDef structure
  169.   * @retval An ErrorStatus enumeration value:
  170.   *          - SUCCESS: DAC registers are initialized
  171.   *          - ERROR: DAC registers are not initialized
  172.   */
  173. ErrorStatus LL_DAC_Init(DAC_TypeDef *DACx, uint32_t DAC_Channel, LL_DAC_InitTypeDef *DAC_InitStruct)
  174. {
  175.   ErrorStatus status = SUCCESS;
  176.  
  177.   /* Check the parameters */
  178.   assert_param(IS_DAC_ALL_INSTANCE(DACx));
  179.   assert_param(IS_LL_DAC_CHANNEL(DAC_Channel));
  180.   assert_param(IS_LL_DAC_TRIGGER_SOURCE(DAC_InitStruct->TriggerSource));
  181.   assert_param(IS_LL_DAC_OUTPUT_BUFFER(DAC_InitStruct->OutputBuffer));
  182.   assert_param(IS_LL_DAC_WAVE_AUTO_GENER_MODE(DAC_InitStruct->WaveAutoGeneration));
  183.   if (DAC_InitStruct->WaveAutoGeneration != LL_DAC_WAVE_AUTO_GENERATION_NONE)
  184.   {
  185.     assert_param(IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(DAC_InitStruct->WaveAutoGeneration,
  186.                                                   DAC_InitStruct->WaveAutoGenerationConfig));
  187.   }
  188.  
  189.   /* Note: Hardware constraint (refer to description of this function)        */
  190.   /*       DAC instance must be disabled.                                     */
  191.   if (LL_DAC_IsEnabled(DACx, DAC_Channel) == 0U)
  192.   {
  193.     /* Configuration of DAC channel:                                          */
  194.     /*  - TriggerSource                                                       */
  195.     /*  - WaveAutoGeneration                                                  */
  196.     /*  - OutputBuffer                                                        */
  197.     /*  - OutputMode                                                          */
  198.     if (DAC_InitStruct->WaveAutoGeneration != LL_DAC_WAVE_AUTO_GENERATION_NONE)
  199.     {
  200.       MODIFY_REG(DACx->CR,
  201.                  (DAC_CR_TSEL1
  202.                   | DAC_CR_WAVE1
  203.                   | DAC_CR_MAMP1
  204.                   | DAC_CR_BOFF1
  205.                  ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
  206.                  ,
  207.                  (DAC_InitStruct->TriggerSource
  208.                   | DAC_InitStruct->WaveAutoGeneration
  209.                   | DAC_InitStruct->WaveAutoGenerationConfig
  210.                   | DAC_InitStruct->OutputBuffer
  211.                  ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
  212.                 );
  213.     }
  214.     else
  215.     {
  216.       MODIFY_REG(DACx->CR,
  217.                  (DAC_CR_TSEL1
  218.                   | DAC_CR_WAVE1
  219.                   | DAC_CR_BOFF1
  220.                  ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
  221.                  ,
  222.                  (DAC_InitStruct->TriggerSource
  223.                   | LL_DAC_WAVE_AUTO_GENERATION_NONE
  224.                   | DAC_InitStruct->OutputBuffer
  225.                  ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
  226.                 );
  227.     }
  228.   }
  229.   else
  230.   {
  231.     /* Initialization error: DAC instance is not disabled.                    */
  232.     status = ERROR;
  233.   }
  234.   return status;
  235. }
  236.  
  237. /**
  238.   * @brief Set each @ref LL_DAC_InitTypeDef field to default value.
  239.   * @param DAC_InitStruct pointer to a @ref LL_DAC_InitTypeDef structure
  240.   *                       whose fields will be set to default values.
  241.   * @retval None
  242.   */
  243. void LL_DAC_StructInit(LL_DAC_InitTypeDef *DAC_InitStruct)
  244. {
  245.   /* Set DAC_InitStruct fields to default values */
  246.   DAC_InitStruct->TriggerSource            = LL_DAC_TRIG_SOFTWARE;
  247.   DAC_InitStruct->WaveAutoGeneration       = LL_DAC_WAVE_AUTO_GENERATION_NONE;
  248.   /* Note: Parameter discarded if wave auto generation is disabled,           */
  249.   /*       set anyway to its default value.                                   */
  250.   DAC_InitStruct->WaveAutoGenerationConfig = LL_DAC_NOISE_LFSR_UNMASK_BIT0;
  251.   DAC_InitStruct->OutputBuffer             = LL_DAC_OUTPUT_BUFFER_ENABLE;
  252. }
  253.  
  254. /**
  255.   * @}
  256.   */
  257.  
  258. /**
  259.   * @}
  260.   */
  261.  
  262. /**
  263.   * @}
  264.   */
  265.  
  266. #endif /* DAC */
  267.  
  268. /**
  269.   * @}
  270.   */
  271.  
  272. #endif /* USE_FULL_LL_DRIVER */
  273.  
  274. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  275.