Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 9 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /** |
1 | /** |
2 | ****************************************************************************** |
2 | ****************************************************************************** |
3 | * @file stm32f1xx_hal_dac.c |
3 | * @file stm32f1xx_hal_dac.c |
4 | * @author MCD Application Team |
4 | * @author MCD Application Team |
5 | * @brief DAC HAL module driver. |
5 | * @brief DAC HAL module driver. |
6 | * This file provides firmware functions to manage the following |
6 | * This file provides firmware functions to manage the following |
7 | * functionalities of the Digital to Analog Converter (DAC) peripheral: |
7 | * functionalities of the Digital to Analog Converter (DAC) peripheral: |
8 | * + Initialization and de-initialization functions |
8 | * + Initialization and de-initialization functions |
9 | * + IO operation functions |
9 | * + IO operation functions |
10 | * + Peripheral Control functions |
10 | * + Peripheral Control functions |
11 | * + Peripheral State and Errors functions |
11 | * + Peripheral State and Errors functions |
12 | * |
- | |
13 | * |
12 | * |
- | 13 | * |
|
14 | @verbatim |
14 | @verbatim |
15 | ============================================================================== |
15 | ============================================================================== |
16 | ##### DAC Peripheral features ##### |
16 | ##### DAC Peripheral features ##### |
17 | ============================================================================== |
17 | ============================================================================== |
18 | [..] |
18 | [..] |
19 | *** DAC Channels *** |
19 | *** DAC Channels *** |
20 | ==================== |
20 | ==================== |
21 | [..] |
21 | [..] |
22 | The device integrates two 12-bit Digital Analog Converters that can |
22 | STM32F1 devices integrate two 12-bit Digital Analog Converters |
- | 23 | ||
- | 24 | The 2 converters (i.e. channel1 & channel2) |
|
23 | be used independently or simultaneously (dual mode): |
25 | can be used independently or simultaneously (dual mode): |
24 | (#) DAC channel1 with DAC_OUT1 (PA4) as output |
26 | (#) DAC channel1 with DAC_OUT1 (PA4) as output or connected to on-chip |
- | 27 | peripherals (ex. timers). |
|
25 | (#) DAC channel2 with DAC_OUT2 (PA5) as output |
28 | (#) DAC channel2 with DAC_OUT2 (PA5) as output or connected to on-chip |
- | 29 | peripherals (ex. timers). |
|
26 | |
30 | |
27 | *** DAC Triggers *** |
31 | *** DAC Triggers *** |
28 | ==================== |
32 | ==================== |
29 | [..] |
33 | [..] |
30 | Digital to Analog conversion can be non-triggered using DAC_TRIGGER_NONE |
34 | Digital to Analog conversion can be non-triggered using DAC_TRIGGER_NONE |
31 | and DAC_OUT1/DAC_OUT2 is available once writing to DHRx register. |
35 | and DAC_OUT1/DAC_OUT2 is available once writing to DHRx register. |
32 | [..] |
36 | [..] |
33 | Digital to Analog conversion can be triggered by: |
37 | Digital to Analog conversion can be triggered by: |
34 | (#) External event: EXTI Line 9 (any GPIOx_PIN_9) using DAC_TRIGGER_EXT_IT9. |
38 | (#) External event: EXTI Line 9 (any GPIOx_PIN_9) using DAC_TRIGGER_EXT_IT9. |
35 | The used pin (GPIOx_PIN_9) must be configured in input mode. |
39 | The used pin (GPIOx_PIN_9) must be configured in input mode. |
36 | |
40 | |
37 | (#) Timers TRGO: TIM2, TIM4, TIM6, TIM7 |
41 | (#) Timers TRGO: TIM2, TIM4, TIM6, TIM7 |
38 | For STM32F10x connectivity line devices and STM32F100x devices: TIM3 |
42 | For STM32F10x connectivity line devices and STM32F100x devices: TIM3 |
39 | For STM32F10x high-density and XL-density devices: TIM8 |
43 | For STM32F10x high-density and XL-density devices: TIM8 |
40 | For STM32F100x high-density value line devices: TIM15 as |
44 | For STM32F100x high-density value line devices: TIM15 as |
41 | replacement of TIM5. |
45 | replacement of TIM5. |
42 | (DAC_TRIGGER_T2_TRGO, DAC_TRIGGER_T4_TRGO...) |
46 | (DAC_TRIGGER_T2_TRGO, DAC_TRIGGER_T4_TRGO...) |
43 | |
47 | |
44 | (#) Software using DAC_TRIGGER_SOFTWARE |
48 | (#) Software using DAC_TRIGGER_SOFTWARE |
45 | |
49 | |
46 | *** DAC Buffer mode feature *** |
50 | *** DAC Buffer mode feature *** |
47 | =============================== |
51 | =============================== |
48 | [..] |
52 | [..] |
49 | Each DAC channel integrates an output buffer that can be used to |
53 | Each DAC channel integrates an output buffer that can be used to |
50 | reduce the output impedance, and to drive external loads directly |
54 | reduce the output impedance, and to drive external loads directly |
51 | without having to add an external operational amplifier. |
55 | without having to add an external operational amplifier. |
52 | To enable, the output buffer use |
56 | To enable, the output buffer use |
53 | sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE; |
57 | sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE; |
54 | [..] |
58 | [..] |
55 | (@) Refer to the device datasheet for more details about output |
59 | (@) Refer to the device datasheet for more details about output |
56 | impedance value with and without output buffer. |
60 | impedance value with and without output buffer. |
57 | 61 | ||
58 | *** DAC connect feature *** |
62 | *** DAC connect feature *** |
59 | =============================== |
63 | =============================== |
60 | [..] |
64 | [..] |
61 | Each DAC channel can be connected internally. |
65 | Each DAC channel can be connected internally. |
62 | To connect, use |
66 | To connect, use |
63 | sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_ENABLE; |
67 | sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_ENABLE; |
64 | |
- | |
- | 68 | ||
65 | *** GPIO configurations guidelines *** |
69 | *** GPIO configurations guidelines *** |
66 | ===================== |
70 | ===================== |
67 | [..] |
71 | [..] |
68 | When a DAC channel is used (ex channel1 on PA4) and the other is not |
72 | When a DAC channel is used (ex channel1 on PA4) and the other is not |
69 | (ex channel1 on PA5 is configured in Analog and disabled). |
73 | (ex channel2 on PA5 is configured in Analog and disabled). |
70 | Channel1 may disturb channel2 as coupling effect. |
74 | Channel1 may disturb channel2 as coupling effect. |
71 | Note that there is no coupling on channel2 as soon as channel2 is turned on. |
75 | Note that there is no coupling on channel2 as soon as channel2 is turned on. |
72 | Coupling on adjacent channel could be avoided as follows: |
76 | Coupling on adjacent channel could be avoided as follows: |
73 | when unused PA5 is configured as INPUT PULL-UP or DOWN. |
77 | when unused PA5 is configured as INPUT PULL-UP or DOWN. |
74 | PA5 is configured in ANALOG just before it is turned on. |
78 | PA5 is configured in ANALOG just before it is turned on. |
75 | |
- | |
- | 79 | ||
76 | *** DAC wave generation feature *** |
80 | *** DAC wave generation feature *** |
77 | =================================== |
81 | =================================== |
78 | [..] |
82 | [..] |
79 | Both DAC channels can be used to generate |
83 | Both DAC channels can be used to generate |
80 | (#) Noise wave using HAL_DACEx_NoiseWaveGenerate() |
84 | (#) Noise wave |
81 | (#) Triangle wave using HAL_DACEx_TriangleWaveGenerate() |
- | |
82 | |
85 | (#) Triangle wave |
- | 86 | ||
83 | *** DAC data format *** |
87 | *** DAC data format *** |
84 | ======================= |
88 | ======================= |
85 | [..] |
89 | [..] |
86 | The DAC data format can be: |
90 | The DAC data format can be: |
87 | (#) 8-bit right alignment using DAC_ALIGN_8B_R |
91 | (#) 8-bit right alignment using DAC_ALIGN_8B_R |
88 | (#) 12-bit left alignment using DAC_ALIGN_12B_L |
92 | (#) 12-bit left alignment using DAC_ALIGN_12B_L |
89 | (#) 12-bit right alignment using DAC_ALIGN_12B_R |
93 | (#) 12-bit right alignment using DAC_ALIGN_12B_R |
90 | |
94 | |
91 | *** DAC data value to voltage correspondance *** |
95 | *** DAC data value to voltage correspondence *** |
92 | ================================================ |
96 | ================================================ |
93 | [..] |
97 | [..] |
94 | The analog output voltage on each DAC channel pin is determined |
98 | The analog output voltage on each DAC channel pin is determined |
95 | by the following equation: |
99 | by the following equation: |
96 | [..] |
100 | [..] |
97 | DAC_OUTx = VREF+ * DOR / 4095 |
101 | DAC_OUTx = VREF+ * DOR / 4095 |
98 | (+) with DOR is the Data Output Register |
102 | (+) with DOR is the Data Output Register |
Line 100... | Line 104... | ||
100 | VEF+ is the input voltage reference (refer to the device datasheet) |
104 | VEF+ is the input voltage reference (refer to the device datasheet) |
101 | [..] |
105 | [..] |
102 | e.g. To set DAC_OUT1 to 0.7V, use |
106 | e.g. To set DAC_OUT1 to 0.7V, use |
103 | (+) Assuming that VREF+ = 3.3V, DAC_OUT1 = (3.3 * 868) / 4095 = 0.7V |
107 | (+) Assuming that VREF+ = 3.3V, DAC_OUT1 = (3.3 * 868) / 4095 = 0.7V |
104 | 108 | ||
105 | *** DMA requests *** |
109 | *** DMA requests *** |
106 | ===================== |
110 | ===================== |
107 | [..] |
- | |
108 | A DMA1 request can be generated when an external trigger (but not |
- | |
109 | a software trigger) occurs if DMA1 requests are enabled using |
- | |
110 | HAL_DAC_Start_DMA() |
- | |
111 | [..] |
111 | [..] |
112 | DMA requests are mapped as following: |
- | |
113 | (#) DAC channel1 : |
- | |
114 | For STM32F100x low-density, medium-density, high-density with DAC |
112 | A DMA request can be generated when an external trigger (but not a software trigger) |
115 | DMA remap: |
- | |
116 | mapped on DMA1 channel3 which must be |
113 | occurs if DMA1 requests are enabled using HAL_DAC_Start_DMA(). |
117 | already configured |
114 | DMA1 requests are mapped as following: |
118 | For STM32F100x high-density without DAC DMA remap and other |
- | |
119 | STM32F1 devices: |
- | |
120 | mapped on DMA2 channel3 which must be |
115 | (#) DAC channel1 mapped on DMA1 channel3 |
121 | already configured |
- | |
122 | (#) DAC channel2 : |
- | |
123 | For STM32F100x low-density, medium-density, high-density with DAC |
116 | for STM32F100x low-density, medium-density, high-density with DAC |
124 | DMA remap: |
117 | DMA remap: |
125 | mapped on DMA1 channel4 which must be |
118 | (#) DAC channel2 mapped on DMA2 channel3 |
126 | already configured |
- | |
127 | For STM32F100x high-density without DAC DMA remap and other |
119 | for STM32F100x high-density without DAC DMA remap and other |
128 | STM32F1 devices: |
120 | STM32F1 devices |
- | 121 | ||
- | 122 | [..] |
|
129 | mapped on DMA2 channel4 which must be |
123 | (@) For Dual mode and specific signal (Triangle and noise) generation please |
130 | already configured |
124 | refer to Extended Features Driver description |
131 | |
125 | |
132 | ##### How to use this driver ##### |
126 | ##### How to use this driver ##### |
133 | ============================================================================== |
127 | ============================================================================== |
134 | [..] |
128 | [..] |
135 | (+) DAC APB clock must be enabled to get write access to DAC |
129 | (+) DAC APB clock must be enabled to get write access to DAC |
136 | registers using HAL_DAC_Init() |
130 | registers using HAL_DAC_Init() |
137 | (+) Configure DAC_OUTx (DAC_OUT1: PA4, DAC_OUT2: PA5) in analog mode. |
131 | (+) Configure DAC_OUTx (DAC_OUT1: PA4, DAC_OUT2: PA5) in analog mode. |
138 | (+) Configure the DAC channel using HAL_DAC_ConfigChannel() function. |
132 | (+) Configure the DAC channel using HAL_DAC_ConfigChannel() function. |
139 | (+) Enable the DAC channel using HAL_DAC_Start() or HAL_DAC_Start_DMA functions |
133 | (+) Enable the DAC channel using HAL_DAC_Start() or HAL_DAC_Start_DMA() functions. |
- | 134 | ||
140 | 135 | ||
141 | *** Polling mode IO operation *** |
136 | *** Polling mode IO operation *** |
142 | ================================= |
137 | ================================= |
143 | [..] |
138 | [..] |
144 | (+) Start the DAC peripheral using HAL_DAC_Start() |
139 | (+) Start the DAC peripheral using HAL_DAC_Start() |
145 | (+) To read the DAC last data output value, use the HAL_DAC_GetValue() function. |
140 | (+) To read the DAC last data output value, use the HAL_DAC_GetValue() function. |
146 | (+) Stop the DAC peripheral using HAL_DAC_Stop() |
141 | (+) Stop the DAC peripheral using HAL_DAC_Stop() |
147 | |
142 | |
148 | *** DMA mode IO operation *** |
143 | *** DMA mode IO operation *** |
149 | ============================== |
144 | ============================== |
150 | [..] |
145 | [..] |
151 | (+) Start the DAC peripheral using HAL_DAC_Start_DMA(), at this stage the user specify the length |
146 | (+) Start the DAC peripheral using HAL_DAC_Start_DMA(), at this stage the user specify the length |
152 | of data to be transferred at each end of conversion |
147 | of data to be transferred at each end of conversion |
- | 148 | First issued trigger will start the conversion of the value previously set by HAL_DAC_SetValue(). |
|
153 | (+) At the middle of data transfer HAL_DACEx_ConvHalfCpltCallbackCh1()or HAL_DACEx_ConvHalfCpltCallbackCh2() |
149 | (+) At the middle of data transfer HAL_DAC_ConvHalfCpltCallbackCh1() or HAL_DACEx_ConvHalfCpltCallbackCh2() |
154 | function is executed and user can add his own code by customization of function pointer |
150 | function is executed and user can add his own code by customization of function pointer |
155 | HAL_DAC_ConvHalfCpltCallbackCh1 or HAL_DAC_ConvHalfCpltCallbackCh2 |
151 | HAL_DAC_ConvHalfCpltCallbackCh1() or HAL_DACEx_ConvHalfCpltCallbackCh2() |
156 | (+) At The end of data transfer HAL_DAC_ConvCpltCallbackCh1()or HAL_DAC_ConvCpltCallbackCh2() |
152 | (+) At The end of data transfer HAL_DAC_ConvCpltCallbackCh1() or HAL_DACEx_ConvHalfCpltCallbackCh2() |
157 | function is executed and user can add his own code by customization of function pointer |
153 | function is executed and user can add his own code by customization of function pointer |
158 | HAL_DAC_ConvCpltCallbackCh1 or HAL_DAC_ConvCpltCallbackCh2 |
154 | HAL_DAC_ConvCpltCallbackCh1() or HAL_DACEx_ConvHalfCpltCallbackCh2() |
159 | (+) In case of transfer Error, HAL_DAC_ErrorCallbackCh1() or HAL_DACEx_ErrorCallbackCh2() function is executed and user can |
155 | (+) In case of transfer Error, HAL_DAC_ErrorCallbackCh1() function is executed and user can |
160 | add his own code by customization of function pointer HAL_DAC_ErrorCallbackCh1 or HAL_DACEx_ErrorCallbackCh2 |
156 | add his own code by customization of function pointer HAL_DAC_ErrorCallbackCh1 |
161 | (+) For STM32F100x devices with specific feature: DMA underrun. |
157 | (+) For STM32F100x devices with specific feature: DMA underrun. |
162 | In case of DMA underrun, DAC interruption triggers and execute internal function HAL_DAC_IRQHandler. |
158 | In case of DMA underrun, DAC interruption triggers and execute internal function HAL_DAC_IRQHandler. |
163 | HAL_DAC_DMAUnderrunCallbackCh1()or HAL_DACEx_DMAUnderrunCallbackCh2() |
159 | HAL_DAC_DMAUnderrunCallbackCh1() or HAL_DACEx_DMAUnderrunCallbackCh2() |
164 | function is executed and user can add his own code by customization of function pointer |
160 | function is executed and user can add his own code by customization of function pointer |
165 | HAL_DAC_DMAUnderrunCallbackCh1 or HAL_DACEx_DMAUnderrunCallbackCh2 |
161 | HAL_DAC_DMAUnderrunCallbackCh1() or HAL_DACEx_DMAUnderrunCallbackCh2() and |
166 | add his own code by customization of function pointer HAL_DAC_ErrorCallbackCh1 |
162 | add his own code by customization of function pointer HAL_DAC_ErrorCallbackCh1() |
167 | (+) Stop the DAC peripheral using HAL_DAC_Stop_DMA() |
163 | (+) Stop the DAC peripheral using HAL_DAC_Stop_DMA() |
- | 164 | ||
- | 165 | *** Callback registration *** |
|
- | 166 | ============================================= |
|
- | 167 | [..] |
|
- | 168 | The compilation define USE_HAL_DAC_REGISTER_CALLBACKS when set to 1 |
|
- | 169 | allows the user to configure dynamically the driver callbacks. |
|
- | 170 | ||
- | 171 | Use Functions @ref HAL_DAC_RegisterCallback() to register a user callback, |
|
- | 172 | it allows to register following callbacks: |
|
- | 173 | (+) ConvCpltCallbackCh1 : callback when a half transfer is completed on Ch1. |
|
- | 174 | (+) ConvHalfCpltCallbackCh1 : callback when a transfer is completed on Ch1. |
|
- | 175 | (+) ErrorCallbackCh1 : callback when an error occurs on Ch1. |
|
- | 176 | (+) DMAUnderrunCallbackCh1 : callback when an underrun error occurs on Ch1. |
|
- | 177 | (+) ConvCpltCallbackCh2 : callback when a half transfer is completed on Ch2. |
|
- | 178 | (+) ConvHalfCpltCallbackCh2 : callback when a transfer is completed on Ch2. |
|
- | 179 | (+) ErrorCallbackCh2 : callback when an error occurs on Ch2. |
|
- | 180 | (+) DMAUnderrunCallbackCh2 : callback when an underrun error occurs on Ch2. |
|
- | 181 | (+) MspInitCallback : DAC MspInit. |
|
- | 182 | (+) MspDeInitCallback : DAC MspdeInit. |
|
- | 183 | This function takes as parameters the HAL peripheral handle, the Callback ID |
|
- | 184 | and a pointer to the user callback function. |
|
- | 185 | ||
- | 186 | Use function @ref HAL_DAC_UnRegisterCallback() to reset a callback to the default |
|
- | 187 | weak (surcharged) function. It allows to reset following callbacks: |
|
- | 188 | (+) ConvCpltCallbackCh1 : callback when a half transfer is completed on Ch1. |
|
- | 189 | (+) ConvHalfCpltCallbackCh1 : callback when a transfer is completed on Ch1. |
|
- | 190 | (+) ErrorCallbackCh1 : callback when an error occurs on Ch1. |
|
- | 191 | (+) DMAUnderrunCallbackCh1 : callback when an underrun error occurs on Ch1. |
|
- | 192 | (+) ConvCpltCallbackCh2 : callback when a half transfer is completed on Ch2. |
|
- | 193 | (+) ConvHalfCpltCallbackCh2 : callback when a transfer is completed on Ch2. |
|
- | 194 | (+) ErrorCallbackCh2 : callback when an error occurs on Ch2. |
|
- | 195 | (+) DMAUnderrunCallbackCh2 : callback when an underrun error occurs on Ch2. |
|
- | 196 | (+) MspInitCallback : DAC MspInit. |
|
- | 197 | (+) MspDeInitCallback : DAC MspdeInit. |
|
168 | |
198 | (+) All Callbacks |
- | 199 | This function) takes as parameters the HAL peripheral handle and the Callback ID. |
|
- | 200 | ||
- | 201 | By default, after the @ref HAL_DAC_Init and if the state is HAL_DAC_STATE_RESET |
|
- | 202 | all callbacks are reset to the corresponding legacy weak (surcharged) functions. |
|
- | 203 | Exception done for MspInit and MspDeInit callbacks that are respectively |
|
- | 204 | reset to the legacy weak (surcharged) functions in the @ref HAL_DAC_Init |
|
- | 205 | and @ref HAL_DAC_DeInit only when these callbacks are null (not registered beforehand). |
|
- | 206 | If not, MspInit or MspDeInit are not null, the @ref HAL_DAC_Init and @ref HAL_DAC_DeInit |
|
- | 207 | keep and use the user MspInit/MspDeInit callbacks (registered beforehand) |
|
- | 208 | ||
- | 209 | Callbacks can be registered/unregistered in READY state only. |
|
- | 210 | Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered |
|
- | 211 | in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used |
|
- | 212 | during the Init/DeInit. |
|
- | 213 | In that case first register the MspInit/MspDeInit user callbacks |
|
- | 214 | using @ref HAL_DAC_RegisterCallback before calling @ref HAL_DAC_DeInit |
|
- | 215 | or @ref HAL_DAC_Init function. |
|
- | 216 | ||
- | 217 | When The compilation define USE_HAL_DAC_REGISTER_CALLBACKS is set to 0 or |
|
- | 218 | not defined, the callback registering feature is not available |
|
- | 219 | and weak (surcharged) callbacks are used. |
|
- | 220 | ||
169 | *** DAC HAL driver macros list *** |
221 | *** DAC HAL driver macros list *** |
170 | ============================================= |
222 | ============================================= |
171 | [..] |
223 | [..] |
172 | Below the list of most used macros in DAC HAL driver. |
224 | Below the list of most used macros in DAC HAL driver. |
173 | |
225 | |
174 | (+) __HAL_DAC_ENABLE : Enable the DAC peripheral (For STM32F100x devices with specific feature: DMA underrun) |
226 | (+) __HAL_DAC_ENABLE : Enable the DAC peripheral (For STM32F100x devices with specific feature: DMA underrun) |
175 | (+) __HAL_DAC_DISABLE : Disable the DAC peripheral (For STM32F100x devices with specific feature: DMA underrun) |
227 | (+) __HAL_DAC_DISABLE : Disable the DAC peripheral (For STM32F100x devices with specific feature: DMA underrun) |
176 | (+) __HAL_DAC_CLEAR_FLAG: Clear the DAC's pending flags (For STM32F100x devices with specific feature: DMA underrun) |
228 | (+) __HAL_DAC_CLEAR_FLAG: Clear the DAC's pending flags (For STM32F100x devices with specific feature: DMA underrun) |
177 | (+) __HAL_DAC_GET_FLAG: Get the selected DAC's flag status (For STM32F100x devices with specific feature: DMA underrun) |
229 | (+) __HAL_DAC_GET_FLAG: Get the selected DAC's flag status (For STM32F100x devices with specific feature: DMA underrun) |
178 | |
230 | |
179 | [..] |
231 | [..] |
180 | (@) You can refer to the DAC HAL driver header file for more useful macros |
232 | (@) You can refer to the DAC HAL driver header file for more useful macros |
181 | |
233 | |
182 | @endverbatim |
234 | @endverbatim |
183 | ****************************************************************************** |
235 | ****************************************************************************** |
184 | * @attention |
236 | * @attention |
185 | * |
237 | * |
186 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
238 | * <h2><center>© Copyright (c) 2016 STMicroelectronics. |
- | 239 | * All rights reserved.</center></h2> |
|
187 | * |
240 | * |
188 | * Redistribution and use in source and binary forms, with or without modification, |
241 | * This software component is licensed by ST under BSD 3-Clause license, |
189 | * are permitted provided that the following conditions are met: |
242 | * the "License"; You may not use this file except in compliance with the |
190 | * 1. Redistributions of source code must retain the above copyright notice, |
- | |
191 | * this list of conditions and the following disclaimer. |
- | |
192 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
- | |
193 | * this list of conditions and the following disclaimer in the documentation |
- | |
194 | * and/or other materials provided with the distribution. |
243 | * License. You may obtain a copy of the License at: |
195 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
- | |
196 | * may be used to endorse or promote products derived from this software |
244 | * opensource.org/licenses/BSD-3-Clause |
197 | * without specific prior written permission. |
- | |
198 | * |
- | |
199 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
- | |
200 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
- | |
201 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
- | |
202 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
- | |
203 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
- | |
204 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
- | |
205 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
- | |
206 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
- | |
207 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
- | |
208 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
- | |
209 | * |
245 | * |
210 | ****************************************************************************** |
246 | ****************************************************************************** |
211 | */ |
247 | */ |
212 | - | ||
213 | 248 | ||
214 | /* Includes ------------------------------------------------------------------*/ |
249 | /* Includes ------------------------------------------------------------------*/ |
215 | #include "stm32f1xx_hal.h" |
250 | #include "stm32f1xx_hal.h" |
216 | 251 | ||
217 | /** @addtogroup STM32F1xx_HAL_Driver |
252 | /** @addtogroup STM32F1xx_HAL_Driver |
218 | * @{ |
253 | * @{ |
219 | */ |
254 | */ |
220 | 255 | ||
- | 256 | #ifdef HAL_DAC_MODULE_ENABLED |
|
- | 257 | #if defined(DAC) |
|
- | 258 | ||
221 | /** @defgroup DAC DAC |
259 | /** @defgroup DAC DAC |
222 | * @brief DAC driver modules |
260 | * @brief DAC driver modules |
223 | * @{ |
261 | * @{ |
224 | */ |
262 | */ |
225 | - | ||
226 | #ifdef HAL_DAC_MODULE_ENABLED |
- | |
227 | #if defined (STM32F100xB) || defined (STM32F100xE) || defined (STM32F101xE) || defined (STM32F101xG) || defined (STM32F103xE) || defined (STM32F103xG) || defined (STM32F105xC) || defined (STM32F107xC) |
- | |
228 | 263 | ||
229 | /* Private typedef -----------------------------------------------------------*/ |
264 | /* Private typedef -----------------------------------------------------------*/ |
230 | /* Private define ------------------------------------------------------------*/ |
265 | /* Private define ------------------------------------------------------------*/ |
- | 266 | /* Private constants ---------------------------------------------------------*/ |
|
231 | /* Private macro -------------------------------------------------------------*/ |
267 | /* Private macro -------------------------------------------------------------*/ |
232 | /* Private variables ---------------------------------------------------------*/ |
268 | /* Private variables ---------------------------------------------------------*/ |
233 | /* Private function prototypes -----------------------------------------------*/ |
269 | /* Private function prototypes -----------------------------------------------*/ |
234 | /* Exported functions -------------------------------------------------------*/ |
270 | /* Exported functions -------------------------------------------------------*/ |
235 | 271 | ||
236 | /** @defgroup DAC_Exported_Functions DAC Exported Functions |
272 | /** @defgroup DAC_Exported_Functions DAC Exported Functions |
237 | * @{ |
273 | * @{ |
238 | */ |
274 | */ |
239 | 275 | ||
240 | /** @defgroup DAC_Exported_Functions_Group1 Initialization and de-initialization functions |
276 | /** @defgroup DAC_Exported_Functions_Group1 Initialization and de-initialization functions |
241 | * @brief Initialization and Configuration functions |
277 | * @brief Initialization and Configuration functions |
242 | * |
278 | * |
243 | @verbatim |
279 | @verbatim |
244 | ============================================================================== |
280 | ============================================================================== |
245 | ##### Initialization and de-initialization functions ##### |
281 | ##### Initialization and de-initialization functions ##### |
246 | ============================================================================== |
282 | ============================================================================== |
247 | [..] This section provides functions allowing to: |
283 | [..] This section provides functions allowing to: |
248 | (+) Initialize and configure the DAC. |
284 | (+) Initialize and configure the DAC. |
249 | (+) De-initialize the DAC. |
285 | (+) De-initialize the DAC. |
250 | |
286 | |
251 | @endverbatim |
287 | @endverbatim |
252 | * @{ |
288 | * @{ |
253 | */ |
289 | */ |
254 | 290 | ||
255 | /** |
291 | /** |
256 | * @brief Initializes the DAC peripheral according to the specified parameters |
292 | * @brief Initialize the DAC peripheral according to the specified parameters |
257 | * in the DAC_InitStruct. |
293 | * in the DAC_InitStruct and initialize the associated handle. |
258 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
294 | * @param hdac pointer to a DAC_HandleTypeDef structure that contains |
259 | * the configuration information for the specified DAC. |
295 | * the configuration information for the specified DAC. |
260 | * @retval HAL status |
296 | * @retval HAL status |
261 | */ |
297 | */ |
262 | HAL_StatusTypeDef HAL_DAC_Init(DAC_HandleTypeDef* hdac) |
298 | HAL_StatusTypeDef HAL_DAC_Init(DAC_HandleTypeDef *hdac) |
263 | { |
299 | { |
264 | /* Check DAC handle */ |
300 | /* Check DAC handle */ |
265 | if(hdac == NULL) |
301 | if (hdac == NULL) |
266 | { |
302 | { |
267 | return HAL_ERROR; |
303 | return HAL_ERROR; |
268 | } |
304 | } |
269 | /* Check the parameters */ |
305 | /* Check the parameters */ |
270 | assert_param(IS_DAC_ALL_INSTANCE(hdac->Instance)); |
306 | assert_param(IS_DAC_ALL_INSTANCE(hdac->Instance)); |
271 | 307 | ||
272 | if(hdac->State == HAL_DAC_STATE_RESET) |
308 | if (hdac->State == HAL_DAC_STATE_RESET) |
- | 309 | { |
|
- | 310 | #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) |
|
- | 311 | /* Init the DAC Callback settings */ |
|
- | 312 | hdac->ConvCpltCallbackCh1 = HAL_DAC_ConvCpltCallbackCh1; |
|
- | 313 | hdac->ConvHalfCpltCallbackCh1 = HAL_DAC_ConvHalfCpltCallbackCh1; |
|
- | 314 | hdac->ErrorCallbackCh1 = HAL_DAC_ErrorCallbackCh1; |
|
- | 315 | hdac->DMAUnderrunCallbackCh1 = HAL_DAC_DMAUnderrunCallbackCh1; |
|
- | 316 | ||
- | 317 | hdac->ConvCpltCallbackCh2 = HAL_DACEx_ConvCpltCallbackCh2; |
|
- | 318 | hdac->ConvHalfCpltCallbackCh2 = HAL_DACEx_ConvHalfCpltCallbackCh2; |
|
- | 319 | hdac->ErrorCallbackCh2 = HAL_DACEx_ErrorCallbackCh2; |
|
- | 320 | hdac->DMAUnderrunCallbackCh2 = HAL_DACEx_DMAUnderrunCallbackCh2; |
|
- | 321 | ||
- | 322 | if (hdac->MspInitCallback == NULL) |
|
- | 323 | { |
|
- | 324 | hdac->MspInitCallback = HAL_DAC_MspInit; |
|
273 | { |
325 | } |
- | 326 | #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ |
|
- | 327 | ||
274 | /* Allocate lock resource and initialize it */ |
328 | /* Allocate lock resource and initialize it */ |
275 | hdac->Lock = HAL_UNLOCKED; |
329 | hdac->Lock = HAL_UNLOCKED; |
- | 330 | ||
- | 331 | #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) |
|
- | 332 | /* Init the low level hardware */ |
|
- | 333 | hdac->MspInitCallback(hdac); |
|
276 | 334 | #else |
|
277 | /* Init the low level hardware */ |
335 | /* Init the low level hardware */ |
278 | HAL_DAC_MspInit(hdac); |
336 | HAL_DAC_MspInit(hdac); |
- | 337 | #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ |
|
279 | } |
338 | } |
280 | 339 | ||
281 | /* Initialize the DAC state*/ |
340 | /* Initialize the DAC state*/ |
282 | hdac->State = HAL_DAC_STATE_BUSY; |
341 | hdac->State = HAL_DAC_STATE_BUSY; |
283 | 342 | ||
284 | /* Set DAC error code to none */ |
343 | /* Set DAC error code to none */ |
285 | hdac->ErrorCode = HAL_DAC_ERROR_NONE; |
344 | hdac->ErrorCode = HAL_DAC_ERROR_NONE; |
286 | 345 | ||
287 | /* Initialize the DAC state*/ |
346 | /* Initialize the DAC state*/ |
288 | hdac->State = HAL_DAC_STATE_READY; |
347 | hdac->State = HAL_DAC_STATE_READY; |
289 | 348 | ||
290 | /* Return function status */ |
349 | /* Return function status */ |
291 | return HAL_OK; |
350 | return HAL_OK; |
292 | } |
351 | } |
293 | 352 | ||
294 | /** |
353 | /** |
295 | * @brief Deinitializes the DAC peripheral registers to their default reset values. |
354 | * @brief Deinitialize the DAC peripheral registers to their default reset values. |
296 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
355 | * @param hdac pointer to a DAC_HandleTypeDef structure that contains |
297 | * the configuration information for the specified DAC. |
356 | * the configuration information for the specified DAC. |
298 | * @retval HAL status |
357 | * @retval HAL status |
299 | */ |
358 | */ |
300 | HAL_StatusTypeDef HAL_DAC_DeInit(DAC_HandleTypeDef* hdac) |
359 | HAL_StatusTypeDef HAL_DAC_DeInit(DAC_HandleTypeDef *hdac) |
301 | { |
360 | { |
302 | /* Check DAC handle */ |
361 | /* Check DAC handle */ |
303 | if(hdac == NULL) |
362 | if (hdac == NULL) |
304 | { |
363 | { |
305 | return HAL_ERROR; |
364 | return HAL_ERROR; |
306 | } |
365 | } |
307 | 366 | ||
308 | /* Check the parameters */ |
367 | /* Check the parameters */ |
309 | assert_param(IS_DAC_ALL_INSTANCE(hdac->Instance)); |
368 | assert_param(IS_DAC_ALL_INSTANCE(hdac->Instance)); |
310 | 369 | ||
311 | /* Change DAC state */ |
370 | /* Change DAC state */ |
312 | hdac->State = HAL_DAC_STATE_BUSY; |
371 | hdac->State = HAL_DAC_STATE_BUSY; |
313 | 372 | ||
- | 373 | #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) |
|
- | 374 | if (hdac->MspDeInitCallback == NULL) |
|
- | 375 | { |
|
- | 376 | hdac->MspDeInitCallback = HAL_DAC_MspDeInit; |
|
- | 377 | } |
|
- | 378 | /* DeInit the low level hardware */ |
|
- | 379 | hdac->MspDeInitCallback(hdac); |
|
- | 380 | #else |
|
314 | /* DeInit the low level hardware */ |
381 | /* DeInit the low level hardware */ |
315 | HAL_DAC_MspDeInit(hdac); |
382 | HAL_DAC_MspDeInit(hdac); |
- | 383 | #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ |
|
316 | 384 | ||
317 | /* Set DAC error code to none */ |
385 | /* Set DAC error code to none */ |
318 | hdac->ErrorCode = HAL_DAC_ERROR_NONE; |
386 | hdac->ErrorCode = HAL_DAC_ERROR_NONE; |
319 | 387 | ||
320 | /* Change DAC state */ |
388 | /* Change DAC state */ |
Line 326... | Line 394... | ||
326 | /* Return function status */ |
394 | /* Return function status */ |
327 | return HAL_OK; |
395 | return HAL_OK; |
328 | } |
396 | } |
329 | 397 | ||
330 | /** |
398 | /** |
331 | * @brief Initializes the DAC MSP. |
399 | * @brief Initialize the DAC MSP. |
332 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
400 | * @param hdac pointer to a DAC_HandleTypeDef structure that contains |
333 | * the configuration information for the specified DAC. |
401 | * the configuration information for the specified DAC. |
334 | * @retval None |
402 | * @retval None |
335 | */ |
403 | */ |
336 | __weak void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac) |
404 | __weak void HAL_DAC_MspInit(DAC_HandleTypeDef *hdac) |
337 | { |
405 | { |
338 | /* Prevent unused argument(s) compilation warning */ |
406 | /* Prevent unused argument(s) compilation warning */ |
339 | UNUSED(hdac); |
407 | UNUSED(hdac); |
- | 408 | ||
340 | /* NOTE : This function Should not be modified, when the callback is needed, |
409 | /* NOTE : This function should not be modified, when the callback is needed, |
341 | the HAL_DAC_MspInit could be implemented in the user file |
410 | the HAL_DAC_MspInit could be implemented in the user file |
342 | */ |
411 | */ |
343 | } |
412 | } |
344 | 413 | ||
345 | /** |
414 | /** |
346 | * @brief DeInitializes the DAC MSP. |
415 | * @brief DeInitialize the DAC MSP. |
347 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
416 | * @param hdac pointer to a DAC_HandleTypeDef structure that contains |
348 | * the configuration information for the specified DAC. |
417 | * the configuration information for the specified DAC. |
349 | * @retval None |
418 | * @retval None |
350 | */ |
419 | */ |
351 | __weak void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac) |
420 | __weak void HAL_DAC_MspDeInit(DAC_HandleTypeDef *hdac) |
352 | { |
421 | { |
353 | /* Prevent unused argument(s) compilation warning */ |
422 | /* Prevent unused argument(s) compilation warning */ |
354 | UNUSED(hdac); |
423 | UNUSED(hdac); |
- | 424 | ||
355 | /* NOTE : This function Should not be modified, when the callback is needed, |
425 | /* NOTE : This function should not be modified, when the callback is needed, |
356 | the HAL_DAC_MspDeInit could be implemented in the user file |
426 | the HAL_DAC_MspDeInit could be implemented in the user file |
357 | */ |
427 | */ |
358 | } |
428 | } |
359 | 429 | ||
360 | /** |
430 | /** |
361 | * @} |
431 | * @} |
362 | */ |
432 | */ |
363 | 433 | ||
364 | /** @defgroup DAC_Exported_Functions_Group2 IO operation functions |
434 | /** @defgroup DAC_Exported_Functions_Group2 IO operation functions |
365 | * @brief IO operation functions |
435 | * @brief IO operation functions |
366 | * |
436 | * |
367 | @verbatim |
437 | @verbatim |
368 | ============================================================================== |
438 | ============================================================================== |
369 | ##### IO operation functions ##### |
439 | ##### IO operation functions ##### |
370 | ============================================================================== |
440 | ============================================================================== |
371 | [..] This section provides functions allowing to: |
441 | [..] This section provides functions allowing to: |
372 | (+) Start conversion. |
442 | (+) Start conversion. |
373 | (+) Stop conversion. |
443 | (+) Stop conversion. |
374 | (+) Start conversion and enable DMA transfer. |
444 | (+) Start conversion and enable DMA transfer. |
375 | (+) Stop conversion and disable DMA transfer. |
445 | (+) Stop conversion and disable DMA transfer. |
376 | (+) Get result of conversion. |
446 | (+) Get result of conversion. |
377 | |
- | |
- | 447 | ||
378 | @endverbatim |
448 | @endverbatim |
379 | * @{ |
449 | * @{ |
380 | */ |
450 | */ |
381 | 451 | ||
382 | /** |
452 | /** |
383 | * @brief Enables DAC and starts conversion of channel. |
453 | * @brief Enables DAC and starts conversion of channel. |
384 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
454 | * @param hdac pointer to a DAC_HandleTypeDef structure that contains |
385 | * the configuration information for the specified DAC. |
455 | * the configuration information for the specified DAC. |
386 | * @param Channel: The selected DAC channel. |
456 | * @param Channel The selected DAC channel. |
387 | * This parameter can be one of the following values: |
457 | * This parameter can be one of the following values: |
388 | * @arg DAC_CHANNEL_1: DAC Channel1 selected |
458 | * @arg DAC_CHANNEL_1: DAC Channel1 selected |
389 | * @arg DAC_CHANNEL_2: DAC Channel2 selected |
459 | * @arg DAC_CHANNEL_2: DAC Channel2 selected |
390 | * @retval HAL status |
460 | * @retval HAL status |
391 | */ |
461 | */ |
392 | HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef* hdac, uint32_t Channel) |
462 | HAL_StatusTypeDef HAL_DAC_Start(DAC_HandleTypeDef *hdac, uint32_t Channel) |
393 | { |
463 | { |
394 | /* Check the parameters */ |
464 | /* Check the parameters */ |
395 | assert_param(IS_DAC_CHANNEL(Channel)); |
465 | assert_param(IS_DAC_CHANNEL(Channel)); |
396 | 466 | ||
397 | /* Process locked */ |
467 | /* Process locked */ |
398 | __HAL_LOCK(hdac); |
468 | __HAL_LOCK(hdac); |
399 | 469 | ||
400 | /* Change DAC state */ |
470 | /* Change DAC state */ |
401 | hdac->State = HAL_DAC_STATE_BUSY; |
471 | hdac->State = HAL_DAC_STATE_BUSY; |
402 | 472 | ||
403 | /* Enable the Peripharal */ |
473 | /* Enable the Peripheral */ |
404 | __HAL_DAC_ENABLE(hdac, Channel); |
474 | __HAL_DAC_ENABLE(hdac, Channel); |
405 | 475 | ||
406 | if(Channel == DAC_CHANNEL_1) |
476 | if (Channel == DAC_CHANNEL_1) |
407 | { |
477 | { |
408 | /* Check if software trigger enabled */ |
478 | /* Check if software trigger enabled */ |
409 | if((hdac->Instance->CR & (DAC_CR_TEN1 | DAC_CR_TSEL1)) == (DAC_CR_TEN1 | DAC_CR_TSEL1)) |
479 | if ((hdac->Instance->CR & (DAC_CR_TEN1 | DAC_CR_TSEL1)) == DAC_TRIGGER_SOFTWARE) |
410 | { |
480 | { |
411 | /* Enable the selected DAC software conversion */ |
481 | /* Enable the selected DAC software conversion */ |
412 | SET_BIT(hdac->Instance->SWTRIGR, DAC_SWTRIGR_SWTRIG1); |
482 | SET_BIT(hdac->Instance->SWTRIGR, DAC_SWTRIGR_SWTRIG1); |
413 | } |
483 | } |
414 | } |
484 | } |
415 | else |
485 | else |
416 | { |
486 | { |
417 | /* Check if software trigger enabled */ |
487 | /* Check if software trigger enabled */ |
418 | if((hdac->Instance->CR & (DAC_CR_TEN2 | DAC_CR_TSEL2)) == (DAC_CR_TEN2 | DAC_CR_TSEL2)) |
488 | if ((hdac->Instance->CR & (DAC_CR_TEN2 | DAC_CR_TSEL2)) == (DAC_TRIGGER_SOFTWARE << (Channel & 0x10UL))) |
419 | { |
489 | { |
420 | /* Enable the selected DAC software conversion*/ |
490 | /* Enable the selected DAC software conversion*/ |
421 | SET_BIT(hdac->Instance->SWTRIGR, DAC_SWTRIGR_SWTRIG2); |
491 | SET_BIT(hdac->Instance->SWTRIGR, DAC_SWTRIGR_SWTRIG2); |
422 | } |
492 | } |
423 | } |
493 | } |
424 | 494 | ||
425 | /* Change DAC state */ |
495 | /* Change DAC state */ |
426 | hdac->State = HAL_DAC_STATE_READY; |
496 | hdac->State = HAL_DAC_STATE_READY; |
427 | 497 | ||
428 | /* Process unlocked */ |
498 | /* Process unlocked */ |
429 | __HAL_UNLOCK(hdac); |
499 | __HAL_UNLOCK(hdac); |
430 | 500 | ||
431 | /* Return function status */ |
501 | /* Return function status */ |
432 | return HAL_OK; |
502 | return HAL_OK; |
433 | } |
503 | } |
434 | 504 | ||
435 | /** |
505 | /** |
436 | * @brief Disables DAC and stop conversion of channel. |
506 | * @brief Disables DAC and stop conversion of channel. |
437 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
507 | * @param hdac pointer to a DAC_HandleTypeDef structure that contains |
438 | * the configuration information for the specified DAC. |
508 | * the configuration information for the specified DAC. |
439 | * @param Channel: The selected DAC channel. |
509 | * @param Channel The selected DAC channel. |
440 | * This parameter can be one of the following values: |
510 | * This parameter can be one of the following values: |
441 | * @arg DAC_CHANNEL_1: DAC Channel1 selected |
511 | * @arg DAC_CHANNEL_1: DAC Channel1 selected |
442 | * @arg DAC_CHANNEL_2: DAC Channel2 selected |
512 | * @arg DAC_CHANNEL_2: DAC Channel2 selected |
443 | * @retval HAL status |
513 | * @retval HAL status |
444 | */ |
514 | */ |
445 | HAL_StatusTypeDef HAL_DAC_Stop(DAC_HandleTypeDef* hdac, uint32_t Channel) |
515 | HAL_StatusTypeDef HAL_DAC_Stop(DAC_HandleTypeDef *hdac, uint32_t Channel) |
446 | { |
516 | { |
447 | /* Check the parameters */ |
517 | /* Check the parameters */ |
448 | assert_param(IS_DAC_CHANNEL(Channel)); |
518 | assert_param(IS_DAC_CHANNEL(Channel)); |
449 | 519 | ||
450 | /* Disable the Peripheral */ |
520 | /* Disable the Peripheral */ |
451 | __HAL_DAC_DISABLE(hdac, Channel); |
521 | __HAL_DAC_DISABLE(hdac, Channel); |
452 | 522 | ||
453 | /* Change DAC state */ |
523 | /* Change DAC state */ |
454 | hdac->State = HAL_DAC_STATE_READY; |
524 | hdac->State = HAL_DAC_STATE_READY; |
455 | 525 | ||
456 | /* Return function status */ |
526 | /* Return function status */ |
457 | return HAL_OK; |
527 | return HAL_OK; |
458 | } |
528 | } |
459 | 529 | ||
460 | /** |
530 | /** |
461 | * @brief Enables DAC and starts conversion of channel. |
531 | * @brief Enables DAC and starts conversion of channel. |
462 | * Note: For STM32F100x devices with specific feature: DMA underrun. |
- | |
463 | * On these devices, this function enables the interruption of DMA |
- | |
464 | * underrun. |
- | |
465 | * (refer to redefinition of this function in DAC extended file) |
- | |
466 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
532 | * @param hdac pointer to a DAC_HandleTypeDef structure that contains |
467 | * the configuration information for the specified DAC. |
533 | * the configuration information for the specified DAC. |
468 | * @param Channel: The selected DAC channel. |
534 | * @param Channel The selected DAC channel. |
469 | * This parameter can be one of the following values: |
535 | * This parameter can be one of the following values: |
470 | * @arg DAC_CHANNEL_1: DAC Channel1 selected |
536 | * @arg DAC_CHANNEL_1: DAC Channel1 selected |
471 | * @arg DAC_CHANNEL_2: DAC Channel2 selected |
537 | * @arg DAC_CHANNEL_2: DAC Channel2 selected |
472 | * @param pData: The Source memory Buffer address. |
538 | * @param pData The destination peripheral Buffer address. |
473 | * @param Length: The length of data to be transferred from memory to DAC peripheral |
539 | * @param Length The length of data to be transferred from memory to DAC peripheral |
474 | * @param Alignment: Specifies the data alignment for DAC channel. |
540 | * @param Alignment Specifies the data alignment for DAC channel. |
475 | * This parameter can be one of the following values: |
541 | * This parameter can be one of the following values: |
476 | * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected |
542 | * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected |
477 | * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected |
543 | * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected |
478 | * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected |
544 | * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected |
479 | * @retval HAL status |
545 | * @retval HAL status |
480 | */ |
546 | */ |
481 | __weak HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t* pData, uint32_t Length, uint32_t Alignment) |
547 | HAL_StatusTypeDef HAL_DAC_Start_DMA(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t *pData, uint32_t Length, |
- | 548 | uint32_t Alignment) |
|
482 | { |
549 | { |
- | 550 | HAL_StatusTypeDef status; |
|
483 | uint32_t tmpreg = 0U; |
551 | uint32_t tmpreg = 0U; |
484 | 552 | ||
485 | /* Check the parameters */ |
553 | /* Check the parameters */ |
486 | assert_param(IS_DAC_CHANNEL(Channel)); |
554 | assert_param(IS_DAC_CHANNEL(Channel)); |
487 | assert_param(IS_DAC_ALIGN(Alignment)); |
555 | assert_param(IS_DAC_ALIGN(Alignment)); |
488 | 556 | ||
489 | /* Process locked */ |
557 | /* Process locked */ |
490 | __HAL_LOCK(hdac); |
558 | __HAL_LOCK(hdac); |
491 | 559 | ||
492 | /* Change DAC state */ |
560 | /* Change DAC state */ |
493 | hdac->State = HAL_DAC_STATE_BUSY; |
561 | hdac->State = HAL_DAC_STATE_BUSY; |
494 | 562 | ||
495 | if(Channel == DAC_CHANNEL_1) |
563 | if (Channel == DAC_CHANNEL_1) |
496 | { |
564 | { |
497 | /* Set the DMA transfer complete callback for channel1 */ |
565 | /* Set the DMA transfer complete callback for channel1 */ |
498 | hdac->DMA_Handle1->XferCpltCallback = DAC_DMAConvCpltCh1; |
566 | hdac->DMA_Handle1->XferCpltCallback = DAC_DMAConvCpltCh1; |
499 | 567 | ||
500 | /* Set the DMA half transfer complete callback for channel1 */ |
568 | /* Set the DMA half transfer complete callback for channel1 */ |
501 | hdac->DMA_Handle1->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh1; |
569 | hdac->DMA_Handle1->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh1; |
502 | 570 | ||
503 | /* Set the DMA error callback for channel1 */ |
571 | /* Set the DMA error callback for channel1 */ |
504 | hdac->DMA_Handle1->XferErrorCallback = DAC_DMAErrorCh1; |
572 | hdac->DMA_Handle1->XferErrorCallback = DAC_DMAErrorCh1; |
505 | 573 | ||
506 | /* Enable the selected DAC channel1 DMA request */ |
574 | /* Enable the selected DAC channel1 DMA request */ |
507 | SET_BIT(hdac->Instance->CR, DAC_CR_DMAEN1); |
575 | SET_BIT(hdac->Instance->CR, DAC_CR_DMAEN1); |
508 | 576 | ||
509 | /* Case of use of channel 1 */ |
577 | /* Case of use of channel 1 */ |
510 | switch(Alignment) |
578 | switch (Alignment) |
511 | { |
579 | { |
512 | case DAC_ALIGN_12B_R: |
580 | case DAC_ALIGN_12B_R: |
513 | /* Get DHR12R1 address */ |
581 | /* Get DHR12R1 address */ |
514 | tmpreg = (uint32_t)&hdac->Instance->DHR12R1; |
582 | tmpreg = (uint32_t)&hdac->Instance->DHR12R1; |
515 | break; |
583 | break; |
Line 527... | Line 595... | ||
527 | } |
595 | } |
528 | else |
596 | else |
529 | { |
597 | { |
530 | /* Set the DMA transfer complete callback for channel2 */ |
598 | /* Set the DMA transfer complete callback for channel2 */ |
531 | hdac->DMA_Handle2->XferCpltCallback = DAC_DMAConvCpltCh2; |
599 | hdac->DMA_Handle2->XferCpltCallback = DAC_DMAConvCpltCh2; |
532 | 600 | ||
533 | /* Set the DMA half transfer complete callback for channel2 */ |
601 | /* Set the DMA half transfer complete callback for channel2 */ |
534 | hdac->DMA_Handle2->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh2; |
602 | hdac->DMA_Handle2->XferHalfCpltCallback = DAC_DMAHalfConvCpltCh2; |
535 | 603 | ||
536 | /* Set the DMA error callback for channel2 */ |
604 | /* Set the DMA error callback for channel2 */ |
537 | hdac->DMA_Handle2->XferErrorCallback = DAC_DMAErrorCh2; |
605 | hdac->DMA_Handle2->XferErrorCallback = DAC_DMAErrorCh2; |
538 | 606 | ||
539 | /* Enable the selected DAC channel2 DMA request */ |
607 | /* Enable the selected DAC channel2 DMA request */ |
540 | SET_BIT(hdac->Instance->CR, DAC_CR_DMAEN2); |
608 | SET_BIT(hdac->Instance->CR, DAC_CR_DMAEN2); |
541 | 609 | ||
542 | /* Case of use of channel 2 */ |
610 | /* Case of use of channel 2 */ |
543 | switch(Alignment) |
611 | switch (Alignment) |
544 | { |
612 | { |
545 | case DAC_ALIGN_12B_R: |
613 | case DAC_ALIGN_12B_R: |
546 | /* Get DHR12R2 address */ |
614 | /* Get DHR12R2 address */ |
547 | tmpreg = (uint32_t)&hdac->Instance->DHR12R2; |
615 | tmpreg = (uint32_t)&hdac->Instance->DHR12R2; |
548 | break; |
616 | break; |
Line 556... | Line 624... | ||
556 | break; |
624 | break; |
557 | default: |
625 | default: |
558 | break; |
626 | break; |
559 | } |
627 | } |
560 | } |
628 | } |
561 | 629 | ||
562 | /* Enable the DMA channel */ |
630 | /* Enable the DMA Stream */ |
563 | if(Channel == DAC_CHANNEL_1) |
631 | if (Channel == DAC_CHANNEL_1) |
564 | { |
632 | { |
- | 633 | #if defined(DAC_CR_DMAUDRIE1) |
|
- | 634 | /* Enable the DAC DMA underrun interrupt */ |
|
- | 635 | __HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR1); |
|
- | 636 | #endif /* DAC_CR_DMAUDRIE1 */ |
|
565 | /* Enable the DMA channel */ |
637 | /* Enable the DMA Stream */ |
566 | HAL_DMA_Start_IT(hdac->DMA_Handle1, (uint32_t)pData, tmpreg, Length); |
638 | status = HAL_DMA_Start_IT(hdac->DMA_Handle1, (uint32_t)pData, tmpreg, Length); |
567 | } |
639 | } |
568 | else |
640 | else |
569 | { |
641 | { |
- | 642 | #if defined(DAC_CR_DMAUDRIE2) |
|
- | 643 | /* Enable the DAC DMA underrun interrupt */ |
|
- | 644 | __HAL_DAC_ENABLE_IT(hdac, DAC_IT_DMAUDR2); |
|
- | 645 | #endif /* DAC_CR_DMAUDRIE2 */ |
|
570 | /* Enable the DMA channel */ |
646 | /* Enable the DMA Stream */ |
571 | HAL_DMA_Start_IT(hdac->DMA_Handle2, (uint32_t)pData, tmpreg, Length); |
647 | status = HAL_DMA_Start_IT(hdac->DMA_Handle2, (uint32_t)pData, tmpreg, Length); |
572 | } |
648 | } |
573 | 649 | ||
574 | /* Process Unlocked */ |
650 | /* Process Unlocked */ |
575 | __HAL_UNLOCK(hdac); |
651 | __HAL_UNLOCK(hdac); |
- | 652 | ||
- | 653 | if (status == HAL_OK) |
|
576 | 654 | { |
|
577 | /* Enable the Peripharal */ |
655 | /* Enable the Peripheral */ |
578 | __HAL_DAC_ENABLE(hdac, Channel); |
656 | __HAL_DAC_ENABLE(hdac, Channel); |
- | 657 | } |
|
- | 658 | else |
|
- | 659 | { |
|
- | 660 | hdac->ErrorCode |= HAL_DAC_ERROR_DMA; |
|
579 | 661 | } |
|
- | 662 | ||
580 | /* Return function status */ |
663 | /* Return function status */ |
581 | return HAL_OK; |
664 | return status; |
582 | } |
665 | } |
583 | 666 | ||
584 | /** |
667 | /** |
585 | * @brief Disables DAC and stop conversion of channel. |
668 | * @brief Disables DAC and stop conversion of channel. |
586 | * Note: For STM32F100x devices with specific feature: DMA underrun. |
- | |
587 | * On these devices, this function disables the interruption of DMA |
- | |
588 | * underrun. |
- | |
589 | * (refer to redefinition of this function in DAC extended file) |
- | |
590 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
669 | * @param hdac pointer to a DAC_HandleTypeDef structure that contains |
591 | * the configuration information for the specified DAC. |
670 | * the configuration information for the specified DAC. |
592 | * @param Channel: The selected DAC channel. |
671 | * @param Channel The selected DAC channel. |
593 | * This parameter can be one of the following values: |
672 | * This parameter can be one of the following values: |
594 | * @arg DAC_CHANNEL_1: DAC Channel1 selected |
673 | * @arg DAC_CHANNEL_1: DAC Channel1 selected |
595 | * @arg DAC_CHANNEL_2: DAC Channel2 selected |
674 | * @arg DAC_CHANNEL_2: DAC Channel2 selected |
596 | * @retval HAL status |
675 | * @retval HAL status |
597 | */ |
676 | */ |
598 | __weak HAL_StatusTypeDef HAL_DAC_Stop_DMA(DAC_HandleTypeDef* hdac, uint32_t Channel) |
677 | HAL_StatusTypeDef HAL_DAC_Stop_DMA(DAC_HandleTypeDef *hdac, uint32_t Channel) |
599 | { |
678 | { |
600 | HAL_StatusTypeDef status = HAL_OK; |
679 | HAL_StatusTypeDef status; |
601 | 680 | ||
602 | /* Check the parameters */ |
681 | /* Check the parameters */ |
603 | assert_param(IS_DAC_CHANNEL(Channel)); |
682 | assert_param(IS_DAC_CHANNEL(Channel)); |
604 | 683 | ||
605 | /* Disable the selected DAC channel DMA request */ |
684 | /* Disable the selected DAC channel DMA request */ |
606 | CLEAR_BIT(hdac->Instance->CR, DAC_CR_DMAEN1 << Channel); |
685 | hdac->Instance->CR &= ~(DAC_CR_DMAEN1 << (Channel & 0x10UL)); |
607 | 686 | ||
608 | /* Disable the Peripharal */ |
687 | /* Disable the Peripheral */ |
609 | __HAL_DAC_DISABLE(hdac, Channel); |
688 | __HAL_DAC_DISABLE(hdac, Channel); |
610 | 689 | ||
611 | /* Disable the DMA Channel */ |
690 | /* Disable the DMA Stream */ |
- | 691 | ||
612 | /* Channel1 is used */ |
692 | /* Channel1 is used */ |
613 | if (Channel == DAC_CHANNEL_1) |
693 | if (Channel == DAC_CHANNEL_1) |
614 | { |
694 | { |
- | 695 | /* Disable the DMA Stream */ |
|
615 | status = HAL_DMA_Abort(hdac->DMA_Handle1); |
696 | status = HAL_DMA_Abort(hdac->DMA_Handle1); |
- | 697 | #if defined(DAC_CR_DMAUDRIE1) |
|
- | 698 | /* Disable the DAC DMA underrun interrupt */ |
|
- | 699 | __HAL_DAC_DISABLE_IT(hdac, DAC_IT_DMAUDR1); |
|
- | 700 | #endif /* DAC_CR_DMAUDRIE1 */ |
|
616 | } |
701 | } |
617 | else /* Channel2 is used for */ |
702 | else /* Channel2 is used for */ |
618 | { |
703 | { |
- | 704 | /* Disable the DMA Stream */ |
|
619 | status = HAL_DMA_Abort(hdac->DMA_Handle2); |
705 | status = HAL_DMA_Abort(hdac->DMA_Handle2); |
- | 706 | #if defined(DAC_CR_DMAUDRIE2) |
|
- | 707 | /* Disable the DAC DMA underrun interrupt */ |
|
- | 708 | __HAL_DAC_DISABLE_IT(hdac, DAC_IT_DMAUDR2); |
|
- | 709 | #endif /* DAC_CR_DMAUDRIE2 */ |
|
620 | } |
710 | } |
621 | 711 | ||
622 | /* Check if DMA Channel effectively disabled */ |
712 | /* Check if DMA Stream effectively disabled */ |
623 | if (status != HAL_OK) |
713 | if (status != HAL_OK) |
624 | { |
714 | { |
625 | /* Update ADC state machine to error */ |
715 | /* Update DAC state machine to error */ |
626 | hdac->State = HAL_DAC_STATE_ERROR; |
716 | hdac->State = HAL_DAC_STATE_ERROR; |
627 | } |
717 | } |
628 | else |
718 | else |
629 | { |
719 | { |
630 | /* Change DAC state */ |
720 | /* Change DAC state */ |
631 | hdac->State = HAL_DAC_STATE_READY; |
721 | hdac->State = HAL_DAC_STATE_READY; |
632 | } |
722 | } |
633 | 723 | ||
634 | /* Return function status */ |
724 | /* Return function status */ |
635 | return status; |
725 | return status; |
636 | } |
726 | } |
637 | 727 | ||
638 | /** |
728 | /** |
- | 729 | * @brief Handles DAC interrupt request |
|
- | 730 | * This function uses the interruption of DMA |
|
- | 731 | * underrun. |
|
- | 732 | * @param hdac pointer to a DAC_HandleTypeDef structure that contains |
|
- | 733 | * the configuration information for the specified DAC. |
|
- | 734 | * @retval None |
|
- | 735 | */ |
|
- | 736 | void HAL_DAC_IRQHandler(DAC_HandleTypeDef *hdac) |
|
- | 737 | { |
|
- | 738 | #if defined(DAC_SR_DMAUDR1) |
|
- | 739 | if (__HAL_DAC_GET_IT_SOURCE(hdac, DAC_IT_DMAUDR1)) |
|
- | 740 | { |
|
- | 741 | /* Check underrun flag of DAC channel 1 */ |
|
- | 742 | if (__HAL_DAC_GET_FLAG(hdac, DAC_FLAG_DMAUDR1)) |
|
- | 743 | { |
|
- | 744 | /* Change DAC state to error state */ |
|
- | 745 | hdac->State = HAL_DAC_STATE_ERROR; |
|
- | 746 | ||
- | 747 | /* Set DAC error code to chanel1 DMA underrun error */ |
|
- | 748 | SET_BIT(hdac->ErrorCode, HAL_DAC_ERROR_DMAUNDERRUNCH1); |
|
- | 749 | ||
- | 750 | /* Clear the underrun flag */ |
|
- | 751 | __HAL_DAC_CLEAR_FLAG(hdac, DAC_FLAG_DMAUDR1); |
|
- | 752 | ||
- | 753 | /* Disable the selected DAC channel1 DMA request */ |
|
- | 754 | CLEAR_BIT(hdac->Instance->CR, DAC_CR_DMAEN1); |
|
- | 755 | ||
- | 756 | /* Error callback */ |
|
- | 757 | #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) |
|
- | 758 | hdac->DMAUnderrunCallbackCh1(hdac); |
|
- | 759 | #else |
|
- | 760 | HAL_DAC_DMAUnderrunCallbackCh1(hdac); |
|
- | 761 | #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ |
|
- | 762 | } |
|
- | 763 | } |
|
- | 764 | #endif /* DAC_SR_DMAUDR1 */ |
|
- | 765 | ||
- | 766 | #if defined(DAC_SR_DMAUDR2) |
|
- | 767 | if (__HAL_DAC_GET_IT_SOURCE(hdac, DAC_IT_DMAUDR2)) |
|
- | 768 | { |
|
- | 769 | /* Check underrun flag of DAC channel 2 */ |
|
- | 770 | if (__HAL_DAC_GET_FLAG(hdac, DAC_FLAG_DMAUDR2)) |
|
- | 771 | { |
|
- | 772 | /* Change DAC state to error state */ |
|
- | 773 | hdac->State = HAL_DAC_STATE_ERROR; |
|
- | 774 | ||
- | 775 | /* Set DAC error code to channel2 DMA underrun error */ |
|
- | 776 | SET_BIT(hdac->ErrorCode, HAL_DAC_ERROR_DMAUNDERRUNCH2); |
|
- | 777 | ||
- | 778 | /* Clear the underrun flag */ |
|
- | 779 | __HAL_DAC_CLEAR_FLAG(hdac, DAC_FLAG_DMAUDR2); |
|
- | 780 | ||
- | 781 | /* Disable the selected DAC channel2 DMA request */ |
|
- | 782 | CLEAR_BIT(hdac->Instance->CR, DAC_CR_DMAEN2); |
|
- | 783 | ||
- | 784 | /* Error callback */ |
|
- | 785 | #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) |
|
- | 786 | hdac->DMAUnderrunCallbackCh2(hdac); |
|
- | 787 | #else |
|
- | 788 | HAL_DACEx_DMAUnderrunCallbackCh2(hdac); |
|
- | 789 | #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ |
|
- | 790 | } |
|
- | 791 | } |
|
- | 792 | #endif /* DAC_SR_DMAUDR2 */ |
|
- | 793 | } |
|
- | 794 | ||
- | 795 | /** |
|
639 | * @brief Returns the last data output value of the selected DAC channel. |
796 | * @brief Set the specified data holding register value for DAC channel. |
640 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
797 | * @param hdac pointer to a DAC_HandleTypeDef structure that contains |
641 | * the configuration information for the specified DAC. |
798 | * the configuration information for the specified DAC. |
642 | * @param Channel: The selected DAC channel. |
799 | * @param Channel The selected DAC channel. |
643 | * This parameter can be one of the following values: |
800 | * This parameter can be one of the following values: |
644 | * @arg DAC_CHANNEL_1: DAC Channel1 selected |
801 | * @arg DAC_CHANNEL_1: DAC Channel1 selected |
645 | * @arg DAC_CHANNEL_2: DAC Channel2 selected |
802 | * @arg DAC_CHANNEL_2: DAC Channel2 selected |
- | 803 | * @param Alignment Specifies the data alignment. |
|
646 | * @retval The selected DAC channel data output value. |
804 | * This parameter can be one of the following values: |
- | 805 | * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected |
|
- | 806 | * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected |
|
- | 807 | * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected |
|
- | 808 | * @param Data Data to be loaded in the selected data holding register. |
|
- | 809 | * @retval HAL status |
|
647 | */ |
810 | */ |
648 | uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef* hdac, uint32_t Channel) |
811 | HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data) |
649 | { |
812 | { |
- | 813 | __IO uint32_t tmp = 0; |
|
- | 814 | ||
650 | /* Check the parameters */ |
815 | /* Check the parameters */ |
651 | assert_param(IS_DAC_CHANNEL(Channel)); |
816 | assert_param(IS_DAC_CHANNEL(Channel)); |
- | 817 | assert_param(IS_DAC_ALIGN(Alignment)); |
|
- | 818 | assert_param(IS_DAC_DATA(Data)); |
|
652 | 819 | ||
653 | /* Returns the DAC channel data output register value */ |
820 | tmp = (uint32_t)hdac->Instance; |
654 | if(Channel == DAC_CHANNEL_1) |
821 | if (Channel == DAC_CHANNEL_1) |
655 | { |
822 | { |
656 | return hdac->Instance->DOR1; |
823 | tmp += DAC_DHR12R1_ALIGNMENT(Alignment); |
657 | } |
824 | } |
658 | else |
825 | else |
659 | { |
826 | { |
660 | return hdac->Instance->DOR2; |
827 | tmp += DAC_DHR12R2_ALIGNMENT(Alignment); |
661 | } |
828 | } |
- | 829 | ||
- | 830 | /* Set the DAC channel selected data holding register */ |
|
- | 831 | *(__IO uint32_t *) tmp = Data; |
|
- | 832 | ||
- | 833 | /* Return function status */ |
|
- | 834 | return HAL_OK; |
|
662 | } |
835 | } |
663 | 836 | ||
664 | /** |
837 | /** |
665 | * @brief Conversion complete callback in non blocking mode for Channel1 |
838 | * @brief Conversion complete callback in non-blocking mode for Channel1 |
666 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
839 | * @param hdac pointer to a DAC_HandleTypeDef structure that contains |
667 | * the configuration information for the specified DAC. |
840 | * the configuration information for the specified DAC. |
668 | * @retval None |
841 | * @retval None |
669 | */ |
842 | */ |
670 | __weak void HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef* hdac) |
843 | __weak void HAL_DAC_ConvCpltCallbackCh1(DAC_HandleTypeDef *hdac) |
671 | { |
844 | { |
672 | /* Prevent unused argument(s) compilation warning */ |
845 | /* Prevent unused argument(s) compilation warning */ |
673 | UNUSED(hdac); |
846 | UNUSED(hdac); |
- | 847 | ||
674 | /* NOTE : This function Should not be modified, when the callback is needed, |
848 | /* NOTE : This function should not be modified, when the callback is needed, |
675 | the HAL_DAC_ConvCpltCallbackCh1 could be implemented in the user file |
849 | the HAL_DAC_ConvCpltCallbackCh1 could be implemented in the user file |
676 | */ |
850 | */ |
677 | } |
851 | } |
678 | 852 | ||
679 | /** |
853 | /** |
680 | * @brief Conversion half DMA transfer callback in non blocking mode for Channel1 |
854 | * @brief Conversion half DMA transfer callback in non-blocking mode for Channel1 |
681 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
855 | * @param hdac pointer to a DAC_HandleTypeDef structure that contains |
682 | * the configuration information for the specified DAC. |
856 | * the configuration information for the specified DAC. |
683 | * @retval None |
857 | * @retval None |
684 | */ |
858 | */ |
685 | __weak void HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef* hdac) |
859 | __weak void HAL_DAC_ConvHalfCpltCallbackCh1(DAC_HandleTypeDef *hdac) |
686 | { |
860 | { |
687 | /* Prevent unused argument(s) compilation warning */ |
861 | /* Prevent unused argument(s) compilation warning */ |
688 | UNUSED(hdac); |
862 | UNUSED(hdac); |
- | 863 | ||
689 | /* NOTE : This function Should not be modified, when the callback is needed, |
864 | /* NOTE : This function should not be modified, when the callback is needed, |
690 | the HAL_DAC_ConvHalfCpltCallbackCh1 could be implemented in the user file |
865 | the HAL_DAC_ConvHalfCpltCallbackCh1 could be implemented in the user file |
691 | */ |
866 | */ |
692 | } |
867 | } |
693 | 868 | ||
694 | /** |
869 | /** |
695 | * @brief Error DAC callback for Channel1. |
870 | * @brief Error DAC callback for Channel1. |
696 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
871 | * @param hdac pointer to a DAC_HandleTypeDef structure that contains |
697 | * the configuration information for the specified DAC. |
872 | * the configuration information for the specified DAC. |
698 | * @retval None |
873 | * @retval None |
699 | */ |
874 | */ |
700 | __weak void HAL_DAC_ErrorCallbackCh1(DAC_HandleTypeDef *hdac) |
875 | __weak void HAL_DAC_ErrorCallbackCh1(DAC_HandleTypeDef *hdac) |
701 | { |
876 | { |
702 | /* Prevent unused argument(s) compilation warning */ |
877 | /* Prevent unused argument(s) compilation warning */ |
703 | UNUSED(hdac); |
878 | UNUSED(hdac); |
- | 879 | ||
704 | /* NOTE : This function Should not be modified, when the callback is needed, |
880 | /* NOTE : This function should not be modified, when the callback is needed, |
705 | the HAL_DAC_ErrorCallbackCh1 could be implemented in the user file |
881 | the HAL_DAC_ErrorCallbackCh1 could be implemented in the user file |
706 | */ |
882 | */ |
707 | } |
883 | } |
708 | 884 | ||
709 | /** |
885 | /** |
- | 886 | * @brief DMA underrun DAC callback for channel1. |
|
- | 887 | * @param hdac pointer to a DAC_HandleTypeDef structure that contains |
|
- | 888 | * the configuration information for the specified DAC. |
|
- | 889 | * @retval None |
|
- | 890 | */ |
|
- | 891 | __weak void HAL_DAC_DMAUnderrunCallbackCh1(DAC_HandleTypeDef *hdac) |
|
- | 892 | { |
|
- | 893 | /* Prevent unused argument(s) compilation warning */ |
|
- | 894 | UNUSED(hdac); |
|
- | 895 | ||
- | 896 | /* NOTE : This function should not be modified, when the callback is needed, |
|
- | 897 | the HAL_DAC_DMAUnderrunCallbackCh1 could be implemented in the user file |
|
- | 898 | */ |
|
- | 899 | } |
|
- | 900 | ||
- | 901 | /** |
|
710 | * @} |
902 | * @} |
711 | */ |
903 | */ |
712 | 904 | ||
713 | /** @defgroup DAC_Exported_Functions_Group3 Peripheral Control functions |
905 | /** @defgroup DAC_Exported_Functions_Group3 Peripheral Control functions |
714 | * @brief Peripheral Control functions |
906 | * @brief Peripheral Control functions |
715 | * |
907 | * |
716 | @verbatim |
908 | @verbatim |
717 | ============================================================================== |
909 | ============================================================================== |
718 | ##### Peripheral Control functions ##### |
910 | ##### Peripheral Control functions ##### |
719 | ============================================================================== |
911 | ============================================================================== |
720 | [..] This section provides functions allowing to: |
912 | [..] This section provides functions allowing to: |
721 | (+) Configure channels. |
913 | (+) Configure channels. |
722 | (+) Set the specified data holding register value for DAC channel. |
914 | (+) Set the specified data holding register value for DAC channel. |
723 | |
915 | |
724 | @endverbatim |
916 | @endverbatim |
725 | * @{ |
917 | * @{ |
726 | */ |
918 | */ |
727 | 919 | ||
728 | /** |
920 | /** |
- | 921 | * @brief Returns the last data output value of the selected DAC channel. |
|
- | 922 | * @param hdac pointer to a DAC_HandleTypeDef structure that contains |
|
- | 923 | * the configuration information for the specified DAC. |
|
- | 924 | * @param Channel The selected DAC channel. |
|
- | 925 | * This parameter can be one of the following values: |
|
- | 926 | * @arg DAC_CHANNEL_1: DAC Channel1 selected |
|
- | 927 | * @arg DAC_CHANNEL_2: DAC Channel2 selected |
|
- | 928 | * @retval The selected DAC channel data output value. |
|
- | 929 | */ |
|
- | 930 | uint32_t HAL_DAC_GetValue(DAC_HandleTypeDef *hdac, uint32_t Channel) |
|
- | 931 | { |
|
- | 932 | /* Check the parameters */ |
|
- | 933 | assert_param(IS_DAC_CHANNEL(Channel)); |
|
- | 934 | ||
- | 935 | /* Returns the DAC channel data output register value */ |
|
- | 936 | if (Channel == DAC_CHANNEL_1) |
|
- | 937 | { |
|
- | 938 | return hdac->Instance->DOR1; |
|
- | 939 | } |
|
- | 940 | else |
|
- | 941 | { |
|
- | 942 | return hdac->Instance->DOR2; |
|
- | 943 | } |
|
- | 944 | } |
|
- | 945 | ||
- | 946 | /** |
|
729 | * @brief Configures the selected DAC channel. |
947 | * @brief Configures the selected DAC channel. |
730 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
948 | * @param hdac pointer to a DAC_HandleTypeDef structure that contains |
731 | * the configuration information for the specified DAC. |
949 | * the configuration information for the specified DAC. |
732 | * @param sConfig: DAC configuration structure. |
950 | * @param sConfig DAC configuration structure. |
733 | * @param Channel: The selected DAC channel. |
951 | * @param Channel The selected DAC channel. |
734 | * This parameter can be one of the following values: |
952 | * This parameter can be one of the following values: |
735 | * @arg DAC_CHANNEL_1: DAC Channel1 selected |
953 | * @arg DAC_CHANNEL_1: DAC Channel1 selected |
736 | * @arg DAC_CHANNEL_2: DAC Channel2 selected |
954 | * @arg DAC_CHANNEL_2: DAC Channel2 selected |
737 | * @retval HAL status |
955 | * @retval HAL status |
738 | */ |
956 | */ |
739 | HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef* hdac, DAC_ChannelConfTypeDef* sConfig, uint32_t Channel) |
957 | HAL_StatusTypeDef HAL_DAC_ConfigChannel(DAC_HandleTypeDef *hdac, DAC_ChannelConfTypeDef *sConfig, uint32_t Channel) |
740 | { |
958 | { |
741 | uint32_t tmpreg1 = 0U; |
959 | uint32_t tmpreg1; |
- | 960 | uint32_t tmpreg2; |
|
742 | 961 | ||
743 | /* Check the DAC parameters */ |
962 | /* Check the DAC parameters */ |
744 | assert_param(IS_DAC_TRIGGER(sConfig->DAC_Trigger)); |
963 | assert_param(IS_DAC_TRIGGER(sConfig->DAC_Trigger)); |
745 | assert_param(IS_DAC_OUTPUT_BUFFER_STATE(sConfig->DAC_OutputBuffer)); |
964 | assert_param(IS_DAC_OUTPUT_BUFFER_STATE(sConfig->DAC_OutputBuffer)); |
746 | assert_param(IS_DAC_CHANNEL(Channel)); |
965 | assert_param(IS_DAC_CHANNEL(Channel)); |
747 | 966 | ||
748 | /* Process locked */ |
967 | /* Process locked */ |
749 | __HAL_LOCK(hdac); |
968 | __HAL_LOCK(hdac); |
750 | 969 | ||
751 | /* Change DAC state */ |
970 | /* Change DAC state */ |
752 | hdac->State = HAL_DAC_STATE_BUSY; |
971 | hdac->State = HAL_DAC_STATE_BUSY; |
753 | 972 | ||
- | 973 | /* Get the DAC CR value */ |
|
- | 974 | tmpreg1 = hdac->Instance->CR; |
|
- | 975 | /* Clear BOFFx, TENx, TSELx, WAVEx and MAMPx bits */ |
|
- | 976 | tmpreg1 &= ~(((uint32_t)(DAC_CR_MAMP1 | DAC_CR_WAVE1 | DAC_CR_TSEL1 | DAC_CR_TEN1 | DAC_CR_BOFF1)) << (Channel & 0x10UL)); |
|
754 | /* Configure for the selected DAC channel: buffer output, trigger */ |
977 | /* Configure for the selected DAC channel: buffer output, trigger */ |
755 | /* Set TSELx and TENx bits according to DAC_Trigger value */ |
978 | /* Set TSELx and TENx bits according to DAC_Trigger value */ |
756 | /* Set BOFFx bit according to DAC_OutputBuffer value */ |
979 | /* Set BOFFx bit according to DAC_OutputBuffer value */ |
757 | SET_BIT(tmpreg1, (sConfig->DAC_Trigger | sConfig->DAC_OutputBuffer)); |
980 | tmpreg2 = (sConfig->DAC_Trigger | sConfig->DAC_OutputBuffer); |
758 | - | ||
759 | /* Clear BOFFx, TENx, TSELx, WAVEx and MAMPx bits */ |
- | |
760 | /* Calculate CR register value depending on DAC_Channel */ |
981 | /* Calculate CR register value depending on DAC_Channel */ |
761 | MODIFY_REG(hdac->Instance->CR, |
982 | tmpreg1 |= tmpreg2 << (Channel & 0x10UL); |
762 | ((uint32_t)(DAC_CR_MAMP1 | DAC_CR_WAVE1 | DAC_CR_TSEL1 | DAC_CR_TEN1 | DAC_CR_BOFF1)) << Channel, |
983 | /* Write to DAC CR */ |
763 | tmpreg1 << Channel); |
984 | hdac->Instance->CR = tmpreg1; |
764 | - | ||
765 | /* Disable wave generation */ |
985 | /* Disable wave generation */ |
- | 986 | CLEAR_BIT(hdac->Instance->CR, (DAC_CR_WAVE1 << (Channel & 0x10UL))); |
|
- | 987 | /* Disable wave generation */ |
|
766 | hdac->Instance->CR &= ~(DAC_CR_WAVE1 << Channel); |
988 | hdac->Instance->CR &= ~(DAC_CR_WAVE1 << (Channel & 0x10UL)); |
767 | 989 | ||
768 | /* Change DAC state */ |
990 | /* Change DAC state */ |
769 | hdac->State = HAL_DAC_STATE_READY; |
991 | hdac->State = HAL_DAC_STATE_READY; |
770 | 992 | ||
771 | /* Process unlocked */ |
993 | /* Process unlocked */ |
772 | __HAL_UNLOCK(hdac); |
994 | __HAL_UNLOCK(hdac); |
773 | - | ||
774 | /* Return function status */ |
- | |
775 | return HAL_OK; |
- | |
776 | } |
- | |
777 | 995 | ||
778 | /** |
- | |
779 | * @brief Set the specified data holding register value for DAC channel. |
- | |
780 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
- | |
781 | * the configuration information for the specified DAC. |
- | |
782 | * @param Channel: The selected DAC channel. |
- | |
783 | * This parameter can be one of the following values: |
- | |
784 | * @arg DAC_CHANNEL_1: DAC Channel1 selected |
- | |
785 | * @arg DAC_CHANNEL_2: DAC Channel2 selected |
- | |
786 | * @param Alignment: Specifies the data alignment. |
- | |
787 | * This parameter can be one of the following values: |
- | |
788 | * @arg DAC_ALIGN_8B_R: 8bit right data alignment selected |
- | |
789 | * @arg DAC_ALIGN_12B_L: 12bit left data alignment selected |
- | |
790 | * @arg DAC_ALIGN_12B_R: 12bit right data alignment selected |
- | |
791 | * @param Data: Data to be loaded in the selected data holding register. |
- | |
792 | * @retval HAL status |
- | |
793 | */ |
- | |
794 | HAL_StatusTypeDef HAL_DAC_SetValue(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data) |
- | |
795 | { |
- | |
796 | __IO uint32_t tmp = 0U; |
- | |
797 | - | ||
798 | /* Check the parameters */ |
- | |
799 | assert_param(IS_DAC_CHANNEL(Channel)); |
- | |
800 | assert_param(IS_DAC_ALIGN(Alignment)); |
- | |
801 | assert_param(IS_DAC_DATA(Data)); |
- | |
802 | - | ||
803 | tmp = (uint32_t)hdac->Instance; |
- | |
804 | if(Channel == DAC_CHANNEL_1) |
- | |
805 | { |
- | |
806 | tmp += DAC_DHR12R1_ALIGNMENT(Alignment); |
- | |
807 | } |
- | |
808 | else |
- | |
809 | { |
- | |
810 | tmp += DAC_DHR12R2_ALIGNMENT(Alignment); |
- | |
811 | } |
- | |
812 | - | ||
813 | /* Set the DAC channel selected data holding register */ |
- | |
814 | *(__IO uint32_t *) tmp = Data; |
- | |
815 | - | ||
816 | /* Return function status */ |
996 | /* Return function status */ |
817 | return HAL_OK; |
997 | return HAL_OK; |
818 | } |
998 | } |
819 | 999 | ||
820 | /** |
1000 | /** |
821 | * @} |
1001 | * @} |
822 | */ |
1002 | */ |
823 | 1003 | ||
824 | /** @defgroup DAC_Exported_Functions_Group4 Peripheral State and Errors functions |
1004 | /** @defgroup DAC_Exported_Functions_Group4 Peripheral State and Errors functions |
825 | * @brief Peripheral State and Errors functions |
1005 | * @brief Peripheral State and Errors functions |
826 | * |
1006 | * |
827 | @verbatim |
1007 | @verbatim |
828 | ============================================================================== |
1008 | ============================================================================== |
829 | ##### Peripheral State and Errors functions ##### |
1009 | ##### Peripheral State and Errors functions ##### |
830 | ============================================================================== |
1010 | ============================================================================== |
831 | [..] |
1011 | [..] |
832 | This subsection provides functions allowing to |
1012 | This subsection provides functions allowing to |
833 | (+) Check the DAC state. |
1013 | (+) Check the DAC state. |
834 | (+) Check the DAC Errors. |
1014 | (+) Check the DAC Errors. |
835 | |
1015 | |
836 | @endverbatim |
1016 | @endverbatim |
837 | * @{ |
1017 | * @{ |
838 | */ |
1018 | */ |
839 | 1019 | ||
840 | /** |
1020 | /** |
841 | * @brief return the DAC state |
1021 | * @brief return the DAC handle state |
842 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
1022 | * @param hdac pointer to a DAC_HandleTypeDef structure that contains |
843 | * the configuration information for the specified DAC. |
1023 | * the configuration information for the specified DAC. |
844 | * @retval HAL state |
1024 | * @retval HAL state |
845 | */ |
1025 | */ |
846 | HAL_DAC_StateTypeDef HAL_DAC_GetState(DAC_HandleTypeDef* hdac) |
1026 | HAL_DAC_StateTypeDef HAL_DAC_GetState(DAC_HandleTypeDef *hdac) |
847 | { |
1027 | { |
848 | /* Return DAC state */ |
1028 | /* Return DAC handle state */ |
849 | return hdac->State; |
1029 | return hdac->State; |
850 | } |
1030 | } |
851 | 1031 | ||
852 | 1032 | ||
853 | /** |
1033 | /** |
854 | * @brief Return the DAC error code |
1034 | * @brief Return the DAC error code |
855 | * @param hdac: pointer to a DAC_HandleTypeDef structure that contains |
1035 | * @param hdac pointer to a DAC_HandleTypeDef structure that contains |
856 | * the configuration information for the specified DAC. |
1036 | * the configuration information for the specified DAC. |
857 | * @retval DAC Error Code |
1037 | * @retval DAC Error Code |
858 | */ |
1038 | */ |
859 | uint32_t HAL_DAC_GetError(DAC_HandleTypeDef *hdac) |
1039 | uint32_t HAL_DAC_GetError(DAC_HandleTypeDef *hdac) |
860 | { |
1040 | { |
Line 862... | Line 1042... | ||
862 | } |
1042 | } |
863 | 1043 | ||
864 | /** |
1044 | /** |
865 | * @} |
1045 | * @} |
866 | */ |
1046 | */ |
- | 1047 | ||
- | 1048 | /** |
|
- | 1049 | * @} |
|
- | 1050 | */ |
|
- | 1051 | ||
- | 1052 | /** @addtogroup DAC_Exported_Functions |
|
- | 1053 | * @{ |
|
- | 1054 | */ |
|
- | 1055 | ||
- | 1056 | /** @addtogroup DAC_Exported_Functions_Group1 |
|
- | 1057 | * @{ |
|
- | 1058 | */ |
|
- | 1059 | #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) |
|
- | 1060 | /** |
|
- | 1061 | * @brief Register a User DAC Callback |
|
- | 1062 | * To be used instead of the weak (surcharged) predefined callback |
|
- | 1063 | * @param hdac DAC handle |
|
- | 1064 | * @param CallbackID ID of the callback to be registered |
|
- | 1065 | * This parameter can be one of the following values: |
|
- | 1066 | * @arg @ref HAL_DAC_ERROR_INVALID_CALLBACK DAC Error Callback ID |
|
- | 1067 | * @arg @ref HAL_DAC_CH1_COMPLETE_CB_ID DAC CH1 Complete Callback ID |
|
- | 1068 | * @arg @ref HAL_DAC_CH1_HALF_COMPLETE_CB_ID DAC CH1 Half Complete Callback ID |
|
- | 1069 | * @arg @ref HAL_DAC_CH1_ERROR_ID DAC CH1 Error Callback ID |
|
- | 1070 | * @arg @ref HAL_DAC_CH1_UNDERRUN_CB_ID DAC CH1 UnderRun Callback ID |
|
- | 1071 | * @arg @ref HAL_DAC_CH2_COMPLETE_CB_ID DAC CH2 Complete Callback ID |
|
- | 1072 | * @arg @ref HAL_DAC_CH2_HALF_COMPLETE_CB_ID DAC CH2 Half Complete Callback ID |
|
- | 1073 | * @arg @ref HAL_DAC_CH2_ERROR_ID DAC CH2 Error Callback ID |
|
- | 1074 | * @arg @ref HAL_DAC_CH2_UNDERRUN_CB_ID DAC CH2 UnderRun Callback ID |
|
- | 1075 | * @arg @ref HAL_DAC_MSPINIT_CB_ID DAC MSP Init Callback ID |
|
- | 1076 | * @arg @ref HAL_DAC_MSPDEINIT_CB_ID DAC MSP DeInit Callback ID |
|
- | 1077 | * |
|
- | 1078 | * @param pCallback pointer to the Callback function |
|
- | 1079 | * @retval status |
|
- | 1080 | */ |
|
- | 1081 | HAL_StatusTypeDef HAL_DAC_RegisterCallback(DAC_HandleTypeDef *hdac, HAL_DAC_CallbackIDTypeDef CallbackID, |
|
- | 1082 | pDAC_CallbackTypeDef pCallback) |
|
- | 1083 | { |
|
- | 1084 | HAL_StatusTypeDef status = HAL_OK; |
|
- | 1085 | ||
- | 1086 | if (pCallback == NULL) |
|
- | 1087 | { |
|
- | 1088 | /* Update the error code */ |
|
- | 1089 | hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK; |
|
- | 1090 | return HAL_ERROR; |
|
- | 1091 | } |
|
- | 1092 | ||
- | 1093 | /* Process locked */ |
|
- | 1094 | __HAL_LOCK(hdac); |
|
- | 1095 | ||
- | 1096 | if (hdac->State == HAL_DAC_STATE_READY) |
|
- | 1097 | { |
|
- | 1098 | switch (CallbackID) |
|
- | 1099 | { |
|
- | 1100 | case HAL_DAC_CH1_COMPLETE_CB_ID : |
|
- | 1101 | hdac->ConvCpltCallbackCh1 = pCallback; |
|
- | 1102 | break; |
|
- | 1103 | case HAL_DAC_CH1_HALF_COMPLETE_CB_ID : |
|
- | 1104 | hdac->ConvHalfCpltCallbackCh1 = pCallback; |
|
- | 1105 | break; |
|
- | 1106 | case HAL_DAC_CH1_ERROR_ID : |
|
- | 1107 | hdac->ErrorCallbackCh1 = pCallback; |
|
- | 1108 | break; |
|
- | 1109 | case HAL_DAC_CH1_UNDERRUN_CB_ID : |
|
- | 1110 | hdac->DMAUnderrunCallbackCh1 = pCallback; |
|
- | 1111 | break; |
|
- | 1112 | case HAL_DAC_CH2_COMPLETE_CB_ID : |
|
- | 1113 | hdac->ConvCpltCallbackCh2 = pCallback; |
|
- | 1114 | break; |
|
- | 1115 | case HAL_DAC_CH2_HALF_COMPLETE_CB_ID : |
|
- | 1116 | hdac->ConvHalfCpltCallbackCh2 = pCallback; |
|
- | 1117 | break; |
|
- | 1118 | case HAL_DAC_CH2_ERROR_ID : |
|
- | 1119 | hdac->ErrorCallbackCh2 = pCallback; |
|
- | 1120 | break; |
|
- | 1121 | case HAL_DAC_CH2_UNDERRUN_CB_ID : |
|
- | 1122 | hdac->DMAUnderrunCallbackCh2 = pCallback; |
|
- | 1123 | break; |
|
- | 1124 | case HAL_DAC_MSPINIT_CB_ID : |
|
- | 1125 | hdac->MspInitCallback = pCallback; |
|
- | 1126 | break; |
|
- | 1127 | case HAL_DAC_MSPDEINIT_CB_ID : |
|
- | 1128 | hdac->MspDeInitCallback = pCallback; |
|
- | 1129 | break; |
|
- | 1130 | default : |
|
- | 1131 | /* Update the error code */ |
|
- | 1132 | hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK; |
|
- | 1133 | /* update return status */ |
|
- | 1134 | status = HAL_ERROR; |
|
- | 1135 | break; |
|
- | 1136 | } |
|
- | 1137 | } |
|
- | 1138 | else if (hdac->State == HAL_DAC_STATE_RESET) |
|
- | 1139 | { |
|
- | 1140 | switch (CallbackID) |
|
- | 1141 | { |
|
- | 1142 | case HAL_DAC_MSPINIT_CB_ID : |
|
- | 1143 | hdac->MspInitCallback = pCallback; |
|
- | 1144 | break; |
|
- | 1145 | case HAL_DAC_MSPDEINIT_CB_ID : |
|
- | 1146 | hdac->MspDeInitCallback = pCallback; |
|
- | 1147 | break; |
|
- | 1148 | default : |
|
- | 1149 | /* Update the error code */ |
|
- | 1150 | hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK; |
|
- | 1151 | /* update return status */ |
|
- | 1152 | status = HAL_ERROR; |
|
- | 1153 | break; |
|
- | 1154 | } |
|
- | 1155 | } |
|
- | 1156 | else |
|
- | 1157 | { |
|
- | 1158 | /* Update the error code */ |
|
- | 1159 | hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK; |
|
- | 1160 | /* update return status */ |
|
- | 1161 | status = HAL_ERROR; |
|
- | 1162 | } |
|
- | 1163 | ||
- | 1164 | /* Release Lock */ |
|
- | 1165 | __HAL_UNLOCK(hdac); |
|
- | 1166 | return status; |
|
- | 1167 | } |
|
- | 1168 | ||
- | 1169 | /** |
|
- | 1170 | * @brief Unregister a User DAC Callback |
|
- | 1171 | * DAC Callback is redirected to the weak (surcharged) predefined callback |
|
- | 1172 | * @param hdac DAC handle |
|
- | 1173 | * @param CallbackID ID of the callback to be unregistered |
|
- | 1174 | * This parameter can be one of the following values: |
|
- | 1175 | * @arg @ref HAL_DAC_CH1_COMPLETE_CB_ID DAC CH1 tranfer Complete Callback ID |
|
- | 1176 | * @arg @ref HAL_DAC_CH1_HALF_COMPLETE_CB_ID DAC CH1 Half Complete Callback ID |
|
- | 1177 | * @arg @ref HAL_DAC_CH1_ERROR_ID DAC CH1 Error Callback ID |
|
- | 1178 | * @arg @ref HAL_DAC_CH1_UNDERRUN_CB_ID DAC CH1 UnderRun Callback ID |
|
- | 1179 | * @arg @ref HAL_DAC_CH2_COMPLETE_CB_ID DAC CH2 Complete Callback ID |
|
- | 1180 | * @arg @ref HAL_DAC_CH2_HALF_COMPLETE_CB_ID DAC CH2 Half Complete Callback ID |
|
- | 1181 | * @arg @ref HAL_DAC_CH2_ERROR_ID DAC CH2 Error Callback ID |
|
- | 1182 | * @arg @ref HAL_DAC_CH2_UNDERRUN_CB_ID DAC CH2 UnderRun Callback ID |
|
- | 1183 | * @arg @ref HAL_DAC_MSPINIT_CB_ID DAC MSP Init Callback ID |
|
- | 1184 | * @arg @ref HAL_DAC_MSPDEINIT_CB_ID DAC MSP DeInit Callback ID |
|
- | 1185 | * @arg @ref HAL_DAC_ALL_CB_ID DAC All callbacks |
|
- | 1186 | * @retval status |
|
- | 1187 | */ |
|
- | 1188 | HAL_StatusTypeDef HAL_DAC_UnRegisterCallback(DAC_HandleTypeDef *hdac, HAL_DAC_CallbackIDTypeDef CallbackID) |
|
- | 1189 | { |
|
- | 1190 | HAL_StatusTypeDef status = HAL_OK; |
|
- | 1191 | ||
- | 1192 | /* Process locked */ |
|
- | 1193 | __HAL_LOCK(hdac); |
|
- | 1194 | ||
- | 1195 | if (hdac->State == HAL_DAC_STATE_READY) |
|
867 | 1196 | { |
|
- | 1197 | switch (CallbackID) |
|
- | 1198 | { |
|
- | 1199 | case HAL_DAC_CH1_COMPLETE_CB_ID : |
|
- | 1200 | hdac->ConvCpltCallbackCh1 = HAL_DAC_ConvCpltCallbackCh1; |
|
- | 1201 | break; |
|
- | 1202 | case HAL_DAC_CH1_HALF_COMPLETE_CB_ID : |
|
- | 1203 | hdac->ConvHalfCpltCallbackCh1 = HAL_DAC_ConvHalfCpltCallbackCh1; |
|
- | 1204 | break; |
|
- | 1205 | case HAL_DAC_CH1_ERROR_ID : |
|
- | 1206 | hdac->ErrorCallbackCh1 = HAL_DAC_ErrorCallbackCh1; |
|
- | 1207 | break; |
|
- | 1208 | case HAL_DAC_CH1_UNDERRUN_CB_ID : |
|
- | 1209 | hdac->DMAUnderrunCallbackCh1 = HAL_DAC_DMAUnderrunCallbackCh1; |
|
- | 1210 | break; |
|
- | 1211 | case HAL_DAC_CH2_COMPLETE_CB_ID : |
|
- | 1212 | hdac->ConvCpltCallbackCh2 = HAL_DACEx_ConvCpltCallbackCh2; |
|
- | 1213 | break; |
|
- | 1214 | case HAL_DAC_CH2_HALF_COMPLETE_CB_ID : |
|
- | 1215 | hdac->ConvHalfCpltCallbackCh2 = HAL_DACEx_ConvHalfCpltCallbackCh2; |
|
- | 1216 | break; |
|
- | 1217 | case HAL_DAC_CH2_ERROR_ID : |
|
- | 1218 | hdac->ErrorCallbackCh2 = HAL_DACEx_ErrorCallbackCh2; |
|
- | 1219 | break; |
|
- | 1220 | case HAL_DAC_CH2_UNDERRUN_CB_ID : |
|
- | 1221 | hdac->DMAUnderrunCallbackCh2 = HAL_DACEx_DMAUnderrunCallbackCh2; |
|
- | 1222 | break; |
|
- | 1223 | case HAL_DAC_MSPINIT_CB_ID : |
|
- | 1224 | hdac->MspInitCallback = HAL_DAC_MspInit; |
|
- | 1225 | break; |
|
- | 1226 | case HAL_DAC_MSPDEINIT_CB_ID : |
|
- | 1227 | hdac->MspDeInitCallback = HAL_DAC_MspDeInit; |
|
- | 1228 | break; |
|
- | 1229 | case HAL_DAC_ALL_CB_ID : |
|
- | 1230 | hdac->ConvCpltCallbackCh1 = HAL_DAC_ConvCpltCallbackCh1; |
|
- | 1231 | hdac->ConvHalfCpltCallbackCh1 = HAL_DAC_ConvHalfCpltCallbackCh1; |
|
- | 1232 | hdac->ErrorCallbackCh1 = HAL_DAC_ErrorCallbackCh1; |
|
- | 1233 | hdac->DMAUnderrunCallbackCh1 = HAL_DAC_DMAUnderrunCallbackCh1; |
|
- | 1234 | hdac->ConvCpltCallbackCh2 = HAL_DACEx_ConvCpltCallbackCh2; |
|
- | 1235 | hdac->ConvHalfCpltCallbackCh2 = HAL_DACEx_ConvHalfCpltCallbackCh2; |
|
- | 1236 | hdac->ErrorCallbackCh2 = HAL_DACEx_ErrorCallbackCh2; |
|
- | 1237 | hdac->DMAUnderrunCallbackCh2 = HAL_DACEx_DMAUnderrunCallbackCh2; |
|
- | 1238 | hdac->MspInitCallback = HAL_DAC_MspInit; |
|
- | 1239 | hdac->MspDeInitCallback = HAL_DAC_MspDeInit; |
|
- | 1240 | break; |
|
- | 1241 | default : |
|
- | 1242 | /* Update the error code */ |
|
- | 1243 | hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK; |
|
- | 1244 | /* update return status */ |
|
- | 1245 | status = HAL_ERROR; |
|
- | 1246 | break; |
|
- | 1247 | } |
|
- | 1248 | } |
|
- | 1249 | else if (hdac->State == HAL_DAC_STATE_RESET) |
|
- | 1250 | { |
|
- | 1251 | switch (CallbackID) |
|
- | 1252 | { |
|
- | 1253 | case HAL_DAC_MSPINIT_CB_ID : |
|
- | 1254 | hdac->MspInitCallback = HAL_DAC_MspInit; |
|
- | 1255 | break; |
|
- | 1256 | case HAL_DAC_MSPDEINIT_CB_ID : |
|
- | 1257 | hdac->MspDeInitCallback = HAL_DAC_MspDeInit; |
|
- | 1258 | break; |
|
- | 1259 | default : |
|
- | 1260 | /* Update the error code */ |
|
- | 1261 | hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK; |
|
- | 1262 | /* update return status */ |
|
- | 1263 | status = HAL_ERROR; |
|
- | 1264 | break; |
|
- | 1265 | } |
|
- | 1266 | } |
|
- | 1267 | else |
|
- | 1268 | { |
|
- | 1269 | /* Update the error code */ |
|
- | 1270 | hdac->ErrorCode |= HAL_DAC_ERROR_INVALID_CALLBACK; |
|
- | 1271 | /* update return status */ |
|
- | 1272 | status = HAL_ERROR; |
|
- | 1273 | } |
|
- | 1274 | ||
- | 1275 | /* Release Lock */ |
|
- | 1276 | __HAL_UNLOCK(hdac); |
|
- | 1277 | return status; |
|
- | 1278 | } |
|
- | 1279 | #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ |
|
- | 1280 | ||
- | 1281 | /** |
|
- | 1282 | * @} |
|
- | 1283 | */ |
|
- | 1284 | ||
868 | /** |
1285 | /** |
869 | * @} |
1286 | * @} |
870 | */ |
1287 | */ |
871 | 1288 | ||
872 | /** @addtogroup DAC_Private_Functions |
1289 | /** @addtogroup DAC_Private_Functions |
873 | * @{ |
1290 | * @{ |
874 | */ |
1291 | */ |
875 | 1292 | ||
876 | /** |
1293 | /** |
877 | * @brief DMA conversion complete callback. |
1294 | * @brief DMA conversion complete callback. |
878 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains |
1295 | * @param hdma pointer to a DMA_HandleTypeDef structure that contains |
879 | * the configuration information for the specified DMA module. |
1296 | * the configuration information for the specified DMA module. |
880 | * @retval None |
1297 | * @retval None |
881 | */ |
1298 | */ |
882 | void DAC_DMAConvCpltCh1(DMA_HandleTypeDef *hdma) |
1299 | void DAC_DMAConvCpltCh1(DMA_HandleTypeDef *hdma) |
883 | { |
1300 | { |
884 | DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
1301 | DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
885 | 1302 | ||
- | 1303 | #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) |
|
- | 1304 | hdac->ConvCpltCallbackCh1(hdac); |
|
- | 1305 | #else |
|
886 | HAL_DAC_ConvCpltCallbackCh1(hdac); |
1306 | HAL_DAC_ConvCpltCallbackCh1(hdac); |
- | 1307 | #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ |
|
887 | 1308 | ||
888 | hdac->State = HAL_DAC_STATE_READY; |
1309 | hdac->State = HAL_DAC_STATE_READY; |
889 | } |
1310 | } |
890 | 1311 | ||
891 | /** |
1312 | /** |
892 | * @brief DMA half transfer complete callback. |
1313 | * @brief DMA half transfer complete callback. |
893 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains |
1314 | * @param hdma pointer to a DMA_HandleTypeDef structure that contains |
894 | * the configuration information for the specified DMA module. |
1315 | * the configuration information for the specified DMA module. |
895 | * @retval None |
1316 | * @retval None |
896 | */ |
1317 | */ |
897 | void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma) |
1318 | void DAC_DMAHalfConvCpltCh1(DMA_HandleTypeDef *hdma) |
898 | { |
1319 | { |
899 | DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
1320 | DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
900 | /* Conversion complete callback */ |
1321 | /* Conversion complete callback */ |
- | 1322 | #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) |
|
- | 1323 | hdac->ConvHalfCpltCallbackCh1(hdac); |
|
- | 1324 | #else |
|
901 | HAL_DAC_ConvHalfCpltCallbackCh1(hdac); |
1325 | HAL_DAC_ConvHalfCpltCallbackCh1(hdac); |
- | 1326 | #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ |
|
902 | } |
1327 | } |
903 | 1328 | ||
904 | /** |
1329 | /** |
905 | * @brief DMA error callback |
1330 | * @brief DMA error callback |
906 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains |
1331 | * @param hdma pointer to a DMA_HandleTypeDef structure that contains |
907 | * the configuration information for the specified DMA module. |
1332 | * the configuration information for the specified DMA module. |
908 | * @retval None |
1333 | * @retval None |
909 | */ |
1334 | */ |
910 | void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma) |
1335 | void DAC_DMAErrorCh1(DMA_HandleTypeDef *hdma) |
911 | { |
1336 | { |
912 | DAC_HandleTypeDef* hdac = ( DAC_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
1337 | DAC_HandleTypeDef *hdac = (DAC_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
913 | 1338 | ||
914 | /* Set DAC error code to DMA error */ |
1339 | /* Set DAC error code to DMA error */ |
915 | hdac->ErrorCode |= HAL_DAC_ERROR_DMA; |
1340 | hdac->ErrorCode |= HAL_DAC_ERROR_DMA; |
- | 1341 | ||
- | 1342 | #if (USE_HAL_DAC_REGISTER_CALLBACKS == 1) |
|
- | 1343 | hdac->ErrorCallbackCh1(hdac); |
|
916 | 1344 | #else |
|
917 | HAL_DAC_ErrorCallbackCh1(hdac); |
1345 | HAL_DAC_ErrorCallbackCh1(hdac); |
- | 1346 | #endif /* USE_HAL_DAC_REGISTER_CALLBACKS */ |
|
918 | 1347 | ||
919 | hdac->State = HAL_DAC_STATE_READY; |
1348 | hdac->State = HAL_DAC_STATE_READY; |
920 | } |
1349 | } |
921 | 1350 | ||
922 | /** |
1351 | /** |
923 | * @} |
1352 | * @} |
924 | */ |
1353 | */ |
925 | 1354 | ||
926 | #endif /* STM32F100xB || STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG || STM32F105xC || STM32F107xC */ |
- | |
927 | #endif /* HAL_DAC_MODULE_ENABLED */ |
- | |
928 | - | ||
929 | /** |
1355 | /** |
930 | * @} |
1356 | * @} |
931 | */ |
1357 | */ |
932 | 1358 | ||
- | 1359 | #endif /* DAC */ |
|
- | 1360 | ||
- | 1361 | #endif /* HAL_DAC_MODULE_ENABLED */ |
|
- | 1362 | ||
933 | /** |
1363 | /** |
934 | * @} |
1364 | * @} |
935 | */ |
1365 | */ |
936 | 1366 | ||
937 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
1367 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |