1 /**
2   ******************************************************************************
3   * @file    stm32mp1xx_hal_dac_ex.h
4   * @author  MCD Application Team
5   * @brief   Header file of DAC HAL Extended module.
6   ******************************************************************************
7   * @attention
8   *
9   * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
10   * All rights reserved.</center></h2>
11   *
12   * This software component is licensed by ST under BSD 3-Clause license,
13   * the "License"; You may not use this file except in compliance with the
14   * License. You may obtain a copy of the License at:
15   *                        opensource.org/licenses/BSD-3-Clause
16   *
17   ******************************************************************************
18   */
19 
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef STM32MP1xx_HAL_DAC_EX_H
22 #define STM32MP1xx_HAL_DAC_EX_H
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32mp1xx_hal_def.h"
30 
31 /** @addtogroup STM32MP1xx_HAL_Driver
32   * @{
33   */
34 
35 /** @addtogroup DACEx
36   * @{
37   */
38 
39 /* Exported types ------------------------------------------------------------*/
40 
41 /**
42   * @brief  HAL State structures definition
43   */
44 
45 /* Exported constants --------------------------------------------------------*/
46 
47 /** @defgroup DACEx_Exported_Constants DACEx Exported Constants
48   * @{
49   */
50 /** @defgroup DACEx_lfsrunmask_triangleamplitude DACEx lfsrunmask triangle amplitude
51   * @{
52   */
53 #define DAC_LFSRUNMASK_BIT0                ((uint32_t)0x00000000) /*!< Unmask DAC channel LFSR bit0 for noise wave generation */
54 #define DAC_LFSRUNMASK_BITS1_0             ((uint32_t)DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[1:0] for noise wave generation */
55 #define DAC_LFSRUNMASK_BITS2_0             ((uint32_t)DAC_CR_MAMP1_1) /*!< Unmask DAC channel LFSR bit[2:0] for noise wave generation */
56 #define DAC_LFSRUNMASK_BITS3_0             ((uint32_t)DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0)/*!< Unmask DAC channel LFSR bit[3:0] for noise wave generation */
57 #define DAC_LFSRUNMASK_BITS4_0             ((uint32_t)DAC_CR_MAMP1_2) /*!< Unmask DAC channel LFSR bit[4:0] for noise wave generation */
58 #define DAC_LFSRUNMASK_BITS5_0             ((uint32_t)DAC_CR_MAMP1_2 | DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[5:0] for noise wave generation */
59 #define DAC_LFSRUNMASK_BITS6_0             ((uint32_t)DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1) /*!< Unmask DAC channel LFSR bit[6:0] for noise wave generation */
60 #define DAC_LFSRUNMASK_BITS7_0             ((uint32_t)DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[7:0] for noise wave generation */
61 #define DAC_LFSRUNMASK_BITS8_0             ((uint32_t)DAC_CR_MAMP1_3) /*!< Unmask DAC channel LFSR bit[8:0] for noise wave generation */
62 #define DAC_LFSRUNMASK_BITS9_0             ((uint32_t)DAC_CR_MAMP1_3 | DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[9:0] for noise wave generation */
63 #define DAC_LFSRUNMASK_BITS10_0            ((uint32_t)DAC_CR_MAMP1_3 | DAC_CR_MAMP1_1) /*!< Unmask DAC channel LFSR bit[10:0] for noise wave generation */
64 #define DAC_LFSRUNMASK_BITS11_0            ((uint32_t)DAC_CR_MAMP1_3 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Unmask DAC channel LFSR bit[11:0] for noise wave generation */
65 #define DAC_TRIANGLEAMPLITUDE_1            ((uint32_t)0x00000000) /*!< Select max triangle amplitude of 1 */
66 #define DAC_TRIANGLEAMPLITUDE_3            ((uint32_t)DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 3 */
67 #define DAC_TRIANGLEAMPLITUDE_7            ((uint32_t)DAC_CR_MAMP1_1) /*!< Select max triangle amplitude of 7 */
68 #define DAC_TRIANGLEAMPLITUDE_15           ((uint32_t)DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 15 */
69 #define DAC_TRIANGLEAMPLITUDE_31           ((uint32_t)DAC_CR_MAMP1_2) /*!< Select max triangle amplitude of 31 */
70 #define DAC_TRIANGLEAMPLITUDE_63           ((uint32_t)DAC_CR_MAMP1_2 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 63 */
71 #define DAC_TRIANGLEAMPLITUDE_127          ((uint32_t)DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1) /*!< Select max triangle amplitude of 127 */
72 #define DAC_TRIANGLEAMPLITUDE_255          ((uint32_t)DAC_CR_MAMP1_2 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 255 */
73 #define DAC_TRIANGLEAMPLITUDE_511          ((uint32_t)DAC_CR_MAMP1_3) /*!< Select max triangle amplitude of 511 */
74 #define DAC_TRIANGLEAMPLITUDE_1023         ((uint32_t)DAC_CR_MAMP1_3 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 1023 */
75 #define DAC_TRIANGLEAMPLITUDE_2047         ((uint32_t)DAC_CR_MAMP1_3 | DAC_CR_MAMP1_1) /*!< Select max triangle amplitude of 2047 */
76 #define DAC_TRIANGLEAMPLITUDE_4095         ((uint32_t)DAC_CR_MAMP1_3 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_0) /*!< Select max triangle amplitude of 4095 */
77 /**
78   * @}
79   */
80 
81 /**
82   * @}
83   */
84 
85 /* Exported macro ------------------------------------------------------------*/
86 
87 
88 /* Private macro -------------------------------------------------------------*/
89 
90 /** @defgroup DACEx_Private_Macros DACEx Private Macros
91   * @{
92   */
93 
94 #define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_TRIGGER_NONE) || \
95                                  ((TRIGGER) == DAC_TRIGGER_T1_TRGO) || \
96                                  ((TRIGGER) == DAC_TRIGGER_T2_TRGO) || \
97                                  ((TRIGGER) == DAC_TRIGGER_T4_TRGO) || \
98                                  ((TRIGGER) == DAC_TRIGGER_T5_TRGO) || \
99                                  ((TRIGGER) == DAC_TRIGGER_T6_TRGO) || \
100                                  ((TRIGGER) == DAC_TRIGGER_T7_TRGO) || \
101                                  ((TRIGGER) == DAC_TRIGGER_T8_TRGO) || \
102                                  ((TRIGGER) == DAC_TRIGGER_T15_TRGO) || \
103                                  ((TRIGGER) == DAC_TRIGGER_LP1_OUT) || \
104                                  ((TRIGGER) == DAC_TRIGGER_LP2_OUT) || \
105                                  ((TRIGGER) == DAC_TRIGGER_EXT_IT9) || \
106                                  ((TRIGGER) == DAC_TRIGGER_SOFTWARE))
107 
108 #define  IS_DAC_HIGH_FREQUENCY_MODE(MODE) (((MODE) == DAC_HIGH_FREQUENCY_INTERFACE_MODE_DISABLE)         || \
109                                            ((MODE) == DAC_HIGH_FREQUENCY_INTERFACE_MODE_ABOVE_80MHZ)     || \
110                                            ((MODE) == DAC_HIGH_FREQUENCY_INTERFACE_MODE_AUTOMATIC))
111 
112 #define IS_DAC_SAMPLETIME(TIME) ((TIME) <= 0x000003FF)
113 
114 #define IS_DAC_HOLDTIME(TIME)   ((TIME) <= 0x000003FF)
115 
116 #define IS_DAC_SAMPLEANDHOLD(MODE) (((MODE) == DAC_SAMPLEANDHOLD_DISABLE) || \
117                                     ((MODE) == DAC_SAMPLEANDHOLD_ENABLE))
118 
119 
120 #define IS_DAC_TRIMMINGVALUE(TRIMMINGVALUE) ((TRIMMINGVALUE) <= 0x1F)
121 
122 #define IS_DAC_NEWTRIMMINGVALUE(TRIMMINGVALUE) ((TRIMMINGVALUE) <= 0x1F)
123 
124 #define IS_DAC_CHIP_CONNECTION(CONNECT) (((CONNECT) == DAC_CHIPCONNECT_DISABLE) || \
125                                          ((CONNECT) == DAC_CHIPCONNECT_ENABLE))
126 
127 #define IS_DAC_TRIMMING(TRIMMING)       (((TRIMMING) == DAC_TRIMMING_FACTORY) || \
128                                         ((TRIMMING) == DAC_TRIMMING_USER))
129 
130 #define IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(VALUE) (((VALUE) == DAC_LFSRUNMASK_BIT0) || \
131                                                       ((VALUE) == DAC_LFSRUNMASK_BITS1_0) || \
132                                                       ((VALUE) == DAC_LFSRUNMASK_BITS2_0) || \
133                                                       ((VALUE) == DAC_LFSRUNMASK_BITS3_0) || \
134                                                       ((VALUE) == DAC_LFSRUNMASK_BITS4_0) || \
135                                                       ((VALUE) == DAC_LFSRUNMASK_BITS5_0) || \
136                                                       ((VALUE) == DAC_LFSRUNMASK_BITS6_0) || \
137                                                       ((VALUE) == DAC_LFSRUNMASK_BITS7_0) || \
138                                                       ((VALUE) == DAC_LFSRUNMASK_BITS8_0) || \
139                                                       ((VALUE) == DAC_LFSRUNMASK_BITS9_0) || \
140                                                       ((VALUE) == DAC_LFSRUNMASK_BITS10_0) || \
141                                                       ((VALUE) == DAC_LFSRUNMASK_BITS11_0) || \
142                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_1) || \
143                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_3) || \
144                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_7) || \
145                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_15) || \
146                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_31) || \
147                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_63) || \
148                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_127) || \
149                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_255) || \
150                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_511) || \
151                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_1023) || \
152                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_2047) || \
153                                                       ((VALUE) == DAC_TRIANGLEAMPLITUDE_4095))
154 
155 /**
156   * @}
157   */
158 
159 /* Exported functions --------------------------------------------------------*/
160 /* Extended features functions ***********************************************/
161 
162 /** @addtogroup DACEx_Exported_Functions
163   * @{
164   */
165 /** @addtogroup DACEx_Exported_Functions_Group2
166 * @{
167 */
168 /* IO operation functions *****************************************************/
169 
170 HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Amplitude);
171 HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Amplitude);
172 HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef *hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2);
173 
174 void HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef *hdac);
175 void HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef *hdac);
176 void HAL_DACEx_ErrorCallbackCh2(DAC_HandleTypeDef *hdac);
177 void HAL_DACEx_DMAUnderrunCallbackCh2(DAC_HandleTypeDef *hdac);
178 
179 HAL_StatusTypeDef HAL_DACEx_SelfCalibrate(DAC_HandleTypeDef *hdac, DAC_ChannelConfTypeDef *sConfig, uint32_t Channel);
180 HAL_StatusTypeDef HAL_DACEx_SetUserTrimming(DAC_HandleTypeDef *hdac, DAC_ChannelConfTypeDef *sConfig, uint32_t Channel, uint32_t NewTrimmingValue);
181 
182 /**
183   * @}
184   */
185 
186 /** @addtogroup DACEx_Exported_Functions_Group3
187   * @{
188   */
189 /* Peripheral Control functions ***********************************************/
190 
191 uint32_t HAL_DACEx_DualGetValue(DAC_HandleTypeDef *hdac);
192 uint32_t HAL_DACEx_GetTrimOffset(DAC_HandleTypeDef *hdac, uint32_t Channel);
193 
194 /**
195   * @}
196   */
197 
198 /**
199   * @}
200   */
201 
202 /** @addtogroup DACEx_Private_Functions
203   * @{
204   */
205 
206 /* DAC_DMAConvCpltCh2 / DAC_DMAErrorCh2 / DAC_DMAHalfConvCpltCh2 */
207 /* are called by HAL_DAC_Start_DMA */
208 void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma);
209 void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma);
210 void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma);
211 
212 /**
213   * @}
214   */
215 
216 /**
217 * @}
218 */
219 
220 /**
221   * @}
222   */
223 
224 
225 #ifdef __cplusplus
226 }
227 #endif
228 
229 #endif /*__STM32MP1xx_HAL_DAC_EX_H */
230 
231 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
232