训练营PLSR题目
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.
 
 
 
 
 
 

281 lines
12 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_ll_dac.c
  4. * @author MCD Application Team
  5. * @brief DAC LL module driver
  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. #if defined(USE_FULL_LL_DRIVER)
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "stm32f4xx_ll_dac.h"
  21. #include "stm32f4xx_ll_bus.h"
  22. #ifdef USE_FULL_ASSERT
  23. #include "stm32_assert.h"
  24. #else
  25. #define assert_param(expr) ((void)0U)
  26. #endif /* USE_FULL_ASSERT */
  27. /** @addtogroup STM32F4xx_LL_Driver
  28. * @{
  29. */
  30. #if defined(DAC)
  31. /** @addtogroup DAC_LL DAC
  32. * @{
  33. */
  34. /* Private types -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Private constants ---------------------------------------------------------*/
  37. /* Private macros ------------------------------------------------------------*/
  38. /** @addtogroup DAC_LL_Private_Macros
  39. * @{
  40. */
  41. #if defined(DAC_CHANNEL2_SUPPORT)
  42. #define IS_LL_DAC_CHANNEL(__DACX__, __DAC_CHANNEL__) \
  43. ( \
  44. ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_1) \
  45. || ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_2) \
  46. )
  47. #else
  48. #define IS_LL_DAC_CHANNEL(__DACX__, __DAC_CHANNEL__) \
  49. ( \
  50. ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_1) \
  51. )
  52. #endif /* DAC_CHANNEL2_SUPPORT */
  53. #define IS_LL_DAC_TRIGGER_SOURCE(__TRIGGER_SOURCE__) \
  54. ( ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_SOFTWARE) \
  55. || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM2_TRGO) \
  56. || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM4_TRGO) \
  57. || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM5_TRGO) \
  58. || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM6_TRGO) \
  59. || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM7_TRGO) \
  60. || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM8_TRGO) \
  61. || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_EXTI_LINE9) \
  62. )
  63. #define IS_LL_DAC_WAVE_AUTO_GENER_MODE(__WAVE_AUTO_GENERATION_MODE__) \
  64. ( ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NONE) \
  65. || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NOISE) \
  66. || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE) \
  67. )
  68. #define IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(__WAVE_AUTO_GENERATION_MODE__, __WAVE_AUTO_GENERATION_CONFIG__) \
  69. ( (((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NOISE) \
  70. && ( ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BIT0) \
  71. || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS1_0) \
  72. || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS2_0) \
  73. || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS3_0) \
  74. || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS4_0) \
  75. || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS5_0) \
  76. || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS6_0) \
  77. || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS7_0) \
  78. || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS8_0) \
  79. || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS9_0) \
  80. || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS10_0) \
  81. || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS11_0)) \
  82. ) \
  83. ||(((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE) \
  84. && ( ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1) \
  85. || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_3) \
  86. || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_7) \
  87. || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_15) \
  88. || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_31) \
  89. || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_63) \
  90. || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_127) \
  91. || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_255) \
  92. || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_511) \
  93. || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1023) \
  94. || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_2047) \
  95. || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_4095)) \
  96. ) \
  97. )
  98. #define IS_LL_DAC_OUTPUT_BUFFER(__OUTPUT_BUFFER__) \
  99. ( ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_ENABLE) \
  100. || ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_DISABLE) \
  101. )
  102. /**
  103. * @}
  104. */
  105. /* Private function prototypes -----------------------------------------------*/
  106. /* Exported functions --------------------------------------------------------*/
  107. /** @addtogroup DAC_LL_Exported_Functions
  108. * @{
  109. */
  110. /** @addtogroup DAC_LL_EF_Init
  111. * @{
  112. */
  113. /**
  114. * @brief De-initialize registers of the selected DAC instance
  115. * to their default reset values.
  116. * @param DACx DAC instance
  117. * @retval An ErrorStatus enumeration value:
  118. * - SUCCESS: DAC registers are de-initialized
  119. * - ERROR: not applicable
  120. */
  121. ErrorStatus LL_DAC_DeInit(DAC_TypeDef *DACx)
  122. {
  123. /* Check the parameters */
  124. assert_param(IS_DAC_ALL_INSTANCE(DACx));
  125. /* Force reset of DAC clock */
  126. LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_DAC1);
  127. /* Release reset of DAC clock */
  128. LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_DAC1);
  129. return SUCCESS;
  130. }
  131. /**
  132. * @brief Initialize some features of DAC channel.
  133. * @note @ref LL_DAC_Init() aims to ease basic configuration of a DAC channel.
  134. * Leaving it ready to be enabled and output:
  135. * a level by calling one of
  136. * @ref LL_DAC_ConvertData12RightAligned
  137. * @ref LL_DAC_ConvertData12LeftAligned
  138. * @ref LL_DAC_ConvertData8RightAligned
  139. * or one of the supported autogenerated wave.
  140. * @note This function allows configuration of:
  141. * - Output mode
  142. * - Trigger
  143. * - Wave generation
  144. * @note The setting of these parameters by function @ref LL_DAC_Init()
  145. * is conditioned to DAC state:
  146. * DAC channel must be disabled.
  147. * @param DACx DAC instance
  148. * @param DAC_Channel This parameter can be one of the following values:
  149. * @arg @ref LL_DAC_CHANNEL_1
  150. * @arg @ref LL_DAC_CHANNEL_2 (1)
  151. *
  152. * (1) On this STM32 serie, parameter not available on all devices.
  153. * Refer to device datasheet for channels availability.
  154. * @param DAC_InitStruct Pointer to a @ref LL_DAC_InitTypeDef structure
  155. * @retval An ErrorStatus enumeration value:
  156. * - SUCCESS: DAC registers are initialized
  157. * - ERROR: DAC registers are not initialized
  158. */
  159. ErrorStatus LL_DAC_Init(DAC_TypeDef *DACx, uint32_t DAC_Channel, LL_DAC_InitTypeDef *DAC_InitStruct)
  160. {
  161. ErrorStatus status = SUCCESS;
  162. /* Check the parameters */
  163. assert_param(IS_DAC_ALL_INSTANCE(DACx));
  164. assert_param(IS_LL_DAC_CHANNEL(DACx, DAC_Channel));
  165. assert_param(IS_LL_DAC_TRIGGER_SOURCE(DAC_InitStruct->TriggerSource));
  166. assert_param(IS_LL_DAC_OUTPUT_BUFFER(DAC_InitStruct->OutputBuffer));
  167. assert_param(IS_LL_DAC_WAVE_AUTO_GENER_MODE(DAC_InitStruct->WaveAutoGeneration));
  168. if (DAC_InitStruct->WaveAutoGeneration != LL_DAC_WAVE_AUTO_GENERATION_NONE)
  169. {
  170. assert_param(IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(DAC_InitStruct->WaveAutoGeneration,
  171. DAC_InitStruct->WaveAutoGenerationConfig));
  172. }
  173. /* Note: Hardware constraint (refer to description of this function) */
  174. /* DAC instance must be disabled. */
  175. if (LL_DAC_IsEnabled(DACx, DAC_Channel) == 0UL)
  176. {
  177. /* Configuration of DAC channel: */
  178. /* - TriggerSource */
  179. /* - WaveAutoGeneration */
  180. /* - OutputBuffer */
  181. /* - OutputMode */
  182. if (DAC_InitStruct->WaveAutoGeneration != LL_DAC_WAVE_AUTO_GENERATION_NONE)
  183. {
  184. MODIFY_REG(DACx->CR,
  185. (DAC_CR_TSEL1
  186. | DAC_CR_WAVE1
  187. | DAC_CR_MAMP1
  188. | DAC_CR_BOFF1
  189. ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
  190. ,
  191. (DAC_InitStruct->TriggerSource
  192. | DAC_InitStruct->WaveAutoGeneration
  193. | DAC_InitStruct->WaveAutoGenerationConfig
  194. | DAC_InitStruct->OutputBuffer
  195. ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
  196. );
  197. }
  198. else
  199. {
  200. MODIFY_REG(DACx->CR,
  201. (DAC_CR_TSEL1
  202. | DAC_CR_WAVE1
  203. | DAC_CR_BOFF1
  204. ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
  205. ,
  206. (DAC_InitStruct->TriggerSource
  207. | LL_DAC_WAVE_AUTO_GENERATION_NONE
  208. | DAC_InitStruct->OutputBuffer
  209. ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
  210. );
  211. }
  212. }
  213. else
  214. {
  215. /* Initialization error: DAC instance is not disabled. */
  216. status = ERROR;
  217. }
  218. return status;
  219. }
  220. /**
  221. * @brief Set each @ref LL_DAC_InitTypeDef field to default value.
  222. * @param DAC_InitStruct pointer to a @ref LL_DAC_InitTypeDef structure
  223. * whose fields will be set to default values.
  224. * @retval None
  225. */
  226. void LL_DAC_StructInit(LL_DAC_InitTypeDef *DAC_InitStruct)
  227. {
  228. /* Set DAC_InitStruct fields to default values */
  229. DAC_InitStruct->TriggerSource = LL_DAC_TRIG_SOFTWARE;
  230. DAC_InitStruct->WaveAutoGeneration = LL_DAC_WAVE_AUTO_GENERATION_NONE;
  231. /* Note: Parameter discarded if wave auto generation is disabled, */
  232. /* set anyway to its default value. */
  233. DAC_InitStruct->WaveAutoGenerationConfig = LL_DAC_NOISE_LFSR_UNMASK_BIT0;
  234. DAC_InitStruct->OutputBuffer = LL_DAC_OUTPUT_BUFFER_ENABLE;
  235. }
  236. /**
  237. * @}
  238. */
  239. /**
  240. * @}
  241. */
  242. /**
  243. * @}
  244. */
  245. #endif /* DAC */
  246. /**
  247. * @}
  248. */
  249. #endif /* USE_FULL_LL_DRIVER */