2 ******************************************************************************
3 * @file stm32f7xx_ll_dac.c
4 * @author MCD Application Team
5 * @brief DAC LL module driver
6 ******************************************************************************
9 * <h2><center>© 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 "stm32f7xx_ll_dac.h"
23 #include "stm32f7xx_ll_bus.h"
25 #ifdef USE_FULL_ASSERT
26 #include "stm32_assert.h"
28 #define assert_param(expr) ((void)0U)
31 /** @addtogroup STM32F7xx_LL_Driver
37 /** @addtogroup DAC_LL DAC
41 /* Private types -------------------------------------------------------------*/
42 /* Private variables ---------------------------------------------------------*/
43 /* Private constants ---------------------------------------------------------*/
44 /* Private macros ------------------------------------------------------------*/
46 /** @addtogroup DAC_LL_Private_Macros
50 #define IS_LL_DAC_CHANNEL(__DACX__, __DAC_CHANNEL__) \
52 ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_1) \
53 || ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_2) \
56 #define IS_LL_DAC_TRIGGER_SOURCE(__TRIGGER_SOURCE__) \
57 ( ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_SOFTWARE) \
58 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM2_TRGO) \
59 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM4_TRGO) \
60 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM5_TRGO) \
61 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM6_TRGO) \
62 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM7_TRGO) \
63 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM8_TRGO) \
64 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_EXTI_LINE9) \
67 #define IS_LL_DAC_WAVE_AUTO_GENER_MODE(__WAVE_AUTO_GENERATION_MODE__) \
68 ( ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NONE) \
69 || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NOISE) \
70 || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE) \
73 #define IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(__WAVE_AUTO_GENERATION_CONFIG__) \
74 ( ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BIT0) \
75 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS1_0) \
76 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS2_0) \
77 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS3_0) \
78 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS4_0) \
79 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS5_0) \
80 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS6_0) \
81 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS7_0) \
82 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS8_0) \
83 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS9_0) \
84 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS10_0) \
85 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS11_0) \
86 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1) \
87 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_3) \
88 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_7) \
89 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_15) \
90 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_31) \
91 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_63) \
92 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_127) \
93 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_255) \
94 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_511) \
95 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1023) \
96 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_2047) \
97 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_4095) \
100 #define IS_LL_DAC_OUTPUT_BUFFER(__OUTPUT_BUFFER__) \
101 ( ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_ENABLE) \
102 || ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_DISABLE) \
110 /* Private function prototypes -----------------------------------------------*/
112 /* Exported functions --------------------------------------------------------*/
113 /** @addtogroup DAC_LL_Exported_Functions
117 /** @addtogroup DAC_LL_EF_Init
122 * @brief De-initialize registers of the selected DAC instance
123 * to their default reset values.
124 * @param DACx DAC instance
125 * @retval An ErrorStatus enumeration value:
126 * - SUCCESS: DAC registers are de-initialized
127 * - ERROR: not applicable
129 ErrorStatus
LL_DAC_DeInit(DAC_TypeDef
*DACx
)
131 /* Check the parameters */
132 assert_param(IS_DAC_ALL_INSTANCE(DACx
));
134 /* Force reset of DAC1 clock */
135 LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_DAC1
);
137 /* Release reset of DAC1 clock */
138 LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_DAC1
);
143 * @brief Initialize some features of DAC instance.
144 * @note The setting of these parameters by function @ref LL_DAC_Init()
145 * is conditioned to DAC state:
146 * DAC instance 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
151 * @param DAC_InitStruct Pointer to a @ref LL_DAC_InitTypeDef structure
152 * @retval An ErrorStatus enumeration value:
153 * - SUCCESS: DAC registers are initialized
154 * - ERROR: DAC registers are not initialized
156 ErrorStatus
LL_DAC_Init(DAC_TypeDef
*DACx
, uint32_t DAC_Channel
, LL_DAC_InitTypeDef
*DAC_InitStruct
)
158 ErrorStatus status
= SUCCESS
;
160 /* Check the parameters */
161 assert_param(IS_DAC_ALL_INSTANCE(DACx
));
162 assert_param(IS_LL_DAC_CHANNEL(DACx
, DAC_Channel
));
163 assert_param(IS_LL_DAC_TRIGGER_SOURCE(DAC_InitStruct
->TriggerSource
));
164 assert_param(IS_LL_DAC_OUTPUT_BUFFER(DAC_InitStruct
->OutputBuffer
));
165 assert_param(IS_LL_DAC_WAVE_AUTO_GENER_MODE(DAC_InitStruct
->WaveAutoGeneration
));
166 if (DAC_InitStruct
->WaveAutoGeneration
!= LL_DAC_WAVE_AUTO_GENERATION_NONE
)
168 assert_param(IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(DAC_InitStruct
->WaveAutoGenerationConfig
));
171 /* Note: Hardware constraint (refer to description of this function) */
172 /* DAC instance must be disabled. */
173 if(LL_DAC_IsEnabled(DACx
, DAC_Channel
) == 0U)
175 /* Configuration of DAC channel: */
176 /* - TriggerSource */
177 /* - WaveAutoGeneration */
179 if (DAC_InitStruct
->WaveAutoGeneration
!= LL_DAC_WAVE_AUTO_GENERATION_NONE
)
186 ) << (DAC_Channel
& DAC_CR_CHX_BITOFFSET_MASK
)
188 ( DAC_InitStruct
->TriggerSource
189 | DAC_InitStruct
->WaveAutoGeneration
190 | DAC_InitStruct
->WaveAutoGenerationConfig
191 | DAC_InitStruct
->OutputBuffer
192 ) << (DAC_Channel
& DAC_CR_CHX_BITOFFSET_MASK
)
201 ) << (DAC_Channel
& DAC_CR_CHX_BITOFFSET_MASK
)
203 ( DAC_InitStruct
->TriggerSource
204 | LL_DAC_WAVE_AUTO_GENERATION_NONE
205 | DAC_InitStruct
->OutputBuffer
206 ) << (DAC_Channel
& DAC_CR_CHX_BITOFFSET_MASK
)
212 /* Initialization error: DAC instance is not disabled. */
219 * @brief Set each @ref LL_DAC_InitTypeDef field to default value.
220 * @param DAC_InitStruct pointer to a @ref LL_DAC_InitTypeDef structure
221 * whose fields will be set to default values.
224 void LL_DAC_StructInit(LL_DAC_InitTypeDef
*DAC_InitStruct
)
226 /* Set DAC_InitStruct fields to default values */
227 DAC_InitStruct
->TriggerSource
= LL_DAC_TRIG_SOFTWARE
;
228 DAC_InitStruct
->WaveAutoGeneration
= LL_DAC_WAVE_AUTO_GENERATION_NONE
;
229 /* Note: Parameter discarded if wave auto generation is disabled, */
230 /* set anyway to its default value. */
231 DAC_InitStruct
->WaveAutoGenerationConfig
= LL_DAC_NOISE_LFSR_UNMASK_BIT0
;
232 DAC_InitStruct
->OutputBuffer
= LL_DAC_OUTPUT_BUFFER_ENABLE
;
253 #endif /* USE_FULL_LL_DRIVER */
255 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/