mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
shaoziyang
Date:
Sat Sep 13 14:25:46 2014 +0000
Revision:
323:9e901b0a5aa1
Parent:
125:23cc3068a9e4
test with CLOCK_SETUP = 0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 125:23cc3068a9e4 1 /**
mbed_official 125:23cc3068a9e4 2 ******************************************************************************
mbed_official 125:23cc3068a9e4 3 * @file stm32f30x_dac.c
mbed_official 125:23cc3068a9e4 4 * @author MCD Application Team
mbed_official 125:23cc3068a9e4 5 * @version V1.1.0
mbed_official 125:23cc3068a9e4 6 * @date 27-February-2014
mbed_official 125:23cc3068a9e4 7 * @brief This file provides firmware functions to manage the following
mbed_official 125:23cc3068a9e4 8 * functionalities of the Digital-to-Analog Converter (DAC) peripheral:
mbed_official 125:23cc3068a9e4 9 * + DAC channels configuration: trigger, output buffer, data format
mbed_official 125:23cc3068a9e4 10 * + DMA management
mbed_official 125:23cc3068a9e4 11 * + Interrupts and flags management
mbed_official 125:23cc3068a9e4 12 *
mbed_official 125:23cc3068a9e4 13 @verbatim
mbed_official 125:23cc3068a9e4 14
mbed_official 125:23cc3068a9e4 15 ===============================================================================
mbed_official 125:23cc3068a9e4 16 ##### DAC Peripheral features #####
mbed_official 125:23cc3068a9e4 17 ===============================================================================
mbed_official 125:23cc3068a9e4 18 [..] The device integrates two 12-bit Digital Analog Converters that can
mbed_official 125:23cc3068a9e4 19 be used independently or simultaneously (dual mode):
mbed_official 125:23cc3068a9e4 20 (#) DAC1 integrates two DAC channels:
mbed_official 125:23cc3068a9e4 21 (++) DAC1 channel 1 with DAC1_OUT1 as output
mbed_official 125:23cc3068a9e4 22 (++) DAC1 channel 2 with DAC1_OUT2 as output
mbed_official 125:23cc3068a9e4 23 (++) The two channels can be used independently or simultaneously (dual mode)
mbed_official 125:23cc3068a9e4 24
mbed_official 125:23cc3068a9e4 25 (#) DAC2 integrates only one channel DAC2 channel 1 with DAC2_OUT1 as output
mbed_official 125:23cc3068a9e4 26
mbed_official 125:23cc3068a9e4 27 [..] Digital to Analog conversion can be non-triggered using DAC_Trigger_None
mbed_official 125:23cc3068a9e4 28 and DAC_OUT1/DAC_OUT2 is available once writing to DHRx register using
mbed_official 125:23cc3068a9e4 29 DAC_SetChannel1Data()/DAC_SetChannel2Data.
mbed_official 125:23cc3068a9e4 30
mbed_official 125:23cc3068a9e4 31 [..] Digital to Analog conversion can be triggered by:
mbed_official 125:23cc3068a9e4 32 (#) External event: EXTI Line 9 (any GPIOx_Pin9) using DAC_Trigger_Ext_IT9.
mbed_official 125:23cc3068a9e4 33 The used pin (GPIOx_Pin9) must be configured in input mode.
mbed_official 125:23cc3068a9e4 34
mbed_official 125:23cc3068a9e4 35 (#) Timers TRGO: TIM2, TIM8/TIM3, TIM4, TIM6, TIM7, and TIM15
mbed_official 125:23cc3068a9e4 36 (DAC_Trigger_T2_TRGO, DAC_Trigger_T4_TRGO...)
mbed_official 125:23cc3068a9e4 37 The timer TRGO event should be selected using TIM_SelectOutputTrigger()
mbed_official 125:23cc3068a9e4 38 (++) To trigger DAC conversions by TIM3 instead of TIM8 follow
mbed_official 125:23cc3068a9e4 39 this sequence:
mbed_official 125:23cc3068a9e4 40 (+++) Enable SYSCFG APB clock by calling
mbed_official 125:23cc3068a9e4 41 RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
mbed_official 125:23cc3068a9e4 42 (+++) Select DAC_Trigger_T3_TRGO when calling DAC_Init()
mbed_official 125:23cc3068a9e4 43 (+++) Remap the DAC trigger from TIM8 to TIM3 by calling
mbed_official 125:23cc3068a9e4 44 SYSCFG_TriggerRemapConfig(SYSCFG_TriggerRemap_DACTIM3, ENABLE)
mbed_official 125:23cc3068a9e4 45 (#) Software using DAC_Trigger_Software
mbed_official 125:23cc3068a9e4 46
mbed_official 125:23cc3068a9e4 47 [..] Each DAC channel integrates an output buffer that can be used to
mbed_official 125:23cc3068a9e4 48 reduce the output impedance, and to drive external loads directly
mbed_official 125:23cc3068a9e4 49 without having to add an external operational amplifier.
mbed_official 125:23cc3068a9e4 50 To enable, the output buffer use
mbed_official 125:23cc3068a9e4 51 DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
mbed_official 125:23cc3068a9e4 52
mbed_official 125:23cc3068a9e4 53 [..] Refer to the device datasheet for more details about output impedance
mbed_official 125:23cc3068a9e4 54 value with and without output buffer.
mbed_official 125:23cc3068a9e4 55
mbed_official 125:23cc3068a9e4 56 [..] Both DAC channels can be used to generate:
mbed_official 125:23cc3068a9e4 57 (+) Noise wave using DAC_WaveGeneration_Noise
mbed_official 125:23cc3068a9e4 58 (+) Triangle wave using DAC_WaveGeneration_Triangle
mbed_official 125:23cc3068a9e4 59
mbed_official 125:23cc3068a9e4 60 [..] Wave generation can be disabled using DAC_WaveGeneration_None
mbed_official 125:23cc3068a9e4 61
mbed_official 125:23cc3068a9e4 62 [..] The DAC data format can be:
mbed_official 125:23cc3068a9e4 63 (+) 8-bit right alignment using DAC_Align_8b_R
mbed_official 125:23cc3068a9e4 64 (+) 12-bit left alignment using DAC_Align_12b_L
mbed_official 125:23cc3068a9e4 65 (+) 12-bit right alignment using DAC_Align_12b_R
mbed_official 125:23cc3068a9e4 66
mbed_official 125:23cc3068a9e4 67 [..] The analog output voltage on each DAC channel pin is determined
mbed_official 125:23cc3068a9e4 68 by the following equation:
mbed_official 125:23cc3068a9e4 69 (+) DAC_OUTx = VREF+ * DOR / 4095 with DOR is the Data Output Register.
mbed_official 125:23cc3068a9e4 70 VREF+ is the input voltage reference (refer to the device datasheet)
mbed_official 125:23cc3068a9e4 71 e.g. To set DAC_OUT1 to 0.7V, use DAC_SetChannel1Data(DAC_Align_12b_R, 868);
mbed_official 125:23cc3068a9e4 72 Assuming that VREF+ = 3.3, DAC_OUT1 = (3.3 * 868) / 4095 = 0.7V
mbed_official 125:23cc3068a9e4 73
mbed_official 125:23cc3068a9e4 74 [..] A DMA1 request can be generated when an external trigger (but not
mbed_official 125:23cc3068a9e4 75 a software trigger) occurs if DMA1 requests are enabled using
mbed_official 125:23cc3068a9e4 76 DAC_DMACmd()
mbed_official 125:23cc3068a9e4 77 DMA1 requests are mapped as following:
mbed_official 125:23cc3068a9e4 78 (+) DAC channel1 is mapped on DMA1 channel3 which must be already
mbed_official 125:23cc3068a9e4 79 configured
mbed_official 125:23cc3068a9e4 80 (+) DAC channel2 is mapped on DMA1 channel4 which must be already
mbed_official 125:23cc3068a9e4 81 configured
mbed_official 125:23cc3068a9e4 82
mbed_official 125:23cc3068a9e4 83 ##### How to use this driver #####
mbed_official 125:23cc3068a9e4 84 ===============================================================================
mbed_official 125:23cc3068a9e4 85 [..]
mbed_official 125:23cc3068a9e4 86 (+) Enable DAC APB1 clock to get write access to DAC registers
mbed_official 125:23cc3068a9e4 87 using RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE)
mbed_official 125:23cc3068a9e4 88
mbed_official 125:23cc3068a9e4 89 (+) Configure DACx_OUTy (DAC1_OUT1: PA4, DAC1_OUT2: PA5, DAC2_OUT1: PA6)
mbed_official 125:23cc3068a9e4 90 in analog mode.
mbed_official 125:23cc3068a9e4 91
mbed_official 125:23cc3068a9e4 92 (+) Configure the DAC channel using DAC_Init()
mbed_official 125:23cc3068a9e4 93
mbed_official 125:23cc3068a9e4 94 (+) Enable the DAC channel using DAC_Cmd()
mbed_official 125:23cc3068a9e4 95
mbed_official 125:23cc3068a9e4 96 @endverbatim
mbed_official 125:23cc3068a9e4 97
mbed_official 125:23cc3068a9e4 98 ******************************************************************************
mbed_official 125:23cc3068a9e4 99 * @attention
mbed_official 125:23cc3068a9e4 100 *
mbed_official 125:23cc3068a9e4 101 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 125:23cc3068a9e4 102 *
mbed_official 125:23cc3068a9e4 103 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 125:23cc3068a9e4 104 * are permitted provided that the following conditions are met:
mbed_official 125:23cc3068a9e4 105 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 125:23cc3068a9e4 106 * this list of conditions and the following disclaimer.
mbed_official 125:23cc3068a9e4 107 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 125:23cc3068a9e4 108 * this list of conditions and the following disclaimer in the documentation
mbed_official 125:23cc3068a9e4 109 * and/or other materials provided with the distribution.
mbed_official 125:23cc3068a9e4 110 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 125:23cc3068a9e4 111 * may be used to endorse or promote products derived from this software
mbed_official 125:23cc3068a9e4 112 * without specific prior written permission.
mbed_official 125:23cc3068a9e4 113 *
mbed_official 125:23cc3068a9e4 114 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 125:23cc3068a9e4 115 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 125:23cc3068a9e4 116 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 125:23cc3068a9e4 117 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 125:23cc3068a9e4 118 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 125:23cc3068a9e4 119 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 125:23cc3068a9e4 120 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 125:23cc3068a9e4 121 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 125:23cc3068a9e4 122 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 125:23cc3068a9e4 123 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 125:23cc3068a9e4 124 *
mbed_official 125:23cc3068a9e4 125 ******************************************************************************
mbed_official 125:23cc3068a9e4 126 */
mbed_official 125:23cc3068a9e4 127
mbed_official 125:23cc3068a9e4 128
mbed_official 125:23cc3068a9e4 129 /* Includes ------------------------------------------------------------------*/
mbed_official 125:23cc3068a9e4 130 #include "stm32f30x_dac.h"
mbed_official 125:23cc3068a9e4 131 #include "stm32f30x_rcc.h"
mbed_official 125:23cc3068a9e4 132
mbed_official 125:23cc3068a9e4 133 /** @addtogroup STM32F30x_StdPeriph_Driver
mbed_official 125:23cc3068a9e4 134 * @{
mbed_official 125:23cc3068a9e4 135 */
mbed_official 125:23cc3068a9e4 136
mbed_official 125:23cc3068a9e4 137 /** @defgroup DAC
mbed_official 125:23cc3068a9e4 138 * @brief DAC driver modules
mbed_official 125:23cc3068a9e4 139 * @{
mbed_official 125:23cc3068a9e4 140 */
mbed_official 125:23cc3068a9e4 141
mbed_official 125:23cc3068a9e4 142 /* Private typedef -----------------------------------------------------------*/
mbed_official 125:23cc3068a9e4 143 /* Private define ------------------------------------------------------------*/
mbed_official 125:23cc3068a9e4 144
mbed_official 125:23cc3068a9e4 145 /* CR register Mask */
mbed_official 125:23cc3068a9e4 146 #define CR_CLEAR_MASK ((uint32_t)0x00000FFE)
mbed_official 125:23cc3068a9e4 147
mbed_official 125:23cc3068a9e4 148 /* DAC Dual Channels SWTRIG masks */
mbed_official 125:23cc3068a9e4 149 #define DUAL_SWTRIG_SET ((uint32_t)0x00000003)
mbed_official 125:23cc3068a9e4 150 #define DUAL_SWTRIG_RESET ((uint32_t)0xFFFFFFFC)
mbed_official 125:23cc3068a9e4 151
mbed_official 125:23cc3068a9e4 152 /* DHR registers offsets */
mbed_official 125:23cc3068a9e4 153 #define DHR12R1_OFFSET ((uint32_t)0x00000008)
mbed_official 125:23cc3068a9e4 154 #define DHR12R2_OFFSET ((uint32_t)0x00000014)
mbed_official 125:23cc3068a9e4 155 #define DHR12RD_OFFSET ((uint32_t)0x00000020)
mbed_official 125:23cc3068a9e4 156
mbed_official 125:23cc3068a9e4 157 /* DOR register offset */
mbed_official 125:23cc3068a9e4 158 #define DOR_OFFSET ((uint32_t)0x0000002C)
mbed_official 125:23cc3068a9e4 159
mbed_official 125:23cc3068a9e4 160 /* Private macro -------------------------------------------------------------*/
mbed_official 125:23cc3068a9e4 161 /* Private variables ---------------------------------------------------------*/
mbed_official 125:23cc3068a9e4 162 /* Private function prototypes -----------------------------------------------*/
mbed_official 125:23cc3068a9e4 163 /* Private functions ---------------------------------------------------------*/
mbed_official 125:23cc3068a9e4 164
mbed_official 125:23cc3068a9e4 165 /** @defgroup DAC_Private_Functions
mbed_official 125:23cc3068a9e4 166 * @{
mbed_official 125:23cc3068a9e4 167 */
mbed_official 125:23cc3068a9e4 168
mbed_official 125:23cc3068a9e4 169 /** @defgroup DAC_Group1 DAC channels configuration
mbed_official 125:23cc3068a9e4 170 * @brief DAC channels configuration: trigger, output buffer, data format
mbed_official 125:23cc3068a9e4 171 *
mbed_official 125:23cc3068a9e4 172 @verbatim
mbed_official 125:23cc3068a9e4 173 ===============================================================================
mbed_official 125:23cc3068a9e4 174 ##### DAC channels configuration: trigger, output buffer, data format #####
mbed_official 125:23cc3068a9e4 175 ===============================================================================
mbed_official 125:23cc3068a9e4 176
mbed_official 125:23cc3068a9e4 177 @endverbatim
mbed_official 125:23cc3068a9e4 178 * @{
mbed_official 125:23cc3068a9e4 179 */
mbed_official 125:23cc3068a9e4 180
mbed_official 125:23cc3068a9e4 181 /**
mbed_official 125:23cc3068a9e4 182 * @brief Deinitializes the DAC peripheral registers to their default reset values.
mbed_official 125:23cc3068a9e4 183 * @param DACx: where x can be 1 or 2 to select the DAC peripheral.
mbed_official 125:23cc3068a9e4 184 * @retval None
mbed_official 125:23cc3068a9e4 185 */
mbed_official 125:23cc3068a9e4 186 void DAC_DeInit(DAC_TypeDef* DACx)
mbed_official 125:23cc3068a9e4 187 {
mbed_official 125:23cc3068a9e4 188 /* Check the parameters */
mbed_official 125:23cc3068a9e4 189 assert_param(IS_DAC_ALL_PERIPH(DACx));
mbed_official 125:23cc3068a9e4 190
mbed_official 125:23cc3068a9e4 191 if (DACx == DAC1)
mbed_official 125:23cc3068a9e4 192 {
mbed_official 125:23cc3068a9e4 193 /* Enable DAC1 reset state */
mbed_official 125:23cc3068a9e4 194 RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC1, ENABLE);
mbed_official 125:23cc3068a9e4 195 /* Release DAC1 from reset state */
mbed_official 125:23cc3068a9e4 196 RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC1, DISABLE);
mbed_official 125:23cc3068a9e4 197 }
mbed_official 125:23cc3068a9e4 198 else
mbed_official 125:23cc3068a9e4 199 {
mbed_official 125:23cc3068a9e4 200 /* Enable DAC2 reset state */
mbed_official 125:23cc3068a9e4 201 RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC2, ENABLE);
mbed_official 125:23cc3068a9e4 202 /* Release DAC2 from reset state */
mbed_official 125:23cc3068a9e4 203 RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC2, DISABLE);
mbed_official 125:23cc3068a9e4 204 }
mbed_official 125:23cc3068a9e4 205 }
mbed_official 125:23cc3068a9e4 206
mbed_official 125:23cc3068a9e4 207 /**
mbed_official 125:23cc3068a9e4 208 * @brief Initializes the DAC peripheral according to the specified
mbed_official 125:23cc3068a9e4 209 * parameters in the DAC_InitStruct.
mbed_official 125:23cc3068a9e4 210 * @param DACx: where x can be 1 or 2 to select the DAC peripheral.
mbed_official 125:23cc3068a9e4 211 * @param DAC_Channel: the selected DAC channel.
mbed_official 125:23cc3068a9e4 212 * This parameter can be one of the following values:
mbed_official 125:23cc3068a9e4 213 * @arg DAC_Channel_1: DAC Channel1 selected
mbed_official 125:23cc3068a9e4 214 * @arg DAC_Channel_2: DAC Channel2 selected
mbed_official 125:23cc3068a9e4 215 * @param DAC_InitStruct: pointer to a DAC_InitTypeDef structure that
mbed_official 125:23cc3068a9e4 216 * contains the configuration information for the specified DAC channel.
mbed_official 125:23cc3068a9e4 217 * @retval None
mbed_official 125:23cc3068a9e4 218 */
mbed_official 125:23cc3068a9e4 219 void DAC_Init(DAC_TypeDef* DACx, uint32_t DAC_Channel, DAC_InitTypeDef* DAC_InitStruct)
mbed_official 125:23cc3068a9e4 220 {
mbed_official 125:23cc3068a9e4 221 uint32_t tmpreg1 = 0, tmpreg2 = 0;
mbed_official 125:23cc3068a9e4 222
mbed_official 125:23cc3068a9e4 223 /* Check the DAC parameters */
mbed_official 125:23cc3068a9e4 224 assert_param(IS_DAC_ALL_PERIPH(DACx));
mbed_official 125:23cc3068a9e4 225 assert_param(IS_DAC_TRIGGER(DAC_InitStruct->DAC_Trigger));
mbed_official 125:23cc3068a9e4 226 assert_param(IS_DAC_GENERATE_WAVE(DAC_InitStruct->DAC_WaveGeneration));
mbed_official 125:23cc3068a9e4 227 assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(DAC_InitStruct->DAC_LFSRUnmask_TriangleAmplitude));
mbed_official 125:23cc3068a9e4 228 assert_param(IS_DAC_BUFFER_SWITCH_STATE(DAC_InitStruct->DAC_Buffer_Switch));
mbed_official 125:23cc3068a9e4 229
mbed_official 125:23cc3068a9e4 230 /*---------------------------- DAC CR Configuration --------------------------*/
mbed_official 125:23cc3068a9e4 231 /* Get the DAC CR value */
mbed_official 125:23cc3068a9e4 232 tmpreg1 = DACx->CR;
mbed_official 125:23cc3068a9e4 233 /* Clear BOFFx, TENx, TSELx, WAVEx and MAMPx bits */
mbed_official 125:23cc3068a9e4 234 tmpreg1 &= ~(CR_CLEAR_MASK << DAC_Channel);
mbed_official 125:23cc3068a9e4 235 /* Configure for the selected DAC channel: buffer output, trigger, wave generation,
mbed_official 125:23cc3068a9e4 236 mask/amplitude for wave generation */
mbed_official 125:23cc3068a9e4 237
mbed_official 125:23cc3068a9e4 238 /* Set TSELx and TENx bits according to DAC_Trigger value */
mbed_official 125:23cc3068a9e4 239 /* Set WAVEx bits according to DAC_WaveGeneration value */
mbed_official 125:23cc3068a9e4 240 /* Set MAMPx bits according to DAC_LFSRUnmask_TriangleAmplitude value */
mbed_official 125:23cc3068a9e4 241 /* Set BOFFx OUTENx bit according to DAC_Buffer_Switch value */
mbed_official 125:23cc3068a9e4 242 tmpreg2 = (DAC_InitStruct->DAC_Trigger | DAC_InitStruct->DAC_WaveGeneration |
mbed_official 125:23cc3068a9e4 243 DAC_InitStruct->DAC_LFSRUnmask_TriangleAmplitude | DAC_InitStruct->DAC_Buffer_Switch);
mbed_official 125:23cc3068a9e4 244
mbed_official 125:23cc3068a9e4 245 /* Calculate CR register value depending on DAC_Channel */
mbed_official 125:23cc3068a9e4 246 tmpreg1 |= tmpreg2 << DAC_Channel;
mbed_official 125:23cc3068a9e4 247 /* Write to DAC CR */
mbed_official 125:23cc3068a9e4 248 DACx->CR = tmpreg1;
mbed_official 125:23cc3068a9e4 249 }
mbed_official 125:23cc3068a9e4 250
mbed_official 125:23cc3068a9e4 251 /**
mbed_official 125:23cc3068a9e4 252 * @brief Fills each DAC_InitStruct member with its default value.
mbed_official 125:23cc3068a9e4 253 * @param DAC_InitStruct: pointer to a DAC_InitTypeDef structure which will
mbed_official 125:23cc3068a9e4 254 * be initialized.
mbed_official 125:23cc3068a9e4 255 * @retval None
mbed_official 125:23cc3068a9e4 256 */
mbed_official 125:23cc3068a9e4 257 void DAC_StructInit(DAC_InitTypeDef* DAC_InitStruct)
mbed_official 125:23cc3068a9e4 258 {
mbed_official 125:23cc3068a9e4 259 /*--------------- Reset DAC init structure parameters values -----------------*/
mbed_official 125:23cc3068a9e4 260 /* Initialize the DAC_Trigger member */
mbed_official 125:23cc3068a9e4 261 DAC_InitStruct->DAC_Trigger = DAC_Trigger_None;
mbed_official 125:23cc3068a9e4 262 /* Initialize the DAC_WaveGeneration member */
mbed_official 125:23cc3068a9e4 263 DAC_InitStruct->DAC_WaveGeneration = DAC_WaveGeneration_None;
mbed_official 125:23cc3068a9e4 264 /* Initialize the DAC_LFSRUnmask_TriangleAmplitude member */
mbed_official 125:23cc3068a9e4 265 DAC_InitStruct->DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bit0;
mbed_official 125:23cc3068a9e4 266 /* Initialize the DAC_Buffer_Switch member */
mbed_official 125:23cc3068a9e4 267 DAC_InitStruct->DAC_Buffer_Switch = DAC_BufferSwitch_Enable;
mbed_official 125:23cc3068a9e4 268 }
mbed_official 125:23cc3068a9e4 269
mbed_official 125:23cc3068a9e4 270 /**
mbed_official 125:23cc3068a9e4 271 * @brief Enables or disables the specified DAC channel.
mbed_official 125:23cc3068a9e4 272 * @param DACx: where x can be 1 or 2 to select the DAC peripheral.
mbed_official 125:23cc3068a9e4 273 * @param DAC_Channel: The selected DAC channel.
mbed_official 125:23cc3068a9e4 274 * This parameter can be one of the following values:
mbed_official 125:23cc3068a9e4 275 * @arg DAC_Channel_1: DAC Channel1 selected
mbed_official 125:23cc3068a9e4 276 * @arg DAC_Channel_2: DAC Channel2 selected
mbed_official 125:23cc3068a9e4 277 * @param NewState: new state of the DAC channel.
mbed_official 125:23cc3068a9e4 278 * This parameter can be: ENABLE or DISABLE.
mbed_official 125:23cc3068a9e4 279 * @note When the DAC channel is enabled the trigger source can no more
mbed_official 125:23cc3068a9e4 280 * be modified.
mbed_official 125:23cc3068a9e4 281 * @retval None
mbed_official 125:23cc3068a9e4 282 */
mbed_official 125:23cc3068a9e4 283 void DAC_Cmd(DAC_TypeDef* DACx, uint32_t DAC_Channel, FunctionalState NewState)
mbed_official 125:23cc3068a9e4 284 {
mbed_official 125:23cc3068a9e4 285 /* Check the parameters */
mbed_official 125:23cc3068a9e4 286 assert_param(IS_DAC_ALL_PERIPH(DACx));
mbed_official 125:23cc3068a9e4 287 assert_param(IS_DAC_CHANNEL(DAC_Channel));
mbed_official 125:23cc3068a9e4 288 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 125:23cc3068a9e4 289
mbed_official 125:23cc3068a9e4 290 if (NewState != DISABLE)
mbed_official 125:23cc3068a9e4 291 {
mbed_official 125:23cc3068a9e4 292 /* Enable the selected DAC channel */
mbed_official 125:23cc3068a9e4 293 DACx->CR |= (DAC_CR_EN1 << DAC_Channel);
mbed_official 125:23cc3068a9e4 294 }
mbed_official 125:23cc3068a9e4 295 else
mbed_official 125:23cc3068a9e4 296 {
mbed_official 125:23cc3068a9e4 297 /* Disable the selected DAC channel */
mbed_official 125:23cc3068a9e4 298 DACx->CR &= (~(DAC_CR_EN1 << DAC_Channel));
mbed_official 125:23cc3068a9e4 299 }
mbed_official 125:23cc3068a9e4 300 }
mbed_official 125:23cc3068a9e4 301
mbed_official 125:23cc3068a9e4 302 /**
mbed_official 125:23cc3068a9e4 303 * @brief Enables or disables the selected DAC channel software trigger.
mbed_official 125:23cc3068a9e4 304 * @param DACx: where x can be 1 or 2 to select the DAC peripheral.
mbed_official 125:23cc3068a9e4 305 * @param DAC_Channel: the selected DAC channel.
mbed_official 125:23cc3068a9e4 306 * This parameter can be one of the following values:
mbed_official 125:23cc3068a9e4 307 * @arg DAC_Channel_1: DAC Channel1 selected
mbed_official 125:23cc3068a9e4 308 * @arg DAC_Channel_2: DAC Channel2 selected
mbed_official 125:23cc3068a9e4 309 * @param NewState: new state of the selected DAC channel software trigger.
mbed_official 125:23cc3068a9e4 310 * This parameter can be: ENABLE or DISABLE.
mbed_official 125:23cc3068a9e4 311 * @retval None
mbed_official 125:23cc3068a9e4 312 */
mbed_official 125:23cc3068a9e4 313 void DAC_SoftwareTriggerCmd(DAC_TypeDef* DACx, uint32_t DAC_Channel, FunctionalState NewState)
mbed_official 125:23cc3068a9e4 314 {
mbed_official 125:23cc3068a9e4 315 /* Check the parameters */
mbed_official 125:23cc3068a9e4 316 assert_param(IS_DAC_ALL_PERIPH(DACx));
mbed_official 125:23cc3068a9e4 317 assert_param(IS_DAC_CHANNEL(DAC_Channel));
mbed_official 125:23cc3068a9e4 318 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 125:23cc3068a9e4 319
mbed_official 125:23cc3068a9e4 320 if (NewState != DISABLE)
mbed_official 125:23cc3068a9e4 321 {
mbed_official 125:23cc3068a9e4 322 /* Enable software trigger for the selected DAC channel */
mbed_official 125:23cc3068a9e4 323 DACx->SWTRIGR |= (uint32_t)DAC_SWTRIGR_SWTRIG1 << (DAC_Channel >> 4);
mbed_official 125:23cc3068a9e4 324 }
mbed_official 125:23cc3068a9e4 325 else
mbed_official 125:23cc3068a9e4 326 {
mbed_official 125:23cc3068a9e4 327 /* Disable software trigger for the selected DAC channel */
mbed_official 125:23cc3068a9e4 328 DACx->SWTRIGR &= ~((uint32_t)DAC_SWTRIGR_SWTRIG1 << (DAC_Channel >> 4));
mbed_official 125:23cc3068a9e4 329 }
mbed_official 125:23cc3068a9e4 330 }
mbed_official 125:23cc3068a9e4 331
mbed_official 125:23cc3068a9e4 332 /**
mbed_official 125:23cc3068a9e4 333 * @brief Enables or disables simultaneously the two DAC channels software
mbed_official 125:23cc3068a9e4 334 * triggers.
mbed_official 125:23cc3068a9e4 335 * @param DACx: where x can be 1 to select the DAC1 peripheral.
mbed_official 125:23cc3068a9e4 336 * @note Dual trigger is not applicable for DAC2 (DAC2 integrates one channel).
mbed_official 125:23cc3068a9e4 337 * @param NewState: new state of the DAC channels software triggers.
mbed_official 125:23cc3068a9e4 338 * This parameter can be: ENABLE or DISABLE.
mbed_official 125:23cc3068a9e4 339 * @retval None
mbed_official 125:23cc3068a9e4 340 */
mbed_official 125:23cc3068a9e4 341 void DAC_DualSoftwareTriggerCmd(DAC_TypeDef* DACx, FunctionalState NewState)
mbed_official 125:23cc3068a9e4 342 {
mbed_official 125:23cc3068a9e4 343 /* Check the parameters */
mbed_official 125:23cc3068a9e4 344 assert_param(IS_DAC_LIST1_PERIPH(DACx));
mbed_official 125:23cc3068a9e4 345 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 125:23cc3068a9e4 346
mbed_official 125:23cc3068a9e4 347 if (NewState != DISABLE)
mbed_official 125:23cc3068a9e4 348 {
mbed_official 125:23cc3068a9e4 349 /* Enable software trigger for both DAC channels */
mbed_official 125:23cc3068a9e4 350 DACx->SWTRIGR |= DUAL_SWTRIG_SET;
mbed_official 125:23cc3068a9e4 351 }
mbed_official 125:23cc3068a9e4 352 else
mbed_official 125:23cc3068a9e4 353 {
mbed_official 125:23cc3068a9e4 354 /* Disable software trigger for both DAC channels */
mbed_official 125:23cc3068a9e4 355 DACx->SWTRIGR &= DUAL_SWTRIG_RESET;
mbed_official 125:23cc3068a9e4 356 }
mbed_official 125:23cc3068a9e4 357 }
mbed_official 125:23cc3068a9e4 358
mbed_official 125:23cc3068a9e4 359 /**
mbed_official 125:23cc3068a9e4 360 * @brief Enables or disables the selected DAC channel wave generation.
mbed_official 125:23cc3068a9e4 361 * @param DACx: where x can be 1 to select the DAC1 peripheral.
mbed_official 125:23cc3068a9e4 362 * @note Wave generation is not available in DAC2.
mbed_official 125:23cc3068a9e4 363 * @param DAC_Channel: the selected DAC channel.
mbed_official 125:23cc3068a9e4 364 * This parameter can be one of the following values:
mbed_official 125:23cc3068a9e4 365 * @arg DAC_Channel_1: DAC Channel1 selected
mbed_official 125:23cc3068a9e4 366 * @arg DAC_Channel_2: DAC Channel2 selected
mbed_official 125:23cc3068a9e4 367 * @param DAC_Wave: Specifies the wave type to enable or disable.
mbed_official 125:23cc3068a9e4 368 * This parameter can be one of the following values:
mbed_official 125:23cc3068a9e4 369 * @arg DAC_Wave_Noise: noise wave generation
mbed_official 125:23cc3068a9e4 370 * @arg DAC_Wave_Triangle: triangle wave generation
mbed_official 125:23cc3068a9e4 371 * @param NewState: new state of the selected DAC channel wave generation.
mbed_official 125:23cc3068a9e4 372 * This parameter can be: ENABLE or DISABLE.
mbed_official 125:23cc3068a9e4 373 * @note
mbed_official 125:23cc3068a9e4 374 * @retval None
mbed_official 125:23cc3068a9e4 375 */
mbed_official 125:23cc3068a9e4 376 void DAC_WaveGenerationCmd(DAC_TypeDef* DACx, uint32_t DAC_Channel, uint32_t DAC_Wave, FunctionalState NewState)
mbed_official 125:23cc3068a9e4 377 {
mbed_official 125:23cc3068a9e4 378 /* Check the parameters */
mbed_official 125:23cc3068a9e4 379 assert_param(IS_DAC_LIST1_PERIPH(DACx));
mbed_official 125:23cc3068a9e4 380 assert_param(IS_DAC_CHANNEL(DAC_Channel));
mbed_official 125:23cc3068a9e4 381 assert_param(IS_DAC_WAVE(DAC_Wave));
mbed_official 125:23cc3068a9e4 382 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 125:23cc3068a9e4 383
mbed_official 125:23cc3068a9e4 384 if (NewState != DISABLE)
mbed_official 125:23cc3068a9e4 385 {
mbed_official 125:23cc3068a9e4 386 /* Enable the selected wave generation for the selected DAC channel */
mbed_official 125:23cc3068a9e4 387 DACx->CR |= DAC_Wave << DAC_Channel;
mbed_official 125:23cc3068a9e4 388 }
mbed_official 125:23cc3068a9e4 389 else
mbed_official 125:23cc3068a9e4 390 {
mbed_official 125:23cc3068a9e4 391 /* Disable the selected wave generation for the selected DAC channel */
mbed_official 125:23cc3068a9e4 392 DACx->CR &= ~(DAC_Wave << DAC_Channel);
mbed_official 125:23cc3068a9e4 393 }
mbed_official 125:23cc3068a9e4 394 }
mbed_official 125:23cc3068a9e4 395
mbed_official 125:23cc3068a9e4 396 /**
mbed_official 125:23cc3068a9e4 397 * @brief Set the specified data holding register value for DAC channel1.
mbed_official 125:23cc3068a9e4 398 * @param DACx: where x can be 1 or 2 to select the DAC peripheral.
mbed_official 125:23cc3068a9e4 399 * @param DAC_Align: Specifies the data alignment for DAC channel1.
mbed_official 125:23cc3068a9e4 400 * This parameter can be one of the following values:
mbed_official 125:23cc3068a9e4 401 * @arg DAC_Align_8b_R: 8bit right data alignment selected
mbed_official 125:23cc3068a9e4 402 * @arg DAC_Align_12b_L: 12bit left data alignment selected
mbed_official 125:23cc3068a9e4 403 * @arg DAC_Align_12b_R: 12bit right data alignment selected
mbed_official 125:23cc3068a9e4 404 * @param Data: Data to be loaded in the selected data holding register.
mbed_official 125:23cc3068a9e4 405 * @retval None
mbed_official 125:23cc3068a9e4 406 */
mbed_official 125:23cc3068a9e4 407 void DAC_SetChannel1Data(DAC_TypeDef* DACx, uint32_t DAC_Align, uint16_t Data)
mbed_official 125:23cc3068a9e4 408 {
mbed_official 125:23cc3068a9e4 409 __IO uint32_t tmp = 0;
mbed_official 125:23cc3068a9e4 410
mbed_official 125:23cc3068a9e4 411 /* Check the parameters */
mbed_official 125:23cc3068a9e4 412 assert_param(IS_DAC_ALL_PERIPH(DACx));
mbed_official 125:23cc3068a9e4 413 assert_param(IS_DAC_ALIGN(DAC_Align));
mbed_official 125:23cc3068a9e4 414 assert_param(IS_DAC_DATA(Data));
mbed_official 125:23cc3068a9e4 415
mbed_official 125:23cc3068a9e4 416 tmp = (uint32_t)DACx;
mbed_official 125:23cc3068a9e4 417 tmp += DHR12R1_OFFSET + DAC_Align;
mbed_official 125:23cc3068a9e4 418
mbed_official 125:23cc3068a9e4 419 /* Set the DAC channel1 selected data holding register */
mbed_official 125:23cc3068a9e4 420 *(__IO uint32_t *) tmp = Data;
mbed_official 125:23cc3068a9e4 421 }
mbed_official 125:23cc3068a9e4 422
mbed_official 125:23cc3068a9e4 423 /**
mbed_official 125:23cc3068a9e4 424 * @brief Set the specified data holding register value for DAC channel2.
mbed_official 125:23cc3068a9e4 425 * @param DACx: where x can be 1 to select the DAC peripheral.
mbed_official 125:23cc3068a9e4 426 * @note This function is available only for DAC1.
mbed_official 125:23cc3068a9e4 427 * @param DAC_Align: Specifies the data alignment for DAC channel2.
mbed_official 125:23cc3068a9e4 428 * This parameter can be one of the following values:
mbed_official 125:23cc3068a9e4 429 * @arg DAC_Align_8b_R: 8bit right data alignment selected
mbed_official 125:23cc3068a9e4 430 * @arg DAC_Align_12b_L: 12bit left data alignment selected
mbed_official 125:23cc3068a9e4 431 * @arg DAC_Align_12b_R: 12bit right data alignment selected
mbed_official 125:23cc3068a9e4 432 * @param Data : Data to be loaded in the selected data holding register.
mbed_official 125:23cc3068a9e4 433 * @retval None
mbed_official 125:23cc3068a9e4 434 */
mbed_official 125:23cc3068a9e4 435 void DAC_SetChannel2Data(DAC_TypeDef* DACx, uint32_t DAC_Align, uint16_t Data)
mbed_official 125:23cc3068a9e4 436 {
mbed_official 125:23cc3068a9e4 437 __IO uint32_t tmp = 0;
mbed_official 125:23cc3068a9e4 438
mbed_official 125:23cc3068a9e4 439 /* Check the parameters */
mbed_official 125:23cc3068a9e4 440 assert_param(IS_DAC_LIST1_PERIPH(DACx));
mbed_official 125:23cc3068a9e4 441 assert_param(IS_DAC_ALIGN(DAC_Align));
mbed_official 125:23cc3068a9e4 442 assert_param(IS_DAC_DATA(Data));
mbed_official 125:23cc3068a9e4 443
mbed_official 125:23cc3068a9e4 444 tmp = (uint32_t)DACx;
mbed_official 125:23cc3068a9e4 445 tmp += DHR12R2_OFFSET + DAC_Align;
mbed_official 125:23cc3068a9e4 446
mbed_official 125:23cc3068a9e4 447 /* Set the DAC channel2 selected data holding register */
mbed_official 125:23cc3068a9e4 448 *(__IO uint32_t *)tmp = Data;
mbed_official 125:23cc3068a9e4 449 }
mbed_official 125:23cc3068a9e4 450
mbed_official 125:23cc3068a9e4 451 /**
mbed_official 125:23cc3068a9e4 452 * @brief Set the specified data holding register value for dual channel DAC.
mbed_official 125:23cc3068a9e4 453 * @param DACx: where x can be 1 to select the DAC peripheral.
mbed_official 125:23cc3068a9e4 454 * @note This function isn't applicable for DAC2.
mbed_official 125:23cc3068a9e4 455 * @param DAC_Align: Specifies the data alignment for dual channel DAC.
mbed_official 125:23cc3068a9e4 456 * This parameter can be one of the following values:
mbed_official 125:23cc3068a9e4 457 * @arg DAC_Align_8b_R: 8bit right data alignment selected
mbed_official 125:23cc3068a9e4 458 * @arg DAC_Align_12b_L: 12bit left data alignment selected
mbed_official 125:23cc3068a9e4 459 * @arg DAC_Align_12b_R: 12bit right data alignment selected
mbed_official 125:23cc3068a9e4 460 * @param Data2: Data for DAC Channel2 to be loaded in the selected data
mbed_official 125:23cc3068a9e4 461 * holding register.
mbed_official 125:23cc3068a9e4 462 * @param Data1: Data for DAC Channel1 to be loaded in the selected data
mbed_official 125:23cc3068a9e4 463 * holding register.
mbed_official 125:23cc3068a9e4 464 * @note In dual mode, a unique register access is required to write in both
mbed_official 125:23cc3068a9e4 465 * DAC channels at the same time.
mbed_official 125:23cc3068a9e4 466 * @retval None
mbed_official 125:23cc3068a9e4 467 */
mbed_official 125:23cc3068a9e4 468 void DAC_SetDualChannelData(DAC_TypeDef* DACx, uint32_t DAC_Align, uint16_t Data2, uint16_t Data1)
mbed_official 125:23cc3068a9e4 469 {
mbed_official 125:23cc3068a9e4 470 uint32_t data = 0, tmp = 0;
mbed_official 125:23cc3068a9e4 471
mbed_official 125:23cc3068a9e4 472 /* Check the parameters */
mbed_official 125:23cc3068a9e4 473 assert_param(IS_DAC_LIST1_PERIPH(DACx));
mbed_official 125:23cc3068a9e4 474 assert_param(IS_DAC_ALIGN(DAC_Align));
mbed_official 125:23cc3068a9e4 475 assert_param(IS_DAC_DATA(Data1));
mbed_official 125:23cc3068a9e4 476 assert_param(IS_DAC_DATA(Data2));
mbed_official 125:23cc3068a9e4 477
mbed_official 125:23cc3068a9e4 478 /* Calculate and set dual DAC data holding register value */
mbed_official 125:23cc3068a9e4 479 if (DAC_Align == DAC_Align_8b_R)
mbed_official 125:23cc3068a9e4 480 {
mbed_official 125:23cc3068a9e4 481 data = ((uint32_t)Data2 << 8) | Data1;
mbed_official 125:23cc3068a9e4 482 }
mbed_official 125:23cc3068a9e4 483 else
mbed_official 125:23cc3068a9e4 484 {
mbed_official 125:23cc3068a9e4 485 data = ((uint32_t)Data2 << 16) | Data1;
mbed_official 125:23cc3068a9e4 486 }
mbed_official 125:23cc3068a9e4 487
mbed_official 125:23cc3068a9e4 488 tmp = (uint32_t)DACx;
mbed_official 125:23cc3068a9e4 489 tmp += DHR12RD_OFFSET + DAC_Align;
mbed_official 125:23cc3068a9e4 490
mbed_official 125:23cc3068a9e4 491 /* Set the dual DAC selected data holding register */
mbed_official 125:23cc3068a9e4 492 *(__IO uint32_t *)tmp = data;
mbed_official 125:23cc3068a9e4 493 }
mbed_official 125:23cc3068a9e4 494
mbed_official 125:23cc3068a9e4 495 /**
mbed_official 125:23cc3068a9e4 496 * @brief Returns the last data output value of the selected DAC channel.
mbed_official 125:23cc3068a9e4 497 * @param DACx: where x can be 1 or 2 to select the DAC peripheral.
mbed_official 125:23cc3068a9e4 498 * @param DAC_Channel: the selected DAC channel.
mbed_official 125:23cc3068a9e4 499 * This parameter can be one of the following values:
mbed_official 125:23cc3068a9e4 500 * @arg DAC_Channel_1: DAC Channel1 selected
mbed_official 125:23cc3068a9e4 501 * @arg DAC_Channel_2: DAC Channel2 selected
mbed_official 125:23cc3068a9e4 502 * @retval The selected DAC channel data output value.
mbed_official 125:23cc3068a9e4 503 */
mbed_official 125:23cc3068a9e4 504 uint16_t DAC_GetDataOutputValue(DAC_TypeDef* DACx, uint32_t DAC_Channel)
mbed_official 125:23cc3068a9e4 505 {
mbed_official 125:23cc3068a9e4 506 __IO uint32_t tmp = 0;
mbed_official 125:23cc3068a9e4 507
mbed_official 125:23cc3068a9e4 508 /* Check the parameters */
mbed_official 125:23cc3068a9e4 509 assert_param(IS_DAC_ALL_PERIPH(DACx));
mbed_official 125:23cc3068a9e4 510 assert_param(IS_DAC_CHANNEL(DAC_Channel));
mbed_official 125:23cc3068a9e4 511
mbed_official 125:23cc3068a9e4 512 tmp = (uint32_t) DACx;
mbed_official 125:23cc3068a9e4 513 tmp += DOR_OFFSET + ((uint32_t)DAC_Channel >> 2);
mbed_official 125:23cc3068a9e4 514
mbed_official 125:23cc3068a9e4 515 /* Returns the DAC channel data output register value */
mbed_official 125:23cc3068a9e4 516 return (uint16_t) (*(__IO uint32_t*) tmp);
mbed_official 125:23cc3068a9e4 517 }
mbed_official 125:23cc3068a9e4 518
mbed_official 125:23cc3068a9e4 519 /**
mbed_official 125:23cc3068a9e4 520 * @}
mbed_official 125:23cc3068a9e4 521 */
mbed_official 125:23cc3068a9e4 522
mbed_official 125:23cc3068a9e4 523 /** @defgroup DAC_Group2 DMA management functions
mbed_official 125:23cc3068a9e4 524 * @brief DMA management functions
mbed_official 125:23cc3068a9e4 525 *
mbed_official 125:23cc3068a9e4 526 @verbatim
mbed_official 125:23cc3068a9e4 527 ===============================================================================
mbed_official 125:23cc3068a9e4 528 ##### DMA management functions #####
mbed_official 125:23cc3068a9e4 529 ===============================================================================
mbed_official 125:23cc3068a9e4 530
mbed_official 125:23cc3068a9e4 531 @endverbatim
mbed_official 125:23cc3068a9e4 532 * @{
mbed_official 125:23cc3068a9e4 533 */
mbed_official 125:23cc3068a9e4 534
mbed_official 125:23cc3068a9e4 535 /**
mbed_official 125:23cc3068a9e4 536 * @brief Enables or disables the specified DAC channel DMA request.
mbed_official 125:23cc3068a9e4 537 * When enabled DMA1 is generated when an external trigger (EXTI Line9,
mbed_official 125:23cc3068a9e4 538 * TIM2, TIM4, TIM6, TIM7 or TIM9 but not a software trigger) occurs
mbed_official 125:23cc3068a9e4 539 * @param DACx: where x can be 1 or 2 to select the DAC peripheral.
mbed_official 125:23cc3068a9e4 540 * @param DAC_Channel: the selected DAC channel.
mbed_official 125:23cc3068a9e4 541 * This parameter can be one of the following values:
mbed_official 125:23cc3068a9e4 542 * @arg DAC_Channel_1: DAC Channel1 selected
mbed_official 125:23cc3068a9e4 543 * @arg DAC_Channel_2: DAC Channel2 selected
mbed_official 125:23cc3068a9e4 544 * @param NewState: new state of the selected DAC channel DMA request.
mbed_official 125:23cc3068a9e4 545 * This parameter can be: ENABLE or DISABLE.
mbed_official 125:23cc3068a9e4 546 * @note The DAC channel1 (channel2) is mapped on DMA1 channel3 (channel4) which
mbed_official 125:23cc3068a9e4 547 * must be already configured.
mbed_official 125:23cc3068a9e4 548 * @retval None
mbed_official 125:23cc3068a9e4 549 */
mbed_official 125:23cc3068a9e4 550 void DAC_DMACmd(DAC_TypeDef* DACx, uint32_t DAC_Channel, FunctionalState NewState)
mbed_official 125:23cc3068a9e4 551 {
mbed_official 125:23cc3068a9e4 552 /* Check the parameters */
mbed_official 125:23cc3068a9e4 553 assert_param(IS_DAC_ALL_PERIPH(DACx));
mbed_official 125:23cc3068a9e4 554 assert_param(IS_DAC_CHANNEL(DAC_Channel));
mbed_official 125:23cc3068a9e4 555 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 125:23cc3068a9e4 556
mbed_official 125:23cc3068a9e4 557 if (NewState != DISABLE)
mbed_official 125:23cc3068a9e4 558 {
mbed_official 125:23cc3068a9e4 559 /* Enable the selected DAC channel DMA request */
mbed_official 125:23cc3068a9e4 560 DACx->CR |= (DAC_CR_DMAEN1 << DAC_Channel);
mbed_official 125:23cc3068a9e4 561 }
mbed_official 125:23cc3068a9e4 562 else
mbed_official 125:23cc3068a9e4 563 {
mbed_official 125:23cc3068a9e4 564 /* Disable the selected DAC channel DMA request */
mbed_official 125:23cc3068a9e4 565 DACx->CR &= (~(DAC_CR_DMAEN1 << DAC_Channel));
mbed_official 125:23cc3068a9e4 566 }
mbed_official 125:23cc3068a9e4 567 }
mbed_official 125:23cc3068a9e4 568
mbed_official 125:23cc3068a9e4 569 /**
mbed_official 125:23cc3068a9e4 570 * @}
mbed_official 125:23cc3068a9e4 571 */
mbed_official 125:23cc3068a9e4 572
mbed_official 125:23cc3068a9e4 573 /** @defgroup DAC_Group3 Interrupts and flags management functions
mbed_official 125:23cc3068a9e4 574 * @brief Interrupts and flags management functions
mbed_official 125:23cc3068a9e4 575 *
mbed_official 125:23cc3068a9e4 576 @verbatim
mbed_official 125:23cc3068a9e4 577 ===============================================================================
mbed_official 125:23cc3068a9e4 578 ##### Interrupts and flags management functions #####
mbed_official 125:23cc3068a9e4 579 ===============================================================================
mbed_official 125:23cc3068a9e4 580
mbed_official 125:23cc3068a9e4 581 @endverbatim
mbed_official 125:23cc3068a9e4 582 * @{
mbed_official 125:23cc3068a9e4 583 */
mbed_official 125:23cc3068a9e4 584
mbed_official 125:23cc3068a9e4 585 /**
mbed_official 125:23cc3068a9e4 586 * @brief Enables or disables the specified DAC interrupts.
mbed_official 125:23cc3068a9e4 587 * @param DACx: where x can be 1 or 2 to select the DAC peripheral.
mbed_official 125:23cc3068a9e4 588 * @param DAC_Channel: the selected DAC channel.
mbed_official 125:23cc3068a9e4 589 * This parameter can be one of the following values:
mbed_official 125:23cc3068a9e4 590 * @arg DAC_Channel_1: DAC Channel1 selected
mbed_official 125:23cc3068a9e4 591 * @arg DAC_Channel_2: DAC Channel2 selected
mbed_official 125:23cc3068a9e4 592 * @param DAC_IT: specifies the DAC interrupt sources to be enabled or disabled.
mbed_official 125:23cc3068a9e4 593 * This parameter can be:
mbed_official 125:23cc3068a9e4 594 * @arg DAC_IT_DMAUDR: DMA underrun interrupt mask
mbed_official 125:23cc3068a9e4 595 * @note The DMA underrun occurs when a second external trigger arrives before
mbed_official 125:23cc3068a9e4 596 * the acknowledgement for the first external trigger is received (first request).
mbed_official 125:23cc3068a9e4 597 * @param NewState: new state of the specified DAC interrupts.
mbed_official 125:23cc3068a9e4 598 * This parameter can be: ENABLE or DISABLE.
mbed_official 125:23cc3068a9e4 599 * @retval None
mbed_official 125:23cc3068a9e4 600 */
mbed_official 125:23cc3068a9e4 601 void DAC_ITConfig(DAC_TypeDef* DACx, uint32_t DAC_Channel, uint32_t DAC_IT, FunctionalState NewState)
mbed_official 125:23cc3068a9e4 602 {
mbed_official 125:23cc3068a9e4 603 /* Check the parameters */
mbed_official 125:23cc3068a9e4 604 assert_param(IS_DAC_ALL_PERIPH(DACx));
mbed_official 125:23cc3068a9e4 605 assert_param(IS_DAC_CHANNEL(DAC_Channel));
mbed_official 125:23cc3068a9e4 606 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 125:23cc3068a9e4 607 assert_param(IS_DAC_IT(DAC_IT));
mbed_official 125:23cc3068a9e4 608
mbed_official 125:23cc3068a9e4 609 if (NewState != DISABLE)
mbed_official 125:23cc3068a9e4 610 {
mbed_official 125:23cc3068a9e4 611 /* Enable the selected DAC interrupts */
mbed_official 125:23cc3068a9e4 612 DACx->CR |= (DAC_IT << DAC_Channel);
mbed_official 125:23cc3068a9e4 613 }
mbed_official 125:23cc3068a9e4 614 else
mbed_official 125:23cc3068a9e4 615 {
mbed_official 125:23cc3068a9e4 616 /* Disable the selected DAC interrupts */
mbed_official 125:23cc3068a9e4 617 DACx->CR &= (~(uint32_t)(DAC_IT << DAC_Channel));
mbed_official 125:23cc3068a9e4 618 }
mbed_official 125:23cc3068a9e4 619 }
mbed_official 125:23cc3068a9e4 620
mbed_official 125:23cc3068a9e4 621 /**
mbed_official 125:23cc3068a9e4 622 * @brief Checks whether the specified DAC flag is set or not.
mbed_official 125:23cc3068a9e4 623 * @param DACx: where x can be 1 or 2 to select the DAC peripheral.
mbed_official 125:23cc3068a9e4 624 * @param DAC_Channel: thee selected DAC channel.
mbed_official 125:23cc3068a9e4 625 * This parameter can be one of the following values:
mbed_official 125:23cc3068a9e4 626 * @arg DAC_Channel_1: DAC Channel1 selected
mbed_official 125:23cc3068a9e4 627 * @arg DAC_Channel_2: DAC Channel2 selected
mbed_official 125:23cc3068a9e4 628 * @param DAC_FLAG: specifies the flag to check.
mbed_official 125:23cc3068a9e4 629 * This parameter can be:
mbed_official 125:23cc3068a9e4 630 * @arg DAC_FLAG_DMAUDR: DMA underrun flag
mbed_official 125:23cc3068a9e4 631 * @note The DMA underrun occurs when a second external trigger arrives before
mbed_official 125:23cc3068a9e4 632 * the acknowledgement for the first external trigger is received (first request).
mbed_official 125:23cc3068a9e4 633 * @retval The new state of DAC_FLAG (SET or RESET).
mbed_official 125:23cc3068a9e4 634 */
mbed_official 125:23cc3068a9e4 635 FlagStatus DAC_GetFlagStatus(DAC_TypeDef* DACx, uint32_t DAC_Channel, uint32_t DAC_FLAG)
mbed_official 125:23cc3068a9e4 636 {
mbed_official 125:23cc3068a9e4 637 FlagStatus bitstatus = RESET;
mbed_official 125:23cc3068a9e4 638
mbed_official 125:23cc3068a9e4 639 /* Check the parameters */
mbed_official 125:23cc3068a9e4 640 assert_param(IS_DAC_ALL_PERIPH(DACx));
mbed_official 125:23cc3068a9e4 641 assert_param(IS_DAC_CHANNEL(DAC_Channel));
mbed_official 125:23cc3068a9e4 642 assert_param(IS_DAC_FLAG(DAC_FLAG));
mbed_official 125:23cc3068a9e4 643
mbed_official 125:23cc3068a9e4 644 /* Check the status of the specified DAC flag */
mbed_official 125:23cc3068a9e4 645 if ((DACx->SR & (DAC_FLAG << DAC_Channel)) != (uint8_t)RESET)
mbed_official 125:23cc3068a9e4 646 {
mbed_official 125:23cc3068a9e4 647 /* DAC_FLAG is set */
mbed_official 125:23cc3068a9e4 648 bitstatus = SET;
mbed_official 125:23cc3068a9e4 649 }
mbed_official 125:23cc3068a9e4 650 else
mbed_official 125:23cc3068a9e4 651 {
mbed_official 125:23cc3068a9e4 652 /* DAC_FLAG is reset */
mbed_official 125:23cc3068a9e4 653 bitstatus = RESET;
mbed_official 125:23cc3068a9e4 654 }
mbed_official 125:23cc3068a9e4 655 /* Return the DAC_FLAG status */
mbed_official 125:23cc3068a9e4 656 return bitstatus;
mbed_official 125:23cc3068a9e4 657 }
mbed_official 125:23cc3068a9e4 658
mbed_official 125:23cc3068a9e4 659 /**
mbed_official 125:23cc3068a9e4 660 * @brief Clears the DAC channel's pending flags.
mbed_official 125:23cc3068a9e4 661 * @param DACx: where x can be 1 or 2 to select the DAC peripheral.
mbed_official 125:23cc3068a9e4 662 * @param DAC_Channel: the selected DAC channel.
mbed_official 125:23cc3068a9e4 663 * This parameter can be one of the following values:
mbed_official 125:23cc3068a9e4 664 * @arg DAC_Channel_1: DAC Channel1 selected
mbed_official 125:23cc3068a9e4 665 * @arg DAC_Channel_2: DAC Channel2 selected
mbed_official 125:23cc3068a9e4 666 * @param DAC_FLAG: specifies the flag to clear.
mbed_official 125:23cc3068a9e4 667 * This parameter can be:
mbed_official 125:23cc3068a9e4 668 * @arg DAC_FLAG_DMAUDR: DMA underrun flag
mbed_official 125:23cc3068a9e4 669 * @retval None
mbed_official 125:23cc3068a9e4 670 */
mbed_official 125:23cc3068a9e4 671 void DAC_ClearFlag(DAC_TypeDef* DACx, uint32_t DAC_Channel, uint32_t DAC_FLAG)
mbed_official 125:23cc3068a9e4 672 {
mbed_official 125:23cc3068a9e4 673 /* Check the parameters */
mbed_official 125:23cc3068a9e4 674 assert_param(IS_DAC_ALL_PERIPH(DACx));
mbed_official 125:23cc3068a9e4 675 assert_param(IS_DAC_CHANNEL(DAC_Channel));
mbed_official 125:23cc3068a9e4 676 assert_param(IS_DAC_FLAG(DAC_FLAG));
mbed_official 125:23cc3068a9e4 677
mbed_official 125:23cc3068a9e4 678 /* Clear the selected DAC flags */
mbed_official 125:23cc3068a9e4 679 DACx->SR = (DAC_FLAG << DAC_Channel);
mbed_official 125:23cc3068a9e4 680 }
mbed_official 125:23cc3068a9e4 681
mbed_official 125:23cc3068a9e4 682 /**
mbed_official 125:23cc3068a9e4 683 * @brief Checks whether the specified DAC interrupt has occurred or not.
mbed_official 125:23cc3068a9e4 684 * @param DACx: where x can be 1 or 2 to select the DAC peripheral.
mbed_official 125:23cc3068a9e4 685 * @param DAC_Channel: the selected DAC channel.
mbed_official 125:23cc3068a9e4 686 * This parameter can be one of the following values:
mbed_official 125:23cc3068a9e4 687 * @arg DAC_Channel_1: DAC Channel1 selected
mbed_official 125:23cc3068a9e4 688 * @arg DAC_Channel_2: DAC Channel2 selected
mbed_official 125:23cc3068a9e4 689 * @param DAC_IT: specifies the DAC interrupt source to check.
mbed_official 125:23cc3068a9e4 690 * This parameter can be:
mbed_official 125:23cc3068a9e4 691 * @arg DAC_IT_DMAUDR: DMA underrun interrupt mask
mbed_official 125:23cc3068a9e4 692 * @note The DMA underrun occurs when a second external trigger arrives before
mbed_official 125:23cc3068a9e4 693 * the acknowledgement for the first external trigger is received (first request).
mbed_official 125:23cc3068a9e4 694 * @retval The new state of DAC_IT (SET or RESET).
mbed_official 125:23cc3068a9e4 695 */
mbed_official 125:23cc3068a9e4 696 ITStatus DAC_GetITStatus(DAC_TypeDef* DACx, uint32_t DAC_Channel, uint32_t DAC_IT)
mbed_official 125:23cc3068a9e4 697 {
mbed_official 125:23cc3068a9e4 698 ITStatus bitstatus = RESET;
mbed_official 125:23cc3068a9e4 699 uint32_t enablestatus = 0;
mbed_official 125:23cc3068a9e4 700
mbed_official 125:23cc3068a9e4 701 /* Check the parameters */
mbed_official 125:23cc3068a9e4 702 assert_param(IS_DAC_ALL_PERIPH(DACx));
mbed_official 125:23cc3068a9e4 703 assert_param(IS_DAC_CHANNEL(DAC_Channel));
mbed_official 125:23cc3068a9e4 704 assert_param(IS_DAC_IT(DAC_IT));
mbed_official 125:23cc3068a9e4 705
mbed_official 125:23cc3068a9e4 706 /* Get the DAC_IT enable bit status */
mbed_official 125:23cc3068a9e4 707 enablestatus = (DACx->CR & (DAC_IT << DAC_Channel)) ;
mbed_official 125:23cc3068a9e4 708
mbed_official 125:23cc3068a9e4 709 /* Check the status of the specified DAC interrupt */
mbed_official 125:23cc3068a9e4 710 if (((DACx->SR & (DAC_IT << DAC_Channel)) != (uint32_t)RESET) && enablestatus)
mbed_official 125:23cc3068a9e4 711 {
mbed_official 125:23cc3068a9e4 712 /* DAC_IT is set */
mbed_official 125:23cc3068a9e4 713 bitstatus = SET;
mbed_official 125:23cc3068a9e4 714 }
mbed_official 125:23cc3068a9e4 715 else
mbed_official 125:23cc3068a9e4 716 {
mbed_official 125:23cc3068a9e4 717 /* DAC_IT is reset */
mbed_official 125:23cc3068a9e4 718 bitstatus = RESET;
mbed_official 125:23cc3068a9e4 719 }
mbed_official 125:23cc3068a9e4 720 /* Return the DAC_IT status */
mbed_official 125:23cc3068a9e4 721 return bitstatus;
mbed_official 125:23cc3068a9e4 722 }
mbed_official 125:23cc3068a9e4 723
mbed_official 125:23cc3068a9e4 724 /**
mbed_official 125:23cc3068a9e4 725 * @brief Clears the DAC channel's interrupt pending bits.
mbed_official 125:23cc3068a9e4 726 * @param DACx: where x can be 1 or 2 to select the DAC peripheral.
mbed_official 125:23cc3068a9e4 727 * @param DAC_Channel: the selected DAC channel.
mbed_official 125:23cc3068a9e4 728 * This parameter can be one of the following values:
mbed_official 125:23cc3068a9e4 729 * @arg DAC_Channel_1: DAC Channel1 selected
mbed_official 125:23cc3068a9e4 730 * @arg DAC_Channel_2: DAC Channel2 selected
mbed_official 125:23cc3068a9e4 731 * @param DAC_IT: specifies the DAC interrupt pending bit to clear.
mbed_official 125:23cc3068a9e4 732 * This parameter can be the following values:
mbed_official 125:23cc3068a9e4 733 * @arg DAC_IT_DMAUDR: DMA underrun interrupt mask
mbed_official 125:23cc3068a9e4 734 * @retval None
mbed_official 125:23cc3068a9e4 735 */
mbed_official 125:23cc3068a9e4 736 void DAC_ClearITPendingBit(DAC_TypeDef* DACx, uint32_t DAC_Channel, uint32_t DAC_IT)
mbed_official 125:23cc3068a9e4 737 {
mbed_official 125:23cc3068a9e4 738 /* Check the parameters */
mbed_official 125:23cc3068a9e4 739 assert_param(IS_DAC_ALL_PERIPH(DACx));
mbed_official 125:23cc3068a9e4 740 assert_param(IS_DAC_CHANNEL(DAC_Channel));
mbed_official 125:23cc3068a9e4 741 assert_param(IS_DAC_IT(DAC_IT));
mbed_official 125:23cc3068a9e4 742
mbed_official 125:23cc3068a9e4 743 /* Clear the selected DAC interrupt pending bits */
mbed_official 125:23cc3068a9e4 744 DACx->SR = (DAC_IT << DAC_Channel);
mbed_official 125:23cc3068a9e4 745 }
mbed_official 125:23cc3068a9e4 746
mbed_official 125:23cc3068a9e4 747 /**
mbed_official 125:23cc3068a9e4 748 * @}
mbed_official 125:23cc3068a9e4 749 */
mbed_official 125:23cc3068a9e4 750
mbed_official 125:23cc3068a9e4 751 /**
mbed_official 125:23cc3068a9e4 752 * @}
mbed_official 125:23cc3068a9e4 753 */
mbed_official 125:23cc3068a9e4 754
mbed_official 125:23cc3068a9e4 755 /**
mbed_official 125:23cc3068a9e4 756 * @}
mbed_official 125:23cc3068a9e4 757 */
mbed_official 125:23cc3068a9e4 758
mbed_official 125:23cc3068a9e4 759 /**
mbed_official 125:23cc3068a9e4 760 * @}
mbed_official 125:23cc3068a9e4 761 */
mbed_official 125:23cc3068a9e4 762
mbed_official 125:23cc3068a9e4 763 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
mbed_official 125:23cc3068a9e4 764