提交 | 用户 | age
|
bfc108
|
1 |
/**
|
Q |
2 |
******************************************************************************
|
|
3 |
* @file stm32f0xx_hal_dac.h
|
|
4 |
* @author MCD Application Team
|
|
5 |
* @brief Header file of DAC HAL module.
|
|
6 |
******************************************************************************
|
|
7 |
* @attention
|
|
8 |
*
|
|
9 |
* <h2><center>© 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_H
|
|
38 |
#define __STM32F0xx_HAL_DAC_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 DAC
|
|
56 |
* @{
|
|
57 |
*/
|
|
58 |
|
|
59 |
/* Exported types ------------------------------------------------------------*/
|
|
60 |
|
|
61 |
/** @defgroup DAC_Exported_Types DAC Exported Types
|
|
62 |
* @{
|
|
63 |
*/
|
|
64 |
|
|
65 |
/**
|
|
66 |
* @brief HAL State structures definition
|
|
67 |
*/
|
|
68 |
typedef enum
|
|
69 |
{
|
|
70 |
HAL_DAC_STATE_RESET = 0x00U, /*!< DAC not yet initialized or disabled */
|
|
71 |
HAL_DAC_STATE_READY = 0x01U, /*!< DAC initialized and ready for use */
|
|
72 |
HAL_DAC_STATE_BUSY = 0x02U, /*!< DAC internal processing is ongoing */
|
|
73 |
HAL_DAC_STATE_TIMEOUT = 0x03U, /*!< DAC timeout state */
|
|
74 |
HAL_DAC_STATE_ERROR = 0x04U /*!< DAC error state */
|
|
75 |
|
|
76 |
}HAL_DAC_StateTypeDef;
|
|
77 |
|
|
78 |
/**
|
|
79 |
* @brief DAC handle Structure definition
|
|
80 |
*/
|
|
81 |
typedef struct
|
|
82 |
{
|
|
83 |
DAC_TypeDef *Instance; /*!< Register base address */
|
|
84 |
|
|
85 |
__IO HAL_DAC_StateTypeDef State; /*!< DAC communication state */
|
|
86 |
|
|
87 |
HAL_LockTypeDef Lock; /*!< DAC locking object */
|
|
88 |
|
|
89 |
DMA_HandleTypeDef *DMA_Handle1; /*!< Pointer DMA handler for channel 1 */
|
|
90 |
|
|
91 |
DMA_HandleTypeDef *DMA_Handle2; /*!< Pointer DMA handler for channel 2 */
|
|
92 |
|
|
93 |
__IO uint32_t ErrorCode; /*!< DAC Error code */
|
|
94 |
|
|
95 |
}DAC_HandleTypeDef;
|
|
96 |
|
|
97 |
/**
|
|
98 |
* @brief DAC Configuration regular Channel structure definition
|
|
99 |
*/
|
|
100 |
typedef struct
|
|
101 |
{
|
|
102 |
uint32_t DAC_Trigger; /*!< Specifies the external trigger for the selected DAC channel.
|
|
103 |
This parameter can be a value of @ref DAC_trigger_selection */
|
|
104 |
|
|
105 |
uint32_t DAC_OutputBuffer; /*!< Specifies whether the DAC channel output buffer is enabled or disabled.
|
|
106 |
This parameter can be a value of @ref DAC_output_buffer */
|
|
107 |
|
|
108 |
}DAC_ChannelConfTypeDef;
|
|
109 |
|
|
110 |
/**
|
|
111 |
* @}
|
|
112 |
*/
|
|
113 |
|
|
114 |
/* Exported constants --------------------------------------------------------*/
|
|
115 |
|
|
116 |
/** @defgroup DAC_Exported_Constants DAC Exported Constants
|
|
117 |
* @{
|
|
118 |
*/
|
|
119 |
|
|
120 |
/** @defgroup DAC_Error_Code DAC Error Code
|
|
121 |
* @{
|
|
122 |
*/
|
|
123 |
#define HAL_DAC_ERROR_NONE 0x00U /*!< No error */
|
|
124 |
#define HAL_DAC_ERROR_DMAUNDERRUNCH1 0x01U /*!< DAC channel1 DMA underrun error */
|
|
125 |
#define HAL_DAC_ERROR_DMAUNDERRUNCH2 0x02U /*!< DAC channel2 DMA underrun error */
|
|
126 |
#define HAL_DAC_ERROR_DMA 0x04U /*!< DMA error */
|
|
127 |
/**
|
|
128 |
* @}
|
|
129 |
*/
|
|
130 |
|
|
131 |
/** @defgroup DAC_output_buffer DAC output buffer
|
|
132 |
* @{
|
|
133 |
*/
|
|
134 |
#define DAC_OUTPUTBUFFER_ENABLE (0x00000000U)
|
|
135 |
#define DAC_OUTPUTBUFFER_DISABLE ((uint32_t)DAC_CR_BOFF1)
|
|
136 |
|
|
137 |
/**
|
|
138 |
* @}
|
|
139 |
*/
|
|
140 |
|
|
141 |
/** @defgroup DAC_data_alignment DAC data alignment
|
|
142 |
* @{
|
|
143 |
*/
|
|
144 |
#define DAC_ALIGN_12B_R (0x00000000U)
|
|
145 |
#define DAC_ALIGN_12B_L (0x00000004U)
|
|
146 |
#define DAC_ALIGN_8B_R (0x00000008U)
|
|
147 |
|
|
148 |
/**
|
|
149 |
* @}
|
|
150 |
*/
|
|
151 |
|
|
152 |
/** @defgroup DAC_flags_definition DAC flags definition
|
|
153 |
* @{
|
|
154 |
*/
|
|
155 |
#define DAC_FLAG_DMAUDR1 ((uint32_t)DAC_SR_DMAUDR1)
|
|
156 |
#define DAC_FLAG_DMAUDR2 ((uint32_t)DAC_SR_DMAUDR2)
|
|
157 |
/**
|
|
158 |
* @}
|
|
159 |
*/
|
|
160 |
|
|
161 |
/** @defgroup DAC_IT_definition DAC IT definition
|
|
162 |
* @{
|
|
163 |
*/
|
|
164 |
#define DAC_IT_DMAUDR1 ((uint32_t)DAC_SR_DMAUDR1)
|
|
165 |
#define DAC_IT_DMAUDR2 ((uint32_t)DAC_SR_DMAUDR2)
|
|
166 |
/**
|
|
167 |
* @}
|
|
168 |
*/
|
|
169 |
|
|
170 |
/**
|
|
171 |
* @}
|
|
172 |
*/
|
|
173 |
|
|
174 |
/* Exported macro ------------------------------------------------------------*/
|
|
175 |
|
|
176 |
/** @defgroup DAC_Exported_Macros DAC Exported Macros
|
|
177 |
* @{
|
|
178 |
*/
|
|
179 |
|
|
180 |
/** @brief Reset DAC handle state
|
|
181 |
* @param __HANDLE__ specifies the DAC handle.
|
|
182 |
* @retval None
|
|
183 |
*/
|
|
184 |
#define __HAL_DAC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_DAC_STATE_RESET)
|
|
185 |
|
|
186 |
/** @brief Enable the DAC channel
|
|
187 |
* @param __HANDLE__ specifies the DAC handle.
|
|
188 |
* @param __DAC_Channel__ specifies the DAC channel
|
|
189 |
* @retval None
|
|
190 |
*/
|
|
191 |
#define __HAL_DAC_ENABLE(__HANDLE__, __DAC_Channel__) \
|
|
192 |
((__HANDLE__)->Instance->CR |= (DAC_CR_EN1 << (__DAC_Channel__)))
|
|
193 |
|
|
194 |
/** @brief Disable the DAC channel
|
|
195 |
* @param __HANDLE__ specifies the DAC handle
|
|
196 |
* @param __DAC_Channel__ specifies the DAC channel.
|
|
197 |
* @retval None
|
|
198 |
*/
|
|
199 |
#define __HAL_DAC_DISABLE(__HANDLE__, __DAC_Channel__) \
|
|
200 |
((__HANDLE__)->Instance->CR &= ~(DAC_CR_EN1 << (__DAC_Channel__)))
|
|
201 |
|
|
202 |
/** @brief Enable the DAC interrupt
|
|
203 |
* @param __HANDLE__ specifies the DAC handle
|
|
204 |
* @param __INTERRUPT__ specifies the DAC interrupt.
|
|
205 |
* This parameter can be any combination of the following values:
|
|
206 |
* @arg DAC_IT_DMAUDR1: DAC channel 1 DMA underrun interrupt
|
|
207 |
* @arg DAC_IT_DMAUDR2: DAC channel 2 DMA underrun interrupt
|
|
208 |
* @retval None
|
|
209 |
*/
|
|
210 |
#define __HAL_DAC_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) |= (__INTERRUPT__))
|
|
211 |
|
|
212 |
/** @brief Disable the DAC interrupt
|
|
213 |
* @param __HANDLE__ specifies the DAC handle
|
|
214 |
* @param __INTERRUPT__ specifies the DAC interrupt.
|
|
215 |
* This parameter can be any combination of the following values:
|
|
216 |
* @arg DAC_IT_DMAUDR1: DAC channel 1 DMA underrun interrupt
|
|
217 |
* @retval None
|
|
218 |
*/
|
|
219 |
#define __HAL_DAC_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR) &= ~(__INTERRUPT__))
|
|
220 |
|
|
221 |
/** @brief Check whether the specified DAC interrupt source is enabled or not
|
|
222 |
* @param __HANDLE__ DAC handle
|
|
223 |
* @param __INTERRUPT__ DAC interrupt source to check
|
|
224 |
* This parameter can be any combination of the following values:
|
|
225 |
* @arg DAC_IT_DMAUDR1: DAC channel 1 DMA underrun interrupt
|
|
226 |
* @arg DAC_IT_DMAUDR2: DAC channel 2 DMA underrun interrupt
|
|
227 |
* @retval State of interruption (SET or RESET)
|
|
228 |
*/
|
|
229 |
#define __HAL_DAC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR & (__INTERRUPT__)) == (__INTERRUPT__))
|
|
230 |
|
|
231 |
/** @brief Get the selected DAC's flag status
|
|
232 |
* @param __HANDLE__ specifies the DAC handle.
|
|
233 |
* @param __FLAG__ specifies the DAC flag to get.
|
|
234 |
* This parameter can be any combination of the following values:
|
|
235 |
* @arg DAC_FLAG_DMAUDR1: DAC channel 1 DMA underrun flag
|
|
236 |
* @retval None
|
|
237 |
*/
|
|
238 |
#define __HAL_DAC_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
|
|
239 |
|
|
240 |
/** @brief Clear the DAC's flag
|
|
241 |
* @param __HANDLE__ specifies the DAC handle.
|
|
242 |
* @param __FLAG__ specifies the DAC flag to clear.
|
|
243 |
* This parameter can be any combination of the following values:
|
|
244 |
* @arg DAC_FLAG_DMAUDR1: DAC channel 1 DMA underrun flag
|
|
245 |
* @retval None
|
|
246 |
*/
|
|
247 |
#define __HAL_DAC_CLEAR_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR) = (__FLAG__))
|
|
248 |
|
|
249 |
/**
|
|
250 |
* @}
|
|
251 |
*/
|
|
252 |
|
|
253 |
/* Private macro -------------------------------------------------------------*/
|
|
254 |
|
|
255 |
/** @addtogroup DAC_Private_Macros
|
|
256 |
* @{
|
|
257 |
*/
|
|
258 |
#define IS_DAC_OUTPUT_BUFFER_STATE(STATE) (((STATE) == DAC_OUTPUTBUFFER_ENABLE) || \
|
|
259 |
((STATE) == DAC_OUTPUTBUFFER_DISABLE))
|
|
260 |
|
|
261 |
|
|
262 |
#if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
|
|
263 |
defined(STM32F091xC) || defined(STM32F098xx)
|
|
264 |
|
|
265 |
#define IS_DAC_CHANNEL(CHANNEL) (((CHANNEL) == DAC_CHANNEL_1) || \
|
|
266 |
((CHANNEL) == DAC_CHANNEL_2))
|
|
267 |
|
|
268 |
#endif /* STM32F071xB || STM32F072xB || STM32F078xx || */
|
|
269 |
/* STM32F091xC || STM32F098xx */
|
|
270 |
|
|
271 |
#if defined(STM32F051x8) || defined(STM32F058xx)
|
|
272 |
|
|
273 |
#define IS_DAC_CHANNEL(CHANNEL) (((CHANNEL) == DAC_CHANNEL_1))
|
|
274 |
|
|
275 |
#endif /* STM32F051x8 || STM32F058xx */
|
|
276 |
|
|
277 |
|
|
278 |
#define IS_DAC_ALIGN(ALIGN) (((ALIGN) == DAC_ALIGN_12B_R) || \
|
|
279 |
((ALIGN) == DAC_ALIGN_12B_L) || \
|
|
280 |
((ALIGN) == DAC_ALIGN_8B_R))
|
|
281 |
|
|
282 |
#define IS_DAC_DATA(DATA) ((DATA) <= 0xFFF0U)
|
|
283 |
|
|
284 |
/** @brief Set DHR12R1 alignment
|
|
285 |
* @param __ALIGNMENT__ specifies the DAC alignment
|
|
286 |
* @retval None
|
|
287 |
*/
|
|
288 |
#define DAC_DHR12R1_ALIGNMENT(__ALIGNMENT__) ((0x00000008U) + (__ALIGNMENT__))
|
|
289 |
|
|
290 |
/** @brief Set DHR12R2 alignment
|
|
291 |
* @param __ALIGNMENT__ specifies the DAC alignment
|
|
292 |
* @retval None
|
|
293 |
*/
|
|
294 |
#define DAC_DHR12R2_ALIGNMENT(__ALIGNMENT__) ((0x00000014U) + (__ALIGNMENT__))
|
|
295 |
|
|
296 |
/** @brief Set DHR12RD alignment
|
|
297 |
* @param __ALIGNMENT__ specifies the DAC alignment
|
|
298 |
* @retval None
|
|
299 |
*/
|
|
300 |
#define DAC_DHR12RD_ALIGNMENT(__ALIGNMENT__) ((0x00000020U) + (__ALIGNMENT__))
|
|
301 |
|
|
302 |
/**
|
|
303 |
* @}
|
|
304 |
*/
|
|
305 |
|
|
306 |
/* Include DAC HAL Extension module */
|
|
307 |
#include "stm32f0xx_hal_dac_ex.h"
|
|
308 |
|
|
309 |
/* Exported functions --------------------------------------------------------*/
|
|
310 |
|
|
311 |
/** @addtogroup DAC_Exported_Functions
|
|
312 |
* @{
|
|
313 |
*/
|
|
314 |
|
|
315 |
/** @addtogroup DAC_Exported_Functions_Group1
|
|
316 |
* @{
|
|
317 |
*/
|
|
318 |
/* Initialization and de-initialization functions *****************************/
|
|
319 |
HAL_StatusTypeDef HAL_DAC_Init(DAC_HandleTypeDef* hdac);
|
|
320 |
HAL_StatusTypeDef HAL_DAC_DeInit(DAC_HandleTypeDef* hdac);
|
|
321 |
void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac);
|
|
322 |
void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac);
|
|
323 |
|
|
324 |
/**
|
|
325 |
* @}
|
|
326 |
*/
|
|
327 |
|
|
328 |
/** @addtogroup DAC_Exported_Functions_Group2
|
|
329 |
* @{
|
|
330 |
*/
|
|
331 |
/* IO operation functions *****************************************************/
|
|
332 |
HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel);
|
|
333 |
HAL_StatusTypeDef HAL_DAC_Stop(DAC_HandleTypeDef* hdac, uint32_t Channel);
|
|
334 |
HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t* pData, uint32_t Length, uint32_t Alignment);
|
|
335 |
HAL_StatusTypeDef HAL_DAC_Stop_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel);
|
|
336 |
|
|
337 |
void HAL_DAC_IRQHandler(DAC_HandleTypeDef* hdac);
|
|
338 |
|
|
339 |
HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data);
|
|
340 |
|
|
341 |
void HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef* hdac);
|
|
342 |
void HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef* hdac);
|
|
343 |
void HAL_DAC_ErrorCallbackCh1(DAC_HandleTypeDef *hdac);
|
|
344 |
void HAL_DAC_DMAUnderrunCallbackCh1(DAC_HandleTypeDef *hdac);
|
|
345 |
/**
|
|
346 |
* @}
|
|
347 |
*/
|
|
348 |
|
|
349 |
/** @addtogroup DAC_Exported_Functions_Group3
|
|
350 |
* @{
|
|
351 |
*/
|
|
352 |
/* Peripheral Control functions ***********************************************/
|
|
353 |
uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef* hdac, uint32_t Channel);
|
|
354 |
|
|
355 |
HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel);
|
|
356 |
/**
|
|
357 |
* @}
|
|
358 |
*/
|
|
359 |
|
|
360 |
/** @addtogroup DAC_Exported_Functions_Group4
|
|
361 |
* @{
|
|
362 |
*/
|
|
363 |
/* Peripheral State and Error functions ***************************************/
|
|
364 |
HAL_DAC_StateTypeDef HAL_DAC_GetState(DAC_HandleTypeDef* hdac);
|
|
365 |
uint32_t HAL_DAC_GetError(DAC_HandleTypeDef *hdac);
|
|
366 |
|
|
367 |
/**
|
|
368 |
* @}
|
|
369 |
*/
|
|
370 |
|
|
371 |
/**
|
|
372 |
* @}
|
|
373 |
*/
|
|
374 |
|
|
375 |
/**
|
|
376 |
* @}
|
|
377 |
*/
|
|
378 |
|
|
379 |
#endif /* STM32F051x8 || STM32F058xx || */
|
|
380 |
/* STM32F071xB || STM32F072xB || STM32F078xx || */
|
|
381 |
/* STM32F091xC || STM32F098xx */
|
|
382 |
|
|
383 |
/**
|
|
384 |
* @}
|
|
385 |
*/
|
|
386 |
|
|
387 |
#ifdef __cplusplus
|
|
388 |
}
|
|
389 |
#endif
|
|
390 |
|
|
391 |
|
|
392 |
#endif /*__STM32F0xx_HAL_DAC_H */
|
|
393 |
|
|
394 |
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
|
395 |
|