2 ******************************************************************************
3 * @file stm32f4xx_dac.h
4 * @author MCD Application Team
7 * @brief This file contains all the functions prototypes for the DAC firmware
9 ******************************************************************************
12 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
14 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
15 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
16 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
17 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
19 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
20 ******************************************************************************
23 /* Define to prevent recursive inclusion -------------------------------------*/
24 #ifndef __STM32F4xx_DAC_H
25 #define __STM32F4xx_DAC_H
31 /* Includes ------------------------------------------------------------------*/
32 #include "stm32f4xx.h"
34 /** @addtogroup STM32F4xx_StdPeriph_Driver
42 /* Exported types ------------------------------------------------------------*/
45 * @brief DAC Init structure definition
50 uint32_t DAC_Trigger; /*!< Specifies the external trigger for the selected DAC channel.
51 This parameter can be a value of @ref DAC_trigger_selection */
53 uint32_t DAC_WaveGeneration; /*!< Specifies whether DAC channel noise waves or triangle waves
54 are generated, or whether no wave is generated.
55 This parameter can be a value of @ref DAC_wave_generation */
57 uint32_t DAC_LFSRUnmask_TriangleAmplitude; /*!< Specifies the LFSR mask for noise wave generation or
58 the maximum amplitude triangle generation for the DAC channel.
59 This parameter can be a value of @ref DAC_lfsrunmask_triangleamplitude */
61 uint32_t DAC_OutputBuffer; /*!< Specifies whether the DAC channel output buffer is enabled or disabled.
62 This parameter can be a value of @ref DAC_output_buffer */
65 /* Exported constants --------------------------------------------------------*/
67 /** @defgroup DAC_Exported_Constants
71 /** @defgroup DAC_trigger_selection
75 #define DAC_Trigger_None ((uint32_t)0x00000000) /*!< Conversion is automatic once the DAC1_DHRxxxx register
76 has been loaded, and not by external trigger */
77 #define DAC_Trigger_T2_TRGO ((uint32_t)0x00000024) /*!< TIM2 TRGO selected as external conversion trigger for DAC channel */
78 #define DAC_Trigger_T4_TRGO ((uint32_t)0x0000002C) /*!< TIM4 TRGO selected as external conversion trigger for DAC channel */
79 #define DAC_Trigger_T5_TRGO ((uint32_t)0x0000001C) /*!< TIM5 TRGO selected as external conversion trigger for DAC channel */
80 #define DAC_Trigger_T6_TRGO ((uint32_t)0x00000004) /*!< TIM6 TRGO selected as external conversion trigger for DAC channel */
81 #define DAC_Trigger_T7_TRGO ((uint32_t)0x00000014) /*!< TIM7 TRGO selected as external conversion trigger for DAC channel */
82 #define DAC_Trigger_T8_TRGO ((uint32_t)0x0000000C) /*!< TIM8 TRGO selected as external conversion trigger for DAC channel */
84 #define DAC_Trigger_Ext_IT9 ((uint32_t)0x00000034) /*!< EXTI Line9 event selected as external conversion trigger for DAC channel */
85 #define DAC_Trigger_Software ((uint32_t)0x0000003C) /*!< Conversion started by software trigger for DAC channel */
87 #define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_Trigger_None) || \
88 ((TRIGGER) == DAC_Trigger_T6_TRGO) || \
89 ((TRIGGER) == DAC_Trigger_T8_TRGO) || \
90 ((TRIGGER) == DAC_Trigger_T7_TRGO) || \
91 ((TRIGGER) == DAC_Trigger_T5_TRGO) || \
92 ((TRIGGER) == DAC_Trigger_T2_TRGO) || \
93 ((TRIGGER) == DAC_Trigger_T4_TRGO) || \
94 ((TRIGGER) == DAC_Trigger_Ext_IT9) || \
95 ((TRIGGER) == DAC_Trigger_Software))
101 /** @defgroup DAC_wave_generation
105 #define DAC_WaveGeneration_None ((uint32_t)0x00000000)
106 #define DAC_WaveGeneration_Noise ((uint32_t)0x00000040)
107 #define DAC_WaveGeneration_Triangle ((uint32_t)0x00000080)
108 #define IS_DAC_GENERATE_WAVE(WAVE) (((WAVE) == DAC_WaveGeneration_None) || \
109 ((WAVE) == DAC_WaveGeneration_Noise) || \
110 ((WAVE) == DAC_WaveGeneration_Triangle))
115 /** @defgroup DAC_lfsrunmask_triangleamplitude
119 #define DAC_LFSRUnmask_Bit0 ((uint32_t)0x00000000) /*!< Unmask DAC channel LFSR bit0 for noise wave generation */
120 #define DAC_LFSRUnmask_Bits1_0 ((uint32_t)0x00000100) /*!< Unmask DAC channel LFSR bit[1:0] for noise wave generation */
121 #define DAC_LFSRUnmask_Bits2_0 ((uint32_t)0x00000200) /*!< Unmask DAC channel LFSR bit[2:0] for noise wave generation */
122 #define DAC_LFSRUnmask_Bits3_0 ((uint32_t)0x00000300) /*!< Unmask DAC channel LFSR bit[3:0] for noise wave generation */
123 #define DAC_LFSRUnmask_Bits4_0 ((uint32_t)0x00000400) /*!< Unmask DAC channel LFSR bit[4:0] for noise wave generation */
124 #define DAC_LFSRUnmask_Bits5_0 ((uint32_t)0x00000500) /*!< Unmask DAC channel LFSR bit[5:0] for noise wave generation */
125 #define DAC_LFSRUnmask_Bits6_0 ((uint32_t)0x00000600) /*!< Unmask DAC channel LFSR bit[6:0] for noise wave generation */
126 #define DAC_LFSRUnmask_Bits7_0 ((uint32_t)0x00000700) /*!< Unmask DAC channel LFSR bit[7:0] for noise wave generation */
127 #define DAC_LFSRUnmask_Bits8_0 ((uint32_t)0x00000800) /*!< Unmask DAC channel LFSR bit[8:0] for noise wave generation */
128 #define DAC_LFSRUnmask_Bits9_0 ((uint32_t)0x00000900) /*!< Unmask DAC channel LFSR bit[9:0] for noise wave generation */
129 #define DAC_LFSRUnmask_Bits10_0 ((uint32_t)0x00000A00) /*!< Unmask DAC channel LFSR bit[10:0] for noise wave generation */
130 #define DAC_LFSRUnmask_Bits11_0 ((uint32_t)0x00000B00) /*!< Unmask DAC channel LFSR bit[11:0] for noise wave generation */
131 #define DAC_TriangleAmplitude_1 ((uint32_t)0x00000000) /*!< Select max triangle amplitude of 1 */
132 #define DAC_TriangleAmplitude_3 ((uint32_t)0x00000100) /*!< Select max triangle amplitude of 3 */
133 #define DAC_TriangleAmplitude_7 ((uint32_t)0x00000200) /*!< Select max triangle amplitude of 7 */
134 #define DAC_TriangleAmplitude_15 ((uint32_t)0x00000300) /*!< Select max triangle amplitude of 15 */
135 #define DAC_TriangleAmplitude_31 ((uint32_t)0x00000400) /*!< Select max triangle amplitude of 31 */
136 #define DAC_TriangleAmplitude_63 ((uint32_t)0x00000500) /*!< Select max triangle amplitude of 63 */
137 #define DAC_TriangleAmplitude_127 ((uint32_t)0x00000600) /*!< Select max triangle amplitude of 127 */
138 #define DAC_TriangleAmplitude_255 ((uint32_t)0x00000700) /*!< Select max triangle amplitude of 255 */
139 #define DAC_TriangleAmplitude_511 ((uint32_t)0x00000800) /*!< Select max triangle amplitude of 511 */
140 #define DAC_TriangleAmplitude_1023 ((uint32_t)0x00000900) /*!< Select max triangle amplitude of 1023 */
141 #define DAC_TriangleAmplitude_2047 ((uint32_t)0x00000A00) /*!< Select max triangle amplitude of 2047 */
142 #define DAC_TriangleAmplitude_4095 ((uint32_t)0x00000B00) /*!< Select max triangle amplitude of 4095 */
144 #define IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(VALUE) (((VALUE) == DAC_LFSRUnmask_Bit0) || \
145 ((VALUE) == DAC_LFSRUnmask_Bits1_0) || \
146 ((VALUE) == DAC_LFSRUnmask_Bits2_0) || \
147 ((VALUE) == DAC_LFSRUnmask_Bits3_0) || \
148 ((VALUE) == DAC_LFSRUnmask_Bits4_0) || \
149 ((VALUE) == DAC_LFSRUnmask_Bits5_0) || \
150 ((VALUE) == DAC_LFSRUnmask_Bits6_0) || \
151 ((VALUE) == DAC_LFSRUnmask_Bits7_0) || \
152 ((VALUE) == DAC_LFSRUnmask_Bits8_0) || \
153 ((VALUE) == DAC_LFSRUnmask_Bits9_0) || \
154 ((VALUE) == DAC_LFSRUnmask_Bits10_0) || \
155 ((VALUE) == DAC_LFSRUnmask_Bits11_0) || \
156 ((VALUE) == DAC_TriangleAmplitude_1) || \
157 ((VALUE) == DAC_TriangleAmplitude_3) || \
158 ((VALUE) == DAC_TriangleAmplitude_7) || \
159 ((VALUE) == DAC_TriangleAmplitude_15) || \
160 ((VALUE) == DAC_TriangleAmplitude_31) || \
161 ((VALUE) == DAC_TriangleAmplitude_63) || \
162 ((VALUE) == DAC_TriangleAmplitude_127) || \
163 ((VALUE) == DAC_TriangleAmplitude_255) || \
164 ((VALUE) == DAC_TriangleAmplitude_511) || \
165 ((VALUE) == DAC_TriangleAmplitude_1023) || \
166 ((VALUE) == DAC_TriangleAmplitude_2047) || \
167 ((VALUE) == DAC_TriangleAmplitude_4095))
172 /** @defgroup DAC_output_buffer
176 #define DAC_OutputBuffer_Enable ((uint32_t)0x00000000)
177 #define DAC_OutputBuffer_Disable ((uint32_t)0x00000002)
178 #define IS_DAC_OUTPUT_BUFFER_STATE(STATE) (((STATE) == DAC_OutputBuffer_Enable) || \
179 ((STATE) == DAC_OutputBuffer_Disable))
184 /** @defgroup DAC_Channel_selection
188 #define DAC_Channel_1 ((uint32_t)0x00000000)
189 #define DAC_Channel_2 ((uint32_t)0x00000010)
190 #define IS_DAC_CHANNEL(CHANNEL) (((CHANNEL) == DAC_Channel_1) || \
191 ((CHANNEL) == DAC_Channel_2))
196 /** @defgroup DAC_data_alignement
200 #define DAC_Align_12b_R ((uint32_t)0x00000000)
201 #define DAC_Align_12b_L ((uint32_t)0x00000004)
202 #define DAC_Align_8b_R ((uint32_t)0x00000008)
203 #define IS_DAC_ALIGN(ALIGN) (((ALIGN) == DAC_Align_12b_R) || \
204 ((ALIGN) == DAC_Align_12b_L) || \
205 ((ALIGN) == DAC_Align_8b_R))
210 /** @defgroup DAC_wave_generation
214 #define DAC_Wave_Noise ((uint32_t)0x00000040)
215 #define DAC_Wave_Triangle ((uint32_t)0x00000080)
216 #define IS_DAC_WAVE(WAVE) (((WAVE) == DAC_Wave_Noise) || \
217 ((WAVE) == DAC_Wave_Triangle))
222 /** @defgroup DAC_data
226 #define IS_DAC_DATA(DATA) ((DATA) <= 0xFFF0)
231 /** @defgroup DAC_interrupts_definition
234 #define DAC_IT_DMAUDR ((uint32_t)0x00002000)
235 #define IS_DAC_IT(IT) (((IT) == DAC_IT_DMAUDR))
241 /** @defgroup DAC_flags_definition
245 #define DAC_FLAG_DMAUDR ((uint32_t)0x00002000)
246 #define IS_DAC_FLAG(FLAG) (((FLAG) == DAC_FLAG_DMAUDR))
256 /* Exported macro ------------------------------------------------------------*/
257 /* Exported functions --------------------------------------------------------*/
259 /* Function used to set the DAC configuration to the default reset state *****/
260 void DAC_DeInit(void);
262 /* DAC channels configuration: trigger, output buffer, data format functions */
263 void DAC_Init(uint32_t DAC_Channel, DAC_InitTypeDef* DAC_InitStruct);
264 void DAC_StructInit(DAC_InitTypeDef* DAC_InitStruct);
265 void DAC_Cmd(uint32_t DAC_Channel, FunctionalState NewState);
266 void DAC_SoftwareTriggerCmd(uint32_t DAC_Channel, FunctionalState NewState);
267 void DAC_DualSoftwareTriggerCmd(FunctionalState NewState);
268 void DAC_WaveGenerationCmd(uint32_t DAC_Channel, uint32_t DAC_Wave, FunctionalState NewState);
269 void DAC_SetChannel1Data(uint32_t DAC_Align, uint16_t Data);
270 void DAC_SetChannel2Data(uint32_t DAC_Align, uint16_t Data);
271 void DAC_SetDualChannelData(uint32_t DAC_Align, uint16_t Data2, uint16_t Data1);
272 uint16_t DAC_GetDataOutputValue(uint32_t DAC_Channel);
274 /* DMA management functions ***************************************************/
275 void DAC_DMACmd(uint32_t DAC_Channel, FunctionalState NewState);
277 /* Interrupts and flags management functions **********************************/
278 void DAC_ITConfig(uint32_t DAC_Channel, uint32_t DAC_IT, FunctionalState NewState);
279 FlagStatus DAC_GetFlagStatus(uint32_t DAC_Channel, uint32_t DAC_FLAG);
280 void DAC_ClearFlag(uint32_t DAC_Channel, uint32_t DAC_FLAG);
281 ITStatus DAC_GetITStatus(uint32_t DAC_Channel, uint32_t DAC_IT);
282 void DAC_ClearITPendingBit(uint32_t DAC_Channel, uint32_t DAC_IT);
288 #endif /*__STM32F4xx_DAC_H */
298 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/