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