• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2022 Beken Corporation
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #include "adc_hw.h"
22 #include "adc_ll.h"
23 #include <driver/hal/hal_adc_types.h>
24 #include "adc_map.h"
25 #include <common/bk_err.h>
26 #include "hal_config.h"
27 
28 typedef struct {
29 	adc_hw_t *hw;
30 } adc_hal_t;
31 
32 
33 #define adc_hal_set_sleep_mode(hal)		adc_ll_set_sleep_mode((hal)->hw)
34 #define adc_hal_set_single_step_mode(hal)	adc_ll_set_single_step_mode((hal)->hw)
35 #define adc_hal_set_software_control_mode(hal)	adc_ll_set_software_control_mode((hal)->hw)
36 #define adc_hal_get_mode(hal)			adc_ll_get_adc_mode((hal)->hw)
37 #define adc_hal_set_continuous_mode(hal)	adc_ll_set_continuous_mode((hal)->hw)
38 #define adc_hal_enbale(hal)			adc_ll_enable((hal)->hw)
39 #define adc_hal_disbale(hal)			adc_ll_disable((hal)->hw)
40 #define adc_hal_sel_channel(hal, id)		adc_ll_sel_channel((hal)->hw, id)
41 #define adc_hal_wait_4_cycle(hal)		adc_ll_wait_4_cycle((hal)->hw)
42 #define adc_hal_wait_8_cycle(hal)		adc_ll_wait_8_cycle((hal)->hw)
43 #define adc_hal_clear_int_status(hal)		adc_ll_clear_int_status((hal)->hw)
44 #define adc_hal_enable_32m_clk(hal)		adc_ll_enable_32m_clk((hal)->hw)
45 #define adc_hal_disable_32m_clk(hal)		adc_ll_disable_32m_clk((hal)->hw)
46 #define adc_hal_set_pre_div(hal, div)		adc_ll_set_pre_div((hal)->hw, div)
47 #define adc_hal_set_sample_rate(hal, rate)	adc_ll_set_sample_rate((hal)->hw, rate)
48 #define adc_hal_set_adc_filter(hal, filter)	adc_ll_set_adc_filter((hal)->hw, filter)
49 #define adc_hal_is_fifo_empty(hal)		adc_ll_is_fifo_empty((hal)->hw)
50 #define adc_hal_is_fifo_full(hal)		adc_ll_is_fifo_full((hal)->hw)
51 #define adc_hal_check_adc_busy(hal)		adc_ll_check_adc_busy((hal)->hw)
52 #define adc_hal_check_adc_enable(hal)		adc_ll_check_adc_enable((hal)->hw)
53 
54 #define adc_hal_get_adc_raw_data(hal)		adc_ll_get_adc_raw_data((hal)->hw)
55 
56 #define adc_hal_set_fifo_threshold(hal, value)	adc_ll_set_fifo_threshold((hal)->hw, value)
57 #define adc_hal_set_steady_ctrl(hal, value)	adc_ll_set_steady_ctrl((hal)->hw, value)
58 
59 #define adc_hal_is_over_flow(hal)		adc_ll_is_over_flow((hal)->hw)
60 
61 #define adc_hal_get_adc_data(hal)		adc_ll_get_adc_data((hal)->hw)
62 
63 #define adc_hal_enable_bypass_calib(hal)	adc_ll_enable_bypass_calib((hal)->hw)
64 #define adc_hal_disable_bypass_calib(hal)	adc_ll_disable_bypass_calib((hal)->hw)
65 
66 #define adc_hal_is_analog_channel(hal, id)      adc_ll_is_analog_channel((hal)->hw, (id))
67 #define adc_hal_is_valid_channel(hal, id)       (adc_ll_is_analog_channel((hal)->hw, (id)) ||\
68 				adc_ll_is_digital_channel((hal)->hw, (id)))
69 
70 bk_err_t adc_hal_init(adc_hal_t *hal);
71 bk_err_t adc_hal_deinit(adc_hal_t *hal);
72 bk_err_t adc_hal_set_clk(adc_hal_t *hal, adc_src_clk_t src_clk, uint32_t adc_clk);
73 bk_err_t adc_hal_set_mode(adc_hal_t *hal, adc_mode_t adc_mode);
74 bk_err_t adc_hal_start_commom(adc_hal_t *hal);
75 bk_err_t adc_hal_stop_commom(adc_hal_t *hal);
76 bk_err_t adc_hal_set_saturate_mode(adc_hal_t *hal, adc_saturate_mode_t mode);
77 uint16_t adc_hal_get_single_step_adc_data(adc_hal_t *hal);
78 
79 #ifdef SOC_ADC_FIFO_DATA_SUPPORT
80 #define adc_hal_get_fifo_data(hal) adc_ll_get_fifo_data((hal)->hw)
81 #endif
82 
83 #ifdef SOC_ADC_DC_OFFSET_SUPPORT
84 #define adc_hal_set_dc_offset(hal, value) adc_ll_set_dc_offset((hal)->hw, value)
85 #define adc_hal_get_dc_offset(hal, value) adc_ll_get_dc_offset((hal)->hw)
86 #endif
87 
88 #ifdef SOC_ADC_GAIN_SUPPORT
89 #define adc_hal_set_gain(hal, value) adc_ll_set_gain((hal)->hw, value)
90 #define adc_hal_get_gain(hal) adc_ll_get_gain((hal)->hw)
91 #endif
92 
93 #define SARADC_AUTOTEST    0
94 
95 #if SARADC_AUTOTEST
96 bk_err_t adc_hal_set_div(adc_hal_t *hal, uint32_t div);
97 #endif
98 
99 #if CFG_HAL_DEBUG_ADC
100 void adc_struct_dump(void);
101 #else
102 #define adc_struct_dump()
103 #endif
104 
105 #ifdef __cplusplus
106 }
107 #endif
108