adc_hal.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2019 Espressif Systems (Shanghai) PTE LTD
  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. #include "hal/adc_hal.h"
  15. #include "hal/adc_hal_conf.h"
  16. void adc_hal_init(void)
  17. {
  18. // Set internal FSM wait time, fixed value.
  19. adc_ll_digi_set_fsm_time(SOC_ADC_FSM_RSTB_WAIT_DEFAULT, SOC_ADC_FSM_START_WAIT_DEFAULT,
  20. SOC_ADC_FSM_STANDBY_WAIT_DEFAULT);
  21. adc_ll_set_sample_cycle(ADC_FSM_SAMPLE_CYCLE_DEFAULT);
  22. adc_hal_pwdet_set_cct(SOC_ADC_PWDET_CCT_DEFAULT);
  23. adc_ll_digi_output_invert(ADC_NUM_1, SOC_ADC_DIGI_DATA_INVERT_DEFAULT(ADC_NUM_1));
  24. adc_ll_digi_output_invert(ADC_NUM_2, SOC_ADC_DIGI_DATA_INVERT_DEFAULT(ADC_NUM_2));
  25. }
  26. void adc_hal_deinit(void)
  27. {
  28. adc_ll_set_power_manage(ADC_POWER_SW_OFF);
  29. }
  30. int adc_hal_convert(adc_ll_num_t adc_n, int channel, int *value)
  31. {
  32. adc_ll_rtc_enable_channel(adc_n, channel);
  33. adc_ll_rtc_start_convert(adc_n, channel);
  34. while (adc_ll_rtc_convert_is_done(adc_n) != true);
  35. *value = adc_ll_rtc_get_convert_value(adc_n);
  36. return (int)adc_ll_rtc_analysis_raw_data(adc_n, (uint16_t)(*value));
  37. }