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