1 /**
2   ******************************************************************************
3   * @file    stm32l4xx_hal_dac_ex.h
4   * @author  MCD Application Team
5   * @brief   Header file of DAC HAL Extended module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2017 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32L4xx_HAL_DAC_EX_H
21 #define STM32L4xx_HAL_DAC_EX_H
22 
23 #ifdef __cplusplus
24  extern "C" {
25 #endif
26 
27 /** @addtogroup STM32L4xx_HAL_Driver
28   * @{
29   */
30 
31 /* Includes ------------------------------------------------------------------*/
32 #include "stm32l4xx_hal_def.h"
33 
34 #if defined(DAC1)
35 
36 /** @addtogroup DACEx
37   * @{
38   */
39 
40 /* Exported types ------------------------------------------------------------*/
41 
42 /**
43   * @brief  HAL State structures definition
44   */
45 
46 /* Exported constants --------------------------------------------------------*/
47 
48 /** @defgroup DACEx_Exported_Constants DACEx Exported Constants
49   * @{
50   */
51 
52 /** @defgroup DACEx_lfsrunmask_triangleamplitude DACEx lfsrunmask triangle amplitude
53   * @{
54   */
55 #define DAC_LFSRUNMASK_BIT0                0x00000000U                                                         /*!< Unmask DAC channel LFSR bit0 for noise wave generation */
56 #define DAC_LFSRUNMASK_BITS1_0             (                                                   DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[1:0] for noise wave generation */
57 #define DAC_LFSRUNMASK_BITS2_0             (                                  DAC_CR_MAMP1_1                 ) /*!< Unmask DAC channel LFSR bit[2:0] for noise wave generation */
58 #define DAC_LFSRUNMASK_BITS3_0             (                                  DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[3:0] for noise wave generation */
59 #define DAC_LFSRUNMASK_BITS4_0             (                 DAC_CR_MAMP1_2                                  ) /*!< Unmask DAC channel LFSR bit[4:0] for noise wave generation */
60 #define DAC_LFSRUNMASK_BITS5_0             (                 DAC_CR_MAMP1_2                  | DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[5:0] for noise wave generation */
61 #define DAC_LFSRUNMASK_BITS6_0             (                 DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1                 ) /*!< Unmask DAC channel LFSR bit[6:0] for noise wave generation */
62 #define DAC_LFSRUNMASK_BITS7_0             (                 DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[7:0] for noise wave generation */
63 #define DAC_LFSRUNMASK_BITS8_0             (DAC_CR_MAMP1_3                                                   ) /*!< Unmask DAC channel LFSR bit[8:0] for noise wave generation */
64 #define DAC_LFSRUNMASK_BITS9_0             (DAC_CR_MAMP1_3                                   | DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[9:0] for noise wave generation */
65 #define DAC_LFSRUNMASK_BITS10_0            (DAC_CR_MAMP1_3                  | DAC_CR_MAMP1_1                 ) /*!< Unmask DAC channel LFSR bit[10:0] for noise wave generation */
66 #define DAC_LFSRUNMASK_BITS11_0            (DAC_CR_MAMP1_3                  | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[11:0] for noise wave generation */
67 #define DAC_TRIANGLEAMPLITUDE_1            0x00000000U                                                         /*!< Select max triangle amplitude of 1 */
68 #define DAC_TRIANGLEAMPLITUDE_3            (                                                   DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 3 */
69 #define DAC_TRIANGLEAMPLITUDE_7            (                                  DAC_CR_MAMP1_1                 ) /*!< Select max triangle amplitude of 7 */
70 #define DAC_TRIANGLEAMPLITUDE_15           (                                  DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 15 */
71 #define DAC_TRIANGLEAMPLITUDE_31           (                 DAC_CR_MAMP1_2                                  ) /*!< Select max triangle amplitude of 31 */
72 #define DAC_TRIANGLEAMPLITUDE_63           (                 DAC_CR_MAMP1_2                  | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 63 */
73 #define DAC_TRIANGLEAMPLITUDE_127          (                 DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1                 ) /*!< Select max triangle amplitude of 127 */
74 #define DAC_TRIANGLEAMPLITUDE_255          (                 DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 255 */
75 #define DAC_TRIANGLEAMPLITUDE_511          (DAC_CR_MAMP1_3                                                   ) /*!< Select max triangle amplitude of 511 */
76 #define DAC_TRIANGLEAMPLITUDE_1023         (DAC_CR_MAMP1_3                                   | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 1023 */
77 #define DAC_TRIANGLEAMPLITUDE_2047         (DAC_CR_MAMP1_3                  | DAC_CR_MAMP1_1                 ) /*!< Select max triangle amplitude of 2047 */
78 #define DAC_TRIANGLEAMPLITUDE_4095         (DAC_CR_MAMP1_3                  | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 4095 */
79 
80 /**
81   * @}
82   */
83 
84 /**
85   * @}
86   */
87 
88 /* Exported macro ------------------------------------------------------------*/
89 
90 
91 /* Private macro -------------------------------------------------------------*/
92 
93 /** @defgroup DACEx_Private_Macros DACEx Private Macros
94   * @{
95   */
96 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx)
97 #define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_TRIGGER_NONE)    || \
98                                  ((TRIGGER) == DAC_TRIGGER_T2_TRGO) || \
99                                  ((TRIGGER) == DAC_TRIGGER_T6_TRGO) || \
100                                  ((TRIGGER) == DAC_TRIGGER_T7_TRGO) || \
101                                  ((TRIGGER) == DAC_TRIGGER_EXT_IT9) || \
102                                  ((TRIGGER) == DAC_TRIGGER_SOFTWARE))
103 #endif     /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx */
104 
105 #if defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx)
106 #define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_TRIGGER_NONE)    || \
107                                  ((TRIGGER) == DAC_TRIGGER_T2_TRGO) || \
108                                  ((TRIGGER) == DAC_TRIGGER_T6_TRGO) || \
109                                  ((TRIGGER) == DAC_TRIGGER_EXT_IT9) || \
110                                  ((TRIGGER) == DAC_TRIGGER_SOFTWARE))
111 #endif     /* STM32L451xx STM32L452xx STM32L462xx                         */
112 
113 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx)
114 #define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_TRIGGER_NONE)    || \
115                                  ((TRIGGER) == DAC_TRIGGER_T2_TRGO) || \
116                                  ((TRIGGER) == DAC_TRIGGER_T4_TRGO) || \
117                                  ((TRIGGER) == DAC_TRIGGER_T5_TRGO) || \
118                                  ((TRIGGER) == DAC_TRIGGER_T6_TRGO) || \
119                                  ((TRIGGER) == DAC_TRIGGER_T7_TRGO) || \
120                                  ((TRIGGER) == DAC_TRIGGER_T8_TRGO) || \
121                                  ((TRIGGER) == DAC_TRIGGER_EXT_IT9) || \
122                                  ((TRIGGER) == DAC_TRIGGER_SOFTWARE))
123 #endif     /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */
124 
125 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx)
126 #define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_TRIGGER_NONE)       || \
127                                  ((TRIGGER) == DAC_TRIGGER_T1_TRGO)    || \
128                                  ((TRIGGER) == DAC_TRIGGER_T2_TRGO)    || \
129                                  ((TRIGGER) == DAC_TRIGGER_T4_TRGO)    || \
130                                  ((TRIGGER) == DAC_TRIGGER_T5_TRGO)    || \
131                                  ((TRIGGER) == DAC_TRIGGER_T6_TRGO)    || \
132                                  ((TRIGGER) == DAC_TRIGGER_T7_TRGO)    || \
133                                  ((TRIGGER) == DAC_TRIGGER_T8_TRGO)    || \
134                                  ((TRIGGER) == DAC_TRIGGER_T15_TRGO)   || \
135                                  ((TRIGGER) == DAC_TRIGGER_LPTIM1_OUT) || \
136                                  ((TRIGGER) == DAC_TRIGGER_LPTIM2_OUT) || \
137                                  ((TRIGGER) == DAC_TRIGGER_EXT_IT9)    || \
138                                  ((TRIGGER) == DAC_TRIGGER_SOFTWARE))
139 
140 #define  IS_DAC_HIGH_FREQUENCY_MODE(MODE) (((MODE) == DAC_HIGH_FREQUENCY_INTERFACE_MODE_DISABLE)         || \
141                                            ((MODE) == DAC_HIGH_FREQUENCY_INTERFACE_MODE_ABOVE_80MHZ)     || \
142                                            ((MODE) == DAC_HIGH_FREQUENCY_INTERFACE_MODE_AUTOMATIC))
143 
144 #endif  /* STM32L4P5xx STM32L4Q5xx STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx */
145 
146 #define IS_DAC_SAMPLETIME(TIME) ((TIME) <= 0x000003FFU)
147 
148 #define IS_DAC_HOLDTIME(TIME)   ((TIME) <= 0x000003FFU)
149 
150 #define IS_DAC_SAMPLEANDHOLD(MODE) (((MODE) == DAC_SAMPLEANDHOLD_DISABLE) || \
151                                     ((MODE) == DAC_SAMPLEANDHOLD_ENABLE))
152 
153 #define IS_DAC_TRIMMINGVALUE(TRIMMINGVALUE) ((TRIMMINGVALUE) <= 0x1FU)
154 
155 #define IS_DAC_NEWTRIMMINGVALUE(TRIMMINGVALUE) ((TRIMMINGVALUE) <= 0x1FU)
156 
157 #define IS_DAC_CHIP_CONNECTION(CONNECT) (((CONNECT) == DAC_CHIPCONNECT_DISABLE) || \
158                                          ((CONNECT) == DAC_CHIPCONNECT_ENABLE))
159 
160 #define IS_DAC_TRIMMING(TRIMMING) (((TRIMMING) == DAC_TRIMMING_FACTORY) || \
161                                      ((TRIMMING) == DAC_TRIMMING_USER))
162 
163 #define IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(VALUE) (((VALUE) == DAC_LFSRUNMASK_BIT0) || \
164                                                       ((VALUE) == DAC_LFSRUNMASK_BITS1_0) || \
165                                                       ((VALUE) == DAC_LFSRUNMASK_BITS2_0) || \
166                                                       ((VALUE) == DAC_LFSRUNMASK_BITS3_0) || \
167                                                       ((VALUE) == DAC_LFSRUNMASK_BITS4_0) || \
168                                                       ((VALUE) == DAC_LFSRUNMASK_BITS5_0) || \
169                                                       ((VALUE) == DAC_LFSRUNMASK_BITS6_0) || \
170                                                       ((VALUE) == DAC_LFSRUNMASK_BITS7_0) || \
171                                                       ((VALUE) == DAC_LFSRUNMASK_BITS8_0) || \
172                                                       ((VALUE) == DAC_LFSRUNMASK_BITS9_0) || \
173                                                       ((VALUE) == DAC_LFSRUNMASK_BITS10_0) || \
174                                                       ((VALUE) == DAC_LFSRUNMASK_BITS11_0) || \
175                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_1) || \
176                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_3) || \
177                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_7) || \
178                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_15) || \
179                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_31) || \
180                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_63) || \
181                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_127) || \
182                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_255) || \
183                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_511) || \
184                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_1023) || \
185                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_2047) || \
186                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_4095))
187 /**
188   * @}
189   */
190 
191 /* Exported functions --------------------------------------------------------*/
192 /* Extended features functions ***********************************************/
193 
194 /** @addtogroup DACEx_Exported_Functions
195   * @{
196   */
197 
198 /** @addtogroup DACEx_Exported_Functions_Group2
199  * @{
200  */
201 /* IO operation functions *****************************************************/
202 
203 HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Amplitude);
204 HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef* hdac, uint32_t Channel, uint32_t Amplitude);
205 
206 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \
207     defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx) || \
208     defined (STM32L4P5xx) || defined (STM32L4Q5xx) || \
209     defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx)
210 HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef* hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2);
211 uint32_t HAL_DACEx_DualGetValue(DAC_HandleTypeDef* hdac);
212 #endif  /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx                         */
213         /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */
214         /* STM32L4P5xx STM32L4Q5xx                                                             */
215         /* STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx             */
216 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \
217     defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx) || \
218     defined (STM32L4P5xx) || defined (STM32L4Q5xx) || \
219     defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx)
220 void HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef* hdac);
221 void HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef* hdac);
222 void HAL_DACEx_ErrorCallbackCh2(DAC_HandleTypeDef* hdac);
223 void HAL_DACEx_DMAUnderrunCallbackCh2(DAC_HandleTypeDef* hdac);
224 #endif  /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx                         */
225         /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */
226         /* STM32L4P5xx STM32L4Q5xx                                                             */
227         /* STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx             */
228 
229 
230 /**
231   * @}
232   */
233 
234 /** @addtogroup DACEx_Exported_Functions_Group3
235   * @{
236   */
237 /* Peripheral Control functions ***********************************************/
238 
239 HAL_StatusTypeDef HAL_DACEx_SelfCalibrate(DAC_HandleTypeDef *hdac, DAC_ChannelConfTypeDef *sConfig, uint32_t Channel);
240 HAL_StatusTypeDef HAL_DACEx_SetUserTrimming(DAC_HandleTypeDef *hdac, DAC_ChannelConfTypeDef *sConfig, uint32_t Channel, uint32_t NewTrimmingValue);
241 uint32_t HAL_DACEx_GetTrimOffset (DAC_HandleTypeDef *hdac, uint32_t Channel);
242 
243 /**
244   * @}
245   */
246 
247 /**
248   * @}
249   */
250 
251 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \
252     defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx) || \
253     defined (STM32L4P5xx) || defined (STM32L4Q5xx) || \
254     defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined(STM32L4S9xx)
255 
256 /** @addtogroup DACEx_Private_Functions
257   * @{
258   */
259 
260 /* DAC_DMAConvCpltCh2 / DAC_DMAErrorCh2 / DAC_DMAHalfConvCpltCh2 */
261 /* are called by HAL_DAC_Start_DMA */
262 void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma);
263 void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma);
264 void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma);
265 
266 /**
267  * @}
268  */
269 #endif  /* STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx                         */
270         /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx STM32L496xx STM32L4A6xx */
271         /* STM32L4P5xx STM32L4Q5xx                                                             */
272         /* STM32L4R5xx STM32L4R7xx STM32L4R9xx STM32L4S5xx STM32L4S7xx STM32L4S9xx             */
273 /**
274   * @}
275   */
276 
277 #endif /* DAC1 */
278 
279 /**
280   * @}
281   */
282 
283 #ifdef __cplusplus
284 }
285 #endif
286 
287 #endif /*STM32L4xx_HAL_DAC_EX_H */
288 
289