1 /* 2 * Copyright (c) 2021 HPMicro 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 #ifndef HPM_DAC_DRV_H 8 #define HPM_DAC_DRV_H 9 10 #include "hpm_common.h" 11 #include "hpm_dac_regs.h" 12 #include "hpm_soc_feature.h" 13 14 #define DAC_AHB_ERROR_EVENT DAC_IRQ_EN_AHB_ERROR_MASK 15 #define DAC_FIFO_EMPTY_EVENT DAC_IRQ_EN_FIFO_EMPTY_MASK 16 #define DAC_BUF1_COMPLETE_EVENT DAC_IRQ_EN_BUF1_CMPT_MASK 17 #define DAC_BUF0_COMPLETE_EVENT DAC_IRQ_EN_BUF0_CMPT_MASK 18 19 20 typedef enum { 21 dac_mode_direct = 0, 22 dac_mode_step, 23 dac_mode_buffer 24 } dac_mode_t; 25 26 typedef enum { 27 dac_ana_div_2 = 0, 28 dac_ana_div_4, 29 dac_ana_div_6, 30 dac_ana_div_8 31 } dac_ana_div_t; 32 33 typedef struct { 34 bool sync_mode; 35 uint8_t dac_mode; 36 uint8_t clk_dac_div; 37 uint16_t div_cfg; 38 } dac_config_t; 39 40 typedef enum { 41 dac_step_up = 0, 42 dac_step_down 43 } dac_step_direction_t; 44 45 typedef enum { 46 dac_round_mode_oneshot = 0, 47 dac_round_mode_loop 48 } dac_round_mode_t; 49 50 typedef struct { 51 uint16_t start_point; 52 uint16_t end_point; 53 uint8_t round_mode; 54 uint8_t up_down; 55 uint8_t step_num; 56 } dac_step_config_t; 57 58 typedef enum { 59 dac_data_stru_2_point = 0, 60 dac_data_stru_1_point 61 } dac_data_structure_t; 62 63 typedef enum { 64 dac_burst_single = 0, 65 dac_burst_incr4 = 3, 66 dac_burst_incr8 = 5 67 } dac_burst_type_t; 68 69 typedef struct { 70 uint32_t start_addr; 71 uint8_t stop; 72 uint16_t len; 73 } dac_buffer_t; 74 75 typedef struct { 76 uint8_t buf_data_mode; 77 uint8_t burst; 78 dac_buffer_t buf0; 79 dac_buffer_t buf1; 80 } dac_buffer_config_t; 81 82 #ifdef __cplusplus 83 extern "C" { 84 #endif 85 86 void dac_get_default_config(dac_config_t *config); 87 hpm_stat_t dac_init(DAC_Type *ptr, dac_config_t *config); 88 hpm_stat_t dac_set_direct_config(DAC_Type *ptr, uint16_t data); 89 hpm_stat_t dac_set_step_config(DAC_Type *ptr, uint8_t step_cfg_idx, dac_step_config_t *config); 90 hpm_stat_t dac_set_buffer_config(DAC_Type *ptr, dac_buffer_config_t *config); 91 hpm_stat_t dac_set_output_frequency(DAC_Type *ptr, uint32_t dac_input_freq, uint32_t dac_output_freq); 92 hpm_stat_t dac_set_step_sw_trigger(DAC_Type *ptr, uint8_t step_sw_trig_idx); 93 void dac_set_buffer_sw_trigger(DAC_Type *ptr); 94 void dac_set_hw_trigger_enable(DAC_Type *ptr, bool enable); 95 hpm_stat_t dac_external_dma_request_enable(DAC_Type *ptr, uint8_t buf_idx, bool enable); 96 void dac_set_buffer_dma_reset(DAC_Type *ptr); 97 void dac_enable_conversion(DAC_Type *ptr, bool enable); 98 void dac_enable_interrupts(DAC_Type *ptr, uint32_t mask); 99 uint32_t dac_get_status_flags(DAC_Type *ptr); 100 void dac_set_status_flags(DAC_Type *ptr, uint32_t mask); 101 uint8_t dac_get_current_buffer_index(DAC_Type *ptr); 102 uint16_t dac_get_current_buffer_offset(DAC_Type *ptr); 103 104 #ifdef __cplusplus 105 } 106 #endif 107 108 #endif