1 /** 2 ****************************************************************************** 3 * @file stm32l5xx_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) 2019 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 STM32L5xx_HAL_DAC_EX_H 21 #define STM32L5xx_HAL_DAC_EX_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /** @addtogroup STM32L5xx_HAL_Driver 28 * @{ 29 */ 30 31 /* Includes ------------------------------------------------------------------*/ 32 #include "stm32l5xx_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 0x00000000UL /*!< 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 0x00000000UL /*!< 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 #define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_TRIGGER_NONE) || \ 97 ((TRIGGER) == DAC_TRIGGER_T1_TRGO) || \ 98 ((TRIGGER) == DAC_TRIGGER_T2_TRGO) || \ 99 ((TRIGGER) == DAC_TRIGGER_T4_TRGO) || \ 100 ((TRIGGER) == DAC_TRIGGER_T5_TRGO) || \ 101 ((TRIGGER) == DAC_TRIGGER_T6_TRGO) || \ 102 ((TRIGGER) == DAC_TRIGGER_T7_TRGO) || \ 103 ((TRIGGER) == DAC_TRIGGER_T8_TRGO) || \ 104 ((TRIGGER) == DAC_TRIGGER_T15_TRGO) || \ 105 ((TRIGGER) == DAC_TRIGGER_LPTIM1_OUT) || \ 106 ((TRIGGER) == DAC_TRIGGER_LPTIM2_OUT) || \ 107 ((TRIGGER) == DAC_TRIGGER_EXT_IT9) || \ 108 ((TRIGGER) == DAC_TRIGGER_SOFTWARE)) 109 110 #define IS_DAC_HIGH_FREQUENCY_MODE(MODE) (((MODE) == DAC_HIGH_FREQUENCY_INTERFACE_MODE_DISABLE) || \ 111 ((MODE) == DAC_HIGH_FREQUENCY_INTERFACE_MODE_ABOVE_80MHZ) || \ 112 ((MODE) == DAC_HIGH_FREQUENCY_INTERFACE_MODE_AUTOMATIC)) 113 114 #define IS_DAC_SAMPLETIME(TIME) ((TIME) <= 0x000003FFU) 115 116 #define IS_DAC_HOLDTIME(TIME) ((TIME) <= 0x000003FFU) 117 118 #define IS_DAC_SAMPLEANDHOLD(MODE) (((MODE) == DAC_SAMPLEANDHOLD_DISABLE) || \ 119 ((MODE) == DAC_SAMPLEANDHOLD_ENABLE)) 120 121 #define IS_DAC_TRIMMINGVALUE(TRIMMINGVALUE) ((TRIMMINGVALUE) <= 0x1FU) 122 123 #define IS_DAC_NEWTRIMMINGVALUE(TRIMMINGVALUE) ((TRIMMINGVALUE) <= 0x1FU) 124 125 #define IS_DAC_CHIP_CONNECTION(CONNECT) (((CONNECT) == DAC_CHIPCONNECT_EXTERNAL) || \ 126 ((CONNECT) == DAC_CHIPCONNECT_INTERNAL) || \ 127 ((CONNECT) == DAC_CHIPCONNECT_BOTH)) 128 129 #define IS_DAC_TRIMMING(TRIMMING) (((TRIMMING) == DAC_TRIMMING_FACTORY) || \ 130 ((TRIMMING) == DAC_TRIMMING_USER)) 131 132 #define IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(VALUE) (((VALUE) == DAC_LFSRUNMASK_BIT0) || \ 133 ((VALUE) == DAC_LFSRUNMASK_BITS1_0) || \ 134 ((VALUE) == DAC_LFSRUNMASK_BITS2_0) || \ 135 ((VALUE) == DAC_LFSRUNMASK_BITS3_0) || \ 136 ((VALUE) == DAC_LFSRUNMASK_BITS4_0) || \ 137 ((VALUE) == DAC_LFSRUNMASK_BITS5_0) || \ 138 ((VALUE) == DAC_LFSRUNMASK_BITS6_0) || \ 139 ((VALUE) == DAC_LFSRUNMASK_BITS7_0) || \ 140 ((VALUE) == DAC_LFSRUNMASK_BITS8_0) || \ 141 ((VALUE) == DAC_LFSRUNMASK_BITS9_0) || \ 142 ((VALUE) == DAC_LFSRUNMASK_BITS10_0) || \ 143 ((VALUE) == DAC_LFSRUNMASK_BITS11_0) || \ 144 ((VALUE) == DAC_TRIANGLEAMPLITUDE_1) || \ 145 ((VALUE) == DAC_TRIANGLEAMPLITUDE_3) || \ 146 ((VALUE) == DAC_TRIANGLEAMPLITUDE_7) || \ 147 ((VALUE) == DAC_TRIANGLEAMPLITUDE_15) || \ 148 ((VALUE) == DAC_TRIANGLEAMPLITUDE_31) || \ 149 ((VALUE) == DAC_TRIANGLEAMPLITUDE_63) || \ 150 ((VALUE) == DAC_TRIANGLEAMPLITUDE_127) || \ 151 ((VALUE) == DAC_TRIANGLEAMPLITUDE_255) || \ 152 ((VALUE) == DAC_TRIANGLEAMPLITUDE_511) || \ 153 ((VALUE) == DAC_TRIANGLEAMPLITUDE_1023) || \ 154 ((VALUE) == DAC_TRIANGLEAMPLITUDE_2047) || \ 155 ((VALUE) == DAC_TRIANGLEAMPLITUDE_4095)) 156 /** 157 * @} 158 */ 159 160 /* Exported functions --------------------------------------------------------*/ 161 /* Extended features functions ***********************************************/ 162 163 /** @addtogroup DACEx_Exported_Functions 164 * @{ 165 */ 166 167 /** @addtogroup DACEx_Exported_Functions_Group2 168 * @{ 169 */ 170 /* IO operation functions *****************************************************/ 171 172 HAL_StatusTypeDef HAL_DACEx_TriangleWaveGenerate(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Amplitude); 173 HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t Amplitude); 174 175 HAL_StatusTypeDef HAL_DACEx_DualStart(DAC_HandleTypeDef *hdac); 176 HAL_StatusTypeDef HAL_DACEx_DualStop(DAC_HandleTypeDef *hdac); 177 HAL_StatusTypeDef HAL_DACEx_DualStart_DMA(DAC_HandleTypeDef *hdac, uint32_t Channel, uint32_t *pData, uint32_t Length, 178 uint32_t Alignment); 179 HAL_StatusTypeDef HAL_DACEx_DualStop_DMA(DAC_HandleTypeDef *hdac, uint32_t Channel); 180 HAL_StatusTypeDef HAL_DACEx_DualSetValue(DAC_HandleTypeDef *hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2); 181 uint32_t HAL_DACEx_DualGetValue(DAC_HandleTypeDef *hdac); 182 void HAL_DACEx_ConvCpltCallbackCh2(DAC_HandleTypeDef *hdac); 183 void HAL_DACEx_ConvHalfCpltCallbackCh2(DAC_HandleTypeDef *hdac); 184 void HAL_DACEx_ErrorCallbackCh2(DAC_HandleTypeDef *hdac); 185 void HAL_DACEx_DMAUnderrunCallbackCh2(DAC_HandleTypeDef *hdac); 186 187 /** 188 * @} 189 */ 190 191 /** @addtogroup DACEx_Exported_Functions_Group3 192 * @{ 193 */ 194 /* Peripheral Control functions ***********************************************/ 195 196 HAL_StatusTypeDef HAL_DACEx_SelfCalibrate(DAC_HandleTypeDef *hdac, DAC_ChannelConfTypeDef *sConfig, uint32_t Channel); 197 HAL_StatusTypeDef HAL_DACEx_SetUserTrimming(DAC_HandleTypeDef *hdac, DAC_ChannelConfTypeDef *sConfig, uint32_t Channel, 198 uint32_t NewTrimmingValue); 199 uint32_t HAL_DACEx_GetTrimOffset(DAC_HandleTypeDef *hdac, uint32_t Channel); 200 201 /** 202 * @} 203 */ 204 205 /** 206 * @} 207 */ 208 209 /** @addtogroup DACEx_Private_Functions 210 * @{ 211 */ 212 213 /* DAC_DMAConvCpltCh2 / DAC_DMAErrorCh2 / DAC_DMAHalfConvCpltCh2 */ 214 /* are called by HAL_DAC_Start_DMA */ 215 void DAC_DMAConvCpltCh2(DMA_HandleTypeDef *hdma); 216 void DAC_DMAErrorCh2(DMA_HandleTypeDef *hdma); 217 void DAC_DMAHalfConvCpltCh2(DMA_HandleTypeDef *hdma); 218 219 /** 220 * @} 221 */ 222 223 /** 224 * @} 225 */ 226 227 #endif /* DAC1 */ 228 229 /** 230 * @} 231 */ 232 233 #ifdef __cplusplus 234 } 235 #endif 236 237 #endif /* STM32L5xx_HAL_DAC_EX_H */ 238 239