stm32f4xx_dac.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_dac.c
  4. * @author MCD Application Team
  5. * @version V1.5.0
  6. * @date 06-March-2015
  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. * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
  101. *
  102. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  103. * You may not use this file except in compliance with the License.
  104. * You may obtain a copy of the License at:
  105. *
  106. * http://www.st.com/software_license_agreement_liberty_v2
  107. *
  108. * Unless required by applicable law or agreed to in writing, software
  109. * distributed under the License is distributed on an "AS IS" BASIS,
  110. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  111. * See the License for the specific language governing permissions and
  112. * limitations under the License.
  113. *
  114. ******************************************************************************
  115. */
  116. /* Includes ------------------------------------------------------------------*/
  117. #include "stm32f4xx_dac.h"
  118. #include "stm32f4xx_rcc.h"
  119. /** @addtogroup STM32F4xx_StdPeriph_Driver
  120. * @{
  121. */
  122. /** @defgroup DAC
  123. * @brief DAC driver modules
  124. * @{
  125. */
  126. /* Private typedef -----------------------------------------------------------*/
  127. /* Private define ------------------------------------------------------------*/
  128. /* CR register Mask */
  129. #define CR_CLEAR_MASK ((uint32_t)0x00000FFE)
  130. /* DAC Dual Channels SWTRIG masks */
  131. #define DUAL_SWTRIG_SET ((uint32_t)0x00000003)
  132. #define DUAL_SWTRIG_RESET ((uint32_t)0xFFFFFFFC)
  133. /* DHR registers offsets */
  134. #define DHR12R1_OFFSET ((uint32_t)0x00000008)
  135. #define DHR12R2_OFFSET ((uint32_t)0x00000014)
  136. #define DHR12RD_OFFSET ((uint32_t)0x00000020)
  137. /* DOR register offset */
  138. #define DOR_OFFSET ((uint32_t)0x0000002C)
  139. /* Private macro -------------------------------------------------------------*/
  140. /* Private variables ---------------------------------------------------------*/
  141. /* Private function prototypes -----------------------------------------------*/
  142. /* Private functions ---------------------------------------------------------*/
  143. /** @defgroup DAC_Private_Functions
  144. * @{
  145. */
  146. /** @defgroup DAC_Group1 DAC channels configuration
  147. * @brief DAC channels configuration: trigger, output buffer, data format
  148. *
  149. @verbatim
  150. ===============================================================================
  151. ##### DAC channels configuration: trigger, output buffer, data format #####
  152. ===============================================================================
  153. @endverbatim
  154. * @{
  155. */
  156. /**
  157. * @brief Deinitializes the DAC peripheral registers to their default reset values.
  158. * @param None
  159. * @retval None
  160. */
  161. void DAC_DeInit(void)
  162. {
  163. /* Enable DAC reset state */
  164. RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC, ENABLE);
  165. /* Release DAC from reset state */
  166. RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC, DISABLE);
  167. }
  168. /**
  169. * @brief Initializes the DAC peripheral according to the specified parameters
  170. * in the DAC_InitStruct.
  171. * @param DAC_Channel: the selected DAC channel.
  172. * This parameter can be one of the following values:
  173. * @arg DAC_Channel_1: DAC Channel1 selected
  174. * @arg DAC_Channel_2: DAC Channel2 selected
  175. * @param DAC_InitStruct: pointer to a DAC_InitTypeDef structure that contains
  176. * the configuration information for the specified DAC channel.
  177. * @retval None
  178. */
  179. void DAC_Init(uint32_t DAC_Channel, DAC_InitTypeDef* DAC_InitStruct)
  180. {
  181. uint32_t tmpreg1 = 0, tmpreg2 = 0;
  182. /* Check the DAC parameters */
  183. assert_param(IS_DAC_TRIGGER(DAC_InitStruct->DAC_Trigger));
  184. assert_param(IS_DAC_GENERATE_WAVE(DAC_InitStruct->DAC_WaveGeneration));
  185. assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(DAC_InitStruct->DAC_LFSRUnmask_TriangleAmplitude));
  186. assert_param(IS_DAC_OUTPUT_BUFFER_STATE(DAC_InitStruct->DAC_OutputBuffer));
  187. /*---------------------------- DAC CR Configuration --------------------------*/
  188. /* Get the DAC CR value */
  189. tmpreg1 = DAC->CR;
  190. /* Clear BOFFx, TENx, TSELx, WAVEx and MAMPx bits */
  191. tmpreg1 &= ~(CR_CLEAR_MASK << DAC_Channel);
  192. /* Configure for the selected DAC channel: buffer output, trigger,
  193. wave generation, mask/amplitude for wave generation */
  194. /* Set TSELx and TENx bits according to DAC_Trigger value */
  195. /* Set WAVEx bits according to DAC_WaveGeneration value */
  196. /* Set MAMPx bits according to DAC_LFSRUnmask_TriangleAmplitude value */
  197. /* Set BOFFx bit according to DAC_OutputBuffer value */
  198. tmpreg2 = (DAC_InitStruct->DAC_Trigger | DAC_InitStruct->DAC_WaveGeneration |
  199. DAC_InitStruct->DAC_LFSRUnmask_TriangleAmplitude | \
  200. DAC_InitStruct->DAC_OutputBuffer);
  201. /* Calculate CR register value depending on DAC_Channel */
  202. tmpreg1 |= tmpreg2 << DAC_Channel;
  203. /* Write to DAC CR */
  204. DAC->CR = tmpreg1;
  205. }
  206. /**
  207. * @brief Fills each DAC_InitStruct member with its default value.
  208. * @param DAC_InitStruct: pointer to a DAC_InitTypeDef structure which will
  209. * be initialized.
  210. * @retval None
  211. */
  212. void DAC_StructInit(DAC_InitTypeDef* DAC_InitStruct)
  213. {
  214. /*--------------- Reset DAC init structure parameters values -----------------*/
  215. /* Initialize the DAC_Trigger member */
  216. DAC_InitStruct->DAC_Trigger = DAC_Trigger_None;
  217. /* Initialize the DAC_WaveGeneration member */
  218. DAC_InitStruct->DAC_WaveGeneration = DAC_WaveGeneration_None;
  219. /* Initialize the DAC_LFSRUnmask_TriangleAmplitude member */
  220. DAC_InitStruct->DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bit0;
  221. /* Initialize the DAC_OutputBuffer member */
  222. DAC_InitStruct->DAC_OutputBuffer = DAC_OutputBuffer_Enable;
  223. }
  224. /**
  225. * @brief Enables or disables the specified DAC channel.
  226. * @param DAC_Channel: The selected DAC channel.
  227. * This parameter can be one of the following values:
  228. * @arg DAC_Channel_1: DAC Channel1 selected
  229. * @arg DAC_Channel_2: DAC Channel2 selected
  230. * @param NewState: new state of the DAC channel.
  231. * This parameter can be: ENABLE or DISABLE.
  232. * @note When the DAC channel is enabled the trigger source can no more be modified.
  233. * @retval None
  234. */
  235. void DAC_Cmd(uint32_t DAC_Channel, FunctionalState NewState)
  236. {
  237. /* Check the parameters */
  238. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  239. assert_param(IS_FUNCTIONAL_STATE(NewState));
  240. if (NewState != DISABLE)
  241. {
  242. /* Enable the selected DAC channel */
  243. DAC->CR |= (DAC_CR_EN1 << DAC_Channel);
  244. }
  245. else
  246. {
  247. /* Disable the selected DAC channel */
  248. DAC->CR &= (~(DAC_CR_EN1 << DAC_Channel));
  249. }
  250. }
  251. /**
  252. * @brief Enables or disables the selected DAC channel software trigger.
  253. * @param DAC_Channel: The selected DAC channel.
  254. * This parameter can be one of the following values:
  255. * @arg DAC_Channel_1: DAC Channel1 selected
  256. * @arg DAC_Channel_2: DAC Channel2 selected
  257. * @param NewState: new state of the selected DAC channel software trigger.
  258. * This parameter can be: ENABLE or DISABLE.
  259. * @retval None
  260. */
  261. void DAC_SoftwareTriggerCmd(uint32_t DAC_Channel, FunctionalState NewState)
  262. {
  263. /* Check the parameters */
  264. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  265. assert_param(IS_FUNCTIONAL_STATE(NewState));
  266. if (NewState != DISABLE)
  267. {
  268. /* Enable software trigger for the selected DAC channel */
  269. DAC->SWTRIGR |= (uint32_t)DAC_SWTRIGR_SWTRIG1 << (DAC_Channel >> 4);
  270. }
  271. else
  272. {
  273. /* Disable software trigger for the selected DAC channel */
  274. DAC->SWTRIGR &= ~((uint32_t)DAC_SWTRIGR_SWTRIG1 << (DAC_Channel >> 4));
  275. }
  276. }
  277. /**
  278. * @brief Enables or disables simultaneously the two DAC channels software triggers.
  279. * @param NewState: new state of the DAC channels software triggers.
  280. * This parameter can be: ENABLE or DISABLE.
  281. * @retval None
  282. */
  283. void DAC_DualSoftwareTriggerCmd(FunctionalState NewState)
  284. {
  285. /* Check the parameters */
  286. assert_param(IS_FUNCTIONAL_STATE(NewState));
  287. if (NewState != DISABLE)
  288. {
  289. /* Enable software trigger for both DAC channels */
  290. DAC->SWTRIGR |= DUAL_SWTRIG_SET;
  291. }
  292. else
  293. {
  294. /* Disable software trigger for both DAC channels */
  295. DAC->SWTRIGR &= DUAL_SWTRIG_RESET;
  296. }
  297. }
  298. /**
  299. * @brief Enables or disables the selected DAC channel wave generation.
  300. * @param DAC_Channel: The selected DAC channel.
  301. * This parameter can be one of the following values:
  302. * @arg DAC_Channel_1: DAC Channel1 selected
  303. * @arg DAC_Channel_2: DAC Channel2 selected
  304. * @param DAC_Wave: specifies the wave type to enable or disable.
  305. * This parameter can be one of the following values:
  306. * @arg DAC_Wave_Noise: noise wave generation
  307. * @arg DAC_Wave_Triangle: triangle wave generation
  308. * @param NewState: new state of the selected DAC channel wave generation.
  309. * This parameter can be: ENABLE or DISABLE.
  310. * @retval None
  311. */
  312. void DAC_WaveGenerationCmd(uint32_t DAC_Channel, uint32_t DAC_Wave, FunctionalState NewState)
  313. {
  314. /* Check the parameters */
  315. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  316. assert_param(IS_DAC_WAVE(DAC_Wave));
  317. assert_param(IS_FUNCTIONAL_STATE(NewState));
  318. if (NewState != DISABLE)
  319. {
  320. /* Enable the selected wave generation for the selected DAC channel */
  321. DAC->CR |= DAC_Wave << DAC_Channel;
  322. }
  323. else
  324. {
  325. /* Disable the selected wave generation for the selected DAC channel */
  326. DAC->CR &= ~(DAC_Wave << DAC_Channel);
  327. }
  328. }
  329. /**
  330. * @brief Set the specified data holding register value for DAC channel1.
  331. * @param DAC_Align: Specifies the data alignment for DAC channel1.
  332. * This parameter can be one of the following values:
  333. * @arg DAC_Align_8b_R: 8bit right data alignment selected
  334. * @arg DAC_Align_12b_L: 12bit left data alignment selected
  335. * @arg DAC_Align_12b_R: 12bit right data alignment selected
  336. * @param Data: Data to be loaded in the selected data holding register.
  337. * @retval None
  338. */
  339. void DAC_SetChannel1Data(uint32_t DAC_Align, uint16_t Data)
  340. {
  341. __IO uint32_t tmp = 0;
  342. /* Check the parameters */
  343. assert_param(IS_DAC_ALIGN(DAC_Align));
  344. assert_param(IS_DAC_DATA(Data));
  345. tmp = (uint32_t)DAC_BASE;
  346. tmp += DHR12R1_OFFSET + DAC_Align;
  347. /* Set the DAC channel1 selected data holding register */
  348. *(__IO uint32_t *) tmp = Data;
  349. }
  350. /**
  351. * @brief Set the specified data holding register value for DAC channel2.
  352. * @param DAC_Align: Specifies the data alignment for DAC channel2.
  353. * This parameter can be one of the following values:
  354. * @arg DAC_Align_8b_R: 8bit right data alignment selected
  355. * @arg DAC_Align_12b_L: 12bit left data alignment selected
  356. * @arg DAC_Align_12b_R: 12bit right data alignment selected
  357. * @param Data: Data to be loaded in the selected data holding register.
  358. * @retval None
  359. */
  360. void DAC_SetChannel2Data(uint32_t DAC_Align, uint16_t Data)
  361. {
  362. __IO uint32_t tmp = 0;
  363. /* Check the parameters */
  364. assert_param(IS_DAC_ALIGN(DAC_Align));
  365. assert_param(IS_DAC_DATA(Data));
  366. tmp = (uint32_t)DAC_BASE;
  367. tmp += DHR12R2_OFFSET + DAC_Align;
  368. /* Set the DAC channel2 selected data holding register */
  369. *(__IO uint32_t *)tmp = Data;
  370. }
  371. /**
  372. * @brief Set the specified data holding register value for dual channel DAC.
  373. * @param DAC_Align: Specifies the data alignment for dual channel DAC.
  374. * This parameter can be one of the following values:
  375. * @arg DAC_Align_8b_R: 8bit right data alignment selected
  376. * @arg DAC_Align_12b_L: 12bit left data alignment selected
  377. * @arg DAC_Align_12b_R: 12bit right data alignment selected
  378. * @param Data2: Data for DAC Channel2 to be loaded in the selected data holding register.
  379. * @param Data1: Data for DAC Channel1 to be loaded in the selected data holding register.
  380. * @note In dual mode, a unique register access is required to write in both
  381. * DAC channels at the same time.
  382. * @retval None
  383. */
  384. void DAC_SetDualChannelData(uint32_t DAC_Align, uint16_t Data2, uint16_t Data1)
  385. {
  386. uint32_t data = 0, tmp = 0;
  387. /* Check the parameters */
  388. assert_param(IS_DAC_ALIGN(DAC_Align));
  389. assert_param(IS_DAC_DATA(Data1));
  390. assert_param(IS_DAC_DATA(Data2));
  391. /* Calculate and set dual DAC data holding register value */
  392. if (DAC_Align == DAC_Align_8b_R)
  393. {
  394. data = ((uint32_t)Data2 << 8) | Data1;
  395. }
  396. else
  397. {
  398. data = ((uint32_t)Data2 << 16) | Data1;
  399. }
  400. tmp = (uint32_t)DAC_BASE;
  401. tmp += DHR12RD_OFFSET + DAC_Align;
  402. /* Set the dual DAC selected data holding register */
  403. *(__IO uint32_t *)tmp = data;
  404. }
  405. /**
  406. * @brief Returns the last data output value of the selected DAC channel.
  407. * @param DAC_Channel: The selected DAC channel.
  408. * This parameter can be one of the following values:
  409. * @arg DAC_Channel_1: DAC Channel1 selected
  410. * @arg DAC_Channel_2: DAC Channel2 selected
  411. * @retval The selected DAC channel data output value.
  412. */
  413. uint16_t DAC_GetDataOutputValue(uint32_t DAC_Channel)
  414. {
  415. __IO uint32_t tmp = 0;
  416. /* Check the parameters */
  417. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  418. tmp = (uint32_t) DAC_BASE ;
  419. tmp += DOR_OFFSET + ((uint32_t)DAC_Channel >> 2);
  420. /* Returns the DAC channel data output register value */
  421. return (uint16_t) (*(__IO uint32_t*) tmp);
  422. }
  423. /**
  424. * @}
  425. */
  426. /** @defgroup DAC_Group2 DMA management functions
  427. * @brief DMA management functions
  428. *
  429. @verbatim
  430. ===============================================================================
  431. ##### DMA management functions #####
  432. ===============================================================================
  433. @endverbatim
  434. * @{
  435. */
  436. /**
  437. * @brief Enables or disables the specified DAC channel DMA request.
  438. * @note When enabled DMA1 is generated when an external trigger (EXTI Line9,
  439. * TIM2, TIM4, TIM5, TIM6, TIM7 or TIM8 but not a software trigger) occurs.
  440. * @param DAC_Channel: The selected DAC channel.
  441. * This parameter can be one of the following values:
  442. * @arg DAC_Channel_1: DAC Channel1 selected
  443. * @arg DAC_Channel_2: DAC Channel2 selected
  444. * @param NewState: new state of the selected DAC channel DMA request.
  445. * This parameter can be: ENABLE or DISABLE.
  446. * @note The DAC channel1 is mapped on DMA1 Stream 5 channel7 which must be
  447. * already configured.
  448. * @note The DAC channel2 is mapped on DMA1 Stream 6 channel7 which must be
  449. * already configured.
  450. * @retval None
  451. */
  452. void DAC_DMACmd(uint32_t DAC_Channel, FunctionalState NewState)
  453. {
  454. /* Check the parameters */
  455. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  456. assert_param(IS_FUNCTIONAL_STATE(NewState));
  457. if (NewState != DISABLE)
  458. {
  459. /* Enable the selected DAC channel DMA request */
  460. DAC->CR |= (DAC_CR_DMAEN1 << DAC_Channel);
  461. }
  462. else
  463. {
  464. /* Disable the selected DAC channel DMA request */
  465. DAC->CR &= (~(DAC_CR_DMAEN1 << DAC_Channel));
  466. }
  467. }
  468. /**
  469. * @}
  470. */
  471. /** @defgroup DAC_Group3 Interrupts and flags management functions
  472. * @brief Interrupts and flags management functions
  473. *
  474. @verbatim
  475. ===============================================================================
  476. ##### Interrupts and flags management functions #####
  477. ===============================================================================
  478. @endverbatim
  479. * @{
  480. */
  481. /**
  482. * @brief Enables or disables the specified DAC interrupts.
  483. * @param DAC_Channel: The selected DAC channel.
  484. * This parameter can be one of the following values:
  485. * @arg DAC_Channel_1: DAC Channel1 selected
  486. * @arg DAC_Channel_2: DAC Channel2 selected
  487. * @param DAC_IT: specifies the DAC interrupt sources to be enabled or disabled.
  488. * This parameter can be the following values:
  489. * @arg DAC_IT_DMAUDR: DMA underrun interrupt mask
  490. * @note The DMA underrun occurs when a second external trigger arrives before the
  491. * acknowledgement for the first external trigger is received (first request).
  492. * @param NewState: new state of the specified DAC interrupts.
  493. * This parameter can be: ENABLE or DISABLE.
  494. * @retval None
  495. */
  496. void DAC_ITConfig(uint32_t DAC_Channel, uint32_t DAC_IT, FunctionalState NewState)
  497. {
  498. /* Check the parameters */
  499. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  500. assert_param(IS_FUNCTIONAL_STATE(NewState));
  501. assert_param(IS_DAC_IT(DAC_IT));
  502. if (NewState != DISABLE)
  503. {
  504. /* Enable the selected DAC interrupts */
  505. DAC->CR |= (DAC_IT << DAC_Channel);
  506. }
  507. else
  508. {
  509. /* Disable the selected DAC interrupts */
  510. DAC->CR &= (~(uint32_t)(DAC_IT << DAC_Channel));
  511. }
  512. }
  513. /**
  514. * @brief Checks whether the specified DAC flag is set or not.
  515. * @param DAC_Channel: The selected DAC channel.
  516. * This parameter can be one of the following values:
  517. * @arg DAC_Channel_1: DAC Channel1 selected
  518. * @arg DAC_Channel_2: DAC Channel2 selected
  519. * @param DAC_FLAG: specifies the flag to check.
  520. * This parameter can be only of the following value:
  521. * @arg DAC_FLAG_DMAUDR: DMA underrun flag
  522. * @note The DMA underrun occurs when a second external trigger arrives before the
  523. * acknowledgement for the first external trigger is received (first request).
  524. * @retval The new state of DAC_FLAG (SET or RESET).
  525. */
  526. FlagStatus DAC_GetFlagStatus(uint32_t DAC_Channel, uint32_t DAC_FLAG)
  527. {
  528. FlagStatus bitstatus = RESET;
  529. /* Check the parameters */
  530. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  531. assert_param(IS_DAC_FLAG(DAC_FLAG));
  532. /* Check the status of the specified DAC flag */
  533. if ((DAC->SR & (DAC_FLAG << DAC_Channel)) != (uint8_t)RESET)
  534. {
  535. /* DAC_FLAG is set */
  536. bitstatus = SET;
  537. }
  538. else
  539. {
  540. /* DAC_FLAG is reset */
  541. bitstatus = RESET;
  542. }
  543. /* Return the DAC_FLAG status */
  544. return bitstatus;
  545. }
  546. /**
  547. * @brief Clears the DAC channel's pending flags.
  548. * @param DAC_Channel: The selected DAC channel.
  549. * This parameter can be one of the following values:
  550. * @arg DAC_Channel_1: DAC Channel1 selected
  551. * @arg DAC_Channel_2: DAC Channel2 selected
  552. * @param DAC_FLAG: specifies the flag to clear.
  553. * This parameter can be of the following value:
  554. * @arg DAC_FLAG_DMAUDR: DMA underrun flag
  555. * @note The DMA underrun occurs when a second external trigger arrives before the
  556. * acknowledgement for the first external trigger is received (first request).
  557. * @retval None
  558. */
  559. void DAC_ClearFlag(uint32_t DAC_Channel, uint32_t DAC_FLAG)
  560. {
  561. /* Check the parameters */
  562. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  563. assert_param(IS_DAC_FLAG(DAC_FLAG));
  564. /* Clear the selected DAC flags */
  565. DAC->SR = (DAC_FLAG << DAC_Channel);
  566. }
  567. /**
  568. * @brief Checks whether the specified DAC interrupt has occurred or not.
  569. * @param DAC_Channel: The selected DAC channel.
  570. * This parameter can be one of the following values:
  571. * @arg DAC_Channel_1: DAC Channel1 selected
  572. * @arg DAC_Channel_2: DAC Channel2 selected
  573. * @param DAC_IT: specifies the DAC interrupt source to check.
  574. * This parameter can be the following values:
  575. * @arg DAC_IT_DMAUDR: DMA underrun interrupt mask
  576. * @note The DMA underrun occurs when a second external trigger arrives before the
  577. * acknowledgement for the first external trigger is received (first request).
  578. * @retval The new state of DAC_IT (SET or RESET).
  579. */
  580. ITStatus DAC_GetITStatus(uint32_t DAC_Channel, uint32_t DAC_IT)
  581. {
  582. ITStatus bitstatus = RESET;
  583. uint32_t enablestatus = 0;
  584. /* Check the parameters */
  585. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  586. assert_param(IS_DAC_IT(DAC_IT));
  587. /* Get the DAC_IT enable bit status */
  588. enablestatus = (DAC->CR & (DAC_IT << DAC_Channel)) ;
  589. /* Check the status of the specified DAC interrupt */
  590. if (((DAC->SR & (DAC_IT << DAC_Channel)) != (uint32_t)RESET) && enablestatus)
  591. {
  592. /* DAC_IT is set */
  593. bitstatus = SET;
  594. }
  595. else
  596. {
  597. /* DAC_IT is reset */
  598. bitstatus = RESET;
  599. }
  600. /* Return the DAC_IT status */
  601. return bitstatus;
  602. }
  603. /**
  604. * @brief Clears the DAC channel's interrupt pending bits.
  605. * @param DAC_Channel: The selected DAC channel.
  606. * This parameter can be one of the following values:
  607. * @arg DAC_Channel_1: DAC Channel1 selected
  608. * @arg DAC_Channel_2: DAC Channel2 selected
  609. * @param DAC_IT: specifies the DAC interrupt pending bit to clear.
  610. * This parameter can be the following values:
  611. * @arg DAC_IT_DMAUDR: DMA underrun interrupt mask
  612. * @note The DMA underrun occurs when a second external trigger arrives before the
  613. * acknowledgement for the first external trigger is received (first request).
  614. * @retval None
  615. */
  616. void DAC_ClearITPendingBit(uint32_t DAC_Channel, uint32_t DAC_IT)
  617. {
  618. /* Check the parameters */
  619. assert_param(IS_DAC_CHANNEL(DAC_Channel));
  620. assert_param(IS_DAC_IT(DAC_IT));
  621. /* Clear the selected DAC interrupt pending bits */
  622. DAC->SR = (DAC_IT << DAC_Channel);
  623. }
  624. /**
  625. * @}
  626. */
  627. /**
  628. * @}
  629. */
  630. /**
  631. * @}
  632. */
  633. /**
  634. * @}
  635. */
  636. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/