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 #include <components/log.h> 18 19 #define ADC_TAG "adc" 20 #define ADC_LOGI(...) BK_LOGI(ADC_TAG, ##__VA_ARGS__) 21 #define ADC_LOGW(...) BK_LOGW(ADC_TAG, ##__VA_ARGS__) 22 #define ADC_LOGE(...) BK_LOGE(ADC_TAG, ##__VA_ARGS__) 23 #define ADC_LOGD(...) BK_LOGD(ADC_TAG, ##__VA_ARGS__) 24 25 26 #define DEFAULT_ADC_MODE ADC_CONTINUOUS_MODE 27 #define DEFAULT_ADC_SAMPLE_RATE 0x20 28 #define DEFAULT_ADC_SCLK ADC_SCLK_XTAL_26M 29 #define DEFAULT_ADC_CLK 2600000 30 #define DEFAULT_ADC_STEADY_TIME 7 31 #define DEFAULT_SATURATE_MODE ADC_SATURATE_MODE_3 32 33 bk_err_t bk_adc_acquire(void); 34 bk_err_t bk_adc_init(adc_chan_t adc_chan); 35 bk_err_t bk_adc_enable_bypass_clalibration(void); 36 bk_err_t bk_adc_start(void); 37 bk_err_t bk_adc_read_raw(uint16_t* buf, uint32_t size, uint32_t timeout); 38 bk_err_t bk_adc_stop(void); 39 bk_err_t bk_adc_deinit(adc_chan_t chan); 40 bk_err_t bk_adc_release(void); 41 42 bk_err_t bk_adc_set_config(adc_config_t *config); 43 bk_err_t bk_adc_get_config(uint32 adc_ch, adc_config_t **config); 44 bk_err_t bk_adc_is_valid_ch(uint32_t ch); 45 bk_err_t bk_adc_register_isr_iot_callback( void* iot_callback, void * p_iot_context); 46 bk_err_t bk_adc_unregister_isr_iot_callback(void); 47 48 bk_err_t bk_adc_en(void); 49 50