before merging master
[inav.git] / lib / main / AT32F43x / Drivers / AT32F43x_StdPeriph_Driver / src / at32f435_437_dac.c
blob3d90ff4d5954bfb75b9e4e482a9768cedef3d5bf
1 /**
2 **************************************************************************
3 * @file at32f435_437_dac.c
4 * @version v2.1.0
5 * @date 2022-08-16
6 * @brief contains all the functions for the dac firmware library
7 **************************************************************************
8 * Copyright notice & Disclaimer
10 * The software Board Support Package (BSP) that is made available to
11 * download from Artery official website is the copyrighted work of Artery.
12 * Artery authorizes customers to use, copy, and distribute the BSP
13 * software and its related documentation for the purpose of design and
14 * development in conjunction with Artery microcontrollers. Use of the
15 * software is governed by this copyright notice and the following disclaimer.
17 * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
18 * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
19 * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
20 * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
21 * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
24 **************************************************************************
27 #include "at32f435_437_conf.h"
29 /** @addtogroup AT32F435_437_periph_driver
30 * @{
33 /** @defgroup DAC
34 * @brief DAC driver modules
35 * @{
38 #ifdef DAC_MODULE_ENABLED
40 /** @defgroup DAC_private_functions
41 * @{
44 /**
45 * @brief dac reset
46 * @param none
47 * @retval none
49 void dac_reset(void)
51 crm_periph_reset(CRM_DAC_PERIPH_RESET, TRUE);
52 crm_periph_reset(CRM_DAC_PERIPH_RESET, FALSE);
55 /**
56 * @brief enable or disable dac
57 * @param dac_select
58 * this parameter can be one of the following values:
59 * - DAC1_SELECT
60 * - DAC2_SELECT
61 * @param new_state (TRUE or FALSE)
62 * @retval none
64 void dac_enable(dac_select_type dac_select, confirm_state new_state)
66 switch(dac_select)
68 case DAC1_SELECT:
69 DAC->ctrl_bit.d1en = new_state;
70 break;
71 case DAC2_SELECT:
72 DAC->ctrl_bit.d2en = new_state;
73 break;
74 default:
75 break;
79 /**
80 * @brief enable or disable dac output buffer
81 * @param dac_select
82 * this parameter can be one of the following values:
83 * - DAC1_SELECT
84 * - DAC2_SELECT
85 * @param new_state (TRUE or FALSE)
86 * @retval none
88 void dac_output_buffer_enable(dac_select_type dac_select, confirm_state new_state)
90 new_state = (confirm_state)!new_state;
91 switch(dac_select)
93 case DAC1_SELECT:
94 DAC->ctrl_bit.d1obdis = new_state;
95 break;
96 case DAC2_SELECT:
97 DAC->ctrl_bit.d2obdis = new_state;
98 break;
99 default:
100 break;
105 * @brief enable or disable dac trigger
106 * @param dac_select
107 * this parameter can be one of the following values:
108 * - DAC1_SELECT
109 * - DAC2_SELECT
110 * @param new_state (TRUE or FALSE)
111 * @retval none
113 void dac_trigger_enable(dac_select_type dac_select, confirm_state new_state)
115 switch(dac_select)
117 case DAC1_SELECT:
118 DAC->ctrl_bit.d1trgen = new_state;
119 break;
120 case DAC2_SELECT:
121 DAC->ctrl_bit.d2trgen = new_state;
122 break;
123 default:
124 break;
129 * @brief select dac trigger
130 * @param dac_select
131 * this parameter can be one of the following values:
132 * - DAC1_SELECT
133 * - DAC2_SELECT
134 * @param dac_trigger_source
135 * this parameter can be one of the following values:
136 * - DAC_TMR6_TRGOUT_EVENT
137 * - DAC_TMR8_TRGOUT_EVENT
138 * - DAC_TMR7_TRGOUT_EVENT
139 * - DAC_TMR5_TRGOUT_EVENT
140 * - DAC_TMR2_TRGOUT_EVENT
141 * - DAC_TMR4_TRGOUT_EVENT
142 * - DAC_EXTERNAL_INTERRUPT_LINE_9
143 * - DAC_SOFTWARE_TRIGGER
144 * @retval none
146 void dac_trigger_select(dac_select_type dac_select, dac_trigger_type dac_trigger_source)
148 switch(dac_select)
150 case DAC1_SELECT:
151 DAC->ctrl_bit.d1trgsel = dac_trigger_source;
152 break;
153 case DAC2_SELECT:
154 DAC->ctrl_bit.d2trgsel = dac_trigger_source;
155 break;
156 default:
157 break;
162 * @brief generate dac software trigger
163 * @param dac_select
164 * this parameter can be one of the following values:
165 * - DAC1_SELECT
166 * - DAC2_SELECT
167 * @retval none
169 void dac_software_trigger_generate(dac_select_type dac_select)
171 switch(dac_select)
173 case DAC1_SELECT:
174 DAC->swtrg_bit.d1swtrg = TRUE;
175 break;
176 case DAC2_SELECT:
177 DAC->swtrg_bit.d2swtrg = TRUE;
178 break;
179 default:
180 break;
185 * @brief generate dac dual software trigger synchronously
186 * @param none
187 * @retval none
189 void dac_dual_software_trigger_generate(void)
191 DAC->swtrg |= 0x03;
195 * @brief generate dac wave
196 * @param dac_select
197 * this parameter can be one of the following values:
198 * - DAC1_SELECT
199 * - DAC2_SELECT
200 * @param dac_wave
201 * this parameter can be one of the following values:
202 * - DAC_WAVE_GENERATE_NONE
203 * - DAC_WAVE_GENERATE_NOISE
204 * - DAC_WAVE_GENERATE_TRIANGLE
205 * @retval none
207 void dac_wave_generate(dac_select_type dac_select, dac_wave_type dac_wave)
209 switch(dac_select)
211 case DAC1_SELECT:
212 DAC->ctrl_bit.d1nm = dac_wave;
213 break;
214 case DAC2_SELECT:
215 DAC->ctrl_bit.d2nm = dac_wave;
216 break;
217 default:
218 break;
223 * @brief select dac mask amplitude
224 * @param dac_select
225 * this parameter can be one of the following values:
226 * - DAC1_SELECT
227 * - DAC2_SELECT
228 * @param dac_mask_amplitude
229 * this parameter can be one of the following values:
230 * - DAC_LSFR_BIT0_AMPLITUDE_1
231 * - DAC_LSFR_BIT10_AMPLITUDE_3
232 * - DAC_LSFR_BIT20_AMPLITUDE_7
233 * - DAC_LSFR_BIT30_AMPLITUDE_15
234 * - DAC_LSFR_BIT40_AMPLITUDE_31
235 * - DAC_LSFR_BIT50_AMPLITUDE_63
236 * - DAC_LSFR_BIT60_AMPLITUDE_127
237 * - DAC_LSFR_BIT70_AMPLITUDE_255
238 * - DAC_LSFR_BIT80_AMPLITUDE_511
239 * - DAC_LSFR_BIT90_AMPLITUDE_1023
240 * - DAC_LSFR_BITA0_AMPLITUDE_2047
241 * - DAC_LSFR_BITB0_AMPLITUDE_4095
242 * @retval none
244 void dac_mask_amplitude_select(dac_select_type dac_select, dac_mask_amplitude_type dac_mask_amplitude)
246 switch(dac_select)
248 case DAC1_SELECT:
249 DAC->ctrl_bit.d1nbsel = dac_mask_amplitude;
250 break;
251 case DAC2_SELECT:
252 DAC->ctrl_bit.d2nbsel = dac_mask_amplitude;
253 break;
254 default:
255 break;
260 * @brief enable or disable dac dma
261 * @param dac_select
262 * this parameter can be one of the following values:
263 * - DAC1_SELECT
264 * - DAC2_SELECT
265 * @param new_state (TRUE or FALSE)
266 * @retval none
268 void dac_dma_enable(dac_select_type dac_select, confirm_state new_state)
270 switch(dac_select)
272 case DAC1_SELECT:
273 DAC->ctrl_bit.d1dmaen = new_state;
274 break;
275 case DAC2_SELECT:
276 DAC->ctrl_bit.d2dmaen = new_state;
277 break;
278 default:
279 break;
284 * @brief get dac data output
285 * @param dac_select
286 * this parameter can be one of the following values:
287 * - DAC1_SELECT
288 * - DAC2_SELECT
289 * @retval dac channel data output
291 uint16_t dac_data_output_get(dac_select_type dac_select)
293 uint16_t data_output =0;
294 switch(dac_select)
296 case DAC1_SELECT:
297 data_output = DAC->d1odt_bit.d1odt;
298 break;
299 case DAC2_SELECT:
300 data_output = DAC->d2odt_bit.d2odt;
301 break;
302 default:
303 break;
305 return data_output;
309 * @brief set dac1 data
310 * @param dac1_aligned
311 * this parameter can be one of the following values:
312 * DAC1_12BIT_RIGHT
313 * DAC1_12BIT_LEFT
314 * DAC1_8BIT_RIGHT
315 * @param dac1_data :indecate from selected data holding register
316 * @retval none
318 void dac_1_data_set(dac1_aligned_data_type dac1_aligned, uint16_t dac1_data)
320 *(__IO uint32_t *) dac1_aligned = dac1_data;
324 * @brief set dac2 data
325 * @param dac2_aligned
326 * this parameter can be one of the following values:
327 * DAC2_12BIT_RIGHT
328 * DAC2_12BIT_LEFT
329 * DAC2_8BIT_RIGHT
330 * @param dac2_data :indecate from selected data holding register
331 * @retval none
333 void dac_2_data_set(dac2_aligned_data_type dac2_aligned, uint16_t dac2_data)
335 *(__IO uint32_t *) dac2_aligned = dac2_data;
339 * @brief set dac dual data
340 * @param dac_dual
341 * this parameter can be one of the following values:
342 * DAC_DUAL_12BIT_RIGHT
343 * DAC_DUAL_12BIT_LEFT
344 * DAC_DUAL_8BIT_RIGHT
345 * @param data1 :dac1 channel indecate from selected data holding register
346 * @param data2 :dac1 channel indecate from selected data holding register
347 * @retval none
349 void dac_dual_data_set(dac_dual_data_type dac_dual, uint16_t data1, uint16_t data2)
351 switch(dac_dual)
353 case DAC_DUAL_12BIT_RIGHT:
354 *(__IO uint32_t *) dac_dual = (uint32_t)(data1 | (data2 << 16));
355 break;
356 case DAC_DUAL_12BIT_LEFT:
357 *(__IO uint32_t *) dac_dual = (uint32_t)(data1 | (data2 << 16));
358 break;
359 case DAC_DUAL_8BIT_RIGHT:
360 *(__IO uint32_t *) dac_dual = (uint32_t)(data1 | (data2 << 8));
361 break;
362 default:
363 break;
368 * @brief enable/disable dac dma udr interrupt
369 * @param dac_select
370 * this parameter can be one of the following values:
371 * - DAC1_SELECT
372 * - DAC2_SELECT
373 * @param new_state (TRUE or FALSE)
374 * @retval none
376 void dac_udr_enable(dac_select_type dac_select, confirm_state new_state)
378 switch(dac_select)
380 case DAC1_SELECT:
381 DAC->ctrl_bit.d1dmaudrien = new_state;
382 break;
383 case DAC2_SELECT:
384 DAC->ctrl_bit.d2dmaudrien = new_state;
385 break;
386 default:
387 break;
392 * @brief get flag of the dac udr flag.
393 * @param dac_select
394 * this parameter can be one of the following values:
395 * - DAC1_SELECT
396 * - DAC2_SELECT
397 * @retval the new state of dac udr flag status(SET or RESET).
399 flag_status dac_udr_flag_get(dac_select_type dac_select)
401 flag_status status = RESET;
403 switch(dac_select)
405 case DAC1_SELECT:
406 if(DAC->sts_bit.d1dmaudrf != 0)
407 status = SET;
408 break;
409 case DAC2_SELECT:
410 if(DAC->sts_bit.d2dmaudrf != 0)
411 status = SET;
412 break;
413 default:
414 break;
416 return status;
420 * @brief clear the dac udr flag.
421 * @param dac_select
422 * this parameter can be one of the following values:
423 * - DAC1_SELECT
424 * - DAC2_SELECT
425 * @retval none
427 void dac_udr_flag_clear(dac_select_type dac_select)
429 switch(dac_select)
431 case DAC1_SELECT:
432 DAC->sts = DAC1_D1DMAUDRF;
433 break;
434 case DAC2_SELECT:
435 DAC->sts = DAC2_D2DMAUDRF;
436 break;
437 default:
438 break;
443 * @}
446 #endif
449 * @}
453 * @}