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