2 ******************************************************************************
3 * @file stm32f1xx_ll_dac.c
4 * @author MCD Application Team
7 * @brief DAC LL module driver
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT(c) 2016 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 "stm32f1xx_ll_dac.h"
41 #include "stm32f1xx_ll_bus.h"
43 #ifdef USE_FULL_ASSERT
44 #include "stm32_assert.h"
46 #define assert_param(expr) ((void)0U)
49 /** @addtogroup STM32F1xx_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 #define IS_LL_DAC_CHANNEL(__DACX__, __DAC_CHANNEL__) \
70 ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_1) \
71 || ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_2) \
74 #define IS_LL_DAC_TRIGGER_SOURCE(__TRIGGER_SOURCE__) \
75 ( ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_SOFTWARE) \
76 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM3_TRGO) \
77 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM15_TRGO) \
78 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM2_TRGO) \
79 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM4_TRGO) \
80 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM5_TRGO) \
81 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM6_TRGO) \
82 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM7_TRGO) \
83 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM8_TRGO) \
84 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_EXTI_LINE9) \
86 #define IS_LL_DAC_WAVE_AUTO_GENER_MODE(__WAVE_AUTO_GENERATION_MODE__) \
87 ( ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NONE) \
88 || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NOISE) \
89 || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE) \
92 #define IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(__WAVE_AUTO_GENERATION_CONFIG__) \
93 ( ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BIT0) \
94 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS1_0) \
95 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS2_0) \
96 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS3_0) \
97 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS4_0) \
98 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS5_0) \
99 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS6_0) \
100 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS7_0) \
101 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS8_0) \
102 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS9_0) \
103 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS10_0) \
104 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS11_0) \
105 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1) \
106 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_3) \
107 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_7) \
108 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_15) \
109 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_31) \
110 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_63) \
111 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_127) \
112 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_255) \
113 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_511) \
114 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1023) \
115 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_2047) \
116 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_4095) \
119 #define IS_LL_DAC_OUTPUT_BUFFER(__OUTPUT_BUFFER__) \
120 ( ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_ENABLE) \
121 || ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_DISABLE) \
129 /* Private function prototypes -----------------------------------------------*/
131 /* Exported functions --------------------------------------------------------*/
132 /** @addtogroup DAC_LL_Exported_Functions
136 /** @addtogroup DAC_LL_EF_Init
141 * @brief De-initialize registers of the selected DAC instance
142 * to their default reset values.
143 * @param DACx DAC instance
144 * @retval An ErrorStatus enumeration value:
145 * - SUCCESS: DAC registers are de-initialized
146 * - ERROR: not applicable
148 ErrorStatus
LL_DAC_DeInit(DAC_TypeDef
*DACx
)
150 /* Check the parameters */
151 assert_param(IS_DAC_ALL_INSTANCE(DACx
));
153 /* Force reset of DAC1 clock */
154 LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_DAC1
);
156 /* Release reset of DAC1 clock */
157 LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_DAC1
);
162 * @brief Initialize some features of DAC instance.
163 * @note The setting of these parameters by function @ref LL_DAC_Init()
164 * is conditioned to DAC state:
165 * DAC instance must be disabled.
166 * @param DACx DAC instance
167 * @param DAC_Channel This parameter can be one of the following values:
168 * @arg @ref LL_DAC_CHANNEL_1
169 * @arg @ref LL_DAC_CHANNEL_2
170 * @param DAC_InitStruct Pointer to a @ref LL_DAC_InitTypeDef structure
171 * @retval An ErrorStatus enumeration value:
172 * - SUCCESS: DAC registers are initialized
173 * - ERROR: DAC registers are not initialized
175 ErrorStatus
LL_DAC_Init(DAC_TypeDef
*DACx
, uint32_t DAC_Channel
, LL_DAC_InitTypeDef
*DAC_InitStruct
)
177 ErrorStatus status
= SUCCESS
;
179 /* Check the parameters */
180 assert_param(IS_DAC_ALL_INSTANCE(DACx
));
181 assert_param(IS_LL_DAC_CHANNEL(DACx
, DAC_Channel
));
182 assert_param(IS_LL_DAC_TRIGGER_SOURCE(DAC_InitStruct
->TriggerSource
));
183 assert_param(IS_LL_DAC_OUTPUT_BUFFER(DAC_InitStruct
->OutputBuffer
));
184 assert_param(IS_LL_DAC_WAVE_AUTO_GENER_MODE(DAC_InitStruct
->WaveAutoGeneration
));
185 if (DAC_InitStruct
->WaveAutoGeneration
!= LL_DAC_WAVE_AUTO_GENERATION_NONE
)
187 assert_param(IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(DAC_InitStruct
->WaveAutoGenerationConfig
));
190 /* Note: Hardware constraint (refer to description of this function) */
191 /* DAC instance must be disabled. */
192 if(LL_DAC_IsEnabled(DACx
, DAC_Channel
) == 0U)
194 /* Configuration of DAC channel: */
195 /* - TriggerSource */
196 /* - WaveAutoGeneration */
198 if (DAC_InitStruct
->WaveAutoGeneration
!= LL_DAC_WAVE_AUTO_GENERATION_NONE
)
205 ) << (DAC_Channel
& DAC_CR_CHX_BITOFFSET_MASK
)
207 ( DAC_InitStruct
->TriggerSource
208 | DAC_InitStruct
->WaveAutoGeneration
209 | DAC_InitStruct
->WaveAutoGenerationConfig
210 | DAC_InitStruct
->OutputBuffer
211 ) << (DAC_Channel
& DAC_CR_CHX_BITOFFSET_MASK
)
220 ) << (DAC_Channel
& DAC_CR_CHX_BITOFFSET_MASK
)
222 ( DAC_InitStruct
->TriggerSource
223 | LL_DAC_WAVE_AUTO_GENERATION_NONE
224 | DAC_InitStruct
->OutputBuffer
225 ) << (DAC_Channel
& DAC_CR_CHX_BITOFFSET_MASK
)
231 /* Initialization error: DAC instance is not disabled. */
238 * @brief Set each @ref LL_DAC_InitTypeDef field to default value.
239 * @param DAC_InitStruct pointer to a @ref LL_DAC_InitTypeDef structure
240 * whose fields will be set to default values.
243 void LL_DAC_StructInit(LL_DAC_InitTypeDef
*DAC_InitStruct
)
245 /* Set DAC_InitStruct fields to default values */
246 DAC_InitStruct
->TriggerSource
= LL_DAC_TRIG_SOFTWARE
;
247 DAC_InitStruct
->WaveAutoGeneration
= LL_DAC_WAVE_AUTO_GENERATION_NONE
;
248 /* Note: Parameter discarded if wave auto generation is disabled, */
249 /* set anyway to its default value. */
250 DAC_InitStruct
->WaveAutoGenerationConfig
= LL_DAC_NOISE_LFSR_UNMASK_BIT0
;
251 DAC_InitStruct
->OutputBuffer
= LL_DAC_OUTPUT_BUFFER_ENABLE
;
272 #endif /* USE_FULL_LL_DRIVER */
274 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/