Subversion Repositories ScreenTimer

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /**
  2.   ******************************************************************************
  3.   * @file    stm32f0xx_hal_dac.c
  4.   * @author  MCD Application Team
  5.   * @brief   DAC HAL module driver.
  6.   *         This file provides firmware functions to manage the following
  7.   *         functionalities of the Digital to Analog Converter (DAC) peripheral:
  8.   *           + Initialization and de-initialization functions
  9.   *           + IO operation functions
  10.   *           + Peripheral Control functions
  11.   *           + Peripheral State and Errors functions      
  12.   *    
  13.   *
  14.   @verbatim      
  15.   ==============================================================================
  16.                       ##### DAC Peripheral features #####
  17.   ==============================================================================
  18.     [..]        
  19.       *** DAC Channels ***
  20.       ====================  
  21.     [..]  
  22.     STM32F0 devices integrates no, one or two 12-bit Digital Analog Converters.
  23.     STM32F05x devices have one converter (channel1)
  24.     STM32F07x & STM32F09x devices have two converters (i.e. channel1 & channel2)
  25.  
  26.     When 2 converters are present (i.e. channel1 & channel2)  they
  27.     can be used independently or simultaneously (dual mode):
  28.       (#) DAC channel1 with DAC_OUT1 (PA4) as output
  29.       (#) DAC channel2 with DAC_OUT2 (PA5) as output
  30.      
  31.       *** DAC Triggers ***
  32.       ====================
  33.     [..]
  34.     Digital to Analog conversion can be non-triggered using DAC_TRIGGER_NONE
  35.     and DAC_OUT1/DAC_OUT2 is available once writing to DHRx register.
  36.     [..]
  37.     Digital to Analog conversion can be triggered by:
  38.       (#) External event: EXTI Line 9 (any GPIOx_PIN_9) using DAC_TRIGGER_EXT_IT9.
  39.           The used pin (GPIOx_PIN_9) must be configured in input mode.
  40.  
  41.       (#) Timers TRGO: TIM2, TIM3, TIM6, and TIM15
  42.           (DAC_TRIGGER_T2_TRGO, DAC_TRIGGER_T3_TRGO...)
  43.  
  44.       (#) Software using DAC_TRIGGER_SOFTWARE
  45.  
  46.       *** DAC Buffer mode feature ***
  47.       ===============================
  48.       [..]
  49.       Each DAC channel integrates an output buffer that can be used to
  50.       reduce the output impedance, and to drive external loads directly
  51.       without having to add an external operational amplifier.
  52.       To enable, the output buffer use  
  53.       sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
  54.       [..]          
  55.       (@) Refer to the device datasheet for more details about output
  56.           impedance value with and without output buffer.
  57.  
  58.       *** GPIO configurations guidelines ***
  59.       =====================
  60.       [..]
  61.       When a DAC channel is used (ex channel1 on PA4) and the other is not
  62.       (ex channel1 on PA5 is configured in Analog and disabled).
  63.       Channel1 may disturb channel2 as coupling effect.
  64.       Note that there is no coupling on channel2 as soon as channel2 is turned on.
  65.       Coupling on adjacent channel could be avoided as follows:
  66.       when unused PA5 is configured as INPUT PULL-UP or DOWN.
  67.       PA5 is configured in ANALOG just before it is turned on.    
  68.            
  69.        *** DAC wave generation feature ***
  70.        ===================================
  71.        [..]    
  72.        Both DAC channels can be used to generate
  73.          (#) Noise wave
  74.          (#) Triangle wave
  75.            
  76.        *** DAC data format ***
  77.        =======================
  78.        [..]  
  79.        The DAC data format can be:
  80.          (#) 8-bit right alignment using DAC_ALIGN_8B_R
  81.          (#) 12-bit left alignment using DAC_ALIGN_12B_L
  82.          (#) 12-bit right alignment using DAC_ALIGN_12B_R
  83.  
  84.        *** DAC data value to voltage correspondance ***  
  85.        ================================================
  86.        [..]
  87.        The analog output voltage on each DAC channel pin is determined
  88.        by the following equation:
  89.        [..]
  90.        DAC_OUTx = VREF+ * DOR / 4095
  91.        (+) with  DOR is the Data Output Register
  92.        [..]
  93.           VEF+ is the input voltage reference (refer to the device datasheet)
  94.        [..]
  95.         e.g. To set DAC_OUT1 to 0.7V, use
  96.        (+) Assuming that VREF+ = 3.3V, DAC_OUT1 = (3.3 * 868) / 4095 = 0.7V
  97.  
  98.        *** DMA requests  ***
  99.        =====================
  100.        [..]    
  101.        A DMA1 request can be generated when an external trigger (but not
  102.        a software trigger) occurs if DMA1 requests are enabled using
  103.        HAL_DAC_Start_DMA()
  104.        [..]
  105.        DMA1 requests are mapped as following:
  106.          (#) DAC channel1 : mapped on DMA1 channel3 which must be
  107.              already configured
  108.          (#) DAC channel2 : mapped on DMA1 channel4 which must be
  109.              already configured
  110.        
  111.     (@) For Dual mode and specific signal (Triangle and noise) generation please
  112.         refer to Extended Features Driver description        
  113.         STM32F0 devices with one channel (one converting capability) does not
  114.         support Dual mode and specific signal (Triangle and noise) generation.
  115.      
  116.                       ##### How to use this driver #####
  117.   ==============================================================================
  118.     [..]          
  119.       (+) DAC APB clock must be enabled to get write access to DAC
  120.           registers using HAL_DAC_Init()
  121.       (+) Configure DAC_OUTx (DAC_OUT1: PA4, DAC_OUT2: PA5) in analog mode.
  122.       (+) Configure the DAC channel using HAL_DAC_ConfigChannel() function.
  123.       (+) Enable the DAC channel using HAL_DAC_Start() or HAL_DAC_Start_DMA() functions.
  124.  
  125.      *** Polling mode IO operation ***
  126.      =================================
  127.      [..]    
  128.        (+) Start the DAC peripheral using HAL_DAC_Start()
  129.        (+) To read the DAC last data output value, use the HAL_DAC_GetValue() function.
  130.        (+) Stop the DAC peripheral using HAL_DAC_Stop()
  131.        
  132.      *** DMA mode IO operation ***    
  133.      ==============================
  134.      [..]    
  135.        (+) Start the DAC peripheral using HAL_DAC_Start_DMA(), at this stage the user specify the length
  136.            of data to be transferred at each end of conversion
  137.        (+) At the middle of data transfer HAL_DAC_ConvHalfCpltCallbackCh1() or HAL_DACEx_ConvHalfCpltCallbackCh2()  
  138.            function is executed and user can add his own code by customization of function pointer
  139.            HAL_DAC_ConvHalfCpltCallbackCh1() or HAL_DACEx_ConvHalfCpltCallbackCh2()
  140.        (+) At The end of data transfer HAL_DAC_ConvCpltCallbackCh1() or HAL_DACEx_ConvHalfCpltCallbackCh2()  
  141.            function is executed and user can add his own code by customization of function pointer
  142.            HAL_DAC_ConvCpltCallbackCh1() or HAL_DACEx_ConvHalfCpltCallbackCh2()
  143.        (+) In case of transfer Error, HAL_DAC_ErrorCallbackCh1() function is executed and user can
  144.             add his own code by customization of function pointer HAL_DAC_ErrorCallbackCh1
  145.        (+) In case of DMA underrun, DAC interruption triggers and execute internal function HAL_DAC_IRQHandler.
  146.            HAL_DAC_DMAUnderrunCallbackCh1() or HAL_DACEx_DMAUnderrunCallbackCh2()  
  147.            function is executed and user can add his own code by customization of function pointer
  148.            HAL_DAC_DMAUnderrunCallbackCh1() or HAL_DACEx_DMAUnderrunCallbackCh2() and
  149.            add his own code by customization of function pointer HAL_DAC_ErrorCallbackCh1()
  150.        (+) Stop the DAC peripheral using HAL_DAC_Stop_DMA()
  151.  
  152.     *** Callback registration ***
  153.     =============================================
  154.     [..]
  155.       The compilation define  USE_HAL_DAC_REGISTER_CALLBACKS when set to 1
  156.       allows the user to configure dynamically the driver callbacks.
  157.  
  158.     Use Functions HAL_DAC_RegisterCallback() to register a user callback,
  159.       it allows to register following callbacks:
  160.       (+) ConvCpltCallbackCh1     : callback when a half transfer is completed on Ch1.                
  161.       (+) ConvHalfCpltCallbackCh1 : callback when a transfer is completed on Ch1.
  162.       (+) ErrorCallbackCh1        : callback when an error occurs on Ch1.
  163.       (+) DMAUnderrunCallbackCh1  : callback when an error occurs on Ch1.
  164.       (+) ConvCpltCallbackCh2     : callback when a half transfer is completed on Ch2.  
  165.       (+) ConvHalfCpltCallbackCh2 : callback when a transfer is completed on Ch2.        
  166.       (+) ErrorCallbackCh2        : callback when an error occurs on Ch2.                
  167.       (+) DMAUnderrunCallbackCh2  : callback when an error occurs on Ch2.                
  168.       (+) MspInitCallback         : DAC MspInit.  
  169.       (+) MspDeInitCallback       : DAC MspdeInit.
  170.       This function takes as parameters the HAL peripheral handle, the Callback ID
  171.       and a pointer to the user callback function.
  172.  
  173.     Use function HAL_DAC_UnRegisterCallback() to reset a callback to the default
  174.       weak (surcharged) function. It allows to reset following callbacks:
  175.       (+) ConvCpltCallbackCh1     : callback when a half transfer is completed on Ch1.                
  176.       (+) ConvHalfCpltCallbackCh1 : callback when a transfer is completed on Ch1.
  177.       (+) ErrorCallbackCh1        : callback when an error occurs on Ch1.
  178.       (+) DMAUnderrunCallbackCh1  : callback when an error occurs on Ch1.
  179.       (+) ConvCpltCallbackCh2     : callback when a half transfer is completed on Ch2.  
  180.       (+) ConvHalfCpltCallbackCh2 : callback when a transfer is completed on Ch2.        
  181.       (+) ErrorCallbackCh2        : callback when an error occurs on Ch2.                
  182.       (+) DMAUnderrunCallbackCh2  : callback when an error occurs on Ch2.                
  183.       (+) MspInitCallback         : DAC MspInit.  
  184.       (+) MspDeInitCallback       : DAC MspdeInit.
  185.       (+) All Callbacks
  186.       This function) takes as parameters the HAL peripheral handle and the Callback ID.
  187.  
  188.       By default, after the HAL_DAC_Init and if the state is HAL_DAC_STATE_RESET
  189.       all callbacks are reset to the corresponding legacy weak (surcharged) functions.
  190.       Exception done for MspInit and MspDeInit callbacks that are respectively
  191.       reset to the legacy weak (surcharged) functions in the HAL_DAC_Init
  192.       and  HAL_DAC_DeInit only when these callbacks are null (not registered beforehand).
  193.       If not, MspInit or MspDeInit are not null, the HAL_DAC_Init and HAL_DAC_DeInit
  194.       keep and use the user MspInit/MspDeInit callbacks (registered beforehand)
  195.  
  196.       Callbacks can be registered/unregistered in READY state only.
  197.       Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
  198.       in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
  199.       during the Init/DeInit.
  200.       In that case first register the MspInit/MspDeInit user callbacks
  201.       using HAL_DAC_RegisterCallback before calling HAL_DAC_DeInit
  202.       or HAL_DAC_Init function.
  203.  
  204.       When The compilation define USE_HAL_DAC_REGISTER_CALLBACKS is set to 0 or
  205.       not defined, the callback registering feature is not available
  206.       and weak (surcharged) callbacks are used.
  207.  
  208.      *** DAC HAL driver macros list ***
  209.      =============================================
  210.      [..]
  211.        Below the list of most used macros in DAC HAL driver.
  212.        
  213.       (+) __HAL_DAC_ENABLE : Enable the DAC peripheral
  214.       (+) __HAL_DAC_DISABLE : Disable the DAC peripheral
  215.       (+) __HAL_DAC_CLEAR_FLAG: Clear the DAC's pending flags
  216.       (+) __HAL_DAC_GET_FLAG: Get the selected DAC's flag status
  217.      
  218.      [..]
  219.       (@) You can refer to the DAC HAL driver header file for more useful macros  
  220.    
  221.  @endverbatim    
  222.   ******************************************************************************
  223.   * @attention
  224.   *
  225.   * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  226.   * All rights reserved.</center></h2>
  227.   *
  228.   * This software component is licensed by ST under BSD 3-Clause license,
  229.   * the "License"; You may not use this file except in compliance with the
  230.   * License. You may obtain a copy of the License at:
  231.   *                        opensource.org/licenses/BSD-3-Clause
  232.   *
  233.   ******************************************************************************
  234.   */
  235.  
  236.  
  237. /* Includes ------------------------------------------------------------------*/
  238. #include "stm32f0xx_hal.h"
  239.  
  240. /** @addtogroup STM32F0xx_HAL_Driver
  241.   * @{
  242.   */
  243.  
  244. #ifdef HAL_DAC_MODULE_ENABLED
  245.  
  246. #if defined (DAC1)
  247.  
  248. /** @defgroup DAC DAC
  249.   * @brief DAC driver modules
  250.   * @{
  251.   */
  252.  
  253. /* Private typedef -----------------------------------------------------------*/
  254. /* Private define ------------------------------------------------------------*/
  255. /* Private macro -------------------------------------------------------------*/
  256. /** @defgroup DAC_Private_Macros DAC Private Macros
  257.   * @{
  258.   */
  259. /**
  260.   * @}
  261.   */
  262.  
  263. /* Private variables ---------------------------------------------------------*/
  264. /* Private function prototypes -----------------------------------------------*/
  265. /** @defgroup DAC_Private_Functions DAC Private Functions
  266.   * @{
  267.   */
  268. /**
  269.   * @}
  270.   */
  271.  
  272. /* Exported functions -------------------------------------------------------*/
  273.  
  274. /** @defgroup DAC_Exported_Functions DAC Exported Functions
  275.   * @{
  276.   */
  277.  
  278. /** @defgroup DAC_Exported_Functions_Group1 Initialization and de-initialization functions
  279.  *  @brief    Initialization and Configuration functions
  280.  *
  281. @verbatim    
  282.   ==============================================================================
  283.               ##### Initialization and de-initialization functions #####
  284.   ==============================================================================
  285.     [..]  This section provides functions allowing to:
  286.       (+) Initialize and configure the DAC.
  287.       (+) De-initialize the DAC.
  288.          
  289. @endverbatim
  290.   * @{
  291.   */
  292.  
  293. /**
  294.   * @brief  Initialize the DAC peripheral according to the specified parameters
  295.   *         in the DAC_InitStruct and initialize the associated handle.
  296.   * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
  297.   *         the configuration information for the specified DAC.
  298.   * @retval HAL status
  299.   */
  300. HAL_StatusTypeDef HAL_DAC_Init(DAC_HandleTypeDef* hdac)
  301. {
  302.   /* Check DAC handle */
  303.   if(hdac == NULL)
  304.   {
  305.      return HAL_ERROR;
  306.   }
  307.   /* Check the parameters */
  308.   assert_param(IS_DAC_ALL_INSTANCE(hdac->Instance));
  309.  
  310.   if (hdac->State == HAL_DAC_STATE_RESET)
  311.   {
  312. #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
  313.     /* Init the DAC Callback settings */
  314.     hdac->ConvCpltCallbackCh1           = HAL_DAC_ConvCpltCallbackCh1;
  315.     hdac->ConvHalfCpltCallbackCh1       = HAL_DAC_ConvHalfCpltCallbackCh1;
  316.     hdac->ErrorCallbackCh1              = HAL_DAC_ErrorCallbackCh1;
  317.     hdac->DMAUnderrunCallbackCh1        = HAL_DAC_DMAUnderrunCallbackCh1;
  318.  
  319.     hdac->ConvCpltCallbackCh2           = HAL_DACEx_ConvCpltCallbackCh2;
  320.     hdac->ConvHalfCpltCallbackCh2       = HAL_DACEx_ConvHalfCpltCallbackCh2;
  321.     hdac->ErrorCallbackCh2              = HAL_DACEx_ErrorCallbackCh2;
  322.     hdac->DMAUnderrunCallbackCh2        = HAL_DACEx_DMAUnderrunCallbackCh2;
  323.  
  324.     if (hdac->MspInitCallback == NULL)
  325.     {
  326.       hdac->MspInitCallback             = HAL_DAC_MspInit;
  327.     }
  328. #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
  329.  
  330.     /* Allocate lock resource and initialize it */
  331.     hdac->Lock = HAL_UNLOCKED;
  332.  
  333. #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
  334.     /* Init the low level hardware */
  335.     hdac->MspInitCallback(hdac);
  336. #else
  337.     /* Init the low level hardware */
  338.     HAL_DAC_MspInit(hdac);
  339. #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
  340.   }
  341.  
  342.   /* Initialize the DAC state*/
  343.   hdac->State = HAL_DAC_STATE_BUSY;
  344.  
  345.   /* Set DAC error code to none */
  346.   hdac->ErrorCode = HAL_DAC_ERROR_NONE;
  347.  
  348.   /* Initialize the DAC state*/
  349.   hdac->State = HAL_DAC_STATE_READY;
  350.  
  351.   /* Return function status */
  352.   return HAL_OK;
  353. }
  354.  
  355. /**
  356.   * @brief  Deinitialize the DAC peripheral registers to their default reset values.
  357.   * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
  358.   *         the configuration information for the specified DAC.
  359.   * @retval HAL status
  360.   */
  361. HAL_StatusTypeDef HAL_DAC_DeInit(DAC_HandleTypeDef* hdac)
  362. {
  363.   /* Check DAC handle */
  364.   if(hdac == NULL)
  365.   {
  366.      return HAL_ERROR;
  367.   }
  368.  
  369.   /* Check the parameters */
  370.   assert_param(IS_DAC_ALL_INSTANCE(hdac->Instance));
  371.  
  372.   /* Change DAC state */
  373.   hdac->State = HAL_DAC_STATE_BUSY;
  374.  
  375. #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
  376.   if(hdac->MspDeInitCallback == NULL)
  377.   {
  378.     hdac->MspDeInitCallback = HAL_DAC_MspDeInit;
  379.   }
  380.   /* DeInit the low level hardware */
  381.   hdac->MspDeInitCallback(hdac);
  382.  
  383. #else
  384.   /* DeInit the low level hardware */
  385.   HAL_DAC_MspDeInit(hdac);
  386. #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
  387.  
  388.   /* Set DAC error code to none */
  389.   hdac->ErrorCode = HAL_DAC_ERROR_NONE;
  390.  
  391.   /* Change DAC state */
  392.   hdac->State = HAL_DAC_STATE_RESET;
  393.  
  394.   /* Release Lock */
  395.   __HAL_UNLOCK(hdac);
  396.  
  397.   /* Return function status */
  398.   return HAL_OK;
  399. }
  400.  
  401. /**
  402.   * @brief  Initialize the DAC MSP.
  403.   * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
  404.   *         the configuration information for the specified DAC.
  405.   * @retval None
  406.   */
  407. __weak void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac)
  408. {
  409.   /* Prevent unused argument(s) compilation warning */
  410.   UNUSED(hdac);
  411.  
  412.   /* NOTE : This function should not be modified, when the callback is needed,
  413.             the HAL_DAC_MspInit could be implemented in the user file
  414.    */
  415. }
  416.  
  417. /**
  418.   * @brief  DeInitialize the DAC MSP.
  419.   * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
  420.   *         the configuration information for the specified DAC.  
  421.   * @retval None
  422.   */
  423. __weak void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac)
  424. {
  425.   /* Prevent unused argument(s) compilation warning */
  426.   UNUSED(hdac);
  427.  
  428.   /* NOTE : This function should not be modified, when the callback is needed,
  429.             the HAL_DAC_MspDeInit could be implemented in the user file
  430.    */
  431. }
  432.  
  433. /**
  434.   * @}
  435.   */
  436.  
  437. /** @defgroup DAC_Exported_Functions_Group2 IO operation functions
  438.  *  @brief    IO operation functions
  439.  *
  440. @verbatim  
  441.   ==============================================================================
  442.              ##### IO operation functions #####
  443.   ==============================================================================  
  444.     [..]  This section provides functions allowing to:
  445.       (+) Start conversion.
  446.       (+) Stop conversion.
  447.       (+) Start conversion and enable DMA transfer.
  448.       (+) Stop conversion and disable DMA transfer.
  449.       (+) Set the specified data holding register value for DAC channel.
  450.                      
  451. @endverbatim
  452.   * @{
  453.   */
  454.  
  455. /**
  456.   * @brief  Enables DAC and starts conversion of channel.
  457.   * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
  458.   *         the configuration information for the specified DAC.
  459.   * @param  Channel The selected DAC channel.
  460.   *          This parameter can be one of the following values:
  461.   *            @arg DAC_CHANNEL_1: DAC Channel1 selected
  462.   *            @arg DAC_CHANNEL_2: DAC Channel2 selected
  463.   * @retval HAL status
  464.   */
  465. __weak HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel)
  466. {
  467.   /* Prevent unused argument(s) compilation warning */
  468.   UNUSED(hdac);
  469.   UNUSED(Channel);
  470.  
  471.   /* Note : This function is defined into this file for library reference. */
  472.   /*        Function content is located into file stm32f0xx_hal_dac_ex.c   */
  473.  
  474.   /* Return error status as not implemented here */
  475.   return HAL_ERROR;
  476. }
  477.  
  478. /**
  479.   * @brief  Disables DAC and stop conversion of channel.
  480.   * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
  481.   *         the configuration information for the specified DAC.
  482.   * @param  Channel The selected DAC channel.
  483.   *          This parameter can be one of the following values:
  484.   *            @arg DAC_CHANNEL_1: DAC Channel1 selected
  485.   *            @arg DAC_CHANNEL_2: DAC Channel2 selected  
  486.   * @retval HAL status
  487.   */
  488. HAL_StatusTypeDef HAL_DAC_Stop(DAC_HandleTypeDef* hdac, uint32_t Channel)
  489. {
  490.   /* Check the parameters */
  491.   assert_param(IS_DAC_CHANNEL(Channel));
  492.  
  493.   /* Disable the Peripheral */
  494.   __HAL_DAC_DISABLE(hdac, Channel);
  495.  
  496.   /* Change DAC state */
  497.   hdac->State = HAL_DAC_STATE_READY;
  498.  
  499.   /* Return function status */
  500.   return HAL_OK;
  501. }
  502.  
  503. /**
  504.   * @brief  Enables DAC and starts conversion of channel.
  505.   * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
  506.   *         the configuration information for the specified DAC.
  507.   * @param  Channel The selected DAC channel.
  508.   *          This parameter can be one of the following values:
  509.   *            @arg DAC_CHANNEL_1: DAC Channel1 selected
  510.   *            @arg DAC_CHANNEL_2: DAC Channel2 selected
  511.   * @param  pData The destination peripheral Buffer address.
  512.   * @param  Length The length of data to be transferred from memory to DAC peripheral
  513.   * @param  Alignment Specifies the data alignment for DAC channel.
  514.   *          This parameter can be one of the following values:
  515.   *            @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
  516.   *            @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
  517.   *            @arg DAC_ALIGN_12B_R: 12bit right data alignment selected
  518.   * @retval HAL status
  519.   */
  520. __weak HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t* pData, uint32_t Length, uint32_t Alignment)
  521. {
  522.   /* Prevent unused argument(s) compilation warning */
  523.   UNUSED(hdac);
  524.   UNUSED(Channel);
  525.   UNUSED(pData);
  526.   UNUSED(Length);
  527.   UNUSED(Alignment);
  528.  
  529.   /* Note : This function is defined into this file for library reference. */
  530.   /*        Function content is located into file stm32f0xx_hal_dac_ex.c   */
  531.  
  532.   /* Return error status as not implemented here */
  533.   return HAL_ERROR;
  534. }
  535.  
  536. /**
  537.   * @brief  Disables DAC and stop conversion of channel.
  538.   * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
  539.   *         the configuration information for the specified DAC.
  540.   * @param  Channel The selected DAC channel.
  541.   *          This parameter can be one of the following values:
  542.   *            @arg DAC_CHANNEL_1: DAC Channel1 selected
  543.   *            @arg DAC_CHANNEL_2: DAC Channel2 selected  
  544.   * @retval HAL status
  545.   */
  546. HAL_StatusTypeDef HAL_DAC_Stop_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel)
  547. {
  548.    HAL_StatusTypeDef status = HAL_OK;
  549.    
  550.   /* Check the parameters */
  551.   assert_param(IS_DAC_CHANNEL(Channel));
  552.  
  553.   /* Disable the selected DAC channel DMA request */
  554.     hdac->Instance->CR &= ~(DAC_CR_DMAEN1 << Channel);
  555.    
  556.   /* Disable the Peripheral */
  557.   __HAL_DAC_DISABLE(hdac, Channel);
  558.  
  559.   /* Disable the DMA channel */
  560.   /* Channel1 is used */
  561.   if (Channel == DAC_CHANNEL_1)
  562.   {
  563.     /* Disable the DMA channel */
  564.     status = HAL_DMA_Abort(hdac->DMA_Handle1);  
  565.    
  566.     /* Disable the DAC DMA underrun interrupt */
  567.     __HAL_DAC_DISABLE_IT(hdac, DAC_IT_DMAUDR1);
  568.   }
  569.  
  570. #if defined(DAC_CHANNEL2_SUPPORT)
  571.  
  572.   else /* Channel2 is used */
  573.   {
  574.     /* Disable the DMA channel */
  575.     status = HAL_DMA_Abort(hdac->DMA_Handle2);  
  576.    
  577.     /* Disable the DAC DMA underrun interrupt */
  578.     __HAL_DAC_DISABLE_IT(hdac, DAC_IT_DMAUDR2);
  579.   }
  580. #endif  /* DAC_CHANNEL2_SUPPORT */
  581.  
  582.   /* Check if DMA Channel effectively disabled */
  583.   if (status != HAL_OK)
  584.   {
  585.   /* Update DAC state machine to error */
  586.   hdac->State = HAL_DAC_STATE_ERROR;
  587.   }
  588.   else
  589.   {
  590.   /* Change DAC state */
  591.   hdac->State = HAL_DAC_STATE_READY;
  592.   }
  593.  
  594.   /* Return function status */
  595.   return status;
  596. }
  597.  
  598. /**
  599.   * @brief  Handles DAC interrupt request  
  600.   * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
  601.   *         the configuration information for the specified DAC.
  602.   * @retval None
  603.   */
  604. __weak void HAL_DAC_IRQHandler(DAC_HandleTypeDef* hdac)
  605. {
  606.   /* Prevent unused argument(s) compilation warning */
  607.   UNUSED(hdac);
  608.  
  609.   /* Note : This function is defined into this file for library reference. */
  610.   /*        Function content is located into file stm32f0xx_hal_dac_ex.c   */
  611. }
  612.  
  613. /**
  614.   * @brief  Set the specified data holding register value for DAC channel.
  615.   * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
  616.   *         the configuration information for the specified DAC.
  617.   * @param  Channel The selected DAC channel.
  618.   *          This parameter can be one of the following values:
  619.   *            @arg DAC_CHANNEL_1: DAC Channel1 selected
  620.   *            @arg DAC_CHANNEL_2: DAC Channel2 selected  
  621.   * @param  Alignment Specifies the data alignment.
  622.   *          This parameter can be one of the following values:
  623.   *            @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
  624.   *            @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
  625.   *            @arg DAC_ALIGN_12B_R: 12bit right data alignment selected
  626.   * @param  Data Data to be loaded in the selected data holding register.
  627.   * @retval HAL status
  628.   */
  629. HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data)
  630. {  
  631.   __IO uint32_t tmp = 0;
  632.  
  633.   /* Check the parameters */
  634.   assert_param(IS_DAC_CHANNEL(Channel));
  635.   assert_param(IS_DAC_ALIGN(Alignment));
  636.   assert_param(IS_DAC_DATA(Data));
  637.  
  638.   tmp = (uint32_t)hdac->Instance;
  639.   if(Channel == DAC_CHANNEL_1)
  640.   {
  641.     tmp += DAC_DHR12R1_ALIGNMENT(Alignment);
  642.   }
  643.   else
  644.   {
  645.     tmp += DAC_DHR12R2_ALIGNMENT(Alignment);
  646.   }
  647.  
  648.   /* Set the DAC channel1 selected data holding register */
  649.   *(__IO uint32_t *) tmp = Data;
  650.  
  651.   /* Return function status */
  652.   return HAL_OK;
  653. }
  654.  
  655. /**
  656.   * @brief  Conversion complete callback in non blocking mode for Channel1
  657.   * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
  658.   *         the configuration information for the specified DAC.
  659.   * @retval None
  660.   */
  661. __weak void HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef* hdac)
  662. {
  663.   /* Prevent unused argument(s) compilation warning */
  664.   UNUSED(hdac);
  665.  
  666.   /* NOTE : This function should not be modified, when the callback is needed,
  667.             the HAL_DAC_ConvCpltCallbackCh1 could be implemented in the user file
  668.    */
  669. }
  670.  
  671. /**
  672.   * @brief  Conversion half DMA transfer callback in non-blocking mode for Channel1
  673.   * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
  674.   *         the configuration information for the specified DAC.
  675.   * @retval None
  676.   */
  677. __weak void HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef* hdac)
  678. {
  679.   /* Prevent unused argument(s) compilation warning */
  680.   UNUSED(hdac);
  681.  
  682.   /* NOTE : This function should not be modified, when the callback is needed,
  683.             the HAL_DAC_ConvHalfCpltCallbackCh1 could be implemented in the user file
  684.    */
  685. }
  686.  
  687. /**
  688.   * @brief  Error DAC callback for Channel1.
  689.   * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
  690.   *         the configuration information for the specified DAC.
  691.   * @retval None
  692.   */
  693. __weak void HAL_DAC_ErrorCallbackCh1(DAC_HandleTypeDef *hdac)
  694. {
  695.   /* Prevent unused argument(s) compilation warning */
  696.   UNUSED(hdac);
  697.  
  698.   /* NOTE : This function should not be modified, when the callback is needed,
  699.             the HAL_DAC_ErrorCallbackCh1 could be implemented in the user file
  700.    */
  701. }
  702.  
  703. /**
  704.   * @brief  DMA underrun DAC callback for channel1.
  705.   * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
  706.   *         the configuration information for the specified DAC.
  707.   * @retval None
  708.   */
  709. __weak void HAL_DAC_DMAUnderrunCallbackCh1(DAC_HandleTypeDef *hdac)
  710. {
  711.   /* Prevent unused argument(s) compilation warning */
  712.   UNUSED(hdac);
  713.  
  714.   /* NOTE : This function should not be modified, when the callback is needed,
  715.             the HAL_DAC_DMAUnderrunCallbackCh1 could be implemented in the user file
  716.    */
  717. }
  718.  
  719. /**
  720.   * @}
  721.   */
  722.  
  723. /** @defgroup DAC_Exported_Functions_Group3 Peripheral Control functions
  724.  *  @brief    Peripheral Control functions
  725.  *
  726. @verbatim
  727.   ==============================================================================
  728.              ##### Peripheral Control functions #####
  729.   ==============================================================================  
  730.     [..]  This section provides functions allowing to:
  731.       (+) Configure channels.
  732.       (+) Get result of conversion.
  733.      
  734. @endverbatim
  735.   * @{
  736.   */
  737.  
  738. /**
  739.   * @brief  Returns the last data output value of the selected DAC channel.
  740.   * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
  741.   *         the configuration information for the specified DAC.
  742.   * @param  Channel The selected DAC channel.
  743.   *          This parameter can be one of the following values:
  744.   *            @arg DAC_CHANNEL_1: DAC Channel1 selected
  745.   *            @arg DAC_CHANNEL_2: DAC Channel2 selected
  746.   * @retval The selected DAC channel data output value.
  747.   */
  748. __weak uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef* hdac, uint32_t Channel)
  749. {
  750.   /* Prevent unused argument(s) compilation warning */
  751.   UNUSED(hdac);
  752.   UNUSED(Channel);
  753.  
  754.   /* Note : This function is defined into this file for library reference. */
  755.   /*        Function content is located into file stm32f0xx_hal_dac_ex.c   */
  756.  
  757.   /* Return error status as not implemented here */
  758.   return HAL_ERROR;
  759. }
  760.  
  761. /**
  762.   * @brief  Configures the selected DAC channel.
  763.   * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
  764.   *         the configuration information for the specified DAC.
  765.   * @param  sConfig DAC configuration structure.
  766.   * @param  Channel The selected DAC channel.
  767.   *          This parameter can be one of the following values:
  768.   *            @arg DAC_CHANNEL_1: DAC Channel1 selected
  769.   *            @arg DAC_CHANNEL_2: DAC Channel2 selected
  770.   * @retval HAL status
  771.   */
  772. __weak HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel)
  773. {
  774.   /* Prevent unused argument(s) compilation warning */
  775.   UNUSED(hdac);
  776.   UNUSED(sConfig);
  777.   UNUSED(Channel);
  778.  
  779.   /* Note : This function is defined into this file for library reference. */
  780.   /*        Function content is located into file stm32f0xx_hal_dac_ex.c   */
  781.  
  782.   /* Return error status as not implemented here */
  783.   return HAL_ERROR;
  784. }
  785.  
  786. /**
  787.   * @}
  788.   */
  789.  
  790. /** @defgroup DAC_Exported_Functions_Group4 Peripheral State and Errors functions
  791.  *  @brief   Peripheral State and Errors functions
  792.  *
  793. @verbatim  
  794.   ==============================================================================
  795.             ##### Peripheral State and Errors functions #####
  796.   ==============================================================================  
  797.     [..]
  798.     This subsection provides functions allowing to
  799.       (+) Check the DAC state.
  800.       (+) Check the DAC Errors.
  801.        
  802. @endverbatim
  803.   * @{
  804.   */
  805.  
  806. /**
  807.   * @brief  return the DAC handle state
  808.   * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
  809.   *         the configuration information for the specified DAC.
  810.   * @retval HAL state
  811.   */
  812. HAL_DAC_StateTypeDef HAL_DAC_GetState(DAC_HandleTypeDef* hdac)
  813. {
  814.   /* Return DAC handle state */
  815.   return hdac->State;
  816. }
  817.  
  818.  
  819. /**
  820.   * @brief  Return the DAC error code
  821.   * @param  hdac pointer to a DAC_HandleTypeDef structure that contains
  822.   *         the configuration information for the specified DAC.
  823.   * @retval DAC Error Code
  824.   */
  825. uint32_t HAL_DAC_GetError(DAC_HandleTypeDef *hdac)
  826. {
  827.   return hdac->ErrorCode;
  828. }
  829.  
  830. /**
  831.   * @}
  832.   */
  833.  
  834.  
  835. /**
  836.   * @}
  837.   */
  838.  
  839. /** @addtogroup DAC_Exported_Functions
  840.   * @{
  841.   */
  842.  
  843. /** @addtogroup DAC_Exported_Functions_Group1
  844.   * @{
  845.   */
  846. #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
  847. /**
  848.   * @brief  Register a User DAC Callback
  849.   *         To be used instead of the weak (surcharged) predefined callback
  850.   * @param  hdac DAC handle
  851.   * @param  CallbackID ID of the callback to be registered
  852.   *         This parameter can be one of the following values:
  853.   *          @arg @ref HAL_DAC_ERROR_INVALID_CALLBACK   DAC Error Callback ID
  854.   *          @arg @ref HAL_DAC_CH1_COMPLETE_CB_ID       DAC CH1 Complete Callback ID
  855.   *          @arg @ref HAL_DAC_CH1_HALF_COMPLETE_CB_ID  DAC CH1 Half Complete Callback ID
  856.   *          @arg @ref HAL_DAC_CH1_ERROR_ID             DAC CH1 Error Callback ID
  857.   *          @arg @ref HAL_DAC_CH1_UNDERRUN_CB_ID       DAC CH1 UnderRun Callback ID
  858.   *          @arg @ref HAL_DAC_CH2_COMPLETE_CB_ID       DAC CH2 Complete Callback ID
  859.   *          @arg @ref HAL_DAC_CH2_HALF_COMPLETE_CB_ID  DAC CH2 Half Complete Callback ID
  860.   *          @arg @ref HAL_DAC_CH2_ERROR_ID             DAC CH2 Error Callback ID
  861.   *          @arg @ref HAL_DAC_CH2_UNDERRUN_CB_ID       DAC CH2 UnderRun Callback ID
  862.   *          @arg @ref HAL_DAC_MSPINIT_CB_ID            DAC MSP Init Callback ID
  863.   *          @arg @ref HAL_DAC_MSPDEINIT_CB_ID          DAC MSP DeInit Callback ID
  864.   *
  865.   * @param  pCallback pointer to the Callback function
  866.   * @retval status
  867.   */
  868. HAL_StatusTypeDef HAL_DAC_RegisterCallback(DAC_HandleTypeDef *hdac, HAL_DAC_CallbackIDTypeDef CallbackID,
  869.                                            pDAC_CallbackTypeDef pCallback)
  870. {
  871.   HAL_StatusTypeDef status = HAL_OK;
  872.  
  873.   if (pCallback == NULL)
  874.   {
  875.     /* Update the error code */
  876.     hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK;
  877.     return HAL_ERROR;
  878.   }
  879.  
  880.   /* Process locked */
  881.   __HAL_LOCK(hdac);
  882.  
  883.   if (hdac->State == HAL_DAC_STATE_READY)
  884.   {
  885.     switch (CallbackID)
  886.     {
  887.     case HAL_DAC_CH1_COMPLETE_CB_ID :
  888.       hdac->ConvCpltCallbackCh1 = pCallback;
  889.       break;
  890.     case HAL_DAC_CH1_HALF_COMPLETE_CB_ID :
  891.       hdac->ConvHalfCpltCallbackCh1 = pCallback;
  892.       break;
  893.     case HAL_DAC_CH1_ERROR_ID :
  894.       hdac->ErrorCallbackCh1 = pCallback;
  895.       break;
  896.     case HAL_DAC_CH1_UNDERRUN_CB_ID :
  897.       hdac->DMAUnderrunCallbackCh1 = pCallback;
  898.       break;
  899.     case HAL_DAC_CH2_COMPLETE_CB_ID :
  900.       hdac->ConvCpltCallbackCh2 = pCallback;
  901.       break;
  902.     case HAL_DAC_CH2_HALF_COMPLETE_CB_ID :
  903.       hdac->ConvHalfCpltCallbackCh2 = pCallback;
  904.       break;
  905.     case HAL_DAC_CH2_ERROR_ID :
  906.       hdac->ErrorCallbackCh2 = pCallback;
  907.       break;
  908.     case HAL_DAC_CH2_UNDERRUN_CB_ID :
  909.       hdac->DMAUnderrunCallbackCh2 = pCallback;
  910.       break;
  911.     case HAL_DAC_MSPINIT_CB_ID :
  912.       hdac->MspInitCallback = pCallback;
  913.       break;
  914.     case HAL_DAC_MSPDEINIT_CB_ID :
  915.       hdac->MspDeInitCallback = pCallback;
  916.       break;
  917.     default :
  918.       /* Update the error code */
  919.       hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK;
  920.       /* update return status */
  921.       status =  HAL_ERROR;
  922.       break;
  923.     }
  924.   }
  925.   else if (hdac->State == HAL_DAC_STATE_RESET)
  926.   {
  927.     switch (CallbackID)
  928.     {
  929.     case HAL_DAC_MSPINIT_CB_ID :
  930.       hdac->MspInitCallback = pCallback;
  931.       break;
  932.     case HAL_DAC_MSPDEINIT_CB_ID :
  933.       hdac->MspDeInitCallback = pCallback;
  934.       break;
  935.     default :
  936.       /* Update the error code */
  937.       hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK;
  938.       /* update return status */
  939.       status =  HAL_ERROR;
  940.       break;
  941.     }
  942.   }
  943.   else
  944.   {
  945.     /* Update the error code */
  946.     hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK;
  947.     /* update return status */
  948.     status =  HAL_ERROR;
  949.   }
  950.  
  951.   /* Release Lock */
  952.   __HAL_UNLOCK(hdac);
  953.   return status;
  954. }
  955.  
  956. /**
  957.   * @brief  Unregister a User DAC Callback
  958.   *         DAC Callback is redirected to the weak (surcharged) predefined callback
  959.   * @param  hdac DAC handle
  960.   * @param  CallbackID ID of the callback to be unregistered
  961.   *         This parameter can be one of the following values:
  962.   *          @arg @ref HAL_DAC_CH1_COMPLETE_CB_ID          DAC CH1 tranfer Complete Callback ID
  963.   *          @arg @ref HAL_DAC_CH1_HALF_COMPLETE_CB_ID     DAC CH1 Half Complete Callback ID
  964.   *          @arg @ref HAL_DAC_CH1_ERROR_ID                DAC CH1 Error Callback ID
  965.   *          @arg @ref HAL_DAC_CH1_UNDERRUN_CB_ID          DAC CH1 UnderRun Callback ID
  966.   *          @arg @ref HAL_DAC_CH2_COMPLETE_CB_ID          DAC CH2 Complete Callback ID
  967.   *          @arg @ref HAL_DAC_CH2_HALF_COMPLETE_CB_ID     DAC CH2 Half Complete Callback ID
  968.   *          @arg @ref HAL_DAC_CH2_ERROR_ID                DAC CH2 Error Callback ID
  969.   *          @arg @ref HAL_DAC_CH2_UNDERRUN_CB_ID          DAC CH2 UnderRun Callback ID
  970.   *          @arg @ref HAL_DAC_MSPINIT_CB_ID               DAC MSP Init Callback ID
  971.   *          @arg @ref HAL_DAC_MSPDEINIT_CB_ID             DAC MSP DeInit Callback ID
  972.   *          @arg @ref HAL_DAC_ALL_CB_ID                   DAC All callbacks
  973.   * @retval status
  974.   */
  975. HAL_StatusTypeDef HAL_DAC_UnRegisterCallback(DAC_HandleTypeDef *hdac, HAL_DAC_CallbackIDTypeDef CallbackID)
  976. {
  977.   HAL_StatusTypeDef status = HAL_OK;
  978.  
  979.   /* Process locked */
  980.   __HAL_LOCK(hdac);
  981.  
  982.   if (hdac->State == HAL_DAC_STATE_READY)
  983.   {
  984.     switch (CallbackID)
  985.     {
  986.     case HAL_DAC_CH1_COMPLETE_CB_ID :
  987.       hdac->ConvCpltCallbackCh1 = HAL_DAC_ConvCpltCallbackCh1;
  988.       break;
  989.     case HAL_DAC_CH1_HALF_COMPLETE_CB_ID :
  990.       hdac->ConvHalfCpltCallbackCh1 = HAL_DAC_ConvHalfCpltCallbackCh1;
  991.       break;
  992.     case HAL_DAC_CH1_ERROR_ID :
  993.       hdac->ErrorCallbackCh1 = HAL_DAC_ErrorCallbackCh1;
  994.       break;
  995.     case HAL_DAC_CH1_UNDERRUN_CB_ID :
  996.       hdac->DMAUnderrunCallbackCh1 = HAL_DAC_DMAUnderrunCallbackCh1;
  997.       break;
  998.     case HAL_DAC_CH2_COMPLETE_CB_ID :
  999.       hdac->ConvCpltCallbackCh2 = HAL_DACEx_ConvCpltCallbackCh2;
  1000.       break;
  1001.     case HAL_DAC_CH2_HALF_COMPLETE_CB_ID :
  1002.       hdac->ConvHalfCpltCallbackCh2 = HAL_DACEx_ConvHalfCpltCallbackCh2;
  1003.       break;
  1004.     case HAL_DAC_CH2_ERROR_ID :
  1005.       hdac->ErrorCallbackCh2 = HAL_DACEx_ErrorCallbackCh2;
  1006.       break;
  1007.     case HAL_DAC_CH2_UNDERRUN_CB_ID :
  1008.       hdac->DMAUnderrunCallbackCh2 = HAL_DACEx_DMAUnderrunCallbackCh2;
  1009.       break;
  1010.     case HAL_DAC_MSPINIT_CB_ID :
  1011.       hdac->MspInitCallback = HAL_DAC_MspInit;
  1012.       break;
  1013.     case HAL_DAC_MSPDEINIT_CB_ID :
  1014.       hdac->MspDeInitCallback = HAL_DAC_MspDeInit;
  1015.       break;
  1016.     case HAL_DAC_ALL_CB_ID :
  1017.       hdac->ConvCpltCallbackCh1 = HAL_DAC_ConvCpltCallbackCh1;
  1018.       hdac->ConvHalfCpltCallbackCh1 = HAL_DAC_ConvHalfCpltCallbackCh1;
  1019.       hdac->ErrorCallbackCh1 = HAL_DAC_ErrorCallbackCh1;
  1020.       hdac->DMAUnderrunCallbackCh1 = HAL_DAC_DMAUnderrunCallbackCh1;
  1021.       hdac->ConvCpltCallbackCh2 = HAL_DACEx_ConvCpltCallbackCh2;
  1022.       hdac->ConvHalfCpltCallbackCh2 = HAL_DACEx_ConvHalfCpltCallbackCh2;
  1023.       hdac->ErrorCallbackCh2 = HAL_DACEx_ErrorCallbackCh2;
  1024.       hdac->DMAUnderrunCallbackCh2 = HAL_DACEx_DMAUnderrunCallbackCh2;
  1025.       hdac->MspInitCallback = HAL_DAC_MspInit;
  1026.       hdac->MspDeInitCallback = HAL_DAC_MspDeInit;
  1027.       break;
  1028.     default :
  1029.       /* Update the error code */
  1030.       hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK;
  1031.       /* update return status */
  1032.       status =  HAL_ERROR;
  1033.       break;
  1034.     }
  1035.   }
  1036.   else if (hdac->State == HAL_DAC_STATE_RESET)
  1037.   {
  1038.     switch (CallbackID)
  1039.     {
  1040.     case HAL_DAC_MSPINIT_CB_ID :
  1041.       hdac->MspInitCallback = HAL_DAC_MspInit;
  1042.       break;
  1043.     case HAL_DAC_MSPDEINIT_CB_ID :
  1044.       hdac->MspDeInitCallback = HAL_DAC_MspDeInit;
  1045.       break;
  1046.     default :
  1047.       /* Update the error code */
  1048.       hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK;
  1049.       /* update return status */
  1050.       status =  HAL_ERROR;
  1051.       break;
  1052.     }
  1053.   }
  1054.   else
  1055.   {
  1056.     /* Update the error code */
  1057.     hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK;
  1058.     /* update return status */
  1059.     status =  HAL_ERROR;
  1060.   }
  1061.  
  1062.   /* Release Lock */
  1063.   __HAL_UNLOCK(hdac);
  1064.   return status;
  1065. }
  1066. #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
  1067.  
  1068. /**
  1069.   * @}
  1070.   */
  1071.  
  1072.  
  1073. /**
  1074.   * @}
  1075.   */
  1076.  
  1077.  
  1078. /**
  1079.   * @}
  1080.   */
  1081. #endif /* DAC1 */
  1082.  
  1083. #endif /* HAL_DAC_MODULE_ENABLED */
  1084.  
  1085. /**
  1086.   * @}
  1087.   */
  1088.  
  1089.  
  1090. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  1091.