stm32f4xx_dac.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_dac.c
  4. * @author MCD Application Team
  5. * @version V1.8.1
  6. * @date 27-January-2022
  7. * @brief This file provides firmware functions to manage the following
  8. * functionalities of the Digital-to-Analog Converter (DAC) peripheral:
  9. * + DAC channels configuration: trigger, output buffer, data format
  10. * + DMA management
  11. * + Interrupts and flags management
  12. *
  13. @verbatim
  14. ===============================================================================
  15. ##### DAC Peripheral features #####
  16. ===============================================================================
  17. [..]
  18. *** DAC Channels ***
  19. ====================
  20. [..]
  21. The device integrates two 12-bit Digital Analog Converters that can
  22. be used independently or simultaneously (dual mode):
  23. (#) DAC channel1 with DAC_OUT1 (PA4) as output
  24. (#) DAC channel2 with DAC_OUT2 (PA5) as output
  25. *** DAC Triggers ***
  26. ====================
  27. [..]
  28. Digital to Analog conversion can be non-triggered using DAC_Trigger_None
  29. and DAC_OUT1/DAC_OUT2 is available once writing to DHRx register
  30. using DAC_SetChannel1Data() / DAC_SetChannel2Data() functions.
  31. [..]
  32. Digital to Analog conversion can be triggered by:
  33. (#) External event: EXTI Line 9 (any GPIOx_Pin9) using DAC_Trigger_Ext_IT9.
  34. The used pin (GPIOx_Pin9) must be configured in input mode.
  35. (#) Timers TRGO: TIM2, TIM4, TIM5, TIM6, TIM7 and TIM8
  36. (DAC_Trigger_T2_TRGO, DAC_Trigger_T4_TRGO...)
  37. The timer TRGO event should be selected using TIM_SelectOutputTrigger()
  38. (#) Software using DAC_Trigger_Software
  39. *** DAC Buffer mode feature ***
  40. ===============================
  41. [..]
  42. Each DAC channel integrates an output buffer that can be used to
  43. reduce the output impedance, and to drive external loads directly
  44. without having to add an external operational amplifier.
  45. To enable, the output buffer use
  46. DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
  47. [..]
  48. (@) Refer to the device datasheet for more details about output
  49. impedance value with and without output buffer.
  50. *** DAC wave generation feature ***
  51. ===================================
  52. [..]
  53. Both DAC channels can be used to generate
  54. (#) Noise wave using DAC_WaveGeneration_Noise
  55. (#) Triangle wave using DAC_WaveGeneration_Triangle
  56. -@- Wave generation can be disabled using DAC_WaveGeneration_None
  57. *** DAC data format ***
  58. =======================
  59. [..]
  60. The DAC data format can be:
  61. (#) 8-bit right alignment using DAC_Align_8b_R
  62. (#) 12-bit left alignment using DAC_Align_12b_L
  63. (#) 12-bit right alignment using DAC_Align_12b_R
  64. *** DAC data value to voltage correspondence ***
  65. ================================================
  66. [..]
  67. The analog output voltage on each DAC channel pin is determined
  68. by the following equation:
  69. DAC_OUTx = VREF+ * DOR / 4095
  70. with DOR is the Data Output Register
  71. VEF+ is the input voltage reference (refer to the device datasheet)
  72. e.g. To set DAC_OUT1 to 0.7V, use
  73. DAC_SetChannel1Data(DAC_Align_12b_R, 868);
  74. Assuming that VREF+ = 3.3V, DAC_OUT1 = (3.3 * 868) / 4095 = 0.7V
  75. *** DMA requests ***
  76. =====================
  77. [..]
  78. A DMA1 request can be generated when an external trigger (but not
  79. a software trigger) occurs if DMA1 requests are enabled using
  80. DAC_DMACmd()
  81. [..]
  82. DMA1 requests are mapped as following:
  83. (#) DAC channel1 : mapped on DMA1 Stream5 channel7 which must be
  84. already configured
  85. (#) DAC channel2 : mapped on DMA1 Stream6 channel7 which must be
  86. already configured
  87. ##### How to use this driver #####
  88. ===============================================================================
  89. [..]
  90. (+) DAC APB clock must be enabled to get write access to DAC
  91. registers using
  92. RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE)
  93. (+) Configure DAC_OUTx (DAC_OUT1: PA4, DAC_OUT2: PA5) in analog mode.
  94. (+) Configure the DAC channel using DAC_Init() function
  95. (+) Enable the DAC channel using DAC_Cmd() function
  96. @endverbatim
  97. ******************************************************************************
  98. * @attention
  99. *
  100. * Copyright (c) 2016 STMicroelectronics.
  101. * All rights reserved.
  102. *
  103. * This software is licensed under terms that can be found in the LICENSE file
  104. * in the root directory of this software component.
  105. * If no LICENSE file comes with this software, it is provided AS-IS.
  106. *
  107. ******************************************************************************
  108. */
  109. /* Includes ------------------------------------------------------------------*/
  110. #include "stm32f4xx_dac.h"
  111. #include "stm32f4xx_rcc.h"
  112. /** @addtogroup STM32F4xx_StdPeriph_Driver
  113. * @{
  114. */
  115. /** @defgroup DAC
  116. * @brief DAC driver modules
  117. * @{
  118. */
  119. /* Private typedef -----------------------------------------------------------*/
  120. /* Private define ------------------------------------------------------------*/
  121. /* CR register Mask */
  122. #define CR_CLEAR_MASK ((uint32_t)0x00000FFE)
  123. /* DAC Dual Channels SWTRIG masks */
  124. #define DUAL_SWTRIG_SET ((uint32_t)0x00000003)
  125. #define DUAL_SWTRIG_RESET ((uint32_t)0xFFFFFFFC)
  126. /* DHR registers offsets */
  127. #define DHR12R1_OFFSET ((uint32_t)0x00000008)
  128. #define DHR12R2_OFFSET ((uint32_t)0x00000014)
  129. #define DHR12RD_OFFSET ((uint32_t)0x00000020)
  130. /* DOR register offset */
  131. #define DOR_OFFSET ((uint32_t)0x0000002C)
  132. /* Private macro -------------------------------------------------------------*/
  133. /* Private variables ---------------------------------------------------------*/
  134. /* Private function prototypes -----------------------------------------------*/
  135. /* Private functions ---------------------------------------------------------*/
  136. /** @defgroup DAC_Private_Functions
  137. * @{
  138. */
  139. /** @defgroup DAC_Group1 DAC channels configuration
  140. * @brief DAC channels configuration: trigger, output buffer, data format
  141. *
  142. @verbatim
  143. ===============================================================================
  144. ##### DAC channels configuration: trigger, output buffer, data format #####
  145. ===============================================================================
  146. @endverbatim
  147. * @{
  148. */
  149. /**
  150. * @brief Deinitializes the DAC peripheral registers to their default reset values.
  151. * @param None
  152. * @retval None
  153. */
  154. void DAC_DeInit(void)
  155. {
  156. /* Enable DAC reset state */
  157. RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC, ENABLE);
  158. /* Release DAC from reset state */
  159. RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC, DISABLE);
  160. }
  161. /**
  162. * @brief Initializes the DAC peripheral according to the specified parameters
  163. * in the DAC_InitStruct.
  164. * @param DAC_Channel: the selected DAC channel.
  165. * This parameter can be one of the following values:
  166. * @arg DAC_Channel_1: DAC Channel1 selected
  167. * @arg DAC_Channel_2: DAC Channel2 selected
  168. * @param DAC_InitStruct: pointer to a DAC_InitTypeDef structure that contains
  169. * the configuration information for the specified DAC channel.
  170. * @retval None
  171. */
  172. void DAC_Init(uint32_t DAC_Channel, DAC_InitTypeDef* DAC_InitStruct)
  173. {
  174. uint32_t tmpreg1 = 0, tmpreg2 = 0;
  175. /* Check the DAC parameters */
  176. assert_param(IS_DAC_TRIGGER(DAC_InitStruct->DAC_Trigger));
  177. assert_param(IS_DAC_GENERATE_WAVE(DAC_InitStruct->DAC_WaveGeneration));
  178. assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(DAC_InitStruct->DAC_LFSRUnmask_TriangleAmplitude));
  179. assert_param(IS_DAC_OUTPUT_BUFFER_STATE(DAC_InitStruct->DAC_OutputBuffer));
  180. /*---------------------------- DAC CR Configuration --------------------------*/
  181. /* Get the DAC CR value */
  182. tmpreg1 = DAC->CR;
  183. /* Clear BOFFx, TENx, TSELx, WAVEx and MAMPx bits */
  184. tmpreg1 &= ~(CR_CLEAR_MASK << DAC_Channel);
  185. /* Configure for the selected DAC channel: buffer output, trigger,
  186. wave generation, mask/amplitude for wave generation */
  187. /* Set TSELx and TENx bits according to DAC_Trigger value */
  188. /* Set WAVEx bits according to DAC_WaveGeneration value */
  189. /* Set MAMPx bits according to DAC_LFSRUnmask_TriangleAmplitude value */
  190. /* Set BOFFx bit according to DAC_OutputBuffer value */
  191. tmpreg2 = (DAC_InitStruct->DAC_Trigger | DAC_InitStruct->DAC_WaveGeneration |
  192. DAC_InitStruct->DAC_LFSRUnmask_TriangleAmplitude | \
  193. DAC_InitStruct->DAC_OutputBuffer);
  194. /* Calculate CR register value depending on DAC_Channel */
  195. tmpreg1 |= tmpreg2 << DAC_Channel;
  196. /* Write to DAC CR */
  197. DAC->CR = tmpreg1;
  198. }
  199. /**
  200. * @brief Fills each DAC_InitStruct member with its default value.
  201. * @param DAC_InitStruct: pointer to a DAC_InitTypeDef structure which will
  202. * be initialized.
  203. * @retval None
  204. */
  205. void DAC_StructInit(DAC_InitTypeDef* DAC_InitStruct)
  206. {
  207. /*--------------- Reset DAC init structure parameters values -----------------*/
  208. /* Initialize the DAC_Trigger member */
  209. DAC_InitStruct->DAC_Trigger = DAC_Trigger_None;
  210. /* Initialize the DAC_WaveGeneration member */
  211. DAC_InitStruct->DAC_WaveGeneration = DAC_WaveGeneration_None;
  212. /* Initialize the DAC_LFSRUnmask_TriangleAmplitude member */
  213. DAC_InitStruct->DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bit0;
  214. /* Initialize the DAC_OutputBuffer member */
  215. DAC_InitStruct->DAC_OutputBuffer = DAC_OutputBuffer_Enable;
  216. }
  217. /**
  218. * @brief Enables or disables the specified DAC channel.
  219. * @param DAC_Channel: The selected DAC channel.
  220. * This parameter can be one of the following values:
  221. * @arg DAC_Channel_1: DAC Channel1 selected
  222. * @arg DAC_Channel_2: DAC Channel2 selected
  223. * @param NewState: new state of the DAC channel.
  224. * This parameter can be: ENABLE or DISABLE.
  225. * @note When the DAC channel is enabled the trigger source can no more be modified.
  226. * @retval None
  227. */
  228. void DAC_Cmd(uint32_t DAC_Channel, FunctionalState NewState)
  229. {
  230. /* Check the parameters */
  231. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  232. assert_param(IS_FUNCTIONAL_STATE(NewState));
  233. if (NewState != DISABLE)
  234. {
  235. /* Enable the selected DAC channel */
  236. DAC->CR |= (DAC_CR_EN1 << DAC_Channel);
  237. }
  238. else
  239. {
  240. /* Disable the selected DAC channel */
  241. DAC->CR &= (~(DAC_CR_EN1 << DAC_Channel));
  242. }
  243. }
  244. /**
  245. * @brief Enables or disables the selected DAC channel software trigger.
  246. * @param DAC_Channel: The selected DAC channel.
  247. * This parameter can be one of the following values:
  248. * @arg DAC_Channel_1: DAC Channel1 selected
  249. * @arg DAC_Channel_2: DAC Channel2 selected
  250. * @param NewState: new state of the selected DAC channel software trigger.
  251. * This parameter can be: ENABLE or DISABLE.
  252. * @retval None
  253. */
  254. void DAC_SoftwareTriggerCmd(uint32_t DAC_Channel, FunctionalState NewState)
  255. {
  256. /* Check the parameters */
  257. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  258. assert_param(IS_FUNCTIONAL_STATE(NewState));
  259. if (NewState != DISABLE)
  260. {
  261. /* Enable software trigger for the selected DAC channel */
  262. DAC->SWTRIGR |= (uint32_t)DAC_SWTRIGR_SWTRIG1 << (DAC_Channel >> 4);
  263. }
  264. else
  265. {
  266. /* Disable software trigger for the selected DAC channel */
  267. DAC->SWTRIGR &= ~((uint32_t)DAC_SWTRIGR_SWTRIG1 << (DAC_Channel >> 4));
  268. }
  269. }
  270. /**
  271. * @brief Enables or disables simultaneously the two DAC channels software triggers.
  272. * @param NewState: new state of the DAC channels software triggers.
  273. * This parameter can be: ENABLE or DISABLE.
  274. * @retval None
  275. */
  276. void DAC_DualSoftwareTriggerCmd(FunctionalState NewState)
  277. {
  278. /* Check the parameters */
  279. assert_param(IS_FUNCTIONAL_STATE(NewState));
  280. if (NewState != DISABLE)
  281. {
  282. /* Enable software trigger for both DAC channels */
  283. DAC->SWTRIGR |= DUAL_SWTRIG_SET;
  284. }
  285. else
  286. {
  287. /* Disable software trigger for both DAC channels */
  288. DAC->SWTRIGR &= DUAL_SWTRIG_RESET;
  289. }
  290. }
  291. /**
  292. * @brief Enables or disables the selected DAC channel wave generation.
  293. * @param DAC_Channel: The selected DAC channel.
  294. * This parameter can be one of the following values:
  295. * @arg DAC_Channel_1: DAC Channel1 selected
  296. * @arg DAC_Channel_2: DAC Channel2 selected
  297. * @param DAC_Wave: specifies the wave type to enable or disable.
  298. * This parameter can be one of the following values:
  299. * @arg DAC_Wave_Noise: noise wave generation
  300. * @arg DAC_Wave_Triangle: triangle wave generation
  301. * @param NewState: new state of the selected DAC channel wave generation.
  302. * This parameter can be: ENABLE or DISABLE.
  303. * @retval None
  304. */
  305. void DAC_WaveGenerationCmd(uint32_t DAC_Channel, uint32_t DAC_Wave, FunctionalState NewState)
  306. {
  307. /* Check the parameters */
  308. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  309. assert_param(IS_DAC_WAVE(DAC_Wave));
  310. assert_param(IS_FUNCTIONAL_STATE(NewState));
  311. if (NewState != DISABLE)
  312. {
  313. /* Enable the selected wave generation for the selected DAC channel */
  314. DAC->CR |= DAC_Wave << DAC_Channel;
  315. }
  316. else
  317. {
  318. /* Disable the selected wave generation for the selected DAC channel */
  319. DAC->CR &= ~(DAC_Wave << DAC_Channel);
  320. }
  321. }
  322. /**
  323. * @brief Set the specified data holding register value for DAC channel1.
  324. * @param DAC_Align: Specifies the data alignment for DAC channel1.
  325. * This parameter can be one of the following values:
  326. * @arg DAC_Align_8b_R: 8bit right data alignment selected
  327. * @arg DAC_Align_12b_L: 12bit left data alignment selected
  328. * @arg DAC_Align_12b_R: 12bit right data alignment selected
  329. * @param Data: Data to be loaded in the selected data holding register.
  330. * @retval None
  331. */
  332. void DAC_SetChannel1Data(uint32_t DAC_Align, uint16_t Data)
  333. {
  334. __IO uint32_t tmp = 0;
  335. /* Check the parameters */
  336. assert_param(IS_DAC_ALIGN(DAC_Align));
  337. assert_param(IS_DAC_DATA(Data));
  338. tmp = (uint32_t)DAC_BASE;
  339. tmp += DHR12R1_OFFSET + DAC_Align;
  340. /* Set the DAC channel1 selected data holding register */
  341. *(__IO uint32_t *) tmp = Data;
  342. }
  343. /**
  344. * @brief Set the specified data holding register value for DAC channel2.
  345. * @param DAC_Align: Specifies the data alignment for DAC channel2.
  346. * This parameter can be one of the following values:
  347. * @arg DAC_Align_8b_R: 8bit right data alignment selected
  348. * @arg DAC_Align_12b_L: 12bit left data alignment selected
  349. * @arg DAC_Align_12b_R: 12bit right data alignment selected
  350. * @param Data: Data to be loaded in the selected data holding register.
  351. * @retval None
  352. */
  353. void DAC_SetChannel2Data(uint32_t DAC_Align, uint16_t Data)
  354. {
  355. __IO uint32_t tmp = 0;
  356. /* Check the parameters */
  357. assert_param(IS_DAC_ALIGN(DAC_Align));
  358. assert_param(IS_DAC_DATA(Data));
  359. tmp = (uint32_t)DAC_BASE;
  360. tmp += DHR12R2_OFFSET + DAC_Align;
  361. /* Set the DAC channel2 selected data holding register */
  362. *(__IO uint32_t *)tmp = Data;
  363. }
  364. /**
  365. * @brief Set the specified data holding register value for dual channel DAC.
  366. * @param DAC_Align: Specifies the data alignment for dual channel DAC.
  367. * This parameter can be one of the following values:
  368. * @arg DAC_Align_8b_R: 8bit right data alignment selected
  369. * @arg DAC_Align_12b_L: 12bit left data alignment selected
  370. * @arg DAC_Align_12b_R: 12bit right data alignment selected
  371. * @param Data2: Data for DAC Channel2 to be loaded in the selected data holding register.
  372. * @param Data1: Data for DAC Channel1 to be loaded in the selected data holding register.
  373. * @note In dual mode, a unique register access is required to write in both
  374. * DAC channels at the same time.
  375. * @retval None
  376. */
  377. void DAC_SetDualChannelData(uint32_t DAC_Align, uint16_t Data2, uint16_t Data1)
  378. {
  379. uint32_t data = 0, tmp = 0;
  380. /* Check the parameters */
  381. assert_param(IS_DAC_ALIGN(DAC_Align));
  382. assert_param(IS_DAC_DATA(Data1));
  383. assert_param(IS_DAC_DATA(Data2));
  384. /* Calculate and set dual DAC data holding register value */
  385. if (DAC_Align == DAC_Align_8b_R)
  386. {
  387. data = ((uint32_t)Data2 << 8) | Data1;
  388. }
  389. else
  390. {
  391. data = ((uint32_t)Data2 << 16) | Data1;
  392. }
  393. tmp = (uint32_t)DAC_BASE;
  394. tmp += DHR12RD_OFFSET + DAC_Align;
  395. /* Set the dual DAC selected data holding register */
  396. *(__IO uint32_t *)tmp = data;
  397. }
  398. /**
  399. * @brief Returns the last data output value of the selected DAC channel.
  400. * @param DAC_Channel: The selected DAC channel.
  401. * This parameter can be one of the following values:
  402. * @arg DAC_Channel_1: DAC Channel1 selected
  403. * @arg DAC_Channel_2: DAC Channel2 selected
  404. * @retval The selected DAC channel data output value.
  405. */
  406. uint16_t DAC_GetDataOutputValue(uint32_t DAC_Channel)
  407. {
  408. __IO uint32_t tmp = 0;
  409. /* Check the parameters */
  410. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  411. tmp = (uint32_t) DAC_BASE ;
  412. tmp += DOR_OFFSET + ((uint32_t)DAC_Channel >> 2);
  413. /* Returns the DAC channel data output register value */
  414. return (uint16_t) (*(__IO uint32_t*) tmp);
  415. }
  416. /**
  417. * @}
  418. */
  419. /** @defgroup DAC_Group2 DMA management functions
  420. * @brief DMA management functions
  421. *
  422. @verbatim
  423. ===============================================================================
  424. ##### DMA management functions #####
  425. ===============================================================================
  426. @endverbatim
  427. * @{
  428. */
  429. /**
  430. * @brief Enables or disables the specified DAC channel DMA request.
  431. * @note When enabled DMA1 is generated when an external trigger (EXTI Line9,
  432. * TIM2, TIM4, TIM5, TIM6, TIM7 or TIM8 but not a software trigger) occurs.
  433. * @param DAC_Channel: The selected DAC channel.
  434. * This parameter can be one of the following values:
  435. * @arg DAC_Channel_1: DAC Channel1 selected
  436. * @arg DAC_Channel_2: DAC Channel2 selected
  437. * @param NewState: new state of the selected DAC channel DMA request.
  438. * This parameter can be: ENABLE or DISABLE.
  439. * @note The DAC channel1 is mapped on DMA1 Stream 5 channel7 which must be
  440. * already configured.
  441. * @note The DAC channel2 is mapped on DMA1 Stream 6 channel7 which must be
  442. * already configured.
  443. * @retval None
  444. */
  445. void DAC_DMACmd(uint32_t DAC_Channel, FunctionalState NewState)
  446. {
  447. /* Check the parameters */
  448. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  449. assert_param(IS_FUNCTIONAL_STATE(NewState));
  450. if (NewState != DISABLE)
  451. {
  452. /* Enable the selected DAC channel DMA request */
  453. DAC->CR |= (DAC_CR_DMAEN1 << DAC_Channel);
  454. }
  455. else
  456. {
  457. /* Disable the selected DAC channel DMA request */
  458. DAC->CR &= (~(DAC_CR_DMAEN1 << DAC_Channel));
  459. }
  460. }
  461. /**
  462. * @}
  463. */
  464. /** @defgroup DAC_Group3 Interrupts and flags management functions
  465. * @brief Interrupts and flags management functions
  466. *
  467. @verbatim
  468. ===============================================================================
  469. ##### Interrupts and flags management functions #####
  470. ===============================================================================
  471. @endverbatim
  472. * @{
  473. */
  474. /**
  475. * @brief Enables or disables the specified DAC interrupts.
  476. * @param DAC_Channel: The selected DAC channel.
  477. * This parameter can be one of the following values:
  478. * @arg DAC_Channel_1: DAC Channel1 selected
  479. * @arg DAC_Channel_2: DAC Channel2 selected
  480. * @param DAC_IT: specifies the DAC interrupt sources to be enabled or disabled.
  481. * This parameter can be the following values:
  482. * @arg DAC_IT_DMAUDR: DMA underrun interrupt mask
  483. * @note The DMA underrun occurs when a second external trigger arrives before the
  484. * acknowledgement for the first external trigger is received (first request).
  485. * @param NewState: new state of the specified DAC interrupts.
  486. * This parameter can be: ENABLE or DISABLE.
  487. * @retval None
  488. */
  489. void DAC_ITConfig(uint32_t DAC_Channel, uint32_t DAC_IT, FunctionalState NewState)
  490. {
  491. /* Check the parameters */
  492. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  493. assert_param(IS_FUNCTIONAL_STATE(NewState));
  494. assert_param(IS_DAC_IT(DAC_IT));
  495. if (NewState != DISABLE)
  496. {
  497. /* Enable the selected DAC interrupts */
  498. DAC->CR |= (DAC_IT << DAC_Channel);
  499. }
  500. else
  501. {
  502. /* Disable the selected DAC interrupts */
  503. DAC->CR &= (~(uint32_t)(DAC_IT << DAC_Channel));
  504. }
  505. }
  506. /**
  507. * @brief Checks whether the specified DAC flag is set or not.
  508. * @param DAC_Channel: The selected DAC channel.
  509. * This parameter can be one of the following values:
  510. * @arg DAC_Channel_1: DAC Channel1 selected
  511. * @arg DAC_Channel_2: DAC Channel2 selected
  512. * @param DAC_FLAG: specifies the flag to check.
  513. * This parameter can be only of the following value:
  514. * @arg DAC_FLAG_DMAUDR: DMA underrun flag
  515. * @note The DMA underrun occurs when a second external trigger arrives before the
  516. * acknowledgement for the first external trigger is received (first request).
  517. * @retval The new state of DAC_FLAG (SET or RESET).
  518. */
  519. FlagStatus DAC_GetFlagStatus(uint32_t DAC_Channel, uint32_t DAC_FLAG)
  520. {
  521. FlagStatus bitstatus = RESET;
  522. /* Check the parameters */
  523. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  524. assert_param(IS_DAC_FLAG(DAC_FLAG));
  525. /* Check the status of the specified DAC flag */
  526. if ((DAC->SR & (DAC_FLAG << DAC_Channel)) != (uint8_t)RESET)
  527. {
  528. /* DAC_FLAG is set */
  529. bitstatus = SET;
  530. }
  531. else
  532. {
  533. /* DAC_FLAG is reset */
  534. bitstatus = RESET;
  535. }
  536. /* Return the DAC_FLAG status */
  537. return bitstatus;
  538. }
  539. /**
  540. * @brief Clears the DAC channel's pending flags.
  541. * @param DAC_Channel: The selected DAC channel.
  542. * This parameter can be one of the following values:
  543. * @arg DAC_Channel_1: DAC Channel1 selected
  544. * @arg DAC_Channel_2: DAC Channel2 selected
  545. * @param DAC_FLAG: specifies the flag to clear.
  546. * This parameter can be of the following value:
  547. * @arg DAC_FLAG_DMAUDR: DMA underrun flag
  548. * @note The DMA underrun occurs when a second external trigger arrives before the
  549. * acknowledgement for the first external trigger is received (first request).
  550. * @retval None
  551. */
  552. void DAC_ClearFlag(uint32_t DAC_Channel, uint32_t DAC_FLAG)
  553. {
  554. /* Check the parameters */
  555. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  556. assert_param(IS_DAC_FLAG(DAC_FLAG));
  557. /* Clear the selected DAC flags */
  558. DAC->SR = (DAC_FLAG << DAC_Channel);
  559. }
  560. /**
  561. * @brief Checks whether the specified DAC interrupt has occurred or not.
  562. * @param DAC_Channel: The selected DAC channel.
  563. * This parameter can be one of the following values:
  564. * @arg DAC_Channel_1: DAC Channel1 selected
  565. * @arg DAC_Channel_2: DAC Channel2 selected
  566. * @param DAC_IT: specifies the DAC interrupt source to check.
  567. * This parameter can be the following values:
  568. * @arg DAC_IT_DMAUDR: DMA underrun interrupt mask
  569. * @note The DMA underrun occurs when a second external trigger arrives before the
  570. * acknowledgement for the first external trigger is received (first request).
  571. * @retval The new state of DAC_IT (SET or RESET).
  572. */
  573. ITStatus DAC_GetITStatus(uint32_t DAC_Channel, uint32_t DAC_IT)
  574. {
  575. ITStatus bitstatus = RESET;
  576. uint32_t enablestatus = 0;
  577. /* Check the parameters */
  578. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  579. assert_param(IS_DAC_IT(DAC_IT));
  580. /* Get the DAC_IT enable bit status */
  581. enablestatus = (DAC->CR & (DAC_IT << DAC_Channel)) ;
  582. /* Check the status of the specified DAC interrupt */
  583. if (((DAC->SR & (DAC_IT << DAC_Channel)) != (uint32_t)RESET) && enablestatus)
  584. {
  585. /* DAC_IT is set */
  586. bitstatus = SET;
  587. }
  588. else
  589. {
  590. /* DAC_IT is reset */
  591. bitstatus = RESET;
  592. }
  593. /* Return the DAC_IT status */
  594. return bitstatus;
  595. }
  596. /**
  597. * @brief Clears the DAC channel's interrupt pending bits.
  598. * @param DAC_Channel: The selected DAC channel.
  599. * This parameter can be one of the following values:
  600. * @arg DAC_Channel_1: DAC Channel1 selected
  601. * @arg DAC_Channel_2: DAC Channel2 selected
  602. * @param DAC_IT: specifies the DAC interrupt pending bit to clear.
  603. * This parameter can be the following values:
  604. * @arg DAC_IT_DMAUDR: DMA underrun interrupt mask
  605. * @note The DMA underrun occurs when a second external trigger arrives before the
  606. * acknowledgement for the first external trigger is received (first request).
  607. * @retval None
  608. */
  609. void DAC_ClearITPendingBit(uint32_t DAC_Channel, uint32_t DAC_IT)
  610. {
  611. /* Check the parameters */
  612. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  613. assert_param(IS_DAC_IT(DAC_IT));
  614. /* Clear the selected DAC interrupt pending bits */
  615. DAC->SR = (DAC_IT << DAC_Channel);
  616. }
  617. /**
  618. * @}
  619. */
  620. /**
  621. * @}
  622. */
  623. /**
  624. * @}
  625. */
  626. /**
  627. * @}
  628. */