123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- #ifndef GD32F30X_DAC_H
- #define GD32F30X_DAC_H
- #include "gd32f30x.h"
- #define DAC DAC_BASE
- #define DAC0 0U
- #define DAC1 1U
- #define DAC_CTL REG32(DAC + 0x00U)
- #define DAC_SWT REG32(DAC + 0x04U)
- #define DAC0_R12DH REG32(DAC + 0x08U)
- #define DAC0_L12DH REG32(DAC + 0x0CU)
- #define DAC0_R8DH REG32(DAC + 0x10U)
- #define DAC1_R12DH REG32(DAC + 0x14U)
- #define DAC1_L12DH REG32(DAC + 0x18U)
- #define DAC1_R8DH REG32(DAC + 0x1CU)
- #define DACC_R12DH REG32(DAC + 0x20U)
- #define DACC_L12DH REG32(DAC + 0x24U)
- #define DACC_R8DH REG32(DAC + 0x28U)
- #define DAC0_DO REG32(DAC + 0x2CU)
- #define DAC1_DO REG32(DAC + 0x30U)
- #define DAC_CTL_DEN0 BIT(0)
- #define DAC_CTL_DBOFF0 BIT(1)
- #define DAC_CTL_DTEN0 BIT(2)
- #define DAC_CTL_DTSEL0 BITS(3,5)
- #define DAC_CTL_DWM0 BITS(6,7)
- #define DAC_CTL_DWBW0 BITS(8,11)
- #define DAC_CTL_DDMAEN0 BIT(12)
- #define DAC_CTL_DEN1 BIT(16)
- #define DAC_CTL_DBOFF1 BIT(17)
- #define DAC_CTL_DTEN1 BIT(18)
- #define DAC_CTL_DTSEL1 BITS(19,21)
- #define DAC_CTL_DWM1 BITS(22,23)
- #define DAC_CTL_DWBW1 BITS(24,27)
- #define DAC_CTL_DDMAEN1 BIT(28)
- #define DAC_SWT_SWTR0 BIT(0)
- #define DAC_SWT_SWTR1 BIT(1)
- #define DAC0_R12DH_DAC0_DH BITS(0,11)
- #define DAC0_L12DH_DAC0_DH BITS(4,15)
- #define DAC0_R8DH_DAC0_DH BITS(0,7)
- #define DAC1_R12DH_DAC1_DH BITS(0,11)
- #define DAC1_L12DH_DAC1_DH BITS(4,15)
- #define DAC1_R8DH_DAC1_DH BITS(0,7)
- #define DACC_R12DH_DAC0_DH BITS(0,11)
- #define DACC_R12DH_DAC1_DH BITS(16,27)
- #define DACC_L12DH_DAC0_DH BITS(4,15)
- #define DACC_L12DH_DAC1_DH BITS(20,31)
- #define DACC_R8DH_DAC0_DH BITS(0,7)
- #define DACC_R8DH_DAC1_DH BITS(8,15)
- #define DAC0_DO_DAC0_DO BITS(0,11)
- #define DAC1_DO_DAC1_DO BITS(0,11)
- #define CTL_DTSEL(regval) (BITS(3,5) & ((uint32_t)(regval) << 3))
- #define DAC_TRIGGER_T5_TRGO CTL_DTSEL(0)
- #if (defined(GD32F30X_HD) || defined(GD32F30X_XD))
- #define DAC_TRIGGER_T7_TRGO CTL_DTSEL(1)
- #elif defined(GD32F30X_CL)
- #define DAC_TRIGGER_T2_TRGO CTL_DTSEL(1)
- #endif
- #define DAC_TRIGGER_T6_TRGO CTL_DTSEL(2)
- #define DAC_TRIGGER_T4_TRGO CTL_DTSEL(3)
- #define DAC_TRIGGER_T1_TRGO CTL_DTSEL(4)
- #define DAC_TRIGGER_T3_TRGO CTL_DTSEL(5)
- #define DAC_TRIGGER_EXTI_9 CTL_DTSEL(6)
- #define DAC_TRIGGER_SOFTWARE CTL_DTSEL(7)
- #define CTL_DWM(regval) (BITS(6,7) & ((uint32_t)(regval) << 6))
- #define DAC_WAVE_DISABLE CTL_DWM(0)
- #define DAC_WAVE_MODE_LFSR CTL_DWM(1)
- #define DAC_WAVE_MODE_TRIANGLE CTL_DWM(2)
- #define DWBW(regval) (BITS(8,11) & ((uint32_t)(regval) << 8))
- #define DAC_WAVE_BIT_WIDTH_1 DWBW(0)
- #define DAC_WAVE_BIT_WIDTH_2 DWBW(1)
- #define DAC_WAVE_BIT_WIDTH_3 DWBW(2)
- #define DAC_WAVE_BIT_WIDTH_4 DWBW(3)
- #define DAC_WAVE_BIT_WIDTH_5 DWBW(4)
- #define DAC_WAVE_BIT_WIDTH_6 DWBW(5)
- #define DAC_WAVE_BIT_WIDTH_7 DWBW(6)
- #define DAC_WAVE_BIT_WIDTH_8 DWBW(7)
- #define DAC_WAVE_BIT_WIDTH_9 DWBW(8)
- #define DAC_WAVE_BIT_WIDTH_10 DWBW(9)
- #define DAC_WAVE_BIT_WIDTH_11 DWBW(10)
- #define DAC_WAVE_BIT_WIDTH_12 DWBW(11)
- #define DAC_LFSR_BIT0 DAC_WAVE_BIT_WIDTH_1
- #define DAC_LFSR_BITS1_0 DAC_WAVE_BIT_WIDTH_2
- #define DAC_LFSR_BITS2_0 DAC_WAVE_BIT_WIDTH_3
- #define DAC_LFSR_BITS3_0 DAC_WAVE_BIT_WIDTH_4
- #define DAC_LFSR_BITS4_0 DAC_WAVE_BIT_WIDTH_5
- #define DAC_LFSR_BITS5_0 DAC_WAVE_BIT_WIDTH_6
- #define DAC_LFSR_BITS6_0 DAC_WAVE_BIT_WIDTH_7
- #define DAC_LFSR_BITS7_0 DAC_WAVE_BIT_WIDTH_8
- #define DAC_LFSR_BITS8_0 DAC_WAVE_BIT_WIDTH_9
- #define DAC_LFSR_BITS9_0 DAC_WAVE_BIT_WIDTH_10
- #define DAC_LFSR_BITS10_0 DAC_WAVE_BIT_WIDTH_11
- #define DAC_LFSR_BITS11_0 DAC_WAVE_BIT_WIDTH_12
- #define DATA_ALIGN(regval) (BITS(0,1) & ((uint32_t)(regval) << 0))
- #define DAC_ALIGN_12B_R DATA_ALIGN(0)
- #define DAC_ALIGN_12B_L DATA_ALIGN(1)
- #define DAC_ALIGN_8B_R DATA_ALIGN(2)
- #define DAC_TRIANGLE_AMPLITUDE_1 DAC_WAVE_BIT_WIDTH_1
- #define DAC_TRIANGLE_AMPLITUDE_3 DAC_WAVE_BIT_WIDTH_2
- #define DAC_TRIANGLE_AMPLITUDE_7 DAC_WAVE_BIT_WIDTH_3
- #define DAC_TRIANGLE_AMPLITUDE_15 DAC_WAVE_BIT_WIDTH_4
- #define DAC_TRIANGLE_AMPLITUDE_31 DAC_WAVE_BIT_WIDTH_5
- #define DAC_TRIANGLE_AMPLITUDE_63 DAC_WAVE_BIT_WIDTH_6
- #define DAC_TRIANGLE_AMPLITUDE_127 DAC_WAVE_BIT_WIDTH_7
- #define DAC_TRIANGLE_AMPLITUDE_255 DAC_WAVE_BIT_WIDTH_8
- #define DAC_TRIANGLE_AMPLITUDE_511 DAC_WAVE_BIT_WIDTH_9
- #define DAC_TRIANGLE_AMPLITUDE_1023 DAC_WAVE_BIT_WIDTH_10
- #define DAC_TRIANGLE_AMPLITUDE_2047 DAC_WAVE_BIT_WIDTH_11
- #define DAC_TRIANGLE_AMPLITUDE_4095 DAC_WAVE_BIT_WIDTH_12
- void dac_deinit(void);
- void dac_enable(uint32_t dac_periph);
- void dac_disable(uint32_t dac_periph);
- void dac_dma_enable(uint32_t dac_periph);
- void dac_dma_disable(uint32_t dac_periph);
- void dac_output_buffer_enable(uint32_t dac_periph);
- void dac_output_buffer_disable(uint32_t dac_periph);
- uint16_t dac_output_value_get(uint32_t dac_periph);
- void dac_data_set(uint32_t dac_periph, uint32_t dac_align, uint16_t data);
- void dac_trigger_enable(uint32_t dac_periph);
- void dac_trigger_disable(uint32_t dac_periph);
- void dac_trigger_source_config(uint32_t dac_periph, uint32_t triggersource);
- void dac_software_trigger_enable(uint32_t dac_periph);
- void dac_software_trigger_disable(uint32_t dac_periph);
- void dac_wave_mode_config(uint32_t dac_periph, uint32_t wave_mode);
- void dac_wave_bit_width_config(uint32_t dac_periph, uint32_t bit_width);
- void dac_lfsr_noise_config(uint32_t dac_periph, uint32_t unmask_bits);
- void dac_triangle_noise_config(uint32_t dac_periph, uint32_t amplitude);
- void dac_concurrent_enable(void);
- void dac_concurrent_disable(void);
- void dac_concurrent_software_trigger_enable(void);
- void dac_concurrent_software_trigger_disable(void);
- void dac_concurrent_output_buffer_enable(void);
- void dac_concurrent_output_buffer_disable(void);
- void dac_concurrent_data_set(uint32_t dac_align, uint16_t data0, uint16_t data1);
- #endif
|