Skip to content

Commit 854e744

Browse files
fixes according to @iabdalkader review
1 parent ec81f7f commit 854e744

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/AdvancedADC.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "AdvancedADC.h"
2323

2424
#define ADC_NP ((ADCName) NC)
25+
#define ADC_PIN_ALT_MASK (uint32_t) (ALT0 | ALT1 )
2526

2627
struct adc_descr_t {
2728
ADC_HandleTypeDef adc;
@@ -126,10 +127,11 @@ int AdvancedADC::begin(uint32_t resolution, uint32_t sample_rate, size_t n_sampl
126127
for (size_t i=0; i<n_channels; i++) {
127128
adc_pins[i] = (PinName) (adc_pins[i] & ~(ADC_PIN_ALT_MASK));
128129
}
130+
129131
// Find an ADC that can be used with these set of pins/channels.
130-
for (size_t i=0; instance == ADC_NP && i<AN_ARRAY_SIZE(pin_alt); i++) {
132+
for (size_t i=0; instance == ADC_NP && i<AN_ARRAY_SIZE(adc_pin_alt); i++) {
131133
// Calculate alternate function pin.
132-
PinName pin = (PinName) (adc_pins[0] | pin_alt[i]); // First pin decides the ADC.
134+
PinName pin = (PinName) (adc_pins[0] | adc_pin_alt[i]); // First pin decides the ADC.
133135

134136
// Check if pin is mapped.
135137
if (pinmap_find_peripheral(pin, PinMap_ADC) == NC) {
@@ -140,7 +142,7 @@ int AdvancedADC::begin(uint32_t resolution, uint32_t sample_rate, size_t n_sampl
140142
for (size_t j=0; instance == ADC_NP && j<AN_ARRAY_SIZE(adc_descr_all); j++) {
141143
descr = &adc_descr_all[j];
142144
if (descr->pool == nullptr) {
143-
ADCName tmp_instance = pinmap_peripheral(pin, PinMap_ADC);
145+
ADCName tmp_instance = (ADCName) pinmap_peripheral(pin, PinMap_ADC);
144146
if (descr->adc.Instance == ((ADC_TypeDef*) tmp_instance)) {
145147
instance = tmp_instance;
146148
adc_pins[0] = pin;
@@ -159,9 +161,9 @@ int AdvancedADC::begin(uint32_t resolution, uint32_t sample_rate, size_t n_sampl
159161
pinmap_pinout(adc_pins[0], PinMap_ADC);
160162
uint8_t ch_init = 1;
161163
for (size_t i=1; i<n_channels; i++) {
162-
for (size_t j=0; j<AN_ARRAY_SIZE(pin_alt); j++) {
164+
for (size_t j=0; j<AN_ARRAY_SIZE(adc_pin_alt); j++) {
163165
// Calculate alternate function pin.
164-
PinName pin = (PinName) (adc_pins[i] | pin_alt[j]);
166+
PinName pin = (PinName) (adc_pins[i] | adc_pin_alt[j]);
165167
// Check if pin is mapped.
166168
if (pinmap_find_peripheral(pin, PinMap_ADC) == NC) {
167169
break;

0 commit comments

Comments
 (0)