STM32F4xx_HAL_Driver  1.8.3
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)
91 HAL_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 */
106  hdac->State = HAL_DAC_STATE_BUSY;
107 
108  /* Enable the Peripheral */
109  __HAL_DAC_ENABLE(hdac, DAC_CHANNEL_1);
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 */
125  hdac->State = HAL_DAC_STATE_READY;
126 
127  /* Process unlocked */
128  __HAL_UNLOCK(hdac);
129 
130  /* Return function status */
131  return HAL_OK;
132 }
133 
140 HAL_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 */
150  __HAL_DAC_DISABLE(hdac, DAC_CHANNEL_1);
151  __HAL_DAC_DISABLE(hdac, DAC_CHANNEL_2);
152 
153  /* Change DAC state */
154  hdac->State = HAL_DAC_STATE_READY;
155 
156  /* Return function status */
157  return HAL_OK;
158 }
159 #endif /* DAC_CHANNEL2_SUPPORT */
160 
185 HAL_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 */
194  assert_param(IS_DAC_CHANNEL(Channel));
195  assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude));
196 
197  /* Process locked */
198  __HAL_LOCK(hdac);
199 
200  /* Change DAC state */
201  hdac->State = HAL_DAC_STATE_BUSY;
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 */
208  hdac->State = HAL_DAC_STATE_READY;
209 
210  /* Process unlocked */
211  __HAL_UNLOCK(hdac);
212 
213  /* Return function status */
214  return HAL_OK;
215 }
216 
241 HAL_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 */
250  assert_param(IS_DAC_CHANNEL(Channel));
251  assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude));
252 
253  /* Process locked */
254  __HAL_LOCK(hdac);
255 
256  /* Change DAC state */
257  hdac->State = HAL_DAC_STATE_BUSY;
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 */
264  hdac->State = HAL_DAC_STATE_READY;
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)
289 HAL_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));
302  assert_param(IS_DAC_DATA(Data1));
303  assert_param(IS_DAC_DATA(Data2));
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 
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 
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 
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 
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)
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)
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
457 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
458 
459  hdac->State = HAL_DAC_STATE_READY;
460 }
461 
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
476 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
477 }
478 
486 {
487  DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
488 
489  /* Set DAC error code to DMA error */
490  hdac->ErrorCode |= HAL_DAC_ERROR_DMA;
491 
492 #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1)
493  hdac->ErrorCallbackCh2(hdac);
494 #else
496 #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */
497 
498  hdac->State = HAL_DAC_STATE_READY;
499 }
500 #endif /* DAC_CHANNEL2_SUPPORT */
501 
510 #endif /* DAC */
511 
512 #endif /* HAL_DAC_MODULE_ENABLED */
513 
HAL_StatusTypeDef HAL_DACEx_DualStart(DAC_HandleTypeDef *hdac)
Enables DAC and starts conversion of both channels.
HAL_StatusTypeDef HAL_DACEx_DualStop(DAC_HandleTypeDef *hdac)
Disables DAC and stop conversion of both channels.
void HAL_DACEx_ErrorCallbackCh2(DAC_HandleTypeDef *hdac)
Error DAC callback for Channel2.
HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Amplitude)
Enable or disable the selected DAC channel wave generation.
void HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef *hdac)
Conversion half DMA transfer callback in non-blocking mode for Channel2.
void HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef *hdac)
Conversion complete callback in non-blocking mode for Channel2.
void HAL_DACEx_DMAUnderrunCallbackCh2(DAC_HandleTypeDef *hdac)
DMA underrun DAC callback for Channel2.
HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef *hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2)
Set the specified data holding register value for dual DAC channel.
HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Amplitude)
Enable or disable the selected DAC channel wave generation.
uint32_t HAL_DACEx_DualGetValue(const DAC_HandleTypeDef *hdac)
Return the last data output value of the selected DAC channel.
void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma)
DMA half transfer complete callback.
void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma)
DMA conversion complete callback.
void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma)
DMA error callback.
struct __DAC_HandleTypeDef else typedef struct endif DAC_HandleTypeDef
DAC handle Structure definition.
@ HAL_DAC_STATE_READY
@ HAL_DAC_STATE_BUSY
This file contains all the functions prototypes for the HAL module driver.
DMA handle Structure definition.