Skip to content

Commit ec81f7f

Browse files
Update src/AdvancedADC.cpp
Co-authored-by: Ibrahim Abdelkader <[email protected]>
1 parent c1e448e commit ec81f7f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/AdvancedADC.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,12 @@ int AdvancedADC::begin(uint32_t resolution, uint32_t sample_rate, size_t n_sampl
139139
// Find the first free ADC according to the available ADCs on pin.
140140
for (size_t j=0; instance == ADC_NP && j<AN_ARRAY_SIZE(adc_descr_all); j++) {
141141
descr = &adc_descr_all[j];
142-
if (descr->pool == nullptr && ((ADC_TypeDef*)pinmap_peripheral(pin, PinMap_ADC) == descr->adc.Instance)) {
143-
instance = (ADCName) pinmap_peripheral(pin, PinMap_ADC);
144-
adc_pins[0] = pin;
142+
if (descr->pool == nullptr) {
143+
ADCName tmp_instance = pinmap_peripheral(pin, PinMap_ADC);
144+
if (descr->adc.Instance == ((ADC_TypeDef*) tmp_instance)) {
145+
instance = tmp_instance;
146+
adc_pins[0] = pin;
147+
}
145148
}
146149
}
147150
}

0 commit comments

Comments
 (0)