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.
 
 
 

645 lines
24 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_dac_ex.c
  4. * @author MCD Application Team
  5. * @version V1.7.2
  6. * @date 16-June-2017
  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) 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 "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. #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \
  176. defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx)
  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. #endif /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */
  272. /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */
  273. /**
  274. * @brief Run the self calibration of one DAC channel.
  275. * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
  276. * the configuration information for the specified DAC.
  277. * @param sConfig: DAC channel configuration structure.
  278. * @param Channel: The selected DAC channel.
  279. * This parameter can be one of the following values:
  280. * @arg DAC_CHANNEL_1: DAC Channel1 selected
  281. * @arg DAC_CHANNEL_2: DAC Channel2 selected
  282. * @retval Updates DAC_TrimmingValue. , DAC_UserTrimming set to DAC_UserTrimming
  283. * @retval HAL status
  284. * @note Calibration runs about 7 ms.
  285. */
  286. HAL_StatusTypeDef HAL_DACEx_SelfCalibrate (DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel)
  287. {
  288. HAL_StatusTypeDef status = HAL_OK;
  289. __IO uint32_t tmp = 0;
  290. uint32_t trimmingvalue = 0;
  291. uint32_t delta;
  292. /* store/restore channel configuration structure purpose */
  293. uint32_t oldmodeconfiguration = 0;
  294. /* Check the parameters */
  295. assert_param(IS_DAC_CHANNEL(Channel));
  296. /* Check the DAC handle allocation */
  297. /* Check if DAC running */
  298. if((hdac == NULL) || (hdac->State == HAL_DAC_STATE_BUSY))
  299. {
  300. status = HAL_ERROR;
  301. }
  302. else
  303. {
  304. /* Process locked */
  305. __HAL_LOCK(hdac);
  306. /* Store configuration */
  307. oldmodeconfiguration = (hdac->Instance->MCR & (DAC_MCR_MODE1 << Channel));
  308. /* Disable the selected DAC channel */
  309. CLEAR_BIT ((hdac->Instance->CR), (DAC_CR_EN1 << Channel));
  310. /* Set mode in MCR for calibration */
  311. MODIFY_REG(hdac->Instance->MCR, (DAC_MCR_MODE1 << Channel), 0);
  312. /* Set DAC Channel1 DHR register to the middle value */
  313. tmp = (uint32_t)hdac->Instance;
  314. #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \
  315. defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx)
  316. if(Channel == DAC_CHANNEL_1)
  317. {
  318. tmp += DAC_DHR12R1_ALIGNMENT(DAC_ALIGN_12B_R);
  319. }
  320. else
  321. {
  322. tmp += DAC_DHR12R2_ALIGNMENT(DAC_ALIGN_12B_R);
  323. }
  324. #endif /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */
  325. /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */
  326. #if defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx)
  327. tmp += DAC_DHR12R1_ALIGNMENT(DAC_ALIGN_12B_R);
  328. #endif /* STM32L451xx STM32L452xx STM32L462xx */
  329. *(__IO uint32_t *) tmp = 0x0800;
  330. /* Enable the selected DAC channel calibration */
  331. /* i.e. set DAC_CR_CENx bit */
  332. SET_BIT ((hdac->Instance->CR), (DAC_CR_CEN1 << Channel));
  333. /* Init trimming counter */
  334. /* Medium value */
  335. trimmingvalue = 16;
  336. delta = 8;
  337. while (delta != 0)
  338. {
  339. /* Set candidate trimming */
  340. MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1<<Channel), (trimmingvalue<<Channel));
  341. /* tOFFTRIMmax delay x ms as per datasheet (electrical characteristics */
  342. /* i.e. minimum time needed between two calibration steps */
  343. HAL_Delay(1);
  344. if ((hdac->Instance->SR & (DAC_SR_CAL_FLAG1<<Channel)) == (DAC_SR_CAL_FLAG1<<Channel))
  345. {
  346. /* DAC_SR_CAL_FLAGx is HIGH try higher trimming */
  347. trimmingvalue -= delta;
  348. }
  349. else
  350. {
  351. /* DAC_SR_CAL_FLAGx is LOW try lower trimming */
  352. trimmingvalue += delta;
  353. }
  354. delta >>= 1;
  355. }
  356. /* Still need to check if right calibration is current value or one step below */
  357. /* Indeed the first value that causes the DAC_SR_CAL_FLAGx bit to change from 0 to 1 */
  358. /* Set candidate trimming */
  359. MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1<<Channel), (trimmingvalue<<Channel));
  360. /* tOFFTRIMmax delay x ms as per datasheet (electrical characteristics */
  361. /* i.e. minimum time needed between two calibration steps */
  362. HAL_Delay(1);
  363. if ((hdac->Instance->SR & (DAC_SR_CAL_FLAG1<<Channel)) == RESET)
  364. {
  365. /* OPAMP_CSR_OUTCAL is actually one value more */
  366. trimmingvalue++;
  367. /* Set right trimming */
  368. MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1<<Channel), (trimmingvalue<<Channel));
  369. }
  370. /* Disable the selected DAC channel calibration */
  371. /* i.e. clear DAC_CR_CENx bit */
  372. CLEAR_BIT ((hdac->Instance->CR), (DAC_CR_CEN1 << Channel));
  373. sConfig->DAC_TrimmingValue = trimmingvalue;
  374. sConfig->DAC_UserTrimming = DAC_TRIMMING_USER;
  375. /* Restore configuration */
  376. MODIFY_REG(hdac->Instance->MCR, (DAC_MCR_MODE1 << Channel), oldmodeconfiguration);
  377. /* Process unlocked */
  378. __HAL_UNLOCK(hdac);
  379. }
  380. return status;
  381. }
  382. /**
  383. * @brief Set the trimming mode and trimming value (user trimming mode applied).
  384. * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
  385. * the configuration information for the specified DAC.
  386. * @param sConfig: DAC configuration structure updated with new DAC trimming value.
  387. * @param Channel: The selected DAC channel.
  388. * This parameter can be one of the following values:
  389. * @arg DAC_CHANNEL_1: DAC Channel1 selected
  390. * @arg DAC_CHANNEL_2: DAC Channel2 selected
  391. * @param NewTrimmingValue: DAC new trimming value
  392. * @retval HAL status
  393. */
  394. HAL_StatusTypeDef HAL_DACEx_SetUserTrimming (DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel, uint32_t NewTrimmingValue)
  395. {
  396. HAL_StatusTypeDef status = HAL_OK;
  397. /* Check the parameters */
  398. assert_param(IS_DAC_CHANNEL(Channel));
  399. assert_param(IS_DAC_NEWTRIMMINGVALUE(NewTrimmingValue));
  400. /* Check the DAC handle allocation */
  401. if(hdac == NULL)
  402. {
  403. status = HAL_ERROR;
  404. }
  405. else
  406. {
  407. /* Process locked */
  408. __HAL_LOCK(hdac);
  409. /* Set new trimming */
  410. MODIFY_REG(hdac->Instance->CCR, (DAC_CCR_OTRIM1<<Channel), (NewTrimmingValue<<Channel));
  411. /* Update trimming mode */
  412. sConfig->DAC_UserTrimming = DAC_TRIMMING_USER;
  413. sConfig->DAC_TrimmingValue = NewTrimmingValue;
  414. /* Process unlocked */
  415. __HAL_UNLOCK(hdac);
  416. }
  417. return status;
  418. }
  419. /**
  420. * @brief Return the DAC trimming value.
  421. * @param hdac : DAC handle
  422. * @param Channel: The selected DAC channel.
  423. * This parameter can be one of the following values:
  424. * @arg DAC_CHANNEL_1: DAC Channel1 selected
  425. * @arg DAC_CHANNEL_2: DAC Channel2 selected
  426. * @retval Trimming value : range: 0->31
  427. *
  428. */
  429. uint32_t HAL_DACEx_GetTrimOffset (DAC_HandleTypeDef *hdac, uint32_t Channel)
  430. {
  431. uint32_t trimmingvalue = 0;
  432. /* Check the DAC handle allocation */
  433. /* And not in Reset state */
  434. if((hdac == NULL) || (hdac->State == HAL_DAC_STATE_RESET))
  435. {
  436. return HAL_ERROR;
  437. }
  438. else
  439. {
  440. /* Check the parameter */
  441. assert_param(IS_DAC_CHANNEL(Channel));
  442. /* Retrieve trimming */
  443. trimmingvalue = ((hdac->Instance->CCR & (DAC_CCR_OTRIM1 << Channel)) >> Channel);
  444. }
  445. return trimmingvalue;
  446. }
  447. /**
  448. * @}
  449. */
  450. #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \
  451. defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx)
  452. /** @defgroup DACEx_Exported_Functions_Group3 Peripheral Control functions
  453. * @brief Extended Peripheral Control functions
  454. *
  455. @verbatim
  456. ==============================================================================
  457. ##### Peripheral Control functions #####
  458. ==============================================================================
  459. [..] This section provides functions allowing to:
  460. (+) Configure channels.
  461. (+) Set the specified data holding register value for DAC channel.
  462. @endverbatim
  463. * @{
  464. */
  465. /**
  466. * @brief Return the last data output value of the selected DAC channel.
  467. * @param hdac: pointer to a DAC_HandleTypeDef structure that contains
  468. * the configuration information for the specified DAC.
  469. * @retval The selected DAC channel data output value.
  470. */
  471. uint32_t HAL_DACEx_DualGetValue(DAC_HandleTypeDef* hdac)
  472. {
  473. uint32_t tmp = 0;
  474. tmp |= hdac->Instance->DOR1;
  475. tmp |= hdac->Instance->DOR2 << 16;
  476. /* Returns the DAC channel data output register value */
  477. return tmp;
  478. }
  479. /**
  480. * @}
  481. */
  482. #endif /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */
  483. /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */
  484. /**
  485. * @}
  486. */
  487. #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \
  488. defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx)
  489. /* Private functions ---------------------------------------------------------*/
  490. /** @defgroup DACEx_Private_Functions DACEx private functions
  491. * @brief Extended private functions
  492. * @{
  493. */
  494. /**
  495. * @brief DMA conversion complete callback.
  496. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  497. * the configuration information for the specified DMA module.
  498. * @retval None
  499. */
  500. void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma)
  501. {
  502. DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  503. HAL_DACEx_ConvCpltCallbackCh2(hdac);
  504. hdac->State= HAL_DAC_STATE_READY;
  505. }
  506. /**
  507. * @brief DMA half transfer complete callback.
  508. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  509. * the configuration information for the specified DMA module.
  510. * @retval None
  511. */
  512. void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma)
  513. {
  514. DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  515. /* Conversion complete callback */
  516. HAL_DACEx_ConvHalfCpltCallbackCh2(hdac);
  517. }
  518. /**
  519. * @brief DMA error callback.
  520. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  521. * the configuration information for the specified DMA module.
  522. * @retval None
  523. */
  524. void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma)
  525. {
  526. DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  527. /* Set DAC error code to DMA error */
  528. hdac->ErrorCode |= HAL_DAC_ERROR_DMA;
  529. HAL_DACEx_ErrorCallbackCh2(hdac);
  530. hdac->State= HAL_DAC_STATE_READY;
  531. }
  532. /**
  533. * @}
  534. */
  535. #endif /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */
  536. /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */
  537. #endif /* HAL_DAC_MODULE_ENABLED */
  538. /**
  539. * @}
  540. */
  541. /**
  542. * @}
  543. */
  544. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/