STM32F479xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f4xx_hal_dac.c 00004 * @author MCD Application Team 00005 * @brief DAC HAL module driver. 00006 * This file provides firmware functions to manage the following 00007 * functionalities of the Digital to Analog Converter (DAC) peripheral: 00008 * + Initialization and de-initialization functions 00009 * + IO operation functions 00010 * + Peripheral Control functions 00011 * + Peripheral State and Errors functions 00012 * 00013 * 00014 @verbatim 00015 ============================================================================== 00016 ##### DAC Peripheral features ##### 00017 ============================================================================== 00018 [..] 00019 *** DAC Channels *** 00020 ==================== 00021 [..] 00022 STM32F4 devices integrate two 12-bit Digital Analog Converters 00023 00024 The 2 converters (i.e. channel1 & channel2) 00025 can be used independently or simultaneously (dual mode): 00026 (#) DAC channel1 with DAC_OUT1 (PA4) as output 00027 (#) DAC channel2 with DAC_OUT2 (PA5) as output 00028 00029 *** DAC Triggers *** 00030 ==================== 00031 [..] 00032 Digital to Analog conversion can be non-triggered using DAC_TRIGGER_NONE 00033 and DAC_OUT1/DAC_OUT2 is available once writing to DHRx register. 00034 [..] 00035 Digital to Analog conversion can be triggered by: 00036 (#) External event: EXTI Line 9 (any GPIOx_PIN_9) using DAC_TRIGGER_EXT_IT9. 00037 The used pin (GPIOx_PIN_9) must be configured in input mode. 00038 00039 (#) Timers TRGO: TIM2, TIM4, TIM5, TIM6, TIM7 and TIM8 00040 (DAC_TRIGGER_T2_TRGO, DAC_TRIGGER_T4_TRGO...) 00041 00042 (#) Software using DAC_TRIGGER_SOFTWARE 00043 00044 *** DAC Buffer mode feature *** 00045 =============================== 00046 [..] 00047 Each DAC channel integrates an output buffer that can be used to 00048 reduce the output impedance, and to drive external loads directly 00049 without having to add an external operational amplifier. 00050 To enable, the output buffer use 00051 sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE; 00052 [..] 00053 (@) Refer to the device datasheet for more details about output 00054 impedance value with and without output buffer. 00055 00056 *** DAC wave generation feature *** 00057 =================================== 00058 [..] 00059 Both DAC channels can be used to generate 00060 (#) Noise wave 00061 (#) Triangle wave 00062 00063 *** DAC data format *** 00064 ======================= 00065 [..] 00066 The DAC data format can be: 00067 (#) 8-bit right alignment using DAC_ALIGN_8B_R 00068 (#) 12-bit left alignment using DAC_ALIGN_12B_L 00069 (#) 12-bit right alignment using DAC_ALIGN_12B_R 00070 00071 *** DAC data value to voltage correspondence *** 00072 ================================================ 00073 [..] 00074 The analog output voltage on each DAC channel pin is determined 00075 by the following equation: 00076 [..] 00077 DAC_OUTx = VREF+ * DOR / 4095 00078 (+) with DOR is the Data Output Register 00079 [..] 00080 VREF+ is the input voltage reference (refer to the device datasheet) 00081 [..] 00082 e.g. To set DAC_OUT1 to 0.7V, use 00083 (+) Assuming that VREF+ = 3.3V, DAC_OUT1 = (3.3 * 868) / 4095 = 0.7V 00084 00085 *** DMA requests *** 00086 ===================== 00087 [..] 00088 A DMA request can be generated when an external trigger (but not a software trigger) 00089 occurs if DMA1 requests are enabled using HAL_DAC_Start_DMA(). 00090 DMA1 requests are mapped as following: 00091 (#) DAC channel1 mapped on DMA1 Stream5 channel7 which must be 00092 already configured 00093 (#) DAC channel2 mapped on DMA1 Stream6 channel7 which must be 00094 already configured 00095 00096 [..] 00097 (@) For Dual mode and specific signal (Triangle and noise) generation please 00098 refer to Extended Features Driver description 00099 00100 ##### How to use this driver ##### 00101 ============================================================================== 00102 [..] 00103 (+) DAC APB clock must be enabled to get write access to DAC 00104 registers using HAL_DAC_Init() 00105 (+) Configure DAC_OUTx (DAC_OUT1: PA4, DAC_OUT2: PA5) in analog mode. 00106 (+) Configure the DAC channel using HAL_DAC_ConfigChannel() function. 00107 (+) Enable the DAC channel using HAL_DAC_Start() or HAL_DAC_Start_DMA() functions. 00108 00109 00110 *** Polling mode IO operation *** 00111 ================================= 00112 [..] 00113 (+) Start the DAC peripheral using HAL_DAC_Start() 00114 (+) To read the DAC last data output value, use the HAL_DAC_GetValue() function. 00115 (+) Stop the DAC peripheral using HAL_DAC_Stop() 00116 00117 *** DMA mode IO operation *** 00118 ============================== 00119 [..] 00120 (+) Start the DAC peripheral using HAL_DAC_Start_DMA(), at this stage the user specify the length 00121 of data to be transferred at each end of conversion 00122 First issued trigger will start the conversion of the value previously set by HAL_DAC_SetValue(). 00123 (+) At the middle of data transfer HAL_DAC_ConvHalfCpltCallbackCh1() or HAL_DACEx_ConvHalfCpltCallbackCh2() 00124 function is executed and user can add his own code by customization of function pointer 00125 HAL_DAC_ConvHalfCpltCallbackCh1() or HAL_DACEx_ConvHalfCpltCallbackCh2() 00126 (+) At The end of data transfer HAL_DAC_ConvCpltCallbackCh1() or HAL_DACEx_ConvHalfCpltCallbackCh2() 00127 function is executed and user can add his own code by customization of function pointer 00128 HAL_DAC_ConvCpltCallbackCh1() or HAL_DACEx_ConvHalfCpltCallbackCh2() 00129 (+) In case of transfer Error, HAL_DAC_ErrorCallbackCh1() function is executed and user can 00130 add his own code by customization of function pointer HAL_DAC_ErrorCallbackCh1 00131 (+) In case of DMA underrun, DAC interruption triggers and execute internal function HAL_DAC_IRQHandler. 00132 HAL_DAC_DMAUnderrunCallbackCh1() or HAL_DACEx_DMAUnderrunCallbackCh2() 00133 function is executed and user can add his own code by customization of function pointer 00134 HAL_DAC_DMAUnderrunCallbackCh1() or HAL_DACEx_DMAUnderrunCallbackCh2() and 00135 add his own code by customization of function pointer HAL_DAC_ErrorCallbackCh1() 00136 (+) Stop the DAC peripheral using HAL_DAC_Stop_DMA() 00137 00138 *** Callback registration *** 00139 ============================================= 00140 [..] 00141 The compilation define USE_HAL_DAC_REGISTER_CALLBACKS when set to 1 00142 allows the user to configure dynamically the driver callbacks. 00143 00144 Use Functions HAL_DAC_RegisterCallback() to register a user callback, 00145 it allows to register following callbacks: 00146 (+) ConvCpltCallbackCh1 : callback when a half transfer is completed on Ch1. 00147 (+) ConvHalfCpltCallbackCh1 : callback when a transfer is completed on Ch1. 00148 (+) ErrorCallbackCh1 : callback when an error occurs on Ch1. 00149 (+) DMAUnderrunCallbackCh1 : callback when an underrun error occurs on Ch1. 00150 (+) ConvCpltCallbackCh2 : callback when a half transfer is completed on Ch2. 00151 (+) ConvHalfCpltCallbackCh2 : callback when a transfer is completed on Ch2. 00152 (+) ErrorCallbackCh2 : callback when an error occurs on Ch2. 00153 (+) DMAUnderrunCallbackCh2 : callback when an underrun error occurs on Ch2. 00154 (+) MspInitCallback : DAC MspInit. 00155 (+) MspDeInitCallback : DAC MspdeInit. 00156 This function takes as parameters the HAL peripheral handle, the Callback ID 00157 and a pointer to the user callback function. 00158 00159 Use function HAL_DAC_UnRegisterCallback() to reset a callback to the default 00160 weak (surcharged) function. It allows to reset following callbacks: 00161 (+) ConvCpltCallbackCh1 : callback when a half transfer is completed on Ch1. 00162 (+) ConvHalfCpltCallbackCh1 : callback when a transfer is completed on Ch1. 00163 (+) ErrorCallbackCh1 : callback when an error occurs on Ch1. 00164 (+) DMAUnderrunCallbackCh1 : callback when an underrun error occurs on Ch1. 00165 (+) ConvCpltCallbackCh2 : callback when a half transfer is completed on Ch2. 00166 (+) ConvHalfCpltCallbackCh2 : callback when a transfer is completed on Ch2. 00167 (+) ErrorCallbackCh2 : callback when an error occurs on Ch2. 00168 (+) DMAUnderrunCallbackCh2 : callback when an underrun error occurs on Ch2. 00169 (+) MspInitCallback : DAC MspInit. 00170 (+) MspDeInitCallback : DAC MspdeInit. 00171 (+) All Callbacks 00172 This function) takes as parameters the HAL peripheral handle and the Callback ID. 00173 00174 By default, after the HAL_DAC_Init and if the state is HAL_DAC_STATE_RESET 00175 all callbacks are reset to the corresponding legacy weak (surcharged) functions. 00176 Exception done for MspInit and MspDeInit callbacks that are respectively 00177 reset to the legacy weak (surcharged) functions in the HAL_DAC_Init 00178 and HAL_DAC_DeInit only when these callbacks are null (not registered beforehand). 00179 If not, MspInit or MspDeInit are not null, the HAL_DAC_Init and HAL_DAC_DeInit 00180 keep and use the user MspInit/MspDeInit callbacks (registered beforehand) 00181 00182 Callbacks can be registered/unregistered in READY state only. 00183 Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered 00184 in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used 00185 during the Init/DeInit. 00186 In that case first register the MspInit/MspDeInit user callbacks 00187 using HAL_DAC_RegisterCallback before calling HAL_DAC_DeInit 00188 or HAL_DAC_Init function. 00189 00190 When The compilation define USE_HAL_DAC_REGISTER_CALLBACKS is set to 0 or 00191 not defined, the callback registering feature is not available 00192 and weak (surcharged) callbacks are used. 00193 00194 *** DAC HAL driver macros list *** 00195 ============================================= 00196 [..] 00197 Below the list of most used macros in DAC HAL driver. 00198 00199 (+) __HAL_DAC_ENABLE : Enable the DAC peripheral 00200 (+) __HAL_DAC_DISABLE : Disable the DAC peripheral 00201 (+) __HAL_DAC_CLEAR_FLAG: Clear the DAC's pending flags 00202 (+) __HAL_DAC_GET_FLAG: Get the selected DAC's flag status 00203 00204 [..] 00205 (@) You can refer to the DAC HAL driver header file for more useful macros 00206 00207 @endverbatim 00208 ****************************************************************************** 00209 * @attention 00210 * 00211 * <h2><center>© Copyright (c) 2016 STMicroelectronics. 00212 * All rights reserved.</center></h2> 00213 * 00214 * This software component is licensed by ST under BSD 3-Clause license, 00215 * the "License"; You may not use this file except in compliance with the 00216 * License. You may obtain a copy of the License at: 00217 * opensource.org/licenses/BSD-3-Clause 00218 * 00219 ****************************************************************************** 00220 */ 00221 00222 /* Includes ------------------------------------------------------------------*/ 00223 #include "stm32f4xx_hal.h" 00224 00225 /** @addtogroup STM32F4xx_HAL_Driver 00226 * @{ 00227 */ 00228 00229 #ifdef HAL_DAC_MODULE_ENABLED 00230 #if defined(DAC) 00231 00232 /** @defgroup DAC DAC 00233 * @brief DAC driver modules 00234 * @{ 00235 */ 00236 00237 /* Private typedef -----------------------------------------------------------*/ 00238 /* Private define ------------------------------------------------------------*/ 00239 /* Private constants ---------------------------------------------------------*/ 00240 /* Private macro -------------------------------------------------------------*/ 00241 /* Private variables ---------------------------------------------------------*/ 00242 /* Private function prototypes -----------------------------------------------*/ 00243 /* Exported functions -------------------------------------------------------*/ 00244 00245 /** @defgroup DAC_Exported_Functions DAC Exported Functions 00246 * @{ 00247 */ 00248 00249 /** @defgroup DAC_Exported_Functions_Group1 Initialization and de-initialization functions 00250 * @brief Initialization and Configuration functions 00251 * 00252 @verbatim 00253 ============================================================================== 00254 ##### Initialization and de-initialization functions ##### 00255 ============================================================================== 00256 [..] This section provides functions allowing to: 00257 (+) Initialize and configure the DAC. 00258 (+) De-initialize the DAC. 00259 00260 @endverbatim 00261 * @{ 00262 */ 00263 00264 /** 00265 * @brief Initialize the DAC peripheral according to the specified parameters 00266 * in the DAC_InitStruct and initialize the associated handle. 00267 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00268 * the configuration information for the specified DAC. 00269 * @retval HAL status 00270 */ 00271 HAL_StatusTypeDef HAL_DAC_Init(DAC_HandleTypeDef *hdac) 00272 { 00273 /* Check DAC handle */ 00274 if (hdac == NULL) 00275 { 00276 return HAL_ERROR; 00277 } 00278 /* Check the parameters */ 00279 assert_param(IS_DAC_ALL_INSTANCE(hdac->Instance)); 00280 00281 if (hdac->State == HAL_DAC_STATE_RESET) 00282 { 00283 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) 00284 /* Init the DAC Callback settings */ 00285 hdac->ConvCpltCallbackCh1 = HAL_DAC_ConvCpltCallbackCh1; 00286 hdac->ConvHalfCpltCallbackCh1 = HAL_DAC_ConvHalfCpltCallbackCh1; 00287 hdac->ErrorCallbackCh1 = HAL_DAC_ErrorCallbackCh1; 00288 hdac->DMAUnderrunCallbackCh1 = HAL_DAC_DMAUnderrunCallbackCh1; 00289 #if defined(DAC_CHANNEL2_SUPPORT) 00290 hdac->ConvCpltCallbackCh2 = HAL_DACEx_ConvCpltCallbackCh2; 00291 hdac->ConvHalfCpltCallbackCh2 = HAL_DACEx_ConvHalfCpltCallbackCh2; 00292 hdac->ErrorCallbackCh2 = HAL_DACEx_ErrorCallbackCh2; 00293 hdac->DMAUnderrunCallbackCh2 = HAL_DACEx_DMAUnderrunCallbackCh2; 00294 #endif /* DAC_CHANNEL2_SUPPORT */ 00295 if (hdac->MspInitCallback == NULL) 00296 { 00297 hdac->MspInitCallback = HAL_DAC_MspInit; 00298 } 00299 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ 00300 00301 /* Allocate lock resource and initialize it */ 00302 hdac->Lock = HAL_UNLOCKED; 00303 00304 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) 00305 /* Init the low level hardware */ 00306 hdac->MspInitCallback(hdac); 00307 #else 00308 /* Init the low level hardware */ 00309 HAL_DAC_MspInit(hdac); 00310 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ 00311 } 00312 00313 /* Initialize the DAC state*/ 00314 hdac->State = HAL_DAC_STATE_BUSY; 00315 00316 /* Set DAC error code to none */ 00317 hdac->ErrorCode = HAL_DAC_ERROR_NONE; 00318 00319 /* Initialize the DAC state*/ 00320 hdac->State = HAL_DAC_STATE_READY; 00321 00322 /* Return function status */ 00323 return HAL_OK; 00324 } 00325 00326 /** 00327 * @brief Deinitialize the DAC peripheral registers to their default reset values. 00328 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00329 * the configuration information for the specified DAC. 00330 * @retval HAL status 00331 */ 00332 HAL_StatusTypeDef HAL_DAC_DeInit(DAC_HandleTypeDef *hdac) 00333 { 00334 /* Check DAC handle */ 00335 if (hdac == NULL) 00336 { 00337 return HAL_ERROR; 00338 } 00339 00340 /* Check the parameters */ 00341 assert_param(IS_DAC_ALL_INSTANCE(hdac->Instance)); 00342 00343 /* Change DAC state */ 00344 hdac->State = HAL_DAC_STATE_BUSY; 00345 00346 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) 00347 if (hdac->MspDeInitCallback == NULL) 00348 { 00349 hdac->MspDeInitCallback = HAL_DAC_MspDeInit; 00350 } 00351 /* DeInit the low level hardware */ 00352 hdac->MspDeInitCallback(hdac); 00353 #else 00354 /* DeInit the low level hardware */ 00355 HAL_DAC_MspDeInit(hdac); 00356 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ 00357 00358 /* Set DAC error code to none */ 00359 hdac->ErrorCode = HAL_DAC_ERROR_NONE; 00360 00361 /* Change DAC state */ 00362 hdac->State = HAL_DAC_STATE_RESET; 00363 00364 /* Release Lock */ 00365 __HAL_UNLOCK(hdac); 00366 00367 /* Return function status */ 00368 return HAL_OK; 00369 } 00370 00371 /** 00372 * @brief Initialize the DAC MSP. 00373 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00374 * the configuration information for the specified DAC. 00375 * @retval None 00376 */ 00377 __weak void HAL_DAC_MspInit(DAC_HandleTypeDef *hdac) 00378 { 00379 /* Prevent unused argument(s) compilation warning */ 00380 UNUSED(hdac); 00381 00382 /* NOTE : This function should not be modified, when the callback is needed, 00383 the HAL_DAC_MspInit could be implemented in the user file 00384 */ 00385 } 00386 00387 /** 00388 * @brief DeInitialize the DAC MSP. 00389 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00390 * the configuration information for the specified DAC. 00391 * @retval None 00392 */ 00393 __weak void HAL_DAC_MspDeInit(DAC_HandleTypeDef *hdac) 00394 { 00395 /* Prevent unused argument(s) compilation warning */ 00396 UNUSED(hdac); 00397 00398 /* NOTE : This function should not be modified, when the callback is needed, 00399 the HAL_DAC_MspDeInit could be implemented in the user file 00400 */ 00401 } 00402 00403 /** 00404 * @} 00405 */ 00406 00407 /** @defgroup DAC_Exported_Functions_Group2 IO operation functions 00408 * @brief IO operation functions 00409 * 00410 @verbatim 00411 ============================================================================== 00412 ##### IO operation functions ##### 00413 ============================================================================== 00414 [..] This section provides functions allowing to: 00415 (+) Start conversion. 00416 (+) Stop conversion. 00417 (+) Start conversion and enable DMA transfer. 00418 (+) Stop conversion and disable DMA transfer. 00419 (+) Get result of conversion. 00420 00421 @endverbatim 00422 * @{ 00423 */ 00424 00425 /** 00426 * @brief Enables DAC and starts conversion of channel. 00427 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00428 * the configuration information for the specified DAC. 00429 * @param Channel The selected DAC channel. 00430 * This parameter can be one of the following values: 00431 * @arg DAC_CHANNEL_1: DAC Channel1 selected 00432 * @arg DAC_CHANNEL_2: DAC Channel2 selected 00433 * @retval HAL status 00434 */ 00435 HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef *hdac, uint32_t Channel) 00436 { 00437 /* Check the parameters */ 00438 assert_param(IS_DAC_CHANNEL(Channel)); 00439 00440 /* Process locked */ 00441 __HAL_LOCK(hdac); 00442 00443 /* Change DAC state */ 00444 hdac->State = HAL_DAC_STATE_BUSY; 00445 00446 /* Enable the Peripheral */ 00447 __HAL_DAC_ENABLE(hdac, Channel); 00448 00449 if (Channel == DAC_CHANNEL_1) 00450 { 00451 /* Check if software trigger enabled */ 00452 if ((hdac->Instance->CR & (DAC_CR_TEN1 | DAC_CR_TSEL1)) == DAC_TRIGGER_SOFTWARE) 00453 { 00454 /* Enable the selected DAC software conversion */ 00455 SET_BIT(hdac->Instance->SWTRIGR, DAC_SWTRIGR_SWTRIG1); 00456 } 00457 } 00458 #if defined(DAC_CHANNEL2_SUPPORT) 00459 else 00460 { 00461 /* Check if software trigger enabled */ 00462 if ((hdac->Instance->CR & (DAC_CR_TEN2 | DAC_CR_TSEL2)) == (DAC_TRIGGER_SOFTWARE << (Channel & 0x10UL))) 00463 { 00464 /* Enable the selected DAC software conversion*/ 00465 SET_BIT(hdac->Instance->SWTRIGR, DAC_SWTRIGR_SWTRIG2); 00466 } 00467 } 00468 #endif /* DAC_CHANNEL2_SUPPORT */ 00469 00470 /* Change DAC state */ 00471 hdac->State = HAL_DAC_STATE_READY; 00472 00473 /* Process unlocked */ 00474 __HAL_UNLOCK(hdac); 00475 00476 /* Return function status */ 00477 return HAL_OK; 00478 } 00479 00480 /** 00481 * @brief Disables DAC and stop conversion of channel. 00482 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00483 * the configuration information for the specified DAC. 00484 * @param Channel The selected DAC channel. 00485 * This parameter can be one of the following values: 00486 * @arg DAC_CHANNEL_1: DAC Channel1 selected 00487 * @arg DAC_CHANNEL_2: DAC Channel2 selected 00488 * @retval HAL status 00489 */ 00490 HAL_StatusTypeDef HAL_DAC_Stop(DAC_HandleTypeDef *hdac, uint32_t Channel) 00491 { 00492 /* Check the parameters */ 00493 assert_param(IS_DAC_CHANNEL(Channel)); 00494 00495 /* Disable the Peripheral */ 00496 __HAL_DAC_DISABLE(hdac, Channel); 00497 00498 /* Change DAC state */ 00499 hdac->State = HAL_DAC_STATE_READY; 00500 00501 /* Return function status */ 00502 return HAL_OK; 00503 } 00504 00505 /** 00506 * @brief Enables DAC and starts conversion of channel. 00507 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00508 * the configuration information for the specified DAC. 00509 * @param Channel The selected DAC channel. 00510 * This parameter can be one of the following values: 00511 * @arg DAC_CHANNEL_1: DAC Channel1 selected 00512 * @arg DAC_CHANNEL_2: DAC Channel2 selected 00513 * @param pData The source Buffer address. 00514 * @param Length The length of data to be transferred from memory to DAC peripheral 00515 * @param Alignment Specifies the data alignment for DAC channel. 00516 * This parameter can be one of the following values: 00517 * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected 00518 * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected 00519 * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected 00520 * @retval HAL status 00521 */ 00522 HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t *pData, uint32_t Length, 00523 uint32_t Alignment) 00524 { 00525 HAL_StatusTypeDef status; 00526 uint32_t tmpreg = 0U; 00527 00528 /* Check the parameters */ 00529 assert_param(IS_DAC_CHANNEL(Channel)); 00530 assert_param(IS_DAC_ALIGN(Alignment)); 00531 00532 /* Process locked */ 00533 __HAL_LOCK(hdac); 00534 00535 /* Change DAC state */ 00536 hdac->State = HAL_DAC_STATE_BUSY; 00537 00538 if (Channel == DAC_CHANNEL_1) 00539 { 00540 /* Set the DMA transfer complete callback for channel1 */ 00541 hdac->DMA_Handle1->XferCpltCallback = DAC_DMAConvCpltCh1; 00542 00543 /* Set the DMA half transfer complete callback for channel1 */ 00544 hdac->DMA_Handle1->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh1; 00545 00546 /* Set the DMA error callback for channel1 */ 00547 hdac->DMA_Handle1->XferErrorCallback = DAC_DMAErrorCh1; 00548 00549 /* Enable the selected DAC channel1 DMA request */ 00550 SET_BIT(hdac->Instance->CR, DAC_CR_DMAEN1); 00551 00552 /* Case of use of channel 1 */ 00553 switch (Alignment) 00554 { 00555 case DAC_ALIGN_12B_R: 00556 /* Get DHR12R1 address */ 00557 tmpreg = (uint32_t)&hdac->Instance->DHR12R1; 00558 break; 00559 case DAC_ALIGN_12B_L: 00560 /* Get DHR12L1 address */ 00561 tmpreg = (uint32_t)&hdac->Instance->DHR12L1; 00562 break; 00563 case DAC_ALIGN_8B_R: 00564 /* Get DHR8R1 address */ 00565 tmpreg = (uint32_t)&hdac->Instance->DHR8R1; 00566 break; 00567 default: 00568 break; 00569 } 00570 } 00571 #if defined(DAC_CHANNEL2_SUPPORT) 00572 else 00573 { 00574 /* Set the DMA transfer complete callback for channel2 */ 00575 hdac->DMA_Handle2->XferCpltCallback = DAC_DMAConvCpltCh2; 00576 00577 /* Set the DMA half transfer complete callback for channel2 */ 00578 hdac->DMA_Handle2->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh2; 00579 00580 /* Set the DMA error callback for channel2 */ 00581 hdac->DMA_Handle2->XferErrorCallback = DAC_DMAErrorCh2; 00582 00583 /* Enable the selected DAC channel2 DMA request */ 00584 SET_BIT(hdac->Instance->CR, DAC_CR_DMAEN2); 00585 00586 /* Case of use of channel 2 */ 00587 switch (Alignment) 00588 { 00589 case DAC_ALIGN_12B_R: 00590 /* Get DHR12R2 address */ 00591 tmpreg = (uint32_t)&hdac->Instance->DHR12R2; 00592 break; 00593 case DAC_ALIGN_12B_L: 00594 /* Get DHR12L2 address */ 00595 tmpreg = (uint32_t)&hdac->Instance->DHR12L2; 00596 break; 00597 case DAC_ALIGN_8B_R: 00598 /* Get DHR8R2 address */ 00599 tmpreg = (uint32_t)&hdac->Instance->DHR8R2; 00600 break; 00601 default: 00602 break; 00603 } 00604 } 00605 #endif /* DAC_CHANNEL2_SUPPORT */ 00606 00607 /* Enable the DMA Stream */ 00608 if (Channel == DAC_CHANNEL_1) 00609 { 00610 /* Enable the DAC DMA underrun interrupt */ 00611 __HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR1); 00612 00613 /* Enable the DMA Stream */ 00614 status = HAL_DMA_Start_IT(hdac->DMA_Handle1, (uint32_t)pData, tmpreg, Length); 00615 } 00616 #if defined(DAC_CHANNEL2_SUPPORT) 00617 else 00618 { 00619 /* Enable the DAC DMA underrun interrupt */ 00620 __HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR2); 00621 00622 /* Enable the DMA Stream */ 00623 status = HAL_DMA_Start_IT(hdac->DMA_Handle2, (uint32_t)pData, tmpreg, Length); 00624 } 00625 #endif /* DAC_CHANNEL2_SUPPORT */ 00626 00627 /* Process Unlocked */ 00628 __HAL_UNLOCK(hdac); 00629 00630 if (status == HAL_OK) 00631 { 00632 /* Enable the Peripheral */ 00633 __HAL_DAC_ENABLE(hdac, Channel); 00634 } 00635 else 00636 { 00637 hdac->ErrorCode |= HAL_DAC_ERROR_DMA; 00638 } 00639 00640 /* Return function status */ 00641 return status; 00642 } 00643 00644 /** 00645 * @brief Disables DAC and stop conversion of channel. 00646 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00647 * the configuration information for the specified DAC. 00648 * @param Channel The selected DAC channel. 00649 * This parameter can be one of the following values: 00650 * @arg DAC_CHANNEL_1: DAC Channel1 selected 00651 * @arg DAC_CHANNEL_2: DAC Channel2 selected 00652 * @retval HAL status 00653 */ 00654 HAL_StatusTypeDef HAL_DAC_Stop_DMA(DAC_HandleTypeDef *hdac, uint32_t Channel) 00655 { 00656 /* Check the parameters */ 00657 assert_param(IS_DAC_CHANNEL(Channel)); 00658 00659 /* Disable the selected DAC channel DMA request */ 00660 hdac->Instance->CR &= ~(DAC_CR_DMAEN1 << (Channel & 0x10UL)); 00661 00662 /* Disable the Peripheral */ 00663 __HAL_DAC_DISABLE(hdac, Channel); 00664 00665 /* Disable the DMA Stream */ 00666 00667 /* Channel1 is used */ 00668 if (Channel == DAC_CHANNEL_1) 00669 { 00670 /* Disable the DMA Stream */ 00671 (void)HAL_DMA_Abort(hdac->DMA_Handle1); 00672 00673 /* Disable the DAC DMA underrun interrupt */ 00674 __HAL_DAC_DISABLE_IT(hdac, DAC_IT_DMAUDR1); 00675 } 00676 #if defined(DAC_CHANNEL2_SUPPORT) 00677 else /* Channel2 is used for */ 00678 { 00679 /* Disable the DMA Stream */ 00680 (void)HAL_DMA_Abort(hdac->DMA_Handle2); 00681 00682 /* Disable the DAC DMA underrun interrupt */ 00683 __HAL_DAC_DISABLE_IT(hdac, DAC_IT_DMAUDR2); 00684 } 00685 #endif /* DAC_CHANNEL2_SUPPORT */ 00686 00687 /* Change DAC state */ 00688 hdac->State = HAL_DAC_STATE_READY; 00689 00690 /* Return function status */ 00691 return HAL_OK; 00692 } 00693 00694 /** 00695 * @brief Handles DAC interrupt request 00696 * This function uses the interruption of DMA 00697 * underrun. 00698 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00699 * the configuration information for the specified DAC. 00700 * @retval None 00701 */ 00702 void HAL_DAC_IRQHandler(DAC_HandleTypeDef *hdac) 00703 { 00704 if (__HAL_DAC_GET_IT_SOURCE(hdac, DAC_IT_DMAUDR1)) 00705 { 00706 /* Check underrun flag of DAC channel 1 */ 00707 if (__HAL_DAC_GET_FLAG(hdac, DAC_FLAG_DMAUDR1)) 00708 { 00709 /* Change DAC state to error state */ 00710 hdac->State = HAL_DAC_STATE_ERROR; 00711 00712 /* Set DAC error code to channel1 DMA underrun error */ 00713 SET_BIT(hdac->ErrorCode, HAL_DAC_ERROR_DMAUNDERRUNCH1); 00714 00715 /* Clear the underrun flag */ 00716 __HAL_DAC_CLEAR_FLAG(hdac, DAC_FLAG_DMAUDR1); 00717 00718 /* Disable the selected DAC channel1 DMA request */ 00719 CLEAR_BIT(hdac->Instance->CR, DAC_CR_DMAEN1); 00720 00721 /* Error callback */ 00722 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) 00723 hdac->DMAUnderrunCallbackCh1(hdac); 00724 #else 00725 HAL_DAC_DMAUnderrunCallbackCh1(hdac); 00726 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ 00727 } 00728 } 00729 00730 #if defined(DAC_CHANNEL2_SUPPORT) 00731 if (__HAL_DAC_GET_IT_SOURCE(hdac, DAC_IT_DMAUDR2)) 00732 { 00733 /* Check underrun flag of DAC channel 2 */ 00734 if (__HAL_DAC_GET_FLAG(hdac, DAC_FLAG_DMAUDR2)) 00735 { 00736 /* Change DAC state to error state */ 00737 hdac->State = HAL_DAC_STATE_ERROR; 00738 00739 /* Set DAC error code to channel2 DMA underrun error */ 00740 SET_BIT(hdac->ErrorCode, HAL_DAC_ERROR_DMAUNDERRUNCH2); 00741 00742 /* Clear the underrun flag */ 00743 __HAL_DAC_CLEAR_FLAG(hdac, DAC_FLAG_DMAUDR2); 00744 00745 /* Disable the selected DAC channel2 DMA request */ 00746 CLEAR_BIT(hdac->Instance->CR, DAC_CR_DMAEN2); 00747 00748 /* Error callback */ 00749 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) 00750 hdac->DMAUnderrunCallbackCh2(hdac); 00751 #else 00752 HAL_DACEx_DMAUnderrunCallbackCh2(hdac); 00753 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ 00754 } 00755 } 00756 #endif /* DAC_CHANNEL2_SUPPORT */ 00757 } 00758 00759 /** 00760 * @brief Set the specified data holding register value for DAC channel. 00761 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00762 * the configuration information for the specified DAC. 00763 * @param Channel The selected DAC channel. 00764 * This parameter can be one of the following values: 00765 * @arg DAC_CHANNEL_1: DAC Channel1 selected 00766 * @arg DAC_CHANNEL_2: DAC Channel2 selected 00767 * @param Alignment Specifies the data alignment. 00768 * This parameter can be one of the following values: 00769 * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected 00770 * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected 00771 * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected 00772 * @param Data Data to be loaded in the selected data holding register. 00773 * @retval HAL status 00774 */ 00775 HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data) 00776 { 00777 __IO uint32_t tmp = 0UL; 00778 00779 /* Check the parameters */ 00780 assert_param(IS_DAC_CHANNEL(Channel)); 00781 assert_param(IS_DAC_ALIGN(Alignment)); 00782 assert_param(IS_DAC_DATA(Data)); 00783 00784 tmp = (uint32_t)hdac->Instance; 00785 if (Channel == DAC_CHANNEL_1) 00786 { 00787 tmp += DAC_DHR12R1_ALIGNMENT(Alignment); 00788 } 00789 #if defined(DAC_CHANNEL2_SUPPORT) 00790 else 00791 { 00792 tmp += DAC_DHR12R2_ALIGNMENT(Alignment); 00793 } 00794 #endif /* DAC_CHANNEL2_SUPPORT */ 00795 00796 /* Set the DAC channel selected data holding register */ 00797 *(__IO uint32_t *) tmp = Data; 00798 00799 /* Return function status */ 00800 return HAL_OK; 00801 } 00802 00803 /** 00804 * @brief Conversion complete callback in non-blocking mode for Channel1 00805 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00806 * the configuration information for the specified DAC. 00807 * @retval None 00808 */ 00809 __weak void HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef *hdac) 00810 { 00811 /* Prevent unused argument(s) compilation warning */ 00812 UNUSED(hdac); 00813 00814 /* NOTE : This function should not be modified, when the callback is needed, 00815 the HAL_DAC_ConvCpltCallbackCh1 could be implemented in the user file 00816 */ 00817 } 00818 00819 /** 00820 * @brief Conversion half DMA transfer callback in non-blocking mode for Channel1 00821 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00822 * the configuration information for the specified DAC. 00823 * @retval None 00824 */ 00825 __weak void HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef *hdac) 00826 { 00827 /* Prevent unused argument(s) compilation warning */ 00828 UNUSED(hdac); 00829 00830 /* NOTE : This function should not be modified, when the callback is needed, 00831 the HAL_DAC_ConvHalfCpltCallbackCh1 could be implemented in the user file 00832 */ 00833 } 00834 00835 /** 00836 * @brief Error DAC callback for Channel1. 00837 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00838 * the configuration information for the specified DAC. 00839 * @retval None 00840 */ 00841 __weak void HAL_DAC_ErrorCallbackCh1(DAC_HandleTypeDef *hdac) 00842 { 00843 /* Prevent unused argument(s) compilation warning */ 00844 UNUSED(hdac); 00845 00846 /* NOTE : This function should not be modified, when the callback is needed, 00847 the HAL_DAC_ErrorCallbackCh1 could be implemented in the user file 00848 */ 00849 } 00850 00851 /** 00852 * @brief DMA underrun DAC callback for channel1. 00853 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00854 * the configuration information for the specified DAC. 00855 * @retval None 00856 */ 00857 __weak void HAL_DAC_DMAUnderrunCallbackCh1(DAC_HandleTypeDef *hdac) 00858 { 00859 /* Prevent unused argument(s) compilation warning */ 00860 UNUSED(hdac); 00861 00862 /* NOTE : This function should not be modified, when the callback is needed, 00863 the HAL_DAC_DMAUnderrunCallbackCh1 could be implemented in the user file 00864 */ 00865 } 00866 00867 /** 00868 * @} 00869 */ 00870 00871 /** @defgroup DAC_Exported_Functions_Group3 Peripheral Control functions 00872 * @brief Peripheral Control functions 00873 * 00874 @verbatim 00875 ============================================================================== 00876 ##### Peripheral Control functions ##### 00877 ============================================================================== 00878 [..] This section provides functions allowing to: 00879 (+) Configure channels. 00880 (+) Set the specified data holding register value for DAC channel. 00881 00882 @endverbatim 00883 * @{ 00884 */ 00885 00886 /** 00887 * @brief Returns the last data output value of the selected DAC channel. 00888 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00889 * the configuration information for the specified DAC. 00890 * @param Channel The selected DAC channel. 00891 * This parameter can be one of the following values: 00892 * @arg DAC_CHANNEL_1: DAC Channel1 selected 00893 * @arg DAC_CHANNEL_2: DAC Channel2 selected 00894 * @retval The selected DAC channel data output value. 00895 */ 00896 uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef *hdac, uint32_t Channel) 00897 { 00898 uint32_t result; 00899 00900 /* Check the parameters */ 00901 assert_param(IS_DAC_CHANNEL(Channel)); 00902 00903 if (Channel == DAC_CHANNEL_1) 00904 { 00905 result = hdac->Instance->DOR1; 00906 } 00907 #if defined(DAC_CHANNEL2_SUPPORT) 00908 else 00909 { 00910 result = hdac->Instance->DOR2; 00911 } 00912 #endif /* DAC_CHANNEL2_SUPPORT */ 00913 /* Returns the DAC channel data output register value */ 00914 return result; 00915 } 00916 00917 /** 00918 * @brief Configures the selected DAC channel. 00919 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00920 * the configuration information for the specified DAC. 00921 * @param sConfig DAC configuration structure. 00922 * @param Channel The selected DAC channel. 00923 * This parameter can be one of the following values: 00924 * @arg DAC_CHANNEL_1: DAC Channel1 selected 00925 * @arg DAC_CHANNEL_2: DAC Channel2 selected 00926 * @retval HAL status 00927 */ 00928 HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef *hdac, DAC_ChannelConfTypeDef *sConfig, uint32_t Channel) 00929 { 00930 uint32_t tmpreg1; 00931 uint32_t tmpreg2; 00932 00933 /* Check the DAC parameters */ 00934 assert_param(IS_DAC_TRIGGER(sConfig->DAC_Trigger)); 00935 assert_param(IS_DAC_OUTPUT_BUFFER_STATE(sConfig->DAC_OutputBuffer)); 00936 assert_param(IS_DAC_CHANNEL(Channel)); 00937 00938 /* Process locked */ 00939 __HAL_LOCK(hdac); 00940 00941 /* Change DAC state */ 00942 hdac->State = HAL_DAC_STATE_BUSY; 00943 00944 /* Get the DAC CR value */ 00945 tmpreg1 = hdac->Instance->CR; 00946 /* Clear BOFFx, TENx, TSELx, WAVEx and MAMPx bits */ 00947 tmpreg1 &= ~(((uint32_t)(DAC_CR_MAMP1 | DAC_CR_WAVE1 | DAC_CR_TSEL1 | DAC_CR_TEN1 | DAC_CR_BOFF1)) << (Channel & 0x10UL)); 00948 /* Configure for the selected DAC channel: buffer output, trigger */ 00949 /* Set TSELx and TENx bits according to DAC_Trigger value */ 00950 /* Set BOFFx bit according to DAC_OutputBuffer value */ 00951 tmpreg2 = (sConfig->DAC_Trigger | sConfig->DAC_OutputBuffer); 00952 /* Calculate CR register value depending on DAC_Channel */ 00953 tmpreg1 |= tmpreg2 << (Channel & 0x10UL); 00954 /* Write to DAC CR */ 00955 hdac->Instance->CR = tmpreg1; 00956 /* Disable wave generation */ 00957 CLEAR_BIT(hdac->Instance->CR, (DAC_CR_WAVE1 << (Channel & 0x10UL))); 00958 00959 /* Change DAC state */ 00960 hdac->State = HAL_DAC_STATE_READY; 00961 00962 /* Process unlocked */ 00963 __HAL_UNLOCK(hdac); 00964 00965 /* Return function status */ 00966 return HAL_OK; 00967 } 00968 00969 /** 00970 * @} 00971 */ 00972 00973 /** @defgroup DAC_Exported_Functions_Group4 Peripheral State and Errors functions 00974 * @brief Peripheral State and Errors functions 00975 * 00976 @verbatim 00977 ============================================================================== 00978 ##### Peripheral State and Errors functions ##### 00979 ============================================================================== 00980 [..] 00981 This subsection provides functions allowing to 00982 (+) Check the DAC state. 00983 (+) Check the DAC Errors. 00984 00985 @endverbatim 00986 * @{ 00987 */ 00988 00989 /** 00990 * @brief return the DAC handle state 00991 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 00992 * the configuration information for the specified DAC. 00993 * @retval HAL state 00994 */ 00995 HAL_DAC_StateTypeDef HAL_DAC_GetState(DAC_HandleTypeDef *hdac) 00996 { 00997 /* Return DAC handle state */ 00998 return hdac->State; 00999 } 01000 01001 01002 /** 01003 * @brief Return the DAC error code 01004 * @param hdac pointer to a DAC_HandleTypeDef structure that contains 01005 * the configuration information for the specified DAC. 01006 * @retval DAC Error Code 01007 */ 01008 uint32_t HAL_DAC_GetError(DAC_HandleTypeDef *hdac) 01009 { 01010 return hdac->ErrorCode; 01011 } 01012 01013 /** 01014 * @} 01015 */ 01016 01017 /** 01018 * @} 01019 */ 01020 01021 /** @addtogroup DAC_Exported_Functions 01022 * @{ 01023 */ 01024 01025 /** @addtogroup DAC_Exported_Functions_Group1 01026 * @{ 01027 */ 01028 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) 01029 /** 01030 * @brief Register a User DAC Callback 01031 * To be used instead of the weak (surcharged) predefined callback 01032 * @param hdac DAC handle 01033 * @param CallbackID ID of the callback to be registered 01034 * This parameter can be one of the following values: 01035 * @arg @ref HAL_DAC_ERROR_INVALID_CALLBACK DAC Error Callback ID 01036 * @arg @ref HAL_DAC_CH1_COMPLETE_CB_ID DAC CH1 Complete Callback ID 01037 * @arg @ref HAL_DAC_CH1_HALF_COMPLETE_CB_ID DAC CH1 Half Complete Callback ID 01038 * @arg @ref HAL_DAC_CH1_ERROR_ID DAC CH1 Error Callback ID 01039 * @arg @ref HAL_DAC_CH1_UNDERRUN_CB_ID DAC CH1 UnderRun Callback ID 01040 * @arg @ref HAL_DAC_CH2_COMPLETE_CB_ID DAC CH2 Complete Callback ID 01041 * @arg @ref HAL_DAC_CH2_HALF_COMPLETE_CB_ID DAC CH2 Half Complete Callback ID 01042 * @arg @ref HAL_DAC_CH2_ERROR_ID DAC CH2 Error Callback ID 01043 * @arg @ref HAL_DAC_CH2_UNDERRUN_CB_ID DAC CH2 UnderRun Callback ID 01044 * @arg @ref HAL_DAC_MSPINIT_CB_ID DAC MSP Init Callback ID 01045 * @arg @ref HAL_DAC_MSPDEINIT_CB_ID DAC MSP DeInit Callback ID 01046 * 01047 * @param pCallback pointer to the Callback function 01048 * @retval status 01049 */ 01050 HAL_StatusTypeDef HAL_DAC_RegisterCallback(DAC_HandleTypeDef *hdac, HAL_DAC_CallbackIDTypeDef CallbackID, 01051 pDAC_CallbackTypeDef pCallback) 01052 { 01053 HAL_StatusTypeDef status = HAL_OK; 01054 01055 if (pCallback == NULL) 01056 { 01057 /* Update the error code */ 01058 hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK; 01059 return HAL_ERROR; 01060 } 01061 01062 /* Process locked */ 01063 __HAL_LOCK(hdac); 01064 01065 if (hdac->State == HAL_DAC_STATE_READY) 01066 { 01067 switch (CallbackID) 01068 { 01069 case HAL_DAC_CH1_COMPLETE_CB_ID : 01070 hdac->ConvCpltCallbackCh1 = pCallback; 01071 break; 01072 case HAL_DAC_CH1_HALF_COMPLETE_CB_ID : 01073 hdac->ConvHalfCpltCallbackCh1 = pCallback; 01074 break; 01075 case HAL_DAC_CH1_ERROR_ID : 01076 hdac->ErrorCallbackCh1 = pCallback; 01077 break; 01078 case HAL_DAC_CH1_UNDERRUN_CB_ID : 01079 hdac->DMAUnderrunCallbackCh1 = pCallback; 01080 break; 01081 #if defined(DAC_CHANNEL2_SUPPORT) 01082 case HAL_DAC_CH2_COMPLETE_CB_ID : 01083 hdac->ConvCpltCallbackCh2 = pCallback; 01084 break; 01085 case HAL_DAC_CH2_HALF_COMPLETE_CB_ID : 01086 hdac->ConvHalfCpltCallbackCh2 = pCallback; 01087 break; 01088 case HAL_DAC_CH2_ERROR_ID : 01089 hdac->ErrorCallbackCh2 = pCallback; 01090 break; 01091 case HAL_DAC_CH2_UNDERRUN_CB_ID : 01092 hdac->DMAUnderrunCallbackCh2 = pCallback; 01093 break; 01094 #endif /* DAC_CHANNEL2_SUPPORT */ 01095 case HAL_DAC_MSPINIT_CB_ID : 01096 hdac->MspInitCallback = pCallback; 01097 break; 01098 case HAL_DAC_MSPDEINIT_CB_ID : 01099 hdac->MspDeInitCallback = pCallback; 01100 break; 01101 default : 01102 /* Update the error code */ 01103 hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK; 01104 /* update return status */ 01105 status = HAL_ERROR; 01106 break; 01107 } 01108 } 01109 else if (hdac->State == HAL_DAC_STATE_RESET) 01110 { 01111 switch (CallbackID) 01112 { 01113 case HAL_DAC_MSPINIT_CB_ID : 01114 hdac->MspInitCallback = pCallback; 01115 break; 01116 case HAL_DAC_MSPDEINIT_CB_ID : 01117 hdac->MspDeInitCallback = pCallback; 01118 break; 01119 default : 01120 /* Update the error code */ 01121 hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK; 01122 /* update return status */ 01123 status = HAL_ERROR; 01124 break; 01125 } 01126 } 01127 else 01128 { 01129 /* Update the error code */ 01130 hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK; 01131 /* update return status */ 01132 status = HAL_ERROR; 01133 } 01134 01135 /* Release Lock */ 01136 __HAL_UNLOCK(hdac); 01137 return status; 01138 } 01139 01140 /** 01141 * @brief Unregister a User DAC Callback 01142 * DAC Callback is redirected to the weak (surcharged) predefined callback 01143 * @param hdac DAC handle 01144 * @param CallbackID ID of the callback to be unregistered 01145 * This parameter can be one of the following values: 01146 * @arg @ref HAL_DAC_CH1_COMPLETE_CB_ID DAC CH1 transfer Complete Callback ID 01147 * @arg @ref HAL_DAC_CH1_HALF_COMPLETE_CB_ID DAC CH1 Half Complete Callback ID 01148 * @arg @ref HAL_DAC_CH1_ERROR_ID DAC CH1 Error Callback ID 01149 * @arg @ref HAL_DAC_CH1_UNDERRUN_CB_ID DAC CH1 UnderRun Callback ID 01150 * @arg @ref HAL_DAC_CH2_COMPLETE_CB_ID DAC CH2 Complete Callback ID 01151 * @arg @ref HAL_DAC_CH2_HALF_COMPLETE_CB_ID DAC CH2 Half Complete Callback ID 01152 * @arg @ref HAL_DAC_CH2_ERROR_ID DAC CH2 Error Callback ID 01153 * @arg @ref HAL_DAC_CH2_UNDERRUN_CB_ID DAC CH2 UnderRun Callback ID 01154 * @arg @ref HAL_DAC_MSPINIT_CB_ID DAC MSP Init Callback ID 01155 * @arg @ref HAL_DAC_MSPDEINIT_CB_ID DAC MSP DeInit Callback ID 01156 * @arg @ref HAL_DAC_ALL_CB_ID DAC All callbacks 01157 * @retval status 01158 */ 01159 HAL_StatusTypeDef HAL_DAC_UnRegisterCallback(DAC_HandleTypeDef *hdac, HAL_DAC_CallbackIDTypeDef CallbackID) 01160 { 01161 HAL_StatusTypeDef status = HAL_OK; 01162 01163 /* Process locked */ 01164 __HAL_LOCK(hdac); 01165 01166 if (hdac->State == HAL_DAC_STATE_READY) 01167 { 01168 switch (CallbackID) 01169 { 01170 case HAL_DAC_CH1_COMPLETE_CB_ID : 01171 hdac->ConvCpltCallbackCh1 = HAL_DAC_ConvCpltCallbackCh1; 01172 break; 01173 case HAL_DAC_CH1_HALF_COMPLETE_CB_ID : 01174 hdac->ConvHalfCpltCallbackCh1 = HAL_DAC_ConvHalfCpltCallbackCh1; 01175 break; 01176 case HAL_DAC_CH1_ERROR_ID : 01177 hdac->ErrorCallbackCh1 = HAL_DAC_ErrorCallbackCh1; 01178 break; 01179 case HAL_DAC_CH1_UNDERRUN_CB_ID : 01180 hdac->DMAUnderrunCallbackCh1 = HAL_DAC_DMAUnderrunCallbackCh1; 01181 break; 01182 #if defined(DAC_CHANNEL2_SUPPORT) 01183 case HAL_DAC_CH2_COMPLETE_CB_ID : 01184 hdac->ConvCpltCallbackCh2 = HAL_DACEx_ConvCpltCallbackCh2; 01185 break; 01186 case HAL_DAC_CH2_HALF_COMPLETE_CB_ID : 01187 hdac->ConvHalfCpltCallbackCh2 = HAL_DACEx_ConvHalfCpltCallbackCh2; 01188 break; 01189 case HAL_DAC_CH2_ERROR_ID : 01190 hdac->ErrorCallbackCh2 = HAL_DACEx_ErrorCallbackCh2; 01191 break; 01192 case HAL_DAC_CH2_UNDERRUN_CB_ID : 01193 hdac->DMAUnderrunCallbackCh2 = HAL_DACEx_DMAUnderrunCallbackCh2; 01194 break; 01195 #endif /* DAC_CHANNEL2_SUPPORT */ 01196 case HAL_DAC_MSPINIT_CB_ID : 01197 hdac->MspInitCallback = HAL_DAC_MspInit; 01198 break; 01199 case HAL_DAC_MSPDEINIT_CB_ID : 01200 hdac->MspDeInitCallback = HAL_DAC_MspDeInit; 01201 break; 01202 case HAL_DAC_ALL_CB_ID : 01203 hdac->ConvCpltCallbackCh1 = HAL_DAC_ConvCpltCallbackCh1; 01204 hdac->ConvHalfCpltCallbackCh1 = HAL_DAC_ConvHalfCpltCallbackCh1; 01205 hdac->ErrorCallbackCh1 = HAL_DAC_ErrorCallbackCh1; 01206 hdac->DMAUnderrunCallbackCh1 = HAL_DAC_DMAUnderrunCallbackCh1; 01207 #if defined(DAC_CHANNEL2_SUPPORT) 01208 hdac->ConvCpltCallbackCh2 = HAL_DACEx_ConvCpltCallbackCh2; 01209 hdac->ConvHalfCpltCallbackCh2 = HAL_DACEx_ConvHalfCpltCallbackCh2; 01210 hdac->ErrorCallbackCh2 = HAL_DACEx_ErrorCallbackCh2; 01211 hdac->DMAUnderrunCallbackCh2 = HAL_DACEx_DMAUnderrunCallbackCh2; 01212 #endif /* DAC_CHANNEL2_SUPPORT */ 01213 hdac->MspInitCallback = HAL_DAC_MspInit; 01214 hdac->MspDeInitCallback = HAL_DAC_MspDeInit; 01215 break; 01216 default : 01217 /* Update the error code */ 01218 hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK; 01219 /* update return status */ 01220 status = HAL_ERROR; 01221 break; 01222 } 01223 } 01224 else if (hdac->State == HAL_DAC_STATE_RESET) 01225 { 01226 switch (CallbackID) 01227 { 01228 case HAL_DAC_MSPINIT_CB_ID : 01229 hdac->MspInitCallback = HAL_DAC_MspInit; 01230 break; 01231 case HAL_DAC_MSPDEINIT_CB_ID : 01232 hdac->MspDeInitCallback = HAL_DAC_MspDeInit; 01233 break; 01234 default : 01235 /* Update the error code */ 01236 hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK; 01237 /* update return status */ 01238 status = HAL_ERROR; 01239 break; 01240 } 01241 } 01242 else 01243 { 01244 /* Update the error code */ 01245 hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK; 01246 /* update return status */ 01247 status = HAL_ERROR; 01248 } 01249 01250 /* Release Lock */ 01251 __HAL_UNLOCK(hdac); 01252 return status; 01253 } 01254 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ 01255 01256 /** 01257 * @} 01258 */ 01259 01260 /** 01261 * @} 01262 */ 01263 01264 /** @addtogroup DAC_Private_Functions 01265 * @{ 01266 */ 01267 01268 /** 01269 * @brief DMA conversion complete callback. 01270 * @param hdma pointer to a DMA_HandleTypeDef structure that contains 01271 * the configuration information for the specified DMA module. 01272 * @retval None 01273 */ 01274 void DAC_DMAConvCpltCh1(DMA_HandleTypeDef *hdma) 01275 { 01276 DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; 01277 01278 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) 01279 hdac->ConvCpltCallbackCh1(hdac); 01280 #else 01281 HAL_DAC_ConvCpltCallbackCh1(hdac); 01282 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ 01283 01284 hdac->State = HAL_DAC_STATE_READY; 01285 } 01286 01287 /** 01288 * @brief DMA half transfer complete callback. 01289 * @param hdma pointer to a DMA_HandleTypeDef structure that contains 01290 * the configuration information for the specified DMA module. 01291 * @retval None 01292 */ 01293 void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma) 01294 { 01295 DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; 01296 /* Conversion complete callback */ 01297 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) 01298 hdac->ConvHalfCpltCallbackCh1(hdac); 01299 #else 01300 HAL_DAC_ConvHalfCpltCallbackCh1(hdac); 01301 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ 01302 } 01303 01304 /** 01305 * @brief DMA error callback 01306 * @param hdma pointer to a DMA_HandleTypeDef structure that contains 01307 * the configuration information for the specified DMA module. 01308 * @retval None 01309 */ 01310 void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma) 01311 { 01312 DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; 01313 01314 /* Set DAC error code to DMA error */ 01315 hdac->ErrorCode |= HAL_DAC_ERROR_DMA; 01316 01317 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) 01318 hdac->ErrorCallbackCh1(hdac); 01319 #else 01320 HAL_DAC_ErrorCallbackCh1(hdac); 01321 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ 01322 01323 hdac->State = HAL_DAC_STATE_READY; 01324 } 01325 01326 /** 01327 * @} 01328 */ 01329 01330 /** 01331 * @} 01332 */ 01333 01334 #endif /* DAC */ 01335 01336 #endif /* HAL_DAC_MODULE_ENABLED */ 01337 01338 /** 01339 * @} 01340 */ 01341 01342 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/