STM32F4xx HAL Documentation
Hardware Abstraction Layer for STM32F4 familiy
Loading...
Searching...
No Matches
stm32f4xx_hal_dac_ex.c
Go to the documentation of this file.
1
37/* Includes ------------------------------------------------------------------*/
38#include "stm32f4xx_hal.h"
39
44#ifdef HAL_DAC_MODULE_ENABLED
45
46#if defined(DAC)
47
53/* Private typedef -----------------------------------------------------------*/
54/* Private define ------------------------------------------------------------*/
55
56/* Private macro -------------------------------------------------------------*/
57/* Private variables ---------------------------------------------------------*/
58/* Private function prototypes -----------------------------------------------*/
59/* Exported functions --------------------------------------------------------*/
60
84#if defined(DAC_CHANNEL2_SUPPORT)
91HAL_StatusTypeDef HAL_DACEx_DualStart(DAC_HandleTypeDef *hdac)
92{
93 uint32_t tmp_swtrig = 0UL;
94
95 /* Check the DAC peripheral handle */
96 if (hdac == NULL)
97 {
98 return HAL_ERROR;
99 }
100
101
102 /* Process locked */
103 __HAL_LOCK(hdac);
104
105 /* Change DAC state */
107
108 /* Enable the Peripheral */
110 __HAL_DAC_ENABLE(hdac, DAC_CHANNEL_2);
111
112 /* Check if software trigger enabled */
113 if ((hdac->Instance->CR & (DAC_CR_TEN1 | DAC_CR_TSEL1)) == DAC_TRIGGER_SOFTWARE)
114 {
115 tmp_swtrig |= DAC_SWTRIGR_SWTRIG1;
116 }
117 if ((hdac->Instance->CR & (DAC_CR_TEN2 | DAC_CR_TSEL2)) == (DAC_TRIGGER_SOFTWARE << (DAC_CHANNEL_2 & 0x10UL)))
118 {
119 tmp_swtrig |= DAC_SWTRIGR_SWTRIG2;
120 }
121 /* Enable the selected DAC software conversion*/
122 SET_BIT(hdac->Instance->SWTRIGR, tmp_swtrig);
123
124 /* Change DAC state */
126
127 /* Process unlocked */
128 __HAL_UNLOCK(hdac);
129
130 /* Return function status */
131 return HAL_OK;
132}
133
140HAL_StatusTypeDef HAL_DACEx_DualStop(DAC_HandleTypeDef *hdac)
141{
142 /* Check the DAC peripheral handle */
143 if (hdac == NULL)
144 {
145 return HAL_ERROR;
146 }
147
148
149 /* Disable the Peripheral */
151 __HAL_DAC_DISABLE(hdac, DAC_CHANNEL_2);
152
153 /* Change DAC state */
155
156 /* Return function status */
157 return HAL_OK;
158}
159#endif /* DAC_CHANNEL2_SUPPORT */
160
185HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Amplitude)
186{
187 /* Check the DAC peripheral handle */
188 if (hdac == NULL)
189 {
190 return HAL_ERROR;
191 }
192
193 /* Check the parameters */
196
197 /* Process locked */
198 __HAL_LOCK(hdac);
199
200 /* Change DAC state */
202
203 /* Enable the triangle wave generation for the selected DAC channel */
204 MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1) | (DAC_CR_MAMP1)) << (Channel & 0x10UL),
205 (DAC_CR_WAVE1_1 | Amplitude) << (Channel & 0x10UL));
206
207 /* Change DAC state */
209
210 /* Process unlocked */
211 __HAL_UNLOCK(hdac);
212
213 /* Return function status */
214 return HAL_OK;
215}
216
241HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Amplitude)
242{
243 /* Check the DAC peripheral handle */
244 if (hdac == NULL)
245 {
246 return HAL_ERROR;
247 }
248
249 /* Check the parameters */
252
253 /* Process locked */
254 __HAL_LOCK(hdac);
255
256 /* Change DAC state */
258
259 /* Enable the noise wave generation for the selected DAC channel */
260 MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1) | (DAC_CR_MAMP1)) << (Channel & 0x10UL),
261 (DAC_CR_WAVE1_0 | Amplitude) << (Channel & 0x10UL));
262
263 /* Change DAC state */
265
266 /* Process unlocked */
267 __HAL_UNLOCK(hdac);
268
269 /* Return function status */
270 return HAL_OK;
271}
272
273#if defined(DAC_CHANNEL2_SUPPORT)
289HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef *hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2)
290{
291 uint32_t data;
292 uint32_t tmp;
293
294 /* Check the DAC peripheral handle */
295 if (hdac == NULL)
296 {
297 return HAL_ERROR;
298 }
299
300 /* Check the parameters */
301 assert_param(IS_DAC_ALIGN(Alignment));
304
305 /* Calculate and set dual DAC data holding register value */
306 if (Alignment == DAC_ALIGN_8B_R)
307 {
308 data = ((uint32_t)Data2 << 8U) | Data1;
309 }
310 else
311 {
312 data = ((uint32_t)Data2 << 16U) | Data1;
313 }
314
315 tmp = (uint32_t)hdac->Instance;
316 tmp += DAC_DHR12RD_ALIGNMENT(Alignment);
317
318 /* Set the dual DAC selected data holding register */
319 *(__IO uint32_t *)tmp = data;
320
321 /* Return function status */
322 return HAL_OK;
323}
324
331__weak void HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef *hdac)
332{
333 /* Prevent unused argument(s) compilation warning */
334 UNUSED(hdac);
335
336 /* NOTE : This function should not be modified, when the callback is needed,
337 the HAL_DACEx_ConvCpltCallbackCh2 could be implemented in the user file
338 */
339}
340
347__weak void HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef *hdac)
348{
349 /* Prevent unused argument(s) compilation warning */
350 UNUSED(hdac);
351
352 /* NOTE : This function should not be modified, when the callback is needed,
353 the HAL_DACEx_ConvHalfCpltCallbackCh2 could be implemented in the user file
354 */
355}
356
363__weak void HAL_DACEx_ErrorCallbackCh2(DAC_HandleTypeDef *hdac)
364{
365 /* Prevent unused argument(s) compilation warning */
366 UNUSED(hdac);
367
368 /* NOTE : This function should not be modified, when the callback is needed,
369 the HAL_DACEx_ErrorCallbackCh2 could be implemented in the user file
370 */
371}
372
379__weak void HAL_DACEx_DMAUnderrunCallbackCh2(DAC_HandleTypeDef *hdac)
380{
381 /* Prevent unused argument(s) compilation warning */
382 UNUSED(hdac);
383
384 /* NOTE : This function should not be modified, when the callback is needed,
385 the HAL_DACEx_DMAUnderrunCallbackCh2 could be implemented in the user file
386 */
387}
388#endif /* DAC_CHANNEL2_SUPPORT */
389
390
409#if defined(DAC_CHANNEL2_SUPPORT)
416uint32_t HAL_DACEx_DualGetValue(const DAC_HandleTypeDef *hdac)
417{
418 uint32_t tmp = 0UL;
419
420 tmp |= hdac->Instance->DOR1;
421
422 tmp |= hdac->Instance->DOR2 << 16UL;
423
424 /* Returns the DAC channel data output register value */
425 return tmp;
426}
427#endif /* DAC_CHANNEL2_SUPPORT */
428
436/* Private functions ---------------------------------------------------------*/
442#if defined(DAC_CHANNEL2_SUPPORT)
449void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma)
450{
451 DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
452
453#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
454 hdac->ConvCpltCallbackCh2(hdac);
455#else
456 HAL_DACEx_ConvCpltCallbackCh2(hdac);
457#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
458
460}
461
468void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma)
469{
470 DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
471 /* Conversion complete callback */
472#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
473 hdac->ConvHalfCpltCallbackCh2(hdac);
474#else
475 HAL_DACEx_ConvHalfCpltCallbackCh2(hdac);
476#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
477}
478
485void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma)
486{
487 DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
488
489 /* Set DAC error code to DMA error */
491
492#if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
493 hdac->ErrorCallbackCh2(hdac);
494#else
495 HAL_DACEx_ErrorCallbackCh2(hdac);
496#endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
497
499}
500#endif /* DAC_CHANNEL2_SUPPORT */
501
510#endif /* DAC */
511
512#endif /* HAL_DAC_MODULE_ENABLED */
513
HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Amplitude)
Enable or disable the selected DAC channel wave generation.
HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Amplitude)
Enable or disable the selected DAC channel wave generation.
#define IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(VALUE)
#define DAC_CHANNEL_1
#define HAL_DAC_ERROR_DMA
#define DAC_DHR12RD_ALIGNMENT(__ALIGNMENT__)
Set DHR12RD alignment.
#define __HAL_DAC_ENABLE(__HANDLE__, __DAC_Channel__)
Enable the DAC channel.
#define __HAL_DAC_DISABLE(__HANDLE__, __DAC_Channel__)
Disable the DAC channel.
@ HAL_DAC_STATE_READY
@ HAL_DAC_STATE_BUSY
#define IS_DAC_ALIGN(ALIGN)
#define IS_DAC_DATA(DATA)
#define IS_DAC_CHANNEL(CHANNEL)
#define DAC_ALIGN_8B_R
#define DAC_TRIGGER_SOFTWARE
#define assert_param(expr)
This file contains all the functions prototypes for the HAL module driver.
HAL_StatusTypeDef
HAL Status structures definition
@ HAL_ERROR
@ HAL_OK
#define UNUSED(X)
#define __HAL_UNLOCK(__HANDLE__)
#define __HAL_LOCK(__HANDLE__)
DAC handle Structure definition.
__IO HAL_DAC_StateTypeDef State
DAC_TypeDef * Instance
__IO uint32_t ErrorCode
DMA handle Structure definition.