stm32f1xx_ll_dac.h 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349
  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx_ll_dac.h
  4. * @author MCD Application Team
  5. * @brief Header file of DAC LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2016 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef STM32F1xx_LL_DAC_H
  20. #define STM32F1xx_LL_DAC_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32f1xx.h"
  26. /** @addtogroup STM32F1xx_LL_Driver
  27. * @{
  28. */
  29. #if defined(DAC)
  30. /** @defgroup DAC_LL DAC
  31. * @{
  32. */
  33. /* Private types -------------------------------------------------------------*/
  34. /* Private variables ---------------------------------------------------------*/
  35. /* Private constants ---------------------------------------------------------*/
  36. /** @defgroup DAC_LL_Private_Constants DAC Private Constants
  37. * @{
  38. */
  39. /* Internal masks for DAC channels definition */
  40. /* To select into literal LL_DAC_CHANNEL_x the relevant bits for: */
  41. /* - channel bits position into registers CR, MCR, CCR, SHHR, SHRR */
  42. /* - channel bits position into register SWTRIG */
  43. /* - channel register offset of data holding register DHRx */
  44. /* - channel register offset of data output register DORx */
  45. #define DAC_CR_CH1_BITOFFSET 0UL /* Position of channel bits into registers
  46. CR, MCR, CCR, SHHR, SHRR of channel 1 */
  47. #define DAC_CR_CH2_BITOFFSET 16UL /* Position of channel bits into registers
  48. CR, MCR, CCR, SHHR, SHRR of channel 2 */
  49. #define DAC_CR_CHX_BITOFFSET_MASK (DAC_CR_CH1_BITOFFSET | DAC_CR_CH2_BITOFFSET)
  50. #define DAC_SWTR_CH1 (DAC_SWTRIGR_SWTRIG1) /* Channel bit into register SWTRIGR of channel 1. */
  51. #define DAC_SWTR_CH2 (DAC_SWTRIGR_SWTRIG2) /* Channel bit into register SWTRIGR of channel 2. */
  52. #define DAC_SWTR_CHX_MASK (DAC_SWTR_CH1 | DAC_SWTR_CH2)
  53. #define DAC_REG_DHR12R1_REGOFFSET 0x00000000UL /* Register DHR12Rx channel 1 taken as reference */
  54. #define DAC_REG_DHR12L1_REGOFFSET 0x00100000UL /* Register offset of DHR12Lx channel 1 versus
  55. DHR12Rx channel 1 (shifted left of 20 bits) */
  56. #define DAC_REG_DHR8R1_REGOFFSET 0x02000000UL /* Register offset of DHR8Rx channel 1 versus
  57. DHR12Rx channel 1 (shifted left of 24 bits) */
  58. #define DAC_REG_DHR12R2_REGOFFSET 0x00030000UL /* Register offset of DHR12Rx channel 2 versus
  59. DHR12Rx channel 1 (shifted left of 16 bits) */
  60. #define DAC_REG_DHR12L2_REGOFFSET 0x00400000UL /* Register offset of DHR12Lx channel 2 versus
  61. DHR12Rx channel 1 (shifted left of 20 bits) */
  62. #define DAC_REG_DHR8R2_REGOFFSET 0x05000000UL /* Register offset of DHR8Rx channel 2 versus
  63. DHR12Rx channel 1 (shifted left of 24 bits) */
  64. #define DAC_REG_DHR12RX_REGOFFSET_MASK 0x000F0000UL
  65. #define DAC_REG_DHR12LX_REGOFFSET_MASK 0x00F00000UL
  66. #define DAC_REG_DHR8RX_REGOFFSET_MASK 0x0F000000UL
  67. #define DAC_REG_DHRX_REGOFFSET_MASK (DAC_REG_DHR12RX_REGOFFSET_MASK\
  68. | DAC_REG_DHR12LX_REGOFFSET_MASK | DAC_REG_DHR8RX_REGOFFSET_MASK)
  69. #define DAC_REG_DOR1_REGOFFSET 0x00000000UL /* Register DORx channel 1 taken as reference */
  70. #define DAC_REG_DOR2_REGOFFSET 0x10000000UL /* Register offset of DORx channel 1 versus
  71. DORx channel 2 (shifted left of 28 bits) */
  72. #define DAC_REG_DORX_REGOFFSET_MASK (DAC_REG_DOR1_REGOFFSET | DAC_REG_DOR2_REGOFFSET)
  73. #define DAC_REG_DHR_REGOFFSET_MASK_POSBIT0 0x0000000FUL /* Mask of data hold registers offset (DHR12Rx,
  74. DHR12Lx, DHR8Rx, ...) when shifted to position 0 */
  75. #define DAC_REG_DORX_REGOFFSET_MASK_POSBIT0 0x00000001UL /* Mask of DORx registers offset when shifted
  76. to position 0 */
  77. #define DAC_REG_SHSRX_REGOFFSET_MASK_POSBIT0 0x00000001UL /* Mask of SHSRx registers offset when shifted
  78. to position 0 */
  79. #define DAC_REG_DHR12RX_REGOFFSET_BITOFFSET_POS 16UL /* Position of bits register offset of DHR12Rx
  80. channel 1 or 2 versus DHR12Rx channel 1
  81. (shifted left of 16 bits) */
  82. #define DAC_REG_DHR12LX_REGOFFSET_BITOFFSET_POS 20UL /* Position of bits register offset of DHR12Lx
  83. channel 1 or 2 versus DHR12Rx channel 1
  84. (shifted left of 20 bits) */
  85. #define DAC_REG_DHR8RX_REGOFFSET_BITOFFSET_POS 24UL /* Position of bits register offset of DHR8Rx
  86. channel 1 or 2 versus DHR12Rx channel 1
  87. (shifted left of 24 bits) */
  88. #define DAC_REG_DORX_REGOFFSET_BITOFFSET_POS 28UL /* Position of bits register offset of DORx
  89. channel 1 or 2 versus DORx channel 1
  90. (shifted left of 28 bits) */
  91. /* DAC registers bits positions */
  92. #define DAC_DHR12RD_DACC2DHR_BITOFFSET_POS DAC_DHR12RD_DACC2DHR_Pos
  93. #define DAC_DHR12LD_DACC2DHR_BITOFFSET_POS DAC_DHR12LD_DACC2DHR_Pos
  94. #define DAC_DHR8RD_DACC2DHR_BITOFFSET_POS DAC_DHR8RD_DACC2DHR_Pos
  95. /* Miscellaneous data */
  96. #define DAC_DIGITAL_SCALE_12BITS 4095UL /* Full-scale digital value with a resolution of 12
  97. bits (voltage range determined by analog voltage
  98. references Vref+ and Vref-, refer to reference manual) */
  99. /**
  100. * @}
  101. */
  102. /* Private macros ------------------------------------------------------------*/
  103. /** @defgroup DAC_LL_Private_Macros DAC Private Macros
  104. * @{
  105. */
  106. /**
  107. * @brief Driver macro reserved for internal use: set a pointer to
  108. * a register from a register basis from which an offset
  109. * is applied.
  110. * @param __REG__ Register basis from which the offset is applied.
  111. * @param __REG_OFFFSET__ Offset to be applied (unit: number of registers).
  112. * @retval Pointer to register address
  113. */
  114. #define __DAC_PTR_REG_OFFSET(__REG__, __REG_OFFFSET__) \
  115. ((uint32_t *)((uint32_t) ((uint32_t)(&(__REG__)) + ((__REG_OFFFSET__) << 2UL))))
  116. /**
  117. * @}
  118. */
  119. /* Exported types ------------------------------------------------------------*/
  120. #if defined(USE_FULL_LL_DRIVER)
  121. /** @defgroup DAC_LL_ES_INIT DAC Exported Init structure
  122. * @{
  123. */
  124. /**
  125. * @brief Structure definition of some features of DAC instance.
  126. */
  127. typedef struct
  128. {
  129. uint32_t TriggerSource; /*!< Set the conversion trigger source for the selected DAC channel:
  130. internal (SW start) or from external peripheral
  131. (timer event, external interrupt line).
  132. This parameter can be a value of @ref DAC_LL_EC_TRIGGER_SOURCE
  133. This feature can be modified afterwards using unitary
  134. function @ref LL_DAC_SetTriggerSource(). */
  135. uint32_t WaveAutoGeneration; /*!< Set the waveform automatic generation mode for the selected DAC channel.
  136. This parameter can be a value of @ref DAC_LL_EC_WAVE_AUTO_GENERATION_MODE
  137. This feature can be modified afterwards using unitary
  138. function @ref LL_DAC_SetWaveAutoGeneration(). */
  139. uint32_t WaveAutoGenerationConfig; /*!< Set the waveform automatic generation mode for the selected DAC channel.
  140. If waveform automatic generation mode is set to noise, this parameter
  141. can be a value of @ref DAC_LL_EC_WAVE_NOISE_LFSR_UNMASK_BITS
  142. If waveform automatic generation mode is set to triangle,
  143. this parameter can be a value of @ref DAC_LL_EC_WAVE_TRIANGLE_AMPLITUDE
  144. @note If waveform automatic generation mode is disabled,
  145. this parameter is discarded.
  146. This feature can be modified afterwards using unitary
  147. function @ref LL_DAC_SetWaveNoiseLFSR(),
  148. @ref LL_DAC_SetWaveTriangleAmplitude()
  149. depending on the wave automatic generation selected. */
  150. uint32_t OutputBuffer; /*!< Set the output buffer for the selected DAC channel.
  151. This parameter can be a value of @ref DAC_LL_EC_OUTPUT_BUFFER
  152. This feature can be modified afterwards using unitary
  153. function @ref LL_DAC_SetOutputBuffer(). */
  154. } LL_DAC_InitTypeDef;
  155. /**
  156. * @}
  157. */
  158. #endif /* USE_FULL_LL_DRIVER */
  159. /* Exported constants --------------------------------------------------------*/
  160. /** @defgroup DAC_LL_Exported_Constants DAC Exported Constants
  161. * @{
  162. */
  163. /** @defgroup DAC_LL_EC_GET_FLAG DAC flags
  164. * @brief Flags defines which can be used with LL_DAC_ReadReg function
  165. * @{
  166. */
  167. /* DAC channel 1 flags */
  168. #define LL_DAC_FLAG_DMAUDR1 (DAC_SR_DMAUDR1) /*!< DAC channel 1 flag DMA underrun */
  169. /* DAC channel 2 flags */
  170. #define LL_DAC_FLAG_DMAUDR2 (DAC_SR_DMAUDR2) /*!< DAC channel 2 flag DMA underrun */
  171. /**
  172. * @}
  173. */
  174. /** @defgroup DAC_LL_EC_IT DAC interruptions
  175. * @brief IT defines which can be used with LL_DAC_ReadReg and LL_DAC_WriteReg functions
  176. * @{
  177. */
  178. #define LL_DAC_IT_DMAUDRIE1 (DAC_CR_DMAUDRIE1) /*!< DAC channel 1 interruption DMA underrun */
  179. #define LL_DAC_IT_DMAUDRIE2 (DAC_CR_DMAUDRIE2) /*!< DAC channel 2 interruption DMA underrun */
  180. /**
  181. * @}
  182. */
  183. /** @defgroup DAC_LL_EC_CHANNEL DAC channels
  184. * @{
  185. */
  186. #define LL_DAC_CHANNEL_1 (DAC_REG_DOR1_REGOFFSET | DAC_REG_DHR12R1_REGOFFSET | DAC_REG_DHR12L1_REGOFFSET | DAC_REG_DHR8R1_REGOFFSET | DAC_CR_CH1_BITOFFSET | DAC_SWTR_CH1) /*!< DAC channel 1 */
  187. #define LL_DAC_CHANNEL_2 (DAC_REG_DOR2_REGOFFSET | DAC_REG_DHR12R2_REGOFFSET | DAC_REG_DHR12L2_REGOFFSET | DAC_REG_DHR8R2_REGOFFSET | DAC_CR_CH2_BITOFFSET | DAC_SWTR_CH2) /*!< DAC channel 2 */
  188. /**
  189. * @}
  190. */
  191. /** @defgroup DAC_LL_EC_TRIGGER_SOURCE DAC trigger source
  192. * @{
  193. */
  194. #define LL_DAC_TRIG_SOFTWARE (DAC_CR_TSEL1_2 | DAC_CR_TSEL1_1 | DAC_CR_TSEL1_0) /*!< DAC channel conversion trigger internal (SW start) */
  195. #define LL_DAC_TRIG_EXT_TIM3_TRGO ( DAC_CR_TSEL1_0) /*!< DAC channel conversion trigger from external peripheral: TIM3 TRGO. */
  196. #define LL_DAC_TRIG_EXT_TIM15_TRGO ( DAC_CR_TSEL1_1 | DAC_CR_TSEL1_0) /*!< DAC channel conversion trigger from external peripheral: TIM15 TRGO. */
  197. #define LL_DAC_TRIG_EXT_TIM2_TRGO (DAC_CR_TSEL1_2 ) /*!< DAC channel conversion trigger from external peripheral: TIM2 TRGO. */
  198. #define LL_DAC_TRIG_EXT_TIM8_TRGO ( DAC_CR_TSEL1_0) /*!< DAC channel conversion trigger from external peripheral: TIM8 TRGO. */
  199. #define LL_DAC_TRIG_EXT_TIM4_TRGO (DAC_CR_TSEL1_2 | DAC_CR_TSEL1_0) /*!< DAC channel conversion trigger from external peripheral: TIM4 TRGO. */
  200. #define LL_DAC_TRIG_EXT_TIM6_TRGO 0x00000000UL /*!< DAC channel conversion trigger from external peripheral: TIM6 TRGO. */
  201. #define LL_DAC_TRIG_EXT_TIM7_TRGO ( DAC_CR_TSEL1_1 ) /*!< DAC channel conversion trigger from external peripheral: TIM7 TRGO. */
  202. #define LL_DAC_TRIG_EXT_TIM5_TRGO ( DAC_CR_TSEL1_1 | DAC_CR_TSEL1_0) /*!< DAC channel conversion trigger from external peripheral: TIM5 TRGO. */
  203. #define LL_DAC_TRIG_EXT_EXTI_LINE9 (DAC_CR_TSEL1_2 | DAC_CR_TSEL1_1 ) /*!< DAC channel conversion trigger from external peripheral: external interrupt line 9. */
  204. /**
  205. * @}
  206. */
  207. /** @defgroup DAC_LL_EC_WAVE_AUTO_GENERATION_MODE DAC waveform automatic generation mode
  208. * @{
  209. */
  210. #define LL_DAC_WAVE_AUTO_GENERATION_NONE 0x00000000UL /*!< DAC channel wave auto generation mode disabled. */
  211. #define LL_DAC_WAVE_AUTO_GENERATION_NOISE ( DAC_CR_WAVE1_0) /*!< DAC channel wave auto generation mode enabled, set generated noise waveform. */
  212. #define LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE (DAC_CR_WAVE1_1 ) /*!< DAC channel wave auto generation mode enabled, set generated triangle waveform. */
  213. /**
  214. * @}
  215. */
  216. /** @defgroup DAC_LL_EC_WAVE_NOISE_LFSR_UNMASK_BITS DAC wave generation - Noise LFSR unmask bits
  217. * @{
  218. */
  219. #define LL_DAC_NOISE_LFSR_UNMASK_BIT0 0x00000000UL /*!< Noise wave generation, unmask LFSR bit0, for the selected DAC channel */
  220. #define LL_DAC_NOISE_LFSR_UNMASK_BITS1_0 ( DAC_CR_MAMP1_0) /*!< Noise wave generation, unmask LFSR bits[1:0], for the selected DAC channel */
  221. #define LL_DAC_NOISE_LFSR_UNMASK_BITS2_0 ( DAC_CR_MAMP1_1 ) /*!< Noise wave generation, unmask LFSR bits[2:0], for the selected DAC channel */
  222. #define LL_DAC_NOISE_LFSR_UNMASK_BITS3_0 ( DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Noise wave generation, unmask LFSR bits[3:0], for the selected DAC channel */
  223. #define LL_DAC_NOISE_LFSR_UNMASK_BITS4_0 ( DAC_CR_MAMP1_2 ) /*!< Noise wave generation, unmask LFSR bits[4:0], for the selected DAC channel */
  224. #define LL_DAC_NOISE_LFSR_UNMASK_BITS5_0 ( DAC_CR_MAMP1_2 | DAC_CR_MAMP1_0) /*!< Noise wave generation, unmask LFSR bits[5:0], for the selected DAC channel */
  225. #define LL_DAC_NOISE_LFSR_UNMASK_BITS6_0 ( DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1 ) /*!< Noise wave generation, unmask LFSR bits[6:0], for the selected DAC channel */
  226. #define LL_DAC_NOISE_LFSR_UNMASK_BITS7_0 ( DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Noise wave generation, unmask LFSR bits[7:0], for the selected DAC channel */
  227. #define LL_DAC_NOISE_LFSR_UNMASK_BITS8_0 (DAC_CR_MAMP1_3 ) /*!< Noise wave generation, unmask LFSR bits[8:0], for the selected DAC channel */
  228. #define LL_DAC_NOISE_LFSR_UNMASK_BITS9_0 (DAC_CR_MAMP1_3 | DAC_CR_MAMP1_0) /*!< Noise wave generation, unmask LFSR bits[9:0], for the selected DAC channel */
  229. #define LL_DAC_NOISE_LFSR_UNMASK_BITS10_0 (DAC_CR_MAMP1_3 | DAC_CR_MAMP1_1 ) /*!< Noise wave generation, unmask LFSR bits[10:0], for the selected DAC channel */
  230. #define LL_DAC_NOISE_LFSR_UNMASK_BITS11_0 (DAC_CR_MAMP1_3 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Noise wave generation, unmask LFSR bits[11:0], for the selected DAC channel */
  231. /**
  232. * @}
  233. */
  234. /** @defgroup DAC_LL_EC_WAVE_TRIANGLE_AMPLITUDE DAC wave generation - Triangle amplitude
  235. * @{
  236. */
  237. #define LL_DAC_TRIANGLE_AMPLITUDE_1 0x00000000UL /*!< Triangle wave generation, amplitude of 1 LSB of DAC output range, for the selected DAC channel */
  238. #define LL_DAC_TRIANGLE_AMPLITUDE_3 ( DAC_CR_MAMP1_0) /*!< Triangle wave generation, amplitude of 3 LSB of DAC output range, for the selected DAC channel */
  239. #define LL_DAC_TRIANGLE_AMPLITUDE_7 ( DAC_CR_MAMP1_1 ) /*!< Triangle wave generation, amplitude of 7 LSB of DAC output range, for the selected DAC channel */
  240. #define LL_DAC_TRIANGLE_AMPLITUDE_15 ( DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Triangle wave generation, amplitude of 15 LSB of DAC output range, for the selected DAC channel */
  241. #define LL_DAC_TRIANGLE_AMPLITUDE_31 ( DAC_CR_MAMP1_2 ) /*!< Triangle wave generation, amplitude of 31 LSB of DAC output range, for the selected DAC channel */
  242. #define LL_DAC_TRIANGLE_AMPLITUDE_63 ( DAC_CR_MAMP1_2 | DAC_CR_MAMP1_0) /*!< Triangle wave generation, amplitude of 63 LSB of DAC output range, for the selected DAC channel */
  243. #define LL_DAC_TRIANGLE_AMPLITUDE_127 ( DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1 ) /*!< Triangle wave generation, amplitude of 127 LSB of DAC output range, for the selected DAC channel */
  244. #define LL_DAC_TRIANGLE_AMPLITUDE_255 ( DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Triangle wave generation, amplitude of 255 LSB of DAC output range, for the selected DAC channel */
  245. #define LL_DAC_TRIANGLE_AMPLITUDE_511 (DAC_CR_MAMP1_3 ) /*!< Triangle wave generation, amplitude of 512 LSB of DAC output range, for the selected DAC channel */
  246. #define LL_DAC_TRIANGLE_AMPLITUDE_1023 (DAC_CR_MAMP1_3 | DAC_CR_MAMP1_0) /*!< Triangle wave generation, amplitude of 1023 LSB of DAC output range, for the selected DAC channel */
  247. #define LL_DAC_TRIANGLE_AMPLITUDE_2047 (DAC_CR_MAMP1_3 | DAC_CR_MAMP1_1 ) /*!< Triangle wave generation, amplitude of 2047 LSB of DAC output range, for the selected DAC channel */
  248. #define LL_DAC_TRIANGLE_AMPLITUDE_4095 (DAC_CR_MAMP1_3 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Triangle wave generation, amplitude of 4095 LSB of DAC output range, for the selected DAC channel */
  249. /**
  250. * @}
  251. */
  252. /** @defgroup DAC_LL_EC_OUTPUT_BUFFER DAC channel output buffer
  253. * @{
  254. */
  255. #define LL_DAC_OUTPUT_BUFFER_ENABLE 0x00000000UL /*!< The selected DAC channel output is buffered: higher drive current capability, but also higher current consumption */
  256. #define LL_DAC_OUTPUT_BUFFER_DISABLE (DAC_CR_BOFF1) /*!< The selected DAC channel output is not buffered: lower drive current capability, but also lower current consumption */
  257. /**
  258. * @}
  259. */
  260. /** @defgroup DAC_LL_EC_RESOLUTION DAC channel output resolution
  261. * @{
  262. */
  263. #define LL_DAC_RESOLUTION_12B 0x00000000UL /*!< DAC channel resolution 12 bits */
  264. #define LL_DAC_RESOLUTION_8B 0x00000002UL /*!< DAC channel resolution 8 bits */
  265. /**
  266. * @}
  267. */
  268. /** @defgroup DAC_LL_EC_REGISTERS DAC registers compliant with specific purpose
  269. * @{
  270. */
  271. /* List of DAC registers intended to be used (most commonly) with */
  272. /* DMA transfer. */
  273. /* Refer to function @ref LL_DAC_DMA_GetRegAddr(). */
  274. #define LL_DAC_DMA_REG_DATA_12BITS_RIGHT_ALIGNED DAC_REG_DHR12RX_REGOFFSET_BITOFFSET_POS /*!< DAC channel data holding register 12 bits right aligned */
  275. #define LL_DAC_DMA_REG_DATA_12BITS_LEFT_ALIGNED DAC_REG_DHR12LX_REGOFFSET_BITOFFSET_POS /*!< DAC channel data holding register 12 bits left aligned */
  276. #define LL_DAC_DMA_REG_DATA_8BITS_RIGHT_ALIGNED DAC_REG_DHR8RX_REGOFFSET_BITOFFSET_POS /*!< DAC channel data holding register 8 bits right aligned */
  277. /**
  278. * @}
  279. */
  280. /** @defgroup DAC_LL_EC_HW_DELAYS Definitions of DAC hardware constraints delays
  281. * @note Only DAC peripheral HW delays are defined in DAC LL driver driver,
  282. * not timeout values.
  283. * For details on delays values, refer to descriptions in source code
  284. * above each literal definition.
  285. * @{
  286. */
  287. /* Delay for DAC channel voltage settling time from DAC channel startup */
  288. /* (transition from disable to enable). */
  289. /* Note: DAC channel startup time depends on board application environment: */
  290. /* impedance connected to DAC channel output. */
  291. /* The delay below is specified under conditions: */
  292. /* - voltage maximum transition (lowest to highest value) */
  293. /* - until voltage reaches final value +-1LSB */
  294. /* - DAC channel output buffer enabled */
  295. /* - load impedance of 5kOhm (min), 50pF (max) */
  296. /* Literal set to maximum value (refer to device datasheet, */
  297. /* parameter "tWAKEUP"). */
  298. /* Unit: us */
  299. #define LL_DAC_DELAY_STARTUP_VOLTAGE_SETTLING_US 15UL /*!< Delay for DAC channel voltage settling time from DAC channel startup (transition from disable to enable) */
  300. /* Delay for DAC channel voltage settling time. */
  301. /* Note: DAC channel startup time depends on board application environment: */
  302. /* impedance connected to DAC channel output. */
  303. /* The delay below is specified under conditions: */
  304. /* - voltage maximum transition (lowest to highest value) */
  305. /* - until voltage reaches final value +-1LSB */
  306. /* - DAC channel output buffer enabled */
  307. /* - load impedance of 5kOhm min, 50pF max */
  308. /* Literal set to maximum value (refer to device datasheet, */
  309. /* parameter "tSETTLING"). */
  310. /* Unit: us */
  311. #define LL_DAC_DELAY_VOLTAGE_SETTLING_US 12UL /*!< Delay for DAC channel voltage settling time */
  312. /**
  313. * @}
  314. */
  315. /**
  316. * @}
  317. */
  318. /* Exported macro ------------------------------------------------------------*/
  319. /** @defgroup DAC_LL_Exported_Macros DAC Exported Macros
  320. * @{
  321. */
  322. /** @defgroup DAC_LL_EM_WRITE_READ Common write and read registers macros
  323. * @{
  324. */
  325. /**
  326. * @brief Write a value in DAC register
  327. * @param __INSTANCE__ DAC Instance
  328. * @param __REG__ Register to be written
  329. * @param __VALUE__ Value to be written in the register
  330. * @retval None
  331. */
  332. #define LL_DAC_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  333. /**
  334. * @brief Read a value in DAC register
  335. * @param __INSTANCE__ DAC Instance
  336. * @param __REG__ Register to be read
  337. * @retval Register value
  338. */
  339. #define LL_DAC_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  340. /**
  341. * @}
  342. */
  343. /** @defgroup DAC_LL_EM_HELPER_MACRO DAC helper macro
  344. * @{
  345. */
  346. /**
  347. * @brief Helper macro to get DAC channel number in decimal format
  348. * from literals LL_DAC_CHANNEL_x.
  349. * Example:
  350. * __LL_DAC_CHANNEL_TO_DECIMAL_NB(LL_DAC_CHANNEL_1)
  351. * will return decimal number "1".
  352. * @note The input can be a value from functions where a channel
  353. * number is returned.
  354. * @param __CHANNEL__ This parameter can be one of the following values:
  355. * @arg @ref LL_DAC_CHANNEL_1
  356. * @arg @ref LL_DAC_CHANNEL_2
  357. * @retval 1...2
  358. */
  359. #define __LL_DAC_CHANNEL_TO_DECIMAL_NB(__CHANNEL__) \
  360. ((__CHANNEL__) & DAC_SWTR_CHX_MASK)
  361. /**
  362. * @brief Helper macro to get DAC channel in literal format LL_DAC_CHANNEL_x
  363. * from number in decimal format.
  364. * Example:
  365. * __LL_DAC_DECIMAL_NB_TO_CHANNEL(1)
  366. * will return a data equivalent to "LL_DAC_CHANNEL_1".
  367. * @note If the input parameter does not correspond to a DAC channel,
  368. * this macro returns value '0'.
  369. * @param __DECIMAL_NB__ 1...2
  370. * @retval Returned value can be one of the following values:
  371. * @arg @ref LL_DAC_CHANNEL_1
  372. * @arg @ref LL_DAC_CHANNEL_2
  373. */
  374. #define __LL_DAC_DECIMAL_NB_TO_CHANNEL(__DECIMAL_NB__)\
  375. (((__DECIMAL_NB__) == 1UL)? (LL_DAC_CHANNEL_1 ):(((__DECIMAL_NB__) == 2UL) ? ( LL_DAC_CHANNEL_2):(0UL)))
  376. /**
  377. * @brief Helper macro to define the DAC conversion data full-scale digital
  378. * value corresponding to the selected DAC resolution.
  379. * @note DAC conversion data full-scale corresponds to voltage range
  380. * determined by analog voltage references Vref+ and Vref-
  381. * (refer to reference manual).
  382. * @param __DAC_RESOLUTION__ This parameter can be one of the following values:
  383. * @arg @ref LL_DAC_RESOLUTION_12B
  384. * @arg @ref LL_DAC_RESOLUTION_8B
  385. * @retval ADC conversion data equivalent voltage value (unit: mVolt)
  386. */
  387. #define __LL_DAC_DIGITAL_SCALE(__DAC_RESOLUTION__) \
  388. ((0x00000FFFUL) >> ((__DAC_RESOLUTION__) << 1UL))
  389. /**
  390. * @brief Helper macro to calculate the DAC conversion data (unit: digital
  391. * value) corresponding to a voltage (unit: mVolt).
  392. * @note This helper macro is intended to provide input data in voltage
  393. * rather than digital value,
  394. * to be used with LL DAC functions such as
  395. * @ref LL_DAC_ConvertData12RightAligned().
  396. * @note Analog reference voltage (Vref+) must be either known from
  397. * user board environment or can be calculated using ADC measurement
  398. * and ADC helper macro __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  399. * @param __VREFANALOG_VOLTAGE__ Analog reference voltage (unit: mV)
  400. * @param __DAC_VOLTAGE__ Voltage to be generated by DAC channel
  401. * (unit: mVolt).
  402. * @param __DAC_RESOLUTION__ This parameter can be one of the following values:
  403. * @arg @ref LL_DAC_RESOLUTION_12B
  404. * @arg @ref LL_DAC_RESOLUTION_8B
  405. * @retval DAC conversion data (unit: digital value)
  406. */
  407. #define __LL_DAC_CALC_VOLTAGE_TO_DATA(__VREFANALOG_VOLTAGE__, __DAC_VOLTAGE__, __DAC_RESOLUTION__) \
  408. ((__DAC_VOLTAGE__) * __LL_DAC_DIGITAL_SCALE(__DAC_RESOLUTION__) \
  409. / (__VREFANALOG_VOLTAGE__) \
  410. )
  411. /**
  412. * @}
  413. */
  414. /**
  415. * @}
  416. */
  417. /* Exported functions --------------------------------------------------------*/
  418. /** @defgroup DAC_LL_Exported_Functions DAC Exported Functions
  419. * @{
  420. */
  421. /**
  422. * @brief Set the conversion trigger source for the selected DAC channel.
  423. * @note For conversion trigger source to be effective, DAC trigger
  424. * must be enabled using function @ref LL_DAC_EnableTrigger().
  425. * @note To set conversion trigger source, DAC channel must be disabled.
  426. * Otherwise, the setting is discarded.
  427. * @note Availability of parameters of trigger sources from timer
  428. * depends on timers availability on the selected device.
  429. * @rmtoll CR TSEL1 LL_DAC_SetTriggerSource\n
  430. * CR TSEL2 LL_DAC_SetTriggerSource
  431. * @param DACx DAC instance
  432. * @param DAC_Channel This parameter can be one of the following values:
  433. * @arg @ref LL_DAC_CHANNEL_1
  434. * @arg @ref LL_DAC_CHANNEL_2
  435. * @param TriggerSource This parameter can be one of the following values:
  436. * @arg @ref LL_DAC_TRIG_SOFTWARE
  437. * @arg @ref LL_DAC_TRIG_EXT_TIM2_TRGO
  438. * @arg @ref LL_DAC_TRIG_EXT_TIM3_TRGO
  439. * @arg @ref LL_DAC_TRIG_EXT_TIM4_TRGO
  440. * @arg @ref LL_DAC_TRIG_EXT_TIM5_TRGO
  441. * @arg @ref LL_DAC_TRIG_EXT_TIM6_TRGO
  442. * @arg @ref LL_DAC_TRIG_EXT_TIM7_TRGO
  443. * @arg @ref LL_DAC_TRIG_EXT_TIM15_TRGO
  444. * @arg @ref LL_DAC_TRIG_EXT_EXTI_LINE9
  445. * @retval None
  446. */
  447. __STATIC_INLINE void LL_DAC_SetTriggerSource(DAC_TypeDef *DACx, uint32_t DAC_Channel, uint32_t TriggerSource)
  448. {
  449. MODIFY_REG(DACx->CR,
  450. DAC_CR_TSEL1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK),
  451. TriggerSource << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK));
  452. }
  453. /**
  454. * @brief Get the conversion trigger source for the selected DAC channel.
  455. * @note For conversion trigger source to be effective, DAC trigger
  456. * must be enabled using function @ref LL_DAC_EnableTrigger().
  457. * @note Availability of parameters of trigger sources from timer
  458. * depends on timers availability on the selected device.
  459. * @rmtoll CR TSEL1 LL_DAC_GetTriggerSource\n
  460. * CR TSEL2 LL_DAC_GetTriggerSource
  461. * @param DACx DAC instance
  462. * @param DAC_Channel This parameter can be one of the following values:
  463. * @arg @ref LL_DAC_CHANNEL_1
  464. * @arg @ref LL_DAC_CHANNEL_2
  465. * @retval Returned value can be one of the following values:
  466. * @arg @ref LL_DAC_TRIG_SOFTWARE
  467. * @arg @ref LL_DAC_TRIG_EXT_TIM2_TRGO
  468. * @arg @ref LL_DAC_TRIG_EXT_TIM3_TRGO
  469. * @arg @ref LL_DAC_TRIG_EXT_TIM4_TRGO
  470. * @arg @ref LL_DAC_TRIG_EXT_TIM5_TRGO
  471. * @arg @ref LL_DAC_TRIG_EXT_TIM6_TRGO
  472. * @arg @ref LL_DAC_TRIG_EXT_TIM7_TRGO
  473. * @arg @ref LL_DAC_TRIG_EXT_TIM15_TRGO
  474. * @arg @ref LL_DAC_TRIG_EXT_EXTI_LINE9
  475. */
  476. __STATIC_INLINE uint32_t LL_DAC_GetTriggerSource(const DAC_TypeDef *DACx, uint32_t DAC_Channel)
  477. {
  478. return (uint32_t)(READ_BIT(DACx->CR, DAC_CR_TSEL1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK))
  479. >> (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
  480. );
  481. }
  482. /**
  483. * @brief Set the waveform automatic generation mode
  484. * for the selected DAC channel.
  485. * @rmtoll CR WAVE1 LL_DAC_SetWaveAutoGeneration\n
  486. * CR WAVE2 LL_DAC_SetWaveAutoGeneration
  487. * @param DACx DAC instance
  488. * @param DAC_Channel This parameter can be one of the following values:
  489. * @arg @ref LL_DAC_CHANNEL_1
  490. * @arg @ref LL_DAC_CHANNEL_2
  491. * @param WaveAutoGeneration This parameter can be one of the following values:
  492. * @arg @ref LL_DAC_WAVE_AUTO_GENERATION_NONE
  493. * @arg @ref LL_DAC_WAVE_AUTO_GENERATION_NOISE
  494. * @arg @ref LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE
  495. * @retval None
  496. */
  497. __STATIC_INLINE void LL_DAC_SetWaveAutoGeneration(DAC_TypeDef *DACx, uint32_t DAC_Channel, uint32_t WaveAutoGeneration)
  498. {
  499. MODIFY_REG(DACx->CR,
  500. DAC_CR_WAVE1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK),
  501. WaveAutoGeneration << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK));
  502. }
  503. /**
  504. * @brief Get the waveform automatic generation mode
  505. * for the selected DAC channel.
  506. * @rmtoll CR WAVE1 LL_DAC_GetWaveAutoGeneration\n
  507. * CR WAVE2 LL_DAC_GetWaveAutoGeneration
  508. * @param DACx DAC instance
  509. * @param DAC_Channel This parameter can be one of the following values:
  510. * @arg @ref LL_DAC_CHANNEL_1
  511. * @arg @ref LL_DAC_CHANNEL_2
  512. * @retval Returned value can be one of the following values:
  513. * @arg @ref LL_DAC_WAVE_AUTO_GENERATION_NONE
  514. * @arg @ref LL_DAC_WAVE_AUTO_GENERATION_NOISE
  515. * @arg @ref LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE
  516. */
  517. __STATIC_INLINE uint32_t LL_DAC_GetWaveAutoGeneration(const DAC_TypeDef *DACx, uint32_t DAC_Channel)
  518. {
  519. return (uint32_t)(READ_BIT(DACx->CR, DAC_CR_WAVE1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK))
  520. >> (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
  521. );
  522. }
  523. /**
  524. * @brief Set the noise waveform generation for the selected DAC channel:
  525. * Noise mode and parameters LFSR (linear feedback shift register).
  526. * @note For wave generation to be effective, DAC channel
  527. * wave generation mode must be enabled using
  528. * function @ref LL_DAC_SetWaveAutoGeneration().
  529. * @note This setting can be set when the selected DAC channel is disabled
  530. * (otherwise, the setting operation is ignored).
  531. * @rmtoll CR MAMP1 LL_DAC_SetWaveNoiseLFSR\n
  532. * CR MAMP2 LL_DAC_SetWaveNoiseLFSR
  533. * @param DACx DAC instance
  534. * @param DAC_Channel This parameter can be one of the following values:
  535. * @arg @ref LL_DAC_CHANNEL_1
  536. * @arg @ref LL_DAC_CHANNEL_2
  537. * @param NoiseLFSRMask This parameter can be one of the following values:
  538. * @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BIT0
  539. * @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS1_0
  540. * @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS2_0
  541. * @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS3_0
  542. * @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS4_0
  543. * @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS5_0
  544. * @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS6_0
  545. * @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS7_0
  546. * @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS8_0
  547. * @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS9_0
  548. * @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS10_0
  549. * @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS11_0
  550. * @retval None
  551. */
  552. __STATIC_INLINE void LL_DAC_SetWaveNoiseLFSR(DAC_TypeDef *DACx, uint32_t DAC_Channel, uint32_t NoiseLFSRMask)
  553. {
  554. MODIFY_REG(DACx->CR,
  555. DAC_CR_MAMP1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK),
  556. NoiseLFSRMask << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK));
  557. }
  558. /**
  559. * @brief Get the noise waveform generation for the selected DAC channel:
  560. * Noise mode and parameters LFSR (linear feedback shift register).
  561. * @rmtoll CR MAMP1 LL_DAC_GetWaveNoiseLFSR\n
  562. * CR MAMP2 LL_DAC_GetWaveNoiseLFSR
  563. * @param DACx DAC instance
  564. * @param DAC_Channel This parameter can be one of the following values:
  565. * @arg @ref LL_DAC_CHANNEL_1
  566. * @arg @ref LL_DAC_CHANNEL_2
  567. * @retval Returned value can be one of the following values:
  568. * @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BIT0
  569. * @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS1_0
  570. * @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS2_0
  571. * @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS3_0
  572. * @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS4_0
  573. * @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS5_0
  574. * @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS6_0
  575. * @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS7_0
  576. * @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS8_0
  577. * @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS9_0
  578. * @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS10_0
  579. * @arg @ref LL_DAC_NOISE_LFSR_UNMASK_BITS11_0
  580. */
  581. __STATIC_INLINE uint32_t LL_DAC_GetWaveNoiseLFSR(const DAC_TypeDef *DACx, uint32_t DAC_Channel)
  582. {
  583. return (uint32_t)(READ_BIT(DACx->CR, DAC_CR_MAMP1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK))
  584. >> (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
  585. );
  586. }
  587. /**
  588. * @brief Set the triangle waveform generation for the selected DAC channel:
  589. * triangle mode and amplitude.
  590. * @note For wave generation to be effective, DAC channel
  591. * wave generation mode must be enabled using
  592. * function @ref LL_DAC_SetWaveAutoGeneration().
  593. * @note This setting can be set when the selected DAC channel is disabled
  594. * (otherwise, the setting operation is ignored).
  595. * @rmtoll CR MAMP1 LL_DAC_SetWaveTriangleAmplitude\n
  596. * CR MAMP2 LL_DAC_SetWaveTriangleAmplitude
  597. * @param DACx DAC instance
  598. * @param DAC_Channel This parameter can be one of the following values:
  599. * @arg @ref LL_DAC_CHANNEL_1
  600. * @arg @ref LL_DAC_CHANNEL_2
  601. * @param TriangleAmplitude This parameter can be one of the following values:
  602. * @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_1
  603. * @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_3
  604. * @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_7
  605. * @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_15
  606. * @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_31
  607. * @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_63
  608. * @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_127
  609. * @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_255
  610. * @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_511
  611. * @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_1023
  612. * @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_2047
  613. * @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_4095
  614. * @retval None
  615. */
  616. __STATIC_INLINE void LL_DAC_SetWaveTriangleAmplitude(DAC_TypeDef *DACx, uint32_t DAC_Channel,
  617. uint32_t TriangleAmplitude)
  618. {
  619. MODIFY_REG(DACx->CR,
  620. DAC_CR_MAMP1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK),
  621. TriangleAmplitude << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK));
  622. }
  623. /**
  624. * @brief Get the triangle waveform generation for the selected DAC channel:
  625. * triangle mode and amplitude.
  626. * @rmtoll CR MAMP1 LL_DAC_GetWaveTriangleAmplitude\n
  627. * CR MAMP2 LL_DAC_GetWaveTriangleAmplitude
  628. * @param DACx DAC instance
  629. * @param DAC_Channel This parameter can be one of the following values:
  630. * @arg @ref LL_DAC_CHANNEL_1
  631. * @arg @ref LL_DAC_CHANNEL_2
  632. * @retval Returned value can be one of the following values:
  633. * @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_1
  634. * @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_3
  635. * @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_7
  636. * @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_15
  637. * @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_31
  638. * @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_63
  639. * @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_127
  640. * @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_255
  641. * @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_511
  642. * @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_1023
  643. * @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_2047
  644. * @arg @ref LL_DAC_TRIANGLE_AMPLITUDE_4095
  645. */
  646. __STATIC_INLINE uint32_t LL_DAC_GetWaveTriangleAmplitude(const DAC_TypeDef *DACx, uint32_t DAC_Channel)
  647. {
  648. return (uint32_t)(READ_BIT(DACx->CR, DAC_CR_MAMP1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK))
  649. >> (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
  650. );
  651. }
  652. /**
  653. * @brief Set the output buffer for the selected DAC channel.
  654. * @rmtoll CR BOFF1 LL_DAC_SetOutputBuffer\n
  655. * CR BOFF2 LL_DAC_SetOutputBuffer
  656. * @param DACx DAC instance
  657. * @param DAC_Channel This parameter can be one of the following values:
  658. * @arg @ref LL_DAC_CHANNEL_1
  659. * @arg @ref LL_DAC_CHANNEL_2
  660. * @param OutputBuffer This parameter can be one of the following values:
  661. * @arg @ref LL_DAC_OUTPUT_BUFFER_ENABLE
  662. * @arg @ref LL_DAC_OUTPUT_BUFFER_DISABLE
  663. * @retval None
  664. */
  665. __STATIC_INLINE void LL_DAC_SetOutputBuffer(DAC_TypeDef *DACx, uint32_t DAC_Channel, uint32_t OutputBuffer)
  666. {
  667. MODIFY_REG(DACx->CR,
  668. DAC_CR_BOFF1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK),
  669. OutputBuffer << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK));
  670. }
  671. /**
  672. * @brief Get the output buffer state for the selected DAC channel.
  673. * @rmtoll CR BOFF1 LL_DAC_GetOutputBuffer\n
  674. * CR BOFF2 LL_DAC_GetOutputBuffer
  675. * @param DACx DAC instance
  676. * @param DAC_Channel This parameter can be one of the following values:
  677. * @arg @ref LL_DAC_CHANNEL_1
  678. * @arg @ref LL_DAC_CHANNEL_2
  679. * @retval Returned value can be one of the following values:
  680. * @arg @ref LL_DAC_OUTPUT_BUFFER_ENABLE
  681. * @arg @ref LL_DAC_OUTPUT_BUFFER_DISABLE
  682. */
  683. __STATIC_INLINE uint32_t LL_DAC_GetOutputBuffer(const DAC_TypeDef *DACx, uint32_t DAC_Channel)
  684. {
  685. return (uint32_t)(READ_BIT(DACx->CR, DAC_CR_BOFF1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK))
  686. >> (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
  687. );
  688. }
  689. /**
  690. * @}
  691. */
  692. /** @defgroup DAC_LL_EF_DMA_Management DMA Management
  693. * @{
  694. */
  695. /**
  696. * @brief Enable DAC DMA transfer request of the selected channel.
  697. * @note To configure DMA source address (peripheral address),
  698. * use function @ref LL_DAC_DMA_GetRegAddr().
  699. * @rmtoll CR DMAEN1 LL_DAC_EnableDMAReq\n
  700. * CR DMAEN2 LL_DAC_EnableDMAReq
  701. * @param DACx DAC instance
  702. * @param DAC_Channel This parameter can be one of the following values:
  703. * @arg @ref LL_DAC_CHANNEL_1
  704. * @arg @ref LL_DAC_CHANNEL_2
  705. * @retval None
  706. */
  707. __STATIC_INLINE void LL_DAC_EnableDMAReq(DAC_TypeDef *DACx, uint32_t DAC_Channel)
  708. {
  709. SET_BIT(DACx->CR,
  710. DAC_CR_DMAEN1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK));
  711. }
  712. /**
  713. * @brief Disable DAC DMA transfer request of the selected channel.
  714. * @note To configure DMA source address (peripheral address),
  715. * use function @ref LL_DAC_DMA_GetRegAddr().
  716. * @rmtoll CR DMAEN1 LL_DAC_DisableDMAReq\n
  717. * CR DMAEN2 LL_DAC_DisableDMAReq
  718. * @param DACx DAC instance
  719. * @param DAC_Channel This parameter can be one of the following values:
  720. * @arg @ref LL_DAC_CHANNEL_1
  721. * @arg @ref LL_DAC_CHANNEL_2
  722. * @retval None
  723. */
  724. __STATIC_INLINE void LL_DAC_DisableDMAReq(DAC_TypeDef *DACx, uint32_t DAC_Channel)
  725. {
  726. CLEAR_BIT(DACx->CR,
  727. DAC_CR_DMAEN1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK));
  728. }
  729. /**
  730. * @brief Get DAC DMA transfer request state of the selected channel.
  731. * (0: DAC DMA transfer request is disabled, 1: DAC DMA transfer request is enabled)
  732. * @rmtoll CR DMAEN1 LL_DAC_IsDMAReqEnabled\n
  733. * CR DMAEN2 LL_DAC_IsDMAReqEnabled
  734. * @param DACx DAC instance
  735. * @param DAC_Channel This parameter can be one of the following values:
  736. * @arg @ref LL_DAC_CHANNEL_1
  737. * @arg @ref LL_DAC_CHANNEL_2
  738. * @retval State of bit (1 or 0).
  739. */
  740. __STATIC_INLINE uint32_t LL_DAC_IsDMAReqEnabled(const DAC_TypeDef *DACx, uint32_t DAC_Channel)
  741. {
  742. return ((READ_BIT(DACx->CR,
  743. DAC_CR_DMAEN1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK))
  744. == (DAC_CR_DMAEN1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK))) ? 1UL : 0UL);
  745. }
  746. /**
  747. * @brief Function to help to configure DMA transfer to DAC: retrieve the
  748. * DAC register address from DAC instance and a list of DAC registers
  749. * intended to be used (most commonly) with DMA transfer.
  750. * @note These DAC registers are data holding registers:
  751. * when DAC conversion is requested, DAC generates a DMA transfer
  752. * request to have data available in DAC data holding registers.
  753. * @note This macro is intended to be used with LL DMA driver, refer to
  754. * function "LL_DMA_ConfigAddresses()".
  755. * Example:
  756. * LL_DMA_ConfigAddresses(DMA1,
  757. * LL_DMA_CHANNEL_1,
  758. * (uint32_t)&< array or variable >,
  759. * LL_DAC_DMA_GetRegAddr(DAC1, LL_DAC_CHANNEL_1,
  760. * LL_DAC_DMA_REG_DATA_12BITS_RIGHT_ALIGNED),
  761. * LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
  762. * @rmtoll DHR12R1 DACC1DHR LL_DAC_DMA_GetRegAddr\n
  763. * DHR12L1 DACC1DHR LL_DAC_DMA_GetRegAddr\n
  764. * DHR8R1 DACC1DHR LL_DAC_DMA_GetRegAddr\n
  765. * DHR12R2 DACC2DHR LL_DAC_DMA_GetRegAddr\n
  766. * DHR12L2 DACC2DHR LL_DAC_DMA_GetRegAddr\n
  767. * DHR8R2 DACC2DHR LL_DAC_DMA_GetRegAddr
  768. * @param DACx DAC instance
  769. * @param DAC_Channel This parameter can be one of the following values:
  770. * @arg @ref LL_DAC_CHANNEL_1
  771. * @arg @ref LL_DAC_CHANNEL_2
  772. * @param Register This parameter can be one of the following values:
  773. * @arg @ref LL_DAC_DMA_REG_DATA_12BITS_RIGHT_ALIGNED
  774. * @arg @ref LL_DAC_DMA_REG_DATA_12BITS_LEFT_ALIGNED
  775. * @arg @ref LL_DAC_DMA_REG_DATA_8BITS_RIGHT_ALIGNED
  776. * @retval DAC register address
  777. */
  778. __STATIC_INLINE uint32_t LL_DAC_DMA_GetRegAddr(const DAC_TypeDef *DACx, uint32_t DAC_Channel, uint32_t Register)
  779. {
  780. /* Retrieve address of register DHR12Rx, DHR12Lx or DHR8Rx depending on */
  781. /* DAC channel selected. */
  782. return ((uint32_t)(__DAC_PTR_REG_OFFSET((DACx)->DHR12R1, ((DAC_Channel >> (Register & 0x1FUL))
  783. & DAC_REG_DHR_REGOFFSET_MASK_POSBIT0))));
  784. }
  785. /**
  786. * @}
  787. */
  788. /** @defgroup DAC_LL_EF_Operation Operation on DAC channels
  789. * @{
  790. */
  791. /**
  792. * @brief Enable DAC selected channel.
  793. * @rmtoll CR EN1 LL_DAC_Enable\n
  794. * CR EN2 LL_DAC_Enable
  795. * @note After enable from off state, DAC channel requires a delay
  796. * for output voltage to reach accuracy +/- 1 LSB.
  797. * Refer to device datasheet, parameter "tWAKEUP".
  798. * @param DACx DAC instance
  799. * @param DAC_Channel This parameter can be one of the following values:
  800. * @arg @ref LL_DAC_CHANNEL_1
  801. * @arg @ref LL_DAC_CHANNEL_2
  802. * @retval None
  803. */
  804. __STATIC_INLINE void LL_DAC_Enable(DAC_TypeDef *DACx, uint32_t DAC_Channel)
  805. {
  806. SET_BIT(DACx->CR,
  807. DAC_CR_EN1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK));
  808. }
  809. /**
  810. * @brief Disable DAC selected channel.
  811. * @rmtoll CR EN1 LL_DAC_Disable\n
  812. * CR EN2 LL_DAC_Disable
  813. * @param DACx DAC instance
  814. * @param DAC_Channel This parameter can be one of the following values:
  815. * @arg @ref LL_DAC_CHANNEL_1
  816. * @arg @ref LL_DAC_CHANNEL_2
  817. * @retval None
  818. */
  819. __STATIC_INLINE void LL_DAC_Disable(DAC_TypeDef *DACx, uint32_t DAC_Channel)
  820. {
  821. CLEAR_BIT(DACx->CR,
  822. DAC_CR_EN1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK));
  823. }
  824. /**
  825. * @brief Get DAC enable state of the selected channel.
  826. * (0: DAC channel is disabled, 1: DAC channel is enabled)
  827. * @rmtoll CR EN1 LL_DAC_IsEnabled\n
  828. * CR EN2 LL_DAC_IsEnabled
  829. * @param DACx DAC instance
  830. * @param DAC_Channel This parameter can be one of the following values:
  831. * @arg @ref LL_DAC_CHANNEL_1
  832. * @arg @ref LL_DAC_CHANNEL_2
  833. * @retval State of bit (1 or 0).
  834. */
  835. __STATIC_INLINE uint32_t LL_DAC_IsEnabled(const DAC_TypeDef *DACx, uint32_t DAC_Channel)
  836. {
  837. return ((READ_BIT(DACx->CR,
  838. DAC_CR_EN1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK))
  839. == (DAC_CR_EN1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK))) ? 1UL : 0UL);
  840. }
  841. /**
  842. * @brief Enable DAC trigger of the selected channel.
  843. * @note - If DAC trigger is disabled, DAC conversion is performed
  844. * automatically once the data holding register is updated,
  845. * using functions "LL_DAC_ConvertData{8; 12}{Right; Left} Aligned()":
  846. * @ref LL_DAC_ConvertData12RightAligned(), ...
  847. * - If DAC trigger is enabled, DAC conversion is performed
  848. * only when a hardware of software trigger event is occurring.
  849. * Select trigger source using
  850. * function @ref LL_DAC_SetTriggerSource().
  851. * @rmtoll CR TEN1 LL_DAC_EnableTrigger\n
  852. * CR TEN2 LL_DAC_EnableTrigger
  853. * @param DACx DAC instance
  854. * @param DAC_Channel This parameter can be one of the following values:
  855. * @arg @ref LL_DAC_CHANNEL_1
  856. * @arg @ref LL_DAC_CHANNEL_2
  857. * @retval None
  858. */
  859. __STATIC_INLINE void LL_DAC_EnableTrigger(DAC_TypeDef *DACx, uint32_t DAC_Channel)
  860. {
  861. SET_BIT(DACx->CR,
  862. DAC_CR_TEN1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK));
  863. }
  864. /**
  865. * @brief Disable DAC trigger of the selected channel.
  866. * @rmtoll CR TEN1 LL_DAC_DisableTrigger\n
  867. * CR TEN2 LL_DAC_DisableTrigger
  868. * @param DACx DAC instance
  869. * @param DAC_Channel This parameter can be one of the following values:
  870. * @arg @ref LL_DAC_CHANNEL_1
  871. * @arg @ref LL_DAC_CHANNEL_2
  872. * @retval None
  873. */
  874. __STATIC_INLINE void LL_DAC_DisableTrigger(DAC_TypeDef *DACx, uint32_t DAC_Channel)
  875. {
  876. CLEAR_BIT(DACx->CR,
  877. DAC_CR_TEN1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK));
  878. }
  879. /**
  880. * @brief Get DAC trigger state of the selected channel.
  881. * (0: DAC trigger is disabled, 1: DAC trigger is enabled)
  882. * @rmtoll CR TEN1 LL_DAC_IsTriggerEnabled\n
  883. * CR TEN2 LL_DAC_IsTriggerEnabled
  884. * @param DACx DAC instance
  885. * @param DAC_Channel This parameter can be one of the following values:
  886. * @arg @ref LL_DAC_CHANNEL_1
  887. * @arg @ref LL_DAC_CHANNEL_2
  888. * @retval State of bit (1 or 0).
  889. */
  890. __STATIC_INLINE uint32_t LL_DAC_IsTriggerEnabled(const DAC_TypeDef *DACx, uint32_t DAC_Channel)
  891. {
  892. return ((READ_BIT(DACx->CR,
  893. DAC_CR_TEN1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK))
  894. == (DAC_CR_TEN1 << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK))) ? 1UL : 0UL);
  895. }
  896. /**
  897. * @brief Trig DAC conversion by software for the selected DAC channel.
  898. * @note Preliminarily, DAC trigger must be set to software trigger
  899. * using function
  900. * @ref LL_DAC_Init()
  901. * @ref LL_DAC_SetTriggerSource()
  902. * with parameter "LL_DAC_TRIGGER_SOFTWARE".
  903. * and DAC trigger must be enabled using
  904. * function @ref LL_DAC_EnableTrigger().
  905. * @note For devices featuring DAC with 2 channels: this function
  906. * can perform a SW start of both DAC channels simultaneously.
  907. * Two channels can be selected as parameter.
  908. * Example: (LL_DAC_CHANNEL_1 | LL_DAC_CHANNEL_2)
  909. * @rmtoll SWTRIGR SWTRIG1 LL_DAC_TrigSWConversion\n
  910. * SWTRIGR SWTRIG2 LL_DAC_TrigSWConversion
  911. * @param DACx DAC instance
  912. * @param DAC_Channel This parameter can a combination of the following values:
  913. * @arg @ref LL_DAC_CHANNEL_1
  914. * @arg @ref LL_DAC_CHANNEL_2
  915. * @retval None
  916. */
  917. __STATIC_INLINE void LL_DAC_TrigSWConversion(DAC_TypeDef *DACx, uint32_t DAC_Channel)
  918. {
  919. SET_BIT(DACx->SWTRIGR,
  920. (DAC_Channel & DAC_SWTR_CHX_MASK));
  921. }
  922. /**
  923. * @brief Set the data to be loaded in the data holding register
  924. * in format 12 bits left alignment (LSB aligned on bit 0),
  925. * for the selected DAC channel.
  926. * @rmtoll DHR12R1 DACC1DHR LL_DAC_ConvertData12RightAligned\n
  927. * DHR12R2 DACC2DHR LL_DAC_ConvertData12RightAligned
  928. * @param DACx DAC instance
  929. * @param DAC_Channel This parameter can be one of the following values:
  930. * @arg @ref LL_DAC_CHANNEL_1
  931. * @arg @ref LL_DAC_CHANNEL_2
  932. * @param Data Value between Min_Data=0x000 and Max_Data=0xFFF
  933. * @retval None
  934. */
  935. __STATIC_INLINE void LL_DAC_ConvertData12RightAligned(DAC_TypeDef *DACx, uint32_t DAC_Channel, uint32_t Data)
  936. {
  937. __IO uint32_t *preg = __DAC_PTR_REG_OFFSET(DACx->DHR12R1, (DAC_Channel >> DAC_REG_DHR12RX_REGOFFSET_BITOFFSET_POS)
  938. & DAC_REG_DHR_REGOFFSET_MASK_POSBIT0);
  939. MODIFY_REG(*preg, DAC_DHR12R1_DACC1DHR, Data);
  940. }
  941. /**
  942. * @brief Set the data to be loaded in the data holding register
  943. * in format 12 bits left alignment (MSB aligned on bit 15),
  944. * for the selected DAC channel.
  945. * @rmtoll DHR12L1 DACC1DHR LL_DAC_ConvertData12LeftAligned\n
  946. * DHR12L2 DACC2DHR LL_DAC_ConvertData12LeftAligned
  947. * @param DACx DAC instance
  948. * @param DAC_Channel This parameter can be one of the following values:
  949. * @arg @ref LL_DAC_CHANNEL_1
  950. * @arg @ref LL_DAC_CHANNEL_2
  951. * @param Data Value between Min_Data=0x000 and Max_Data=0xFFF
  952. * @retval None
  953. */
  954. __STATIC_INLINE void LL_DAC_ConvertData12LeftAligned(DAC_TypeDef *DACx, uint32_t DAC_Channel, uint32_t Data)
  955. {
  956. __IO uint32_t *preg = __DAC_PTR_REG_OFFSET(DACx->DHR12R1, (DAC_Channel >> DAC_REG_DHR12LX_REGOFFSET_BITOFFSET_POS)
  957. & DAC_REG_DHR_REGOFFSET_MASK_POSBIT0);
  958. MODIFY_REG(*preg, DAC_DHR12L1_DACC1DHR, Data);
  959. }
  960. /**
  961. * @brief Set the data to be loaded in the data holding register
  962. * in format 8 bits left alignment (LSB aligned on bit 0),
  963. * for the selected DAC channel.
  964. * @rmtoll DHR8R1 DACC1DHR LL_DAC_ConvertData8RightAligned\n
  965. * DHR8R2 DACC2DHR LL_DAC_ConvertData8RightAligned
  966. * @param DACx DAC instance
  967. * @param DAC_Channel This parameter can be one of the following values:
  968. * @arg @ref LL_DAC_CHANNEL_1
  969. * @arg @ref LL_DAC_CHANNEL_2
  970. * @param Data Value between Min_Data=0x00 and Max_Data=0xFF
  971. * @retval None
  972. */
  973. __STATIC_INLINE void LL_DAC_ConvertData8RightAligned(DAC_TypeDef *DACx, uint32_t DAC_Channel, uint32_t Data)
  974. {
  975. __IO uint32_t *preg = __DAC_PTR_REG_OFFSET(DACx->DHR12R1, (DAC_Channel >> DAC_REG_DHR8RX_REGOFFSET_BITOFFSET_POS)
  976. & DAC_REG_DHR_REGOFFSET_MASK_POSBIT0);
  977. MODIFY_REG(*preg, DAC_DHR8R1_DACC1DHR, Data);
  978. }
  979. /**
  980. * @brief Set the data to be loaded in the data holding register
  981. * in format 12 bits left alignment (LSB aligned on bit 0),
  982. * for both DAC channels.
  983. * @rmtoll DHR12RD DACC1DHR LL_DAC_ConvertDualData12RightAligned\n
  984. * DHR12RD DACC2DHR LL_DAC_ConvertDualData12RightAligned
  985. * @param DACx DAC instance
  986. * @param DataChannel1 Value between Min_Data=0x000 and Max_Data=0xFFF
  987. * @param DataChannel2 Value between Min_Data=0x000 and Max_Data=0xFFF
  988. * @retval None
  989. */
  990. __STATIC_INLINE void LL_DAC_ConvertDualData12RightAligned(DAC_TypeDef *DACx, uint32_t DataChannel1,
  991. uint32_t DataChannel2)
  992. {
  993. MODIFY_REG(DACx->DHR12RD,
  994. (DAC_DHR12RD_DACC2DHR | DAC_DHR12RD_DACC1DHR),
  995. ((DataChannel2 << DAC_DHR12RD_DACC2DHR_BITOFFSET_POS) | DataChannel1));
  996. }
  997. /**
  998. * @brief Set the data to be loaded in the data holding register
  999. * in format 12 bits left alignment (MSB aligned on bit 15),
  1000. * for both DAC channels.
  1001. * @rmtoll DHR12LD DACC1DHR LL_DAC_ConvertDualData12LeftAligned\n
  1002. * DHR12LD DACC2DHR LL_DAC_ConvertDualData12LeftAligned
  1003. * @param DACx DAC instance
  1004. * @param DataChannel1 Value between Min_Data=0x000 and Max_Data=0xFFF
  1005. * @param DataChannel2 Value between Min_Data=0x000 and Max_Data=0xFFF
  1006. * @retval None
  1007. */
  1008. __STATIC_INLINE void LL_DAC_ConvertDualData12LeftAligned(DAC_TypeDef *DACx, uint32_t DataChannel1,
  1009. uint32_t DataChannel2)
  1010. {
  1011. /* Note: Data of DAC channel 2 shift value subtracted of 4 because */
  1012. /* data on 16 bits and DAC channel 2 bits field is on the 12 MSB, */
  1013. /* the 4 LSB must be taken into account for the shift value. */
  1014. MODIFY_REG(DACx->DHR12LD,
  1015. (DAC_DHR12LD_DACC2DHR | DAC_DHR12LD_DACC1DHR),
  1016. ((DataChannel2 << (DAC_DHR12LD_DACC2DHR_BITOFFSET_POS - 4U)) | DataChannel1));
  1017. }
  1018. /**
  1019. * @brief Set the data to be loaded in the data holding register
  1020. * in format 8 bits left alignment (LSB aligned on bit 0),
  1021. * for both DAC channels.
  1022. * @rmtoll DHR8RD DACC1DHR LL_DAC_ConvertDualData8RightAligned\n
  1023. * DHR8RD DACC2DHR LL_DAC_ConvertDualData8RightAligned
  1024. * @param DACx DAC instance
  1025. * @param DataChannel1 Value between Min_Data=0x00 and Max_Data=0xFF
  1026. * @param DataChannel2 Value between Min_Data=0x00 and Max_Data=0xFF
  1027. * @retval None
  1028. */
  1029. __STATIC_INLINE void LL_DAC_ConvertDualData8RightAligned(DAC_TypeDef *DACx, uint32_t DataChannel1,
  1030. uint32_t DataChannel2)
  1031. {
  1032. MODIFY_REG(DACx->DHR8RD,
  1033. (DAC_DHR8RD_DACC2DHR | DAC_DHR8RD_DACC1DHR),
  1034. ((DataChannel2 << DAC_DHR8RD_DACC2DHR_BITOFFSET_POS) | DataChannel1));
  1035. }
  1036. /**
  1037. * @brief Retrieve output data currently generated for the selected DAC channel.
  1038. * @note Whatever alignment and resolution settings
  1039. * (using functions "LL_DAC_ConvertData{8; 12}{Right; Left} Aligned()":
  1040. * @ref LL_DAC_ConvertData12RightAligned(), ...),
  1041. * output data format is 12 bits right aligned (LSB aligned on bit 0).
  1042. * @rmtoll DOR1 DACC1DOR LL_DAC_RetrieveOutputData\n
  1043. * DOR2 DACC2DOR LL_DAC_RetrieveOutputData
  1044. * @param DACx DAC instance
  1045. * @param DAC_Channel This parameter can be one of the following values:
  1046. * @arg @ref LL_DAC_CHANNEL_1
  1047. * @arg @ref LL_DAC_CHANNEL_2
  1048. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  1049. */
  1050. __STATIC_INLINE uint32_t LL_DAC_RetrieveOutputData(const DAC_TypeDef *DACx, uint32_t DAC_Channel)
  1051. {
  1052. __IO uint32_t const *preg = __DAC_PTR_REG_OFFSET(DACx->DOR1, (DAC_Channel >> DAC_REG_DORX_REGOFFSET_BITOFFSET_POS)
  1053. & DAC_REG_DORX_REGOFFSET_MASK_POSBIT0);
  1054. return (uint16_t) READ_BIT(*preg, DAC_DOR1_DACC1DOR);
  1055. }
  1056. /**
  1057. * @}
  1058. */
  1059. /** @defgroup DAC_LL_EF_FLAG_Management FLAG Management
  1060. * @{
  1061. */
  1062. #if defined(DAC_SR_DMAUDR1)
  1063. /**
  1064. * @brief Get DAC underrun flag for DAC channel 1
  1065. * @rmtoll SR DMAUDR1 LL_DAC_IsActiveFlag_DMAUDR1
  1066. * @param DACx DAC instance
  1067. * @retval State of bit (1 or 0).
  1068. */
  1069. __STATIC_INLINE uint32_t LL_DAC_IsActiveFlag_DMAUDR1(const DAC_TypeDef *DACx)
  1070. {
  1071. return ((READ_BIT(DACx->SR, LL_DAC_FLAG_DMAUDR1) == (LL_DAC_FLAG_DMAUDR1)) ? 1UL : 0UL);
  1072. }
  1073. #endif /* DAC_SR_DMAUDR1 */
  1074. #if defined(DAC_SR_DMAUDR2)
  1075. /**
  1076. * @brief Get DAC underrun flag for DAC channel 2
  1077. * @rmtoll SR DMAUDR2 LL_DAC_IsActiveFlag_DMAUDR2
  1078. * @param DACx DAC instance
  1079. * @retval State of bit (1 or 0).
  1080. */
  1081. __STATIC_INLINE uint32_t LL_DAC_IsActiveFlag_DMAUDR2(const DAC_TypeDef *DACx)
  1082. {
  1083. return ((READ_BIT(DACx->SR, LL_DAC_FLAG_DMAUDR2) == (LL_DAC_FLAG_DMAUDR2)) ? 1UL : 0UL);
  1084. }
  1085. #endif /* DAC_SR_DMAUDR2 */
  1086. #if defined(DAC_SR_DMAUDR1)
  1087. /**
  1088. * @brief Clear DAC underrun flag for DAC channel 1
  1089. * @rmtoll SR DMAUDR1 LL_DAC_ClearFlag_DMAUDR1
  1090. * @param DACx DAC instance
  1091. * @retval None
  1092. */
  1093. __STATIC_INLINE void LL_DAC_ClearFlag_DMAUDR1(DAC_TypeDef *DACx)
  1094. {
  1095. WRITE_REG(DACx->SR, LL_DAC_FLAG_DMAUDR1);
  1096. }
  1097. #endif /* DAC_SR_DMAUDR1 */
  1098. #if defined(DAC_SR_DMAUDR2)
  1099. /**
  1100. * @brief Clear DAC underrun flag for DAC channel 2
  1101. * @rmtoll SR DMAUDR2 LL_DAC_ClearFlag_DMAUDR2
  1102. * @param DACx DAC instance
  1103. * @retval None
  1104. */
  1105. __STATIC_INLINE void LL_DAC_ClearFlag_DMAUDR2(DAC_TypeDef *DACx)
  1106. {
  1107. WRITE_REG(DACx->SR, LL_DAC_FLAG_DMAUDR2);
  1108. }
  1109. #endif /* DAC_SR_DMAUDR2 */
  1110. /**
  1111. * @}
  1112. */
  1113. /** @defgroup DAC_LL_EF_IT_Management IT management
  1114. * @{
  1115. */
  1116. #if defined(DAC_CR_DMAUDRIE1)
  1117. /**
  1118. * @brief Enable DMA underrun interrupt for DAC channel 1
  1119. * @rmtoll CR DMAUDRIE1 LL_DAC_EnableIT_DMAUDR1
  1120. * @param DACx DAC instance
  1121. * @retval None
  1122. */
  1123. __STATIC_INLINE void LL_DAC_EnableIT_DMAUDR1(DAC_TypeDef *DACx)
  1124. {
  1125. SET_BIT(DACx->CR, LL_DAC_IT_DMAUDRIE1);
  1126. }
  1127. #endif /* DAC_CR_DMAUDRIE1 */
  1128. #if defined(DAC_CR_DMAUDRIE2)
  1129. /**
  1130. * @brief Enable DMA underrun interrupt for DAC channel 2
  1131. * @rmtoll CR DMAUDRIE2 LL_DAC_EnableIT_DMAUDR2
  1132. * @param DACx DAC instance
  1133. * @retval None
  1134. */
  1135. __STATIC_INLINE void LL_DAC_EnableIT_DMAUDR2(DAC_TypeDef *DACx)
  1136. {
  1137. SET_BIT(DACx->CR, LL_DAC_IT_DMAUDRIE2);
  1138. }
  1139. #endif /* DAC_CR_DMAUDRIE2 */
  1140. #if defined(DAC_CR_DMAUDRIE1)
  1141. /**
  1142. * @brief Disable DMA underrun interrupt for DAC channel 1
  1143. * @rmtoll CR DMAUDRIE1 LL_DAC_DisableIT_DMAUDR1
  1144. * @param DACx DAC instance
  1145. * @retval None
  1146. */
  1147. __STATIC_INLINE void LL_DAC_DisableIT_DMAUDR1(DAC_TypeDef *DACx)
  1148. {
  1149. CLEAR_BIT(DACx->CR, LL_DAC_IT_DMAUDRIE1);
  1150. }
  1151. #endif /* DAC_CR_DMAUDRIE1 */
  1152. #if defined(DAC_CR_DMAUDRIE2)
  1153. /**
  1154. * @brief Disable DMA underrun interrupt for DAC channel 2
  1155. * @rmtoll CR DMAUDRIE2 LL_DAC_DisableIT_DMAUDR2
  1156. * @param DACx DAC instance
  1157. * @retval None
  1158. */
  1159. __STATIC_INLINE void LL_DAC_DisableIT_DMAUDR2(DAC_TypeDef *DACx)
  1160. {
  1161. CLEAR_BIT(DACx->CR, LL_DAC_IT_DMAUDRIE2);
  1162. }
  1163. #endif /* DAC_CR_DMAUDRIE2 */
  1164. #if defined(DAC_CR_DMAUDRIE1)
  1165. /**
  1166. * @brief Get DMA underrun interrupt for DAC channel 1
  1167. * @rmtoll CR DMAUDRIE1 LL_DAC_IsEnabledIT_DMAUDR1
  1168. * @param DACx DAC instance
  1169. * @retval State of bit (1 or 0).
  1170. */
  1171. __STATIC_INLINE uint32_t LL_DAC_IsEnabledIT_DMAUDR1(const DAC_TypeDef *DACx)
  1172. {
  1173. return ((READ_BIT(DACx->CR, LL_DAC_IT_DMAUDRIE1) == (LL_DAC_IT_DMAUDRIE1)) ? 1UL : 0UL);
  1174. }
  1175. #endif /* DAC_CR_DMAUDRIE1 */
  1176. #if defined(DAC_CR_DMAUDRIE2)
  1177. /**
  1178. * @brief Get DMA underrun interrupt for DAC channel 2
  1179. * @rmtoll CR DMAUDRIE2 LL_DAC_IsEnabledIT_DMAUDR2
  1180. * @param DACx DAC instance
  1181. * @retval State of bit (1 or 0).
  1182. */
  1183. __STATIC_INLINE uint32_t LL_DAC_IsEnabledIT_DMAUDR2(const DAC_TypeDef *DACx)
  1184. {
  1185. return ((READ_BIT(DACx->CR, LL_DAC_IT_DMAUDRIE2) == (LL_DAC_IT_DMAUDRIE2)) ? 1UL : 0UL);
  1186. }
  1187. #endif /* DAC_CR_DMAUDRIE2 */
  1188. /**
  1189. * @}
  1190. */
  1191. #if defined(USE_FULL_LL_DRIVER)
  1192. /** @defgroup DAC_LL_EF_Init Initialization and de-initialization functions
  1193. * @{
  1194. */
  1195. ErrorStatus LL_DAC_DeInit(const DAC_TypeDef *DACx);
  1196. ErrorStatus LL_DAC_Init(DAC_TypeDef *DACx, uint32_t DAC_Channel, const LL_DAC_InitTypeDef *DAC_InitStruct);
  1197. void LL_DAC_StructInit(LL_DAC_InitTypeDef *DAC_InitStruct);
  1198. /**
  1199. * @}
  1200. */
  1201. #endif /* USE_FULL_LL_DRIVER */
  1202. /**
  1203. * @}
  1204. */
  1205. /**
  1206. * @}
  1207. */
  1208. #endif /* DAC */
  1209. /**
  1210. * @}
  1211. */
  1212. #ifdef __cplusplus
  1213. }
  1214. #endif
  1215. #endif /* STM32F1xx_LL_DAC_H */