mbed library sources modified for open wear
Dependents: openwear-lifelogger-example
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F030R8/stm32f0xx_dac.c@310:6188e0254baa, 2014-09-16 (annotated)
- Committer:
- janekm
- Date:
- Tue Sep 16 22:42:01 2014 +0000
- Revision:
- 310:6188e0254baa
- Parent:
- 106:ced8cbb51063
N/A
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 | 106:ced8cbb51063 | 90 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 76:aeb1df146756 | 91 | * |
mbed_official | 106:ced8cbb51063 | 92 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 106:ced8cbb51063 | 93 | * are permitted provided that the following conditions are met: |
mbed_official | 106:ced8cbb51063 | 94 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 106:ced8cbb51063 | 95 | * this list of conditions and the following disclaimer. |
mbed_official | 106:ced8cbb51063 | 96 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 106:ced8cbb51063 | 97 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 106:ced8cbb51063 | 98 | * and/or other materials provided with the distribution. |
mbed_official | 106:ced8cbb51063 | 99 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 106:ced8cbb51063 | 100 | * may be used to endorse or promote products derived from this software |
mbed_official | 106:ced8cbb51063 | 101 | * without specific prior written permission. |
mbed_official | 76:aeb1df146756 | 102 | * |
mbed_official | 106:ced8cbb51063 | 103 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 106:ced8cbb51063 | 104 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 106:ced8cbb51063 | 105 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 106:ced8cbb51063 | 106 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 106:ced8cbb51063 | 107 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 106:ced8cbb51063 | 108 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 106:ced8cbb51063 | 109 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 106:ced8cbb51063 | 110 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 106:ced8cbb51063 | 111 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 106:ced8cbb51063 | 112 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 76:aeb1df146756 | 113 | * |
mbed_official | 76:aeb1df146756 | 114 | ****************************************************************************** |
mbed_official | 76:aeb1df146756 | 115 | */ |
mbed_official | 76:aeb1df146756 | 116 | |
mbed_official | 76:aeb1df146756 | 117 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 118 | #include "stm32f0xx_dac.h" |
mbed_official | 76:aeb1df146756 | 119 | |
mbed_official | 76:aeb1df146756 | 120 | /** @addtogroup STM32F0xx_StdPeriph_Driver |
mbed_official | 76:aeb1df146756 | 121 | * @{ |
mbed_official | 76:aeb1df146756 | 122 | */ |
mbed_official | 76:aeb1df146756 | 123 | |
mbed_official | 76:aeb1df146756 | 124 | /** @defgroup DAC |
mbed_official | 76:aeb1df146756 | 125 | * @brief DAC driver modules |
mbed_official | 76:aeb1df146756 | 126 | * @{ |
mbed_official | 76:aeb1df146756 | 127 | */ |
mbed_official | 76:aeb1df146756 | 128 | |
mbed_official | 76:aeb1df146756 | 129 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 130 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 131 | /* CR register Mask */ |
mbed_official | 76:aeb1df146756 | 132 | #define CR_CLEAR_MASK ((uint32_t)0x00000FFE) /* check the value of the mask */ |
mbed_official | 76:aeb1df146756 | 133 | |
mbed_official | 76:aeb1df146756 | 134 | /* DAC Dual Channels SWTRIG masks */ |
mbed_official | 76:aeb1df146756 | 135 | #define DUAL_SWTRIG_SET ((uint32_t)0x00000003) /*!< Only applicable for STM32F072 devices */ |
mbed_official | 76:aeb1df146756 | 136 | #define DUAL_SWTRIG_RESET ((uint32_t)0xFFFFFFFC) /*!< Only applicable for STM32F072 devices */ |
mbed_official | 76:aeb1df146756 | 137 | |
mbed_official | 76:aeb1df146756 | 138 | /* DHR registers offsets */ |
mbed_official | 76:aeb1df146756 | 139 | #define DHR12R1_OFFSET ((uint32_t)0x00000008) |
mbed_official | 76:aeb1df146756 | 140 | #define DHR12R2_OFFSET ((uint32_t)0x00000014) /*!< Only applicable for STM32F072 devices */ |
mbed_official | 76:aeb1df146756 | 141 | #define DHR12RD_OFFSET ((uint32_t)0x00000020) /*!< Only applicable for STM32F072 devices */ |
mbed_official | 76:aeb1df146756 | 142 | |
mbed_official | 76:aeb1df146756 | 143 | /* DOR register offset */ |
mbed_official | 76:aeb1df146756 | 144 | #define DOR_OFFSET ((uint32_t)0x0000002C) |
mbed_official | 76:aeb1df146756 | 145 | |
mbed_official | 76:aeb1df146756 | 146 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 147 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 148 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 149 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 150 | |
mbed_official | 76:aeb1df146756 | 151 | /** @defgroup DAC_Private_Functions |
mbed_official | 76:aeb1df146756 | 152 | * @{ |
mbed_official | 76:aeb1df146756 | 153 | */ |
mbed_official | 76:aeb1df146756 | 154 | |
mbed_official | 76:aeb1df146756 | 155 | /** @defgroup DAC_Group1 DAC channels configuration |
mbed_official | 76:aeb1df146756 | 156 | * @brief DAC channels configuration: trigger, output buffer, data format |
mbed_official | 76:aeb1df146756 | 157 | * |
mbed_official | 76:aeb1df146756 | 158 | @verbatim |
mbed_official | 76:aeb1df146756 | 159 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 160 | ##### DAC channels configuration: trigger, output buffer, data format ##### |
mbed_official | 76:aeb1df146756 | 161 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 162 | |
mbed_official | 76:aeb1df146756 | 163 | @endverbatim |
mbed_official | 76:aeb1df146756 | 164 | * @{ |
mbed_official | 76:aeb1df146756 | 165 | */ |
mbed_official | 76:aeb1df146756 | 166 | |
mbed_official | 76:aeb1df146756 | 167 | /** |
mbed_official | 76:aeb1df146756 | 168 | * @brief Deinitializes the DAC peripheral registers to their default reset values. |
mbed_official | 76:aeb1df146756 | 169 | * @param None |
mbed_official | 76:aeb1df146756 | 170 | * @retval None |
mbed_official | 76:aeb1df146756 | 171 | */ |
mbed_official | 76:aeb1df146756 | 172 | void DAC_DeInit(void) |
mbed_official | 76:aeb1df146756 | 173 | { |
mbed_official | 76:aeb1df146756 | 174 | /* Enable DAC reset state */ |
mbed_official | 76:aeb1df146756 | 175 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC, ENABLE); |
mbed_official | 76:aeb1df146756 | 176 | /* Release DAC from reset state */ |
mbed_official | 76:aeb1df146756 | 177 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC, DISABLE); |
mbed_official | 76:aeb1df146756 | 178 | } |
mbed_official | 76:aeb1df146756 | 179 | |
mbed_official | 76:aeb1df146756 | 180 | /** |
mbed_official | 76:aeb1df146756 | 181 | * @brief Initializes the DAC peripheral according to the specified parameters |
mbed_official | 76:aeb1df146756 | 182 | * in the DAC_InitStruct. |
mbed_official | 76:aeb1df146756 | 183 | * @param DAC_Channel: the selected DAC channel. |
mbed_official | 76:aeb1df146756 | 184 | * This parameter can be: |
mbed_official | 76:aeb1df146756 | 185 | * @arg DAC_Channel_1: DAC Channel1 selected |
mbed_official | 76:aeb1df146756 | 186 | * @arg DAC_Channel_2: DAC Channel2 selected, applicable only for STM32F072 devices |
mbed_official | 76:aeb1df146756 | 187 | * @param DAC_InitStruct: pointer to a DAC_InitTypeDef structure that contains |
mbed_official | 76:aeb1df146756 | 188 | * the configuration information for the specified DAC channel. |
mbed_official | 76:aeb1df146756 | 189 | * @retval None |
mbed_official | 76:aeb1df146756 | 190 | */ |
mbed_official | 76:aeb1df146756 | 191 | void DAC_Init(uint32_t DAC_Channel, DAC_InitTypeDef* DAC_InitStruct) |
mbed_official | 76:aeb1df146756 | 192 | { |
mbed_official | 76:aeb1df146756 | 193 | uint32_t tmpreg1 = 0, tmpreg2 = 0; |
mbed_official | 76:aeb1df146756 | 194 | |
mbed_official | 76:aeb1df146756 | 195 | /* Check the DAC parameters */ |
mbed_official | 76:aeb1df146756 | 196 | assert_param(IS_DAC_TRIGGER(DAC_InitStruct->DAC_Trigger)); |
mbed_official | 76:aeb1df146756 | 197 | assert_param(IS_DAC_GENERATE_WAVE(DAC_InitStruct->DAC_WaveGeneration)); |
mbed_official | 76:aeb1df146756 | 198 | assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(DAC_InitStruct->DAC_LFSRUnmask_TriangleAmplitude)); |
mbed_official | 76:aeb1df146756 | 199 | assert_param(IS_DAC_OUTPUT_BUFFER_STATE(DAC_InitStruct->DAC_OutputBuffer)); |
mbed_official | 76:aeb1df146756 | 200 | |
mbed_official | 76:aeb1df146756 | 201 | /*---------------------------- DAC CR Configuration --------------------------*/ |
mbed_official | 76:aeb1df146756 | 202 | /* Get the DAC CR value */ |
mbed_official | 76:aeb1df146756 | 203 | tmpreg1 = DAC->CR; |
mbed_official | 76:aeb1df146756 | 204 | /* Clear BOFFx, TENx, TSELx, WAVEx and MAMPx bits */ |
mbed_official | 76:aeb1df146756 | 205 | tmpreg1 &= ~(CR_CLEAR_MASK << DAC_Channel); |
mbed_official | 76:aeb1df146756 | 206 | /* Configure for the selected DAC channel: buffer output, trigger, |
mbed_official | 76:aeb1df146756 | 207 | wave generation, mask/amplitude for wave generation */ |
mbed_official | 76:aeb1df146756 | 208 | /* Set TSELx and TENx bits according to DAC_Trigger value */ |
mbed_official | 76:aeb1df146756 | 209 | /* Set WAVEx bits according to DAC_WaveGeneration value */ |
mbed_official | 76:aeb1df146756 | 210 | /* Set MAMPx bits according to DAC_LFSRUnmask_TriangleAmplitude value */ |
mbed_official | 76:aeb1df146756 | 211 | /* Set BOFFx bit according to DAC_OutputBuffer value */ |
mbed_official | 76:aeb1df146756 | 212 | tmpreg2 = (DAC_InitStruct->DAC_Trigger | DAC_InitStruct->DAC_WaveGeneration | |
mbed_official | 76:aeb1df146756 | 213 | DAC_InitStruct->DAC_LFSRUnmask_TriangleAmplitude | \ |
mbed_official | 76:aeb1df146756 | 214 | DAC_InitStruct->DAC_OutputBuffer); |
mbed_official | 76:aeb1df146756 | 215 | /* Calculate CR register value depending on DAC_Channel */ |
mbed_official | 76:aeb1df146756 | 216 | tmpreg1 |= tmpreg2 << DAC_Channel; |
mbed_official | 76:aeb1df146756 | 217 | /* Write to DAC CR */ |
mbed_official | 76:aeb1df146756 | 218 | DAC->CR = tmpreg1; |
mbed_official | 76:aeb1df146756 | 219 | } |
mbed_official | 76:aeb1df146756 | 220 | |
mbed_official | 76:aeb1df146756 | 221 | /** |
mbed_official | 76:aeb1df146756 | 222 | * @brief Fills each DAC_InitStruct member with its default value. |
mbed_official | 76:aeb1df146756 | 223 | * @param DAC_InitStruct: pointer to a DAC_InitTypeDef structure which will |
mbed_official | 76:aeb1df146756 | 224 | * be initialized. |
mbed_official | 76:aeb1df146756 | 225 | * @retval None |
mbed_official | 76:aeb1df146756 | 226 | */ |
mbed_official | 76:aeb1df146756 | 227 | void DAC_StructInit(DAC_InitTypeDef* DAC_InitStruct) |
mbed_official | 76:aeb1df146756 | 228 | { |
mbed_official | 76:aeb1df146756 | 229 | /*--------------- Reset DAC init structure parameters values -----------------*/ |
mbed_official | 76:aeb1df146756 | 230 | /* Initialize the DAC_Trigger member */ |
mbed_official | 76:aeb1df146756 | 231 | DAC_InitStruct->DAC_Trigger = DAC_Trigger_None; |
mbed_official | 76:aeb1df146756 | 232 | |
mbed_official | 76:aeb1df146756 | 233 | /* Initialize the DAC_WaveGeneration member */ |
mbed_official | 76:aeb1df146756 | 234 | DAC_InitStruct->DAC_WaveGeneration = DAC_WaveGeneration_None; |
mbed_official | 76:aeb1df146756 | 235 | |
mbed_official | 76:aeb1df146756 | 236 | /* Initialize the DAC_LFSRUnmask_TriangleAmplitude member */ |
mbed_official | 76:aeb1df146756 | 237 | DAC_InitStruct->DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bit0; |
mbed_official | 76:aeb1df146756 | 238 | |
mbed_official | 76:aeb1df146756 | 239 | /* Initialize the DAC_OutputBuffer member */ |
mbed_official | 76:aeb1df146756 | 240 | DAC_InitStruct->DAC_OutputBuffer = DAC_OutputBuffer_Enable; |
mbed_official | 76:aeb1df146756 | 241 | } |
mbed_official | 76:aeb1df146756 | 242 | |
mbed_official | 76:aeb1df146756 | 243 | /** |
mbed_official | 76:aeb1df146756 | 244 | * @brief Enables or disables the specified DAC channel. |
mbed_official | 76:aeb1df146756 | 245 | * @param DAC_Channel: The selected DAC channel. |
mbed_official | 76:aeb1df146756 | 246 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 247 | * @arg DAC_Channel_1: DAC Channel1 selected |
mbed_official | 76:aeb1df146756 | 248 | * @arg DAC_Channel_2: DAC Channel2 selected, applicable only for STM32F072 devices |
mbed_official | 76:aeb1df146756 | 249 | * @param NewState: new state of the DAC channel. |
mbed_official | 76:aeb1df146756 | 250 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 251 | * @note When the DAC channel is enabled the trigger source can no more be modified. |
mbed_official | 76:aeb1df146756 | 252 | * @retval None |
mbed_official | 76:aeb1df146756 | 253 | */ |
mbed_official | 76:aeb1df146756 | 254 | void DAC_Cmd(uint32_t DAC_Channel, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 255 | { |
mbed_official | 76:aeb1df146756 | 256 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 257 | assert_param(IS_DAC_CHANNEL(DAC_Channel)); |
mbed_official | 76:aeb1df146756 | 258 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 259 | |
mbed_official | 76:aeb1df146756 | 260 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 261 | { |
mbed_official | 76:aeb1df146756 | 262 | /* Enable the selected DAC channel */ |
mbed_official | 76:aeb1df146756 | 263 | DAC->CR |= (DAC_CR_EN1 << DAC_Channel); |
mbed_official | 76:aeb1df146756 | 264 | } |
mbed_official | 76:aeb1df146756 | 265 | else |
mbed_official | 76:aeb1df146756 | 266 | { |
mbed_official | 76:aeb1df146756 | 267 | /* Disable the selected DAC channel */ |
mbed_official | 76:aeb1df146756 | 268 | DAC->CR &= (~(DAC_CR_EN1 << DAC_Channel)); |
mbed_official | 76:aeb1df146756 | 269 | } |
mbed_official | 76:aeb1df146756 | 270 | } |
mbed_official | 76:aeb1df146756 | 271 | |
mbed_official | 76:aeb1df146756 | 272 | /** |
mbed_official | 76:aeb1df146756 | 273 | * @brief Enables or disables the selected DAC channel software trigger. |
mbed_official | 76:aeb1df146756 | 274 | * @param DAC_Channel: The selected DAC channel. |
mbed_official | 76:aeb1df146756 | 275 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 276 | * @arg DAC_Channel_1: DAC Channel1 selected |
mbed_official | 76:aeb1df146756 | 277 | * @arg DAC_Channel_2: DAC Channel2 selected, applicable only for STM32F072 devices |
mbed_official | 76:aeb1df146756 | 278 | * @param NewState: new state of the selected DAC channel software trigger. |
mbed_official | 76:aeb1df146756 | 279 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 280 | * @retval None |
mbed_official | 76:aeb1df146756 | 281 | */ |
mbed_official | 76:aeb1df146756 | 282 | void DAC_SoftwareTriggerCmd(uint32_t DAC_Channel, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 283 | { |
mbed_official | 76:aeb1df146756 | 284 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 285 | assert_param(IS_DAC_CHANNEL(DAC_Channel)); |
mbed_official | 76:aeb1df146756 | 286 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 287 | |
mbed_official | 76:aeb1df146756 | 288 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 289 | { |
mbed_official | 76:aeb1df146756 | 290 | /* Enable software trigger for the selected DAC channel */ |
mbed_official | 76:aeb1df146756 | 291 | DAC->SWTRIGR |= (uint32_t)DAC_SWTRIGR_SWTRIG1 << (DAC_Channel >> 4); |
mbed_official | 76:aeb1df146756 | 292 | } |
mbed_official | 76:aeb1df146756 | 293 | else |
mbed_official | 76:aeb1df146756 | 294 | { |
mbed_official | 76:aeb1df146756 | 295 | /* Disable software trigger for the selected DAC channel */ |
mbed_official | 76:aeb1df146756 | 296 | DAC->SWTRIGR &= ~((uint32_t)DAC_SWTRIGR_SWTRIG1 << (DAC_Channel >> 4)); |
mbed_official | 76:aeb1df146756 | 297 | } |
mbed_official | 76:aeb1df146756 | 298 | } |
mbed_official | 76:aeb1df146756 | 299 | |
mbed_official | 76:aeb1df146756 | 300 | /** |
mbed_official | 76:aeb1df146756 | 301 | * @brief Enables or disables simultaneously the two DAC channels software triggers. |
mbed_official | 76:aeb1df146756 | 302 | * This function is applicable only for STM32F072 devices. |
mbed_official | 76:aeb1df146756 | 303 | * @param NewState: new state of the DAC channels software triggers. |
mbed_official | 76:aeb1df146756 | 304 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 305 | * @retval None |
mbed_official | 76:aeb1df146756 | 306 | */ |
mbed_official | 76:aeb1df146756 | 307 | void DAC_DualSoftwareTriggerCmd(FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 308 | { |
mbed_official | 76:aeb1df146756 | 309 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 310 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 311 | |
mbed_official | 76:aeb1df146756 | 312 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 313 | { |
mbed_official | 76:aeb1df146756 | 314 | /* Enable software trigger for both DAC channels */ |
mbed_official | 76:aeb1df146756 | 315 | DAC->SWTRIGR |= DUAL_SWTRIG_SET; |
mbed_official | 76:aeb1df146756 | 316 | } |
mbed_official | 76:aeb1df146756 | 317 | else |
mbed_official | 76:aeb1df146756 | 318 | { |
mbed_official | 76:aeb1df146756 | 319 | /* Disable software trigger for both DAC channels */ |
mbed_official | 76:aeb1df146756 | 320 | DAC->SWTRIGR &= DUAL_SWTRIG_RESET; |
mbed_official | 76:aeb1df146756 | 321 | } |
mbed_official | 76:aeb1df146756 | 322 | } |
mbed_official | 76:aeb1df146756 | 323 | |
mbed_official | 76:aeb1df146756 | 324 | /** |
mbed_official | 76:aeb1df146756 | 325 | * @brief Enables or disables the selected DAC channel wave generation. |
mbed_official | 76:aeb1df146756 | 326 | * This function is applicable only for STM32F072 devices. |
mbed_official | 76:aeb1df146756 | 327 | * @param DAC_Channel: The selected DAC channel. |
mbed_official | 76:aeb1df146756 | 328 | * This parameter can be: |
mbed_official | 76:aeb1df146756 | 329 | * @arg DAC_Channel_1: DAC Channel1 selected |
mbed_official | 76:aeb1df146756 | 330 | * @arg DAC_Channel_2: DAC Channel2 selected |
mbed_official | 76:aeb1df146756 | 331 | * @param DAC_Wave: specifies the wave type to enable or disable. |
mbed_official | 76:aeb1df146756 | 332 | * This parameter can be: |
mbed_official | 76:aeb1df146756 | 333 | * @arg DAC_Wave_Noise: noise wave generation |
mbed_official | 76:aeb1df146756 | 334 | * @arg DAC_Wave_Triangle: triangle wave generation |
mbed_official | 76:aeb1df146756 | 335 | * @param NewState: new state of the selected DAC channel wave generation. |
mbed_official | 76:aeb1df146756 | 336 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 337 | * @retval None |
mbed_official | 76:aeb1df146756 | 338 | */ |
mbed_official | 76:aeb1df146756 | 339 | void DAC_WaveGenerationCmd(uint32_t DAC_Channel, uint32_t DAC_Wave, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 340 | { |
mbed_official | 76:aeb1df146756 | 341 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 342 | assert_param(IS_DAC_CHANNEL(DAC_Channel)); |
mbed_official | 76:aeb1df146756 | 343 | assert_param(IS_DAC_WAVE(DAC_Wave)); |
mbed_official | 76:aeb1df146756 | 344 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 345 | |
mbed_official | 76:aeb1df146756 | 346 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 347 | { |
mbed_official | 76:aeb1df146756 | 348 | /* Enable the selected wave generation for the selected DAC channel */ |
mbed_official | 76:aeb1df146756 | 349 | DAC->CR |= DAC_Wave << DAC_Channel; |
mbed_official | 76:aeb1df146756 | 350 | } |
mbed_official | 76:aeb1df146756 | 351 | else |
mbed_official | 76:aeb1df146756 | 352 | { |
mbed_official | 76:aeb1df146756 | 353 | /* Disable the selected wave generation for the selected DAC channel */ |
mbed_official | 76:aeb1df146756 | 354 | DAC->CR &= ~(DAC_Wave << DAC_Channel); |
mbed_official | 76:aeb1df146756 | 355 | } |
mbed_official | 76:aeb1df146756 | 356 | } |
mbed_official | 76:aeb1df146756 | 357 | |
mbed_official | 76:aeb1df146756 | 358 | /** |
mbed_official | 76:aeb1df146756 | 359 | * @brief Set the specified data holding register value for DAC channel1. |
mbed_official | 76:aeb1df146756 | 360 | * @param DAC_Align: Specifies the data alignment for DAC channel1. |
mbed_official | 76:aeb1df146756 | 361 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 362 | * @arg DAC_Align_8b_R: 8bit right data alignment selected |
mbed_official | 76:aeb1df146756 | 363 | * @arg DAC_Align_12b_L: 12bit left data alignment selected |
mbed_official | 76:aeb1df146756 | 364 | * @arg DAC_Align_12b_R: 12bit right data alignment selected |
mbed_official | 76:aeb1df146756 | 365 | * @param Data: Data to be loaded in the selected data holding register. |
mbed_official | 76:aeb1df146756 | 366 | * @retval None |
mbed_official | 76:aeb1df146756 | 367 | */ |
mbed_official | 76:aeb1df146756 | 368 | void DAC_SetChannel1Data(uint32_t DAC_Align, uint16_t Data) |
mbed_official | 76:aeb1df146756 | 369 | { |
mbed_official | 76:aeb1df146756 | 370 | __IO uint32_t tmp = 0; |
mbed_official | 76:aeb1df146756 | 371 | |
mbed_official | 76:aeb1df146756 | 372 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 373 | assert_param(IS_DAC_ALIGN(DAC_Align)); |
mbed_official | 76:aeb1df146756 | 374 | assert_param(IS_DAC_DATA(Data)); |
mbed_official | 76:aeb1df146756 | 375 | |
mbed_official | 76:aeb1df146756 | 376 | tmp = (uint32_t)DAC_BASE; |
mbed_official | 76:aeb1df146756 | 377 | tmp += DHR12R1_OFFSET + DAC_Align; |
mbed_official | 76:aeb1df146756 | 378 | |
mbed_official | 76:aeb1df146756 | 379 | /* Set the DAC channel1 selected data holding register */ |
mbed_official | 76:aeb1df146756 | 380 | *(__IO uint32_t *) tmp = Data; |
mbed_official | 76:aeb1df146756 | 381 | } |
mbed_official | 76:aeb1df146756 | 382 | |
mbed_official | 76:aeb1df146756 | 383 | /** |
mbed_official | 76:aeb1df146756 | 384 | * @brief Sets the specified data holding register value for DAC channel2. |
mbed_official | 76:aeb1df146756 | 385 | * This function is applicable only for STM32F072 devices. |
mbed_official | 76:aeb1df146756 | 386 | * @param DAC_Align: Specifies the data alignment for DAC channel2. |
mbed_official | 76:aeb1df146756 | 387 | * This parameter can be: |
mbed_official | 76:aeb1df146756 | 388 | * @arg DAC_Align_8b_R: 8bit right data alignment selected |
mbed_official | 76:aeb1df146756 | 389 | * @arg DAC_Align_12b_L: 12bit left data alignment selected |
mbed_official | 76:aeb1df146756 | 390 | * @arg DAC_Align_12b_R: 12bit right data alignment selected |
mbed_official | 76:aeb1df146756 | 391 | * @param Data: Data to be loaded in the selected data holding register. |
mbed_official | 76:aeb1df146756 | 392 | * @retval None |
mbed_official | 76:aeb1df146756 | 393 | */ |
mbed_official | 76:aeb1df146756 | 394 | void DAC_SetChannel2Data(uint32_t DAC_Align, uint16_t Data) |
mbed_official | 76:aeb1df146756 | 395 | { |
mbed_official | 76:aeb1df146756 | 396 | __IO uint32_t tmp = 0; |
mbed_official | 76:aeb1df146756 | 397 | |
mbed_official | 76:aeb1df146756 | 398 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 399 | assert_param(IS_DAC_ALIGN(DAC_Align)); |
mbed_official | 76:aeb1df146756 | 400 | assert_param(IS_DAC_DATA(Data)); |
mbed_official | 76:aeb1df146756 | 401 | |
mbed_official | 76:aeb1df146756 | 402 | tmp = (uint32_t)DAC_BASE; |
mbed_official | 76:aeb1df146756 | 403 | tmp += DHR12R2_OFFSET + DAC_Align; |
mbed_official | 76:aeb1df146756 | 404 | |
mbed_official | 76:aeb1df146756 | 405 | /* Set the DAC channel2 selected data holding register */ |
mbed_official | 76:aeb1df146756 | 406 | *(__IO uint32_t *)tmp = Data; |
mbed_official | 76:aeb1df146756 | 407 | } |
mbed_official | 76:aeb1df146756 | 408 | |
mbed_official | 76:aeb1df146756 | 409 | /** |
mbed_official | 76:aeb1df146756 | 410 | * @brief Sets the specified data holding register value for dual channel DAC. |
mbed_official | 76:aeb1df146756 | 411 | * This function is applicable only for STM32F072 devices. |
mbed_official | 76:aeb1df146756 | 412 | * @param DAC_Align: Specifies the data alignment for dual channel DAC. |
mbed_official | 76:aeb1df146756 | 413 | * This parameter can be: |
mbed_official | 76:aeb1df146756 | 414 | * @arg DAC_Align_8b_R: 8bit right data alignment selected |
mbed_official | 76:aeb1df146756 | 415 | * @arg DAC_Align_12b_L: 12bit left data alignment selected |
mbed_official | 76:aeb1df146756 | 416 | * @arg DAC_Align_12b_R: 12bit right data alignment selected |
mbed_official | 76:aeb1df146756 | 417 | * @param Data2: Data for DAC Channel2 to be loaded in the selected data holding register. |
mbed_official | 76:aeb1df146756 | 418 | * @param Data1: Data for DAC Channel1 to be loaded in the selected data holding register. |
mbed_official | 76:aeb1df146756 | 419 | * @note In dual mode, a unique register access is required to write in both |
mbed_official | 76:aeb1df146756 | 420 | * DAC channels at the same time. |
mbed_official | 76:aeb1df146756 | 421 | * @retval None |
mbed_official | 76:aeb1df146756 | 422 | */ |
mbed_official | 76:aeb1df146756 | 423 | void DAC_SetDualChannelData(uint32_t DAC_Align, uint16_t Data2, uint16_t Data1) |
mbed_official | 76:aeb1df146756 | 424 | { |
mbed_official | 76:aeb1df146756 | 425 | uint32_t data = 0, tmp = 0; |
mbed_official | 76:aeb1df146756 | 426 | |
mbed_official | 76:aeb1df146756 | 427 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 428 | assert_param(IS_DAC_ALIGN(DAC_Align)); |
mbed_official | 76:aeb1df146756 | 429 | assert_param(IS_DAC_DATA(Data1)); |
mbed_official | 76:aeb1df146756 | 430 | assert_param(IS_DAC_DATA(Data2)); |
mbed_official | 76:aeb1df146756 | 431 | |
mbed_official | 76:aeb1df146756 | 432 | /* Calculate and set dual DAC data holding register value */ |
mbed_official | 76:aeb1df146756 | 433 | if (DAC_Align == DAC_Align_8b_R) |
mbed_official | 76:aeb1df146756 | 434 | { |
mbed_official | 76:aeb1df146756 | 435 | data = ((uint32_t)Data2 << 8) | Data1; |
mbed_official | 76:aeb1df146756 | 436 | } |
mbed_official | 76:aeb1df146756 | 437 | else |
mbed_official | 76:aeb1df146756 | 438 | { |
mbed_official | 76:aeb1df146756 | 439 | data = ((uint32_t)Data2 << 16) | Data1; |
mbed_official | 76:aeb1df146756 | 440 | } |
mbed_official | 76:aeb1df146756 | 441 | |
mbed_official | 76:aeb1df146756 | 442 | tmp = (uint32_t)DAC_BASE; |
mbed_official | 76:aeb1df146756 | 443 | tmp += DHR12RD_OFFSET + DAC_Align; |
mbed_official | 76:aeb1df146756 | 444 | |
mbed_official | 76:aeb1df146756 | 445 | /* Set the dual DAC selected data holding register */ |
mbed_official | 76:aeb1df146756 | 446 | *(__IO uint32_t *)tmp = data; |
mbed_official | 76:aeb1df146756 | 447 | } |
mbed_official | 76:aeb1df146756 | 448 | |
mbed_official | 76:aeb1df146756 | 449 | /** |
mbed_official | 76:aeb1df146756 | 450 | * @brief Returns the last data output value of the selected DAC channel. |
mbed_official | 76:aeb1df146756 | 451 | * @param DAC_Channel: The selected DAC channel. |
mbed_official | 76:aeb1df146756 | 452 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 453 | * @arg DAC_Channel_1: DAC Channel1 selected |
mbed_official | 76:aeb1df146756 | 454 | * @arg DAC_Channel_2: DAC Channel2 selected, applicable only for STM32F072 devices |
mbed_official | 76:aeb1df146756 | 455 | * @retval The selected DAC channel data output value. |
mbed_official | 76:aeb1df146756 | 456 | */ |
mbed_official | 76:aeb1df146756 | 457 | uint16_t DAC_GetDataOutputValue(uint32_t DAC_Channel) |
mbed_official | 76:aeb1df146756 | 458 | { |
mbed_official | 76:aeb1df146756 | 459 | __IO uint32_t tmp = 0; |
mbed_official | 76:aeb1df146756 | 460 | |
mbed_official | 76:aeb1df146756 | 461 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 462 | assert_param(IS_DAC_CHANNEL(DAC_Channel)); |
mbed_official | 76:aeb1df146756 | 463 | |
mbed_official | 76:aeb1df146756 | 464 | tmp = (uint32_t) DAC_BASE ; |
mbed_official | 76:aeb1df146756 | 465 | tmp += DOR_OFFSET + ((uint32_t)DAC_Channel >> 2); |
mbed_official | 76:aeb1df146756 | 466 | |
mbed_official | 76:aeb1df146756 | 467 | /* Returns the DAC channel data output register value */ |
mbed_official | 76:aeb1df146756 | 468 | return (uint16_t) (*(__IO uint32_t*) tmp); |
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 | */ |
mbed_official | 76:aeb1df146756 | 474 | |
mbed_official | 76:aeb1df146756 | 475 | /** @defgroup DAC_Group2 DMA management functions |
mbed_official | 76:aeb1df146756 | 476 | * @brief DMA management functions |
mbed_official | 76:aeb1df146756 | 477 | * |
mbed_official | 76:aeb1df146756 | 478 | @verbatim |
mbed_official | 76:aeb1df146756 | 479 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 480 | ##### DMA management functions ##### |
mbed_official | 76:aeb1df146756 | 481 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 482 | |
mbed_official | 76:aeb1df146756 | 483 | @endverbatim |
mbed_official | 76:aeb1df146756 | 484 | * @{ |
mbed_official | 76:aeb1df146756 | 485 | */ |
mbed_official | 76:aeb1df146756 | 486 | |
mbed_official | 76:aeb1df146756 | 487 | /** |
mbed_official | 76:aeb1df146756 | 488 | * @brief Enables or disables the specified DAC channel DMA request. |
mbed_official | 76:aeb1df146756 | 489 | * When enabled DMA1 is generated when an external trigger (EXTI Line9, |
mbed_official | 76:aeb1df146756 | 490 | * TIM2, TIM3, TIM6 or TIM15 but not a software trigger) occurs |
mbed_official | 76:aeb1df146756 | 491 | * @param DAC_Channel: the selected DAC channel. |
mbed_official | 76:aeb1df146756 | 492 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 493 | * @arg DAC_Channel_1: DAC Channel1 selected |
mbed_official | 76:aeb1df146756 | 494 | * @arg DAC_Channel_2: DAC Channel2 selected, applicable only for STM32F072 devices |
mbed_official | 76:aeb1df146756 | 495 | * @param NewState: new state of the selected DAC channel DMA request. |
mbed_official | 76:aeb1df146756 | 496 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 497 | * @note The DAC channel1 is mapped on DMA1 channel3 which must be already configured. |
mbed_official | 76:aeb1df146756 | 498 | * @note The DAC channel2 is mapped on DMA1 channel4 which must be already configured. |
mbed_official | 76:aeb1df146756 | 499 | * @retval None |
mbed_official | 76:aeb1df146756 | 500 | */ |
mbed_official | 76:aeb1df146756 | 501 | void DAC_DMACmd(uint32_t DAC_Channel, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 502 | { |
mbed_official | 76:aeb1df146756 | 503 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 504 | assert_param(IS_DAC_CHANNEL(DAC_Channel)); |
mbed_official | 76:aeb1df146756 | 505 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 506 | |
mbed_official | 76:aeb1df146756 | 507 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 508 | { |
mbed_official | 76:aeb1df146756 | 509 | /* Enable the selected DAC channel DMA request */ |
mbed_official | 76:aeb1df146756 | 510 | DAC->CR |= (DAC_CR_DMAEN1 << DAC_Channel); |
mbed_official | 76:aeb1df146756 | 511 | } |
mbed_official | 76:aeb1df146756 | 512 | else |
mbed_official | 76:aeb1df146756 | 513 | { |
mbed_official | 76:aeb1df146756 | 514 | /* Disable the selected DAC channel DMA request */ |
mbed_official | 76:aeb1df146756 | 515 | DAC->CR &= (~(DAC_CR_DMAEN1 << DAC_Channel)); |
mbed_official | 76:aeb1df146756 | 516 | } |
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 | */ |
mbed_official | 76:aeb1df146756 | 522 | |
mbed_official | 76:aeb1df146756 | 523 | /** @defgroup DAC_Group3 Interrupts and flags management functions |
mbed_official | 76:aeb1df146756 | 524 | * @brief Interrupts and flags management functions |
mbed_official | 76:aeb1df146756 | 525 | * |
mbed_official | 76:aeb1df146756 | 526 | @verbatim |
mbed_official | 76:aeb1df146756 | 527 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 528 | ##### Interrupts and flags management functions ##### |
mbed_official | 76:aeb1df146756 | 529 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 530 | |
mbed_official | 76:aeb1df146756 | 531 | @endverbatim |
mbed_official | 76:aeb1df146756 | 532 | * @{ |
mbed_official | 76:aeb1df146756 | 533 | */ |
mbed_official | 76:aeb1df146756 | 534 | |
mbed_official | 76:aeb1df146756 | 535 | /** |
mbed_official | 76:aeb1df146756 | 536 | * @brief Enables or disables the specified DAC interrupts. |
mbed_official | 76:aeb1df146756 | 537 | * @param DAC_Channel: The selected DAC channel. |
mbed_official | 76:aeb1df146756 | 538 | * This parameter can be: |
mbed_official | 76:aeb1df146756 | 539 | * @arg DAC_Channel_1: DAC Channel1 selected |
mbed_official | 76:aeb1df146756 | 540 | * @arg DAC_Channel_2: DAC Channel2 selected, applicable only for STM32F072 devices |
mbed_official | 76:aeb1df146756 | 541 | * @param DAC_IT: specifies the DAC interrupt sources to be enabled or disabled. |
mbed_official | 76:aeb1df146756 | 542 | * This parameter can be the following values: |
mbed_official | 76:aeb1df146756 | 543 | * @arg DAC_IT_DMAUDR: DMA underrun interrupt mask |
mbed_official | 76:aeb1df146756 | 544 | * @note The DMA underrun occurs when a second external trigger arrives before the |
mbed_official | 76:aeb1df146756 | 545 | * acknowledgement for the first external trigger is received (first request). |
mbed_official | 76:aeb1df146756 | 546 | * @param NewState: new state of the specified DAC interrupts. |
mbed_official | 76:aeb1df146756 | 547 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 548 | * @retval None |
mbed_official | 76:aeb1df146756 | 549 | */ |
mbed_official | 76:aeb1df146756 | 550 | void DAC_ITConfig(uint32_t DAC_Channel, uint32_t DAC_IT, FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 551 | { |
mbed_official | 76:aeb1df146756 | 552 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 553 | assert_param(IS_DAC_CHANNEL(DAC_Channel)); |
mbed_official | 76:aeb1df146756 | 554 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 555 | assert_param(IS_DAC_IT(DAC_IT)); |
mbed_official | 76:aeb1df146756 | 556 | |
mbed_official | 76:aeb1df146756 | 557 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 558 | { |
mbed_official | 76:aeb1df146756 | 559 | /* Enable the selected DAC interrupts */ |
mbed_official | 76:aeb1df146756 | 560 | DAC->CR |= (DAC_IT << DAC_Channel); |
mbed_official | 76:aeb1df146756 | 561 | } |
mbed_official | 76:aeb1df146756 | 562 | else |
mbed_official | 76:aeb1df146756 | 563 | { |
mbed_official | 76:aeb1df146756 | 564 | /* Disable the selected DAC interrupts */ |
mbed_official | 76:aeb1df146756 | 565 | DAC->CR &= (~(uint32_t)(DAC_IT << DAC_Channel)); |
mbed_official | 76:aeb1df146756 | 566 | } |
mbed_official | 76:aeb1df146756 | 567 | } |
mbed_official | 76:aeb1df146756 | 568 | |
mbed_official | 76:aeb1df146756 | 569 | /** |
mbed_official | 76:aeb1df146756 | 570 | * @brief Checks whether the specified DAC flag is set or not. |
mbed_official | 76:aeb1df146756 | 571 | * @param DAC_Channel: The selected DAC channel. |
mbed_official | 76:aeb1df146756 | 572 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 573 | * @arg DAC_Channel_1: DAC Channel1 selected |
mbed_official | 76:aeb1df146756 | 574 | * @arg DAC_Channel_2: DAC Channel2 selected, applicable only for STM32F072 devices |
mbed_official | 76:aeb1df146756 | 575 | * @param DAC_FLAG: specifies the flag to check. |
mbed_official | 76:aeb1df146756 | 576 | * This parameter can be only of the following value: |
mbed_official | 76:aeb1df146756 | 577 | * @arg DAC_FLAG_DMAUDR: DMA underrun flag |
mbed_official | 76:aeb1df146756 | 578 | * @note The DMA underrun occurs when a second external trigger arrives before the |
mbed_official | 76:aeb1df146756 | 579 | * acknowledgement for the first external trigger is received (first request). |
mbed_official | 76:aeb1df146756 | 580 | * @retval The new state of DAC_FLAG (SET or RESET). |
mbed_official | 76:aeb1df146756 | 581 | */ |
mbed_official | 76:aeb1df146756 | 582 | FlagStatus DAC_GetFlagStatus(uint32_t DAC_Channel, uint32_t DAC_FLAG) |
mbed_official | 76:aeb1df146756 | 583 | { |
mbed_official | 76:aeb1df146756 | 584 | FlagStatus bitstatus = RESET; |
mbed_official | 76:aeb1df146756 | 585 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 586 | assert_param(IS_DAC_CHANNEL(DAC_Channel)); |
mbed_official | 76:aeb1df146756 | 587 | assert_param(IS_DAC_FLAG(DAC_FLAG)); |
mbed_official | 76:aeb1df146756 | 588 | |
mbed_official | 76:aeb1df146756 | 589 | /* Check the status of the specified DAC flag */ |
mbed_official | 76:aeb1df146756 | 590 | if ((DAC->SR & (DAC_FLAG << DAC_Channel)) != (uint8_t)RESET) |
mbed_official | 76:aeb1df146756 | 591 | { |
mbed_official | 76:aeb1df146756 | 592 | /* DAC_FLAG is set */ |
mbed_official | 76:aeb1df146756 | 593 | bitstatus = SET; |
mbed_official | 76:aeb1df146756 | 594 | } |
mbed_official | 76:aeb1df146756 | 595 | else |
mbed_official | 76:aeb1df146756 | 596 | { |
mbed_official | 76:aeb1df146756 | 597 | /* DAC_FLAG is reset */ |
mbed_official | 76:aeb1df146756 | 598 | bitstatus = RESET; |
mbed_official | 76:aeb1df146756 | 599 | } |
mbed_official | 76:aeb1df146756 | 600 | /* Return the DAC_FLAG status */ |
mbed_official | 76:aeb1df146756 | 601 | return bitstatus; |
mbed_official | 76:aeb1df146756 | 602 | } |
mbed_official | 76:aeb1df146756 | 603 | |
mbed_official | 76:aeb1df146756 | 604 | /** |
mbed_official | 76:aeb1df146756 | 605 | * @brief Clears the DAC channel's pending flags. |
mbed_official | 76:aeb1df146756 | 606 | * @param DAC_Channel: The selected DAC channel. |
mbed_official | 76:aeb1df146756 | 607 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 608 | * @arg DAC_Channel_1: DAC Channel1 selected |
mbed_official | 76:aeb1df146756 | 609 | * @arg DAC_Channel_2: DAC Channel2 selected, applicable only for STM32F072 devices |
mbed_official | 76:aeb1df146756 | 610 | * @param DAC_FLAG: specifies the flag to clear. |
mbed_official | 76:aeb1df146756 | 611 | * This parameter can be of the following value: |
mbed_official | 76:aeb1df146756 | 612 | * @arg DAC_FLAG_DMAUDR: DMA underrun flag |
mbed_official | 76:aeb1df146756 | 613 | * @retval None |
mbed_official | 76:aeb1df146756 | 614 | */ |
mbed_official | 76:aeb1df146756 | 615 | void DAC_ClearFlag(uint32_t DAC_Channel, uint32_t DAC_FLAG) |
mbed_official | 76:aeb1df146756 | 616 | { |
mbed_official | 76:aeb1df146756 | 617 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 618 | assert_param(IS_DAC_CHANNEL(DAC_Channel)); |
mbed_official | 76:aeb1df146756 | 619 | assert_param(IS_DAC_FLAG(DAC_FLAG)); |
mbed_official | 76:aeb1df146756 | 620 | |
mbed_official | 76:aeb1df146756 | 621 | /* Clear the selected DAC flags */ |
mbed_official | 76:aeb1df146756 | 622 | DAC->SR = (DAC_FLAG << DAC_Channel); |
mbed_official | 76:aeb1df146756 | 623 | } |
mbed_official | 76:aeb1df146756 | 624 | |
mbed_official | 76:aeb1df146756 | 625 | /** |
mbed_official | 76:aeb1df146756 | 626 | * @brief Checks whether the specified DAC interrupt has occurred or not. |
mbed_official | 76:aeb1df146756 | 627 | * @param DAC_Channel: The selected DAC channel. |
mbed_official | 76:aeb1df146756 | 628 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 629 | * @arg DAC_Channel_1: DAC Channel1 selected |
mbed_official | 76:aeb1df146756 | 630 | * @arg DAC_Channel_2: DAC Channel2 selected, applicable only for STM32F072 devices |
mbed_official | 76:aeb1df146756 | 631 | * @param DAC_IT: specifies the DAC interrupt source to check. |
mbed_official | 76:aeb1df146756 | 632 | * This parameter can be the following values: |
mbed_official | 76:aeb1df146756 | 633 | * @arg DAC_IT_DMAUDR: DMA underrun interrupt mask |
mbed_official | 76:aeb1df146756 | 634 | * @note The DMA underrun occurs when a second external trigger arrives before the |
mbed_official | 76:aeb1df146756 | 635 | * acknowledgement for the first external trigger is received (first request). |
mbed_official | 76:aeb1df146756 | 636 | * @retval The new state of DAC_IT (SET or RESET). |
mbed_official | 76:aeb1df146756 | 637 | */ |
mbed_official | 76:aeb1df146756 | 638 | ITStatus DAC_GetITStatus(uint32_t DAC_Channel, uint32_t DAC_IT) |
mbed_official | 76:aeb1df146756 | 639 | { |
mbed_official | 76:aeb1df146756 | 640 | ITStatus bitstatus = RESET; |
mbed_official | 76:aeb1df146756 | 641 | uint32_t enablestatus = 0; |
mbed_official | 76:aeb1df146756 | 642 | |
mbed_official | 76:aeb1df146756 | 643 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 644 | assert_param(IS_DAC_CHANNEL(DAC_Channel)); |
mbed_official | 76:aeb1df146756 | 645 | assert_param(IS_DAC_IT(DAC_IT)); |
mbed_official | 76:aeb1df146756 | 646 | |
mbed_official | 76:aeb1df146756 | 647 | /* Get the DAC_IT enable bit status */ |
mbed_official | 76:aeb1df146756 | 648 | enablestatus = (DAC->CR & (DAC_IT << DAC_Channel)) ; |
mbed_official | 76:aeb1df146756 | 649 | |
mbed_official | 76:aeb1df146756 | 650 | /* Check the status of the specified DAC interrupt */ |
mbed_official | 76:aeb1df146756 | 651 | if (((DAC->SR & (DAC_IT << DAC_Channel)) != (uint32_t)RESET) && enablestatus) |
mbed_official | 76:aeb1df146756 | 652 | { |
mbed_official | 76:aeb1df146756 | 653 | /* DAC_IT is set */ |
mbed_official | 76:aeb1df146756 | 654 | bitstatus = SET; |
mbed_official | 76:aeb1df146756 | 655 | } |
mbed_official | 76:aeb1df146756 | 656 | else |
mbed_official | 76:aeb1df146756 | 657 | { |
mbed_official | 76:aeb1df146756 | 658 | /* DAC_IT is reset */ |
mbed_official | 76:aeb1df146756 | 659 | bitstatus = RESET; |
mbed_official | 76:aeb1df146756 | 660 | } |
mbed_official | 76:aeb1df146756 | 661 | /* Return the DAC_IT status */ |
mbed_official | 76:aeb1df146756 | 662 | return bitstatus; |
mbed_official | 76:aeb1df146756 | 663 | } |
mbed_official | 76:aeb1df146756 | 664 | |
mbed_official | 76:aeb1df146756 | 665 | /** |
mbed_official | 76:aeb1df146756 | 666 | * @brief Clears the DAC channel's interrupt pending bits. |
mbed_official | 76:aeb1df146756 | 667 | * @param DAC_Channel: The selected DAC channel. |
mbed_official | 76:aeb1df146756 | 668 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 669 | * @arg DAC_Channel_1: DAC Channel1 selected |
mbed_official | 76:aeb1df146756 | 670 | * @arg DAC_Channel_2: DAC Channel2 selected, applicable only for STM32F072 devices |
mbed_official | 76:aeb1df146756 | 671 | * @param DAC_IT: specifies the DAC interrupt pending bit to clear. |
mbed_official | 76:aeb1df146756 | 672 | * This parameter can be the following values: |
mbed_official | 76:aeb1df146756 | 673 | * @arg DAC_IT_DMAUDR: DMA underrun interrupt mask |
mbed_official | 76:aeb1df146756 | 674 | * @retval None |
mbed_official | 76:aeb1df146756 | 675 | */ |
mbed_official | 76:aeb1df146756 | 676 | void DAC_ClearITPendingBit(uint32_t DAC_Channel, uint32_t DAC_IT) |
mbed_official | 76:aeb1df146756 | 677 | { |
mbed_official | 76:aeb1df146756 | 678 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 679 | assert_param(IS_DAC_CHANNEL(DAC_Channel)); |
mbed_official | 76:aeb1df146756 | 680 | assert_param(IS_DAC_IT(DAC_IT)); |
mbed_official | 76:aeb1df146756 | 681 | |
mbed_official | 76:aeb1df146756 | 682 | /* Clear the selected DAC interrupt pending bits */ |
mbed_official | 76:aeb1df146756 | 683 | DAC->SR = (DAC_IT << DAC_Channel); |
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 | */ |
mbed_official | 76:aeb1df146756 | 693 | |
mbed_official | 76:aeb1df146756 | 694 | /** |
mbed_official | 76:aeb1df146756 | 695 | * @} |
mbed_official | 76:aeb1df146756 | 696 | */ |
mbed_official | 76:aeb1df146756 | 697 | |
mbed_official | 76:aeb1df146756 | 698 | /** |
mbed_official | 76:aeb1df146756 | 699 | * @} |
mbed_official | 76:aeb1df146756 | 700 | */ |
mbed_official | 76:aeb1df146756 | 701 | |
mbed_official | 76:aeb1df146756 | 702 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |