Create release.yml
[betaflight.git] / lib / main / STM32H7 / Drivers / STM32H7xx_HAL_Driver / Src / stm32h7xx_ll_dac.c
blobf5983de03572ea495179c08a32612170ab1f1d8b
1 /**
2 ******************************************************************************
3 * @file stm32h7xx_ll_dac.c
4 * @author MCD Application Team
5 * @brief DAC LL module driver
6 ******************************************************************************
7 * @attention
9 * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
10 * All rights reserved.</center></h2>
12 * This software component is licensed by ST under BSD 3-Clause license,
13 * the "License"; You may not use this file except in compliance with the
14 * License. You may obtain a copy of the License at:
15 * opensource.org/licenses/BSD-3-Clause
17 ******************************************************************************
19 #if defined(USE_FULL_LL_DRIVER)
21 /* Includes ------------------------------------------------------------------*/
22 #include "stm32h7xx_ll_dac.h"
23 #include "stm32h7xx_ll_bus.h"
25 #ifdef USE_FULL_ASSERT
26 #include "stm32_assert.h"
27 #else
28 #define assert_param(expr) ((void)0U)
29 #endif
31 /** @addtogroup STM32H7xx_LL_Driver
32 * @{
35 #if defined(DAC1) || defined(DAC2)
37 /** @addtogroup DAC_LL DAC
38 * @{
41 /* Private types -------------------------------------------------------------*/
42 /* Private variables ---------------------------------------------------------*/
43 /* Private constants ---------------------------------------------------------*/
44 /* Private macros ------------------------------------------------------------*/
46 /** @addtogroup DAC_LL_Private_Macros
47 * @{
49 #define IS_LL_DAC_CHANNEL(__DAC_CHANNEL__) \
50 ( \
51 ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_1) \
52 || ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_2) \
55 #if defined (HRTIM1)
56 #define IS_LL_DAC_TRIGGER_SOURCE(__TRIGGER_SOURCE__) \
57 ( ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_SOFTWARE) \
58 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM1_TRGO) \
59 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM2_TRGO) \
60 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM4_TRGO) \
61 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM5_TRGO) \
62 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM6_TRGO) \
63 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM7_TRGO) \
64 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM8_TRGO) \
65 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM15_TRGO) \
66 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_HRTIM_TRGO1) \
67 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_HRTIM_TRGO2) \
68 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_LPTIM1_OUT) \
69 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_LPTIM2_OUT) \
70 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_EXTI_LINE9) \
72 #elif defined (DAC2)
73 #define IS_LL_DAC_TRIGGER_SOURCE(__TRIGGER_SOURCE__) \
74 ( ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_SOFTWARE) \
75 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM1_TRGO) \
76 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM2_TRGO) \
77 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM4_TRGO) \
78 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM5_TRGO) \
79 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM6_TRGO) \
80 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM7_TRGO) \
81 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM8_TRGO) \
82 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM15_TRGO) \
83 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_LPTIM1_OUT) \
84 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_LPTIM2_OUT) \
85 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_EXTI_LINE9) \
86 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_LPTIM3_OUT) \
88 #else
89 #define IS_LL_DAC_TRIGGER_SOURCE(__TRIGGER_SOURCE__) \
90 ( ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_SOFTWARE) \
91 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM1_TRGO) \
92 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM2_TRGO) \
93 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM4_TRGO) \
94 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM5_TRGO) \
95 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM6_TRGO) \
96 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM7_TRGO) \
97 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM8_TRGO) \
98 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM15_TRGO) \
99 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_LPTIM1_OUT) \
100 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_LPTIM2_OUT) \
101 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_EXTI_LINE9) \
102 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM23_TRGO) \
103 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM24_TRGO) \
105 #endif
107 #define IS_LL_DAC_WAVE_AUTO_GENER_MODE(__WAVE_AUTO_GENERATION_MODE__) \
108 ( ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NONE) \
109 || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NOISE) \
110 || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE) \
113 #define IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(__WAVE_AUTO_GENERATION_MODE__, __WAVE_AUTO_GENERATION_CONFIG__) \
114 ( (((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NOISE) \
115 && ( ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BIT0) \
116 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS1_0) \
117 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS2_0) \
118 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS3_0) \
119 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS4_0) \
120 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS5_0) \
121 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS6_0) \
122 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS7_0) \
123 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS8_0) \
124 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS9_0) \
125 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS10_0) \
126 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS11_0)) \
128 ||(((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE) \
129 && ( ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1) \
130 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_3) \
131 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_7) \
132 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_15) \
133 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_31) \
134 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_63) \
135 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_127) \
136 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_255) \
137 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_511) \
138 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1023) \
139 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_2047) \
140 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_4095)) \
144 #define IS_LL_DAC_OUTPUT_BUFFER(__OUTPUT_BUFFER__) \
145 ( ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_ENABLE) \
146 || ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_DISABLE) \
149 #define IS_LL_DAC_OUTPUT_CONNECTION(__OUTPUT_CONNECTION__) \
150 ( ((__OUTPUT_CONNECTION__) == LL_DAC_OUTPUT_CONNECT_GPIO) \
151 || ((__OUTPUT_CONNECTION__) == LL_DAC_OUTPUT_CONNECT_INTERNAL) \
154 #define IS_LL_DAC_OUTPUT_MODE(__OUTPUT_MODE__) \
155 ( ((__OUTPUT_MODE__) == LL_DAC_OUTPUT_MODE_NORMAL) \
156 || ((__OUTPUT_MODE__) == LL_DAC_OUTPUT_MODE_SAMPLE_AND_HOLD) \
160 * @}
164 /* Private function prototypes -----------------------------------------------*/
166 /* Exported functions --------------------------------------------------------*/
167 /** @addtogroup DAC_LL_Exported_Functions
168 * @{
171 /** @addtogroup DAC_LL_EF_Init
172 * @{
176 * @brief De-initialize registers of the selected DAC instance
177 * to their default reset values.
178 * @param DACx DAC instance
179 * @retval An ErrorStatus enumeration value:
180 * - SUCCESS: DAC registers are de-initialized
181 * - ERROR: not applicable
183 ErrorStatus LL_DAC_DeInit(DAC_TypeDef *DACx)
185 /* Check the parameters */
186 assert_param(IS_DAC_ALL_INSTANCE(DACx));
188 if(DACx == DAC1)
190 /* Force reset of DAC clock */
191 LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_DAC12);
193 /* Release reset of DAC clock */
194 LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_DAC12);
196 #if defined (DAC2)
197 else
199 /* Force reset of DAC clock */
200 LL_APB4_GRP1_ForceReset(LL_APB4_GRP1_PERIPH_DAC2);
202 /* Release reset of DAC clock */
203 LL_APB4_GRP1_ReleaseReset(LL_APB4_GRP1_PERIPH_DAC2);
205 #endif
208 return SUCCESS;
212 * @brief Initialize some features of DAC channel.
213 * @note @ref LL_DAC_Init() aims to ease basic configuration of a DAC channel.
214 * Leaving it ready to be enabled and output:
215 * a level by calling one of
216 * @ref LL_DAC_ConvertData12RightAligned
217 * @ref LL_DAC_ConvertData12LeftAligned
218 * @ref LL_DAC_ConvertData8RightAligned
219 * or one of the supported autogenerated wave.
220 * @note This function allows configuration of:
221 * - Output mode
222 * - Trigger
223 * - Wave generation
224 * @note The setting of these parameters by function @ref LL_DAC_Init()
225 * is conditioned to DAC state:
226 * DAC channel must be disabled.
227 * @param DACx DAC instance
228 * @param DAC_Channel This parameter can be one of the following values:
229 * @arg @ref LL_DAC_CHANNEL_1
230 * @arg @ref LL_DAC_CHANNEL_2
231 * @param DAC_InitStruct Pointer to a @ref LL_DAC_InitTypeDef structure
232 * @retval An ErrorStatus enumeration value:
233 * - SUCCESS: DAC registers are initialized
234 * - ERROR: DAC registers are not initialized
236 ErrorStatus LL_DAC_Init(DAC_TypeDef *DACx, uint32_t DAC_Channel, LL_DAC_InitTypeDef *DAC_InitStruct)
238 ErrorStatus status = SUCCESS;
240 /* Check the parameters */
241 assert_param(IS_DAC_ALL_INSTANCE(DACx));
242 assert_param(IS_LL_DAC_CHANNEL(DAC_Channel));
243 assert_param(IS_LL_DAC_TRIGGER_SOURCE(DAC_InitStruct->TriggerSource));
244 assert_param(IS_LL_DAC_OUTPUT_BUFFER(DAC_InitStruct->OutputBuffer));
245 assert_param(IS_LL_DAC_OUTPUT_CONNECTION(DAC_InitStruct->OutputConnection));
246 assert_param(IS_LL_DAC_OUTPUT_MODE(DAC_InitStruct->OutputMode));
247 assert_param(IS_LL_DAC_WAVE_AUTO_GENER_MODE(DAC_InitStruct->WaveAutoGeneration));
248 if (DAC_InitStruct->WaveAutoGeneration != LL_DAC_WAVE_AUTO_GENERATION_NONE)
250 assert_param(IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(DAC_InitStruct->WaveAutoGeneration,
251 DAC_InitStruct->WaveAutoGenerationConfig));
254 /* Note: Hardware constraint (refer to description of this function) */
255 /* DAC instance must be disabled. */
256 if (LL_DAC_IsEnabled(DACx, DAC_Channel) == 0UL)
258 /* Configuration of DAC channel: */
259 /* - TriggerSource */
260 /* - WaveAutoGeneration */
261 /* - OutputBuffer */
262 /* - OutputConnection */
263 /* - OutputMode */
264 if (DAC_InitStruct->WaveAutoGeneration != LL_DAC_WAVE_AUTO_GENERATION_NONE)
266 MODIFY_REG(DACx->CR,
267 (DAC_CR_TSEL1
268 | DAC_CR_WAVE1
269 | DAC_CR_MAMP1
270 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
272 (DAC_InitStruct->TriggerSource
273 | DAC_InitStruct->WaveAutoGeneration
274 | DAC_InitStruct->WaveAutoGenerationConfig
275 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
278 else
280 MODIFY_REG(DACx->CR,
281 (DAC_CR_TSEL1
282 | DAC_CR_WAVE1
283 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
285 (DAC_InitStruct->TriggerSource
286 | LL_DAC_WAVE_AUTO_GENERATION_NONE
287 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
290 MODIFY_REG(DACx->MCR,
291 (DAC_MCR_MODE1_1
292 | DAC_MCR_MODE1_0
293 | DAC_MCR_MODE1_2
294 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
296 (DAC_InitStruct->OutputBuffer
297 | DAC_InitStruct->OutputConnection
298 | DAC_InitStruct->OutputMode
299 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
302 else
304 /* Initialization error: DAC instance is not disabled. */
305 status = ERROR;
307 return status;
311 * @brief Set each @ref LL_DAC_InitTypeDef field to default value.
312 * @param DAC_InitStruct pointer to a @ref LL_DAC_InitTypeDef structure
313 * whose fields will be set to default values.
314 * @retval None
316 void LL_DAC_StructInit(LL_DAC_InitTypeDef *DAC_InitStruct)
318 /* Set DAC_InitStruct fields to default values */
319 DAC_InitStruct->TriggerSource = LL_DAC_TRIG_SOFTWARE;
320 DAC_InitStruct->WaveAutoGeneration = LL_DAC_WAVE_AUTO_GENERATION_NONE;
321 /* Note: Parameter discarded if wave auto generation is disabled, */
322 /* set anyway to its default value. */
323 DAC_InitStruct->WaveAutoGenerationConfig = LL_DAC_NOISE_LFSR_UNMASK_BIT0;
324 DAC_InitStruct->OutputBuffer = LL_DAC_OUTPUT_BUFFER_ENABLE;
325 DAC_InitStruct->OutputConnection = LL_DAC_OUTPUT_CONNECT_GPIO;
326 DAC_InitStruct->OutputMode = LL_DAC_OUTPUT_MODE_NORMAL;
330 * @}
334 * @}
338 * @}
341 #endif /* DAC1 || DAC2 */
344 * @}
347 #endif /* USE_FULL_LL_DRIVER */
349 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/