1 /**
2   ******************************************************************************
3   * @file    stm32f30x_dac.h
4   * @author  MCD Application Team
5   * @version V1.2.3
6   * @date    10-July-2015
7   * @brief   This file contains all the functions prototypes for the DAC firmware
8   *          library.
9   ******************************************************************************
10   * @attention
11   *
12   * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
13   *
14   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
15   * You may not use this file except in compliance with the License.
16   * You may obtain a copy of the License at:
17   *
18   *        http://www.st.com/software_license_agreement_liberty_v2
19   *
20   * Unless required by applicable law or agreed to in writing, software
21   * distributed under the License is distributed on an "AS IS" BASIS,
22   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23   * See the License for the specific language governing permissions and
24   * limitations under the License.
25   *
26   ******************************************************************************
27   */
28 
29 /* Define to prevent recursive inclusion -------------------------------------*/
30 #ifndef __STM32F30x_DAC_H
31 #define __STM32F30x_DAC_H
32 
33 #ifdef __cplusplus
34  extern "C" {
35 #endif
36 
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32f30x.h"
39 
40 /** @addtogroup STM32F30x_StdPeriph_Driver
41   * @{
42   */
43 
44 /** @addtogroup DAC
45   * @{
46   */
47 
48 /* Exported types ------------------------------------------------------------*/
49 #define DAC_CR_DMAUDRIE                  ((uint32_t)0x00002000)        /*!< DAC channel DMA underrun interrupt enable */
50 
51 /**
52   * @brief  DAC Init structure definition
53   */
54 
55 typedef struct
56 {
57   uint32_t DAC_Trigger;                      /*!< Specifies the external trigger for the selected DAC channel.
58                                                   This parameter can be a value of @ref DAC_trigger_selection */
59 
60   uint32_t DAC_WaveGeneration;               /*!< Specifies whether DAC channel noise waves or triangle waves
61                                                   are generated, or whether no wave is generated.
62                                                   This parameter can be a value of @ref DAC_wave_generation */
63 
64   uint32_t DAC_LFSRUnmask_TriangleAmplitude; /*!< Specifies the LFSR mask for noise wave generation or
65                                                   the maximum amplitude triangle generation for the DAC channel.
66                                                   This parameter can be a value of @ref DAC_lfsrunmask_triangleamplitude */
67 
68   uint32_t DAC_Buffer_Switch;                /*!< Specifies whether the DAC channel output buffer is enabled or disabled or
69                                                   the DAC channel output switch is enabled or disabled.
70                                                   This parameter can be a value of @ref DAC_buffer_switch */
71 }DAC_InitTypeDef;
72 
73 /* Exported constants --------------------------------------------------------*/
74 
75 /** @defgroup DAC_Exported_Constants
76   * @{
77   */
78 
79 #define IS_DAC_ALL_PERIPH(PERIPH) (((PERIPH) == DAC1) || \
80                                    ((PERIPH) == DAC2))
81 
82 #define IS_DAC_LIST1_PERIPH(PERIPH) (((PERIPH) == DAC1))
83 
84 /** @defgroup DAC_trigger_selection
85   * @{
86   */
87 
88 #define DAC_Trigger_None                     ((uint32_t)0x00000000) /*!< Conversion is automatic once the DAC1_DHRxxxx register
89                                                                          has been loaded, and not by external trigger */
90 #define DAC_Trigger_T6_TRGO                  ((uint32_t)0x00000004) /*!< TIM6 TRGO selected as external conversion trigger for DAC1/2 channel1/2 */
91 #define DAC_Trigger_T3_TRGO                  ((uint32_t)0x0000000C) /*!< TIM3 TRGO selected as external conversion trigger for DAC1/2 channel1/2 */
92 #define DAC_Trigger_T8_TRGO                  ((uint32_t)0x0000000C) /*!< TIM8 TRGO selected as external conversion trigger for DAC1 channel1/2 */
93 #define DAC_Trigger_T7_TRGO                  ((uint32_t)0x00000014) /*!< TIM7 TRGO selected as external conversion trigger for DAC1/2 channel1/2 */
94 #define DAC_Trigger_T15_TRGO                 ((uint32_t)0x0000001C) /*!< TIM15 TRGO selected as external conversion trigger for DAC1/2 channel1/2 */
95 #define DAC_Trigger_HRTIM1_DACTRG1           ((uint32_t)0x0000001C)  /*!< HRTIM1 DACTRG1 selected as external conversion trigger for DAC1 channel1/2 */
96 #define DAC_Trigger_T2_TRGO                  ((uint32_t)0x00000024) /*!< TIM2 TRGO selected as external conversion trigger for DAC1/2 channel1/2 */
97 #define DAC_Trigger_T4_TRGO                  ((uint32_t)0x0000002C) /*!< TIM4 TRGO selected as external conversion trigger for DAC channel */
98 #define DAC_Trigger_HRTIM1_DACTRG2           ((uint32_t)0x0000002C) /*!< HRTIM1 DACTRG2 selected as external conversion trigger for DAC1 channel1/2 */
99 #define DAC_Trigger_HRTIM1_DACTRG3           ((uint32_t)0x0000002C) /*!< HRTIM1 DACTRG3 selected as external conversion trigger for DAC2 channel1 */
100 #define DAC_Trigger_Ext_IT9                  ((uint32_t)0x00000034) /*!< EXTI Line9 event selected as external conversion trigger for DAC1/2 channel1/2 */
101 #define DAC_Trigger_Software                 ((uint32_t)0x0000003C) /*!< Conversion started by software trigger for DAC1/2 channel1/2 */
102 
103 #define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_Trigger_None)          || \
104                                  ((TRIGGER) == DAC_Trigger_T6_TRGO)       || \
105                                  ((TRIGGER) == DAC_Trigger_T3_TRGO)       || \
106                                  ((TRIGGER) == DAC_Trigger_T8_TRGO)       || \
107                                  ((TRIGGER) == DAC_Trigger_T7_TRGO)       || \
108                                  ((TRIGGER) == DAC_Trigger_T15_TRGO)      || \
109                                  ((TRIGGER) == DAC_Trigger_HRTIM1_DACTRG1)|| \
110                                  ((TRIGGER) == DAC_Trigger_T2_TRGO)       || \
111                                  ((TRIGGER) == DAC_Trigger_T4_TRGO)       || \
112                                  ((TRIGGER) == DAC_Trigger_HRTIM1_DACTRG2)|| \
113                                  ((TRIGGER) == DAC_Trigger_HRTIM1_DACTRG3)|| \
114                                  ((TRIGGER) == DAC_Trigger_Ext_IT9)       || \
115                                  ((TRIGGER) == DAC_Trigger_Software))
116 
117 /**
118   * @}
119   */
120 
121 /** @defgroup DAC_wave_generation
122   * @{
123   */
124 
125 #define DAC_WaveGeneration_None            ((uint32_t)0x00000000)
126 #define DAC_WaveGeneration_Noise           ((uint32_t)0x00000040)
127 #define DAC_WaveGeneration_Triangle        ((uint32_t)0x00000080)
128 
129 #define IS_DAC_GENERATE_WAVE(WAVE) (((WAVE) == DAC_WaveGeneration_None)  || \
130                                     ((WAVE) == DAC_WaveGeneration_Noise) || \
131                                     ((WAVE) == DAC_WaveGeneration_Triangle))
132 /**
133   * @}
134   */
135 
136 /** @defgroup DAC_lfsrunmask_triangleamplitude
137   * @{
138   */
139 
140 #define DAC_LFSRUnmask_Bit0                ((uint32_t)0x00000000) /*!< Unmask DAC channel LFSR bit0 for noise wave generation */
141 #define DAC_LFSRUnmask_Bits1_0             ((uint32_t)0x00000100) /*!< Unmask DAC channel LFSR bit[1:0] for noise wave generation */
142 #define DAC_LFSRUnmask_Bits2_0             ((uint32_t)0x00000200) /*!< Unmask DAC channel LFSR bit[2:0] for noise wave generation */
143 #define DAC_LFSRUnmask_Bits3_0             ((uint32_t)0x00000300) /*!< Unmask DAC channel LFSR bit[3:0] for noise wave generation */
144 #define DAC_LFSRUnmask_Bits4_0             ((uint32_t)0x00000400) /*!< Unmask DAC channel LFSR bit[4:0] for noise wave generation */
145 #define DAC_LFSRUnmask_Bits5_0             ((uint32_t)0x00000500) /*!< Unmask DAC channel LFSR bit[5:0] for noise wave generation */
146 #define DAC_LFSRUnmask_Bits6_0             ((uint32_t)0x00000600) /*!< Unmask DAC channel LFSR bit[6:0] for noise wave generation */
147 #define DAC_LFSRUnmask_Bits7_0             ((uint32_t)0x00000700) /*!< Unmask DAC channel LFSR bit[7:0] for noise wave generation */
148 #define DAC_LFSRUnmask_Bits8_0             ((uint32_t)0x00000800) /*!< Unmask DAC channel LFSR bit[8:0] for noise wave generation */
149 #define DAC_LFSRUnmask_Bits9_0             ((uint32_t)0x00000900) /*!< Unmask DAC channel LFSR bit[9:0] for noise wave generation */
150 #define DAC_LFSRUnmask_Bits10_0            ((uint32_t)0x00000A00) /*!< Unmask DAC channel LFSR bit[10:0] for noise wave generation */
151 #define DAC_LFSRUnmask_Bits11_0            ((uint32_t)0x00000B00) /*!< Unmask DAC channel LFSR bit[11:0] for noise wave generation */
152 #define DAC_TriangleAmplitude_1            ((uint32_t)0x00000000) /*!< Select max triangle amplitude of 1 */
153 #define DAC_TriangleAmplitude_3            ((uint32_t)0x00000100) /*!< Select max triangle amplitude of 3 */
154 #define DAC_TriangleAmplitude_7            ((uint32_t)0x00000200) /*!< Select max triangle amplitude of 7 */
155 #define DAC_TriangleAmplitude_15           ((uint32_t)0x00000300) /*!< Select max triangle amplitude of 15 */
156 #define DAC_TriangleAmplitude_31           ((uint32_t)0x00000400) /*!< Select max triangle amplitude of 31 */
157 #define DAC_TriangleAmplitude_63           ((uint32_t)0x00000500) /*!< Select max triangle amplitude of 63 */
158 #define DAC_TriangleAmplitude_127          ((uint32_t)0x00000600) /*!< Select max triangle amplitude of 127 */
159 #define DAC_TriangleAmplitude_255          ((uint32_t)0x00000700) /*!< Select max triangle amplitude of 255 */
160 #define DAC_TriangleAmplitude_511          ((uint32_t)0x00000800) /*!< Select max triangle amplitude of 511 */
161 #define DAC_TriangleAmplitude_1023         ((uint32_t)0x00000900) /*!< Select max triangle amplitude of 1023 */
162 #define DAC_TriangleAmplitude_2047         ((uint32_t)0x00000A00) /*!< Select max triangle amplitude of 2047 */
163 #define DAC_TriangleAmplitude_4095         ((uint32_t)0x00000B00) /*!< Select max triangle amplitude of 4095 */
164 
165 #define IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(VALUE) (((VALUE) == DAC_LFSRUnmask_Bit0) || \
166                                                       ((VALUE) == DAC_LFSRUnmask_Bits1_0) || \
167                                                       ((VALUE) == DAC_LFSRUnmask_Bits2_0) || \
168                                                       ((VALUE) == DAC_LFSRUnmask_Bits3_0) || \
169                                                       ((VALUE) == DAC_LFSRUnmask_Bits4_0) || \
170                                                       ((VALUE) == DAC_LFSRUnmask_Bits5_0) || \
171                                                       ((VALUE) == DAC_LFSRUnmask_Bits6_0) || \
172                                                       ((VALUE) == DAC_LFSRUnmask_Bits7_0) || \
173                                                       ((VALUE) == DAC_LFSRUnmask_Bits8_0) || \
174                                                       ((VALUE) == DAC_LFSRUnmask_Bits9_0) || \
175                                                       ((VALUE) == DAC_LFSRUnmask_Bits10_0) || \
176                                                       ((VALUE) == DAC_LFSRUnmask_Bits11_0) || \
177                                                       ((VALUE) == DAC_TriangleAmplitude_1) || \
178                                                       ((VALUE) == DAC_TriangleAmplitude_3) || \
179                                                       ((VALUE) == DAC_TriangleAmplitude_7) || \
180                                                       ((VALUE) == DAC_TriangleAmplitude_15) || \
181                                                       ((VALUE) == DAC_TriangleAmplitude_31) || \
182                                                       ((VALUE) == DAC_TriangleAmplitude_63) || \
183                                                       ((VALUE) == DAC_TriangleAmplitude_127) || \
184                                                       ((VALUE) == DAC_TriangleAmplitude_255) || \
185                                                       ((VALUE) == DAC_TriangleAmplitude_511) || \
186                                                       ((VALUE) == DAC_TriangleAmplitude_1023) || \
187                                                       ((VALUE) == DAC_TriangleAmplitude_2047) || \
188                                                       ((VALUE) == DAC_TriangleAmplitude_4095))
189 /**
190   * @}
191   */
192 
193 /** @defgroup DAC_buffer_switch
194   * @{
195   */
196 
197 #define DAC_BufferSwitch_Disable                 ((uint32_t)0x00000000)
198 #define DAC_BufferSwitch_Enable                  ((uint32_t)0x00000002)
199 
200 #define IS_DAC_BUFFER_SWITCH_STATE(STATE) (((STATE) == DAC_BufferSwitch_Enable) || \
201                                            ((STATE) == DAC_BufferSwitch_Disable))
202 /**
203   * @}
204   */
205 
206 /** @defgroup DAC_Channel_selection
207   * @{
208   */
209 #define DAC_Channel_1                     ((uint32_t)0x00000000)
210 #define DAC_Channel_2                     ((uint32_t)0x00000010)
211 
212 #define IS_DAC_CHANNEL(CHANNEL) (((CHANNEL) == DAC_Channel_1) || \
213                                  ((CHANNEL) == DAC_Channel_2))
214 /**
215   * @}
216   */
217 
218 /** @defgroup DAC_data_alignement
219   * @{
220   */
221 
222 #define DAC_Align_12b_R                    ((uint32_t)0x00000000)
223 #define DAC_Align_12b_L                    ((uint32_t)0x00000004)
224 #define DAC_Align_8b_R                     ((uint32_t)0x00000008)
225 
226 #define IS_DAC_ALIGN(ALIGN) (((ALIGN) == DAC_Align_12b_R) || \
227                              ((ALIGN) == DAC_Align_12b_L) || \
228                              ((ALIGN) == DAC_Align_8b_R))
229 /**
230   * @}
231   */
232 
233 /** @defgroup DAC_wave_generation
234   * @{
235   */
236 
237 #define DAC_Wave_Noise                     ((uint32_t)0x00000040)
238 #define DAC_Wave_Triangle                  ((uint32_t)0x00000080)
239 
240 #define IS_DAC_WAVE(WAVE) (((WAVE) == DAC_Wave_Noise) || \
241                            ((WAVE) == DAC_Wave_Triangle))
242 /**
243   * @}
244   */
245 
246 /** @defgroup DAC_data
247   * @{
248   */
249 
250 #define IS_DAC_DATA(DATA) ((DATA) <= 0xFFF0)
251 /**
252   * @}
253   */
254 
255 /** @defgroup DAC_interrupts_definition
256   * @{
257   */
258 #define DAC_IT_DMAUDR                      ((uint32_t)0x00002000)
259 #define IS_DAC_IT(IT) (((IT) == DAC_IT_DMAUDR))
260 
261 /**
262   * @}
263   */
264 
265 /** @defgroup DAC_flags_definition
266   * @{
267   */
268 
269 #define DAC_FLAG_DMAUDR                    ((uint32_t)0x00002000)
270 #define IS_DAC_FLAG(FLAG) (((FLAG) == DAC_FLAG_DMAUDR))
271 
272 /**
273   * @}
274   */
275 
276 /**
277   * @}
278   */
279 
280 /* Exported macro ------------------------------------------------------------*/
281 /* Exported functions --------------------------------------------------------*/
282 
283 /*  Function used to set the DAC configuration to the default reset state *****/
284 void DAC_DeInit(DAC_TypeDef* DACx);
285 
286 /*  DAC channels configuration: trigger, output buffer, data format functions */
287 void DAC_Init(DAC_TypeDef* DACx, uint32_t DAC_Channel, DAC_InitTypeDef* DAC_InitStruct);
288 void DAC_StructInit(DAC_InitTypeDef* DAC_InitStruct);
289 void DAC_Cmd(DAC_TypeDef* DACx, uint32_t DAC_Channel, FunctionalState NewState);
290 void DAC_SoftwareTriggerCmd(DAC_TypeDef* DACx, uint32_t DAC_Channel, FunctionalState NewState);
291 void DAC_DualSoftwareTriggerCmd(DAC_TypeDef* DACx, FunctionalState NewState);
292 void DAC_WaveGenerationCmd(DAC_TypeDef* DACx, uint32_t DAC_Channel, uint32_t DAC_Wave, FunctionalState NewState);
293 void DAC_SetChannel1Data(DAC_TypeDef* DACx, uint32_t DAC_Align, uint16_t Data);
294 void DAC_SetChannel2Data(DAC_TypeDef* DACx, uint32_t DAC_Align, uint16_t Data);
295 void DAC_SetDualChannelData(DAC_TypeDef* DACx, uint32_t DAC_Align, uint16_t Data2, uint16_t Data1);
296 uint16_t DAC_GetDataOutputValue(DAC_TypeDef* DACx, uint32_t DAC_Channel);
297 
298 /* DMA management functions ***************************************************/
299 void DAC_DMACmd(DAC_TypeDef* DACx, uint32_t DAC_Channel, FunctionalState NewState);
300 
301 /* Interrupts and flags management functions **********************************/
302 void DAC_ITConfig(DAC_TypeDef* DACx, uint32_t DAC_Channel, uint32_t DAC_IT, FunctionalState NewState);
303 FlagStatus DAC_GetFlagStatus(DAC_TypeDef* DACx, uint32_t DAC_Channel, uint32_t DAC_FLAG);
304 void DAC_ClearFlag(DAC_TypeDef* DACx, uint32_t DAC_Channel, uint32_t DAC_FLAG);
305 ITStatus DAC_GetITStatus(DAC_TypeDef* DACx, uint32_t DAC_Channel, uint32_t DAC_IT);
306 void DAC_ClearITPendingBit(DAC_TypeDef* DACx, uint32_t DAC_Channel, uint32_t DAC_IT);
307 
308 #ifdef __cplusplus
309 }
310 #endif
311 
312 #endif /*__STM32F30x_DAC_H */
313 
314 /**
315   * @}
316   */
317 
318 /**
319   * @}
320   */
321 
322 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
323