2 ******************************************************************************
3 * @file stm32f30x_dac.h
4 * @author MCD Application Team
6 * @date 27-February-2014
7 * @brief This file contains all the functions prototypes for the DAC firmware
9 ******************************************************************************
12 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
14 * Redistribution and use in source and binary forms, with or without modification,
15 * are permitted provided that the following conditions are met:
16 * 1. Redistributions of source code must retain the above copyright notice,
17 * this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright notice,
19 * this list of conditions and the following disclaimer in the documentation
20 * and/or other materials provided with the distribution.
21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 ******************************************************************************
39 /* Define to prevent recursive inclusion -------------------------------------*/
40 #ifndef __STM32F30x_DAC_H
41 #define __STM32F30x_DAC_H
47 /* Includes ------------------------------------------------------------------*/
48 #include "stm32f30x.h"
50 /** @addtogroup STM32F30x_StdPeriph_Driver
58 /* Exported types ------------------------------------------------------------*/
59 #define DAC_CR_DMAUDRIE ((uint32_t)0x00002000) /*!< DAC channel DMA underrun interrupt enable */
62 * @brief DAC Init structure definition
67 uint32_t DAC_Trigger; /*!< Specifies the external trigger for the selected DAC channel.
68 This parameter can be a value of @ref DAC_trigger_selection */
70 uint32_t DAC_WaveGeneration; /*!< Specifies whether DAC channel noise waves or triangle waves
71 are generated, or whether no wave is generated.
72 This parameter can be a value of @ref DAC_wave_generation */
74 uint32_t DAC_LFSRUnmask_TriangleAmplitude; /*!< Specifies the LFSR mask for noise wave generation or
75 the maximum amplitude triangle generation for the DAC channel.
76 This parameter can be a value of @ref DAC_lfsrunmask_triangleamplitude */
78 uint32_t DAC_Buffer_Switch; /*!< Specifies whether the DAC channel output buffer is enabled or disabled or
79 the DAC channel output switch is enabled or disabled.
80 This parameter can be a value of @ref DAC_buffer_switch */
83 /* Exported constants --------------------------------------------------------*/
85 /** @defgroup DAC_Exported_Constants
89 #define IS_DAC_ALL_PERIPH(PERIPH) (((PERIPH) == DAC1) || \
92 #define IS_DAC_LIST1_PERIPH(PERIPH) (((PERIPH) == DAC1))
94 /** @defgroup DAC_trigger_selection
98 #define DAC_Trigger_None ((uint32_t)0x00000000) /*!< Conversion is automatic once the DAC1_DHRxxxx register
99 has been loaded, and not by external trigger */
100 #define DAC_Trigger_T6_TRGO ((uint32_t)0x00000004) /*!< TIM6 TRGO selected as external conversion trigger for DAC1/2 channel1/2 */
101 #define DAC_Trigger_T3_TRGO ((uint32_t)0x0000000C) /*!< TIM3 TRGO selected as external conversion trigger for DAC1/2 channel1/2 */
102 #define DAC_Trigger_T8_TRGO ((uint32_t)0x0000000C) /*!< TIM8 TRGO selected as external conversion trigger for DAC1 channel1/2 */
103 #define DAC_Trigger_T7_TRGO ((uint32_t)0x00000014) /*!< TIM7 TRGO selected as external conversion trigger for DAC1/2 channel1/2 */
104 #define DAC_Trigger_T15_TRGO ((uint32_t)0x0000001C) /*!< TIM15 TRGO selected as external conversion trigger for DAC1/2 channel1/2 */
105 #define DAC_Trigger_HRTIM1_DACTRG1 ((uint32_t)0x0000001C) /*!< HRTIM1 DACTRG1 selected as external conversion trigger for DAC1 channel1/2 */
106 #define DAC_Trigger_T2_TRGO ((uint32_t)0x00000024) /*!< TIM2 TRGO selected as external conversion trigger for DAC1/2 channel1/2 */
107 #define DAC_Trigger_T4_TRGO ((uint32_t)0x0000002C) /*!< TIM4 TRGO selected as external conversion trigger for DAC channel */
108 #define DAC_Trigger_HRTIM1_DACTRG2 ((uint32_t)0x0000002C) /*!< HRTIM1 DACTRG2 selected as external conversion trigger for DAC1 channel1/2 */
109 #define DAC_Trigger_HRTIM1_DACTRG3 ((uint32_t)0x0000002C) /*!< HRTIM1 DACTRG3 selected as external conversion trigger for DAC2 channel1 */
110 #define DAC_Trigger_Ext_IT9 ((uint32_t)0x00000034) /*!< EXTI Line9 event selected as external conversion trigger for DAC1/2 channel1/2 */
111 #define DAC_Trigger_Software ((uint32_t)0x0000003C) /*!< Conversion started by software trigger for DAC1/2 channel1/2 */
113 #define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_Trigger_None) || \
114 ((TRIGGER) == DAC_Trigger_T6_TRGO) || \
115 ((TRIGGER) == DAC_Trigger_T3_TRGO) || \
116 ((TRIGGER) == DAC_Trigger_T8_TRGO) || \
117 ((TRIGGER) == DAC_Trigger_T7_TRGO) || \
118 ((TRIGGER) == DAC_Trigger_T15_TRGO) || \
119 ((TRIGGER) == DAC_Trigger_HRTIM1_DACTRG1)|| \
120 ((TRIGGER) == DAC_Trigger_T2_TRGO) || \
121 ((TRIGGER) == DAC_Trigger_T4_TRGO) || \
122 ((TRIGGER) == DAC_Trigger_HRTIM1_DACTRG2)|| \
123 ((TRIGGER) == DAC_Trigger_HRTIM1_DACTRG3)|| \
124 ((TRIGGER) == DAC_Trigger_Ext_IT9) || \
125 ((TRIGGER) == DAC_Trigger_Software))
131 /** @defgroup DAC_wave_generation
135 #define DAC_WaveGeneration_None ((uint32_t)0x00000000)
136 #define DAC_WaveGeneration_Noise ((uint32_t)0x00000040)
137 #define DAC_WaveGeneration_Triangle ((uint32_t)0x00000080)
139 #define IS_DAC_GENERATE_WAVE(WAVE) (((WAVE) == DAC_WaveGeneration_None) || \
140 ((WAVE) == DAC_WaveGeneration_Noise) || \
141 ((WAVE) == DAC_WaveGeneration_Triangle))
146 /** @defgroup DAC_lfsrunmask_triangleamplitude
150 #define DAC_LFSRUnmask_Bit0 ((uint32_t)0x00000000) /*!< Unmask DAC channel LFSR bit0 for noise wave generation */
151 #define DAC_LFSRUnmask_Bits1_0 ((uint32_t)0x00000100) /*!< Unmask DAC channel LFSR bit[1:0] for noise wave generation */
152 #define DAC_LFSRUnmask_Bits2_0 ((uint32_t)0x00000200) /*!< Unmask DAC channel LFSR bit[2:0] for noise wave generation */
153 #define DAC_LFSRUnmask_Bits3_0 ((uint32_t)0x00000300) /*!< Unmask DAC channel LFSR bit[3:0] for noise wave generation */
154 #define DAC_LFSRUnmask_Bits4_0 ((uint32_t)0x00000400) /*!< Unmask DAC channel LFSR bit[4:0] for noise wave generation */
155 #define DAC_LFSRUnmask_Bits5_0 ((uint32_t)0x00000500) /*!< Unmask DAC channel LFSR bit[5:0] for noise wave generation */
156 #define DAC_LFSRUnmask_Bits6_0 ((uint32_t)0x00000600) /*!< Unmask DAC channel LFSR bit[6:0] for noise wave generation */
157 #define DAC_LFSRUnmask_Bits7_0 ((uint32_t)0x00000700) /*!< Unmask DAC channel LFSR bit[7:0] for noise wave generation */
158 #define DAC_LFSRUnmask_Bits8_0 ((uint32_t)0x00000800) /*!< Unmask DAC channel LFSR bit[8:0] for noise wave generation */
159 #define DAC_LFSRUnmask_Bits9_0 ((uint32_t)0x00000900) /*!< Unmask DAC channel LFSR bit[9:0] for noise wave generation */
160 #define DAC_LFSRUnmask_Bits10_0 ((uint32_t)0x00000A00) /*!< Unmask DAC channel LFSR bit[10:0] for noise wave generation */
161 #define DAC_LFSRUnmask_Bits11_0 ((uint32_t)0x00000B00) /*!< Unmask DAC channel LFSR bit[11:0] for noise wave generation */
162 #define DAC_TriangleAmplitude_1 ((uint32_t)0x00000000) /*!< Select max triangle amplitude of 1 */
163 #define DAC_TriangleAmplitude_3 ((uint32_t)0x00000100) /*!< Select max triangle amplitude of 3 */
164 #define DAC_TriangleAmplitude_7 ((uint32_t)0x00000200) /*!< Select max triangle amplitude of 7 */
165 #define DAC_TriangleAmplitude_15 ((uint32_t)0x00000300) /*!< Select max triangle amplitude of 15 */
166 #define DAC_TriangleAmplitude_31 ((uint32_t)0x00000400) /*!< Select max triangle amplitude of 31 */
167 #define DAC_TriangleAmplitude_63 ((uint32_t)0x00000500) /*!< Select max triangle amplitude of 63 */
168 #define DAC_TriangleAmplitude_127 ((uint32_t)0x00000600) /*!< Select max triangle amplitude of 127 */
169 #define DAC_TriangleAmplitude_255 ((uint32_t)0x00000700) /*!< Select max triangle amplitude of 255 */
170 #define DAC_TriangleAmplitude_511 ((uint32_t)0x00000800) /*!< Select max triangle amplitude of 511 */
171 #define DAC_TriangleAmplitude_1023 ((uint32_t)0x00000900) /*!< Select max triangle amplitude of 1023 */
172 #define DAC_TriangleAmplitude_2047 ((uint32_t)0x00000A00) /*!< Select max triangle amplitude of 2047 */
173 #define DAC_TriangleAmplitude_4095 ((uint32_t)0x00000B00) /*!< Select max triangle amplitude of 4095 */
175 #define IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(VALUE) (((VALUE) == DAC_LFSRUnmask_Bit0) || \
176 ((VALUE) == DAC_LFSRUnmask_Bits1_0) || \
177 ((VALUE) == DAC_LFSRUnmask_Bits2_0) || \
178 ((VALUE) == DAC_LFSRUnmask_Bits3_0) || \
179 ((VALUE) == DAC_LFSRUnmask_Bits4_0) || \
180 ((VALUE) == DAC_LFSRUnmask_Bits5_0) || \
181 ((VALUE) == DAC_LFSRUnmask_Bits6_0) || \
182 ((VALUE) == DAC_LFSRUnmask_Bits7_0) || \
183 ((VALUE) == DAC_LFSRUnmask_Bits8_0) || \
184 ((VALUE) == DAC_LFSRUnmask_Bits9_0) || \
185 ((VALUE) == DAC_LFSRUnmask_Bits10_0) || \
186 ((VALUE) == DAC_LFSRUnmask_Bits11_0) || \
187 ((VALUE) == DAC_TriangleAmplitude_1) || \
188 ((VALUE) == DAC_TriangleAmplitude_3) || \
189 ((VALUE) == DAC_TriangleAmplitude_7) || \
190 ((VALUE) == DAC_TriangleAmplitude_15) || \
191 ((VALUE) == DAC_TriangleAmplitude_31) || \
192 ((VALUE) == DAC_TriangleAmplitude_63) || \
193 ((VALUE) == DAC_TriangleAmplitude_127) || \
194 ((VALUE) == DAC_TriangleAmplitude_255) || \
195 ((VALUE) == DAC_TriangleAmplitude_511) || \
196 ((VALUE) == DAC_TriangleAmplitude_1023) || \
197 ((VALUE) == DAC_TriangleAmplitude_2047) || \
198 ((VALUE) == DAC_TriangleAmplitude_4095))
203 /** @defgroup DAC_buffer_switch
207 #define DAC_BufferSwitch_Disable ((uint32_t)0x00000000)
208 #define DAC_BufferSwitch_Enable ((uint32_t)0x00000002)
210 #define IS_DAC_BUFFER_SWITCH_STATE(STATE) (((STATE) == DAC_BufferSwitch_Enable) || \
211 ((STATE) == DAC_BufferSwitch_Disable))
216 /** @defgroup DAC_Channel_selection
219 #define DAC_Channel_1 ((uint32_t)0x00000000)
220 #define DAC_Channel_2 ((uint32_t)0x00000010)
222 #define IS_DAC_CHANNEL(CHANNEL) (((CHANNEL) == DAC_Channel_1) || \
223 ((CHANNEL) == DAC_Channel_2))
228 /** @defgroup DAC_data_alignement
232 #define DAC_Align_12b_R ((uint32_t)0x00000000)
233 #define DAC_Align_12b_L ((uint32_t)0x00000004)
234 #define DAC_Align_8b_R ((uint32_t)0x00000008)
236 #define IS_DAC_ALIGN(ALIGN) (((ALIGN) == DAC_Align_12b_R) || \
237 ((ALIGN) == DAC_Align_12b_L) || \
238 ((ALIGN) == DAC_Align_8b_R))
243 /** @defgroup DAC_wave_generation
247 #define DAC_Wave_Noise ((uint32_t)0x00000040)
248 #define DAC_Wave_Triangle ((uint32_t)0x00000080)
250 #define IS_DAC_WAVE(WAVE) (((WAVE) == DAC_Wave_Noise) || \
251 ((WAVE) == DAC_Wave_Triangle))
256 /** @defgroup DAC_data
260 #define IS_DAC_DATA(DATA) ((DATA) <= 0xFFF0)
265 /** @defgroup DAC_interrupts_definition
268 #define DAC_IT_DMAUDR ((uint32_t)0x00002000)
269 #define IS_DAC_IT(IT) (((IT) == DAC_IT_DMAUDR))
275 /** @defgroup DAC_flags_definition
279 #define DAC_FLAG_DMAUDR ((uint32_t)0x00002000)
280 #define IS_DAC_FLAG(FLAG) (((FLAG) == DAC_FLAG_DMAUDR))
290 /* Exported macro ------------------------------------------------------------*/
291 /* Exported functions --------------------------------------------------------*/
293 /* Function used to set the DAC configuration to the default reset state *****/
294 void DAC_DeInit(DAC_TypeDef* DACx);
296 /* DAC channels configuration: trigger, output buffer, data format functions */
297 void DAC_Init(DAC_TypeDef* DACx, uint32_t DAC_Channel, DAC_InitTypeDef* DAC_InitStruct);
298 void DAC_StructInit(DAC_InitTypeDef* DAC_InitStruct);
299 void DAC_Cmd(DAC_TypeDef* DACx, uint32_t DAC_Channel, FunctionalState NewState);
300 void DAC_SoftwareTriggerCmd(DAC_TypeDef* DACx, uint32_t DAC_Channel, FunctionalState NewState);
301 void DAC_DualSoftwareTriggerCmd(DAC_TypeDef* DACx, FunctionalState NewState);
302 void DAC_WaveGenerationCmd(DAC_TypeDef* DACx, uint32_t DAC_Channel, uint32_t DAC_Wave, FunctionalState NewState);
303 void DAC_SetChannel1Data(DAC_TypeDef* DACx, uint32_t DAC_Align, uint16_t Data);
304 void DAC_SetChannel2Data(DAC_TypeDef* DACx, uint32_t DAC_Align, uint16_t Data);
305 void DAC_SetDualChannelData(DAC_TypeDef* DACx, uint32_t DAC_Align, uint16_t Data2, uint16_t Data1);
306 uint16_t DAC_GetDataOutputValue(DAC_TypeDef* DACx, uint32_t DAC_Channel);
308 /* DMA management functions ***************************************************/
309 void DAC_DMACmd(DAC_TypeDef* DACx, uint32_t DAC_Channel, FunctionalState NewState);
311 /* Interrupts and flags management functions **********************************/
312 void DAC_ITConfig(DAC_TypeDef* DACx, uint32_t DAC_Channel, uint32_t DAC_IT, FunctionalState NewState);
313 FlagStatus DAC_GetFlagStatus(DAC_TypeDef* DACx, uint32_t DAC_Channel, uint32_t DAC_FLAG);
314 void DAC_ClearFlag(DAC_TypeDef* DACx, uint32_t DAC_Channel, uint32_t DAC_FLAG);
315 ITStatus DAC_GetITStatus(DAC_TypeDef* DACx, uint32_t DAC_Channel, uint32_t DAC_IT);
316 void DAC_ClearITPendingBit(DAC_TypeDef* DACx, uint32_t DAC_Channel, uint32_t DAC_IT);
322 #endif /*__STM32F30x_DAC_H */
332 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/