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