2 **************************************************************************
3 * @file at32f435_437_dac.c
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
34 * @brief DAC driver modules
38 #ifdef DAC_MODULE_ENABLED
40 /** @defgroup DAC_private_functions
51 crm_periph_reset(CRM_DAC_PERIPH_RESET
, TRUE
);
52 crm_periph_reset(CRM_DAC_PERIPH_RESET
, FALSE
);
56 * @brief enable or disable dac
58 * this parameter can be one of the following values:
61 * @param new_state (TRUE or FALSE)
64 void dac_enable(dac_select_type dac_select
, confirm_state new_state
)
69 DAC
->ctrl_bit
.d1en
= new_state
;
72 DAC
->ctrl_bit
.d2en
= new_state
;
80 * @brief enable or disable dac output buffer
82 * this parameter can be one of the following values:
85 * @param new_state (TRUE or FALSE)
88 void dac_output_buffer_enable(dac_select_type dac_select
, confirm_state new_state
)
90 new_state
= (confirm_state
)!new_state
;
94 DAC
->ctrl_bit
.d1obdis
= new_state
;
97 DAC
->ctrl_bit
.d2obdis
= new_state
;
105 * @brief enable or disable dac trigger
107 * this parameter can be one of the following values:
110 * @param new_state (TRUE or FALSE)
113 void dac_trigger_enable(dac_select_type dac_select
, confirm_state new_state
)
118 DAC
->ctrl_bit
.d1trgen
= new_state
;
121 DAC
->ctrl_bit
.d2trgen
= new_state
;
129 * @brief select dac trigger
131 * this parameter can be one of the following values:
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
146 void dac_trigger_select(dac_select_type dac_select
, dac_trigger_type dac_trigger_source
)
151 DAC
->ctrl_bit
.d1trgsel
= dac_trigger_source
;
154 DAC
->ctrl_bit
.d2trgsel
= dac_trigger_source
;
162 * @brief generate dac software trigger
164 * this parameter can be one of the following values:
169 void dac_software_trigger_generate(dac_select_type dac_select
)
174 DAC
->swtrg_bit
.d1swtrg
= TRUE
;
177 DAC
->swtrg_bit
.d2swtrg
= TRUE
;
185 * @brief generate dac dual software trigger synchronously
189 void dac_dual_software_trigger_generate(void)
195 * @brief generate dac wave
197 * this parameter can be one of the following values:
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
207 void dac_wave_generate(dac_select_type dac_select
, dac_wave_type dac_wave
)
212 DAC
->ctrl_bit
.d1nm
= dac_wave
;
215 DAC
->ctrl_bit
.d2nm
= dac_wave
;
223 * @brief select dac mask amplitude
225 * this parameter can be one of the following values:
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
244 void dac_mask_amplitude_select(dac_select_type dac_select
, dac_mask_amplitude_type dac_mask_amplitude
)
249 DAC
->ctrl_bit
.d1nbsel
= dac_mask_amplitude
;
252 DAC
->ctrl_bit
.d2nbsel
= dac_mask_amplitude
;
260 * @brief enable or disable dac dma
262 * this parameter can be one of the following values:
265 * @param new_state (TRUE or FALSE)
268 void dac_dma_enable(dac_select_type dac_select
, confirm_state new_state
)
273 DAC
->ctrl_bit
.d1dmaen
= new_state
;
276 DAC
->ctrl_bit
.d2dmaen
= new_state
;
284 * @brief get dac data output
286 * this parameter can be one of the following values:
289 * @retval dac channel data output
291 uint16_t dac_data_output_get(dac_select_type dac_select
)
293 uint16_t data_output
=0;
297 data_output
= DAC
->d1odt_bit
.d1odt
;
300 data_output
= DAC
->d2odt_bit
.d2odt
;
309 * @brief set dac1 data
310 * @param dac1_aligned
311 * this parameter can be one of the following values:
315 * @param dac1_data :indecate from selected data holding register
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:
330 * @param dac2_data :indecate from selected data holding register
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
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
349 void dac_dual_data_set(dac_dual_data_type dac_dual
, uint16_t data1
, uint16_t data2
)
353 case DAC_DUAL_12BIT_RIGHT
:
354 *(__IO
uint32_t *) dac_dual
= (uint32_t)(data1
| (data2
<< 16));
356 case DAC_DUAL_12BIT_LEFT
:
357 *(__IO
uint32_t *) dac_dual
= (uint32_t)(data1
| (data2
<< 16));
359 case DAC_DUAL_8BIT_RIGHT
:
360 *(__IO
uint32_t *) dac_dual
= (uint32_t)(data1
| (data2
<< 8));
368 * @brief enable/disable dac dma udr interrupt
370 * this parameter can be one of the following values:
373 * @param new_state (TRUE or FALSE)
376 void dac_udr_enable(dac_select_type dac_select
, confirm_state new_state
)
381 DAC
->ctrl_bit
.d1dmaudrien
= new_state
;
384 DAC
->ctrl_bit
.d2dmaudrien
= new_state
;
392 * @brief get flag of the dac udr flag.
394 * this parameter can be one of the following values:
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
;
406 if(DAC
->sts_bit
.d1dmaudrf
!= 0)
410 if(DAC
->sts_bit
.d2dmaudrf
!= 0)
420 * @brief clear the dac udr flag.
422 * this parameter can be one of the following values:
427 void dac_udr_flag_clear(dac_select_type dac_select
)
432 DAC
->sts
= DAC1_D1DMAUDRF
;
435 DAC
->sts
= DAC2_D2DMAUDRF
;