2 ******************************************************************************
3 * @file stm32f4xx_ll_dac.c
4 * @author MCD Application Team
7 * @brief DAC LL module driver
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 ******************************************************************************
37 #if defined(USE_FULL_LL_DRIVER)
39 /* Includes ------------------------------------------------------------------*/
40 #include "stm32f4xx_ll_dac.h"
41 #include "stm32f4xx_ll_bus.h"
43 #ifdef USE_FULL_ASSERT
44 #include "stm32_assert.h"
46 #define assert_param(expr) ((void)0U)
49 /** @addtogroup STM32F4xx_LL_Driver
55 /** @addtogroup DAC_LL DAC
59 /* Private types -------------------------------------------------------------*/
60 /* Private variables ---------------------------------------------------------*/
61 /* Private constants ---------------------------------------------------------*/
62 /* Private macros ------------------------------------------------------------*/
64 /** @addtogroup DAC_LL_Private_Macros
68 #if defined(DAC_CHANNEL2_SUPPORT)
69 #define IS_LL_DAC_CHANNEL(__DACX__, __DAC_CHANNEL__) \
71 ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_1) \
72 || ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_2) \
75 #define IS_LL_DAC_CHANNEL(__DACX__, __DAC_CHANNEL__) \
77 ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_1) \
79 #endif /* DAC_CHANNEL2_SUPPORT */
81 #define IS_LL_DAC_TRIGGER_SOURCE(__TRIGGER_SOURCE__) \
82 ( ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_SOFTWARE) \
83 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM2_TRGO) \
84 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM4_TRGO) \
85 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM5_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_TIM8_TRGO) \
89 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_EXTI_LINE9) \
92 #define IS_LL_DAC_WAVE_AUTO_GENER_MODE(__WAVE_AUTO_GENERATION_MODE__) \
93 ( ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NONE) \
94 || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NOISE) \
95 || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE) \
98 #define IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(__WAVE_AUTO_GENERATION_CONFIG__) \
99 ( ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BIT0) \
100 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS1_0) \
101 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS2_0) \
102 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS3_0) \
103 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS4_0) \
104 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS5_0) \
105 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS6_0) \
106 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS7_0) \
107 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS8_0) \
108 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS9_0) \
109 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS10_0) \
110 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS11_0) \
111 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1) \
112 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_3) \
113 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_7) \
114 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_15) \
115 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_31) \
116 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_63) \
117 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_127) \
118 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_255) \
119 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_511) \
120 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1023) \
121 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_2047) \
122 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_4095) \
125 #define IS_LL_DAC_OUTPUT_BUFFER(__OUTPUT_BUFFER__) \
126 ( ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_ENABLE) \
127 || ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_DISABLE) \
135 /* Private function prototypes -----------------------------------------------*/
137 /* Exported functions --------------------------------------------------------*/
138 /** @addtogroup DAC_LL_Exported_Functions
142 /** @addtogroup DAC_LL_EF_Init
147 * @brief De-initialize registers of the selected DAC instance
148 * to their default reset values.
149 * @param DACx DAC instance
150 * @retval An ErrorStatus enumeration value:
151 * - SUCCESS: DAC registers are de-initialized
152 * - ERROR: not applicable
154 ErrorStatus
LL_DAC_DeInit(DAC_TypeDef
*DACx
)
156 /* Check the parameters */
157 assert_param(IS_DAC_ALL_INSTANCE(DACx
));
159 /* Force reset of DAC1 clock */
160 LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_DAC1
);
162 /* Release reset of DAC1 clock */
163 LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_DAC1
);
168 * @brief Initialize some features of DAC instance.
169 * @note The setting of these parameters by function @ref LL_DAC_Init()
170 * is conditioned to DAC state:
171 * DAC instance must be disabled.
172 * @param DACx DAC instance
173 * @param DAC_Channel This parameter can be one of the following values:
174 * @arg @ref LL_DAC_CHANNEL_1
175 * @arg @ref LL_DAC_CHANNEL_2 (1)
177 * (1) On this STM32 serie, parameter not available on all devices.
178 * Refer to device datasheet for channels availability.
179 * @param DAC_InitStruct Pointer to a @ref LL_DAC_InitTypeDef structure
180 * @retval An ErrorStatus enumeration value:
181 * - SUCCESS: DAC registers are initialized
182 * - ERROR: DAC registers are not initialized
184 ErrorStatus
LL_DAC_Init(DAC_TypeDef
*DACx
, uint32_t DAC_Channel
, LL_DAC_InitTypeDef
*DAC_InitStruct
)
186 ErrorStatus status
= SUCCESS
;
188 /* Check the parameters */
189 assert_param(IS_DAC_ALL_INSTANCE(DACx
));
190 assert_param(IS_LL_DAC_CHANNEL(DACx
, DAC_Channel
));
191 assert_param(IS_LL_DAC_TRIGGER_SOURCE(DAC_InitStruct
->TriggerSource
));
192 assert_param(IS_LL_DAC_OUTPUT_BUFFER(DAC_InitStruct
->OutputBuffer
));
193 assert_param(IS_LL_DAC_WAVE_AUTO_GENER_MODE(DAC_InitStruct
->WaveAutoGeneration
));
194 if (DAC_InitStruct
->WaveAutoGeneration
!= LL_DAC_WAVE_AUTO_GENERATION_NONE
)
196 assert_param(IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(DAC_InitStruct
->WaveAutoGenerationConfig
));
199 /* Note: Hardware constraint (refer to description of this function) */
200 /* DAC instance must be disabled. */
201 if(LL_DAC_IsEnabled(DACx
, DAC_Channel
) == 0U)
203 /* Configuration of DAC channel: */
204 /* - TriggerSource */
205 /* - WaveAutoGeneration */
207 if (DAC_InitStruct
->WaveAutoGeneration
!= LL_DAC_WAVE_AUTO_GENERATION_NONE
)
214 ) << (DAC_Channel
& DAC_CR_CHX_BITOFFSET_MASK
)
216 ( DAC_InitStruct
->TriggerSource
217 | DAC_InitStruct
->WaveAutoGeneration
218 | DAC_InitStruct
->WaveAutoGenerationConfig
219 | DAC_InitStruct
->OutputBuffer
220 ) << (DAC_Channel
& DAC_CR_CHX_BITOFFSET_MASK
)
229 ) << (DAC_Channel
& DAC_CR_CHX_BITOFFSET_MASK
)
231 ( DAC_InitStruct
->TriggerSource
232 | LL_DAC_WAVE_AUTO_GENERATION_NONE
233 | DAC_InitStruct
->OutputBuffer
234 ) << (DAC_Channel
& DAC_CR_CHX_BITOFFSET_MASK
)
240 /* Initialization error: DAC instance is not disabled. */
247 * @brief Set each @ref LL_DAC_InitTypeDef field to default value.
248 * @param DAC_InitStruct pointer to a @ref LL_DAC_InitTypeDef structure
249 * whose fields will be set to default values.
252 void LL_DAC_StructInit(LL_DAC_InitTypeDef
*DAC_InitStruct
)
254 /* Set DAC_InitStruct fields to default values */
255 DAC_InitStruct
->TriggerSource
= LL_DAC_TRIG_SOFTWARE
;
256 DAC_InitStruct
->WaveAutoGeneration
= LL_DAC_WAVE_AUTO_GENERATION_NONE
;
257 /* Note: Parameter discarded if wave auto generation is disabled, */
258 /* set anyway to its default value. */
259 DAC_InitStruct
->WaveAutoGenerationConfig
= LL_DAC_NOISE_LFSR_UNMASK_BIT0
;
260 DAC_InitStruct
->OutputBuffer
= LL_DAC_OUTPUT_BUFFER_ENABLE
;
281 #endif /* USE_FULL_LL_DRIVER */
283 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/