Fix pin attenuation being overwritten (#5399)

Fixes: #5041
This commit is contained in:
Me No Dev 2021-07-16 17:34:25 +03:00 committed by GitHub
parent 5eda278177
commit a9bd39de66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -48,6 +48,7 @@ static uint8_t __analogVRefPin = 0;
static uint8_t __analogAttenuation = 3;//11db
static uint8_t __analogWidth = 3;//12 bits
static uint8_t __analogClockDiv = 1;
static adc_attenuation_t __pin_attenuation[SOC_GPIO_PIN_COUNT];
void __analogSetClockDiv(uint8_t clockDiv){
if(!clockDiv){
@ -86,6 +87,9 @@ void __analogInit(){
#if CONFIG_IDF_TARGET_ESP32
__analogSetWidth(__analogWidth + 9);//in bits
#endif
for(int i=0; i<SOC_GPIO_PIN_COUNT; i++){
__pin_attenuation[i] = ADC_ATTENDB_MAX;
}
}
void __analogSetPinAttenuation(uint8_t pin, adc_attenuation_t attenuation)
@ -100,6 +104,7 @@ void __analogSetPinAttenuation(uint8_t pin, adc_attenuation_t attenuation)
adc1_config_channel_atten(channel, attenuation);
}
__analogInit();
__pin_attenuation[pin] = attenuation;
}
bool __adcAttachPin(uint8_t pin){
@ -129,7 +134,7 @@ bool __adcAttachPin(uint8_t pin){
#endif
pinMode(pin, ANALOG);
__analogSetPinAttenuation(pin, __analogAttenuation);
__analogSetPinAttenuation(pin, (__pin_attenuation[pin] != ADC_ATTENDB_MAX)?__pin_attenuation[pin]:__analogAttenuation);
return true;
}

View File

@ -30,7 +30,8 @@ typedef enum {
ADC_0db,
ADC_2_5db,
ADC_6db,
ADC_11db
ADC_11db,
ADC_ATTENDB_MAX
} adc_attenuation_t;
/*