/* * BSD 2-Clause License * Copyright (c) 2022, LiteEMF * All rights reserved. * This software component is licensed by LiteEMF under BSD 2-Clause license, * the "License"; You may not use this file except in compliance with the * License. You may obtain a copy of the License at: * opensource.org/licenses/BSD-2-Clause * */ /************************************************************************************************************ ** Description: ************************************************************************************************************/ #include "hw_config.h" #include "hw_board.h" // #ifdef HW_ADC_MAP #if 1 #include "api/api_adc.h" #include "py32f002b_ll_adc.h" /****************************************************************************************************** ** Defined *******************************************************************************************************/ /****************************************************************************************************** ** static Parameters *******************************************************************************************************/ /****************************************************************************************************** ** public Parameters *******************************************************************************************************/ /***************************************************************************************************** ** static Function ******************************************************************************************************/ uint16_t irq_adc[m_adc_num]; //全局变量, 防止adc采样失败数据出错 uint8_t num = 0; /***************************************************************************************************** ** Function ******************************************************************************************************/ /** * @brief ADC calibration program. * @param None * @retval None */ static void APP_AdcCalibrate(void) { #if (USE_TIMEOUT == 1) uint32_t Timeout = 0; #endif if (LL_ADC_IsEnabled(ADC1) == 0) { /* Enable ADC calibration */ LL_ADC_StartCalibration(ADC1); #if (USE_TIMEOUT == 1) Timeout = ADC_CALIBRATION_TIMEOUT_MS; #endif while (LL_ADC_IsCalibrationOnGoing(ADC1) != 0) { #if (USE_TIMEOUT == 1) /* Detects if the calibration has timed out */ if (LL_SYSTICK_IsActiveCounterFlag()) { if(Timeout-- == 0) { } } #endif } /* The delay between the end of ADC calibration and ADC enablement is at least 4 ADC clocks */ LL_mDelay(1); } } /** * @brief Enable ADC. * @param None * @retval None */ static void APP_AdcEnable(void) { /* Enable ADC */ LL_ADC_Enable(ADC1); /* The delay between ADC enablement and ADC stabilization is at least 8 ADC clocks */ LL_mDelay(1); } /******************************************************************* ** Parameters: ** Returns: ** Description: *******************************************************************/ uint16_t hal_adc_to_voltage(uint16_t adc) { return 0; } bool hal_adc_value(uint8_t id, uint16_t* valp) { if(id >= m_adc_num) return false; valp = irq_adc[id]; return true; } bool hal_adc_start_scan(void) { return false; } bool hal_adc_init(void) { uint8_t id; LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_ADC1); for(id=0; idDR; if(num >= m_adc_num) i = 0; } #endif