Skip to content

Commit aa3e6bc

Browse files
committed
AdvancedADC: Increase the maximum number of channels.
Signed-off-by: iabdalkader <[email protected]>
1 parent 07bf0df commit aa3e6bc

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

src/AdvancedADC.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,23 @@ class AdvancedADC {
3636
template <typename ... T>
3737
AdvancedADC(pin_size_t p0, T ... args): n_channels(0), descr(nullptr) {
3838
static_assert(sizeof ...(args) < AN_MAX_ADC_CHANNELS,
39-
"A maximum of 5 channels can be sampled successively.");
39+
"A maximum of 16 channels can be sampled successively.");
4040

4141
for (auto p : {p0, args...}) {
4242
adc_pins[n_channels++] = analogPinToPinName(p);
4343
}
4444
}
45-
AdvancedADC(): n_channels(0), descr(nullptr) {}
45+
AdvancedADC(): n_channels(0), descr(nullptr) {
46+
}
4647
~AdvancedADC();
4748
bool available();
4849
SampleBuffer read();
4950
int begin(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers);
50-
int begin(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers, size_t n_pins, pin_size_t *pins) {
51-
if (n_pins > AN_MAX_ADC_CHANNELS) n_pins = AN_MAX_ADC_CHANNELS;
51+
int begin(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers,
52+
size_t n_pins, pin_size_t *pins) {
53+
if (n_pins > AN_MAX_ADC_CHANNELS) {
54+
n_pins = AN_MAX_ADC_CHANNELS;
55+
}
5256
for (size_t i = 0; i < n_pins; ++i) {
5357
adc_pins[i] = analogPinToPinName(pins[i]);
5458
}

src/AdvancedAnalog.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ enum {
3535
typedef uint16_t Sample; // Sample type used for ADC/DAC.
3636
typedef DMABuffer<Sample> &SampleBuffer;
3737

38-
#define AN_MAX_ADC_CHANNELS (5)
38+
#define AN_MAX_ADC_CHANNELS (16)
3939
#define AN_MAX_DAC_CHANNELS (1)
4040
#define AN_ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
4141

src/HALConfig.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,10 @@ int hal_dac_config(DAC_HandleTypeDef *dac, uint32_t channel, uint32_t trigger) {
164164
}
165165

166166
static uint32_t ADC_RANK_LUT[] = {
167-
ADC_REGULAR_RANK_1, ADC_REGULAR_RANK_2, ADC_REGULAR_RANK_3, ADC_REGULAR_RANK_4, ADC_REGULAR_RANK_5
167+
ADC_REGULAR_RANK_1, ADC_REGULAR_RANK_2, ADC_REGULAR_RANK_3, ADC_REGULAR_RANK_4,
168+
ADC_REGULAR_RANK_5, ADC_REGULAR_RANK_6, ADC_REGULAR_RANK_7, ADC_REGULAR_RANK_8,
169+
ADC_REGULAR_RANK_9, ADC_REGULAR_RANK_10, ADC_REGULAR_RANK_11, ADC_REGULAR_RANK_12,
170+
ADC_REGULAR_RANK_13, ADC_REGULAR_RANK_14, ADC_REGULAR_RANK_15, ADC_REGULAR_RANK_16
168171
};
169172

170173
int hal_adc_config(ADC_HandleTypeDef *adc, uint32_t resolution, uint32_t trigger, PinName *adc_pins, uint32_t n_channels) {
@@ -196,7 +199,7 @@ int hal_adc_config(ADC_HandleTypeDef *adc, uint32_t resolution, uint32_t trigger
196199
adc->Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
197200
adc->Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_CIRCULAR;
198201

199-
if (HAL_ADC_Init(adc) != HAL_OK
202+
if (HAL_ADC_Init(adc) != HAL_OK
200203
|| HAL_ADCEx_Calibration_Start(adc, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED) != HAL_OK) {
201204
return -1;
202205
}

0 commit comments

Comments
 (0)