You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

633 lines
22 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_hal_dac_ex.c
  4. * @author MCD Application Team
  5. * @version V1.2.0
  6. * @date 29-December-2017
  7. * @brief Extended DAC HAL module driver.
  8. * This file provides firmware functions to manage the extended
  9. * functionalities of DAC peripheral.
  10. *
  11. *
  12. @verbatim
  13. ==============================================================================
  14. ##### How to use this driver #####
  15. ==============================================================================
  16. [..]
  17. (+) When Dual mode is enabled (i.e DAC Channel1 and Channel2 are used simultaneously) :
  18. Use HAL_DACEx_DualGetValue() to get digital data to be converted and use
  19. HAL_DACEx_DualSetValue() to set digital value to converted simultaneously in Channel 1 and Channel 2.
  20. (+) Use HAL_DACEx_TriangleWaveGenerate() to generate Triangle signal.
  21. (+) Use HAL_DACEx_NoiseWaveGenerate() to generate Noise signal.
  22. (+) HAL_DACEx_SelfCalibrate to calibrate one DAC channel.
  23. (+) HAL_DACEx_SetUserTrimming to set user trimming value.
  24. (+) HAL_DACEx_GetTrimOffset to retrieve trimming value (factory setting
  25. after reset, user setting if HAL_DACEx_SetUserTrimming have been used
  26. at least one time after reset).
  27. @endverbatim
  28. ******************************************************************************
  29. * @attention
  30. *
  31. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  32. *
  33. * Redistribution and use in source and binary forms, with or without modification,
  34. * are permitted provided that the following conditions are met:
  35. * 1. Redistributions of source code must retain the above copyright notice,
  36. * this list of conditions and the following disclaimer.
  37. * 2. Redistributions in binary form must reproduce the above copyright notice,
  38. * this list of conditions and the following disclaimer in the documentation
  39. * and/or other materials provided with the distribution.
  40. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  41. * may be used to endorse or promote products derived from this software
  42. * without specific prior written permission.
  43. *
  44. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  45. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  46. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  47. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  48. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  49. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  50. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  51. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  52. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  53. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  54. *
  55. ******************************************************************************
  56. */
  57. /* Includes ------------------------------------------------------------------*/
  58. #include "stm32h7xx_hal.h"
  59. /** @addtogroup STM32H7xx_HAL_Driver
  60. * @{
  61. */
  62. /** @defgroup DACEx DACEx
  63. * @brief DAC Extended HAL module driver
  64. * @{
  65. */
  66. #ifdef HAL_DAC_MODULE_ENABLED
  67. /* Private typedef -----------------------------------------------------------*/
  68. /* Private define ------------------------------------------------------------*/
  69. /* Private macro -------------------------------------------------------------*/
  70. /* Private variables ---------------------------------------------------------*/
  71. /* Private function prototypes -----------------------------------------------*/
  72. /* Private functions ---------------------------------------------------------*/
  73. /* Exported functions --------------------------------------------------------*/
  74. /** @defgroup DACEx_Exported_Functions DACEx Exported Functions
  75. * @{
  76. */
  77. /** @defgroup DACEx_Exported_Functions_Group2 IO operation functions
  78. * @brief Extended IO operation functions
  79. *
  80. @verbatim
  81. ==============================================================================
  82. ##### Extended features functions #####
  83. ==============================================================================
  84. [..] This section provides functions allowing to:
  85. (+) Start conversion with triangle wave generation.
  86. (+) Start conversion with noise wave generation.
  87. (+) Start self calibration.
  88. (+) Set user trimming mode.
  89. (+) Get result of dual mode conversion.
  90. @endverbatim
  91. * @{
  92. */
  93. /**
  94. * @brief Enable or disable the selected DAC channel wave generation.
  95. * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
  96. * the configuration information for the specified DAC.
  97. * @param Channel: The selected DAC channel.
  98. * This parameter can be one of the following values:
  99. * @arg DAC_CHANNEL_1: DAC Channel1 selected
  100. * @arg DAC_CHANNEL_2: DAC Channel2 selected
  101. * @param Amplitude: Select max triangle amplitude.
  102. * This parameter can be one of the following values:
  103. * @arg DAC_TRIANGLEAMPLITUDE_1: Select max triangle amplitude of 1
  104. * @arg DAC_TRIANGLEAMPLITUDE_3: Select max triangle amplitude of 3
  105. * @arg DAC_TRIANGLEAMPLITUDE_7: Select max triangle amplitude of 7
  106. * @arg DAC_TRIANGLEAMPLITUDE_15: Select max triangle amplitude of 15
  107. * @arg DAC_TRIANGLEAMPLITUDE_31: Select max triangle amplitude of 31
  108. * @arg DAC_TRIANGLEAMPLITUDE_63: Select max triangle amplitude of 63
  109. * @arg DAC_TRIANGLEAMPLITUDE_127: Select max triangle amplitude of 127
  110. * @arg DAC_TRIANGLEAMPLITUDE_255: Select max triangle amplitude of 255
  111. * @arg DAC_TRIANGLEAMPLITUDE_511: Select max triangle amplitude of 511
  112. * @arg DAC_TRIANGLEAMPLITUDE_1023: Select max triangle amplitude of 1023
  113. * @arg DAC_TRIANGLEAMPLITUDE_2047: Select max triangle amplitude of 2047
  114. * @arg DAC_TRIANGLEAMPLITUDE_4095: Select max triangle amplitude of 4095
  115. * @retval HAL status
  116. */
  117. HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Amplitude)
  118. {
  119. /* Check the parameters */
  120. assert_param(IS_DAC_CHANNEL(Channel));
  121. assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude));
  122. /* Process locked */
  123. __HAL_LOCK(hdac);
  124. /* Change DAC state */
  125. hdac->State = HAL_DAC_STATE_BUSY;
  126. /* Enable the triangle wave generation for the selected DAC channel */
  127. MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1)|(DAC_CR_MAMP1))<<Channel, (DAC_CR_WAVE1_1 | Amplitude) << Channel);
  128. /* Change DAC state */
  129. hdac->State = HAL_DAC_STATE_READY;
  130. /* Process unlocked */
  131. __HAL_UNLOCK(hdac);
  132. /* Return function status */
  133. return HAL_OK;
  134. }
  135. /**
  136. * @brief Enable or disable the selected DAC channel wave generation.
  137. * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
  138. * the configuration information for the specified DAC.
  139. * @param Channel: The selected DAC channel.
  140. * This parameter can be one of the following values:
  141. * @arg DAC_CHANNEL_1: DAC Channel1 selected
  142. * @arg DAC_CHANNEL_2: DAC Channel2 selected
  143. * @param Amplitude: Unmask DAC channel LFSR for noise wave generation.
  144. * This parameter can be one of the following values:
  145. * @arg DAC_LFSRUNMASK_BIT0: Unmask DAC channel LFSR bit0 for noise wave generation
  146. * @arg DAC_LFSRUNMASK_BITS1_0: Unmask DAC channel LFSR bit[1:0] for noise wave generation
  147. * @arg DAC_LFSRUNMASK_BITS2_0: Unmask DAC channel LFSR bit[2:0] for noise wave generation
  148. * @arg DAC_LFSRUNMASK_BITS3_0: Unmask DAC channel LFSR bit[3:0] for noise wave generation
  149. * @arg DAC_LFSRUNMASK_BITS4_0: Unmask DAC channel LFSR bit[4:0] for noise wave generation
  150. * @arg DAC_LFSRUNMASK_BITS5_0: Unmask DAC channel LFSR bit[5:0] for noise wave generation
  151. * @arg DAC_LFSRUNMASK_BITS6_0: Unmask DAC channel LFSR bit[6:0] for noise wave generation
  152. * @arg DAC_LFSRUNMASK_BITS7_0: Unmask DAC channel LFSR bit[7:0] for noise wave generation
  153. * @arg DAC_LFSRUNMASK_BITS8_0: Unmask DAC channel LFSR bit[8:0] for noise wave generation
  154. * @arg DAC_LFSRUNMASK_BITS9_0: Unmask DAC channel LFSR bit[9:0] for noise wave generation
  155. * @arg DAC_LFSRUNMASK_BITS10_0: Unmask DAC channel LFSR bit[10:0] for noise wave generation
  156. * @arg DAC_LFSRUNMASK_BITS11_0: Unmask DAC channel LFSR bit[11:0] for noise wave generation
  157. * @retval HAL status
  158. */
  159. HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Amplitude)
  160. {
  161. /* Check the parameters */
  162. assert_param(IS_DAC_CHANNEL(Channel));
  163. assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude));
  164. /* Process locked */
  165. __HAL_LOCK(hdac);
  166. /* Change DAC state */
  167. hdac->State = HAL_DAC_STATE_BUSY;
  168. /* Enable the noise wave generation for the selected DAC channel */
  169. MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1)|(DAC_CR_MAMP1))<<Channel, (DAC_CR_WAVE1_0 | Amplitude) << Channel);
  170. /* Change DAC state */
  171. hdac->State = HAL_DAC_STATE_READY;
  172. /* Process unlocked */
  173. __HAL_UNLOCK(hdac);
  174. /* Return function status */
  175. return HAL_OK;
  176. }
  177. /**
  178. * @brief Set the specified data holding register value for dual DAC channel.
  179. * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
  180. * the configuration information for the specified DAC.
  181. * @param Alignment: Specifies the data alignment for dual channel DAC.
  182. * This parameter can be one of the following values:
  183. * DAC_ALIGN_8B_R: 8bit right data alignment selected
  184. * DAC_ALIGN_12B_L: 12bit left data alignment selected
  185. * DAC_ALIGN_12B_R: 12bit right data alignment selected
  186. * @param Data1: Data for DAC Channel2 to be loaded in the selected data holding register.
  187. * @param Data2: Data for DAC Channel1 to be loaded in the selected data holding register.
  188. * @note In dual mode, a unique register access is required to write in both
  189. * DAC channels at the same time.
  190. * @retval HAL status
  191. */
  192. HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef* hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2)
  193. {
  194. uint32_t data = 0, tmp = 0;
  195. /* Check the parameters */
  196. assert_param(IS_DAC_ALIGN(Alignment));
  197. assert_param(IS_DAC_DATA(Data1));
  198. assert_param(IS_DAC_DATA(Data2));
  199. /* Calculate and set dual DAC data holding register value */
  200. if (Alignment == DAC_ALIGN_8B_R)
  201. {
  202. data = ((uint32_t)Data2 << 8) | Data1;
  203. }
  204. else
  205. {
  206. data = ((uint32_t)Data2 << 16) | Data1;
  207. }
  208. tmp = (uint32_t)hdac->Instance;
  209. tmp += DAC_DHR12RD_ALIGNMENT(Alignment);
  210. /* Set the dual DAC selected data holding register */
  211. *(__IO uint32_t *)tmp = data;
  212. /* Return function status */
  213. return HAL_OK;
  214. }
  215. /**
  216. * @brief Conversion complete callback in non-blocking mode for Channel2.
  217. * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
  218. * the configuration information for the specified DAC.
  219. * @retval None
  220. */
  221. __weak void HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef* hdac)
  222. {
  223. /* Prevent unused argument(s) compilation warning */
  224. UNUSED(hdac);
  225. /* NOTE : This function should not be modified, when the callback is needed,
  226. the HAL_DACEx_ConvCpltCallbackCh2 could be implemented in the user file
  227. */
  228. }
  229. /**
  230. * @brief Conversion half DMA transfer callback in non-blocking mode for Channel2.
  231. * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
  232. * the configuration information for the specified DAC.
  233. * @retval None
  234. */
  235. __weak void HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef* hdac)
  236. {
  237. /* Prevent unused argument(s) compilation warning */
  238. UNUSED(hdac);
  239. /* NOTE : This function should not be modified, when the callback is needed,
  240. the HAL_DACEx_ConvHalfCpltCallbackCh2 could be implemented in the user file
  241. */
  242. }
  243. /**
  244. * @brief Error DAC callback for Channel2.
  245. * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
  246. * the configuration information for the specified DAC.
  247. * @retval None
  248. */
  249. __weak void HAL_DACEx_ErrorCallbackCh2(DAC_HandleTypeDef *hdac)
  250. {
  251. /* Prevent unused argument(s) compilation warning */
  252. UNUSED(hdac);
  253. /* NOTE : This function should not be modified, when the callback is needed,
  254. the HAL_DACEx_ErrorCallbackCh2 could be implemented in the user file
  255. */
  256. }
  257. /**
  258. * @brief DMA underrun DAC callback for channel2.
  259. * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
  260. * the configuration information for the specified DAC.
  261. * @retval None
  262. */
  263. __weak void HAL_DACEx_DMAUnderrunCallbackCh2(DAC_HandleTypeDef *hdac)
  264. {
  265. /* Prevent unused argument(s) compilation warning */
  266. UNUSED(hdac);
  267. /* NOTE : This function should not be modified, when the callback is needed,
  268. the HAL_DACEx_DMAUnderrunCallbackCh2 could be implemented in the user file
  269. */
  270. }
  271. /**
  272. * @brief Run the self calibration of one DAC channel.
  273. * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
  274. * the configuration information for the specified DAC.
  275. * @param sConfig: DAC channel configuration structure.
  276. * @param Channel: The selected DAC channel.
  277. * This parameter can be one of the following values:
  278. * @arg DAC_CHANNEL_1: DAC Channel1 selected
  279. * @arg DAC_CHANNEL_2: DAC Channel2 selected
  280. * @retval Updates DAC_TrimmingValue. , DAC_UserTrimming set to DAC_UserTrimming
  281. * @retval HAL status
  282. * @note Calibration runs about 7 ms.
  283. */
  284. HAL_StatusTypeDef HAL_DACEx_SelfCalibrate (DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel)
  285. {
  286. HAL_StatusTypeDef status = HAL_OK;
  287. __IO uint32_t tmp = 0;
  288. uint32_t trimmingvalue = 0;
  289. uint32_t delta;
  290. /* store/restore channel configuration structure purpose */
  291. uint32_t oldmodeconfiguration = 0;
  292. /* Check the parameters */
  293. assert_param(IS_DAC_CHANNEL(Channel));
  294. /* Check the DAC handle allocation */
  295. /* Check if DAC running */
  296. if((hdac == NULL) || (hdac->State == HAL_DAC_STATE_BUSY))
  297. {
  298. status = HAL_ERROR;
  299. }
  300. else
  301. {
  302. /* Process locked */
  303. __HAL_LOCK(hdac);
  304. /* Store configuration */
  305. oldmodeconfiguration = (hdac->Instance->MCR & (DAC_MCR_MODE1 << Channel));
  306. /* Disable the selected DAC channel */
  307. CLEAR_BIT ((hdac->Instance->CR), (DAC_CR_EN1 << Channel));
  308. /* Set mode in MCR for calibration */
  309. MODIFY_REG(hdac->Instance->MCR, (DAC_MCR_MODE1 << Channel), 0);
  310. /* Set DAC Channel1 DHR register to the middle value */
  311. tmp = (uint32_t)hdac->Instance;
  312. if(Channel == DAC_CHANNEL_1)
  313. {
  314. tmp += DAC_DHR12R1_ALIGNMENT(DAC_ALIGN_12B_R);
  315. }
  316. else
  317. {
  318. tmp += DAC_DHR12R2_ALIGNMENT(DAC_ALIGN_12B_R);
  319. }
  320. *(__IO uint32_t *) tmp = 0x0800;
  321. /* Enable the selected DAC channel calibration */
  322. /* i.e. set DAC_CR_CENx bit */
  323. SET_BIT ((hdac->Instance->CR), (DAC_CR_CEN1 << Channel));
  324. /* Init trimming counter */
  325. /* Medium value */
  326. trimmingvalue = 16;
  327. delta = 8;
  328. while (delta != 0)
  329. {
  330. /* Set candidate trimming */
  331. MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1<<Channel), (trimmingvalue<<Channel));
  332. /* tOFFTRIMmax delay x ms as per datasheet (electrical characteristics */
  333. /* i.e. minimum time needed between two calibration steps */
  334. HAL_Delay(1);
  335. if ((hdac->Instance->SR & (DAC_SR_CAL_FLAG1<<Channel)) == (DAC_SR_CAL_FLAG1<<Channel))
  336. {
  337. /* DAC_SR_CAL_FLAGx is HIGH try higher trimming */
  338. trimmingvalue -= delta;
  339. }
  340. else
  341. {
  342. /* DAC_SR_CAL_FLAGx is LOW try lower trimming */
  343. trimmingvalue += delta;
  344. }
  345. delta >>= 1;
  346. }
  347. /* Still need to check if right calibration is current value or one step below */
  348. /* Indeed the first value that causes the DAC_SR_CAL_FLAGx bit to change from 0 to 1 */
  349. /* Set candidate trimming */
  350. MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1<<Channel), (trimmingvalue<<Channel));
  351. /* tOFFTRIMmax delay x ms as per datasheet (electrical characteristics */
  352. /* i.e. minimum time needed between two calibration steps */
  353. HAL_Delay(1);
  354. if (!(hdac->Instance->SR & (DAC_SR_CAL_FLAG1<<Channel)))
  355. {
  356. /* Trimming is actually one value more */
  357. trimmingvalue ++;
  358. /* Set right trimming */
  359. MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1<<Channel), (trimmingvalue<<Channel));
  360. }
  361. /* Disable the selected DAC channel calibration */
  362. /* i.e. clear DAC_CR_CENx bit */
  363. CLEAR_BIT ((hdac->Instance->CR), (DAC_CR_CEN1 << Channel));
  364. sConfig->DAC_TrimmingValue = trimmingvalue;
  365. sConfig->DAC_UserTrimming = DAC_TRIMMING_USER;
  366. /* Restore configuration */
  367. MODIFY_REG(hdac->Instance->MCR, (DAC_MCR_MODE1 << Channel), oldmodeconfiguration);
  368. /* Process unlocked */
  369. __HAL_UNLOCK(hdac);
  370. }
  371. return status;
  372. }
  373. /**
  374. * @}
  375. */
  376. /**
  377. * @brief Set the trimming mode and trimming value (user trimming mode applied).
  378. * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
  379. * the configuration information for the specified DAC.
  380. * @param sConfig: DAC configuration structure updated with new DAC trimming value.
  381. * @param Channel: The selected DAC channel.
  382. * This parameter can be one of the following values:
  383. * @arg DAC_CHANNEL_1: DAC Channel1 selected
  384. * @arg DAC_CHANNEL_2: DAC Channel2 selected
  385. * @param NewTrimmingValue: DAC new trimming value
  386. * @retval HAL status
  387. */
  388. HAL_StatusTypeDef HAL_DACEx_SetUserTrimming (DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel, uint32_t NewTrimmingValue)
  389. {
  390. HAL_StatusTypeDef status = HAL_OK;
  391. /* Check the parameters */
  392. assert_param(IS_DAC_CHANNEL(Channel));
  393. assert_param(IS_DAC_NEWTRIMMINGVALUE(NewTrimmingValue));
  394. /* Check the DAC handle allocation */
  395. if(hdac == NULL)
  396. {
  397. status = HAL_ERROR;
  398. }
  399. else
  400. {
  401. /* Process locked */
  402. __HAL_LOCK(hdac);
  403. /* Set new trimming */
  404. MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1<<Channel), (NewTrimmingValue<<Channel));
  405. /* Update trimming mode */
  406. sConfig->DAC_UserTrimming = DAC_TRIMMING_USER;
  407. sConfig->DAC_TrimmingValue = NewTrimmingValue;
  408. /* Process unlocked */
  409. __HAL_UNLOCK(hdac);
  410. }
  411. return status;
  412. }
  413. /**
  414. * @brief Return the DAC trimming value.
  415. * @param hdac : DAC handle
  416. * @param Channel: The selected DAC channel.
  417. * This parameter can be one of the following values:
  418. * @arg DAC_CHANNEL_1: DAC Channel1 selected
  419. * @arg DAC_CHANNEL_2: DAC Channel2 selected
  420. * @retval Trimming value : range: 0->31
  421. *
  422. */
  423. uint32_t HAL_DACEx_GetTrimOffset (DAC_HandleTypeDef *hdac, uint32_t Channel)
  424. {
  425. uint32_t trimmingvalue = 0;
  426. /* Check the DAC handle allocation */
  427. /* And not in Reset state */
  428. if((hdac == NULL) || (hdac->State == HAL_DAC_STATE_RESET))
  429. {
  430. return HAL_ERROR;
  431. }
  432. else
  433. {
  434. /* Check the parameter */
  435. assert_param(IS_DAC_CHANNEL(Channel));
  436. /* Retrieve trimming */
  437. trimmingvalue = ((hdac->Instance->CCR & (DAC_CCR_OTRIM1 << Channel)) >> Channel);
  438. }
  439. return trimmingvalue;
  440. }
  441. /**
  442. * @}
  443. */
  444. /** @defgroup DACEx_Exported_Functions_Group3 Peripheral Control functions
  445. * @brief Extended Peripheral Control functions
  446. *
  447. @verbatim
  448. ==============================================================================
  449. ##### Peripheral Control functions #####
  450. ==============================================================================
  451. [..] This section provides functions allowing to:
  452. (+) Configure channels.
  453. (+) Set the specified data holding register value for DAC channel.
  454. @endverbatim
  455. * @{
  456. */
  457. /**
  458. * @brief Return the last data output value of the selected DAC channel.
  459. * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
  460. * the configuration information for the specified DAC.
  461. * @retval The selected DAC channel data output value.
  462. */
  463. uint32_t HAL_DACEx_DualGetValue(DAC_HandleTypeDef* hdac)
  464. {
  465. uint32_t tmp = 0;
  466. tmp |= hdac->Instance->DOR1;
  467. tmp |= hdac->Instance->DOR2 << 16;
  468. /* Returns the DAC channel data output register value */
  469. return tmp;
  470. }
  471. /**
  472. * @}
  473. */
  474. /* Private functions ---------------------------------------------------------*/
  475. /** @defgroup DACEx_Private_Functions DACEx private functions
  476. * @brief Extended private functions
  477. * @{
  478. */
  479. /**
  480. * @brief DMA conversion complete callback.
  481. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  482. * the configuration information for the specified DMA module.
  483. * @retval None
  484. */
  485. void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma)
  486. {
  487. DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  488. HAL_DACEx_ConvCpltCallbackCh2(hdac);
  489. hdac->State= HAL_DAC_STATE_READY;
  490. }
  491. /**
  492. * @brief DMA half transfer complete callback.
  493. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  494. * the configuration information for the specified DMA module.
  495. * @retval None
  496. */
  497. void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma)
  498. {
  499. DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  500. /* Conversion complete callback */
  501. HAL_DACEx_ConvHalfCpltCallbackCh2(hdac);
  502. }
  503. /**
  504. * @brief DMA error callback.
  505. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  506. * the configuration information for the specified DMA module.
  507. * @retval None
  508. */
  509. void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma)
  510. {
  511. DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  512. /* Set DAC error code to DMA error */
  513. hdac->ErrorCode |= HAL_DAC_ERROR_DMA;
  514. HAL_DACEx_ErrorCallbackCh2(hdac);
  515. hdac->State= HAL_DAC_STATE_READY;
  516. }
  517. /**
  518. * @}
  519. */
  520. #endif /* HAL_DAC_MODULE_ENABLED */
  521. /**
  522. * @}
  523. */
  524. /**
  525. * @}
  526. */
  527. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/