Mercurial > public > ostc4
comparison Common/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dac_ex.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_hal_dac_ex.c | |
4 * @author MCD Application Team | |
5 * @brief DAC HAL module driver. | |
6 * This file provides firmware functions to manage the following | |
7 * functionalities of DAC extension peripheral: | |
8 * + Extended features functions | |
9 * | |
10 * | |
11 @verbatim | |
12 ============================================================================== | |
13 ##### How to use this driver ##### | |
14 ============================================================================== | |
15 [..] | |
16 (+) When Dual mode is enabled (i.e DAC Channel1 and Channel2 are used simultaneously) : | |
17 Use HAL_DACEx_DualGetValue() to get digital data to be converted and use | |
18 HAL_DACEx_DualSetValue() to set digital value to converted simultaneously in Channel 1 and Channel 2. | |
19 (+) Use HAL_DACEx_TriangleWaveGenerate() to generate Triangle signal. | |
20 (+) Use HAL_DACEx_NoiseWaveGenerate() to generate Noise signal. | |
21 | |
22 @endverbatim | |
23 ****************************************************************************** | |
24 * @attention | |
25 * | |
26 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> | |
27 * | |
28 * Redistribution and use in source and binary forms, with or without modification, | |
29 * are permitted provided that the following conditions are met: | |
30 * 1. Redistributions of source code must retain the above copyright notice, | |
31 * this list of conditions and the following disclaimer. | |
32 * 2. Redistributions in binary form must reproduce the above copyright notice, | |
33 * this list of conditions and the following disclaimer in the documentation | |
34 * and/or other materials provided with the distribution. | |
35 * 3. Neither the name of STMicroelectronics nor the names of its contributors | |
36 * may be used to endorse or promote products derived from this software | |
37 * without specific prior written permission. | |
38 * | |
39 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
40 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
42 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |
43 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
44 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
45 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
46 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
47 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
48 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
49 * | |
50 ****************************************************************************** | |
51 */ | |
52 | |
53 | |
54 /* Includes ------------------------------------------------------------------*/ | |
55 #include "stm32f4xx_hal.h" | |
56 | |
57 /** @addtogroup STM32F4xx_HAL_Driver | |
58 * @{ | |
59 */ | |
60 | |
61 /** @defgroup DACEx DACEx | |
62 * @brief DAC driver modules | |
63 * @{ | |
64 */ | |
65 | |
66 #ifdef HAL_DAC_MODULE_ENABLED | |
67 | |
68 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) ||\ | |
69 defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\ | |
70 defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F446xx) ||\ | |
71 defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F413xx) || defined(STM32F423xx) | |
72 /* Private typedef -----------------------------------------------------------*/ | |
73 /* Private define ------------------------------------------------------------*/ | |
74 /* Private macro -------------------------------------------------------------*/ | |
75 /* Private variables ---------------------------------------------------------*/ | |
76 /* Private function prototypes -----------------------------------------------*/ | |
77 /* Private functions ---------------------------------------------------------*/ | |
78 /* Exported functions --------------------------------------------------------*/ | |
79 /** @defgroup DACEx_Exported_Functions DAC Exported Functions | |
80 * @{ | |
81 */ | |
82 | |
83 /** @defgroup DACEx_Exported_Functions_Group1 Extended features functions | |
84 * @brief Extended features functions | |
85 * | |
86 @verbatim | |
87 ============================================================================== | |
88 ##### Extended features functions ##### | |
89 ============================================================================== | |
90 [..] This section provides functions allowing to: | |
91 (+) Start conversion. | |
92 (+) Stop conversion. | |
93 (+) Start conversion and enable DMA transfer. | |
94 (+) Stop conversion and disable DMA transfer. | |
95 (+) Get result of conversion. | |
96 (+) Get result of dual mode conversion. | |
97 | |
98 @endverbatim | |
99 * @{ | |
100 */ | |
101 | |
102 /** | |
103 * @brief Returns the last data output value of the selected DAC channel. | |
104 * @param hdac pointer to a DAC_HandleTypeDef structure that contains | |
105 * the configuration information for the specified DAC. | |
106 * @retval The selected DAC channel data output value. | |
107 */ | |
108 uint32_t HAL_DACEx_DualGetValue(DAC_HandleTypeDef* hdac) | |
109 { | |
110 uint32_t tmp = 0U; | |
111 | |
112 tmp |= hdac->Instance->DOR1; | |
113 | |
114 tmp |= hdac->Instance->DOR2 << 16U; | |
115 | |
116 /* Returns the DAC channel data output register value */ | |
117 return tmp; | |
118 } | |
119 | |
120 /** | |
121 * @brief Enables or disables the selected DAC channel wave generation. | |
122 * @param hdac pointer to a DAC_HandleTypeDef structure that contains | |
123 * the configuration information for the specified DAC. | |
124 * @param Channel The selected DAC channel. | |
125 * This parameter can be one of the following values: | |
126 * DAC_CHANNEL_1 / DAC_CHANNEL_2 | |
127 * @param Amplitude Select max triangle amplitude. | |
128 * This parameter can be one of the following values: | |
129 * @arg DAC_TRIANGLEAMPLITUDE_1: Select max triangle amplitude of 1 | |
130 * @arg DAC_TRIANGLEAMPLITUDE_3: Select max triangle amplitude of 3 | |
131 * @arg DAC_TRIANGLEAMPLITUDE_7: Select max triangle amplitude of 7 | |
132 * @arg DAC_TRIANGLEAMPLITUDE_15: Select max triangle amplitude of 15 | |
133 * @arg DAC_TRIANGLEAMPLITUDE_31: Select max triangle amplitude of 31 | |
134 * @arg DAC_TRIANGLEAMPLITUDE_63: Select max triangle amplitude of 63 | |
135 * @arg DAC_TRIANGLEAMPLITUDE_127: Select max triangle amplitude of 127 | |
136 * @arg DAC_TRIANGLEAMPLITUDE_255: Select max triangle amplitude of 255 | |
137 * @arg DAC_TRIANGLEAMPLITUDE_511: Select max triangle amplitude of 511 | |
138 * @arg DAC_TRIANGLEAMPLITUDE_1023: Select max triangle amplitude of 1023 | |
139 * @arg DAC_TRIANGLEAMPLITUDE_2047: Select max triangle amplitude of 2047 | |
140 * @arg DAC_TRIANGLEAMPLITUDE_4095: Select max triangle amplitude of 4095 | |
141 * @retval HAL status | |
142 */ | |
143 HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Amplitude) | |
144 { | |
145 /* Check the parameters */ | |
146 assert_param(IS_DAC_CHANNEL(Channel)); | |
147 assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude)); | |
148 | |
149 /* Process locked */ | |
150 __HAL_LOCK(hdac); | |
151 | |
152 /* Change DAC state */ | |
153 hdac->State = HAL_DAC_STATE_BUSY; | |
154 | |
155 /* Enable the selected wave generation for the selected DAC channel */ | |
156 MODIFY_REG(hdac->Instance->CR, (DAC_CR_WAVE1 | DAC_CR_MAMP1) << Channel, (DAC_CR_WAVE1_1 | Amplitude) << Channel); | |
157 | |
158 /* Change DAC state */ | |
159 hdac->State = HAL_DAC_STATE_READY; | |
160 | |
161 /* Process unlocked */ | |
162 __HAL_UNLOCK(hdac); | |
163 | |
164 /* Return function status */ | |
165 return HAL_OK; | |
166 } | |
167 | |
168 /** | |
169 * @brief Enables or disables the selected DAC channel wave generation. | |
170 * @param hdac pointer to a DAC_HandleTypeDef structure that contains | |
171 * the configuration information for the specified DAC. | |
172 * @param Channel The selected DAC channel. | |
173 * This parameter can be one of the following values: | |
174 * DAC_CHANNEL_1 / DAC_CHANNEL_2 | |
175 * @param Amplitude Unmask DAC channel LFSR for noise wave generation. | |
176 * This parameter can be one of the following values: | |
177 * @arg DAC_LFSRUNMASK_BIT0: Unmask DAC channel LFSR bit0 for noise wave generation | |
178 * @arg DAC_LFSRUNMASK_BITS1_0: Unmask DAC channel LFSR bit[1:0] for noise wave generation | |
179 * @arg DAC_LFSRUNMASK_BITS2_0: Unmask DAC channel LFSR bit[2:0] for noise wave generation | |
180 * @arg DAC_LFSRUNMASK_BITS3_0: Unmask DAC channel LFSR bit[3:0] for noise wave generation | |
181 * @arg DAC_LFSRUNMASK_BITS4_0: Unmask DAC channel LFSR bit[4:0] for noise wave generation | |
182 * @arg DAC_LFSRUNMASK_BITS5_0: Unmask DAC channel LFSR bit[5:0] for noise wave generation | |
183 * @arg DAC_LFSRUNMASK_BITS6_0: Unmask DAC channel LFSR bit[6:0] for noise wave generation | |
184 * @arg DAC_LFSRUNMASK_BITS7_0: Unmask DAC channel LFSR bit[7:0] for noise wave generation | |
185 * @arg DAC_LFSRUNMASK_BITS8_0: Unmask DAC channel LFSR bit[8:0] for noise wave generation | |
186 * @arg DAC_LFSRUNMASK_BITS9_0: Unmask DAC channel LFSR bit[9:0] for noise wave generation | |
187 * @arg DAC_LFSRUNMASK_BITS10_0: Unmask DAC channel LFSR bit[10:0] for noise wave generation | |
188 * @arg DAC_LFSRUNMASK_BITS11_0: Unmask DAC channel LFSR bit[11:0] for noise wave generation | |
189 * @retval HAL status | |
190 */ | |
191 HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Amplitude) | |
192 { | |
193 /* Check the parameters */ | |
194 assert_param(IS_DAC_CHANNEL(Channel)); | |
195 assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(Amplitude)); | |
196 | |
197 /* Process locked */ | |
198 __HAL_LOCK(hdac); | |
199 | |
200 /* Change DAC state */ | |
201 hdac->State = HAL_DAC_STATE_BUSY; | |
202 | |
203 /* Enable the selected wave generation for the selected DAC channel */ | |
204 MODIFY_REG(hdac->Instance->CR, (DAC_CR_WAVE1 | DAC_CR_MAMP1) << Channel, (DAC_CR_WAVE1_0 | Amplitude) << Channel); | |
205 | |
206 /* Change DAC state */ | |
207 hdac->State = HAL_DAC_STATE_READY; | |
208 | |
209 /* Process unlocked */ | |
210 __HAL_UNLOCK(hdac); | |
211 | |
212 /* Return function status */ | |
213 return HAL_OK; | |
214 } | |
215 | |
216 /** | |
217 * @brief Set the specified data holding register value for dual DAC channel. | |
218 * @param hdac pointer to a DAC_HandleTypeDef structure that contains | |
219 * the configuration information for the specified DAC. | |
220 * @param Alignment Specifies the data alignment for dual channel DAC. | |
221 * This parameter can be one of the following values: | |
222 * DAC_ALIGN_8B_R: 8bit right data alignment selected | |
223 * DAC_ALIGN_12B_L: 12bit left data alignment selected | |
224 * DAC_ALIGN_12B_R: 12bit right data alignment selected | |
225 * @param Data1 Data for DAC Channel2 to be loaded in the selected data holding register. | |
226 * @param Data2 Data for DAC Channel1 to be loaded in the selected data holding register. | |
227 * @note In dual mode, a unique register access is required to write in both | |
228 * DAC channels at the same time. | |
229 * @retval HAL status | |
230 */ | |
231 HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef* hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2) | |
232 { | |
233 uint32_t data = 0U, tmp = 0U; | |
234 | |
235 /* Check the parameters */ | |
236 assert_param(IS_DAC_ALIGN(Alignment)); | |
237 assert_param(IS_DAC_DATA(Data1)); | |
238 assert_param(IS_DAC_DATA(Data2)); | |
239 | |
240 /* Calculate and set dual DAC data holding register value */ | |
241 if (Alignment == DAC_ALIGN_8B_R) | |
242 { | |
243 data = ((uint32_t)Data2 << 8U) | Data1; | |
244 } | |
245 else | |
246 { | |
247 data = ((uint32_t)Data2 << 16U) | Data1; | |
248 } | |
249 | |
250 tmp = (uint32_t)hdac->Instance; | |
251 tmp += DAC_DHR12RD_ALIGNMENT(Alignment); | |
252 | |
253 /* Set the dual DAC selected data holding register */ | |
254 *(__IO uint32_t *)tmp = data; | |
255 | |
256 /* Return function status */ | |
257 return HAL_OK; | |
258 } | |
259 | |
260 /** | |
261 * @} | |
262 */ | |
263 | |
264 /** | |
265 * @brief Conversion complete callback in non blocking mode for Channel2 | |
266 * @param hdac pointer to a DAC_HandleTypeDef structure that contains | |
267 * the configuration information for the specified DAC. | |
268 * @retval None | |
269 */ | |
270 __weak void HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef* hdac) | |
271 { | |
272 /* Prevent unused argument(s) compilation warning */ | |
273 UNUSED(hdac); | |
274 /* NOTE : This function Should not be modified, when the callback is needed, | |
275 the HAL_DAC_ConvCpltCallback could be implemented in the user file | |
276 */ | |
277 } | |
278 | |
279 /** | |
280 * @brief Conversion half DMA transfer callback in non blocking mode for Channel2 | |
281 * @param hdac pointer to a DAC_HandleTypeDef structure that contains | |
282 * the configuration information for the specified DAC. | |
283 * @retval None | |
284 */ | |
285 __weak void HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef* hdac) | |
286 { | |
287 /* Prevent unused argument(s) compilation warning */ | |
288 UNUSED(hdac); | |
289 /* NOTE : This function Should not be modified, when the callback is needed, | |
290 the HAL_DAC_ConvHalfCpltCallbackCh2 could be implemented in the user file | |
291 */ | |
292 } | |
293 | |
294 /** | |
295 * @brief Error DAC callback for Channel2. | |
296 * @param hdac pointer to a DAC_HandleTypeDef structure that contains | |
297 * the configuration information for the specified DAC. | |
298 * @retval None | |
299 */ | |
300 __weak void HAL_DACEx_ErrorCallbackCh2(DAC_HandleTypeDef *hdac) | |
301 { | |
302 /* Prevent unused argument(s) compilation warning */ | |
303 UNUSED(hdac); | |
304 /* NOTE : This function Should not be modified, when the callback is needed, | |
305 the HAL_DAC_ErrorCallback could be implemented in the user file | |
306 */ | |
307 } | |
308 | |
309 /** | |
310 * @brief DMA underrun DAC callback for channel2. | |
311 * @param hdac pointer to a DAC_HandleTypeDef structure that contains | |
312 * the configuration information for the specified DAC. | |
313 * @retval None | |
314 */ | |
315 __weak void HAL_DACEx_DMAUnderrunCallbackCh2(DAC_HandleTypeDef *hdac) | |
316 { | |
317 /* Prevent unused argument(s) compilation warning */ | |
318 UNUSED(hdac); | |
319 /* NOTE : This function Should not be modified, when the callback is needed, | |
320 the HAL_DAC_DMAUnderrunCallbackCh2 could be implemented in the user file | |
321 */ | |
322 } | |
323 | |
324 /** | |
325 * @brief DMA conversion complete callback. | |
326 * @param hdma pointer to a DMA_HandleTypeDef structure that contains | |
327 * the configuration information for the specified DMA module. | |
328 * @retval None | |
329 */ | |
330 void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma) | |
331 { | |
332 DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; | |
333 | |
334 HAL_DACEx_ConvCpltCallbackCh2(hdac); | |
335 | |
336 hdac->State= HAL_DAC_STATE_READY; | |
337 } | |
338 | |
339 /** | |
340 * @brief DMA half transfer complete callback. | |
341 * @param hdma pointer to a DMA_HandleTypeDef structure that contains | |
342 * the configuration information for the specified DMA module. | |
343 * @retval None | |
344 */ | |
345 void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma) | |
346 { | |
347 DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; | |
348 /* Conversion complete callback */ | |
349 HAL_DACEx_ConvHalfCpltCallbackCh2(hdac); | |
350 } | |
351 | |
352 /** | |
353 * @brief DMA error callback | |
354 * @param hdma pointer to a DMA_HandleTypeDef structure that contains | |
355 * the configuration information for the specified DMA module. | |
356 * @retval None | |
357 */ | |
358 void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma) | |
359 { | |
360 DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; | |
361 | |
362 /* Set DAC error code to DMA error */ | |
363 hdac->ErrorCode |= HAL_DAC_ERROR_DMA; | |
364 | |
365 HAL_DACEx_ErrorCallbackCh2(hdac); | |
366 | |
367 hdac->State= HAL_DAC_STATE_READY; | |
368 } | |
369 | |
370 /** | |
371 * @} | |
372 */ | |
373 | |
374 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx ||\ | |
375 STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx ||\ | |
376 STM32F410xx || STM32F446xx || STM32F469xx || STM32F479xx ||\ | |
377 STM32F413xx || STM32F423xx */ | |
378 | |
379 #endif /* HAL_DAC_MODULE_ENABLED */ | |
380 | |
381 /** | |
382 * @} | |
383 */ | |
384 | |
385 /** | |
386 * @} | |
387 */ | |
388 | |
389 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |