comparison Common/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_dac.c @ 128:c78bcbd5deda FlipDisplay

Added current STM32 standandard libraries in version independend folder structure
author Ideenmodellierer
date Sun, 17 Feb 2019 21:12:22 +0100
parents
children
comparison
equal deleted inserted replaced
127:1369f8660eaa 128:c78bcbd5deda
1 /**
2 ******************************************************************************
3 * @file stm32f4xx_ll_dac.c
4 * @author MCD Application Team
5 * @brief DAC LL module driver
6 ******************************************************************************
7 * @attention
8 *
9 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
10 *
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.
21 *
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.
32 *
33 ******************************************************************************
34 */
35 #if defined(USE_FULL_LL_DRIVER)
36
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32f4xx_ll_dac.h"
39 #include "stm32f4xx_ll_bus.h"
40
41 #ifdef USE_FULL_ASSERT
42 #include "stm32_assert.h"
43 #else
44 #define assert_param(expr) ((void)0U)
45 #endif
46
47 /** @addtogroup STM32F4xx_LL_Driver
48 * @{
49 */
50
51 #if defined(DAC)
52
53 /** @addtogroup DAC_LL DAC
54 * @{
55 */
56
57 /* Private types -------------------------------------------------------------*/
58 /* Private variables ---------------------------------------------------------*/
59 /* Private constants ---------------------------------------------------------*/
60 /* Private macros ------------------------------------------------------------*/
61
62 /** @addtogroup DAC_LL_Private_Macros
63 * @{
64 */
65
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) \
71 )
72 #else
73 #define IS_LL_DAC_CHANNEL(__DACX__, __DAC_CHANNEL__) \
74 ( \
75 ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_1) \
76 )
77 #endif /* DAC_CHANNEL2_SUPPORT */
78
79 #define IS_LL_DAC_TRIGGER_SOURCE(__TRIGGER_SOURCE__) \
80 ( ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_SOFTWARE) \
81 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM2_TRGO) \
82 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM4_TRGO) \
83 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM5_TRGO) \
84 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM6_TRGO) \
85 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM7_TRGO) \
86 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM8_TRGO) \
87 || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_EXTI_LINE9) \
88 )
89
90 #define IS_LL_DAC_WAVE_AUTO_GENER_MODE(__WAVE_AUTO_GENERATION_MODE__) \
91 ( ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NONE) \
92 || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NOISE) \
93 || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE) \
94 )
95
96 #define IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(__WAVE_AUTO_GENERATION_CONFIG__) \
97 ( ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BIT0) \
98 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS1_0) \
99 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS2_0) \
100 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS3_0) \
101 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS4_0) \
102 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS5_0) \
103 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS6_0) \
104 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS7_0) \
105 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS8_0) \
106 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS9_0) \
107 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS10_0) \
108 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS11_0) \
109 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1) \
110 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_3) \
111 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_7) \
112 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_15) \
113 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_31) \
114 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_63) \
115 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_127) \
116 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_255) \
117 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_511) \
118 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1023) \
119 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_2047) \
120 || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_4095) \
121 )
122
123 #define IS_LL_DAC_OUTPUT_BUFFER(__OUTPUT_BUFFER__) \
124 ( ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_ENABLE) \
125 || ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_DISABLE) \
126 )
127
128 /**
129 * @}
130 */
131
132
133 /* Private function prototypes -----------------------------------------------*/
134
135 /* Exported functions --------------------------------------------------------*/
136 /** @addtogroup DAC_LL_Exported_Functions
137 * @{
138 */
139
140 /** @addtogroup DAC_LL_EF_Init
141 * @{
142 */
143
144 /**
145 * @brief De-initialize registers of the selected DAC instance
146 * to their default reset values.
147 * @param DACx DAC instance
148 * @retval An ErrorStatus enumeration value:
149 * - SUCCESS: DAC registers are de-initialized
150 * - ERROR: not applicable
151 */
152 ErrorStatus LL_DAC_DeInit(DAC_TypeDef *DACx)
153 {
154 /* Check the parameters */
155 assert_param(IS_DAC_ALL_INSTANCE(DACx));
156
157 /* Force reset of DAC1 clock */
158 LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_DAC1);
159
160 /* Release reset of DAC1 clock */
161 LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_DAC1);
162 return SUCCESS;
163 }
164
165 /**
166 * @brief Initialize some features of DAC instance.
167 * @note The setting of these parameters by function @ref LL_DAC_Init()
168 * is conditioned to DAC state:
169 * DAC instance must be disabled.
170 * @param DACx DAC instance
171 * @param DAC_Channel This parameter can be one of the following values:
172 * @arg @ref LL_DAC_CHANNEL_1
173 * @arg @ref LL_DAC_CHANNEL_2 (1)
174 *
175 * (1) On this STM32 serie, parameter not available on all devices.
176 * Refer to device datasheet for channels availability.
177 * @param DAC_InitStruct Pointer to a @ref LL_DAC_InitTypeDef structure
178 * @retval An ErrorStatus enumeration value:
179 * - SUCCESS: DAC registers are initialized
180 * - ERROR: DAC registers are not initialized
181 */
182 ErrorStatus LL_DAC_Init(DAC_TypeDef *DACx, uint32_t DAC_Channel, LL_DAC_InitTypeDef *DAC_InitStruct)
183 {
184 ErrorStatus status = SUCCESS;
185
186 /* Check the parameters */
187 assert_param(IS_DAC_ALL_INSTANCE(DACx));
188 assert_param(IS_LL_DAC_CHANNEL(DACx, DAC_Channel));
189 assert_param(IS_LL_DAC_TRIGGER_SOURCE(DAC_InitStruct->TriggerSource));
190 assert_param(IS_LL_DAC_OUTPUT_BUFFER(DAC_InitStruct->OutputBuffer));
191 assert_param(IS_LL_DAC_WAVE_AUTO_GENER_MODE(DAC_InitStruct->WaveAutoGeneration));
192 if (DAC_InitStruct->WaveAutoGeneration != LL_DAC_WAVE_AUTO_GENERATION_NONE)
193 {
194 assert_param(IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(DAC_InitStruct->WaveAutoGenerationConfig));
195 }
196
197 /* Note: Hardware constraint (refer to description of this function) */
198 /* DAC instance must be disabled. */
199 if(LL_DAC_IsEnabled(DACx, DAC_Channel) == 0U)
200 {
201 /* Configuration of DAC channel: */
202 /* - TriggerSource */
203 /* - WaveAutoGeneration */
204 /* - OutputBuffer */
205 if (DAC_InitStruct->WaveAutoGeneration != LL_DAC_WAVE_AUTO_GENERATION_NONE)
206 {
207 MODIFY_REG(DACx->CR,
208 ( DAC_CR_TSEL1
209 | DAC_CR_WAVE1
210 | DAC_CR_MAMP1
211 | DAC_CR_BOFF1
212 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
213 ,
214 ( DAC_InitStruct->TriggerSource
215 | DAC_InitStruct->WaveAutoGeneration
216 | DAC_InitStruct->WaveAutoGenerationConfig
217 | DAC_InitStruct->OutputBuffer
218 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
219 );
220 }
221 else
222 {
223 MODIFY_REG(DACx->CR,
224 ( DAC_CR_TSEL1
225 | DAC_CR_WAVE1
226 | DAC_CR_BOFF1
227 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
228 ,
229 ( DAC_InitStruct->TriggerSource
230 | LL_DAC_WAVE_AUTO_GENERATION_NONE
231 | DAC_InitStruct->OutputBuffer
232 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK)
233 );
234 }
235 }
236 else
237 {
238 /* Initialization error: DAC instance is not disabled. */
239 status = ERROR;
240 }
241 return status;
242 }
243
244 /**
245 * @brief Set each @ref LL_DAC_InitTypeDef field to default value.
246 * @param DAC_InitStruct pointer to a @ref LL_DAC_InitTypeDef structure
247 * whose fields will be set to default values.
248 * @retval None
249 */
250 void LL_DAC_StructInit(LL_DAC_InitTypeDef *DAC_InitStruct)
251 {
252 /* Set DAC_InitStruct fields to default values */
253 DAC_InitStruct->TriggerSource = LL_DAC_TRIG_SOFTWARE;
254 DAC_InitStruct->WaveAutoGeneration = LL_DAC_WAVE_AUTO_GENERATION_NONE;
255 /* Note: Parameter discarded if wave auto generation is disabled, */
256 /* set anyway to its default value. */
257 DAC_InitStruct->WaveAutoGenerationConfig = LL_DAC_NOISE_LFSR_UNMASK_BIT0;
258 DAC_InitStruct->OutputBuffer = LL_DAC_OUTPUT_BUFFER_ENABLE;
259 }
260
261 /**
262 * @}
263 */
264
265 /**
266 * @}
267 */
268
269 /**
270 * @}
271 */
272
273 #endif /* DAC */
274
275 /**
276 * @}
277 */
278
279 #endif /* USE_FULL_LL_DRIVER */
280
281 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/