TUKS MCU Introductory course / TUKS-COURSE-2-LED
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32l4xx_hal_dac_ex.c Source File

stm32l4xx_hal_dac_ex.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4xx_hal_dac_ex.c
00004   * @author  MCD Application Team
00005   * @version V1.5.1
00006   * @date    31-May-2016
00007   * @brief   DAC HAL module driver.
00008   *          This file provides firmware functions to manage the extended 
00009   *          functionalities of the DAC peripheral.  
00010   *     
00011   *
00012   @verbatim      
00013   ==============================================================================
00014                       ##### How to use this driver #####
00015   ==============================================================================
00016     [..]          
00017       (+) When Dual mode is enabled (i.e. DAC Channel1 and Channel2 are used simultaneously) :
00018           Use HAL_DACEx_DualGetValue() to get digital data to be converted and use
00019           HAL_DACEx_DualSetValue() to set digital value to converted simultaneously in Channel 1 and Channel 2.  
00020       (+) Use HAL_DACEx_TriangleWaveGenerate() to generate Triangle signal.
00021       (+) Use HAL_DACEx_NoiseWaveGenerate() to generate Noise signal.
00022 
00023       (+) HAL_DACEx_SelfCalibrate to calibrate one DAC channel.
00024       (+) HAL_DACEx_SetUserTrimming to set user trimming value.
00025       (+) HAL_DACEx_GetTrimOffset to retrieve trimming value (factory setting 
00026           after reset, user setting if HAL_DACEx_SetUserTrimming have been used 
00027           at least one time after reset).
00028 
00029  @endverbatim    
00030   ******************************************************************************
00031   * @attention
00032   *
00033   * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
00034   *
00035   * Redistribution and use in source and binary forms, with or without modification,
00036   * are permitted provided that the following conditions are met:
00037   *   1. Redistributions of source code must retain the above copyright notice,
00038   *      this list of conditions and the following disclaimer.
00039   *   2. Redistributions in binary form must reproduce the above copyright notice,
00040   *      this list of conditions and the following disclaimer in the documentation
00041   *      and/or other materials provided with the distribution.
00042   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00043   *      may be used to endorse or promote products derived from this software
00044   *      without specific prior written permission.
00045   *
00046   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00047   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00048   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00049   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00050   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00051   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00052   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00053   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00054   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00055   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00056   *
00057   ******************************************************************************
00058   */ 
00059 
00060 
00061 /* Includes ------------------------------------------------------------------*/
00062 #include "stm32l4xx_hal.h"
00063 
00064 /** @addtogroup STM32L4xx_HAL_Driver
00065   * @{
00066   */
00067 
00068 /** @defgroup DACEx DACEx
00069   * @brief DAC Extended HAL module driver
00070   * @{
00071   */ 
00072 
00073 #ifdef HAL_DAC_MODULE_ENABLED
00074 
00075 /* Private typedef -----------------------------------------------------------*/
00076 /* Private define ------------------------------------------------------------*/
00077 /* Private macro -------------------------------------------------------------*/
00078 /* Private variables ---------------------------------------------------------*/
00079 /* Private function prototypes -----------------------------------------------*/
00080 /* Exported functions --------------------------------------------------------*/
00081   
00082 /** @defgroup DACEx_Exported_Functions DACEx Exported Functions
00083   * @{
00084   */
00085 
00086 /** @defgroup DACEx_Exported_Functions_Group2 IO operation functions
00087  *  @brief    Extended IO operation functions 
00088  *
00089 @verbatim   
00090   ==============================================================================
00091                  ##### Extended features functions #####
00092   ==============================================================================  
00093     [..]  This section provides functions allowing to:
00094       (+) Start conversion.
00095       (+) Stop conversion.
00096       (+) Start conversion and enable DMA transfer.
00097       (+) Stop conversion and disable DMA transfer.
00098       (+) Get result of conversion.
00099       (+) Get result of dual mode conversion.
00100                      
00101 @endverbatim
00102   * @{
00103   */
00104 
00105 /**
00106   * @brief  Enable or disable the selected DAC channel wave generation.
00107   * @param  hdac: pointer to a DAC_HandleTypeDef structure that contains
00108   *         the configuration information for the specified DAC.
00109   * @param  Channel: The selected DAC channel. 
00110   *          This parameter can be one of the following values:
00111   *            DAC_CHANNEL_1 / DAC_CHANNEL_2
00112   * @param  Amplitude: Select max triangle amplitude. 
00113   *          This parameter can be one of the following values:
00114   *            @arg DAC_TRIANGLEAMPLITUDE_1: Select max triangle amplitude of 1
00115   *            @arg DAC_TRIANGLEAMPLITUDE_3: Select max triangle amplitude of 3
00116   *            @arg DAC_TRIANGLEAMPLITUDE_7: Select max triangle amplitude of 7
00117   *            @arg DAC_TRIANGLEAMPLITUDE_15: Select max triangle amplitude of 15
00118   *            @arg DAC_TRIANGLEAMPLITUDE_31: Select max triangle amplitude of 31
00119   *            @arg DAC_TRIANGLEAMPLITUDE_63: Select max triangle amplitude of 63
00120   *            @arg DAC_TRIANGLEAMPLITUDE_127: Select max triangle amplitude of 127
00121   *            @arg DAC_TRIANGLEAMPLITUDE_255: Select max triangle amplitude of 255
00122   *            @arg DAC_TRIANGLEAMPLITUDE_511: Select max triangle amplitude of 511
00123   *            @arg DAC_TRIANGLEAMPLITUDE_1023: Select max triangle amplitude of 1023
00124   *            @arg DAC_TRIANGLEAMPLITUDE_2047: Select max triangle amplitude of 2047
00125   *            @arg DAC_TRIANGLEAMPLITUDE_4095: Select max triangle amplitude of 4095                               
00126   * @retval HAL status
00127   */
00128 HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Amplitude)
00129 {  
00130   /* Check the parameters */
00131   assert_param(IS_DAC_CHANNEL(Channel));
00132   assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude));
00133   
00134   /* Process locked */
00135   __HAL_LOCK(hdac);
00136   
00137   /* Change DAC state */
00138   hdac->State = HAL_DAC_STATE_BUSY;
00139   
00140   /* Enable the triangle wave generation for the selected DAC channel */
00141   MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1)|(DAC_CR_MAMP1))<<Channel, (DAC_CR_WAVE1_1 | Amplitude) << Channel);
00142   
00143   /* Change DAC state */
00144   hdac->State = HAL_DAC_STATE_READY;
00145   
00146   /* Process unlocked */
00147   __HAL_UNLOCK(hdac);
00148   
00149   /* Return function status */
00150   return HAL_OK;
00151 }
00152 
00153 /**
00154   * @brief  Enable or disable the selected DAC channel wave generation.
00155   * @param  hdac: pointer to a DAC_HandleTypeDef structure that contains
00156   *         the configuration information for the specified DAC. 
00157   * @param  Channel: The selected DAC channel. 
00158   *          This parameter can be one of the following values:
00159   *            DAC_CHANNEL_1 / DAC_CHANNEL_2
00160   * @param  Amplitude: Unmask DAC channel LFSR for noise wave generation. 
00161   *          This parameter can be one of the following values: 
00162   *            @arg DAC_LFSRUNMASK_BIT0: Unmask DAC channel LFSR bit0 for noise wave generation
00163   *            @arg DAC_LFSRUNMASK_BITS1_0: Unmask DAC channel LFSR bit[1:0] for noise wave generation  
00164   *            @arg DAC_LFSRUNMASK_BITS2_0: Unmask DAC channel LFSR bit[2:0] for noise wave generation
00165   *            @arg DAC_LFSRUNMASK_BITS3_0: Unmask DAC channel LFSR bit[3:0] for noise wave generation 
00166   *            @arg DAC_LFSRUNMASK_BITS4_0: Unmask DAC channel LFSR bit[4:0] for noise wave generation 
00167   *            @arg DAC_LFSRUNMASK_BITS5_0: Unmask DAC channel LFSR bit[5:0] for noise wave generation 
00168   *            @arg DAC_LFSRUNMASK_BITS6_0: Unmask DAC channel LFSR bit[6:0] for noise wave generation 
00169   *            @arg DAC_LFSRUNMASK_BITS7_0: Unmask DAC channel LFSR bit[7:0] for noise wave generation 
00170   *            @arg DAC_LFSRUNMASK_BITS8_0: Unmask DAC channel LFSR bit[8:0] for noise wave generation 
00171   *            @arg DAC_LFSRUNMASK_BITS9_0: Unmask DAC channel LFSR bit[9:0] for noise wave generation 
00172   *            @arg DAC_LFSRUNMASK_BITS10_0: Unmask DAC channel LFSR bit[10:0] for noise wave generation 
00173   *            @arg DAC_LFSRUNMASK_BITS11_0: Unmask DAC channel LFSR bit[11:0] for noise wave generation 
00174   * @retval HAL status
00175   */
00176 HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Amplitude)
00177 {   
00178   /* Check the parameters */
00179   assert_param(IS_DAC_CHANNEL(Channel));
00180   assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude));
00181   
00182   /* Process locked */
00183   __HAL_LOCK(hdac);
00184   
00185   /* Change DAC state */
00186   hdac->State = HAL_DAC_STATE_BUSY;
00187      
00188   /* Enable the noise wave generation for the selected DAC channel */
00189   MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1)|(DAC_CR_MAMP1))<<Channel, (DAC_CR_WAVE1_0 | Amplitude) << Channel);
00190   
00191   /* Change DAC state */
00192   hdac->State = HAL_DAC_STATE_READY;
00193   
00194   /* Process unlocked */
00195   __HAL_UNLOCK(hdac);
00196   
00197   /* Return function status */
00198   return HAL_OK;
00199 }
00200 
00201 
00202 
00203 /**
00204   * @brief  Set the specified data holding register value for dual DAC channel.
00205   * @param  hdac: pointer to a DAC_HandleTypeDef structure that contains
00206   *               the configuration information for the specified DAC.
00207   * @param  Alignment: Specifies the data alignment for dual channel DAC.
00208   *          This parameter can be one of the following values:
00209   *            DAC_ALIGN_8B_R: 8bit right data alignment selected
00210   *            DAC_ALIGN_12B_L: 12bit left data alignment selected
00211   *            DAC_ALIGN_12B_R: 12bit right data alignment selected
00212   * @param  Data1: Data for DAC Channel2 to be loaded in the selected data holding register.
00213   * @param  Data2: Data for DAC Channel1 to be loaded in the selected data  holding register.
00214   * @note   In dual mode, a unique register access is required to write in both
00215   *          DAC channels at the same time.
00216   * @retval HAL status
00217   */
00218 HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef* hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2)
00219 {  
00220   uint32_t data = 0, tmp = 0;
00221   
00222   /* Check the parameters */
00223   assert_param(IS_DAC_ALIGN(Alignment));
00224   assert_param(IS_DAC_DATA(Data1));
00225   assert_param(IS_DAC_DATA(Data2));
00226   
00227   /* Calculate and set dual DAC data holding register value */
00228   if (Alignment == DAC_ALIGN_8B_R)
00229   {
00230     data = ((uint32_t)Data2 << 8) | Data1; 
00231   }
00232   else
00233   {
00234     data = ((uint32_t)Data2 << 16) | Data1;
00235   }
00236   
00237   tmp = (uint32_t)hdac->Instance;
00238   tmp += DAC_DHR12RD_ALIGNMENT(Alignment);
00239 
00240   /* Set the dual DAC selected data holding register */
00241   *(__IO uint32_t *)tmp = data;
00242   
00243   /* Return function status */
00244   return HAL_OK;
00245 }
00246 
00247 /**
00248   * @brief  Conversion complete callback in non-blocking mode for Channel2.
00249   * @param  hdac: pointer to a DAC_HandleTypeDef structure that contains
00250   *         the configuration information for the specified DAC.
00251   * @retval None
00252   */
00253 __weak void HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef* hdac)
00254 {
00255   /* Prevent unused argument(s) compilation warning */
00256   UNUSED(hdac);
00257 
00258   /* NOTE : This function should not be modified, when the callback is needed,
00259             the HAL_DACEx_ConvCpltCallbackCh2 could be implemented in the user file
00260    */
00261 }
00262 
00263 /**
00264   * @brief  Conversion half DMA transfer callback in non-blocking mode for Channel2. 
00265   * @param  hdac: pointer to a DAC_HandleTypeDef structure that contains
00266   *         the configuration information for the specified DAC.
00267   * @retval None
00268   */
00269 __weak void HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef* hdac)
00270 {
00271   /* Prevent unused argument(s) compilation warning */
00272   UNUSED(hdac);
00273 
00274   /* NOTE : This function should not be modified, when the callback is needed,
00275             the HAL_DACEx_ConvHalfCpltCallbackCh2 could be implemented in the user file
00276    */
00277 }
00278 
00279 /**
00280   * @brief  Error DAC callback for Channel2.
00281   * @param  hdac: pointer to a DAC_HandleTypeDef structure that contains
00282   *         the configuration information for the specified DAC.
00283   * @retval None
00284   */
00285 __weak void HAL_DACEx_ErrorCallbackCh2(DAC_HandleTypeDef *hdac)
00286 {
00287   /* Prevent unused argument(s) compilation warning */
00288   UNUSED(hdac);
00289 
00290   /* NOTE : This function should not be modified, when the callback is needed,
00291             the HAL_DACEx_ErrorCallbackCh2 could be implemented in the user file
00292    */
00293 }
00294 
00295 /**
00296   * @brief  DMA underrun DAC callback for Channel2.
00297   * @param  hdac: pointer to a DAC_HandleTypeDef structure that contains
00298   *         the configuration information for the specified DAC.
00299   * @retval None
00300   */
00301 __weak void HAL_DACEx_DMAUnderrunCallbackCh2(DAC_HandleTypeDef *hdac)
00302 {
00303   /* Prevent unused argument(s) compilation warning */
00304   UNUSED(hdac);
00305 
00306   /* NOTE : This function should not be modified, when the callback is needed,
00307             the HAL_DACEx_DMAUnderrunCallbackCh2 could be implemented in the user file
00308    */
00309 }
00310 
00311 /**
00312   * @brief  Run the self calibration of one DAC channel.
00313   * @param  hdac: pointer to a DAC_HandleTypeDef structure that contains
00314   *         the configuration information for the specified DAC.
00315   * @param  sConfig: DAC channel configuration structure.
00316   * @param  Channel: The selected DAC channel. 
00317   *          This parameter can be one of the following values:
00318   *            @arg DAC_CHANNEL_1: DAC Channel1 selected
00319   *            @arg DAC_CHANNEL_2: DAC Channel2 selected
00320   * @retval Updates DAC_TrimmingValue. , DAC_UserTrimming set to DAC_UserTrimming
00321   * @retval HAL status
00322   * @note   Calibration runs about 7 ms.
00323   */
00324 
00325 HAL_StatusTypeDef HAL_DACEx_SelfCalibrate (DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel)
00326 { 
00327   HAL_StatusTypeDef status = HAL_OK;
00328    
00329   __IO uint32_t tmp = 0;
00330   uint32_t trimmingvalue = 0;
00331   uint32_t delta;
00332   
00333   /* store/restore channel configuration structure purpose */
00334   uint32_t oldmodeconfiguration = 0;
00335   
00336   /* Check the parameters */
00337   assert_param(IS_DAC_CHANNEL(Channel));
00338     
00339  /* Check the DAC handle allocation */
00340  /* Check if DAC running */
00341   if((hdac == NULL) || (hdac->State == HAL_DAC_STATE_BUSY))
00342   {
00343     status = HAL_ERROR;
00344   }
00345   
00346   /* Process locked */
00347   __HAL_LOCK(hdac);
00348   
00349   /* Store configuration */
00350   oldmodeconfiguration = (hdac->Instance->MCR & (DAC_MCR_MODE1 << Channel));
00351   
00352   /* Disable the selected DAC channel */
00353   CLEAR_BIT ((hdac->Instance->CR), (DAC_CR_EN1 << Channel));
00354   
00355   /* Set mode in MCR  for calibration */
00356    MODIFY_REG(hdac->Instance->MCR, (DAC_MCR_MODE1 << Channel), 0);
00357    
00358   /* Set DAC Channel1 DHR register to the middle value */
00359   /* HAL_DAC_SetValue(hdac, Channel, DAC_ALIGN_12B_R, 0x0800); */
00360   tmp = (uint32_t)hdac->Instance; 
00361   if(Channel == DAC_CHANNEL_1)
00362   {
00363     tmp += DAC_DHR12R1_ALIGNMENT(DAC_ALIGN_12B_R);
00364   }
00365   else
00366   {
00367     tmp += DAC_DHR12R2_ALIGNMENT(DAC_ALIGN_12B_R);
00368   }
00369   *(__IO uint32_t *) tmp = 0x0800;
00370      
00371   /* Enable the selected DAC channel calibration */
00372   /* i.e. set DAC_CR_CENx bit */
00373   SET_BIT ((hdac->Instance->CR), (DAC_CR_CEN1 << Channel));
00374   
00375   /* Init trimming counter */    
00376   /* Medium value */
00377   trimmingvalue = 16; 
00378   delta = 8;
00379   while (delta != 0) 
00380     {
00381     /* Set candidate trimming */
00382     MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1<<Channel), (trimmingvalue<<Channel));
00383   
00384     /* tOFFTRIMmax delay x ms as per datasheet (electrical characteristics */ 
00385     /* i.e. minimum time needed between two calibration steps */
00386     HAL_Delay(1);
00387   
00388     if ((hdac->Instance->SR & (DAC_SR_CAL_FLAG1<<Channel)) == RESET)
00389       { 
00390         /* DAC_SR_CAL_FLAGx is HIGH try higher trimming */
00391         trimmingvalue += delta;
00392       }
00393       else
00394       {
00395         /* DAC_SR_CAL_FLAGx is LOW try lower trimming */
00396         trimmingvalue -= delta;
00397        }                   
00398      delta >>= 1;
00399     }
00400   
00401     /* Still need to check if right calibration is current value or one step below */
00402     /* Indeed the first value that causes the DAC_SR_CAL_FLAGx bit to change from 0 to 1  */
00403     /* Set candidate trimming */
00404     MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1<<Channel), (trimmingvalue<<Channel));
00405   
00406     /* tOFFTRIMmax delay x ms as per datasheet (electrical characteristics */ 
00407     /* i.e. minimum time needed between two calibration steps */
00408     HAL_Delay(1);
00409     
00410     if ((hdac->Instance->SR & (DAC_SR_CAL_FLAG1<<Channel)) == RESET)
00411       { 
00412       /* OPAMP_CSR_OUTCAL is actually one value more */
00413       trimmingvalue++;
00414       /* Set right trimming */
00415         MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1<<Channel), (trimmingvalue<<Channel));
00416       }
00417     
00418   /* Disable the selected DAC channel calibration */
00419   /* i.e. clear DAC_CR_CENx bit */
00420   CLEAR_BIT ((hdac->Instance->CR), (DAC_CR_CEN1 << Channel));
00421   
00422   sConfig->DAC_TrimmingValue = trimmingvalue;
00423   sConfig->DAC_UserTrimming = DAC_TRIMMING_USER;
00424   
00425   /* Restore configuration */
00426   MODIFY_REG(hdac->Instance->MCR, (DAC_MCR_MODE1 << Channel), oldmodeconfiguration);
00427   
00428   /* Process unlocked */
00429   __HAL_UNLOCK(hdac);
00430   
00431   return status;
00432 }
00433 
00434 /**
00435   * @brief  Set the trimming mode and trimming value (user trimming mode applied).
00436   * @param  hdac: pointer to a DAC_HandleTypeDef structure that contains
00437   *         the configuration information for the specified DAC.
00438   * @param  sConfig: DAC configuration structure updated with new DAC trimming value.
00439   * @param  Channel: The selected DAC channel. 
00440   *          This parameter can be one of the following values:
00441   *            @arg DAC_CHANNEL_1: DAC Channel1 selected
00442   *            @arg DAC_CHANNEL_2: DAC Channel2 selected
00443   * @param  NewTrimmingValue: DAC new trimming value
00444   * @retval HAL status
00445   */
00446 
00447 HAL_StatusTypeDef HAL_DACEx_SetUserTrimming (DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel, uint32_t NewTrimmingValue)
00448 { 
00449   HAL_StatusTypeDef status = HAL_OK;
00450      
00451   /* Check the parameters */
00452   assert_param(IS_DAC_CHANNEL(Channel));
00453   assert_param(IS_DAC_NEWTRIMMINGVALUE(NewTrimmingValue));
00454   
00455  /* Check the DAC handle allocation */
00456   if(hdac == NULL)
00457   {
00458     status = HAL_ERROR;
00459   }
00460   
00461   /* Process locked */
00462   __HAL_LOCK(hdac);
00463   
00464   /* Set new trimming */
00465   MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1<<Channel), (NewTrimmingValue<<Channel));
00466   
00467   /* Update trimming mode */
00468   sConfig->DAC_UserTrimming = DAC_TRIMMING_USER;
00469   sConfig->DAC_TrimmingValue = NewTrimmingValue;
00470   
00471   /* Process unlocked */
00472   __HAL_UNLOCK(hdac);
00473     
00474   return status;
00475 }
00476 
00477 /**
00478   * @brief  Return the DAC trimming value.
00479   * @param  hdac : DAC handle
00480   * @param  Channel: The selected DAC channel. 
00481   *          This parameter can be one of the following values:
00482   *            @arg DAC_CHANNEL_1: DAC Channel1 selected
00483   *            @arg DAC_CHANNEL_2: DAC Channel2 selected
00484   * @retval Trimming value : range: 0->31
00485   *         
00486  */
00487 
00488 uint32_t HAL_DACEx_GetTrimOffset (DAC_HandleTypeDef *hdac, uint32_t Channel)
00489 {
00490   uint32_t trimmingvalue = 0;
00491   
00492   /* Check the DAC handle allocation */
00493   /* And not in Reset state */
00494   if((hdac == NULL) || (hdac->State == HAL_DAC_STATE_RESET))
00495   {
00496     return HAL_ERROR;
00497   }
00498   else
00499   {
00500     /* Check the parameter */
00501     assert_param(IS_DAC_CHANNEL(Channel));
00502 
00503     /* Retrieve trimming  */
00504     trimmingvalue = ((hdac->Instance->CCR & (DAC_CCR_OTRIM1 << Channel)) >> Channel);
00505   }  
00506   return trimmingvalue;
00507 }
00508 
00509 /**
00510   * @}
00511   */
00512 
00513 /** @defgroup DACEx_Exported_Functions_Group3 Peripheral Control functions
00514  *  @brief    Extended Peripheral Control functions 
00515  *
00516 @verbatim   
00517   ==============================================================================
00518              ##### Peripheral Control functions #####
00519   ==============================================================================  
00520     [..]  This section provides functions allowing to:
00521       (+) Configure channels. 
00522       (+) Set the specified data holding register value for DAC channel.
00523       
00524 @endverbatim
00525   * @{
00526   */
00527 
00528 /**
00529   * @brief  Return the last data output value of the selected DAC channel.
00530   * @param  hdac: pointer to a DAC_HandleTypeDef structure that contains
00531   *         the configuration information for the specified DAC.
00532   * @retval The selected DAC channel data output value.
00533   */
00534 uint32_t HAL_DACEx_DualGetValue(DAC_HandleTypeDef* hdac)
00535 {
00536   uint32_t tmp = 0;
00537   
00538   tmp |= hdac->Instance->DOR1;
00539 
00540   tmp |= hdac->Instance->DOR2 << 16;
00541   
00542   /* Returns the DAC channel data output register value */
00543   return tmp;
00544 }
00545 
00546 /**
00547   * @}
00548   */
00549 
00550 /**
00551   * @}
00552   */
00553 
00554 /* Private functions ---------------------------------------------------------*/
00555 /** @defgroup DACEx_Private_Functions DACEx private functions
00556  *  @brief    Extended private functions
00557    * @{
00558   */
00559 
00560 /**
00561   * @brief  DMA conversion complete callback. 
00562   * @param  hdma: pointer to a DMA_HandleTypeDef structure that contains
00563   *                the configuration information for the specified DMA module.
00564   * @retval None
00565   */
00566 void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma)   
00567 {
00568   DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
00569   
00570   HAL_DACEx_ConvCpltCallbackCh2(hdac); 
00571   
00572   hdac->State= HAL_DAC_STATE_READY;
00573 }
00574 
00575 /**
00576   * @brief  DMA half transfer complete callback. 
00577   * @param  hdma: pointer to a DMA_HandleTypeDef structure that contains
00578   *                the configuration information for the specified DMA module.
00579   * @retval None
00580   */
00581 void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma)   
00582 {
00583     DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
00584     /* Conversion complete callback */
00585     HAL_DACEx_ConvHalfCpltCallbackCh2(hdac); 
00586 }
00587 
00588 /**
00589   * @brief  DMA error callback.
00590   * @param  hdma: pointer to a DMA_HandleTypeDef structure that contains
00591   *                the configuration information for the specified DMA module.
00592   * @retval None
00593   */
00594 void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma)   
00595 {
00596   DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
00597     
00598   /* Set DAC error code to DMA error */
00599   hdac->ErrorCode |= HAL_DAC_ERROR_DMA;
00600     
00601   HAL_DACEx_ErrorCallbackCh2(hdac); 
00602     
00603   hdac->State= HAL_DAC_STATE_READY;
00604 }
00605 
00606 /**
00607   * @}
00608   */
00609 
00610 #endif /* HAL_DAC_MODULE_ENABLED */
00611 
00612 /**
00613   * @}
00614   */
00615 
00616 /**
00617   * @}
00618   */
00619 
00620 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/