Skip to content

Commit

Permalink
fixes according to @iabdalkader review
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardocavagnis committed Dec 6, 2023
1 parent ec81f7f commit 854e744
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/AdvancedADC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "AdvancedADC.h"

#define ADC_NP ((ADCName) NC)
#define ADC_PIN_ALT_MASK (uint32_t) (ALT0 | ALT1 )

struct adc_descr_t {
ADC_HandleTypeDef adc;
Expand Down Expand Up @@ -126,10 +127,11 @@ int AdvancedADC::begin(uint32_t resolution, uint32_t sample_rate, size_t n_sampl
for (size_t i=0; i<n_channels; i++) {
adc_pins[i] = (PinName) (adc_pins[i] & ~(ADC_PIN_ALT_MASK));
}

// Find an ADC that can be used with these set of pins/channels.
for (size_t i=0; instance == ADC_NP && i<AN_ARRAY_SIZE(pin_alt); i++) {
for (size_t i=0; instance == ADC_NP && i<AN_ARRAY_SIZE(adc_pin_alt); i++) {
// Calculate alternate function pin.
PinName pin = (PinName) (adc_pins[0] | pin_alt[i]); // First pin decides the ADC.
PinName pin = (PinName) (adc_pins[0] | adc_pin_alt[i]); // First pin decides the ADC.

// Check if pin is mapped.
if (pinmap_find_peripheral(pin, PinMap_ADC) == NC) {
Expand All @@ -140,7 +142,7 @@ int AdvancedADC::begin(uint32_t resolution, uint32_t sample_rate, size_t n_sampl
for (size_t j=0; instance == ADC_NP && j<AN_ARRAY_SIZE(adc_descr_all); j++) {
descr = &adc_descr_all[j];
if (descr->pool == nullptr) {
ADCName tmp_instance = pinmap_peripheral(pin, PinMap_ADC);
ADCName tmp_instance = (ADCName) pinmap_peripheral(pin, PinMap_ADC);
if (descr->adc.Instance == ((ADC_TypeDef*) tmp_instance)) {
instance = tmp_instance;
adc_pins[0] = pin;
Expand All @@ -159,9 +161,9 @@ int AdvancedADC::begin(uint32_t resolution, uint32_t sample_rate, size_t n_sampl
pinmap_pinout(adc_pins[0], PinMap_ADC);
uint8_t ch_init = 1;
for (size_t i=1; i<n_channels; i++) {
for (size_t j=0; j<AN_ARRAY_SIZE(pin_alt); j++) {
for (size_t j=0; j<AN_ARRAY_SIZE(adc_pin_alt); j++) {
// Calculate alternate function pin.
PinName pin = (PinName) (adc_pins[i] | pin_alt[j]);
PinName pin = (PinName) (adc_pins[i] | adc_pin_alt[j]);
// Check if pin is mapped.
if (pinmap_find_peripheral(pin, PinMap_ADC) == NC) {
break;
Expand Down

0 comments on commit 854e744

Please sign in to comment.