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