1 /**
2 ******************************************************************************
3 * @file    HAL_dac.h
4 * @author  AE Team
5 * @version V1.0.0
6 * @date    28/7/2017
7 * @brief   This file contains all the functions prototypes for the DAC firmware
8 *          library.
9 ******************************************************************************
10 * @copy
11 *
12 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
13 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
14 * TIME. AS A RESULT, MindMotion SHALL NOT BE HELD LIABLE FOR ANY
15 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
16 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
17 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 *
19 * <h2><center>&copy; COPYRIGHT 2017 MindMotion</center></h2>
20 */
21 
22 /* Define to prevent recursive inclusion -------------------------------------*/
23 #ifndef __HAL_DAC_H
24 #define __HAL_DAC_H
25 
26 /* Includes ------------------------------------------------------------------*/
27 #include "HAL_device.h"
28 
29 /** @addtogroup StdPeriph_Driver
30 * @{
31 */
32 
33 /** @addtogroup DAC
34 * @{
35 */
36 
37 /** @defgroup DAC_Exported_Types
38 * @{
39 */
40 
41 /**
42 * @brief  DAC Init structure definition
43 */
44 
45 typedef struct
46 {
47   uint32_t DAC_Trigger;
48   uint32_t DAC_WaveGeneration;
49   uint32_t DAC_LFSRUnmask_TriangleAmplitude;
50   uint32_t DAC_OutputBuffer;
51 }DAC_InitTypeDef;
52 
53 /**
54 * @}
55 */
56 
57 /** @defgroup DAC_Exported_Constants
58 * @{
59 */
60 
61 /** @defgroup DAC_trigger_selection
62 * @{
63 */
64 
65 #define DAC_Trigger_None                   ((uint32_t)0x00000000)
66 #define DAC_Trigger_T1_TRGO                ((uint32_t)0x00000004)
67 #define DAC_Trigger_T3_TRGO                ((uint32_t)0x0000000C)
68 #define DAC_Trigger_T2_TRGO                ((uint32_t)0x00000024)
69 #define DAC_Trigger_T4_TRGO                ((uint32_t)0x0000002C)
70 #define DAC_Trigger_Ext_IT9                ((uint32_t)0x00000034)
71 #define DAC_Trigger_Software               ((uint32_t)0x0000003C)
72 
73 #define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_Trigger_None) || \
74 ((TRIGGER) == DAC_Trigger_T1_TRGO) || \
75   ((TRIGGER) == DAC_Trigger_T3_TRGO) || \
76     ((TRIGGER) == DAC_Trigger_T2_TRGO) || \
77       ((TRIGGER) == DAC_Trigger_T4_TRGO) || \
78         ((TRIGGER) == DAC_Trigger_Ext_IT9) || \
79           ((TRIGGER) == DAC_Trigger_Software))
80 
81 /**
82 * @}
83 */
84 
85 /** @defgroup DAC_wave_generation
86 * @{
87 */
88 
89 #define DAC_WaveGeneration_None            ((uint32_t)0x00000000)
90 #define DAC_WaveGeneration_Noise           ((uint32_t)0x00000040)
91 #define DAC_WaveGeneration_Triangle        ((uint32_t)0x00000080)
92 #define IS_DAC_GENERATE_WAVE(WAVE) (((WAVE) == DAC_WaveGeneration_None) || \
93 ((WAVE) == DAC_WaveGeneration_Noise) || \
94   ((WAVE) == DAC_WaveGeneration_Triangle))
95 /**
96 * @}
97 */
98 
99 /** @defgroup DAC_noise_wave_generation_mask_triangle_wave_generation_max_amplitude
100 * @{
101 */
102 
103 #define DAC_LFSRUnmask_Bit0                ((uint32_t)0x00000000)
104 #define DAC_LFSRUnmask_Bits1_0             ((uint32_t)0x00000100)
105 #define DAC_LFSRUnmask_Bits2_0             ((uint32_t)0x00000200)
106 #define DAC_LFSRUnmask_Bits3_0             ((uint32_t)0x00000300)
107 #define DAC_LFSRUnmask_Bits4_0             ((uint32_t)0x00000400)
108 #define DAC_LFSRUnmask_Bits5_0             ((uint32_t)0x00000500)
109 #define DAC_LFSRUnmask_Bits6_0             ((uint32_t)0x00000600)
110 #define DAC_LFSRUnmask_Bits7_0             ((uint32_t)0x00000700)
111 #define DAC_LFSRUnmask_Bits8_0             ((uint32_t)0x00000800)
112 #define DAC_LFSRUnmask_Bits9_0             ((uint32_t)0x00000900)
113 #define DAC_LFSRUnmask_Bits10_0            ((uint32_t)0x00000A00)
114 #define DAC_LFSRUnmask_Bits11_0            ((uint32_t)0x00000B00)
115 #define DAC_TriangleAmplitude_1            ((uint32_t)0x00000000)
116 #define DAC_TriangleAmplitude_3            ((uint32_t)0x00000100)
117 #define DAC_TriangleAmplitude_7            ((uint32_t)0x00000200)
118 #define DAC_TriangleAmplitude_15           ((uint32_t)0x00000300)
119 #define DAC_TriangleAmplitude_31           ((uint32_t)0x00000400)
120 #define DAC_TriangleAmplitude_63           ((uint32_t)0x00000500)
121 #define DAC_TriangleAmplitude_127          ((uint32_t)0x00000600)
122 #define DAC_TriangleAmplitude_255          ((uint32_t)0x00000700)
123 #define DAC_TriangleAmplitude_511          ((uint32_t)0x00000800)
124 #define DAC_TriangleAmplitude_1023         ((uint32_t)0x00000900)
125 #define DAC_TriangleAmplitude_2047         ((uint32_t)0x00000A00)
126 #define DAC_TriangleAmplitude_4095         ((uint32_t)0x00000B00)
127 
128 #define IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(VALUE) (((VALUE) == DAC_LFSRUnmask_Bit0) || \
129 ((VALUE) == DAC_LFSRUnmask_Bits1_0) || \
130   ((VALUE) == DAC_LFSRUnmask_Bits2_0) || \
131     ((VALUE) == DAC_LFSRUnmask_Bits3_0) || \
132       ((VALUE) == DAC_LFSRUnmask_Bits4_0) || \
133         ((VALUE) == DAC_LFSRUnmask_Bits5_0) || \
134           ((VALUE) == DAC_LFSRUnmask_Bits6_0) || \
135             ((VALUE) == DAC_LFSRUnmask_Bits7_0) || \
136               ((VALUE) == DAC_LFSRUnmask_Bits8_0) || \
137                 ((VALUE) == DAC_LFSRUnmask_Bits9_0) || \
138                   ((VALUE) == DAC_LFSRUnmask_Bits10_0) || \
139                     ((VALUE) == DAC_LFSRUnmask_Bits11_0) || \
140                       ((VALUE) == DAC_TriangleAmplitude_1) || \
141                         ((VALUE) == DAC_TriangleAmplitude_3) || \
142                           ((VALUE) == DAC_TriangleAmplitude_7) || \
143                             ((VALUE) == DAC_TriangleAmplitude_15) || \
144                               ((VALUE) == DAC_TriangleAmplitude_31) || \
145                                 ((VALUE) == DAC_TriangleAmplitude_63) || \
146                                   ((VALUE) == DAC_TriangleAmplitude_127) || \
147                                     ((VALUE) == DAC_TriangleAmplitude_255) || \
148                                       ((VALUE) == DAC_TriangleAmplitude_511) || \
149                                         ((VALUE) == DAC_TriangleAmplitude_1023) || \
150                                           ((VALUE) == DAC_TriangleAmplitude_2047) || \
151                                             ((VALUE) == DAC_TriangleAmplitude_4095))
152 /**
153 * @}
154 */
155 
156 /** @defgroup DAC_output_buffer
157 * @{
158 */
159 
160 #define DAC_OutputBuffer_Enable            ((uint32_t)0x00000000)
161 #define DAC_OutputBuffer_Disable           ((uint32_t)0x00000002)
162 #define IS_DAC_OUTPUT_BUFFER_STATE(STATE) (((STATE) == DAC_OutputBuffer_Enable) || \
163 ((STATE) == DAC_OutputBuffer_Disable))
164 /**
165 * @}
166 */
167 
168 /** @defgroup DAC_Channel_selection
169 * @{
170 */
171 
172 #define DAC_Channel_1                      ((uint32_t)0x00000000)
173 #define DAC_Channel_2                      ((uint32_t)0x00000010)
174 #define IS_DAC_CHANNEL(CHANNEL) (((CHANNEL) == DAC_Channel_1) || \
175 ((CHANNEL) == DAC_Channel_2))
176 /**
177 * @}
178 */
179 
180 /** @defgroup DAC_data_alignement
181 * @{
182 */
183 
184 #define DAC_Align_12b_R                    ((uint32_t)0x00000000)
185 #define DAC_Align_12b_L                    ((uint32_t)0x00000004)
186 #define DAC_Align_8b_R                     ((uint32_t)0x00000008)
187 #define IS_DAC_ALIGN(ALIGN) (((ALIGN) == DAC_Align_12b_R) || \
188 ((ALIGN) == DAC_Align_12b_L) || \
189   ((ALIGN) == DAC_Align_8b_R))
190 /**
191 * @}
192 */
193 
194 /** @defgroup DAC_wave_generation
195 * @{
196 */
197 
198 #define DAC_Wave_Noise                     ((uint32_t)0x00000040)
199 #define DAC_Wave_Triangle                  ((uint32_t)0x00000080)
200 #define IS_DAC_WAVE(WAVE) (((WAVE) == DAC_Wave_Noise) || \
201 ((WAVE) == DAC_Wave_Triangle))
202 /**
203 * @}
204 */
205 
206 /** @defgroup DAC_data
207 * @{
208 */
209 
210 #define IS_DAC_DATA(DATA) ((DATA) <= 0xFFF0)
211 /**
212 * @}
213 */
214 
215 /**
216 * @}
217 */
218 
219 /** @defgroup DAC_Exported_Macros
220 * @{
221 */
222 
223 /**
224 * @}
225 */
226 
227 /** @defgroup DAC_Exported_Functions
228 * @{
229 */
230 
231 void DAC_DeInit(void);
232 void DAC_Init(uint32_t DAC_Channel, DAC_InitTypeDef* DAC_InitStruct);
233 void DAC_StructInit(DAC_InitTypeDef* DAC_InitStruct);
234 void DAC_Cmd(uint32_t DAC_Channel, FunctionalState NewState);
235 void DAC_DMACmd(uint32_t DAC_Channel, FunctionalState NewState);
236 void DAC_SoftwareTriggerCmd(uint32_t DAC_Channel, FunctionalState NewState);
237 void DAC_DualSoftwareTriggerCmd(FunctionalState NewState);
238 void DAC_WaveGenerationCmd(uint32_t DAC_Channel, uint32_t DAC_Wave, FunctionalState NewState);
239 void DAC_SetChannel1Data(uint32_t DAC_Align, uint16_t Data);
240 void DAC_SetChannel2Data(uint32_t DAC_Align, uint16_t Data);
241 void DAC_SetDualChannelData(uint32_t DAC_Align, uint16_t Data2, uint16_t Data1);
242 uint16_t DAC_GetDataOutputValue(uint32_t DAC_Channel);
243 
244 #endif /*__HAL_DAC_H */
245 /**
246 * @}
247 */
248 
249 /**
250 * @}
251 */
252 
253 /**
254 * @}
255 */
256 
257 /*-------------------------(C) COPYRIGHT 2017 MindMotion ----------------------*/
258