mbed SDK library sources

Fork of mbed-src by mbed official

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Thu Jan 30 12:15:05 2014 +0000
Revision:
80:66393a7b209d
Parent:
76:aeb1df146756
Synchronized with git revision dba523f83fe09b7fce11fc1299dd1216e9776359

Full URL: https://github.com/mbedmicro/mbed/commit/dba523f83fe09b7fce11fc1299dd1216e9776359/

Update of I2C, SPI, SLEEP for NUCLEO_F103RB and L152RE

Who changed what in which revision?

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