1 /*
2  * Copyright (C) 2022-2024, Xiaohua Semiconductor Co., Ltd.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2022-04-28     CDT          first version
9  * 2024-02-20     CDT          add structure for associating with the dma
10  */
11 
12 #ifndef __DRV_ADC_H__
13 #define __DRV_ADC_H__
14 
15 /*******************************************************************************
16  * Include files
17  ******************************************************************************/
18 #include <rtthread.h>
19 #include <rtdevice.h>
20 #include "board_config.h"
21 #include "drv_irq.h"
22 #include "drv_dma.h"
23 
24 #include "hc32_ll.h"
25 
26 /* C binding of definitions if building with C++ compiler */
27 #ifdef __cplusplus
28 extern "C"
29 {
30 #endif
31 
32 
33 /*******************************************************************************
34  * Global type definitions ('typedef')
35  ******************************************************************************/
36 struct adc_dev_init_params
37 {
38     char name[8];
39     uint16_t vref;                      /*!< Specifies the ADC reference voltage, unit is mv */
40     uint16_t resolution;                /*!< Specifies the ADC resolution.
41                                              This parameter can be a value of @ref ADC_Resolution */
42     uint16_t data_align;                /*!< Specifies ADC data alignment.
43                                              This parameter can be a value of @ref ADC_Data_Align */
44     rt_bool_t hard_trig_enable;
45 
46     uint32_t hard_trig_src;             /*a value of @ref ADC_Hard_Trigger_Sel */
47     rt_bool_t internal_trig0_comtrg0_enable;
48     rt_bool_t internal_trig0_comtrg1_enable;
49     en_event_src_t internal_trig0_sel;         /*@ref en_event_src_t in details */
50     rt_bool_t internal_trig1_comtrg0_enable;
51     rt_bool_t internal_trig1_comtrg1_enable;
52     en_event_src_t internal_trig1_sel;         /*@ref en_event_src_t in details */
53 
54     rt_bool_t continue_conv_mode_enable;
55     rt_bool_t data_reg_auto_clear;
56     uint32_t eoc_poll_time_max;
57     struct dma_config *adc_eoca_dma;
58 };
59 
60 struct adc_dev_dma_priv_ops
61 {
62     rt_err_t (*dma_trig_start)(void);
63     rt_err_t (*dma_trig_stop)(void);
64     rt_err_t (*dma_trig_config)(void);
65 };
66 
67 struct adc_dev_priv_params
68 {
69     uint32_t flag;
70     struct adc_dev_dma_priv_ops *ops;
71 };
72 
73 /*******************************************************************************
74  * Global pre-processor symbols/macros ('#define')
75  ******************************************************************************/
76 #define ADC_USING_EOCA_DMA_FLAG     (1U)
77 
78 /*******************************************************************************
79  * Global variable definitions ('extern')
80  ******************************************************************************/
81 
82 /*******************************************************************************
83  * Global function prototypes (definition in C source)
84  ******************************************************************************/
85 int rt_hw_adc_init(void);
86 
87 
88 #ifdef __cplusplus
89 }
90 #endif
91 
92 #endif /* __DRV_ADC_H__ */
93 
94 /*******************************************************************************
95  * EOF (not truncated)
96  ******************************************************************************/
97