From 7a77b311031b61c2be98c98850425aa3fc056ad4 Mon Sep 17 00:00:00 2001 From: jmdodd95682 <46497064+jmdodd95682@users.noreply.github.com> Date: Mon, 5 Feb 2024 16:29:04 -0800 Subject: [PATCH 01/22] Declared new member functions ready(), start(), and clear() ready() and start() are just the begin() function split into two pieces so you can setup the DMA and ADC without starting until later. --- src/AdvancedADC.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/AdvancedADC.h b/src/AdvancedADC.h index 844985b..97f6e30 100644 --- a/src/AdvancedADC.h +++ b/src/AdvancedADC.h @@ -55,6 +55,17 @@ class AdvancedADC { n_channels = n_pins; return begin(resolution, sample_rate, n_samples, n_buffers); } + void clear(); //clears any existing DMA buffers from read queue + int ready(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers); + int ready(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers, size_t n_pins, pin_size_t *pins) { + if (n_pins > AN_MAX_ADC_CHANNELS) n_pins = AN_MAX_ADC_CHANNELS; + for (size_t i = 0; i < n_pins; ++i) { + adc_pins[i] = analogPinToPinName(pins[i]); + } + n_channels = n_pins; + return ready(resolution, sample_rate, n_samples, n_buffers); + } + int start(uint32_t sample_rate); int stop(); }; From a76e0e49ecd18838cecc69ef1912b78144075a12 Mon Sep 17 00:00:00 2001 From: jmdodd95682 <46497064+jmdodd95682@users.noreply.github.com> Date: Mon, 5 Feb 2024 16:54:19 -0800 Subject: [PATCH 02/22] Added member functions ready(), start() and clear() ready() and start() are just the begin() function split into two pieces. ready() does everything except start the ADC capture. clear() is calling the DMABufferPool routine to flush out anything in the DMA buffers. --- src/AdvancedADC.cpp | 116 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/src/AdvancedADC.cpp b/src/AdvancedADC.cpp index 49f7e23..52b3349 100644 --- a/src/AdvancedADC.cpp +++ b/src/AdvancedADC.cpp @@ -221,12 +221,128 @@ int AdvancedADC::begin(uint32_t resolution, uint32_t sample_rate, size_t n_sampl return 1; } +int AdvancedADC::ready(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers) { + ADCName instance = ADC_NP; + + // Sanity checks. + if (resolution >= AN_ARRAY_SIZE(ADC_RES_LUT) || (descr && descr->pool)) { + return 0; + } + + // Clear ALTx pin. + for (size_t i=0; ipool == nullptr) { + ADCName tmp_instance = (ADCName) pinmap_peripheral(pin, PinMap_ADC); + if (descr->adc.Instance == ((ADC_TypeDef*) tmp_instance)) { + instance = tmp_instance; + adc_pins[0] = pin; + } + } + } + } + + if (instance == ADC_NP) { + // Couldn't find a free ADC/descriptor. + descr = nullptr; + return 0; + } + + // Configure ADC pins. + pinmap_pinout(adc_pins[0], PinMap_ADC); + uint8_t ch_init = 1; + for (size_t i=1; ipool = new DMABufferPool(n_samples, n_channels, n_buffers); + if (descr->pool == nullptr) { + return 0; + } + + descr->dmabuf[0] = descr->pool->allocate(); + descr->dmabuf[1] = descr->pool->allocate(); + + + // Init and config DMA. + if (hal_dma_config(&descr->dma, descr->dma_irqn, DMA_PERIPH_TO_MEMORY) < 0) { + return 0; + } + + if (hal_adc_config(&descr->adc, ADC_RES_LUT[resolution], descr->tim_trig, adc_pins, n_channels) < 0) { + return 0; + } + + return(1); +} + +int AdvancedADC::start(uint32_t sample_rate) +{ + + // Link DMA handle to ADC handle, and start the ADC. + __HAL_LINKDMA(&descr->adc, DMA_Handle, descr->dma); + if (HAL_ADC_Start_DMA(&descr->adc, (uint32_t *) descr->dmabuf[0]->data(), descr->dmabuf[0]->size()) != HAL_OK) { + return 0; + } + + // Re/enable DMA double buffer mode. + hal_dma_enable_dbm(&descr->dma, descr->dmabuf[0]->data(), descr->dmabuf[1]->data()); + + // Init, config and start the ADC timer. + hal_tim_config(&descr->tim, sample_rate); + if (HAL_TIM_Base_Start(&descr->tim) != HAL_OK) { + return 0; + } + + return 1; +} + int AdvancedADC::stop() { dac_descr_deinit(descr, true); return 1; } +void AdvancedADC::clear() +{ + descr->pool->flush(); +} + AdvancedADC::~AdvancedADC() { dac_descr_deinit(descr, true); From d30bcea1cd979b4c7155dde2b1c45890a576149d Mon Sep 17 00:00:00 2001 From: jmdodd95682 <46497064+jmdodd95682@users.noreply.github.com> Date: Wed, 7 Feb 2024 10:07:56 -0800 Subject: [PATCH 03/22] Changed implementation to re-use begin() for backward compatibility Added bool noStart with default of false to allow backward compatibility with existing code. --- src/AdvancedADC.h | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/AdvancedADC.h b/src/AdvancedADC.h index 97f6e30..694a3f3 100644 --- a/src/AdvancedADC.h +++ b/src/AdvancedADC.h @@ -46,25 +46,17 @@ class AdvancedADC { ~AdvancedADC(); bool available(); SampleBuffer read(); - int begin(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers); - 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) { + int begin(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers, bool noStart); + 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, bool noStart=false) { if (n_pins > AN_MAX_ADC_CHANNELS) n_pins = AN_MAX_ADC_CHANNELS; for (size_t i = 0; i < n_pins; ++i) { adc_pins[i] = analogPinToPinName(pins[i]); } n_channels = n_pins; - return begin(resolution, sample_rate, n_samples, n_buffers); - } - void clear(); //clears any existing DMA buffers from read queue - int ready(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers); - int ready(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers, size_t n_pins, pin_size_t *pins) { - if (n_pins > AN_MAX_ADC_CHANNELS) n_pins = AN_MAX_ADC_CHANNELS; - for (size_t i = 0; i < n_pins; ++i) { - adc_pins[i] = analogPinToPinName(pins[i]); - } - n_channels = n_pins; - return ready(resolution, sample_rate, n_samples, n_buffers); + return begin(resolution, sample_rate, n_samples, n_buffers,noStart); } + void clear(); + int start(uint32_t sample_rate); int stop(); }; From 6e9040b9bdc9fe724d5a710404f2c4fa77861d5d Mon Sep 17 00:00:00 2001 From: jmdodd95682 <46497064+jmdodd95682@users.noreply.github.com> Date: Wed, 7 Feb 2024 10:10:22 -0800 Subject: [PATCH 04/22] Changed implementation to reuse begin() with option noStart --- src/AdvancedADC.cpp | 121 ++++---------------------------------------- 1 file changed, 11 insertions(+), 110 deletions(-) diff --git a/src/AdvancedADC.cpp b/src/AdvancedADC.cpp index 52b3349..d7e9b34 100644 --- a/src/AdvancedADC.cpp +++ b/src/AdvancedADC.cpp @@ -115,19 +115,19 @@ DMABuffer &AdvancedADC::read() { return NULLBUF; } -int AdvancedADC::begin(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers) { +int AdvancedADC::begin(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers,bool noStart=false) { + ADCName instance = ADC_NP; - // Sanity checks. if (resolution >= AN_ARRAY_SIZE(ADC_RES_LUT) || (descr && descr->pool)) { return 0; } - + // Clear ALTx pin. for (size_t i=0; ipool == nullptr) { return 0; } + descr->dmabuf[0] = descr->pool->allocate(); descr->dmabuf[1] = descr->pool->allocate(); + // Init and config DMA. if (hal_dma_config(&descr->dma, descr->dma_irqn, DMA_PERIPH_TO_MEMORY) < 0) { return 0; @@ -201,118 +203,17 @@ int AdvancedADC::begin(uint32_t resolution, uint32_t sample_rate, size_t n_sampl return 0; } - // Link DMA handle to ADC handle, and start the ADC. - __HAL_LINKDMA(&descr->adc, DMA_Handle, descr->dma); - if (HAL_ADC_Start_DMA(&descr->adc, (uint32_t *) descr->dmabuf[0]->data(), descr->dmabuf[0]->size()) != HAL_OK) { - return 0; + //if noStart is not set, proceed with starting ADC capture + if(!noStart) { + return(start(sample_rate)); } - // Re/enable DMA double buffer mode. - HAL_NVIC_DisableIRQ(descr->dma_irqn); - hal_dma_enable_dbm(&descr->dma, descr->dmabuf[0]->data(), descr->dmabuf[1]->data()); - HAL_NVIC_EnableIRQ(descr->dma_irqn); - - // Init, config and start the ADC timer. - hal_tim_config(&descr->tim, sample_rate); - if (HAL_TIM_Base_Start(&descr->tim) != HAL_OK) { - return 0; - } - return 1; } -int AdvancedADC::ready(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers) { - ADCName instance = ADC_NP; - - // Sanity checks. - if (resolution >= AN_ARRAY_SIZE(ADC_RES_LUT) || (descr && descr->pool)) { - return 0; - } - - // Clear ALTx pin. - for (size_t i=0; ipool == nullptr) { - ADCName tmp_instance = (ADCName) pinmap_peripheral(pin, PinMap_ADC); - if (descr->adc.Instance == ((ADC_TypeDef*) tmp_instance)) { - instance = tmp_instance; - adc_pins[0] = pin; - } - } - } - } - - if (instance == ADC_NP) { - // Couldn't find a free ADC/descriptor. - descr = nullptr; - return 0; - } - - // Configure ADC pins. - pinmap_pinout(adc_pins[0], PinMap_ADC); - uint8_t ch_init = 1; - for (size_t i=1; ipool = new DMABufferPool(n_samples, n_channels, n_buffers); - if (descr->pool == nullptr) { - return 0; - } - - descr->dmabuf[0] = descr->pool->allocate(); - descr->dmabuf[1] = descr->pool->allocate(); +int AdvancedADC::start(uint32_t sample_rate){ - - // Init and config DMA. - if (hal_dma_config(&descr->dma, descr->dma_irqn, DMA_PERIPH_TO_MEMORY) < 0) { - return 0; - } - - if (hal_adc_config(&descr->adc, ADC_RES_LUT[resolution], descr->tim_trig, adc_pins, n_channels) < 0) { - return 0; - } - - return(1); -} - -int AdvancedADC::start(uint32_t sample_rate) -{ + //This routine links adc and dma already setup via the begin() function, and then starts ADC capture timer // Link DMA handle to ADC handle, and start the ADC. __HAL_LINKDMA(&descr->adc, DMA_Handle, descr->dma); From 563bf02dcaee46e566baa8ffcddd18c99df69bea Mon Sep 17 00:00:00 2001 From: jmdodd95682 <46497064+jmdodd95682@users.noreply.github.com> Date: Wed, 7 Feb 2024 11:06:53 -0800 Subject: [PATCH 05/22] Fixed compile bug with defaulted parameters --- src/AdvancedADC.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AdvancedADC.cpp b/src/AdvancedADC.cpp index d7e9b34..333d42c 100644 --- a/src/AdvancedADC.cpp +++ b/src/AdvancedADC.cpp @@ -115,7 +115,7 @@ DMABuffer &AdvancedADC::read() { return NULLBUF; } -int AdvancedADC::begin(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers,bool noStart=false) { +int AdvancedADC::begin(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers,bool noStart) { ADCName instance = ADC_NP; // Sanity checks. From 13e9f0e9981e15b2aee6ebf8a60ee85c693d21f5 Mon Sep 17 00:00:00 2001 From: jmdodd95682 <46497064+jmdodd95682@users.noreply.github.com> Date: Wed, 7 Feb 2024 11:07:24 -0800 Subject: [PATCH 06/22] Fixed compile bug with defaulted parameters --- src/AdvancedADC.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AdvancedADC.h b/src/AdvancedADC.h index 694a3f3..8afe266 100644 --- a/src/AdvancedADC.h +++ b/src/AdvancedADC.h @@ -46,7 +46,7 @@ class AdvancedADC { ~AdvancedADC(); bool available(); SampleBuffer read(); - int begin(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers, bool noStart); + int begin(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers, bool noStart=false); 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, bool noStart=false) { if (n_pins > AN_MAX_ADC_CHANNELS) n_pins = AN_MAX_ADC_CHANNELS; for (size_t i = 0; i < n_pins; ++i) { From bf6113c421dbb8939a8946a21ec901e38d5befcd Mon Sep 17 00:00:00 2001 From: Leonardo Cavagnis <45899760+leonardocavagnis@users.noreply.github.com> Date: Thu, 8 Feb 2024 09:57:07 +0100 Subject: [PATCH 07/22] Update src/AdvancedADC.cpp Co-authored-by: Ibrahim Abdelkader --- src/AdvancedADC.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/AdvancedADC.cpp b/src/AdvancedADC.cpp index 333d42c..e2867c7 100644 --- a/src/AdvancedADC.cpp +++ b/src/AdvancedADC.cpp @@ -122,7 +122,6 @@ int AdvancedADC::begin(uint32_t resolution, uint32_t sample_rate, size_t n_sampl if (resolution >= AN_ARRAY_SIZE(ADC_RES_LUT) || (descr && descr->pool)) { return 0; } - // Clear ALTx pin. for (size_t i=0; i Date: Thu, 8 Feb 2024 09:57:15 +0100 Subject: [PATCH 08/22] Update src/AdvancedADC.cpp Co-authored-by: Ibrahim Abdelkader --- src/AdvancedADC.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AdvancedADC.cpp b/src/AdvancedADC.cpp index e2867c7..f221d08 100644 --- a/src/AdvancedADC.cpp +++ b/src/AdvancedADC.cpp @@ -115,7 +115,7 @@ DMABuffer &AdvancedADC::read() { return NULLBUF; } -int AdvancedADC::begin(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers,bool noStart) { +int AdvancedADC::begin(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers, bool start) { ADCName instance = ADC_NP; // Sanity checks. From 0a854f165fe216fa8b91b44bfb38c3d7c54086ec Mon Sep 17 00:00:00 2001 From: Leonardo Cavagnis <45899760+leonardocavagnis@users.noreply.github.com> Date: Thu, 8 Feb 2024 09:57:25 +0100 Subject: [PATCH 09/22] Update src/AdvancedADC.cpp Co-authored-by: Ibrahim Abdelkader --- src/AdvancedADC.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/AdvancedADC.cpp b/src/AdvancedADC.cpp index f221d08..e1e758d 100644 --- a/src/AdvancedADC.cpp +++ b/src/AdvancedADC.cpp @@ -202,9 +202,9 @@ int AdvancedADC::begin(uint32_t resolution, uint32_t sample_rate, size_t n_sampl return 0; } - //if noStart is not set, proceed with starting ADC capture - if(!noStart) { - return(start(sample_rate)); + // Start sampling immediately unless start==false. + if (start) { + return start(sample_rate); } return 1; From 1341867a58fe338681cc1b300fc3ae641cdc4689 Mon Sep 17 00:00:00 2001 From: Leonardo Cavagnis <45899760+leonardocavagnis@users.noreply.github.com> Date: Thu, 8 Feb 2024 09:57:34 +0100 Subject: [PATCH 10/22] Update src/AdvancedADC.cpp Co-authored-by: Ibrahim Abdelkader --- src/AdvancedADC.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/AdvancedADC.cpp b/src/AdvancedADC.cpp index e1e758d..71f3d0c 100644 --- a/src/AdvancedADC.cpp +++ b/src/AdvancedADC.cpp @@ -238,9 +238,10 @@ int AdvancedADC::stop() return 1; } -void AdvancedADC::clear() -{ - descr->pool->flush(); +void AdvancedADC::clear() { + if (descr && descr->pool) { + descr->pool->flush(); + } } AdvancedADC::~AdvancedADC() From 8cb517dc63e6fdadee10e051149390612b496dde Mon Sep 17 00:00:00 2001 From: Leonardo Cavagnis <45899760+leonardocavagnis@users.noreply.github.com> Date: Thu, 8 Feb 2024 09:57:42 +0100 Subject: [PATCH 11/22] Update src/AdvancedADC.h Co-authored-by: Ibrahim Abdelkader --- src/AdvancedADC.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AdvancedADC.h b/src/AdvancedADC.h index 8afe266..8f9967d 100644 --- a/src/AdvancedADC.h +++ b/src/AdvancedADC.h @@ -53,7 +53,7 @@ class AdvancedADC { adc_pins[i] = analogPinToPinName(pins[i]); } n_channels = n_pins; - return begin(resolution, sample_rate, n_samples, n_buffers,noStart); + return begin(resolution, sample_rate, n_samples, n_buffers, start); } void clear(); From db817ed27ced581cd0658ddb6f549f1bbdd5e77f Mon Sep 17 00:00:00 2001 From: Leonardo Cavagnis <45899760+leonardocavagnis@users.noreply.github.com> Date: Thu, 8 Feb 2024 09:57:48 +0100 Subject: [PATCH 12/22] Update src/AdvancedADC.h Co-authored-by: Ibrahim Abdelkader --- src/AdvancedADC.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/AdvancedADC.h b/src/AdvancedADC.h index 8f9967d..fc1431b 100644 --- a/src/AdvancedADC.h +++ b/src/AdvancedADC.h @@ -56,7 +56,6 @@ class AdvancedADC { return begin(resolution, sample_rate, n_samples, n_buffers, start); } void clear(); - int start(uint32_t sample_rate); int stop(); }; From 0d2b69c152cd8925f64205b94c842d4edde0ae24 Mon Sep 17 00:00:00 2001 From: Leonardo Cavagnis <45899760+leonardocavagnis@users.noreply.github.com> Date: Thu, 8 Feb 2024 09:58:05 +0100 Subject: [PATCH 13/22] Update src/AdvancedADC.cpp Co-authored-by: Ibrahim Abdelkader --- src/AdvancedADC.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/AdvancedADC.cpp b/src/AdvancedADC.cpp index 71f3d0c..8d3f0cd 100644 --- a/src/AdvancedADC.cpp +++ b/src/AdvancedADC.cpp @@ -210,10 +210,7 @@ int AdvancedADC::begin(uint32_t resolution, uint32_t sample_rate, size_t n_sampl return 1; } -int AdvancedADC::start(uint32_t sample_rate){ - - //This routine links adc and dma already setup via the begin() function, and then starts ADC capture timer - +int AdvancedADC::start(uint32_t sample_rate) { // Link DMA handle to ADC handle, and start the ADC. __HAL_LINKDMA(&descr->adc, DMA_Handle, descr->dma); if (HAL_ADC_Start_DMA(&descr->adc, (uint32_t *) descr->dmabuf[0]->data(), descr->dmabuf[0]->size()) != HAL_OK) { From d17986d3d2693813abd22a9d0268b0b86136b169 Mon Sep 17 00:00:00 2001 From: Leonardo Cavagnis <45899760+leonardocavagnis@users.noreply.github.com> Date: Thu, 8 Feb 2024 10:39:04 +0100 Subject: [PATCH 14/22] Update src/AdvancedADC.h --- src/AdvancedADC.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AdvancedADC.h b/src/AdvancedADC.h index fc1431b..d9d2acc 100644 --- a/src/AdvancedADC.h +++ b/src/AdvancedADC.h @@ -56,7 +56,7 @@ class AdvancedADC { return begin(resolution, sample_rate, n_samples, n_buffers, start); } void clear(); - int start(uint32_t sample_rate); + int start(); int stop(); }; From 4cbc4c409ad8d01fdd3efd8f9bf4de9cb7350cc6 Mon Sep 17 00:00:00 2001 From: Leonardo Cavagnis <45899760+leonardocavagnis@users.noreply.github.com> Date: Thu, 8 Feb 2024 10:39:12 +0100 Subject: [PATCH 15/22] Update src/AdvancedADC.cpp --- src/AdvancedADC.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/AdvancedADC.cpp b/src/AdvancedADC.cpp index 8d3f0cd..af02791 100644 --- a/src/AdvancedADC.cpp +++ b/src/AdvancedADC.cpp @@ -218,7 +218,9 @@ int AdvancedADC::start(uint32_t sample_rate) { } // Re/enable DMA double buffer mode. + HAL_NVIC_DisableIRQ(descr->dma_irqn); hal_dma_enable_dbm(&descr->dma, descr->dmabuf[0]->data(), descr->dmabuf[1]->data()); + HAL_NVIC_EnableIRQ(descr->dma_irqn); // Init, config and start the ADC timer. hal_tim_config(&descr->tim, sample_rate); From 9e461a0a952150f143667c876db936a5868a5274 Mon Sep 17 00:00:00 2001 From: Leonardo Cavagnis <45899760+leonardocavagnis@users.noreply.github.com> Date: Thu, 8 Feb 2024 10:39:24 +0100 Subject: [PATCH 16/22] Update src/AdvancedADC.cpp --- src/AdvancedADC.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AdvancedADC.cpp b/src/AdvancedADC.cpp index af02791..fdcbfbf 100644 --- a/src/AdvancedADC.cpp +++ b/src/AdvancedADC.cpp @@ -210,7 +210,7 @@ int AdvancedADC::begin(uint32_t resolution, uint32_t sample_rate, size_t n_sampl return 1; } -int AdvancedADC::start(uint32_t sample_rate) { +int AdvancedADC::start() { // Link DMA handle to ADC handle, and start the ADC. __HAL_LINKDMA(&descr->adc, DMA_Handle, descr->dma); if (HAL_ADC_Start_DMA(&descr->adc, (uint32_t *) descr->dmabuf[0]->data(), descr->dmabuf[0]->size()) != HAL_OK) { From 06a9cdb1e4b29725fa953e6cb9fb63c01ca0db84 Mon Sep 17 00:00:00 2001 From: Leonardo Cavagnis <45899760+leonardocavagnis@users.noreply.github.com> Date: Thu, 8 Feb 2024 10:39:32 +0100 Subject: [PATCH 17/22] Update src/AdvancedADC.cpp --- src/AdvancedADC.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/AdvancedADC.cpp b/src/AdvancedADC.cpp index fdcbfbf..739b887 100644 --- a/src/AdvancedADC.cpp +++ b/src/AdvancedADC.cpp @@ -202,9 +202,10 @@ int AdvancedADC::begin(uint32_t resolution, uint32_t sample_rate, size_t n_sampl return 0; } - // Start sampling immediately unless start==false. - if (start) { - return start(sample_rate); + sampling_rate = sample_rate; + // Start sampling immediately unless start_sampling==false. + if (start_sampling) { + return start(); } return 1; From 2c23027b3a337ffdbde6a0704ee059d4738ee1f1 Mon Sep 17 00:00:00 2001 From: Leonardo Cavagnis <45899760+leonardocavagnis@users.noreply.github.com> Date: Thu, 8 Feb 2024 10:39:43 +0100 Subject: [PATCH 18/22] Update src/AdvancedADC.cpp --- src/AdvancedADC.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/AdvancedADC.cpp b/src/AdvancedADC.cpp index 739b887..d73b934 100644 --- a/src/AdvancedADC.cpp +++ b/src/AdvancedADC.cpp @@ -116,7 +116,6 @@ DMABuffer &AdvancedADC::read() { } int AdvancedADC::begin(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers, bool start) { - ADCName instance = ADC_NP; // Sanity checks. if (resolution >= AN_ARRAY_SIZE(ADC_RES_LUT) || (descr && descr->pool)) { From 79e7ffc7fb64a1252669e7816b4ff3d864cd40b3 Mon Sep 17 00:00:00 2001 From: Leonardo Cavagnis <45899760+leonardocavagnis@users.noreply.github.com> Date: Thu, 8 Feb 2024 10:39:52 +0100 Subject: [PATCH 19/22] Update src/AdvancedADC.cpp --- src/AdvancedADC.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AdvancedADC.cpp b/src/AdvancedADC.cpp index d73b934..f79147c 100644 --- a/src/AdvancedADC.cpp +++ b/src/AdvancedADC.cpp @@ -115,7 +115,7 @@ DMABuffer &AdvancedADC::read() { return NULLBUF; } -int AdvancedADC::begin(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers, bool start) { +int AdvancedADC::begin(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers, bool start_sampling) { ADCName instance = ADC_NP; // Sanity checks. if (resolution >= AN_ARRAY_SIZE(ADC_RES_LUT) || (descr && descr->pool)) { From 1c457e927e9a5973adb5fe53c25e11d9f41b9c6d Mon Sep 17 00:00:00 2001 From: Leonardo Cavagnis <45899760+leonardocavagnis@users.noreply.github.com> Date: Thu, 8 Feb 2024 10:40:05 +0100 Subject: [PATCH 20/22] Update src/AdvancedADC.h --- src/AdvancedADC.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AdvancedADC.h b/src/AdvancedADC.h index d9d2acc..9120814 100644 --- a/src/AdvancedADC.h +++ b/src/AdvancedADC.h @@ -46,7 +46,7 @@ class AdvancedADC { ~AdvancedADC(); bool available(); SampleBuffer read(); - int begin(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers, bool noStart=false); + int begin(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers, bool start_sampling = true); 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, bool noStart=false) { if (n_pins > AN_MAX_ADC_CHANNELS) n_pins = AN_MAX_ADC_CHANNELS; for (size_t i = 0; i < n_pins; ++i) { From f27400e7d9906f48685d7a3fe7a4e6c90be2b41b Mon Sep 17 00:00:00 2001 From: Leonardo Cavagnis <45899760+leonardocavagnis@users.noreply.github.com> Date: Thu, 8 Feb 2024 10:40:12 +0100 Subject: [PATCH 21/22] Update src/AdvancedADC.h --- src/AdvancedADC.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AdvancedADC.h b/src/AdvancedADC.h index 9120814..8bf54fb 100644 --- a/src/AdvancedADC.h +++ b/src/AdvancedADC.h @@ -47,7 +47,7 @@ class AdvancedADC { bool available(); SampleBuffer read(); int begin(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers, bool start_sampling = true); - 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, bool noStart=false) { + 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, bool start_sampling = true) { if (n_pins > AN_MAX_ADC_CHANNELS) n_pins = AN_MAX_ADC_CHANNELS; for (size_t i = 0; i < n_pins; ++i) { adc_pins[i] = analogPinToPinName(pins[i]); From e988ee5aaf104d7b3d1500dfd8f78c39ca0bac95 Mon Sep 17 00:00:00 2001 From: Leonardo Cavagnis <45899760+leonardocavagnis@users.noreply.github.com> Date: Thu, 8 Feb 2024 10:40:36 +0100 Subject: [PATCH 22/22] Update src/AdvancedADC.h --- src/AdvancedADC.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AdvancedADC.h b/src/AdvancedADC.h index 8bf54fb..359c8f5 100644 --- a/src/AdvancedADC.h +++ b/src/AdvancedADC.h @@ -53,7 +53,7 @@ class AdvancedADC { adc_pins[i] = analogPinToPinName(pins[i]); } n_channels = n_pins; - return begin(resolution, sample_rate, n_samples, n_buffers, start); + return begin(resolution, sample_rate, n_samples, n_buffers, start_sampling); } void clear(); int start();