Merge pull request #11189 from klutvott123/move-telemetry-displayport-init
[betaflight.git] / lib / main / STM32F3 / Drivers / STM32F3xx_HAL_Driver / Src / stm32f3xx_ll_dac.c
blob6a5f393b4efba71378bc1894e1be9c423c501acf
1 /**
2 ******************************************************************************
3 * @file stm32f3xx_ll_dac.c
4 * @author MCD Application Team
5 * @brief DAC LL module driver
6 ******************************************************************************
7 * @attention
9 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
11 * Redistribution and use in source and binary forms, with or without modification,
12 * are permitted provided that the following conditions are met:
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * 3. Neither the name of STMicroelectronics nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 ******************************************************************************
35 #if defined(USE_FULL_LL_DRIVER)
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32f3xx_ll_dac.h"
39 #include "stm32f3xx_ll_bus.h"
41 #ifdef USE_FULL_ASSERT
42 #include "stm32_assert.h"
43 #else
44 #define assert_param(expr) ((void)0U)
45 #endif
47 /** @addtogroup STM32F3xx_LL_Driver
48 * @{
51 #if defined (DAC1) || defined (DAC2)
53 /** @addtogroup DAC_LL DAC
54 * @{
57 /* Private types -------------------------------------------------------------*/
58 /* Private variables ---------------------------------------------------------*/
59 /* Private constants ---------------------------------------------------------*/
60 /* Private macros ------------------------------------------------------------*/
62 /** @addtogroup DAC_LL_Private_Macros
63 * @{
66 #if defined(DAC_CHANNEL2_SUPPORT)
67 #define IS_LL_DAC_CHANNEL(__DACX__, __DAC_CHANNEL__) \
68 ( \
69 ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_1) \
70 || ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_2) \
72 #else
73 #define IS_LL_DAC_CHANNEL(__DACX__, __DAC_CHANNEL__) \
74 ( \
75 ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_1) \
77 #endif /* DAC_CHANNEL2_SUPPORT */
79 #if defined(STM32F303xE) || defined(STM32F398xx) || defined(STM32F303xC) || defined(STM32F358xx)
80 #define IS_LL_DAC_TRIGGER_SOURCE(__TRIGGER_SOURCE__) \
81 ( ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_SOFTWARE) \
82 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM2_TRGO) \
83 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM3_TRGO) \
84 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM4_TRGO) \
85 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM15_TRGO) \
86 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM6_TRGO) \
87 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM7_TRGO) \
88 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_EXTI_LINE9) \
91 #elif defined(STM32F303x8) || defined(STM32F328xx)
92 #define IS_LL_DAC_TRIGGER_SOURCE(__TRIGGER_SOURCE__) \
93 ( ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_SOFTWARE) \
94 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM2_TRGO) \
95 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM3_TRGO) \
96 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM15_TRGO) \
97 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM6_TRGO) \
98 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM7_TRGO) \
99 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_EXTI_LINE9) \
102 #elif defined(STM32F302xE) || defined(STM32F302xC) || defined(STM32F302x8)
103 #define IS_LL_DAC_TRIGGER_SOURCE(__TRIGGER_SOURCE__) \
104 ( ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_SOFTWARE) \
105 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM2_TRGO) \
106 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM3_TRGO) \
107 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM4_TRGO) \
108 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM15_TRGO) \
109 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM6_TRGO) \
110 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_EXTI_LINE9) \
113 #elif defined(STM32F301x8) || defined(STM32F318xx)
114 #define IS_LL_DAC_TRIGGER_SOURCE(__TRIGGER_SOURCE__) \
115 ( ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_SOFTWARE) \
116 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM2_TRGO) \
117 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM6_TRGO) \
118 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM15_TRGO) \
119 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_EXTI_LINE9) \
122 #elif defined(STM32F373xC) || defined(STM32F378xx)
123 #define IS_LL_DAC_TRIGGER_SOURCE(__TRIGGER_SOURCE__) \
124 ( ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_SOFTWARE) \
125 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM2_TRGO) \
126 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM3_TRGO) \
127 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM4_TRGO) \
128 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM5_TRGO) \
129 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM6_TRGO) \
130 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM7_TRGO) \
131 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_EXTI_LINE9) \
134 #elif defined(STM32F334x8)
135 #define IS_LL_DAC_TRIGGER_SOURCE(__TRIGGER_SOURCE__) \
136 ( ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_SOFTWARE) \
137 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM6_TRGO) \
138 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM3_TRGO) \
139 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM7_TRGO) \
140 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM15_TRGO) \
141 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM2_TRGO) \
142 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIGGER_HRTIM1_DACTRG2) \
143 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIGGER_HRTIM1_DACTRG3) \
144 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_EXTI_LINE9) \
146 #endif
148 #define IS_LL_DAC_WAVE_AUTO_GENER_MODE(__WAVE_AUTO_GENERATION_MODE__) \
149 ( ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NONE) \
150 || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NOISE) \
151 || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE) \
154 #define IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(__WAVE_AUTO_GENERATION_CONFIG__) \
155 ( ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BIT0) \
156 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS1_0) \
157 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS2_0) \
158 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS3_0) \
159 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS4_0) \
160 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS5_0) \
161 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS6_0) \
162 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS7_0) \
163 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS8_0) \
164 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS9_0) \
165 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS10_0) \
166 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS11_0) \
167 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1) \
168 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_3) \
169 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_7) \
170 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_15) \
171 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_31) \
172 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_63) \
173 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_127) \
174 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_255) \
175 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_511) \
176 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1023) \
177 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_2047) \
178 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_4095) \
181 #define IS_LL_DAC_OUTPUT_BUFFER(__OUTPUT_BUFFER__) \
182 ( ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_ENABLE) \
183 || ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_DISABLE) \
187 * @}
191 /* Private function prototypes -----------------------------------------------*/
193 /* Exported functions --------------------------------------------------------*/
194 /** @addtogroup DAC_LL_Exported_Functions
195 * @{
198 /** @addtogroup DAC_LL_EF_Init
199 * @{
203 * @brief De-initialize registers of the selected DAC instance
204 * to their default reset values.
205 * @param DACx DAC instance
206 * @retval An ErrorStatus enumeration value:
207 * - SUCCESS: DAC registers are de-initialized
208 * - ERROR: not applicable
210 ErrorStatus LL_DAC_DeInit(DAC_TypeDef *DACx)
212 /* Check the parameters */
213 assert_param(IS_DAC_ALL_INSTANCE(DACx));
215 if(DACx == DAC1)
217 /* Force reset of DAC clock */
218 LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_DAC1);
220 /* Release reset of DAC clock */
221 LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_DAC1);
223 #if defined(DAC2)
224 else
226 /* Force reset of DAC clock */
227 LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_DAC2);
229 /* Release reset of DAC clock */
230 LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_DAC2);
232 #endif
233 return SUCCESS;
237 * @brief Initialize some features of DAC instance.
238 * @note The setting of these parameters by function @ref LL_DAC_Init()
239 * is conditioned to DAC state:
240 * DAC instance must be disabled.
241 * @param DACx DAC instance
242 * @param DAC_Channel This parameter can be one of the following values:
243 * @arg @ref LL_DAC_CHANNEL_1
244 * @arg @ref LL_DAC_CHANNEL_2 (1)
246 * (1) On this STM32 serie, parameter not available on all devices.
247 * Refer to device datasheet for channels availability.
248 * @param DAC_InitStruct Pointer to a @ref LL_DAC_InitTypeDef structure
249 * @retval An ErrorStatus enumeration value:
250 * - SUCCESS: DAC registers are initialized
251 * - ERROR: DAC registers are not initialized
253 ErrorStatus LL_DAC_Init(DAC_TypeDef *DACx, uint32_t DAC_Channel, LL_DAC_InitTypeDef *DAC_InitStruct)
255 ErrorStatus status = SUCCESS;
257 /* Check the parameters */
258 assert_param(IS_DAC_ALL_INSTANCE(DACx));
259 assert_param(IS_LL_DAC_CHANNEL(DACx, DAC_Channel));
260 assert_param(IS_LL_DAC_TRIGGER_SOURCE(DAC_InitStruct->TriggerSource));
261 assert_param(IS_LL_DAC_OUTPUT_BUFFER(DAC_InitStruct->OutputBuffer));
262 assert_param(IS_LL_DAC_WAVE_AUTO_GENER_MODE(DAC_InitStruct->WaveAutoGeneration));
263 if (DAC_InitStruct->WaveAutoGeneration != LL_DAC_WAVE_AUTO_GENERATION_NONE)
265 assert_param(IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(DAC_InitStruct->WaveAutoGenerationConfig));
268 /* Note: Hardware constraint (refer to description of this function) */
269 /* DAC instance must be disabled. */
270 if(LL_DAC_IsEnabled(DACx, DAC_Channel) == 0U)
272 /* Configuration of DAC channel: */
273 /* - TriggerSource */
274 /* - WaveAutoGeneration */
275 /* - OutputBuffer */
276 if (DAC_InitStruct->WaveAutoGeneration != LL_DAC_WAVE_AUTO_GENERATION_NONE)
278 MODIFY_REG(DACx->CR,
279 ( DAC_CR_TSEL1
280 | DAC_CR_WAVE1
281 | DAC_CR_MAMP1
282 | DAC_CR_BOFF1
283 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
285 ( DAC_InitStruct->TriggerSource
286 | DAC_InitStruct->WaveAutoGeneration
287 | DAC_InitStruct->WaveAutoGenerationConfig
288 | DAC_InitStruct->OutputBuffer
289 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
292 else
294 MODIFY_REG(DACx->CR,
295 ( DAC_CR_TSEL1
296 | DAC_CR_WAVE1
297 | DAC_CR_BOFF1
298 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
300 ( DAC_InitStruct->TriggerSource
301 | LL_DAC_WAVE_AUTO_GENERATION_NONE
302 | DAC_InitStruct->OutputBuffer
303 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
307 else
309 /* Initialization error: DAC instance is not disabled. */
310 status = ERROR;
312 return status;
316 * @brief Set each @ref LL_DAC_InitTypeDef field to default value.
317 * @param DAC_InitStruct pointer to a @ref LL_DAC_InitTypeDef structure
318 * whose fields will be set to default values.
319 * @retval None
321 void LL_DAC_StructInit(LL_DAC_InitTypeDef *DAC_InitStruct)
323 /* Set DAC_InitStruct fields to default values */
324 DAC_InitStruct->TriggerSource = LL_DAC_TRIG_SOFTWARE;
325 DAC_InitStruct->WaveAutoGeneration = LL_DAC_WAVE_AUTO_GENERATION_NONE;
326 /* Note: Parameter discarded if wave auto generation is disabled, */
327 /* set anyway to its default value. */
328 DAC_InitStruct->WaveAutoGenerationConfig = LL_DAC_NOISE_LFSR_UNMASK_BIT0;
329 DAC_InitStruct->OutputBuffer = LL_DAC_OUTPUT_BUFFER_ENABLE;
333 * @}
337 * @}
341 * @}
344 #endif /* DAC1 || DAC2 */
347 * @}
350 #endif /* USE_FULL_LL_DRIVER */
352 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/