inport from local

Dependents:   Hobbyking_Cheetah_0511

Committer:
NYX
Date:
Mon Mar 16 06:35:48 2020 +0000
Revision:
0:85b3fd62ea1a
reinport to mbed;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NYX 0:85b3fd62ea1a 1 /**
NYX 0:85b3fd62ea1a 2 ******************************************************************************
NYX 0:85b3fd62ea1a 3 * @file stm32f4xx_hal_dac.c
NYX 0:85b3fd62ea1a 4 * @author MCD Application Team
NYX 0:85b3fd62ea1a 5 * @version V1.7.1
NYX 0:85b3fd62ea1a 6 * @date 14-April-2017
NYX 0:85b3fd62ea1a 7 * @brief DAC HAL module driver.
NYX 0:85b3fd62ea1a 8 * This file provides firmware functions to manage the following
NYX 0:85b3fd62ea1a 9 * functionalities of the Digital to Analog Converter (DAC) peripheral:
NYX 0:85b3fd62ea1a 10 * + Initialization and de-initialization functions
NYX 0:85b3fd62ea1a 11 * + IO operation functions
NYX 0:85b3fd62ea1a 12 * + Peripheral Control functions
NYX 0:85b3fd62ea1a 13 * + Peripheral State and Errors functions
NYX 0:85b3fd62ea1a 14 *
NYX 0:85b3fd62ea1a 15 *
NYX 0:85b3fd62ea1a 16 @verbatim
NYX 0:85b3fd62ea1a 17 ==============================================================================
NYX 0:85b3fd62ea1a 18 ##### DAC Peripheral features #####
NYX 0:85b3fd62ea1a 19 ==============================================================================
NYX 0:85b3fd62ea1a 20 [..]
NYX 0:85b3fd62ea1a 21 *** DAC Channels ***
NYX 0:85b3fd62ea1a 22 ====================
NYX 0:85b3fd62ea1a 23 [..]
NYX 0:85b3fd62ea1a 24 The device integrates two 12-bit Digital Analog Converters that can
NYX 0:85b3fd62ea1a 25 be used independently or simultaneously (dual mode):
NYX 0:85b3fd62ea1a 26 (#) DAC channel1 with DAC_OUT1 (PA4) as output
NYX 0:85b3fd62ea1a 27 (#) DAC channel2 with DAC_OUT2 (PA5) as output
NYX 0:85b3fd62ea1a 28
NYX 0:85b3fd62ea1a 29 *** DAC Triggers ***
NYX 0:85b3fd62ea1a 30 ====================
NYX 0:85b3fd62ea1a 31 [..]
NYX 0:85b3fd62ea1a 32 Digital to Analog conversion can be non-triggered using DAC_TRIGGER_NONE
NYX 0:85b3fd62ea1a 33 and DAC_OUT1/DAC_OUT2 is available once writing to DHRx register.
NYX 0:85b3fd62ea1a 34 [..]
NYX 0:85b3fd62ea1a 35 Digital to Analog conversion can be triggered by:
NYX 0:85b3fd62ea1a 36 (#) External event: EXTI Line 9 (any GPIOx_Pin9) using DAC_TRIGGER_EXT_IT9.
NYX 0:85b3fd62ea1a 37 The used pin (GPIOx_Pin9) must be configured in input mode.
NYX 0:85b3fd62ea1a 38
NYX 0:85b3fd62ea1a 39 (#) Timers TRGO: TIM2, TIM4, TIM5, TIM6, TIM7 and TIM8
NYX 0:85b3fd62ea1a 40 (DAC_TRIGGER_T2_TRGO, DAC_TRIGGER_T4_TRGO...)
NYX 0:85b3fd62ea1a 41
NYX 0:85b3fd62ea1a 42 (#) Software using DAC_TRIGGER_SOFTWARE
NYX 0:85b3fd62ea1a 43
NYX 0:85b3fd62ea1a 44 *** DAC Buffer mode feature ***
NYX 0:85b3fd62ea1a 45 ===============================
NYX 0:85b3fd62ea1a 46 [..]
NYX 0:85b3fd62ea1a 47 Each DAC channel integrates an output buffer that can be used to
NYX 0:85b3fd62ea1a 48 reduce the output impedance, and to drive external loads directly
NYX 0:85b3fd62ea1a 49 without having to add an external operational amplifier.
NYX 0:85b3fd62ea1a 50 To enable, the output buffer use
NYX 0:85b3fd62ea1a 51 sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
NYX 0:85b3fd62ea1a 52 [..]
NYX 0:85b3fd62ea1a 53 (@) Refer to the device datasheet for more details about output
NYX 0:85b3fd62ea1a 54 impedance value with and without output buffer.
NYX 0:85b3fd62ea1a 55
NYX 0:85b3fd62ea1a 56 *** DAC wave generation feature ***
NYX 0:85b3fd62ea1a 57 ===================================
NYX 0:85b3fd62ea1a 58 [..]
NYX 0:85b3fd62ea1a 59 Both DAC channels can be used to generate
NYX 0:85b3fd62ea1a 60 (#) Noise wave
NYX 0:85b3fd62ea1a 61 (#) Triangle wave
NYX 0:85b3fd62ea1a 62
NYX 0:85b3fd62ea1a 63 *** DAC data format ***
NYX 0:85b3fd62ea1a 64 =======================
NYX 0:85b3fd62ea1a 65 [..]
NYX 0:85b3fd62ea1a 66 The DAC data format can be:
NYX 0:85b3fd62ea1a 67 (#) 8-bit right alignment using DAC_ALIGN_8B_R
NYX 0:85b3fd62ea1a 68 (#) 12-bit left alignment using DAC_ALIGN_12B_L
NYX 0:85b3fd62ea1a 69 (#) 12-bit right alignment using DAC_ALIGN_12B_R
NYX 0:85b3fd62ea1a 70
NYX 0:85b3fd62ea1a 71 *** DAC data value to voltage correspondence ***
NYX 0:85b3fd62ea1a 72 ================================================
NYX 0:85b3fd62ea1a 73 [..]
NYX 0:85b3fd62ea1a 74 The analog output voltage on each DAC channel pin is determined
NYX 0:85b3fd62ea1a 75 by the following equation:
NYX 0:85b3fd62ea1a 76 DAC_OUTx = VREF+ * DOR / 4095
NYX 0:85b3fd62ea1a 77 with DOR is the Data Output Register
NYX 0:85b3fd62ea1a 78 VEF+ is the input voltage reference (refer to the device datasheet)
NYX 0:85b3fd62ea1a 79 e.g. To set DAC_OUT1 to 0.7V, use
NYX 0:85b3fd62ea1a 80 Assuming that VREF+ = 3.3V, DAC_OUT1 = (3.3 * 868) / 4095 = 0.7V
NYX 0:85b3fd62ea1a 81
NYX 0:85b3fd62ea1a 82 *** DMA requests ***
NYX 0:85b3fd62ea1a 83 =====================
NYX 0:85b3fd62ea1a 84 [..]
NYX 0:85b3fd62ea1a 85 A DMA1 request can be generated when an external trigger (but not
NYX 0:85b3fd62ea1a 86 a software trigger) occurs if DMA1 requests are enabled using
NYX 0:85b3fd62ea1a 87 HAL_DAC_Start_DMA()
NYX 0:85b3fd62ea1a 88 [..]
NYX 0:85b3fd62ea1a 89 DMA1 requests are mapped as following:
NYX 0:85b3fd62ea1a 90 (#) DAC channel1 : mapped on DMA1 Stream5 channel7 which must be
NYX 0:85b3fd62ea1a 91 already configured
NYX 0:85b3fd62ea1a 92 (#) DAC channel2 : mapped on DMA1 Stream6 channel7 which must be
NYX 0:85b3fd62ea1a 93 already configured
NYX 0:85b3fd62ea1a 94
NYX 0:85b3fd62ea1a 95 -@- For Dual mode and specific signal (Triangle and noise) generation please
NYX 0:85b3fd62ea1a 96 refer to Extension Features Driver description
NYX 0:85b3fd62ea1a 97
NYX 0:85b3fd62ea1a 98
NYX 0:85b3fd62ea1a 99 ##### How to use this driver #####
NYX 0:85b3fd62ea1a 100 ==============================================================================
NYX 0:85b3fd62ea1a 101 [..]
NYX 0:85b3fd62ea1a 102 (+) DAC APB clock must be enabled to get write access to DAC
NYX 0:85b3fd62ea1a 103 registers using HAL_DAC_Init()
NYX 0:85b3fd62ea1a 104 (+) Configure DAC_OUTx (DAC_OUT1: PA4, DAC_OUT2: PA5) in analog mode.
NYX 0:85b3fd62ea1a 105 (+) Configure the DAC channel using HAL_DAC_ConfigChannel() function.
NYX 0:85b3fd62ea1a 106 (+) Enable the DAC channel using HAL_DAC_Start() or HAL_DAC_Start_DMA functions
NYX 0:85b3fd62ea1a 107
NYX 0:85b3fd62ea1a 108 *** Polling mode IO operation ***
NYX 0:85b3fd62ea1a 109 =================================
NYX 0:85b3fd62ea1a 110 [..]
NYX 0:85b3fd62ea1a 111 (+) Start the DAC peripheral using HAL_DAC_Start()
NYX 0:85b3fd62ea1a 112 (+) To read the DAC last data output value, use the HAL_DAC_GetValue() function.
NYX 0:85b3fd62ea1a 113 (+) Stop the DAC peripheral using HAL_DAC_Stop()
NYX 0:85b3fd62ea1a 114
NYX 0:85b3fd62ea1a 115 *** DMA mode IO operation ***
NYX 0:85b3fd62ea1a 116 ==============================
NYX 0:85b3fd62ea1a 117 [..]
NYX 0:85b3fd62ea1a 118 (+) Start the DAC peripheral using HAL_DAC_Start_DMA(), at this stage the user specify the length
NYX 0:85b3fd62ea1a 119 of data to be transferred at each end of conversion
NYX 0:85b3fd62ea1a 120 (+) At The end of data transfer HAL_DAC_ConvCpltCallbackCh1()or HAL_DAC_ConvCpltCallbackCh2()
NYX 0:85b3fd62ea1a 121 function is executed and user can add his own code by customization of function pointer
NYX 0:85b3fd62ea1a 122 HAL_DAC_ConvCpltCallbackCh1 or HAL_DAC_ConvCpltCallbackCh2
NYX 0:85b3fd62ea1a 123 (+) In case of transfer Error, HAL_DAC_ErrorCallbackCh1() function is executed and user can
NYX 0:85b3fd62ea1a 124 add his own code by customization of function pointer HAL_DAC_ErrorCallbackCh1
NYX 0:85b3fd62ea1a 125 (+) Stop the DAC peripheral using HAL_DAC_Stop_DMA()
NYX 0:85b3fd62ea1a 126
NYX 0:85b3fd62ea1a 127 *** DAC HAL driver macros list ***
NYX 0:85b3fd62ea1a 128 =============================================
NYX 0:85b3fd62ea1a 129 [..]
NYX 0:85b3fd62ea1a 130 Below the list of most used macros in DAC HAL driver.
NYX 0:85b3fd62ea1a 131
NYX 0:85b3fd62ea1a 132 (+) __HAL_DAC_ENABLE : Enable the DAC peripheral
NYX 0:85b3fd62ea1a 133 (+) __HAL_DAC_DISABLE : Disable the DAC peripheral
NYX 0:85b3fd62ea1a 134 (+) __HAL_DAC_CLEAR_FLAG: Clear the DAC's pending flags
NYX 0:85b3fd62ea1a 135 (+) __HAL_DAC_GET_FLAG: Get the selected DAC's flag status
NYX 0:85b3fd62ea1a 136
NYX 0:85b3fd62ea1a 137 [..]
NYX 0:85b3fd62ea1a 138 (@) You can refer to the DAC HAL driver header file for more useful macros
NYX 0:85b3fd62ea1a 139
NYX 0:85b3fd62ea1a 140 @endverbatim
NYX 0:85b3fd62ea1a 141 ******************************************************************************
NYX 0:85b3fd62ea1a 142 * @attention
NYX 0:85b3fd62ea1a 143 *
NYX 0:85b3fd62ea1a 144 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
NYX 0:85b3fd62ea1a 145 *
NYX 0:85b3fd62ea1a 146 * Redistribution and use in source and binary forms, with or without modification,
NYX 0:85b3fd62ea1a 147 * are permitted provided that the following conditions are met:
NYX 0:85b3fd62ea1a 148 * 1. Redistributions of source code must retain the above copyright notice,
NYX 0:85b3fd62ea1a 149 * this list of conditions and the following disclaimer.
NYX 0:85b3fd62ea1a 150 * 2. Redistributions in binary form must reproduce the above copyright notice,
NYX 0:85b3fd62ea1a 151 * this list of conditions and the following disclaimer in the documentation
NYX 0:85b3fd62ea1a 152 * and/or other materials provided with the distribution.
NYX 0:85b3fd62ea1a 153 * 3. Neither the name of STMicroelectronics nor the names of its contributors
NYX 0:85b3fd62ea1a 154 * may be used to endorse or promote products derived from this software
NYX 0:85b3fd62ea1a 155 * without specific prior written permission.
NYX 0:85b3fd62ea1a 156 *
NYX 0:85b3fd62ea1a 157 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
NYX 0:85b3fd62ea1a 158 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
NYX 0:85b3fd62ea1a 159 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
NYX 0:85b3fd62ea1a 160 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
NYX 0:85b3fd62ea1a 161 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
NYX 0:85b3fd62ea1a 162 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
NYX 0:85b3fd62ea1a 163 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
NYX 0:85b3fd62ea1a 164 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
NYX 0:85b3fd62ea1a 165 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
NYX 0:85b3fd62ea1a 166 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
NYX 0:85b3fd62ea1a 167 *
NYX 0:85b3fd62ea1a 168 ******************************************************************************
NYX 0:85b3fd62ea1a 169 */
NYX 0:85b3fd62ea1a 170
NYX 0:85b3fd62ea1a 171
NYX 0:85b3fd62ea1a 172 /* Includes ------------------------------------------------------------------*/
NYX 0:85b3fd62ea1a 173 #include "stm32f4xx_hal.h"
NYX 0:85b3fd62ea1a 174
NYX 0:85b3fd62ea1a 175 /** @addtogroup STM32F4xx_HAL_Driver
NYX 0:85b3fd62ea1a 176 * @{
NYX 0:85b3fd62ea1a 177 */
NYX 0:85b3fd62ea1a 178
NYX 0:85b3fd62ea1a 179 /** @defgroup DAC DAC
NYX 0:85b3fd62ea1a 180 * @brief DAC driver modules
NYX 0:85b3fd62ea1a 181 * @{
NYX 0:85b3fd62ea1a 182 */
NYX 0:85b3fd62ea1a 183
NYX 0:85b3fd62ea1a 184 #ifdef HAL_DAC_MODULE_ENABLED
NYX 0:85b3fd62ea1a 185
NYX 0:85b3fd62ea1a 186 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) ||\
NYX 0:85b3fd62ea1a 187 defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
NYX 0:85b3fd62ea1a 188 defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F446xx) ||\
NYX 0:85b3fd62ea1a 189 defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F413xx) || defined(STM32F423xx)
NYX 0:85b3fd62ea1a 190 /* Private typedef -----------------------------------------------------------*/
NYX 0:85b3fd62ea1a 191 /* Private define ------------------------------------------------------------*/
NYX 0:85b3fd62ea1a 192 /* Private macro -------------------------------------------------------------*/
NYX 0:85b3fd62ea1a 193 /* Private variables ---------------------------------------------------------*/
NYX 0:85b3fd62ea1a 194 /** @addtogroup DAC_Private_Functions
NYX 0:85b3fd62ea1a 195 * @{
NYX 0:85b3fd62ea1a 196 */
NYX 0:85b3fd62ea1a 197 /* Private function prototypes -----------------------------------------------*/
NYX 0:85b3fd62ea1a 198 static void DAC_DMAConvCpltCh1(DMA_HandleTypeDef *hdma);
NYX 0:85b3fd62ea1a 199 static void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma);
NYX 0:85b3fd62ea1a 200 static void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma);
NYX 0:85b3fd62ea1a 201 /**
NYX 0:85b3fd62ea1a 202 * @}
NYX 0:85b3fd62ea1a 203 */
NYX 0:85b3fd62ea1a 204
NYX 0:85b3fd62ea1a 205 /* Exported functions --------------------------------------------------------*/
NYX 0:85b3fd62ea1a 206 /** @defgroup DAC_Exported_Functions DAC Exported Functions
NYX 0:85b3fd62ea1a 207 * @{
NYX 0:85b3fd62ea1a 208 */
NYX 0:85b3fd62ea1a 209
NYX 0:85b3fd62ea1a 210 /** @defgroup DAC_Exported_Functions_Group1 Initialization and de-initialization functions
NYX 0:85b3fd62ea1a 211 * @brief Initialization and Configuration functions
NYX 0:85b3fd62ea1a 212 *
NYX 0:85b3fd62ea1a 213 @verbatim
NYX 0:85b3fd62ea1a 214 ==============================================================================
NYX 0:85b3fd62ea1a 215 ##### Initialization and de-initialization functions #####
NYX 0:85b3fd62ea1a 216 ==============================================================================
NYX 0:85b3fd62ea1a 217 [..] This section provides functions allowing to:
NYX 0:85b3fd62ea1a 218 (+) Initialize and configure the DAC.
NYX 0:85b3fd62ea1a 219 (+) De-initialize the DAC.
NYX 0:85b3fd62ea1a 220
NYX 0:85b3fd62ea1a 221 @endverbatim
NYX 0:85b3fd62ea1a 222 * @{
NYX 0:85b3fd62ea1a 223 */
NYX 0:85b3fd62ea1a 224
NYX 0:85b3fd62ea1a 225 /**
NYX 0:85b3fd62ea1a 226 * @brief Initializes the DAC peripheral according to the specified parameters
NYX 0:85b3fd62ea1a 227 * in the DAC_InitStruct.
NYX 0:85b3fd62ea1a 228 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 229 * the configuration information for the specified DAC.
NYX 0:85b3fd62ea1a 230 * @retval HAL status
NYX 0:85b3fd62ea1a 231 */
NYX 0:85b3fd62ea1a 232 HAL_StatusTypeDef HAL_DAC_Init(DAC_HandleTypeDef* hdac)
NYX 0:85b3fd62ea1a 233 {
NYX 0:85b3fd62ea1a 234 /* Check DAC handle */
NYX 0:85b3fd62ea1a 235 if(hdac == NULL)
NYX 0:85b3fd62ea1a 236 {
NYX 0:85b3fd62ea1a 237 return HAL_ERROR;
NYX 0:85b3fd62ea1a 238 }
NYX 0:85b3fd62ea1a 239 /* Check the parameters */
NYX 0:85b3fd62ea1a 240 assert_param(IS_DAC_ALL_INSTANCE(hdac->Instance));
NYX 0:85b3fd62ea1a 241
NYX 0:85b3fd62ea1a 242 if(hdac->State == HAL_DAC_STATE_RESET)
NYX 0:85b3fd62ea1a 243 {
NYX 0:85b3fd62ea1a 244 /* Allocate lock resource and initialize it */
NYX 0:85b3fd62ea1a 245 hdac->Lock = HAL_UNLOCKED;
NYX 0:85b3fd62ea1a 246 /* Init the low level hardware */
NYX 0:85b3fd62ea1a 247 HAL_DAC_MspInit(hdac);
NYX 0:85b3fd62ea1a 248 }
NYX 0:85b3fd62ea1a 249
NYX 0:85b3fd62ea1a 250 /* Initialize the DAC state*/
NYX 0:85b3fd62ea1a 251 hdac->State = HAL_DAC_STATE_BUSY;
NYX 0:85b3fd62ea1a 252
NYX 0:85b3fd62ea1a 253 /* Set DAC error code to none */
NYX 0:85b3fd62ea1a 254 hdac->ErrorCode = HAL_DAC_ERROR_NONE;
NYX 0:85b3fd62ea1a 255
NYX 0:85b3fd62ea1a 256 /* Initialize the DAC state*/
NYX 0:85b3fd62ea1a 257 hdac->State = HAL_DAC_STATE_READY;
NYX 0:85b3fd62ea1a 258
NYX 0:85b3fd62ea1a 259 /* Return function status */
NYX 0:85b3fd62ea1a 260 return HAL_OK;
NYX 0:85b3fd62ea1a 261 }
NYX 0:85b3fd62ea1a 262
NYX 0:85b3fd62ea1a 263 /**
NYX 0:85b3fd62ea1a 264 * @brief Deinitializes the DAC peripheral registers to their default reset values.
NYX 0:85b3fd62ea1a 265 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 266 * the configuration information for the specified DAC.
NYX 0:85b3fd62ea1a 267 * @retval HAL status
NYX 0:85b3fd62ea1a 268 */
NYX 0:85b3fd62ea1a 269 HAL_StatusTypeDef HAL_DAC_DeInit(DAC_HandleTypeDef* hdac)
NYX 0:85b3fd62ea1a 270 {
NYX 0:85b3fd62ea1a 271 /* Check DAC handle */
NYX 0:85b3fd62ea1a 272 if(hdac == NULL)
NYX 0:85b3fd62ea1a 273 {
NYX 0:85b3fd62ea1a 274 return HAL_ERROR;
NYX 0:85b3fd62ea1a 275 }
NYX 0:85b3fd62ea1a 276
NYX 0:85b3fd62ea1a 277 /* Check the parameters */
NYX 0:85b3fd62ea1a 278 assert_param(IS_DAC_ALL_INSTANCE(hdac->Instance));
NYX 0:85b3fd62ea1a 279
NYX 0:85b3fd62ea1a 280 /* Change DAC state */
NYX 0:85b3fd62ea1a 281 hdac->State = HAL_DAC_STATE_BUSY;
NYX 0:85b3fd62ea1a 282
NYX 0:85b3fd62ea1a 283 /* DeInit the low level hardware */
NYX 0:85b3fd62ea1a 284 HAL_DAC_MspDeInit(hdac);
NYX 0:85b3fd62ea1a 285
NYX 0:85b3fd62ea1a 286 /* Set DAC error code to none */
NYX 0:85b3fd62ea1a 287 hdac->ErrorCode = HAL_DAC_ERROR_NONE;
NYX 0:85b3fd62ea1a 288
NYX 0:85b3fd62ea1a 289 /* Change DAC state */
NYX 0:85b3fd62ea1a 290 hdac->State = HAL_DAC_STATE_RESET;
NYX 0:85b3fd62ea1a 291
NYX 0:85b3fd62ea1a 292 /* Release Lock */
NYX 0:85b3fd62ea1a 293 __HAL_UNLOCK(hdac);
NYX 0:85b3fd62ea1a 294
NYX 0:85b3fd62ea1a 295 /* Return function status */
NYX 0:85b3fd62ea1a 296 return HAL_OK;
NYX 0:85b3fd62ea1a 297 }
NYX 0:85b3fd62ea1a 298
NYX 0:85b3fd62ea1a 299 /**
NYX 0:85b3fd62ea1a 300 * @brief Initializes the DAC MSP.
NYX 0:85b3fd62ea1a 301 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 302 * the configuration information for the specified DAC.
NYX 0:85b3fd62ea1a 303 * @retval None
NYX 0:85b3fd62ea1a 304 */
NYX 0:85b3fd62ea1a 305 __weak void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac)
NYX 0:85b3fd62ea1a 306 {
NYX 0:85b3fd62ea1a 307 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 308 UNUSED(hdac);
NYX 0:85b3fd62ea1a 309 /* NOTE : This function Should not be modified, when the callback is needed,
NYX 0:85b3fd62ea1a 310 the HAL_DAC_MspInit could be implemented in the user file
NYX 0:85b3fd62ea1a 311 */
NYX 0:85b3fd62ea1a 312 }
NYX 0:85b3fd62ea1a 313
NYX 0:85b3fd62ea1a 314 /**
NYX 0:85b3fd62ea1a 315 * @brief DeInitializes the DAC MSP.
NYX 0:85b3fd62ea1a 316 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 317 * the configuration information for the specified DAC.
NYX 0:85b3fd62ea1a 318 * @retval None
NYX 0:85b3fd62ea1a 319 */
NYX 0:85b3fd62ea1a 320 __weak void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac)
NYX 0:85b3fd62ea1a 321 {
NYX 0:85b3fd62ea1a 322 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 323 UNUSED(hdac);
NYX 0:85b3fd62ea1a 324 /* NOTE : This function Should not be modified, when the callback is needed,
NYX 0:85b3fd62ea1a 325 the HAL_DAC_MspDeInit could be implemented in the user file
NYX 0:85b3fd62ea1a 326 */
NYX 0:85b3fd62ea1a 327 }
NYX 0:85b3fd62ea1a 328
NYX 0:85b3fd62ea1a 329 /**
NYX 0:85b3fd62ea1a 330 * @}
NYX 0:85b3fd62ea1a 331 */
NYX 0:85b3fd62ea1a 332
NYX 0:85b3fd62ea1a 333 /** @defgroup DAC_Exported_Functions_Group2 IO operation functions
NYX 0:85b3fd62ea1a 334 * @brief IO operation functions
NYX 0:85b3fd62ea1a 335 *
NYX 0:85b3fd62ea1a 336 @verbatim
NYX 0:85b3fd62ea1a 337 ==============================================================================
NYX 0:85b3fd62ea1a 338 ##### IO operation functions #####
NYX 0:85b3fd62ea1a 339 ==============================================================================
NYX 0:85b3fd62ea1a 340 [..] This section provides functions allowing to:
NYX 0:85b3fd62ea1a 341 (+) Start conversion.
NYX 0:85b3fd62ea1a 342 (+) Stop conversion.
NYX 0:85b3fd62ea1a 343 (+) Start conversion and enable DMA transfer.
NYX 0:85b3fd62ea1a 344 (+) Stop conversion and disable DMA transfer.
NYX 0:85b3fd62ea1a 345 (+) Get result of conversion.
NYX 0:85b3fd62ea1a 346
NYX 0:85b3fd62ea1a 347 @endverbatim
NYX 0:85b3fd62ea1a 348 * @{
NYX 0:85b3fd62ea1a 349 */
NYX 0:85b3fd62ea1a 350
NYX 0:85b3fd62ea1a 351 /**
NYX 0:85b3fd62ea1a 352 * @brief Enables DAC and starts conversion of channel.
NYX 0:85b3fd62ea1a 353 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 354 * the configuration information for the specified DAC.
NYX 0:85b3fd62ea1a 355 * @param Channel: The selected DAC channel.
NYX 0:85b3fd62ea1a 356 * This parameter can be one of the following values:
NYX 0:85b3fd62ea1a 357 * @arg DAC_CHANNEL_1: DAC Channel1 selected
NYX 0:85b3fd62ea1a 358 * @arg DAC_CHANNEL_2: DAC Channel2 selected
NYX 0:85b3fd62ea1a 359 * @retval HAL status
NYX 0:85b3fd62ea1a 360 */
NYX 0:85b3fd62ea1a 361 HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel)
NYX 0:85b3fd62ea1a 362 {
NYX 0:85b3fd62ea1a 363 uint32_t tmp1 = 0U, tmp2 = 0U;
NYX 0:85b3fd62ea1a 364
NYX 0:85b3fd62ea1a 365 /* Check the parameters */
NYX 0:85b3fd62ea1a 366 assert_param(IS_DAC_CHANNEL(Channel));
NYX 0:85b3fd62ea1a 367
NYX 0:85b3fd62ea1a 368 /* Process locked */
NYX 0:85b3fd62ea1a 369 __HAL_LOCK(hdac);
NYX 0:85b3fd62ea1a 370
NYX 0:85b3fd62ea1a 371 /* Change DAC state */
NYX 0:85b3fd62ea1a 372 hdac->State = HAL_DAC_STATE_BUSY;
NYX 0:85b3fd62ea1a 373
NYX 0:85b3fd62ea1a 374 /* Enable the Peripheral */
NYX 0:85b3fd62ea1a 375 __HAL_DAC_ENABLE(hdac, Channel);
NYX 0:85b3fd62ea1a 376
NYX 0:85b3fd62ea1a 377 if(Channel == DAC_CHANNEL_1)
NYX 0:85b3fd62ea1a 378 {
NYX 0:85b3fd62ea1a 379 tmp1 = hdac->Instance->CR & DAC_CR_TEN1;
NYX 0:85b3fd62ea1a 380 tmp2 = hdac->Instance->CR & DAC_CR_TSEL1;
NYX 0:85b3fd62ea1a 381 /* Check if software trigger enabled */
NYX 0:85b3fd62ea1a 382 if((tmp1 == DAC_CR_TEN1) && (tmp2 == DAC_CR_TSEL1))
NYX 0:85b3fd62ea1a 383 {
NYX 0:85b3fd62ea1a 384 /* Enable the selected DAC software conversion */
NYX 0:85b3fd62ea1a 385 hdac->Instance->SWTRIGR |= (uint32_t)DAC_SWTRIGR_SWTRIG1;
NYX 0:85b3fd62ea1a 386 }
NYX 0:85b3fd62ea1a 387 }
NYX 0:85b3fd62ea1a 388 else
NYX 0:85b3fd62ea1a 389 {
NYX 0:85b3fd62ea1a 390 tmp1 = hdac->Instance->CR & DAC_CR_TEN2;
NYX 0:85b3fd62ea1a 391 tmp2 = hdac->Instance->CR & DAC_CR_TSEL2;
NYX 0:85b3fd62ea1a 392 /* Check if software trigger enabled */
NYX 0:85b3fd62ea1a 393 if((tmp1 == DAC_CR_TEN2) && (tmp2 == DAC_CR_TSEL2))
NYX 0:85b3fd62ea1a 394 {
NYX 0:85b3fd62ea1a 395 /* Enable the selected DAC software conversion*/
NYX 0:85b3fd62ea1a 396 hdac->Instance->SWTRIGR |= (uint32_t)DAC_SWTRIGR_SWTRIG2;
NYX 0:85b3fd62ea1a 397 }
NYX 0:85b3fd62ea1a 398 }
NYX 0:85b3fd62ea1a 399
NYX 0:85b3fd62ea1a 400 /* Change DAC state */
NYX 0:85b3fd62ea1a 401 hdac->State = HAL_DAC_STATE_READY;
NYX 0:85b3fd62ea1a 402
NYX 0:85b3fd62ea1a 403 /* Process unlocked */
NYX 0:85b3fd62ea1a 404 __HAL_UNLOCK(hdac);
NYX 0:85b3fd62ea1a 405
NYX 0:85b3fd62ea1a 406 /* Return function status */
NYX 0:85b3fd62ea1a 407 return HAL_OK;
NYX 0:85b3fd62ea1a 408 }
NYX 0:85b3fd62ea1a 409
NYX 0:85b3fd62ea1a 410 /**
NYX 0:85b3fd62ea1a 411 * @brief Disables DAC and stop conversion of channel.
NYX 0:85b3fd62ea1a 412 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 413 * the configuration information for the specified DAC.
NYX 0:85b3fd62ea1a 414 * @param Channel: The selected DAC channel.
NYX 0:85b3fd62ea1a 415 * This parameter can be one of the following values:
NYX 0:85b3fd62ea1a 416 * @arg DAC_CHANNEL_1: DAC Channel1 selected
NYX 0:85b3fd62ea1a 417 * @arg DAC_CHANNEL_2: DAC Channel2 selected
NYX 0:85b3fd62ea1a 418 * @retval HAL status
NYX 0:85b3fd62ea1a 419 */
NYX 0:85b3fd62ea1a 420 HAL_StatusTypeDef HAL_DAC_Stop(DAC_HandleTypeDef* hdac, uint32_t Channel)
NYX 0:85b3fd62ea1a 421 {
NYX 0:85b3fd62ea1a 422 /* Check the parameters */
NYX 0:85b3fd62ea1a 423 assert_param(IS_DAC_CHANNEL(Channel));
NYX 0:85b3fd62ea1a 424
NYX 0:85b3fd62ea1a 425 /* Disable the Peripheral */
NYX 0:85b3fd62ea1a 426 __HAL_DAC_DISABLE(hdac, Channel);
NYX 0:85b3fd62ea1a 427
NYX 0:85b3fd62ea1a 428 /* Change DAC state */
NYX 0:85b3fd62ea1a 429 hdac->State = HAL_DAC_STATE_READY;
NYX 0:85b3fd62ea1a 430
NYX 0:85b3fd62ea1a 431 /* Return function status */
NYX 0:85b3fd62ea1a 432 return HAL_OK;
NYX 0:85b3fd62ea1a 433 }
NYX 0:85b3fd62ea1a 434
NYX 0:85b3fd62ea1a 435 /**
NYX 0:85b3fd62ea1a 436 * @brief Enables DAC and starts conversion of channel.
NYX 0:85b3fd62ea1a 437 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 438 * the configuration information for the specified DAC.
NYX 0:85b3fd62ea1a 439 * @param Channel: The selected DAC channel.
NYX 0:85b3fd62ea1a 440 * This parameter can be one of the following values:
NYX 0:85b3fd62ea1a 441 * @arg DAC_CHANNEL_1: DAC Channel1 selected
NYX 0:85b3fd62ea1a 442 * @arg DAC_CHANNEL_2: DAC Channel2 selected
NYX 0:85b3fd62ea1a 443 * @param pData: The destination peripheral Buffer address.
NYX 0:85b3fd62ea1a 444 * @param Length: The length of data to be transferred from memory to DAC peripheral
NYX 0:85b3fd62ea1a 445 * @param Alignment: Specifies the data alignment for DAC channel.
NYX 0:85b3fd62ea1a 446 * This parameter can be one of the following values:
NYX 0:85b3fd62ea1a 447 * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
NYX 0:85b3fd62ea1a 448 * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
NYX 0:85b3fd62ea1a 449 * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected
NYX 0:85b3fd62ea1a 450 * @retval HAL status
NYX 0:85b3fd62ea1a 451 */
NYX 0:85b3fd62ea1a 452 HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t* pData, uint32_t Length, uint32_t Alignment)
NYX 0:85b3fd62ea1a 453 {
NYX 0:85b3fd62ea1a 454 uint32_t tmpreg = 0U;
NYX 0:85b3fd62ea1a 455
NYX 0:85b3fd62ea1a 456 /* Check the parameters */
NYX 0:85b3fd62ea1a 457 assert_param(IS_DAC_CHANNEL(Channel));
NYX 0:85b3fd62ea1a 458 assert_param(IS_DAC_ALIGN(Alignment));
NYX 0:85b3fd62ea1a 459
NYX 0:85b3fd62ea1a 460 /* Process locked */
NYX 0:85b3fd62ea1a 461 __HAL_LOCK(hdac);
NYX 0:85b3fd62ea1a 462
NYX 0:85b3fd62ea1a 463 /* Change DAC state */
NYX 0:85b3fd62ea1a 464 hdac->State = HAL_DAC_STATE_BUSY;
NYX 0:85b3fd62ea1a 465
NYX 0:85b3fd62ea1a 466 if(Channel == DAC_CHANNEL_1)
NYX 0:85b3fd62ea1a 467 {
NYX 0:85b3fd62ea1a 468 /* Set the DMA transfer complete callback for channel1 */
NYX 0:85b3fd62ea1a 469 hdac->DMA_Handle1->XferCpltCallback = DAC_DMAConvCpltCh1;
NYX 0:85b3fd62ea1a 470
NYX 0:85b3fd62ea1a 471 /* Set the DMA half transfer complete callback for channel1 */
NYX 0:85b3fd62ea1a 472 hdac->DMA_Handle1->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh1;
NYX 0:85b3fd62ea1a 473
NYX 0:85b3fd62ea1a 474 /* Set the DMA error callback for channel1 */
NYX 0:85b3fd62ea1a 475 hdac->DMA_Handle1->XferErrorCallback = DAC_DMAErrorCh1;
NYX 0:85b3fd62ea1a 476
NYX 0:85b3fd62ea1a 477 /* Enable the selected DAC channel1 DMA request */
NYX 0:85b3fd62ea1a 478 hdac->Instance->CR |= DAC_CR_DMAEN1;
NYX 0:85b3fd62ea1a 479
NYX 0:85b3fd62ea1a 480 /* Case of use of channel 1 */
NYX 0:85b3fd62ea1a 481 switch(Alignment)
NYX 0:85b3fd62ea1a 482 {
NYX 0:85b3fd62ea1a 483 case DAC_ALIGN_12B_R:
NYX 0:85b3fd62ea1a 484 /* Get DHR12R1 address */
NYX 0:85b3fd62ea1a 485 tmpreg = (uint32_t)&hdac->Instance->DHR12R1;
NYX 0:85b3fd62ea1a 486 break;
NYX 0:85b3fd62ea1a 487 case DAC_ALIGN_12B_L:
NYX 0:85b3fd62ea1a 488 /* Get DHR12L1 address */
NYX 0:85b3fd62ea1a 489 tmpreg = (uint32_t)&hdac->Instance->DHR12L1;
NYX 0:85b3fd62ea1a 490 break;
NYX 0:85b3fd62ea1a 491 case DAC_ALIGN_8B_R:
NYX 0:85b3fd62ea1a 492 /* Get DHR8R1 address */
NYX 0:85b3fd62ea1a 493 tmpreg = (uint32_t)&hdac->Instance->DHR8R1;
NYX 0:85b3fd62ea1a 494 break;
NYX 0:85b3fd62ea1a 495 default:
NYX 0:85b3fd62ea1a 496 break;
NYX 0:85b3fd62ea1a 497 }
NYX 0:85b3fd62ea1a 498 }
NYX 0:85b3fd62ea1a 499 else
NYX 0:85b3fd62ea1a 500 {
NYX 0:85b3fd62ea1a 501 /* Set the DMA transfer complete callback for channel2 */
NYX 0:85b3fd62ea1a 502 hdac->DMA_Handle2->XferCpltCallback = DAC_DMAConvCpltCh2;
NYX 0:85b3fd62ea1a 503
NYX 0:85b3fd62ea1a 504 /* Set the DMA half transfer complete callback for channel2 */
NYX 0:85b3fd62ea1a 505 hdac->DMA_Handle2->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh2;
NYX 0:85b3fd62ea1a 506
NYX 0:85b3fd62ea1a 507 /* Set the DMA error callback for channel2 */
NYX 0:85b3fd62ea1a 508 hdac->DMA_Handle2->XferErrorCallback = DAC_DMAErrorCh2;
NYX 0:85b3fd62ea1a 509
NYX 0:85b3fd62ea1a 510 /* Enable the selected DAC channel2 DMA request */
NYX 0:85b3fd62ea1a 511 hdac->Instance->CR |= DAC_CR_DMAEN2;
NYX 0:85b3fd62ea1a 512
NYX 0:85b3fd62ea1a 513 /* Case of use of channel 2 */
NYX 0:85b3fd62ea1a 514 switch(Alignment)
NYX 0:85b3fd62ea1a 515 {
NYX 0:85b3fd62ea1a 516 case DAC_ALIGN_12B_R:
NYX 0:85b3fd62ea1a 517 /* Get DHR12R2 address */
NYX 0:85b3fd62ea1a 518 tmpreg = (uint32_t)&hdac->Instance->DHR12R2;
NYX 0:85b3fd62ea1a 519 break;
NYX 0:85b3fd62ea1a 520 case DAC_ALIGN_12B_L:
NYX 0:85b3fd62ea1a 521 /* Get DHR12L2 address */
NYX 0:85b3fd62ea1a 522 tmpreg = (uint32_t)&hdac->Instance->DHR12L2;
NYX 0:85b3fd62ea1a 523 break;
NYX 0:85b3fd62ea1a 524 case DAC_ALIGN_8B_R:
NYX 0:85b3fd62ea1a 525 /* Get DHR8R2 address */
NYX 0:85b3fd62ea1a 526 tmpreg = (uint32_t)&hdac->Instance->DHR8R2;
NYX 0:85b3fd62ea1a 527 break;
NYX 0:85b3fd62ea1a 528 default:
NYX 0:85b3fd62ea1a 529 break;
NYX 0:85b3fd62ea1a 530 }
NYX 0:85b3fd62ea1a 531 }
NYX 0:85b3fd62ea1a 532
NYX 0:85b3fd62ea1a 533 /* Enable the DMA Stream */
NYX 0:85b3fd62ea1a 534 if(Channel == DAC_CHANNEL_1)
NYX 0:85b3fd62ea1a 535 {
NYX 0:85b3fd62ea1a 536 /* Enable the DAC DMA underrun interrupt */
NYX 0:85b3fd62ea1a 537 __HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR1);
NYX 0:85b3fd62ea1a 538
NYX 0:85b3fd62ea1a 539 /* Enable the DMA Stream */
NYX 0:85b3fd62ea1a 540 HAL_DMA_Start_IT(hdac->DMA_Handle1, (uint32_t)pData, tmpreg, Length);
NYX 0:85b3fd62ea1a 541 }
NYX 0:85b3fd62ea1a 542 else
NYX 0:85b3fd62ea1a 543 {
NYX 0:85b3fd62ea1a 544 /* Enable the DAC DMA underrun interrupt */
NYX 0:85b3fd62ea1a 545 __HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR2);
NYX 0:85b3fd62ea1a 546
NYX 0:85b3fd62ea1a 547 /* Enable the DMA Stream */
NYX 0:85b3fd62ea1a 548 HAL_DMA_Start_IT(hdac->DMA_Handle2, (uint32_t)pData, tmpreg, Length);
NYX 0:85b3fd62ea1a 549 }
NYX 0:85b3fd62ea1a 550
NYX 0:85b3fd62ea1a 551 /* Enable the Peripheral */
NYX 0:85b3fd62ea1a 552 __HAL_DAC_ENABLE(hdac, Channel);
NYX 0:85b3fd62ea1a 553
NYX 0:85b3fd62ea1a 554 /* Process Unlocked */
NYX 0:85b3fd62ea1a 555 __HAL_UNLOCK(hdac);
NYX 0:85b3fd62ea1a 556
NYX 0:85b3fd62ea1a 557 /* Return function status */
NYX 0:85b3fd62ea1a 558 return HAL_OK;
NYX 0:85b3fd62ea1a 559 }
NYX 0:85b3fd62ea1a 560
NYX 0:85b3fd62ea1a 561 /**
NYX 0:85b3fd62ea1a 562 * @brief Disables DAC and stop conversion of channel.
NYX 0:85b3fd62ea1a 563 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 564 * the configuration information for the specified DAC.
NYX 0:85b3fd62ea1a 565 * @param Channel: The selected DAC channel.
NYX 0:85b3fd62ea1a 566 * This parameter can be one of the following values:
NYX 0:85b3fd62ea1a 567 * @arg DAC_CHANNEL_1: DAC Channel1 selected
NYX 0:85b3fd62ea1a 568 * @arg DAC_CHANNEL_2: DAC Channel2 selected
NYX 0:85b3fd62ea1a 569 * @retval HAL status
NYX 0:85b3fd62ea1a 570 */
NYX 0:85b3fd62ea1a 571 HAL_StatusTypeDef HAL_DAC_Stop_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel)
NYX 0:85b3fd62ea1a 572 {
NYX 0:85b3fd62ea1a 573 HAL_StatusTypeDef status = HAL_OK;
NYX 0:85b3fd62ea1a 574
NYX 0:85b3fd62ea1a 575 /* Check the parameters */
NYX 0:85b3fd62ea1a 576 assert_param(IS_DAC_CHANNEL(Channel));
NYX 0:85b3fd62ea1a 577
NYX 0:85b3fd62ea1a 578 /* Disable the selected DAC channel DMA request */
NYX 0:85b3fd62ea1a 579 hdac->Instance->CR &= ~(DAC_CR_DMAEN1 << Channel);
NYX 0:85b3fd62ea1a 580
NYX 0:85b3fd62ea1a 581 /* Disable the Peripheral */
NYX 0:85b3fd62ea1a 582 __HAL_DAC_DISABLE(hdac, Channel);
NYX 0:85b3fd62ea1a 583
NYX 0:85b3fd62ea1a 584 /* Disable the DMA Channel */
NYX 0:85b3fd62ea1a 585 /* Channel1 is used */
NYX 0:85b3fd62ea1a 586 if(Channel == DAC_CHANNEL_1)
NYX 0:85b3fd62ea1a 587 {
NYX 0:85b3fd62ea1a 588 status = HAL_DMA_Abort(hdac->DMA_Handle1);
NYX 0:85b3fd62ea1a 589 }
NYX 0:85b3fd62ea1a 590 else /* Channel2 is used for */
NYX 0:85b3fd62ea1a 591 {
NYX 0:85b3fd62ea1a 592 status = HAL_DMA_Abort(hdac->DMA_Handle2);
NYX 0:85b3fd62ea1a 593 }
NYX 0:85b3fd62ea1a 594
NYX 0:85b3fd62ea1a 595 /* Check if DMA Channel effectively disabled */
NYX 0:85b3fd62ea1a 596 if(status != HAL_OK)
NYX 0:85b3fd62ea1a 597 {
NYX 0:85b3fd62ea1a 598 /* Update DAC state machine to error */
NYX 0:85b3fd62ea1a 599 hdac->State = HAL_DAC_STATE_ERROR;
NYX 0:85b3fd62ea1a 600 }
NYX 0:85b3fd62ea1a 601 else
NYX 0:85b3fd62ea1a 602 {
NYX 0:85b3fd62ea1a 603 /* Change DAC state */
NYX 0:85b3fd62ea1a 604 hdac->State = HAL_DAC_STATE_READY;
NYX 0:85b3fd62ea1a 605 }
NYX 0:85b3fd62ea1a 606
NYX 0:85b3fd62ea1a 607 /* Return function status */
NYX 0:85b3fd62ea1a 608 return status;
NYX 0:85b3fd62ea1a 609 }
NYX 0:85b3fd62ea1a 610
NYX 0:85b3fd62ea1a 611 /**
NYX 0:85b3fd62ea1a 612 * @brief Returns the last data output value of the selected DAC channel.
NYX 0:85b3fd62ea1a 613 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 614 * the configuration information for the specified DAC.
NYX 0:85b3fd62ea1a 615 * @param Channel: The selected DAC channel.
NYX 0:85b3fd62ea1a 616 * This parameter can be one of the following values:
NYX 0:85b3fd62ea1a 617 * @arg DAC_CHANNEL_1: DAC Channel1 selected
NYX 0:85b3fd62ea1a 618 * @arg DAC_CHANNEL_2: DAC Channel2 selected
NYX 0:85b3fd62ea1a 619 * @retval The selected DAC channel data output value.
NYX 0:85b3fd62ea1a 620 */
NYX 0:85b3fd62ea1a 621 uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef* hdac, uint32_t Channel)
NYX 0:85b3fd62ea1a 622 {
NYX 0:85b3fd62ea1a 623 /* Check the parameters */
NYX 0:85b3fd62ea1a 624 assert_param(IS_DAC_CHANNEL(Channel));
NYX 0:85b3fd62ea1a 625
NYX 0:85b3fd62ea1a 626 /* Returns the DAC channel data output register value */
NYX 0:85b3fd62ea1a 627 if(Channel == DAC_CHANNEL_1)
NYX 0:85b3fd62ea1a 628 {
NYX 0:85b3fd62ea1a 629 return hdac->Instance->DOR1;
NYX 0:85b3fd62ea1a 630 }
NYX 0:85b3fd62ea1a 631 else
NYX 0:85b3fd62ea1a 632 {
NYX 0:85b3fd62ea1a 633 return hdac->Instance->DOR2;
NYX 0:85b3fd62ea1a 634 }
NYX 0:85b3fd62ea1a 635 }
NYX 0:85b3fd62ea1a 636
NYX 0:85b3fd62ea1a 637 /**
NYX 0:85b3fd62ea1a 638 * @brief Handles DAC interrupt request
NYX 0:85b3fd62ea1a 639 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 640 * the configuration information for the specified DAC.
NYX 0:85b3fd62ea1a 641 * @retval None
NYX 0:85b3fd62ea1a 642 */
NYX 0:85b3fd62ea1a 643 void HAL_DAC_IRQHandler(DAC_HandleTypeDef* hdac)
NYX 0:85b3fd62ea1a 644 {
NYX 0:85b3fd62ea1a 645 /* Check underrun channel 1 flag */
NYX 0:85b3fd62ea1a 646 if(__HAL_DAC_GET_FLAG(hdac, DAC_FLAG_DMAUDR1))
NYX 0:85b3fd62ea1a 647 {
NYX 0:85b3fd62ea1a 648 /* Change DAC state to error state */
NYX 0:85b3fd62ea1a 649 hdac->State = HAL_DAC_STATE_ERROR;
NYX 0:85b3fd62ea1a 650
NYX 0:85b3fd62ea1a 651 /* Set DAC error code to channel1 DMA underrun error */
NYX 0:85b3fd62ea1a 652 hdac->ErrorCode |= HAL_DAC_ERROR_DMAUNDERRUNCH1;
NYX 0:85b3fd62ea1a 653
NYX 0:85b3fd62ea1a 654 /* Clear the underrun flag */
NYX 0:85b3fd62ea1a 655 __HAL_DAC_CLEAR_FLAG(hdac,DAC_FLAG_DMAUDR1);
NYX 0:85b3fd62ea1a 656
NYX 0:85b3fd62ea1a 657 /* Disable the selected DAC channel1 DMA request */
NYX 0:85b3fd62ea1a 658 hdac->Instance->CR &= ~DAC_CR_DMAEN1;
NYX 0:85b3fd62ea1a 659
NYX 0:85b3fd62ea1a 660 /* Error callback */
NYX 0:85b3fd62ea1a 661 HAL_DAC_DMAUnderrunCallbackCh1(hdac);
NYX 0:85b3fd62ea1a 662 }
NYX 0:85b3fd62ea1a 663 /* Check underrun channel 2 flag */
NYX 0:85b3fd62ea1a 664 if(__HAL_DAC_GET_FLAG(hdac, DAC_FLAG_DMAUDR2))
NYX 0:85b3fd62ea1a 665 {
NYX 0:85b3fd62ea1a 666 /* Change DAC state to error state */
NYX 0:85b3fd62ea1a 667 hdac->State = HAL_DAC_STATE_ERROR;
NYX 0:85b3fd62ea1a 668
NYX 0:85b3fd62ea1a 669 /* Set DAC error code to channel2 DMA underrun error */
NYX 0:85b3fd62ea1a 670 hdac->ErrorCode |= HAL_DAC_ERROR_DMAUNDERRUNCH2;
NYX 0:85b3fd62ea1a 671
NYX 0:85b3fd62ea1a 672 /* Clear the underrun flag */
NYX 0:85b3fd62ea1a 673 __HAL_DAC_CLEAR_FLAG(hdac,DAC_FLAG_DMAUDR2);
NYX 0:85b3fd62ea1a 674
NYX 0:85b3fd62ea1a 675 /* Disable the selected DAC channel1 DMA request */
NYX 0:85b3fd62ea1a 676 hdac->Instance->CR &= ~DAC_CR_DMAEN2;
NYX 0:85b3fd62ea1a 677
NYX 0:85b3fd62ea1a 678 /* Error callback */
NYX 0:85b3fd62ea1a 679 HAL_DACEx_DMAUnderrunCallbackCh2(hdac);
NYX 0:85b3fd62ea1a 680 }
NYX 0:85b3fd62ea1a 681 }
NYX 0:85b3fd62ea1a 682
NYX 0:85b3fd62ea1a 683 /**
NYX 0:85b3fd62ea1a 684 * @brief Conversion complete callback in non blocking mode for Channel1
NYX 0:85b3fd62ea1a 685 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 686 * the configuration information for the specified DAC.
NYX 0:85b3fd62ea1a 687 * @retval None
NYX 0:85b3fd62ea1a 688 */
NYX 0:85b3fd62ea1a 689 __weak void HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef* hdac)
NYX 0:85b3fd62ea1a 690 {
NYX 0:85b3fd62ea1a 691 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 692 UNUSED(hdac);
NYX 0:85b3fd62ea1a 693 /* NOTE : This function Should not be modified, when the callback is needed,
NYX 0:85b3fd62ea1a 694 the HAL_DAC_ConvCpltCallback could be implemented in the user file
NYX 0:85b3fd62ea1a 695 */
NYX 0:85b3fd62ea1a 696 }
NYX 0:85b3fd62ea1a 697
NYX 0:85b3fd62ea1a 698 /**
NYX 0:85b3fd62ea1a 699 * @brief Conversion half DMA transfer callback in non blocking mode for Channel1
NYX 0:85b3fd62ea1a 700 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 701 * the configuration information for the specified DAC.
NYX 0:85b3fd62ea1a 702 * @retval None
NYX 0:85b3fd62ea1a 703 */
NYX 0:85b3fd62ea1a 704 __weak void HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef* hdac)
NYX 0:85b3fd62ea1a 705 {
NYX 0:85b3fd62ea1a 706 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 707 UNUSED(hdac);
NYX 0:85b3fd62ea1a 708 /* NOTE : This function Should not be modified, when the callback is needed,
NYX 0:85b3fd62ea1a 709 the HAL_DAC_ConvHalfCpltCallbackCh1 could be implemented in the user file
NYX 0:85b3fd62ea1a 710 */
NYX 0:85b3fd62ea1a 711 }
NYX 0:85b3fd62ea1a 712
NYX 0:85b3fd62ea1a 713 /**
NYX 0:85b3fd62ea1a 714 * @brief Error DAC callback for Channel1.
NYX 0:85b3fd62ea1a 715 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 716 * the configuration information for the specified DAC.
NYX 0:85b3fd62ea1a 717 * @retval None
NYX 0:85b3fd62ea1a 718 */
NYX 0:85b3fd62ea1a 719 __weak void HAL_DAC_ErrorCallbackCh1(DAC_HandleTypeDef *hdac)
NYX 0:85b3fd62ea1a 720 {
NYX 0:85b3fd62ea1a 721 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 722 UNUSED(hdac);
NYX 0:85b3fd62ea1a 723 /* NOTE : This function Should not be modified, when the callback is needed,
NYX 0:85b3fd62ea1a 724 the HAL_DAC_ErrorCallbackCh1 could be implemented in the user file
NYX 0:85b3fd62ea1a 725 */
NYX 0:85b3fd62ea1a 726 }
NYX 0:85b3fd62ea1a 727
NYX 0:85b3fd62ea1a 728 /**
NYX 0:85b3fd62ea1a 729 * @brief DMA underrun DAC callback for channel1.
NYX 0:85b3fd62ea1a 730 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 731 * the configuration information for the specified DAC.
NYX 0:85b3fd62ea1a 732 * @retval None
NYX 0:85b3fd62ea1a 733 */
NYX 0:85b3fd62ea1a 734 __weak void HAL_DAC_DMAUnderrunCallbackCh1(DAC_HandleTypeDef *hdac)
NYX 0:85b3fd62ea1a 735 {
NYX 0:85b3fd62ea1a 736 /* Prevent unused argument(s) compilation warning */
NYX 0:85b3fd62ea1a 737 UNUSED(hdac);
NYX 0:85b3fd62ea1a 738 /* NOTE : This function Should not be modified, when the callback is needed,
NYX 0:85b3fd62ea1a 739 the HAL_DAC_DMAUnderrunCallbackCh1 could be implemented in the user file
NYX 0:85b3fd62ea1a 740 */
NYX 0:85b3fd62ea1a 741 }
NYX 0:85b3fd62ea1a 742
NYX 0:85b3fd62ea1a 743 /**
NYX 0:85b3fd62ea1a 744 * @}
NYX 0:85b3fd62ea1a 745 */
NYX 0:85b3fd62ea1a 746
NYX 0:85b3fd62ea1a 747 /** @defgroup DAC_Exported_Functions_Group3 Peripheral Control functions
NYX 0:85b3fd62ea1a 748 * @brief Peripheral Control functions
NYX 0:85b3fd62ea1a 749 *
NYX 0:85b3fd62ea1a 750 @verbatim
NYX 0:85b3fd62ea1a 751 ==============================================================================
NYX 0:85b3fd62ea1a 752 ##### Peripheral Control functions #####
NYX 0:85b3fd62ea1a 753 ==============================================================================
NYX 0:85b3fd62ea1a 754 [..] This section provides functions allowing to:
NYX 0:85b3fd62ea1a 755 (+) Configure channels.
NYX 0:85b3fd62ea1a 756 (+) Set the specified data holding register value for DAC channel.
NYX 0:85b3fd62ea1a 757
NYX 0:85b3fd62ea1a 758 @endverbatim
NYX 0:85b3fd62ea1a 759 * @{
NYX 0:85b3fd62ea1a 760 */
NYX 0:85b3fd62ea1a 761
NYX 0:85b3fd62ea1a 762 /**
NYX 0:85b3fd62ea1a 763 * @brief Configures the selected DAC channel.
NYX 0:85b3fd62ea1a 764 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 765 * the configuration information for the specified DAC.
NYX 0:85b3fd62ea1a 766 * @param sConfig: DAC configuration structure.
NYX 0:85b3fd62ea1a 767 * @param Channel: The selected DAC channel.
NYX 0:85b3fd62ea1a 768 * This parameter can be one of the following values:
NYX 0:85b3fd62ea1a 769 * @arg DAC_CHANNEL_1: DAC Channel1 selected
NYX 0:85b3fd62ea1a 770 * @arg DAC_CHANNEL_2: DAC Channel2 selected
NYX 0:85b3fd62ea1a 771 * @retval HAL status
NYX 0:85b3fd62ea1a 772 */
NYX 0:85b3fd62ea1a 773 HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel)
NYX 0:85b3fd62ea1a 774 {
NYX 0:85b3fd62ea1a 775 uint32_t tmpreg1 = 0U, tmpreg2 = 0U;
NYX 0:85b3fd62ea1a 776
NYX 0:85b3fd62ea1a 777 /* Check the DAC parameters */
NYX 0:85b3fd62ea1a 778 assert_param(IS_DAC_TRIGGER(sConfig->DAC_Trigger));
NYX 0:85b3fd62ea1a 779 assert_param(IS_DAC_OUTPUT_BUFFER_STATE(sConfig->DAC_OutputBuffer));
NYX 0:85b3fd62ea1a 780 assert_param(IS_DAC_CHANNEL(Channel));
NYX 0:85b3fd62ea1a 781
NYX 0:85b3fd62ea1a 782 /* Process locked */
NYX 0:85b3fd62ea1a 783 __HAL_LOCK(hdac);
NYX 0:85b3fd62ea1a 784
NYX 0:85b3fd62ea1a 785 /* Change DAC state */
NYX 0:85b3fd62ea1a 786 hdac->State = HAL_DAC_STATE_BUSY;
NYX 0:85b3fd62ea1a 787
NYX 0:85b3fd62ea1a 788 /* Get the DAC CR value */
NYX 0:85b3fd62ea1a 789 tmpreg1 = hdac->Instance->CR;
NYX 0:85b3fd62ea1a 790 /* Clear BOFFx, TENx, TSELx, WAVEx and MAMPx bits */
NYX 0:85b3fd62ea1a 791 tmpreg1 &= ~(((uint32_t)(DAC_CR_MAMP1 | DAC_CR_WAVE1 | DAC_CR_TSEL1 | DAC_CR_TEN1 | DAC_CR_BOFF1)) << Channel);
NYX 0:85b3fd62ea1a 792 /* Configure for the selected DAC channel: buffer output, trigger */
NYX 0:85b3fd62ea1a 793 /* Set TSELx and TENx bits according to DAC_Trigger value */
NYX 0:85b3fd62ea1a 794 /* Set BOFFx bit according to DAC_OutputBuffer value */
NYX 0:85b3fd62ea1a 795 tmpreg2 = (sConfig->DAC_Trigger | sConfig->DAC_OutputBuffer);
NYX 0:85b3fd62ea1a 796 /* Calculate CR register value depending on DAC_Channel */
NYX 0:85b3fd62ea1a 797 tmpreg1 |= tmpreg2 << Channel;
NYX 0:85b3fd62ea1a 798 /* Write to DAC CR */
NYX 0:85b3fd62ea1a 799 hdac->Instance->CR = tmpreg1;
NYX 0:85b3fd62ea1a 800 /* Disable wave generation */
NYX 0:85b3fd62ea1a 801 hdac->Instance->CR &= ~(DAC_CR_WAVE1 << Channel);
NYX 0:85b3fd62ea1a 802
NYX 0:85b3fd62ea1a 803 /* Change DAC state */
NYX 0:85b3fd62ea1a 804 hdac->State = HAL_DAC_STATE_READY;
NYX 0:85b3fd62ea1a 805
NYX 0:85b3fd62ea1a 806 /* Process unlocked */
NYX 0:85b3fd62ea1a 807 __HAL_UNLOCK(hdac);
NYX 0:85b3fd62ea1a 808
NYX 0:85b3fd62ea1a 809 /* Return function status */
NYX 0:85b3fd62ea1a 810 return HAL_OK;
NYX 0:85b3fd62ea1a 811 }
NYX 0:85b3fd62ea1a 812
NYX 0:85b3fd62ea1a 813 /**
NYX 0:85b3fd62ea1a 814 * @brief Set the specified data holding register value for DAC channel.
NYX 0:85b3fd62ea1a 815 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 816 * the configuration information for the specified DAC.
NYX 0:85b3fd62ea1a 817 * @param Channel: The selected DAC channel.
NYX 0:85b3fd62ea1a 818 * This parameter can be one of the following values:
NYX 0:85b3fd62ea1a 819 * @arg DAC_CHANNEL_1: DAC Channel1 selected
NYX 0:85b3fd62ea1a 820 * @arg DAC_CHANNEL_2: DAC Channel2 selected
NYX 0:85b3fd62ea1a 821 * @param Alignment: Specifies the data alignment.
NYX 0:85b3fd62ea1a 822 * This parameter can be one of the following values:
NYX 0:85b3fd62ea1a 823 * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
NYX 0:85b3fd62ea1a 824 * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
NYX 0:85b3fd62ea1a 825 * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected
NYX 0:85b3fd62ea1a 826 * @param Data: Data to be loaded in the selected data holding register.
NYX 0:85b3fd62ea1a 827 * @retval HAL status
NYX 0:85b3fd62ea1a 828 */
NYX 0:85b3fd62ea1a 829 HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data)
NYX 0:85b3fd62ea1a 830 {
NYX 0:85b3fd62ea1a 831 __IO uint32_t tmp = 0U;
NYX 0:85b3fd62ea1a 832
NYX 0:85b3fd62ea1a 833 /* Check the parameters */
NYX 0:85b3fd62ea1a 834 assert_param(IS_DAC_CHANNEL(Channel));
NYX 0:85b3fd62ea1a 835 assert_param(IS_DAC_ALIGN(Alignment));
NYX 0:85b3fd62ea1a 836 assert_param(IS_DAC_DATA(Data));
NYX 0:85b3fd62ea1a 837
NYX 0:85b3fd62ea1a 838 tmp = (uint32_t)hdac->Instance;
NYX 0:85b3fd62ea1a 839 if(Channel == DAC_CHANNEL_1)
NYX 0:85b3fd62ea1a 840 {
NYX 0:85b3fd62ea1a 841 tmp += DAC_DHR12R1_ALIGNMENT(Alignment);
NYX 0:85b3fd62ea1a 842 }
NYX 0:85b3fd62ea1a 843 else
NYX 0:85b3fd62ea1a 844 {
NYX 0:85b3fd62ea1a 845 tmp += DAC_DHR12R2_ALIGNMENT(Alignment);
NYX 0:85b3fd62ea1a 846 }
NYX 0:85b3fd62ea1a 847
NYX 0:85b3fd62ea1a 848 /* Set the DAC channel1 selected data holding register */
NYX 0:85b3fd62ea1a 849 *(__IO uint32_t *) tmp = Data;
NYX 0:85b3fd62ea1a 850
NYX 0:85b3fd62ea1a 851 /* Return function status */
NYX 0:85b3fd62ea1a 852 return HAL_OK;
NYX 0:85b3fd62ea1a 853 }
NYX 0:85b3fd62ea1a 854
NYX 0:85b3fd62ea1a 855 /**
NYX 0:85b3fd62ea1a 856 * @}
NYX 0:85b3fd62ea1a 857 */
NYX 0:85b3fd62ea1a 858
NYX 0:85b3fd62ea1a 859 /** @defgroup DAC_Exported_Functions_Group4 Peripheral State and Errors functions
NYX 0:85b3fd62ea1a 860 * @brief Peripheral State and Errors functions
NYX 0:85b3fd62ea1a 861 *
NYX 0:85b3fd62ea1a 862 @verbatim
NYX 0:85b3fd62ea1a 863 ==============================================================================
NYX 0:85b3fd62ea1a 864 ##### Peripheral State and Errors functions #####
NYX 0:85b3fd62ea1a 865 ==============================================================================
NYX 0:85b3fd62ea1a 866 [..]
NYX 0:85b3fd62ea1a 867 This subsection provides functions allowing to
NYX 0:85b3fd62ea1a 868 (+) Check the DAC state.
NYX 0:85b3fd62ea1a 869 (+) Check the DAC Errors.
NYX 0:85b3fd62ea1a 870
NYX 0:85b3fd62ea1a 871 @endverbatim
NYX 0:85b3fd62ea1a 872 * @{
NYX 0:85b3fd62ea1a 873 */
NYX 0:85b3fd62ea1a 874
NYX 0:85b3fd62ea1a 875 /**
NYX 0:85b3fd62ea1a 876 * @brief return the DAC state
NYX 0:85b3fd62ea1a 877 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 878 * the configuration information for the specified DAC.
NYX 0:85b3fd62ea1a 879 * @retval HAL state
NYX 0:85b3fd62ea1a 880 */
NYX 0:85b3fd62ea1a 881 HAL_DAC_StateTypeDef HAL_DAC_GetState(DAC_HandleTypeDef* hdac)
NYX 0:85b3fd62ea1a 882 {
NYX 0:85b3fd62ea1a 883 /* Return DAC state */
NYX 0:85b3fd62ea1a 884 return hdac->State;
NYX 0:85b3fd62ea1a 885 }
NYX 0:85b3fd62ea1a 886
NYX 0:85b3fd62ea1a 887
NYX 0:85b3fd62ea1a 888 /**
NYX 0:85b3fd62ea1a 889 * @brief Return the DAC error code
NYX 0:85b3fd62ea1a 890 * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 891 * the configuration information for the specified DAC.
NYX 0:85b3fd62ea1a 892 * @retval DAC Error Code
NYX 0:85b3fd62ea1a 893 */
NYX 0:85b3fd62ea1a 894 uint32_t HAL_DAC_GetError(DAC_HandleTypeDef *hdac)
NYX 0:85b3fd62ea1a 895 {
NYX 0:85b3fd62ea1a 896 return hdac->ErrorCode;
NYX 0:85b3fd62ea1a 897 }
NYX 0:85b3fd62ea1a 898
NYX 0:85b3fd62ea1a 899 /**
NYX 0:85b3fd62ea1a 900 * @}
NYX 0:85b3fd62ea1a 901 */
NYX 0:85b3fd62ea1a 902
NYX 0:85b3fd62ea1a 903 /**
NYX 0:85b3fd62ea1a 904 * @brief DMA conversion complete callback.
NYX 0:85b3fd62ea1a 905 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 906 * the configuration information for the specified DMA module.
NYX 0:85b3fd62ea1a 907 * @retval None
NYX 0:85b3fd62ea1a 908 */
NYX 0:85b3fd62ea1a 909 static void DAC_DMAConvCpltCh1(DMA_HandleTypeDef *hdma)
NYX 0:85b3fd62ea1a 910 {
NYX 0:85b3fd62ea1a 911 DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
NYX 0:85b3fd62ea1a 912
NYX 0:85b3fd62ea1a 913 HAL_DAC_ConvCpltCallbackCh1(hdac);
NYX 0:85b3fd62ea1a 914
NYX 0:85b3fd62ea1a 915 hdac->State= HAL_DAC_STATE_READY;
NYX 0:85b3fd62ea1a 916 }
NYX 0:85b3fd62ea1a 917
NYX 0:85b3fd62ea1a 918 /**
NYX 0:85b3fd62ea1a 919 * @brief DMA half transfer complete callback.
NYX 0:85b3fd62ea1a 920 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 921 * the configuration information for the specified DMA module.
NYX 0:85b3fd62ea1a 922 * @retval None
NYX 0:85b3fd62ea1a 923 */
NYX 0:85b3fd62ea1a 924 static void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma)
NYX 0:85b3fd62ea1a 925 {
NYX 0:85b3fd62ea1a 926 DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
NYX 0:85b3fd62ea1a 927 /* Conversion complete callback */
NYX 0:85b3fd62ea1a 928 HAL_DAC_ConvHalfCpltCallbackCh1(hdac);
NYX 0:85b3fd62ea1a 929 }
NYX 0:85b3fd62ea1a 930
NYX 0:85b3fd62ea1a 931 /**
NYX 0:85b3fd62ea1a 932 * @brief DMA error callback
NYX 0:85b3fd62ea1a 933 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
NYX 0:85b3fd62ea1a 934 * the configuration information for the specified DMA module.
NYX 0:85b3fd62ea1a 935 * @retval None
NYX 0:85b3fd62ea1a 936 */
NYX 0:85b3fd62ea1a 937 static void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma)
NYX 0:85b3fd62ea1a 938 {
NYX 0:85b3fd62ea1a 939 DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
NYX 0:85b3fd62ea1a 940
NYX 0:85b3fd62ea1a 941 /* Set DAC error code to DMA error */
NYX 0:85b3fd62ea1a 942 hdac->ErrorCode |= HAL_DAC_ERROR_DMA;
NYX 0:85b3fd62ea1a 943
NYX 0:85b3fd62ea1a 944 HAL_DAC_ErrorCallbackCh1(hdac);
NYX 0:85b3fd62ea1a 945
NYX 0:85b3fd62ea1a 946 hdac->State= HAL_DAC_STATE_READY;
NYX 0:85b3fd62ea1a 947 }
NYX 0:85b3fd62ea1a 948
NYX 0:85b3fd62ea1a 949 /**
NYX 0:85b3fd62ea1a 950 * @}
NYX 0:85b3fd62ea1a 951 */
NYX 0:85b3fd62ea1a 952 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx ||\
NYX 0:85b3fd62ea1a 953 STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx ||\
NYX 0:85b3fd62ea1a 954 STM32F410xx || STM32F446xx || STM32F469xx || STM32F479xx ||\
NYX 0:85b3fd62ea1a 955 STM32F413xx || STM32F423xx */
NYX 0:85b3fd62ea1a 956 #endif /* HAL_DAC_MODULE_ENABLED */
NYX 0:85b3fd62ea1a 957
NYX 0:85b3fd62ea1a 958 /**
NYX 0:85b3fd62ea1a 959 * @}
NYX 0:85b3fd62ea1a 960 */
NYX 0:85b3fd62ea1a 961
NYX 0:85b3fd62ea1a 962 /**
NYX 0:85b3fd62ea1a 963 * @}
NYX 0:85b3fd62ea1a 964 */
NYX 0:85b3fd62ea1a 965
NYX 0:85b3fd62ea1a 966 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/