2 ******************************************************************************
\r
3 * @file stm32l1xx_dac.h
\r
4 * @author MCD Application Team
\r
6 * @date 05-March-2012
\r
7 * @brief This file contains all the functions prototypes for the DAC firmware
\r
9 ******************************************************************************
\r
12 * <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
\r
14 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
\r
15 * You may not use this file except in compliance with the License.
\r
16 * You may obtain a copy of the License at:
\r
18 * http://www.st.com/software_license_agreement_liberty_v2
\r
20 * Unless required by applicable law or agreed to in writing, software
\r
21 * distributed under the License is distributed on an "AS IS" BASIS,
\r
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
23 * See the License for the specific language governing permissions and
\r
24 * limitations under the License.
\r
26 ******************************************************************************
\r
29 /* Define to prevent recursive inclusion -------------------------------------*/
\r
30 #ifndef __STM32L1xx_DAC_H
\r
31 #define __STM32L1xx_DAC_H
\r
37 /* Includes ------------------------------------------------------------------*/
\r
38 #include "stm32l1xx.h"
\r
40 /** @addtogroup STM32L1xx_StdPeriph_Driver
\r
48 /* Exported types ------------------------------------------------------------*/
\r
51 * @brief DAC Init structure definition
\r
56 uint32_t DAC_Trigger; /*!< Specifies the external trigger for the selected DAC channel.
\r
57 This parameter can be a value of @ref DAC_trigger_selection */
\r
59 uint32_t DAC_WaveGeneration; /*!< Specifies whether DAC channel noise waves or triangle waves
\r
60 are generated, or whether no wave is generated.
\r
61 This parameter can be a value of @ref DAC_wave_generation */
\r
63 uint32_t DAC_LFSRUnmask_TriangleAmplitude; /*!< Specifies the LFSR mask for noise wave generation or
\r
64 the maximum amplitude triangle generation for the DAC channel.
\r
65 This parameter can be a value of @ref DAC_lfsrunmask_triangleamplitude */
\r
67 uint32_t DAC_OutputBuffer; /*!< Specifies whether the DAC channel output buffer is enabled or disabled.
\r
68 This parameter can be a value of @ref DAC_output_buffer */
\r
71 /* Exported constants --------------------------------------------------------*/
\r
73 /** @defgroup DAC_Exported_Constants
\r
77 /** @defgroup DAC_trigger_selection
\r
81 #define DAC_Trigger_None ((uint32_t)0x00000000) /*!< Conversion is automatic once the DAC1_DHRxxxx register
\r
82 has been loaded, and not by external trigger */
\r
83 #define DAC_Trigger_T6_TRGO ((uint32_t)0x00000004) /*!< TIM6 TRGO selected as external conversion trigger for DAC channel */
\r
84 #define DAC_Trigger_T7_TRGO ((uint32_t)0x00000014) /*!< TIM7 TRGO selected as external conversion trigger for DAC channel */
\r
85 #define DAC_Trigger_T9_TRGO ((uint32_t)0x0000001C) /*!< TIM9 TRGO selected as external conversion trigger for DAC channel */
\r
86 #define DAC_Trigger_T2_TRGO ((uint32_t)0x00000024) /*!< TIM2 TRGO selected as external conversion trigger for DAC channel */
\r
87 #define DAC_Trigger_T4_TRGO ((uint32_t)0x0000002C) /*!< TIM4 TRGO selected as external conversion trigger for DAC channel */
\r
88 #define DAC_Trigger_Ext_IT9 ((uint32_t)0x00000034) /*!< EXTI Line9 event selected as external conversion trigger for DAC channel */
\r
89 #define DAC_Trigger_Software ((uint32_t)0x0000003C) /*!< Conversion started by software trigger for DAC channel */
\r
91 #define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_Trigger_None) || \
\r
92 ((TRIGGER) == DAC_Trigger_T6_TRGO) || \
\r
93 ((TRIGGER) == DAC_Trigger_T7_TRGO) || \
\r
94 ((TRIGGER) == DAC_Trigger_T9_TRGO) || \
\r
95 ((TRIGGER) == DAC_Trigger_T2_TRGO) || \
\r
96 ((TRIGGER) == DAC_Trigger_T4_TRGO) || \
\r
97 ((TRIGGER) == DAC_Trigger_Ext_IT9) || \
\r
98 ((TRIGGER) == DAC_Trigger_Software))
\r
104 /** @defgroup DAC_wave_generation
\r
108 #define DAC_WaveGeneration_None ((uint32_t)0x00000000)
\r
109 #define DAC_WaveGeneration_Noise ((uint32_t)0x00000040)
\r
110 #define DAC_WaveGeneration_Triangle ((uint32_t)0x00000080)
\r
111 #define IS_DAC_GENERATE_WAVE(WAVE) (((WAVE) == DAC_WaveGeneration_None) || \
\r
112 ((WAVE) == DAC_WaveGeneration_Noise) || \
\r
113 ((WAVE) == DAC_WaveGeneration_Triangle))
\r
118 /** @defgroup DAC_lfsrunmask_triangleamplitude
\r
122 #define DAC_LFSRUnmask_Bit0 ((uint32_t)0x00000000) /*!< Unmask DAC channel LFSR bit0 for noise wave generation */
\r
123 #define DAC_LFSRUnmask_Bits1_0 ((uint32_t)0x00000100) /*!< Unmask DAC channel LFSR bit[1:0] for noise wave generation */
\r
124 #define DAC_LFSRUnmask_Bits2_0 ((uint32_t)0x00000200) /*!< Unmask DAC channel LFSR bit[2:0] for noise wave generation */
\r
125 #define DAC_LFSRUnmask_Bits3_0 ((uint32_t)0x00000300) /*!< Unmask DAC channel LFSR bit[3:0] for noise wave generation */
\r
126 #define DAC_LFSRUnmask_Bits4_0 ((uint32_t)0x00000400) /*!< Unmask DAC channel LFSR bit[4:0] for noise wave generation */
\r
127 #define DAC_LFSRUnmask_Bits5_0 ((uint32_t)0x00000500) /*!< Unmask DAC channel LFSR bit[5:0] for noise wave generation */
\r
128 #define DAC_LFSRUnmask_Bits6_0 ((uint32_t)0x00000600) /*!< Unmask DAC channel LFSR bit[6:0] for noise wave generation */
\r
129 #define DAC_LFSRUnmask_Bits7_0 ((uint32_t)0x00000700) /*!< Unmask DAC channel LFSR bit[7:0] for noise wave generation */
\r
130 #define DAC_LFSRUnmask_Bits8_0 ((uint32_t)0x00000800) /*!< Unmask DAC channel LFSR bit[8:0] for noise wave generation */
\r
131 #define DAC_LFSRUnmask_Bits9_0 ((uint32_t)0x00000900) /*!< Unmask DAC channel LFSR bit[9:0] for noise wave generation */
\r
132 #define DAC_LFSRUnmask_Bits10_0 ((uint32_t)0x00000A00) /*!< Unmask DAC channel LFSR bit[10:0] for noise wave generation */
\r
133 #define DAC_LFSRUnmask_Bits11_0 ((uint32_t)0x00000B00) /*!< Unmask DAC channel LFSR bit[11:0] for noise wave generation */
\r
134 #define DAC_TriangleAmplitude_1 ((uint32_t)0x00000000) /*!< Select max triangle amplitude of 1 */
\r
135 #define DAC_TriangleAmplitude_3 ((uint32_t)0x00000100) /*!< Select max triangle amplitude of 3 */
\r
136 #define DAC_TriangleAmplitude_7 ((uint32_t)0x00000200) /*!< Select max triangle amplitude of 7 */
\r
137 #define DAC_TriangleAmplitude_15 ((uint32_t)0x00000300) /*!< Select max triangle amplitude of 15 */
\r
138 #define DAC_TriangleAmplitude_31 ((uint32_t)0x00000400) /*!< Select max triangle amplitude of 31 */
\r
139 #define DAC_TriangleAmplitude_63 ((uint32_t)0x00000500) /*!< Select max triangle amplitude of 63 */
\r
140 #define DAC_TriangleAmplitude_127 ((uint32_t)0x00000600) /*!< Select max triangle amplitude of 127 */
\r
141 #define DAC_TriangleAmplitude_255 ((uint32_t)0x00000700) /*!< Select max triangle amplitude of 255 */
\r
142 #define DAC_TriangleAmplitude_511 ((uint32_t)0x00000800) /*!< Select max triangle amplitude of 511 */
\r
143 #define DAC_TriangleAmplitude_1023 ((uint32_t)0x00000900) /*!< Select max triangle amplitude of 1023 */
\r
144 #define DAC_TriangleAmplitude_2047 ((uint32_t)0x00000A00) /*!< Select max triangle amplitude of 2047 */
\r
145 #define DAC_TriangleAmplitude_4095 ((uint32_t)0x00000B00) /*!< Select max triangle amplitude of 4095 */
\r
147 #define IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(VALUE) (((VALUE) == DAC_LFSRUnmask_Bit0) || \
\r
148 ((VALUE) == DAC_LFSRUnmask_Bits1_0) || \
\r
149 ((VALUE) == DAC_LFSRUnmask_Bits2_0) || \
\r
150 ((VALUE) == DAC_LFSRUnmask_Bits3_0) || \
\r
151 ((VALUE) == DAC_LFSRUnmask_Bits4_0) || \
\r
152 ((VALUE) == DAC_LFSRUnmask_Bits5_0) || \
\r
153 ((VALUE) == DAC_LFSRUnmask_Bits6_0) || \
\r
154 ((VALUE) == DAC_LFSRUnmask_Bits7_0) || \
\r
155 ((VALUE) == DAC_LFSRUnmask_Bits8_0) || \
\r
156 ((VALUE) == DAC_LFSRUnmask_Bits9_0) || \
\r
157 ((VALUE) == DAC_LFSRUnmask_Bits10_0) || \
\r
158 ((VALUE) == DAC_LFSRUnmask_Bits11_0) || \
\r
159 ((VALUE) == DAC_TriangleAmplitude_1) || \
\r
160 ((VALUE) == DAC_TriangleAmplitude_3) || \
\r
161 ((VALUE) == DAC_TriangleAmplitude_7) || \
\r
162 ((VALUE) == DAC_TriangleAmplitude_15) || \
\r
163 ((VALUE) == DAC_TriangleAmplitude_31) || \
\r
164 ((VALUE) == DAC_TriangleAmplitude_63) || \
\r
165 ((VALUE) == DAC_TriangleAmplitude_127) || \
\r
166 ((VALUE) == DAC_TriangleAmplitude_255) || \
\r
167 ((VALUE) == DAC_TriangleAmplitude_511) || \
\r
168 ((VALUE) == DAC_TriangleAmplitude_1023) || \
\r
169 ((VALUE) == DAC_TriangleAmplitude_2047) || \
\r
170 ((VALUE) == DAC_TriangleAmplitude_4095))
\r
175 /** @defgroup DAC_output_buffer
\r
179 #define DAC_OutputBuffer_Enable ((uint32_t)0x00000000)
\r
180 #define DAC_OutputBuffer_Disable ((uint32_t)0x00000002)
\r
181 #define IS_DAC_OUTPUT_BUFFER_STATE(STATE) (((STATE) == DAC_OutputBuffer_Enable) || \
\r
182 ((STATE) == DAC_OutputBuffer_Disable))
\r
187 /** @defgroup DAC_Channel_selection
\r
191 #define DAC_Channel_1 ((uint32_t)0x00000000)
\r
192 #define DAC_Channel_2 ((uint32_t)0x00000010)
\r
193 #define IS_DAC_CHANNEL(CHANNEL) (((CHANNEL) == DAC_Channel_1) || \
\r
194 ((CHANNEL) == DAC_Channel_2))
\r
199 /** @defgroup DAC_data_alignment
\r
203 #define DAC_Align_12b_R ((uint32_t)0x00000000)
\r
204 #define DAC_Align_12b_L ((uint32_t)0x00000004)
\r
205 #define DAC_Align_8b_R ((uint32_t)0x00000008)
\r
206 #define IS_DAC_ALIGN(ALIGN) (((ALIGN) == DAC_Align_12b_R) || \
\r
207 ((ALIGN) == DAC_Align_12b_L) || \
\r
208 ((ALIGN) == DAC_Align_8b_R))
\r
213 /** @defgroup DAC_wave_generation
\r
217 #define DAC_Wave_Noise ((uint32_t)0x00000040)
\r
218 #define DAC_Wave_Triangle ((uint32_t)0x00000080)
\r
219 #define IS_DAC_WAVE(WAVE) (((WAVE) == DAC_Wave_Noise) || \
\r
220 ((WAVE) == DAC_Wave_Triangle))
\r
225 /** @defgroup DAC_data
\r
229 #define IS_DAC_DATA(DATA) ((DATA) <= 0xFFF0)
\r
235 /** @defgroup DAC_interrupts_definition
\r
239 #define DAC_IT_DMAUDR ((uint32_t)0x00002000)
\r
240 #define IS_DAC_IT(IT) (((IT) == DAC_IT_DMAUDR))
\r
247 /** @defgroup DAC_flags_definition
\r
251 #define DAC_FLAG_DMAUDR ((uint32_t)0x00002000)
\r
253 #define IS_DAC_FLAG(FLAG) (((FLAG) == DAC_FLAG_DMAUDR))
\r
263 /* Exported macro ------------------------------------------------------------*/
\r
264 /* Exported functions ------------------------------------------------------- */
\r
266 /* Function used to set the DAC configuration to the default reset state *****/
\r
267 void DAC_DeInit(void);
\r
269 /* DAC channels configuration: trigger, output buffer, data format functions */
\r
270 void DAC_Init(uint32_t DAC_Channel, DAC_InitTypeDef* DAC_InitStruct);
\r
271 void DAC_StructInit(DAC_InitTypeDef* DAC_InitStruct);
\r
272 void DAC_Cmd(uint32_t DAC_Channel, FunctionalState NewState);
\r
273 void DAC_SoftwareTriggerCmd(uint32_t DAC_Channel, FunctionalState NewState);
\r
274 void DAC_DualSoftwareTriggerCmd(FunctionalState NewState);
\r
275 void DAC_WaveGenerationCmd(uint32_t DAC_Channel, uint32_t DAC_Wave, FunctionalState NewState);
\r
276 void DAC_SetChannel1Data(uint32_t DAC_Align, uint16_t Data);
\r
277 void DAC_SetChannel2Data(uint32_t DAC_Align, uint16_t Data);
\r
278 void DAC_SetDualChannelData(uint32_t DAC_Align, uint16_t Data2, uint16_t Data1);
\r
279 uint16_t DAC_GetDataOutputValue(uint32_t DAC_Channel);
\r
281 /* DMA management functions ***************************************************/
\r
282 void DAC_DMACmd(uint32_t DAC_Channel, FunctionalState NewState);
\r
284 /* Interrupts and flags management functions **********************************/
\r
285 void DAC_ITConfig(uint32_t DAC_Channel, uint32_t DAC_IT, FunctionalState NewState);
\r
286 FlagStatus DAC_GetFlagStatus(uint32_t DAC_Channel, uint32_t DAC_FLAG);
\r
287 void DAC_ClearFlag(uint32_t DAC_Channel, uint32_t DAC_FLAG);
\r
288 ITStatus DAC_GetITStatus(uint32_t DAC_Channel, uint32_t DAC_IT);
\r
289 void DAC_ClearITPendingBit(uint32_t DAC_Channel, uint32_t DAC_IT);
\r
295 #endif /*__STM32L1xx_DAC_H */
\r
305 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r