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.
 
 
 

786 lines
27 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_hal_dac.c
  4. * @author MCD Application Team
  5. * @brief DAC HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the Digital to Analog Converter (DAC) peripheral:
  8. * + Initialization and de-initialization functions
  9. * + IO operation functions
  10. * + Peripheral Control functions
  11. * + Peripheral State and Errors functions
  12. *
  13. *
  14. @verbatim
  15. ==============================================================================
  16. ##### DAC Peripheral features #####
  17. ==============================================================================
  18. [..]
  19. *** DAC Channels ***
  20. ====================
  21. [..]
  22. STM32F0 devices integrates no, one or two 12-bit Digital Analog Converters.
  23. STM32F05x devices have one converter (channel1)
  24. STM32F07x & STM32F09x devices have two converters (i.e. channel1 & channel2)
  25. When 2 converters are present (i.e. channel1 & channel2) they
  26. can be used independently or simultaneously (dual mode):
  27. (#) DAC channel1 with DAC_OUT1 (PA4) as output
  28. (#) DAC channel2 with DAC_OUT2 (PA5) as output
  29. *** DAC Triggers ***
  30. ====================
  31. [..]
  32. Digital to Analog conversion can be non-triggered using DAC_TRIGGER_NONE
  33. and DAC_OUT1/DAC_OUT2 is available once writing to DHRx register.
  34. [..]
  35. Digital to Analog conversion can be triggered by:
  36. (#) External event: EXTI Line 9 (any GPIOx_PIN_9) using DAC_TRIGGER_EXT_IT9.
  37. The used pin (GPIOx_PIN_9) must be configured in input mode.
  38. (#) Timers TRGO: TIM2, TIM3, TIM6, and TIM15
  39. (DAC_TRIGGER_T2_TRGO, DAC_TRIGGER_T3_TRGO...)
  40. (#) Software using DAC_TRIGGER_SOFTWARE
  41. *** DAC Buffer mode feature ***
  42. ===============================
  43. [..]
  44. Each DAC channel integrates an output buffer that can be used to
  45. reduce the output impedance, and to drive external loads directly
  46. without having to add an external operational amplifier.
  47. To enable, the output buffer use
  48. sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
  49. [..]
  50. (@) Refer to the device datasheet for more details about output
  51. impedance value with and without output buffer.
  52. *** GPIO configurations guidelines ***
  53. =====================
  54. [..]
  55. When a DAC channel is used (ex channel1 on PA4) and the other is not
  56. (ex channel1 on PA5 is configured in Analog and disabled).
  57. Channel1 may disturb channel2 as coupling effect.
  58. Note that there is no coupling on channel2 as soon as channel2 is turned on.
  59. Coupling on adjacent channel could be avoided as follows:
  60. when unused PA5 is configured as INPUT PULL-UP or DOWN.
  61. PA5 is configured in ANALOG just before it is turned on.
  62. *** DAC wave generation feature ***
  63. ===================================
  64. [..]
  65. Both DAC channels can be used to generate
  66. (#) Noise wave
  67. (#) Triangle wave
  68. *** DAC data format ***
  69. =======================
  70. [..]
  71. The DAC data format can be:
  72. (#) 8-bit right alignment using DAC_ALIGN_8B_R
  73. (#) 12-bit left alignment using DAC_ALIGN_12B_L
  74. (#) 12-bit right alignment using DAC_ALIGN_12B_R
  75. *** DAC data value to voltage correspondance ***
  76. ================================================
  77. [..]
  78. The analog output voltage on each DAC channel pin is determined
  79. by the following equation:
  80. [..]
  81. DAC_OUTx = VREF+ * DOR / 4095
  82. (+) with DOR is the Data Output Register
  83. [..]
  84. VEF+ is the input voltage reference (refer to the device datasheet)
  85. [..]
  86. e.g. To set DAC_OUT1 to 0.7V, use
  87. (+) Assuming that VREF+ = 3.3V, DAC_OUT1 = (3.3 * 868) / 4095 = 0.7V
  88. *** DMA requests ***
  89. =====================
  90. [..]
  91. A DMA1 request can be generated when an external trigger (but not
  92. a software trigger) occurs if DMA1 requests are enabled using
  93. HAL_DAC_Start_DMA()
  94. [..]
  95. DMA1 requests are mapped as following:
  96. (#) DAC channel1 : mapped on DMA1 channel3 which must be
  97. already configured
  98. (#) DAC channel2 : mapped on DMA1 channel4 which must be
  99. already configured
  100. (@) For Dual mode and specific signal (Triangle and noise) generation please
  101. refer to Extended Features Driver description
  102. STM32F0 devices with one channel (one converting capability) does not
  103. support Dual mode and specific signal (Triangle and noise) generation.
  104. ##### How to use this driver #####
  105. ==============================================================================
  106. [..]
  107. (+) DAC APB clock must be enabled to get write access to DAC
  108. registers using HAL_DAC_Init()
  109. (+) Configure DAC_OUTx (DAC_OUT1: PA4, DAC_OUT2: PA5) in analog mode.
  110. (+) Configure the DAC channel using HAL_DAC_ConfigChannel() function.
  111. (+) Enable the DAC channel using HAL_DAC_Start() or HAL_DAC_Start_DMA() functions.
  112. *** Polling mode IO operation ***
  113. =================================
  114. [..]
  115. (+) Start the DAC peripheral using HAL_DAC_Start()
  116. (+) To read the DAC last data output value, use the HAL_DAC_GetValue() function.
  117. (+) Stop the DAC peripheral using HAL_DAC_Stop()
  118. *** DMA mode IO operation ***
  119. ==============================
  120. [..]
  121. (+) Start the DAC peripheral using HAL_DAC_Start_DMA(), at this stage the user specify the length
  122. of data to be transferred at each end of conversion
  123. (+) At the middle of data transfer HAL_DAC_ConvHalfCpltCallbackCh1() or HAL_DACEx_ConvHalfCpltCallbackCh2()
  124. function is executed and user can add his own code by customization of function pointer
  125. HAL_DAC_ConvHalfCpltCallbackCh1() or HAL_DACEx_ConvHalfCpltCallbackCh2()
  126. (+) At The end of data transfer HAL_DAC_ConvCpltCallbackCh1() or HAL_DACEx_ConvHalfCpltCallbackCh2()
  127. function is executed and user can add his own code by customization of function pointer
  128. HAL_DAC_ConvCpltCallbackCh1() or HAL_DACEx_ConvHalfCpltCallbackCh2()
  129. (+) In case of transfer Error, HAL_DAC_ErrorCallbackCh1() function is executed and user can
  130. add his own code by customization of function pointer HAL_DAC_ErrorCallbackCh1
  131. (+) In case of DMA underrun, DAC interruption triggers and execute internal function HAL_DAC_IRQHandler.
  132. HAL_DAC_DMAUnderrunCallbackCh1() or HAL_DACEx_DMAUnderrunCallbackCh2()
  133. function is executed and user can add his own code by customization of function pointer
  134. HAL_DAC_DMAUnderrunCallbackCh1() or HAL_DACEx_DMAUnderrunCallbackCh2() and
  135. add his own code by customization of function pointer HAL_DAC_ErrorCallbackCh1()
  136. (+) Stop the DAC peripheral using HAL_DAC_Stop_DMA()
  137. *** DAC HAL driver macros list ***
  138. =============================================
  139. [..]
  140. Below the list of most used macros in DAC HAL driver.
  141. (+) __HAL_DAC_ENABLE : Enable the DAC peripheral
  142. (+) __HAL_DAC_DISABLE : Disable the DAC peripheral
  143. (+) __HAL_DAC_CLEAR_FLAG: Clear the DAC's pending flags
  144. (+) __HAL_DAC_GET_FLAG: Get the selected DAC's flag status
  145. [..]
  146. (@) You can refer to the DAC HAL driver header file for more useful macros
  147. @endverbatim
  148. ******************************************************************************
  149. * @attention
  150. *
  151. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  152. *
  153. * Redistribution and use in source and binary forms, with or without modification,
  154. * are permitted provided that the following conditions are met:
  155. * 1. Redistributions of source code must retain the above copyright notice,
  156. * this list of conditions and the following disclaimer.
  157. * 2. Redistributions in binary form must reproduce the above copyright notice,
  158. * this list of conditions and the following disclaimer in the documentation
  159. * and/or other materials provided with the distribution.
  160. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  161. * may be used to endorse or promote products derived from this software
  162. * without specific prior written permission.
  163. *
  164. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  165. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  166. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  167. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  168. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  169. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  170. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  171. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  172. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  173. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  174. *
  175. ******************************************************************************
  176. */
  177. /* Includes ------------------------------------------------------------------*/
  178. #include "stm32f0xx_hal.h"
  179. /** @addtogroup STM32F0xx_HAL_Driver
  180. * @{
  181. */
  182. #ifdef HAL_DAC_MODULE_ENABLED
  183. #if defined(STM32F051x8) || defined(STM32F058xx) || \
  184. defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
  185. defined(STM32F091xC) || defined (STM32F098xx)
  186. /** @defgroup DAC DAC
  187. * @brief DAC driver modules
  188. * @{
  189. */
  190. /* Private typedef -----------------------------------------------------------*/
  191. /* Private define ------------------------------------------------------------*/
  192. /* Private macro -------------------------------------------------------------*/
  193. /** @defgroup DAC_Private_Macros DAC Private Macros
  194. * @{
  195. */
  196. /**
  197. * @}
  198. */
  199. /* Private variables ---------------------------------------------------------*/
  200. /* Private function prototypes -----------------------------------------------*/
  201. /** @defgroup DAC_Private_Functions DAC Private Functions
  202. * @{
  203. */
  204. /**
  205. * @}
  206. */
  207. /* Exported functions -------------------------------------------------------*/
  208. /** @defgroup DAC_Exported_Functions DAC Exported Functions
  209. * @{
  210. */
  211. /** @defgroup DAC_Exported_Functions_Group1 Initialization and de-initialization functions
  212. * @brief Initialization and Configuration functions
  213. *
  214. @verbatim
  215. ==============================================================================
  216. ##### Initialization and de-initialization functions #####
  217. ==============================================================================
  218. [..] This section provides functions allowing to:
  219. (+) Initialize and configure the DAC.
  220. (+) De-initialize the DAC.
  221. @endverbatim
  222. * @{
  223. */
  224. /**
  225. * @brief Initialize the DAC peripheral according to the specified parameters
  226. * in the DAC_InitStruct and initialize the associated handle.
  227. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  228. * the configuration information for the specified DAC.
  229. * @retval HAL status
  230. */
  231. HAL_StatusTypeDef HAL_DAC_Init(DAC_HandleTypeDef* hdac)
  232. {
  233. /* Check DAC handle */
  234. if(hdac == NULL)
  235. {
  236. return HAL_ERROR;
  237. }
  238. /* Check the parameters */
  239. assert_param(IS_DAC_ALL_INSTANCE(hdac->Instance));
  240. if(hdac->State == HAL_DAC_STATE_RESET)
  241. {
  242. /* Allocate lock resource and initialize it */
  243. hdac->Lock = HAL_UNLOCKED;
  244. /* Init the low level hardware */
  245. HAL_DAC_MspInit(hdac);
  246. }
  247. /* Initialize the DAC state*/
  248. hdac->State = HAL_DAC_STATE_BUSY;
  249. /* Set DAC error code to none */
  250. hdac->ErrorCode = HAL_DAC_ERROR_NONE;
  251. /* Initialize the DAC state*/
  252. hdac->State = HAL_DAC_STATE_READY;
  253. /* Return function status */
  254. return HAL_OK;
  255. }
  256. /**
  257. * @brief Deinitialize the DAC peripheral registers to their default reset values.
  258. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  259. * the configuration information for the specified DAC.
  260. * @retval HAL status
  261. */
  262. HAL_StatusTypeDef HAL_DAC_DeInit(DAC_HandleTypeDef* hdac)
  263. {
  264. /* Check DAC handle */
  265. if(hdac == NULL)
  266. {
  267. return HAL_ERROR;
  268. }
  269. /* Check the parameters */
  270. assert_param(IS_DAC_ALL_INSTANCE(hdac->Instance));
  271. /* Change DAC state */
  272. hdac->State = HAL_DAC_STATE_BUSY;
  273. /* DeInit the low level hardware */
  274. HAL_DAC_MspDeInit(hdac);
  275. /* Set DAC error code to none */
  276. hdac->ErrorCode = HAL_DAC_ERROR_NONE;
  277. /* Change DAC state */
  278. hdac->State = HAL_DAC_STATE_RESET;
  279. /* Release Lock */
  280. __HAL_UNLOCK(hdac);
  281. /* Return function status */
  282. return HAL_OK;
  283. }
  284. /**
  285. * @brief Initialize the DAC MSP.
  286. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  287. * the configuration information for the specified DAC.
  288. * @retval None
  289. */
  290. __weak void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac)
  291. {
  292. /* Prevent unused argument(s) compilation warning */
  293. UNUSED(hdac);
  294. /* NOTE : This function should not be modified, when the callback is needed,
  295. the HAL_DAC_MspInit could be implemented in the user file
  296. */
  297. }
  298. /**
  299. * @brief DeInitialize the DAC MSP.
  300. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  301. * the configuration information for the specified DAC.
  302. * @retval None
  303. */
  304. __weak void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac)
  305. {
  306. /* Prevent unused argument(s) compilation warning */
  307. UNUSED(hdac);
  308. /* NOTE : This function should not be modified, when the callback is needed,
  309. the HAL_DAC_MspDeInit could be implemented in the user file
  310. */
  311. }
  312. /**
  313. * @}
  314. */
  315. /** @defgroup DAC_Exported_Functions_Group2 IO operation functions
  316. * @brief IO operation functions
  317. *
  318. @verbatim
  319. ==============================================================================
  320. ##### IO operation functions #####
  321. ==============================================================================
  322. [..] This section provides functions allowing to:
  323. (+) Start conversion.
  324. (+) Stop conversion.
  325. (+) Start conversion and enable DMA transfer.
  326. (+) Stop conversion and disable DMA transfer.
  327. (+) Set the specified data holding register value for DAC channel.
  328. @endverbatim
  329. * @{
  330. */
  331. /**
  332. * @brief Enables DAC and starts conversion of channel.
  333. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  334. * the configuration information for the specified DAC.
  335. * @param Channel The selected DAC channel.
  336. * This parameter can be one of the following values:
  337. * @arg DAC_CHANNEL_1: DAC Channel1 selected
  338. * @arg DAC_CHANNEL_2: DAC Channel2 selected
  339. * @retval HAL status
  340. */
  341. __weak HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel)
  342. {
  343. /* Prevent unused argument(s) compilation warning */
  344. UNUSED(hdac);
  345. UNUSED(Channel);
  346. /* Note : This function is defined into this file for library reference. */
  347. /* Function content is located into file stm32f0xx_hal_dac_ex.c */
  348. /* Return error status as not implemented here */
  349. return HAL_ERROR;
  350. }
  351. /**
  352. * @brief Disables DAC and stop conversion of channel.
  353. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  354. * the configuration information for the specified DAC.
  355. * @param Channel The selected DAC channel.
  356. * This parameter can be one of the following values:
  357. * @arg DAC_CHANNEL_1: DAC Channel1 selected
  358. * @arg DAC_CHANNEL_2: DAC Channel2 selected
  359. * @retval HAL status
  360. */
  361. HAL_StatusTypeDef HAL_DAC_Stop(DAC_HandleTypeDef* hdac, uint32_t Channel)
  362. {
  363. /* Check the parameters */
  364. assert_param(IS_DAC_CHANNEL(Channel));
  365. /* Disable the Peripheral */
  366. __HAL_DAC_DISABLE(hdac, Channel);
  367. /* Change DAC state */
  368. hdac->State = HAL_DAC_STATE_READY;
  369. /* Return function status */
  370. return HAL_OK;
  371. }
  372. /**
  373. * @brief Enables DAC and starts conversion of channel.
  374. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  375. * the configuration information for the specified DAC.
  376. * @param Channel The selected DAC channel.
  377. * This parameter can be one of the following values:
  378. * @arg DAC_CHANNEL_1: DAC Channel1 selected
  379. * @arg DAC_CHANNEL_2: DAC Channel2 selected
  380. * @param pData The destination peripheral Buffer address.
  381. * @param Length The length of data to be transferred from memory to DAC peripheral
  382. * @param Alignment Specifies the data alignment for DAC channel.
  383. * This parameter can be one of the following values:
  384. * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
  385. * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
  386. * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected
  387. * @retval HAL status
  388. */
  389. __weak HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t* pData, uint32_t Length, uint32_t Alignment)
  390. {
  391. /* Prevent unused argument(s) compilation warning */
  392. UNUSED(hdac);
  393. UNUSED(Channel);
  394. UNUSED(pData);
  395. UNUSED(Length);
  396. UNUSED(Alignment);
  397. /* Note : This function is defined into this file for library reference. */
  398. /* Function content is located into file stm32f0xx_hal_dac_ex.c */
  399. /* Return error status as not implemented here */
  400. return HAL_ERROR;
  401. }
  402. /**
  403. * @brief Disables DAC and stop conversion of channel.
  404. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  405. * the configuration information for the specified DAC.
  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 HAL status
  411. */
  412. HAL_StatusTypeDef HAL_DAC_Stop_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel)
  413. {
  414. HAL_StatusTypeDef status = HAL_OK;
  415. /* Check the parameters */
  416. assert_param(IS_DAC_CHANNEL(Channel));
  417. /* Disable the selected DAC channel DMA request */
  418. hdac->Instance->CR &= ~(DAC_CR_DMAEN1 << Channel);
  419. /* Disable the Peripheral */
  420. __HAL_DAC_DISABLE(hdac, Channel);
  421. /* Disable the DMA channel */
  422. /* Channel1 is used */
  423. if (Channel == DAC_CHANNEL_1)
  424. {
  425. /* Disable the DMA channel */
  426. status = HAL_DMA_Abort(hdac->DMA_Handle1);
  427. /* Disable the DAC DMA underrun interrupt */
  428. __HAL_DAC_DISABLE_IT(hdac, DAC_IT_DMAUDR1);
  429. }
  430. #if defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
  431. defined(STM32F091xC) || defined (STM32F098xx)
  432. /* Does not apply to STM32F051x8 & STM32F058xx */
  433. else /* Channel2 is used for */
  434. {
  435. /* Disable the DMA channel */
  436. status = HAL_DMA_Abort(hdac->DMA_Handle2);
  437. /* Disable the DAC DMA underrun interrupt */
  438. __HAL_DAC_DISABLE_IT(hdac, DAC_IT_DMAUDR2);
  439. }
  440. #endif /* STM32F071xB || STM32F072xB || STM32F078xx || */
  441. /* STM32F091xC || STM32F098xx */
  442. /* Check if DMA Channel effectively disabled */
  443. if (status != HAL_OK)
  444. {
  445. /* Update DAC state machine to error */
  446. hdac->State = HAL_DAC_STATE_ERROR;
  447. }
  448. else
  449. {
  450. /* Change DAC state */
  451. hdac->State = HAL_DAC_STATE_READY;
  452. }
  453. /* Return function status */
  454. return status;
  455. }
  456. /**
  457. * @brief Handles DAC interrupt request
  458. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  459. * the configuration information for the specified DAC.
  460. * @retval None
  461. */
  462. __weak void HAL_DAC_IRQHandler(DAC_HandleTypeDef* hdac)
  463. {
  464. /* Prevent unused argument(s) compilation warning */
  465. UNUSED(hdac);
  466. /* Note : This function is defined into this file for library reference. */
  467. /* Function content is located into file stm32f0xx_hal_dac_ex.c */
  468. }
  469. /**
  470. * @brief Set the specified data holding register value for DAC channel.
  471. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  472. * the configuration information for the specified DAC.
  473. * @param Channel The selected DAC channel.
  474. * This parameter can be one of the following values:
  475. * @arg DAC_CHANNEL_1: DAC Channel1 selected
  476. * @arg DAC_CHANNEL_2: DAC Channel2 selected
  477. * @param Alignment Specifies the data alignment.
  478. * This parameter can be one of the following values:
  479. * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected
  480. * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected
  481. * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected
  482. * @param Data Data to be loaded in the selected data holding register.
  483. * @retval HAL status
  484. */
  485. HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data)
  486. {
  487. __IO uint32_t tmp = 0;
  488. /* Check the parameters */
  489. assert_param(IS_DAC_CHANNEL(Channel));
  490. assert_param(IS_DAC_ALIGN(Alignment));
  491. assert_param(IS_DAC_DATA(Data));
  492. tmp = (uint32_t)hdac->Instance;
  493. if(Channel == DAC_CHANNEL_1)
  494. {
  495. tmp += DAC_DHR12R1_ALIGNMENT(Alignment);
  496. }
  497. else
  498. {
  499. tmp += DAC_DHR12R2_ALIGNMENT(Alignment);
  500. }
  501. /* Set the DAC channel1 selected data holding register */
  502. *(__IO uint32_t *) tmp = Data;
  503. /* Return function status */
  504. return HAL_OK;
  505. }
  506. /**
  507. * @brief Conversion complete callback in non blocking mode for Channel1
  508. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  509. * the configuration information for the specified DAC.
  510. * @retval None
  511. */
  512. __weak void HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef* hdac)
  513. {
  514. /* Prevent unused argument(s) compilation warning */
  515. UNUSED(hdac);
  516. /* NOTE : This function should not be modified, when the callback is needed,
  517. the HAL_DAC_ConvCpltCallbackCh1 could be implemented in the user file
  518. */
  519. }
  520. /**
  521. * @brief Conversion half DMA transfer callback in non-blocking mode for Channel1
  522. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  523. * the configuration information for the specified DAC.
  524. * @retval None
  525. */
  526. __weak void HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef* hdac)
  527. {
  528. /* Prevent unused argument(s) compilation warning */
  529. UNUSED(hdac);
  530. /* NOTE : This function should not be modified, when the callback is needed,
  531. the HAL_DAC_ConvHalfCpltCallbackCh1 could be implemented in the user file
  532. */
  533. }
  534. /**
  535. * @brief Error DAC callback for Channel1.
  536. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  537. * the configuration information for the specified DAC.
  538. * @retval None
  539. */
  540. __weak void HAL_DAC_ErrorCallbackCh1(DAC_HandleTypeDef *hdac)
  541. {
  542. /* Prevent unused argument(s) compilation warning */
  543. UNUSED(hdac);
  544. /* NOTE : This function should not be modified, when the callback is needed,
  545. the HAL_DAC_ErrorCallbackCh1 could be implemented in the user file
  546. */
  547. }
  548. /**
  549. * @brief DMA underrun DAC callback for channel1.
  550. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  551. * the configuration information for the specified DAC.
  552. * @retval None
  553. */
  554. __weak void HAL_DAC_DMAUnderrunCallbackCh1(DAC_HandleTypeDef *hdac)
  555. {
  556. /* Prevent unused argument(s) compilation warning */
  557. UNUSED(hdac);
  558. /* NOTE : This function should not be modified, when the callback is needed,
  559. the HAL_DAC_DMAUnderrunCallbackCh1 could be implemented in the user file
  560. */
  561. }
  562. /**
  563. * @}
  564. */
  565. /** @defgroup DAC_Exported_Functions_Group3 Peripheral Control functions
  566. * @brief Peripheral Control functions
  567. *
  568. @verbatim
  569. ==============================================================================
  570. ##### Peripheral Control functions #####
  571. ==============================================================================
  572. [..] This section provides functions allowing to:
  573. (+) Configure channels.
  574. (+) Get result of conversion.
  575. @endverbatim
  576. * @{
  577. */
  578. /**
  579. * @brief Returns the last data output value of the selected DAC channel.
  580. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  581. * the configuration information for the specified DAC.
  582. * @param Channel The selected DAC channel.
  583. * This parameter can be one of the following values:
  584. * @arg DAC_CHANNEL_1: DAC Channel1 selected
  585. * @arg DAC_CHANNEL_2: DAC Channel2 selected
  586. * @retval The selected DAC channel data output value.
  587. */
  588. __weak uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef* hdac, uint32_t Channel)
  589. {
  590. /* Prevent unused argument(s) compilation warning */
  591. UNUSED(hdac);
  592. UNUSED(Channel);
  593. /* Note : This function is defined into this file for library reference. */
  594. /* Function content is located into file stm32f0xx_hal_dac_ex.c */
  595. /* Return error status as not implemented here */
  596. return HAL_ERROR;
  597. }
  598. /**
  599. * @brief Configures the selected DAC channel.
  600. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  601. * the configuration information for the specified DAC.
  602. * @param sConfig DAC configuration structure.
  603. * @param Channel The selected DAC channel.
  604. * This parameter can be one of the following values:
  605. * @arg DAC_CHANNEL_1: DAC Channel1 selected
  606. * @arg DAC_CHANNEL_2: DAC Channel2 selected
  607. * @retval HAL status
  608. */
  609. __weak HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel)
  610. {
  611. /* Prevent unused argument(s) compilation warning */
  612. UNUSED(hdac);
  613. UNUSED(sConfig);
  614. UNUSED(Channel);
  615. /* Note : This function is defined into this file for library reference. */
  616. /* Function content is located into file stm32f0xx_hal_dac_ex.c */
  617. /* Return error status as not implemented here */
  618. return HAL_ERROR;
  619. }
  620. /**
  621. * @}
  622. */
  623. /** @defgroup DAC_Exported_Functions_Group4 Peripheral State and Errors functions
  624. * @brief Peripheral State and Errors functions
  625. *
  626. @verbatim
  627. ==============================================================================
  628. ##### Peripheral State and Errors functions #####
  629. ==============================================================================
  630. [..]
  631. This subsection provides functions allowing to
  632. (+) Check the DAC state.
  633. (+) Check the DAC Errors.
  634. @endverbatim
  635. * @{
  636. */
  637. /**
  638. * @brief return the DAC handle state
  639. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  640. * the configuration information for the specified DAC.
  641. * @retval HAL state
  642. */
  643. HAL_DAC_StateTypeDef HAL_DAC_GetState(DAC_HandleTypeDef* hdac)
  644. {
  645. /* Return DAC handle state */
  646. return hdac->State;
  647. }
  648. /**
  649. * @brief Return the DAC error code
  650. * @param hdac pointer to a DAC_HandleTypeDef structure that contains
  651. * the configuration information for the specified DAC.
  652. * @retval DAC Error Code
  653. */
  654. uint32_t HAL_DAC_GetError(DAC_HandleTypeDef *hdac)
  655. {
  656. return hdac->ErrorCode;
  657. }
  658. /**
  659. * @}
  660. */
  661. /**
  662. * @}
  663. */
  664. /**
  665. * @}
  666. */
  667. #endif /* STM32F051x8 || STM32F058xx || */
  668. /* STM32F071xB || STM32F072xB || STM32F078xx || */
  669. /* STM32F091xC || STM32F098xx */
  670. #endif /* HAL_DAC_MODULE_ENABLED */
  671. /**
  672. * @}
  673. */
  674. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/