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.
 
 
 

621 lines
22 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_dac_ex.c
  4. * @author MCD Application Team
  5. * @version V1.3.0
  6. * @date 29-January-2016
  7. * @brief DAC HAL module driver.
  8. * This file provides firmware functions to manage the extended
  9. * functionalities of the 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) 2016 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 "stm32l4xx_hal.h"
  59. /** @addtogroup STM32L4xx_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. /* Exported functions --------------------------------------------------------*/
  73. /** @defgroup DACEx_Exported_Functions DACEx Exported Functions
  74. * @{
  75. */
  76. /** @defgroup DACEx_Exported_Functions_Group2 IO operation functions
  77. * @brief Extended IO operation functions
  78. *
  79. @verbatim
  80. ==============================================================================
  81. ##### Extended features functions #####
  82. ==============================================================================
  83. [..] This section provides functions allowing to:
  84. (+) Start conversion.
  85. (+) Stop conversion.
  86. (+) Start conversion and enable DMA transfer.
  87. (+) Stop conversion and disable DMA transfer.
  88. (+) Get result of conversion.
  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. * DAC_CHANNEL_1 / DAC_CHANNEL_2
  100. * @param Amplitude: Select max triangle amplitude.
  101. * This parameter can be one of the following values:
  102. * @arg DAC_TRIANGLEAMPLITUDE_1: Select max triangle amplitude of 1
  103. * @arg DAC_TRIANGLEAMPLITUDE_3: Select max triangle amplitude of 3
  104. * @arg DAC_TRIANGLEAMPLITUDE_7: Select max triangle amplitude of 7
  105. * @arg DAC_TRIANGLEAMPLITUDE_15: Select max triangle amplitude of 15
  106. * @arg DAC_TRIANGLEAMPLITUDE_31: Select max triangle amplitude of 31
  107. * @arg DAC_TRIANGLEAMPLITUDE_63: Select max triangle amplitude of 63
  108. * @arg DAC_TRIANGLEAMPLITUDE_127: Select max triangle amplitude of 127
  109. * @arg DAC_TRIANGLEAMPLITUDE_255: Select max triangle amplitude of 255
  110. * @arg DAC_TRIANGLEAMPLITUDE_511: Select max triangle amplitude of 511
  111. * @arg DAC_TRIANGLEAMPLITUDE_1023: Select max triangle amplitude of 1023
  112. * @arg DAC_TRIANGLEAMPLITUDE_2047: Select max triangle amplitude of 2047
  113. * @arg DAC_TRIANGLEAMPLITUDE_4095: Select max triangle amplitude of 4095
  114. * @retval HAL status
  115. */
  116. HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Amplitude)
  117. {
  118. /* Check the parameters */
  119. assert_param(IS_DAC_CHANNEL(Channel));
  120. assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude));
  121. /* Process locked */
  122. __HAL_LOCK(hdac);
  123. /* Change DAC state */
  124. hdac->State = HAL_DAC_STATE_BUSY;
  125. /* Enable the triangle wave generation for the selected DAC channel */
  126. MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1)|(DAC_CR_MAMP1))<<Channel, (DAC_CR_WAVE1_1 | Amplitude) << Channel);
  127. /* Change DAC state */
  128. hdac->State = HAL_DAC_STATE_READY;
  129. /* Process unlocked */
  130. __HAL_UNLOCK(hdac);
  131. /* Return function status */
  132. return HAL_OK;
  133. }
  134. /**
  135. * @brief Enable or disable the selected DAC channel wave generation.
  136. * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
  137. * the configuration information for the specified DAC.
  138. * @param Channel: The selected DAC channel.
  139. * This parameter can be one of the following values:
  140. * DAC_CHANNEL_1 / DAC_CHANNEL_2
  141. * @param Amplitude: Unmask DAC channel LFSR for noise wave generation.
  142. * This parameter can be one of the following values:
  143. * @arg DAC_LFSRUNMASK_BIT0: Unmask DAC channel LFSR bit0 for noise wave generation
  144. * @arg DAC_LFSRUNMASK_BITS1_0: Unmask DAC channel LFSR bit[1:0] for noise wave generation
  145. * @arg DAC_LFSRUNMASK_BITS2_0: Unmask DAC channel LFSR bit[2:0] for noise wave generation
  146. * @arg DAC_LFSRUNMASK_BITS3_0: Unmask DAC channel LFSR bit[3:0] for noise wave generation
  147. * @arg DAC_LFSRUNMASK_BITS4_0: Unmask DAC channel LFSR bit[4:0] for noise wave generation
  148. * @arg DAC_LFSRUNMASK_BITS5_0: Unmask DAC channel LFSR bit[5:0] for noise wave generation
  149. * @arg DAC_LFSRUNMASK_BITS6_0: Unmask DAC channel LFSR bit[6:0] for noise wave generation
  150. * @arg DAC_LFSRUNMASK_BITS7_0: Unmask DAC channel LFSR bit[7:0] for noise wave generation
  151. * @arg DAC_LFSRUNMASK_BITS8_0: Unmask DAC channel LFSR bit[8:0] for noise wave generation
  152. * @arg DAC_LFSRUNMASK_BITS9_0: Unmask DAC channel LFSR bit[9:0] for noise wave generation
  153. * @arg DAC_LFSRUNMASK_BITS10_0: Unmask DAC channel LFSR bit[10:0] for noise wave generation
  154. * @arg DAC_LFSRUNMASK_BITS11_0: Unmask DAC channel LFSR bit[11:0] for noise wave generation
  155. * @retval HAL status
  156. */
  157. HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Amplitude)
  158. {
  159. /* Check the parameters */
  160. assert_param(IS_DAC_CHANNEL(Channel));
  161. assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude));
  162. /* Process locked */
  163. __HAL_LOCK(hdac);
  164. /* Change DAC state */
  165. hdac->State = HAL_DAC_STATE_BUSY;
  166. /* Enable the noise wave generation for the selected DAC channel */
  167. MODIFY_REG(hdac->Instance->CR, ((DAC_CR_WAVE1)|(DAC_CR_MAMP1))<<Channel, (DAC_CR_WAVE1_0 | Amplitude) << Channel);
  168. /* Change DAC state */
  169. hdac->State = HAL_DAC_STATE_READY;
  170. /* Process unlocked */
  171. __HAL_UNLOCK(hdac);
  172. /* Return function status */
  173. return HAL_OK;
  174. }
  175. /**
  176. * @brief Set the specified data holding register value for dual DAC channel.
  177. * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
  178. * the configuration information for the specified DAC.
  179. * @param Alignment: Specifies the data alignment for dual channel DAC.
  180. * This parameter can be one of the following values:
  181. * DAC_ALIGN_8B_R: 8bit right data alignment selected
  182. * DAC_ALIGN_12B_L: 12bit left data alignment selected
  183. * DAC_ALIGN_12B_R: 12bit right data alignment selected
  184. * @param Data1: Data for DAC Channel2 to be loaded in the selected data holding register.
  185. * @param Data2: Data for DAC Channel1 to be loaded in the selected data holding register.
  186. * @note In dual mode, a unique register access is required to write in both
  187. * DAC channels at the same time.
  188. * @retval HAL status
  189. */
  190. HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef* hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2)
  191. {
  192. uint32_t data = 0, tmp = 0;
  193. /* Check the parameters */
  194. assert_param(IS_DAC_ALIGN(Alignment));
  195. assert_param(IS_DAC_DATA(Data1));
  196. assert_param(IS_DAC_DATA(Data2));
  197. /* Calculate and set dual DAC data holding register value */
  198. if (Alignment == DAC_ALIGN_8B_R)
  199. {
  200. data = ((uint32_t)Data2 << 8) | Data1;
  201. }
  202. else
  203. {
  204. data = ((uint32_t)Data2 << 16) | Data1;
  205. }
  206. tmp = (uint32_t)hdac->Instance;
  207. tmp += DAC_DHR12RD_ALIGNMENT(Alignment);
  208. /* Set the dual DAC selected data holding register */
  209. *(__IO uint32_t *)tmp = data;
  210. /* Return function status */
  211. return HAL_OK;
  212. }
  213. /**
  214. * @brief Conversion complete callback in non-blocking mode for Channel2.
  215. * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
  216. * the configuration information for the specified DAC.
  217. * @retval None
  218. */
  219. __weak void HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef* hdac)
  220. {
  221. /* Prevent unused argument(s) compilation warning */
  222. UNUSED(hdac);
  223. /* NOTE : This function should not be modified, when the callback is needed,
  224. the HAL_DACEx_ConvCpltCallbackCh2 could be implemented in the user file
  225. */
  226. }
  227. /**
  228. * @brief Conversion half DMA transfer callback in non-blocking mode for Channel2.
  229. * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
  230. * the configuration information for the specified DAC.
  231. * @retval None
  232. */
  233. __weak void HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef* hdac)
  234. {
  235. /* Prevent unused argument(s) compilation warning */
  236. UNUSED(hdac);
  237. /* NOTE : This function should not be modified, when the callback is needed,
  238. the HAL_DACEx_ConvHalfCpltCallbackCh2 could be implemented in the user file
  239. */
  240. }
  241. /**
  242. * @brief Error DAC callback for Channel2.
  243. * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
  244. * the configuration information for the specified DAC.
  245. * @retval None
  246. */
  247. __weak void HAL_DACEx_ErrorCallbackCh2(DAC_HandleTypeDef *hdac)
  248. {
  249. /* Prevent unused argument(s) compilation warning */
  250. UNUSED(hdac);
  251. /* NOTE : This function should not be modified, when the callback is needed,
  252. the HAL_DACEx_ErrorCallbackCh2 could be implemented in the user file
  253. */
  254. }
  255. /**
  256. * @brief DMA underrun DAC callback for Channel2.
  257. * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
  258. * the configuration information for the specified DAC.
  259. * @retval None
  260. */
  261. __weak void HAL_DACEx_DMAUnderrunCallbackCh2(DAC_HandleTypeDef *hdac)
  262. {
  263. /* Prevent unused argument(s) compilation warning */
  264. UNUSED(hdac);
  265. /* NOTE : This function should not be modified, when the callback is needed,
  266. the HAL_DACEx_DMAUnderrunCallbackCh2 could be implemented in the user file
  267. */
  268. }
  269. /**
  270. * @brief Run the self calibration of one DAC channel.
  271. * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
  272. * the configuration information for the specified DAC.
  273. * @param sConfig: DAC channel configuration structure.
  274. * @param Channel: The selected DAC channel.
  275. * This parameter can be one of the following values:
  276. * @arg DAC_CHANNEL_1: DAC Channel1 selected
  277. * @arg DAC_CHANNEL_2: DAC Channel2 selected
  278. * @retval Updates DAC_TrimmingValue. , DAC_UserTrimming set to DAC_UserTrimming
  279. * @retval HAL status
  280. * @note Calibration runs about 7 ms.
  281. */
  282. HAL_StatusTypeDef HAL_DACEx_SelfCalibrate (DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel)
  283. {
  284. HAL_StatusTypeDef status = HAL_OK;
  285. __IO uint32_t tmp = 0;
  286. uint32_t trimmingvalue = 0;
  287. uint32_t delta;
  288. /* store/restore channel configuration structure purpose */
  289. uint32_t oldmodeconfiguration = 0;
  290. /* Check the parameters */
  291. assert_param(IS_DAC_CHANNEL(Channel));
  292. /* Check the DAC handle allocation */
  293. /* Check if DAC running */
  294. if((hdac == NULL) || (hdac->State == HAL_DAC_STATE_BUSY))
  295. {
  296. status = HAL_ERROR;
  297. }
  298. /* Process locked */
  299. __HAL_LOCK(hdac);
  300. /* Store configuration */
  301. oldmodeconfiguration = (hdac->Instance->MCR & (DAC_MCR_MODE1 << Channel));
  302. /* Disable the selected DAC channel */
  303. CLEAR_BIT ((hdac->Instance->CR), (DAC_CR_EN1 << Channel));
  304. /* Set mode in MCR for calibration */
  305. MODIFY_REG(hdac->Instance->MCR, (DAC_MCR_MODE1 << Channel), 0);
  306. /* Set DAC Channel1 DHR register to the middle value */
  307. /* HAL_DAC_SetValue(hdac, Channel, DAC_ALIGN_12B_R, 0x0800); */
  308. tmp = (uint32_t)hdac->Instance;
  309. if(Channel == DAC_CHANNEL_1)
  310. {
  311. tmp += DAC_DHR12R1_ALIGNMENT(DAC_ALIGN_12B_R);
  312. }
  313. else
  314. {
  315. tmp += DAC_DHR12R2_ALIGNMENT(DAC_ALIGN_12B_R);
  316. }
  317. *(__IO uint32_t *) tmp = 0x0800;
  318. /* Enable the selected DAC channel calibration */
  319. /* i.e. set DAC_CR_CENx bit */
  320. SET_BIT ((hdac->Instance->CR), (DAC_CR_CEN1 << Channel));
  321. /* Init trimming counter */
  322. /* Medium value */
  323. trimmingvalue = 16;
  324. delta = 8;
  325. while (delta != 0)
  326. {
  327. /* Set candidate trimming */
  328. MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1<<Channel), (trimmingvalue<<Channel));
  329. /* tOFFTRIMmax delay x ms as per datasheet (electrical characteristics */
  330. /* i.e. minimum time needed between two calibration steps */
  331. HAL_Delay(1);
  332. if ((hdac->Instance->SR & (DAC_SR_CAL_FLAG1<<Channel)) == RESET)
  333. {
  334. /* DAC_SR_CAL_FLAGx is HIGH try higher trimming */
  335. trimmingvalue += delta;
  336. }
  337. else
  338. {
  339. /* DAC_SR_CAL_FLAGx is LOW try lower trimming */
  340. trimmingvalue -= delta;
  341. }
  342. delta >>= 1;
  343. }
  344. /* Still need to check if right calibration is current value or one step below */
  345. /* Indeed the first value that causes the DAC_SR_CAL_FLAGx bit to change from 0 to 1 */
  346. /* Set candidate trimming */
  347. MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1<<Channel), (trimmingvalue<<Channel));
  348. /* tOFFTRIMmax delay x ms as per datasheet (electrical characteristics */
  349. /* i.e. minimum time needed between two calibration steps */
  350. HAL_Delay(1);
  351. if ((hdac->Instance->SR & (DAC_SR_CAL_FLAG1<<Channel)) == RESET)
  352. {
  353. /* OPAMP_CSR_OUTCAL is actually one value more */
  354. trimmingvalue++;
  355. /* Set right trimming */
  356. MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1<<Channel), (trimmingvalue<<Channel));
  357. }
  358. /* Disable the selected DAC channel calibration */
  359. /* i.e. clear DAC_CR_CENx bit */
  360. CLEAR_BIT ((hdac->Instance->CR), (DAC_CR_CEN1 << Channel));
  361. sConfig->DAC_TrimmingValue = trimmingvalue;
  362. sConfig->DAC_UserTrimming = DAC_TRIMMING_USER;
  363. /* Restore configuration */
  364. MODIFY_REG(hdac->Instance->MCR, (DAC_MCR_MODE1 << Channel), oldmodeconfiguration);
  365. /* Process unlocked */
  366. __HAL_UNLOCK(hdac);
  367. return status;
  368. }
  369. /**
  370. * @brief Set the trimming mode and trimming value (user trimming mode applied).
  371. * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
  372. * the configuration information for the specified DAC.
  373. * @param sConfig: DAC configuration structure updated with new DAC trimming value.
  374. * @param Channel: The selected DAC channel.
  375. * This parameter can be one of the following values:
  376. * @arg DAC_CHANNEL_1: DAC Channel1 selected
  377. * @arg DAC_CHANNEL_2: DAC Channel2 selected
  378. * @param NewTrimmingValue: DAC new trimming value
  379. * @retval HAL status
  380. */
  381. HAL_StatusTypeDef HAL_DACEx_SetUserTrimming (DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel, uint32_t NewTrimmingValue)
  382. {
  383. HAL_StatusTypeDef status = HAL_OK;
  384. /* Check the parameters */
  385. assert_param(IS_DAC_CHANNEL(Channel));
  386. assert_param(IS_DAC_NEWTRIMMINGVALUE(NewTrimmingValue));
  387. /* Check the DAC handle allocation */
  388. if(hdac == NULL)
  389. {
  390. status = HAL_ERROR;
  391. }
  392. /* Process locked */
  393. __HAL_LOCK(hdac);
  394. /* Set new trimming */
  395. MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1<<Channel), (NewTrimmingValue<<Channel));
  396. /* Update trimming mode */
  397. sConfig->DAC_UserTrimming = DAC_TRIMMING_USER;
  398. sConfig->DAC_TrimmingValue = NewTrimmingValue;
  399. /* Process unlocked */
  400. __HAL_UNLOCK(hdac);
  401. return status;
  402. }
  403. /**
  404. * @brief Return the DAC trimming value.
  405. * @param hdac : DAC handle
  406. * @param Channel: The selected DAC channel.
  407. * This parameter can be one of the following values:
  408. * @arg DAC_CHANNEL_1: DAC Channel1 selected
  409. * @arg DAC_CHANNEL_2: DAC Channel2 selected
  410. * @retval Trimming value : range: 0->31
  411. *
  412. */
  413. uint32_t HAL_DACEx_GetTrimOffset (DAC_HandleTypeDef *hdac, uint32_t Channel)
  414. {
  415. uint32_t trimmingvalue = 0;
  416. /* Check the DAC handle allocation */
  417. /* And not in Reset state */
  418. if((hdac == NULL) || (hdac->State == HAL_DAC_STATE_RESET))
  419. {
  420. return HAL_ERROR;
  421. }
  422. else
  423. {
  424. /* Check the parameter */
  425. assert_param(IS_DAC_CHANNEL(Channel));
  426. /* Retrieve trimming */
  427. trimmingvalue = ((hdac->Instance->CCR & (DAC_CCR_OTRIM1 << Channel)) >> Channel);
  428. }
  429. return trimmingvalue;
  430. }
  431. /**
  432. * @}
  433. */
  434. /** @defgroup DACEx_Exported_Functions_Group3 Peripheral Control functions
  435. * @brief Extended Peripheral Control functions
  436. *
  437. @verbatim
  438. ==============================================================================
  439. ##### Peripheral Control functions #####
  440. ==============================================================================
  441. [..] This section provides functions allowing to:
  442. (+) Configure channels.
  443. (+) Set the specified data holding register value for DAC channel.
  444. @endverbatim
  445. * @{
  446. */
  447. /**
  448. * @brief Return the last data output value of the selected DAC channel.
  449. * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
  450. * the configuration information for the specified DAC.
  451. * @retval The selected DAC channel data output value.
  452. */
  453. uint32_t HAL_DACEx_DualGetValue(DAC_HandleTypeDef* hdac)
  454. {
  455. uint32_t tmp = 0;
  456. tmp |= hdac->Instance->DOR1;
  457. tmp |= hdac->Instance->DOR2 << 16;
  458. /* Returns the DAC channel data output register value */
  459. return tmp;
  460. }
  461. /**
  462. * @}
  463. */
  464. /**
  465. * @}
  466. */
  467. /* Private functions ---------------------------------------------------------*/
  468. /** @defgroup DACEx_Private_Functions DACEx private functions
  469. * @brief Extended private functions
  470. * @{
  471. */
  472. /**
  473. * @brief DMA conversion complete callback.
  474. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  475. * the configuration information for the specified DMA module.
  476. * @retval None
  477. */
  478. void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma)
  479. {
  480. DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  481. HAL_DACEx_ConvCpltCallbackCh2(hdac);
  482. hdac->State= HAL_DAC_STATE_READY;
  483. }
  484. /**
  485. * @brief DMA half transfer complete callback.
  486. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  487. * the configuration information for the specified DMA module.
  488. * @retval None
  489. */
  490. void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma)
  491. {
  492. DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  493. /* Conversion complete callback */
  494. HAL_DACEx_ConvHalfCpltCallbackCh2(hdac);
  495. }
  496. /**
  497. * @brief DMA error callback.
  498. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  499. * the configuration information for the specified DMA module.
  500. * @retval None
  501. */
  502. void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma)
  503. {
  504. DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  505. /* Set DAC error code to DMA error */
  506. hdac->ErrorCode |= HAL_DAC_ERROR_DMA;
  507. HAL_DACEx_ErrorCallbackCh2(hdac);
  508. hdac->State= HAL_DAC_STATE_READY;
  509. }
  510. /**
  511. * @}
  512. */
  513. #endif /* HAL_DAC_MODULE_ENABLED */
  514. /**
  515. * @}
  516. */
  517. /**
  518. * @}
  519. */
  520. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/