Skip to content

Commit 850a92a

Browse files
authored
Merge pull request #2 from CyberCastle/codex/añadir-soporte-para-pureanalogpin-en-advancedadc
Add PureAnalogPin support in AdvancedADC
2 parents 36653fd + d13732f commit 850a92a

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

src/AdvancedADC.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@
2020
#include "Arduino.h"
2121
#include "HALConfig.h"
2222
#include "AdvancedADC.h"
23+
#if __has_include("pure_analog_pins.h")
24+
#include "pure_analog_pins.h"
25+
#endif
26+
27+
#if __has_include("pure_analog_pins.h")
28+
template <>
29+
PinName AdvancedADC::_toPinName(PureAnalogPin p) {
30+
extern AnalogPinDescription g_pureAAnalogPinDescription[];
31+
return g_pureAAnalogPinDescription[p.get()].name;
32+
}
33+
#endif
2334

2435
#define ADC_NP ((ADCName) NC)
2536
#define ADC_PIN_ALT_MASK (uint32_t) (ALT0 | ALT1 )
@@ -237,6 +248,23 @@ int AdvancedADC::begin(uint32_t resolution, uint32_t sample_rate, size_t n_sampl
237248
return 1;
238249
}
239250

251+
#if __has_include("pure_analog_pins.h")
252+
int AdvancedADC::begin(uint32_t resolution, uint32_t sample_rate, size_t n_samples,
253+
size_t n_buffers, size_t n_pins, PureAnalogPin *pins,
254+
bool start, adc_sample_time_t sample_time) {
255+
if (n_pins > AN_MAX_ADC_CHANNELS) {
256+
n_pins = AN_MAX_ADC_CHANNELS;
257+
}
258+
259+
for (size_t i = 0; i < n_pins; ++i) {
260+
adc_pins[i] = _toPinName(pins[i]);
261+
}
262+
263+
n_channels = n_pins;
264+
return begin(resolution, sample_rate, n_samples, n_buffers, start, sample_time);
265+
}
266+
#endif
267+
240268
int AdvancedADC::start(uint32_t sample_rate){
241269
// Initialize and configure the ADC timer.
242270
hal_tim_config(&descr->tim, sample_rate);

src/AdvancedADC.h

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ class AdvancedADC {
4949
return analogPinToPinName(p);
5050
}
5151
#if __has_include("pure_analog_pins.h")
52-
static inline PinName _toPinName(PureAnalogPin p) {
53-
extern AnalogPinDescription g_pureAAnalogPinDescription[];
54-
return g_pureAAnalogPinDescription[p.get()].name;
55-
}
52+
static PinName _toPinName(PureAnalogPin p);
5653
#endif
5754

5855
public:
@@ -89,17 +86,7 @@ class AdvancedADC {
8986
#if __has_include("pure_analog_pins.h")
9087
int begin(uint32_t resolution, uint32_t sample_rate, size_t n_samples,
9188
size_t n_buffers, size_t n_pins, PureAnalogPin *pins, bool start=true,
92-
adc_sample_time_t sample_time=AN_ADC_SAMPLETIME_8_5) {
93-
if (n_pins > AN_MAX_ADC_CHANNELS) {
94-
n_pins = AN_MAX_ADC_CHANNELS;
95-
}
96-
for (size_t i = 0; i < n_pins; ++i) {
97-
adc_pins[i] = _toPinName(pins[i]);
98-
}
99-
100-
n_channels = n_pins;
101-
return begin(resolution, sample_rate, n_samples, n_buffers, start, sample_time);
102-
}
89+
adc_sample_time_t sample_time=AN_ADC_SAMPLETIME_8_5);
10390
#endif
10491
int start(uint32_t sample_rate);
10592
int stop();

0 commit comments

Comments
 (0)