1 /**
2   ******************************************************************************
3   * @file    stm32f0xx_hal_dac_ex.h
4   * @author  MCD Application Team
5   * @brief   Header file of DAC HAL Extension module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2016 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef __STM32F0xx_HAL_DAC_EX_H
21 #define __STM32F0xx_HAL_DAC_EX_H
22 
23 #ifdef __cplusplus
24  extern "C" {
25 #endif
26 
27 /** @addtogroup STM32F0xx_HAL_Driver
28   * @{
29   */
30 
31 #if defined(STM32F051x8) || defined(STM32F058xx) || \
32     defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
33     defined(STM32F091xC) || defined(STM32F098xx)
34 
35 /* Includes ------------------------------------------------------------------*/
36 #include "stm32f0xx_hal_def.h"
37 
38 /** @addtogroup DACEx
39   * @{
40   */
41 
42 /* Exported types ------------------------------------------------------------*/
43 
44 /* Exported constants --------------------------------------------------------*/
45 
46 /** @defgroup DACEx_Exported_Constants DACEx Exported Constants
47   * @{
48   */
49 
50 /** @defgroup DACEx_lfsrunmask_triangleamplitude DACEx lfsrunmask triangleamplitude
51   * @{
52   */
53 #define DAC_LFSRUNMASK_BIT0                (0x00000000U) /*!< Unmask DAC channel LFSR bit0 for noise wave generation */
54 #define DAC_LFSRUNMASK_BITS1_0             ((uint32_t)DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[1:0] for noise wave generation */
55 #define DAC_LFSRUNMASK_BITS2_0             ((uint32_t)DAC_CR_MAMP1_1) /*!< Unmask DAC channel LFSR bit[2:0] for noise wave generation */
56 #define DAC_LFSRUNMASK_BITS3_0             ((uint32_t)DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0)/*!< Unmask DAC channel LFSR bit[3:0] for noise wave generation */
57 #define DAC_LFSRUNMASK_BITS4_0             ((uint32_t)DAC_CR_MAMP1_2) /*!< Unmask DAC channel LFSR bit[4:0] for noise wave generation */
58 #define DAC_LFSRUNMASK_BITS5_0             ((uint32_t)DAC_CR_MAMP1_2 | DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[5:0] for noise wave generation */
59 #define DAC_LFSRUNMASK_BITS6_0             ((uint32_t)DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1) /*!< Unmask DAC channel LFSR bit[6:0] for noise wave generation */
60 #define DAC_LFSRUNMASK_BITS7_0             ((uint32_t)DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[7:0] for noise wave generation */
61 #define DAC_LFSRUNMASK_BITS8_0             ((uint32_t)DAC_CR_MAMP1_3) /*!< Unmask DAC channel LFSR bit[8:0] for noise wave generation */
62 #define DAC_LFSRUNMASK_BITS9_0             ((uint32_t)DAC_CR_MAMP1_3 | DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[9:0] for noise wave generation */
63 #define DAC_LFSRUNMASK_BITS10_0            ((uint32_t)DAC_CR_MAMP1_3 | DAC_CR_MAMP1_1) /*!< Unmask DAC channel LFSR bit[10:0] for noise wave generation */
64 #define DAC_LFSRUNMASK_BITS11_0            ((uint32_t)DAC_CR_MAMP1_3 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[11:0] for noise wave generation */
65 #define DAC_TRIANGLEAMPLITUDE_1            (0x00000000U) /*!< Select max triangle amplitude of 1 */
66 #define DAC_TRIANGLEAMPLITUDE_3            ((uint32_t)DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 3 */
67 #define DAC_TRIANGLEAMPLITUDE_7            ((uint32_t)DAC_CR_MAMP1_1) /*!< Select max triangle amplitude of 7 */
68 #define DAC_TRIANGLEAMPLITUDE_15           ((uint32_t)DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 15 */
69 #define DAC_TRIANGLEAMPLITUDE_31           ((uint32_t)DAC_CR_MAMP1_2) /*!< Select max triangle amplitude of 31 */
70 #define DAC_TRIANGLEAMPLITUDE_63           ((uint32_t)DAC_CR_MAMP1_2 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 63 */
71 #define DAC_TRIANGLEAMPLITUDE_127          ((uint32_t)DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1) /*!< Select max triangle amplitude of 127 */
72 #define DAC_TRIANGLEAMPLITUDE_255          ((uint32_t)DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 255 */
73 #define DAC_TRIANGLEAMPLITUDE_511          ((uint32_t)DAC_CR_MAMP1_3) /*!< Select max triangle amplitude of 511 */
74 #define DAC_TRIANGLEAMPLITUDE_1023         ((uint32_t)DAC_CR_MAMP1_3 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 1023 */
75 #define DAC_TRIANGLEAMPLITUDE_2047         ((uint32_t)DAC_CR_MAMP1_3 | DAC_CR_MAMP1_1) /*!< Select max triangle amplitude of 2047 */
76 #define DAC_TRIANGLEAMPLITUDE_4095         ((uint32_t)DAC_CR_MAMP1_3 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 4095 */
77 
78 
79 /**
80   * @}
81   */
82 
83 /**
84   * @}
85   */
86 
87 /* Exported macro ------------------------------------------------------------*/
88 
89 
90 /** @defgroup DACEx_Exported_Macros DACEx Exported Macros
91   * @{
92   */
93 
94 /** @defgroup DAC_trigger_selection DAC trigger selection
95   * @{
96   */
97 #if defined(STM32F051x8) || defined(STM32F058xx)
98 
99 #define DAC_TRIGGER_NONE                   (0x00000000U) /*!< Conversion is automatic once the DAC1_DHRxxxx register
100                                                                        has been loaded, and not by external trigger */
101 #define DAC_TRIGGER_T2_TRGO                ((uint32_t)(DAC_CR_TSEL1_2 | DAC_CR_TEN1)) /*!< TIM2 TRGO selected as external conversion trigger for DAC channel */
102 #define DAC_TRIGGER_T3_TRGO                ((uint32_t)(DAC_CR_TSEL1_0 | DAC_CR_TEN1)) /*!< TIM3 TRGO selected as external conversion trigger for DAC channel */
103 #define DAC_TRIGGER_T6_TRGO                ((uint32_t)DAC_CR_TEN1) /*!< TIM6 TRGO selected as external conversion trigger for DAC channel */
104 #define DAC_TRIGGER_T15_TRGO                ((uint32_t)(DAC_CR_TSEL1_1 | DAC_CR_TSEL1_0 | DAC_CR_TEN1)) /*!< TIM15 TRGO selected as external conversion trigger for DAC channel */
105 #define DAC_TRIGGER_EXT_IT9                ((uint32_t)(DAC_CR_TSEL1_2 | DAC_CR_TSEL1_1 | DAC_CR_TEN1)) /*!< EXTI Line9 event selected as external conversion trigger for DAC channel */
106 #define DAC_TRIGGER_SOFTWARE               ((uint32_t)(DAC_CR_TSEL1 | DAC_CR_TEN1)) /*!< Conversion started by software trigger for DAC channel */
107 
108 #endif /* STM32F051x8 || STM32F058xx */
109 
110 #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
111     defined(STM32F091xC) || defined(STM32F098xx)
112 
113 #define DAC_TRIGGER_NONE                   (0x00000000U) /*!< Conversion is automatic once the DAC1_DHRxxxx register
114                                                                        has been loaded, and not by external trigger */
115 #define DAC_TRIGGER_T2_TRGO                ((uint32_t)(DAC_CR_TSEL1_2 | DAC_CR_TEN1)) /*!< TIM2 TRGO selected as external conversion trigger for DAC channel */
116 #define DAC_TRIGGER_T3_TRGO                ((uint32_t)(DAC_CR_TSEL1_0 | DAC_CR_TEN1)) /*!< TIM3 TRGO selected as external conversion trigger for DAC channel */
117 #define DAC_TRIGGER_T6_TRGO                ((uint32_t)DAC_CR_TEN1) /*!< TIM6 TRGO selected as external conversion trigger for DAC channel */
118 #define DAC_TRIGGER_T7_TRGO                ((uint32_t)(DAC_CR_TSEL1_1 | DAC_CR_TEN1)) /*!< TIM7 TRGO selected as external conversion trigger for DAC channel */
119 #define DAC_TRIGGER_T15_TRGO                ((uint32_t)(DAC_CR_TSEL1_1 | DAC_CR_TSEL1_0 | DAC_CR_TEN1)) /*!< TIM15 TRGO selected as external conversion trigger for DAC channel */
120 #define DAC_TRIGGER_EXT_IT9                ((uint32_t)(DAC_CR_TSEL1_2 | DAC_CR_TSEL1_1 | DAC_CR_TEN1)) /*!< EXTI Line9 event selected as external conversion trigger for DAC channel */
121 #define DAC_TRIGGER_SOFTWARE               ((uint32_t)(DAC_CR_TSEL1 | DAC_CR_TEN1)) /*!< Conversion started by software trigger for DAC channel */
122 
123 #endif /* STM32F071xB || STM32F072xB || STM32F078xx || */
124        /* STM32F091xC || STM32F098xx */
125 
126 /**
127   * @}
128   */
129 
130 /** @defgroup DAC_Channel_selection DAC Channel selection
131   * @{
132   */
133 
134 #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
135     defined(STM32F091xC) || defined(STM32F098xx)
136 
137 #define DAC_CHANNEL_1                      (0x00000000U)
138 #define DAC_CHANNEL_2                      (0x00000010U)
139 
140 #endif /* STM32F071xB || STM32F072xB || STM32F078xx || */
141        /* STM32F091xC || STM32F098xx */
142 
143 #if defined(STM32F051x8) || defined(STM32F058xx)
144 
145 #define DAC_CHANNEL_1                      (0x00000000U)
146 
147 #endif  /* STM32F051x8 || STM32F058xx */
148 
149 /**
150   * @}
151   */
152 
153 /**
154   * @}
155   */
156 
157 /* Private macro -------------------------------------------------------------*/
158 
159 /** @addtogroup DACEx_Private_Macros
160   * @{
161   */
162 
163 #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
164     defined(STM32F091xC) || defined(STM32F098xx)
165 
166 #define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_TRIGGER_NONE) || \
167                                  ((TRIGGER) == DAC_TRIGGER_T2_TRGO) || \
168                                  ((TRIGGER) == DAC_TRIGGER_T3_TRGO) || \
169                                  ((TRIGGER) == DAC_TRIGGER_T6_TRGO) || \
170                                  ((TRIGGER) == DAC_TRIGGER_T7_TRGO) || \
171                                  ((TRIGGER) == DAC_TRIGGER_T15_TRGO) || \
172                                  ((TRIGGER) == DAC_TRIGGER_EXT_IT9) || \
173                                  ((TRIGGER) == DAC_TRIGGER_SOFTWARE))
174 
175 #endif /* STM32F071xB || STM32F072xB || STM32F078xx || */
176        /* STM32F091xC || STM32F098xx */
177 
178 #if defined(STM32F051x8) || defined(STM32F058xx)
179 
180 #define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_TRIGGER_NONE) || \
181                                  ((TRIGGER) == DAC_TRIGGER_T2_TRGO) || \
182                                  ((TRIGGER) == DAC_TRIGGER_T3_TRGO) || \
183                                  ((TRIGGER) == DAC_TRIGGER_T6_TRGO) || \
184                                  ((TRIGGER) == DAC_TRIGGER_T15_TRGO) || \
185                                  ((TRIGGER) == DAC_TRIGGER_EXT_IT9) || \
186                                  ((TRIGGER) == DAC_TRIGGER_SOFTWARE))
187 
188 #endif /* STM32F051x8 || STM32F058xx */
189 
190 #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
191     defined(STM32F091xC) || defined(STM32F098xx)
192 
193 #define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_TRIGGER_NONE) || \
194                                  ((TRIGGER) == DAC_TRIGGER_T2_TRGO) || \
195                                  ((TRIGGER) == DAC_TRIGGER_T3_TRGO) || \
196                                  ((TRIGGER) == DAC_TRIGGER_T6_TRGO) || \
197                                  ((TRIGGER) == DAC_TRIGGER_T7_TRGO) || \
198                                  ((TRIGGER) == DAC_TRIGGER_T15_TRGO) || \
199                                  ((TRIGGER) == DAC_TRIGGER_EXT_IT9) || \
200                                  ((TRIGGER) == DAC_TRIGGER_SOFTWARE))
201 
202 #endif /* STM32F071xB || STM32F072xB || STM32F078xx || */
203        /* STM32F091xC || STM32F098xx */
204 
205 #define IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(VALUE) (((VALUE) == DAC_LFSRUNMASK_BIT0) || \
206                                                       ((VALUE) == DAC_LFSRUNMASK_BITS1_0) || \
207                                                       ((VALUE) == DAC_LFSRUNMASK_BITS2_0) || \
208                                                       ((VALUE) == DAC_LFSRUNMASK_BITS3_0) || \
209                                                       ((VALUE) == DAC_LFSRUNMASK_BITS4_0) || \
210                                                       ((VALUE) == DAC_LFSRUNMASK_BITS5_0) || \
211                                                       ((VALUE) == DAC_LFSRUNMASK_BITS6_0) || \
212                                                       ((VALUE) == DAC_LFSRUNMASK_BITS7_0) || \
213                                                       ((VALUE) == DAC_LFSRUNMASK_BITS8_0) || \
214                                                       ((VALUE) == DAC_LFSRUNMASK_BITS9_0) || \
215                                                       ((VALUE) == DAC_LFSRUNMASK_BITS10_0) || \
216                                                       ((VALUE) == DAC_LFSRUNMASK_BITS11_0) || \
217                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_1) || \
218                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_3) || \
219                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_7) || \
220                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_15) || \
221                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_31) || \
222                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_63) || \
223                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_127) || \
224                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_255) || \
225                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_511) || \
226                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_1023) || \
227                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_2047) || \
228                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_4095))
229 
230 /**
231   * @}
232   */
233 
234 /* Exported functions --------------------------------------------------------*/
235 
236 /** @addtogroup DACEx_Exported_Functions
237   * @{
238   */
239 
240 /** @addtogroup DACEx_Exported_Functions_Group1
241  * @{
242  */
243 /* IO operation functions *****************************************************/
244 
245 HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Amplitude);
246 HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Amplitude);
247 HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef* hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2);
248 
249 void              HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef* hdac);
250 void              HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef* hdac);
251 void              HAL_DACEx_ErrorCallbackCh2(DAC_HandleTypeDef* hdac);
252 void              HAL_DACEx_DMAUnderrunCallbackCh2(DAC_HandleTypeDef* hdac);
253 
254 /**
255   * @}
256   */
257 
258 /** @addtogroup DACEx_Exported_Functions_Group3
259   * @{
260   */
261 /* Peripheral Control functions ***********************************************/
262 
263 uint32_t          HAL_DACEx_DualGetValue(DAC_HandleTypeDef* hdac);
264 
265 /**
266   * @}
267   */
268 
269 /**
270   * @}
271   */
272 
273 /**
274   * @}
275   */
276 
277 #endif   /* STM32F051x8 || STM32F058xx ||                */
278          /* STM32F071xB || STM32F072xB || STM32F078xx || */
279          /* STM32F091xC || STM32F098xx */
280 
281 /**
282   * @}
283   */
284 
285 #ifdef __cplusplus
286 }
287 #endif
288 
289 #endif /*__STM32F0xx_HAL_DAC_EX_H */
290 
291