1 /* Define to prevent recursive inclusion -------------------------------------*/ 2 #ifndef __AIR32F10x_DAC_H 3 #define __AIR32F10x_DAC_H 4 5 #ifdef __cplusplus 6 extern "C" { 7 #endif 8 9 /* Includes ------------------------------------------------------------------*/ 10 #include "air32f10x.h" 11 12 /** @addtogroup air32f10x_StdPeriph_Driver 13 * @{ 14 */ 15 16 /** @addtogroup DAC 17 * @{ 18 */ 19 20 /** @defgroup DAC_Exported_Types 21 * @{ 22 */ 23 24 /** 25 * @brief DAC Init structure definition 26 */ 27 28 typedef struct 29 { 30 uint32_t DAC_Trigger; /*!< Specifies the external trigger for the selected DAC channel. 31 This parameter can be a value of @ref DAC_trigger_selection */ 32 33 uint32_t DAC_WaveGeneration; /*!< Specifies whether DAC channel noise waves or triangle waves 34 are generated, or whether no wave is generated. 35 This parameter can be a value of @ref DAC_wave_generation */ 36 37 uint32_t DAC_LFSRUnmask_TriangleAmplitude; /*!< Specifies the LFSR mask for noise wave generation or 38 the maximum amplitude triangle generation for the DAC channel. 39 This parameter can be a value of @ref DAC_lfsrunmask_triangleamplitude */ 40 41 uint32_t DAC_OutputBuffer; /*!< Specifies whether the DAC channel output buffer is enabled or disabled. 42 This parameter can be a value of @ref DAC_output_buffer */ 43 }DAC_InitTypeDef; 44 45 /** 46 * @} 47 */ 48 49 /** @defgroup DAC_Exported_Constants 50 * @{ 51 */ 52 53 /** @defgroup DAC_trigger_selection 54 * @{ 55 */ 56 57 #define DAC_Trigger_None ((uint32_t)0x00000000) /*!< Conversion is automatic once the DAC1_DHRxxxx register 58 has been loaded, and not by external trigger */ 59 #define DAC_Trigger_T6_TRGO ((uint32_t)0x00000004) /*!< TIM6 TRGO selected as external conversion trigger for DAC channel */ 60 #define DAC_Trigger_T8_TRGO ((uint32_t)0x0000000C) /*!< TIM8 TRGO selected as external conversion trigger for DAC channel 61 only in High-density devices*/ 62 #define DAC_Trigger_T3_TRGO ((uint32_t)0x0000000C) /*!< TIM8 TRGO selected as external conversion trigger for DAC channel 63 only in Connectivity line, Medium-density and Low-density Value Line devices */ 64 #define DAC_Trigger_T7_TRGO ((uint32_t)0x00000014) /*!< TIM7 TRGO selected as external conversion trigger for DAC channel */ 65 #define DAC_Trigger_T5_TRGO ((uint32_t)0x0000001C) /*!< TIM5 TRGO selected as external conversion trigger for DAC channel */ 66 #define DAC_Trigger_T15_TRGO ((uint32_t)0x0000001C) /*!< TIM15 TRGO selected as external conversion trigger for DAC channel 67 only in Medium-density and Low-density Value Line devices*/ 68 #define DAC_Trigger_T2_TRGO ((uint32_t)0x00000024) /*!< TIM2 TRGO selected as external conversion trigger for DAC channel */ 69 #define DAC_Trigger_T4_TRGO ((uint32_t)0x0000002C) /*!< TIM4 TRGO selected as external conversion trigger for DAC channel */ 70 #define DAC_Trigger_Ext_IT9 ((uint32_t)0x00000034) /*!< EXTI Line9 event selected as external conversion trigger for DAC channel */ 71 #define DAC_Trigger_Software ((uint32_t)0x0000003C) /*!< Conversion started by software trigger for DAC channel */ 72 73 #define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_Trigger_None) || \ 74 ((TRIGGER) == DAC_Trigger_T6_TRGO) || \ 75 ((TRIGGER) == DAC_Trigger_T8_TRGO) || \ 76 ((TRIGGER) == DAC_Trigger_T7_TRGO) || \ 77 ((TRIGGER) == DAC_Trigger_T5_TRGO) || \ 78 ((TRIGGER) == DAC_Trigger_T2_TRGO) || \ 79 ((TRIGGER) == DAC_Trigger_T4_TRGO) || \ 80 ((TRIGGER) == DAC_Trigger_Ext_IT9) || \ 81 ((TRIGGER) == DAC_Trigger_Software)) 82 83 /** 84 * @} 85 */ 86 87 /** @defgroup DAC_wave_generation 88 * @{ 89 */ 90 91 #define DAC_WaveGeneration_None ((uint32_t)0x00000000) 92 #define DAC_WaveGeneration_Noise ((uint32_t)0x00000040) 93 #define DAC_WaveGeneration_Triangle ((uint32_t)0x00000080) 94 #define IS_DAC_GENERATE_WAVE(WAVE) (((WAVE) == DAC_WaveGeneration_None) || \ 95 ((WAVE) == DAC_WaveGeneration_Noise) || \ 96 ((WAVE) == DAC_WaveGeneration_Triangle)) 97 /** 98 * @} 99 */ 100 101 /** @defgroup DAC_lfsrunmask_triangleamplitude 102 * @{ 103 */ 104 105 #define DAC_LFSRUnmask_Bit0 ((uint32_t)0x00000000) /*!< Unmask DAC channel LFSR bit0 for noise wave generation */ 106 #define DAC_LFSRUnmask_Bits1_0 ((uint32_t)0x00000100) /*!< Unmask DAC channel LFSR bit[1:0] for noise wave generation */ 107 #define DAC_LFSRUnmask_Bits2_0 ((uint32_t)0x00000200) /*!< Unmask DAC channel LFSR bit[2:0] for noise wave generation */ 108 #define DAC_LFSRUnmask_Bits3_0 ((uint32_t)0x00000300) /*!< Unmask DAC channel LFSR bit[3:0] for noise wave generation */ 109 #define DAC_LFSRUnmask_Bits4_0 ((uint32_t)0x00000400) /*!< Unmask DAC channel LFSR bit[4:0] for noise wave generation */ 110 #define DAC_LFSRUnmask_Bits5_0 ((uint32_t)0x00000500) /*!< Unmask DAC channel LFSR bit[5:0] for noise wave generation */ 111 #define DAC_LFSRUnmask_Bits6_0 ((uint32_t)0x00000600) /*!< Unmask DAC channel LFSR bit[6:0] for noise wave generation */ 112 #define DAC_LFSRUnmask_Bits7_0 ((uint32_t)0x00000700) /*!< Unmask DAC channel LFSR bit[7:0] for noise wave generation */ 113 #define DAC_LFSRUnmask_Bits8_0 ((uint32_t)0x00000800) /*!< Unmask DAC channel LFSR bit[8:0] for noise wave generation */ 114 #define DAC_LFSRUnmask_Bits9_0 ((uint32_t)0x00000900) /*!< Unmask DAC channel LFSR bit[9:0] for noise wave generation */ 115 #define DAC_LFSRUnmask_Bits10_0 ((uint32_t)0x00000A00) /*!< Unmask DAC channel LFSR bit[10:0] for noise wave generation */ 116 #define DAC_LFSRUnmask_Bits11_0 ((uint32_t)0x00000B00) /*!< Unmask DAC channel LFSR bit[11:0] for noise wave generation */ 117 #define DAC_TriangleAmplitude_1 ((uint32_t)0x00000000) /*!< Select max triangle amplitude of 1 */ 118 #define DAC_TriangleAmplitude_3 ((uint32_t)0x00000100) /*!< Select max triangle amplitude of 3 */ 119 #define DAC_TriangleAmplitude_7 ((uint32_t)0x00000200) /*!< Select max triangle amplitude of 7 */ 120 #define DAC_TriangleAmplitude_15 ((uint32_t)0x00000300) /*!< Select max triangle amplitude of 15 */ 121 #define DAC_TriangleAmplitude_31 ((uint32_t)0x00000400) /*!< Select max triangle amplitude of 31 */ 122 #define DAC_TriangleAmplitude_63 ((uint32_t)0x00000500) /*!< Select max triangle amplitude of 63 */ 123 #define DAC_TriangleAmplitude_127 ((uint32_t)0x00000600) /*!< Select max triangle amplitude of 127 */ 124 #define DAC_TriangleAmplitude_255 ((uint32_t)0x00000700) /*!< Select max triangle amplitude of 255 */ 125 #define DAC_TriangleAmplitude_511 ((uint32_t)0x00000800) /*!< Select max triangle amplitude of 511 */ 126 #define DAC_TriangleAmplitude_1023 ((uint32_t)0x00000900) /*!< Select max triangle amplitude of 1023 */ 127 #define DAC_TriangleAmplitude_2047 ((uint32_t)0x00000A00) /*!< Select max triangle amplitude of 2047 */ 128 #define DAC_TriangleAmplitude_4095 ((uint32_t)0x00000B00) /*!< Select max triangle amplitude of 4095 */ 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 /** @defgroup DAC_output_buffer 159 * @{ 160 */ 161 162 #define DAC_OutputBuffer_Enable ((uint32_t)0x00000000) 163 #define DAC_OutputBuffer_Disable ((uint32_t)0x00000002) 164 #define IS_DAC_OUTPUT_BUFFER_STATE(STATE) (((STATE) == DAC_OutputBuffer_Enable) || \ 165 ((STATE) == DAC_OutputBuffer_Disable)) 166 /** 167 * @} 168 */ 169 170 /** @defgroup DAC_Channel_selection 171 * @{ 172 */ 173 174 #define DAC_Channel_1 ((uint32_t)0x00000000) 175 #define DAC_Channel_2 ((uint32_t)0x00000010) 176 #define IS_DAC_CHANNEL(CHANNEL) (((CHANNEL) == DAC_Channel_1) || \ 177 ((CHANNEL) == DAC_Channel_2)) 178 /** 179 * @} 180 */ 181 182 /** @defgroup DAC_data_alignment 183 * @{ 184 */ 185 186 #define DAC_Align_12b_R ((uint32_t)0x00000000) 187 #define DAC_Align_12b_L ((uint32_t)0x00000004) 188 #define DAC_Align_8b_R ((uint32_t)0x00000008) 189 #define IS_DAC_ALIGN(ALIGN) (((ALIGN) == DAC_Align_12b_R) || \ 190 ((ALIGN) == DAC_Align_12b_L) || \ 191 ((ALIGN) == DAC_Align_8b_R)) 192 /** 193 * @} 194 */ 195 196 /** @defgroup DAC_wave_generation 197 * @{ 198 */ 199 200 #define DAC_Wave_Noise ((uint32_t)0x00000040) 201 #define DAC_Wave_Triangle ((uint32_t)0x00000080) 202 #define IS_DAC_WAVE(WAVE) (((WAVE) == DAC_Wave_Noise) || \ 203 ((WAVE) == DAC_Wave_Triangle)) 204 /** 205 * @} 206 */ 207 208 /** @defgroup DAC_data 209 * @{ 210 */ 211 212 #define IS_DAC_DATA(DATA) ((DATA) <= 0xFFF0) 213 /** 214 * @} 215 */ 216 217 /** 218 * @} 219 */ 220 221 /** @defgroup DAC_Exported_Macros 222 * @{ 223 */ 224 225 /** 226 * @} 227 */ 228 229 /** @defgroup DAC_Exported_Functions 230 * @{ 231 */ 232 233 void DAC_DeInit(void); 234 void DAC_Init(uint32_t DAC_Channel, DAC_InitTypeDef* DAC_InitStruct); 235 void DAC_StructInit(DAC_InitTypeDef* DAC_InitStruct); 236 void DAC_Cmd(uint32_t DAC_Channel, FunctionalState NewState); 237 void DAC_DMACmd(uint32_t DAC_Channel, FunctionalState NewState); 238 void DAC_SoftwareTriggerCmd(uint32_t DAC_Channel, FunctionalState NewState); 239 void DAC_DualSoftwareTriggerCmd(FunctionalState NewState); 240 void DAC_WaveGenerationCmd(uint32_t DAC_Channel, uint32_t DAC_Wave, FunctionalState NewState); 241 void DAC_SetChannel1Data(uint32_t DAC_Align, uint16_t Data); 242 void DAC_SetChannel2Data(uint32_t DAC_Align, uint16_t Data); 243 void DAC_SetDualChannelData(uint32_t DAC_Align, uint16_t Data2, uint16_t Data1); 244 uint16_t DAC_GetDataOutputValue(uint32_t DAC_Channel); 245 246 #ifdef __cplusplus 247 } 248 #endif 249 250 #endif /*__AIR32F10x_DAC_H */ 251 /** 252 * @} 253 */ 254 255 /** 256 * @} 257 */ 258 259 /** 260 * @} 261 */ 262 263