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