QuakeGod
2022-09-29 e1f35018c4dec304b00f50d9dbe12204fd57a623
提交 | 用户 | age
bfc108 1 /**
Q 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   * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
10   *
11   * Redistribution and use in source and binary forms, with or without modification,
12   * are permitted provided that the following conditions are met:
13   *   1. Redistributions of source code must retain the above copyright notice,
14   *      this list of conditions and the following disclaimer.
15   *   2. Redistributions in binary form must reproduce the above copyright notice,
16   *      this list of conditions and the following disclaimer in the documentation
17   *      and/or other materials provided with the distribution.
18   *   3. Neither the name of STMicroelectronics nor the names of its contributors
19   *      may be used to endorse or promote products derived from this software
20   *      without specific prior written permission.
21   *
22   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   *
33   ******************************************************************************
34   */
35
36 /* Define to prevent recursive inclusion -------------------------------------*/
37 #ifndef __STM32F0xx_HAL_DAC_EX_H
38 #define __STM32F0xx_HAL_DAC_EX_H
39
40 #ifdef __cplusplus
41  extern "C" {
42 #endif
43
44 /** @addtogroup STM32F0xx_HAL_Driver
45   * @{
46   */
47
48 #if defined(STM32F051x8) || defined(STM32F058xx) || \
49     defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
50     defined(STM32F091xC) || defined(STM32F098xx)
51
52 /* Includes ------------------------------------------------------------------*/
53 #include "stm32f0xx_hal_def.h"
54            
55 /** @addtogroup DACEx
56   * @{
57   */
58
59 /* Exported types ------------------------------------------------------------*/
60    
61 /* Exported constants --------------------------------------------------------*/
62
63 /** @defgroup DACEx_Exported_Constants DACEx Exported Constants
64   * @{
65   */  
66
67 /** @defgroup DACEx_lfsrunmask_triangleamplitude DACEx lfsrunmask triangleamplitude
68   * @{
69   */
70 #define DAC_LFSRUNMASK_BIT0                (0x00000000U) /*!< Unmask DAC channel LFSR bit0 for noise wave generation */
71 #define DAC_LFSRUNMASK_BITS1_0             ((uint32_t)DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[1:0] for noise wave generation */
72 #define DAC_LFSRUNMASK_BITS2_0             ((uint32_t)DAC_CR_MAMP1_1) /*!< Unmask DAC channel LFSR bit[2:0] for noise wave generation */
73 #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 */
74 #define DAC_LFSRUNMASK_BITS4_0             ((uint32_t)DAC_CR_MAMP1_2) /*!< Unmask DAC channel LFSR bit[4:0] for noise wave generation */
75 #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 */
76 #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 */
77 #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 */
78 #define DAC_LFSRUNMASK_BITS8_0             ((uint32_t)DAC_CR_MAMP1_3) /*!< Unmask DAC channel LFSR bit[8:0] for noise wave generation */
79 #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 */
80 #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 */
81 #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 */
82 #define DAC_TRIANGLEAMPLITUDE_1            (0x00000000U) /*!< Select max triangle amplitude of 1 */
83 #define DAC_TRIANGLEAMPLITUDE_3            ((uint32_t)DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 3 */
84 #define DAC_TRIANGLEAMPLITUDE_7            ((uint32_t)DAC_CR_MAMP1_1) /*!< Select max triangle amplitude of 7 */
85 #define DAC_TRIANGLEAMPLITUDE_15           ((uint32_t)DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 15 */
86 #define DAC_TRIANGLEAMPLITUDE_31           ((uint32_t)DAC_CR_MAMP1_2) /*!< Select max triangle amplitude of 31 */
87 #define DAC_TRIANGLEAMPLITUDE_63           ((uint32_t)DAC_CR_MAMP1_2 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 63 */
88 #define DAC_TRIANGLEAMPLITUDE_127          ((uint32_t)DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1) /*!< Select max triangle amplitude of 127 */
89 #define DAC_TRIANGLEAMPLITUDE_255          ((uint32_t)DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 255 */
90 #define DAC_TRIANGLEAMPLITUDE_511          ((uint32_t)DAC_CR_MAMP1_3) /*!< Select max triangle amplitude of 511 */
91 #define DAC_TRIANGLEAMPLITUDE_1023         ((uint32_t)DAC_CR_MAMP1_3 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 1023 */
92 #define DAC_TRIANGLEAMPLITUDE_2047         ((uint32_t)DAC_CR_MAMP1_3 | DAC_CR_MAMP1_1) /*!< Select max triangle amplitude of 2047 */
93 #define DAC_TRIANGLEAMPLITUDE_4095         ((uint32_t)DAC_CR_MAMP1_3 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 4095 */
94
95
96 /**
97   * @}
98   */
99
100 /**
101   * @}
102   */
103
104 /* Exported macro ------------------------------------------------------------*/
105
106
107 /** @defgroup DACEx_Exported_Macros DACEx Exported Macros
108   * @{
109   */
110   
111 /** @defgroup DAC_trigger_selection DAC trigger selection
112   * @{
113   */
114 #if defined(STM32F051x8) || defined(STM32F058xx)
115
116 #define DAC_TRIGGER_NONE                   (0x00000000U) /*!< Conversion is automatic once the DAC1_DHRxxxx register 
117                                                                        has been loaded, and not by external trigger */
118 #define DAC_TRIGGER_T2_TRGO                ((uint32_t)(DAC_CR_TSEL1_2 | DAC_CR_TEN1)) /*!< TIM2 TRGO selected as external conversion trigger for DAC channel */
119 #define DAC_TRIGGER_T3_TRGO                ((uint32_t)(DAC_CR_TSEL1_0 | DAC_CR_TEN1)) /*!< TIM3 TRGO selected as external conversion trigger for DAC channel */
120 #define DAC_TRIGGER_T6_TRGO                ((uint32_t)DAC_CR_TEN1) /*!< TIM6 TRGO selected as external conversion trigger for DAC channel */
121 #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 */
122 #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 */
123 #define DAC_TRIGGER_SOFTWARE               ((uint32_t)(DAC_CR_TSEL1 | DAC_CR_TEN1)) /*!< Conversion started by software trigger for DAC channel */
124
125 #endif /* STM32F051x8 || STM32F058xx */
126
127 #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
128     defined(STM32F091xC) || defined(STM32F098xx)
129
130 #define DAC_TRIGGER_NONE                   (0x00000000U) /*!< Conversion is automatic once the DAC1_DHRxxxx register 
131                                                                        has been loaded, and not by external trigger */
132 #define DAC_TRIGGER_T2_TRGO                ((uint32_t)(DAC_CR_TSEL1_2 | DAC_CR_TEN1)) /*!< TIM2 TRGO selected as external conversion trigger for DAC channel */
133 #define DAC_TRIGGER_T3_TRGO                ((uint32_t)(DAC_CR_TSEL1_0 | DAC_CR_TEN1)) /*!< TIM3 TRGO selected as external conversion trigger for DAC channel */
134 #define DAC_TRIGGER_T6_TRGO                ((uint32_t)DAC_CR_TEN1) /*!< TIM6 TRGO selected as external conversion trigger for DAC channel */
135 #define DAC_TRIGGER_T7_TRGO                ((uint32_t)(DAC_CR_TSEL1_1 | DAC_CR_TEN1)) /*!< TIM7 TRGO selected as external conversion trigger for DAC channel */
136 #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 */
137 #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 */
138 #define DAC_TRIGGER_SOFTWARE               ((uint32_t)(DAC_CR_TSEL1 | DAC_CR_TEN1)) /*!< Conversion started by software trigger for DAC channel */
139
140 #endif /* STM32F071xB || STM32F072xB || STM32F078xx || */
141        /* STM32F091xC || STM32F098xx */
142
143 /**
144   * @}
145   */
146
147 /** @defgroup DAC_Channel_selection DAC Channel selection
148   * @{
149   */
150   
151 #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
152     defined(STM32F091xC) || defined(STM32F098xx)
153
154 #define DAC_CHANNEL_1                      (0x00000000U)
155 #define DAC_CHANNEL_2                      (0x00000010U)
156
157 #endif /* STM32F071xB || STM32F072xB || STM32F078xx || */
158        /* STM32F091xC || STM32F098xx */
159
160 #if defined(STM32F051x8) || defined(STM32F058xx)
161
162 #define DAC_CHANNEL_1                      (0x00000000U)
163
164 #endif  /* STM32F051x8 || STM32F058xx */ 
165
166 /**
167   * @}
168   */
169   
170 /**
171   * @}
172   */
173
174 /* Private macro -------------------------------------------------------------*/
175
176 /** @addtogroup DACEx_Private_Macros
177   * @{
178   */
179
180 #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
181     defined(STM32F091xC) || defined(STM32F098xx)
182       
183 #define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_TRIGGER_NONE) || \
184                                  ((TRIGGER) == DAC_TRIGGER_T2_TRGO) || \
185                                  ((TRIGGER) == DAC_TRIGGER_T3_TRGO) || \
186                                  ((TRIGGER) == DAC_TRIGGER_T6_TRGO) || \
187                                  ((TRIGGER) == DAC_TRIGGER_T7_TRGO) || \
188                                  ((TRIGGER) == DAC_TRIGGER_T15_TRGO) || \
189                                  ((TRIGGER) == DAC_TRIGGER_EXT_IT9) || \
190                                  ((TRIGGER) == DAC_TRIGGER_SOFTWARE))      
191
192 #endif /* STM32F071xB || STM32F072xB || STM32F078xx || */
193        /* STM32F091xC || STM32F098xx */
194
195 #if defined(STM32F051x8) || defined(STM32F058xx)
196
197 #define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_TRIGGER_NONE) || \
198                                  ((TRIGGER) == DAC_TRIGGER_T2_TRGO) || \
199                                  ((TRIGGER) == DAC_TRIGGER_T3_TRGO) || \
200                                  ((TRIGGER) == DAC_TRIGGER_T6_TRGO) || \
201                                  ((TRIGGER) == DAC_TRIGGER_T15_TRGO) || \
202                                  ((TRIGGER) == DAC_TRIGGER_EXT_IT9) || \
203                                  ((TRIGGER) == DAC_TRIGGER_SOFTWARE))
204
205 #endif /* STM32F051x8 || STM32F058xx */
206
207 #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
208     defined(STM32F091xC) || defined(STM32F098xx)
209       
210 #define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_TRIGGER_NONE) || \
211                                  ((TRIGGER) == DAC_TRIGGER_T2_TRGO) || \
212                                  ((TRIGGER) == DAC_TRIGGER_T3_TRGO) || \
213                                  ((TRIGGER) == DAC_TRIGGER_T6_TRGO) || \
214                                  ((TRIGGER) == DAC_TRIGGER_T7_TRGO) || \
215                                  ((TRIGGER) == DAC_TRIGGER_T15_TRGO) || \
216                                  ((TRIGGER) == DAC_TRIGGER_EXT_IT9) || \
217                                  ((TRIGGER) == DAC_TRIGGER_SOFTWARE))      
218
219 #endif /* STM32F071xB || STM32F072xB || STM32F078xx || */
220        /* STM32F091xC || STM32F098xx */
221
222 #define IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(VALUE) (((VALUE) == DAC_LFSRUNMASK_BIT0) || \
223                                                       ((VALUE) == DAC_LFSRUNMASK_BITS1_0) || \
224                                                       ((VALUE) == DAC_LFSRUNMASK_BITS2_0) || \
225                                                       ((VALUE) == DAC_LFSRUNMASK_BITS3_0) || \
226                                                       ((VALUE) == DAC_LFSRUNMASK_BITS4_0) || \
227                                                       ((VALUE) == DAC_LFSRUNMASK_BITS5_0) || \
228                                                       ((VALUE) == DAC_LFSRUNMASK_BITS6_0) || \
229                                                       ((VALUE) == DAC_LFSRUNMASK_BITS7_0) || \
230                                                       ((VALUE) == DAC_LFSRUNMASK_BITS8_0) || \
231                                                       ((VALUE) == DAC_LFSRUNMASK_BITS9_0) || \
232                                                       ((VALUE) == DAC_LFSRUNMASK_BITS10_0) || \
233                                                       ((VALUE) == DAC_LFSRUNMASK_BITS11_0) || \
234                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_1) || \
235                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_3) || \
236                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_7) || \
237                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_15) || \
238                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_31) || \
239                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_63) || \
240                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_127) || \
241                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_255) || \
242                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_511) || \
243                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_1023) || \
244                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_2047) || \
245                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_4095))
246
247 /**
248   * @}
249   */
250
251 /* Exported functions --------------------------------------------------------*/  
252
253 /** @addtogroup DACEx_Exported_Functions
254   * @{
255   */
256
257 /** @addtogroup DACEx_Exported_Functions_Group1
258  * @{
259  */    
260 /* IO operation functions *****************************************************/
261   
262 HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Amplitude);
263 HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Amplitude);
264 HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef* hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2);
265
266 void              HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef* hdac);
267 void              HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef* hdac);
268 void              HAL_DACEx_ErrorCallbackCh2(DAC_HandleTypeDef* hdac);
269 void              HAL_DACEx_DMAUnderrunCallbackCh2(DAC_HandleTypeDef* hdac);
270
271 /**
272   * @}
273   */
274
275 /** @addtogroup DACEx_Exported_Functions_Group3
276   * @{
277   */ 
278 /* Peripheral Control functions ***********************************************/
279
280 uint32_t          HAL_DACEx_DualGetValue(DAC_HandleTypeDef* hdac);
281
282 /**
283   * @}
284   */
285
286 /**
287   * @}
288   */
289
290 /**
291   * @}
292   */
293
294 #endif   /* STM32F051x8 || STM32F058xx ||                */
295          /* STM32F071xB || STM32F072xB || STM32F078xx || */
296          /* STM32F091xC || STM32F098xx */
297
298 /**
299   * @}
300   */
301
302 #ifdef __cplusplus
303 }
304 #endif 
305   
306 #endif /*__STM32F0xx_HAL_DAC_EX_H */
307
308 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/