From 3764fb412505c5ace4f60ffc0c682809ce0b936f Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 1 Mar 2023 10:28:09 +0100 Subject: [PATCH 01/13] Change arduino-lint action to 'update', since the library has been added to the library index. (#25) --- .github/workflows/arduino-lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/arduino-lint.yml b/.github/workflows/arduino-lint.yml index 8141476..677b774 100644 --- a/.github/workflows/arduino-lint.yml +++ b/.github/workflows/arduino-lint.yml @@ -24,4 +24,4 @@ jobs: with: official: true project-type: library - library-manager: submit + library-manager: update From a0aa54428545825b622522623ce45d02f26a1166 Mon Sep 17 00:00:00 2001 From: Ibrahim Abdelkader Date: Fri, 3 Mar 2023 11:58:44 +0200 Subject: [PATCH 02/13] Fix library build for the M4 core. (#26) --- src/Arduino_AdvancedAnalog.h | 4 ---- src/DMABuffer.h | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Arduino_AdvancedAnalog.h b/src/Arduino_AdvancedAnalog.h index 6aec2b3..f654650 100644 --- a/src/Arduino_AdvancedAnalog.h +++ b/src/Arduino_AdvancedAnalog.h @@ -24,10 +24,6 @@ * INCLUDE **************************************************************************************/ -#ifdef ARDUINO_PORTENTA_H7_M4 -# error "This library only works on the M7 core of any STM32H747 based board (Portenta H7, Giga)." -#endif - #include "AdvancedADC.h" #include "AdvancedDAC.h" diff --git a/src/DMABuffer.h b/src/DMABuffer.h index ac85ccd..0f495df 100644 --- a/src/DMABuffer.h +++ b/src/DMABuffer.h @@ -92,15 +92,19 @@ template class DMABuffer { } void flush() { + #if __DCACHE_PRESENT if (ptr) { SCB_CleanDCache_by_Addr(data(), bytes()); } + #endif } void invalidate() { + #if __DCACHE_PRESENT if (ptr) { SCB_InvalidateDCache_by_Addr(data(), bytes()); } + #endif } uint32_t timestamp() { From 703d933cb76640cf4fe0fddd98f57929075a5d8c Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Fri, 3 Mar 2023 11:20:10 +0100 Subject: [PATCH 03/13] Update CI build: USBHostMbed5 branch test_hs_in_fs has been merged to master. (#27) https://github.com/facchinm/USBHostMbed5/pull/3 --- .github/workflows/compile-examples.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index e1bb5ff..f95eb24 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -50,7 +50,6 @@ jobs: # Install the library from the local path. - source-path: ./ - source-url: https://github.com/facchinm/USBHostMbed5.git - version: test_hs_in_fs sketch-paths: | - examples enable-deltas-report: true From ffaa7a1ecb3172c523d38eac317e22869d1a215d Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Fri, 3 Mar 2023 12:30:58 +0100 Subject: [PATCH 04/13] Ensure that begin() is not called multiple times. --- src/AdvancedADC.cpp | 2 +- src/AdvancedDAC.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AdvancedADC.cpp b/src/AdvancedADC.cpp index 9078be4..e01c894 100644 --- a/src/AdvancedADC.cpp +++ b/src/AdvancedADC.cpp @@ -117,7 +117,7 @@ int AdvancedADC::begin(uint32_t resolution, uint32_t sample_rate, size_t n_sampl ADCName instance = ADC_NP; // Sanity checks. - if (resolution >= AN_ARRAY_SIZE(ADC_RES_LUT)) { + if (resolution >= AN_ARRAY_SIZE(ADC_RES_LUT) || (descr && descr->pool)) { return 0; } diff --git a/src/AdvancedDAC.cpp b/src/AdvancedDAC.cpp index fc04461..443336f 100644 --- a/src/AdvancedDAC.cpp +++ b/src/AdvancedDAC.cpp @@ -135,7 +135,7 @@ void AdvancedDAC::write(DMABuffer &dmabuf) { int AdvancedDAC::begin(uint32_t resolution, uint32_t frequency, size_t n_samples, size_t n_buffers) { // Sanity checks. - if (resolution >= AN_ARRAY_SIZE(DAC_RES_LUT)) { + if (resolution >= AN_ARRAY_SIZE(DAC_RES_LUT) || (descr && descr->pool)) { return 0; } From 757c9932ab2687424223553c81f9c36b86f3374d Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Fri, 3 Mar 2023 12:37:09 +0100 Subject: [PATCH 05/13] Add function to change DAC frequency on the fly. --- src/AdvancedDAC.cpp | 9 +++++++++ src/AdvancedDAC.h | 1 + 2 files changed, 10 insertions(+) diff --git a/src/AdvancedDAC.cpp b/src/AdvancedDAC.cpp index fc04461..064a4e1 100644 --- a/src/AdvancedDAC.cpp +++ b/src/AdvancedDAC.cpp @@ -182,6 +182,15 @@ int AdvancedDAC::stop() return 1; } +int AdvancedDAC::frequency(uint32_t frequency) +{ + if (descr && descr->pool) { + // Reconfigure the trigger timer. + dac_descr_deinit(descr, false); + hal_tim_config(&descr->tim, frequency); + } +} + AdvancedDAC::~AdvancedDAC() { dac_descr_deinit(descr, true); diff --git a/src/AdvancedDAC.h b/src/AdvancedDAC.h index 57707ee..bdba295 100644 --- a/src/AdvancedDAC.h +++ b/src/AdvancedDAC.h @@ -49,6 +49,7 @@ class AdvancedDAC { void write(SampleBuffer dmabuf); int begin(uint32_t resolution, uint32_t frequency, size_t n_samples=0, size_t n_buffers=0); int stop(); + int frequency(uint32_t frequency); }; #endif /* ARDUINO_ADVANCED_DAC_H_ */ From 0ab56386e918681b818a6b7e124fc30168bd9ad1 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Fri, 3 Mar 2023 12:37:34 +0100 Subject: [PATCH 06/13] Waveform_Generator: Use the new function to change DAC frequency. --- .../Beginner/Waveform_Generator/Waveform_Generator.ino | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/examples/Beginner/Waveform_Generator/Waveform_Generator.ino b/examples/Beginner/Waveform_Generator/Waveform_Generator.ino index 2f8dc89..5ba5494 100644 --- a/examples/Beginner/Waveform_Generator/Waveform_Generator.ino +++ b/examples/Beginner/Waveform_Generator/Waveform_Generator.ino @@ -55,13 +55,9 @@ void generate_waveform(int cmd) } else { break; } - - dac1.stop(); - delay(500); - if (!dac1.begin(AN_RESOLUTION_8, dac_frequency * N_SAMPLES, N_SAMPLES, 32)) { - Serial.println("Failed to start DAC1 !"); - } - delay(500); + + // Change frequency. + dac1.frequency(dac_frequency * N_SAMPLES); break; default: From 20da84ec1dbdd990e4d9ab002467901ed6f0e2cb Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Mon, 6 Mar 2023 11:34:37 +0100 Subject: [PATCH 07/13] AdvancedDAC: Make frequency const. --- src/AdvancedDAC.cpp | 2 +- src/AdvancedDAC.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AdvancedDAC.cpp b/src/AdvancedDAC.cpp index 064a4e1..3277158 100644 --- a/src/AdvancedDAC.cpp +++ b/src/AdvancedDAC.cpp @@ -182,7 +182,7 @@ int AdvancedDAC::stop() return 1; } -int AdvancedDAC::frequency(uint32_t frequency) +int AdvancedDAC::frequency(uint32_t const frequency) { if (descr && descr->pool) { // Reconfigure the trigger timer. diff --git a/src/AdvancedDAC.h b/src/AdvancedDAC.h index bdba295..da199a6 100644 --- a/src/AdvancedDAC.h +++ b/src/AdvancedDAC.h @@ -49,7 +49,7 @@ class AdvancedDAC { void write(SampleBuffer dmabuf); int begin(uint32_t resolution, uint32_t frequency, size_t n_samples=0, size_t n_buffers=0); int stop(); - int frequency(uint32_t frequency); + int frequency(uint32_t const frequency); }; #endif /* ARDUINO_ADVANCED_DAC_H_ */ From 96afb18e32888c12bbe400e4c8504a67b704f6d3 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 7 Mar 2023 15:12:12 +0100 Subject: [PATCH 08/13] Fix: Use latest officially released mbed_giga core for CI build. (#30) --- .github/workflows/compile-examples.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index f95eb24..4c15e24 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -34,7 +34,6 @@ jobs: - fqbn: arduino:mbed_giga:giga platforms: | - name: arduino:mbed_giga - source-url: https://downloads.arduino.cc/packages/package_mbed_index.json steps: - name: Checkout repository From 0b717286f2809133a24513ae2676a33aa7068e6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20S=C3=B6derby?= <35461661+karlsoderby@users.noreply.github.com> Date: Tue, 21 Mar 2023 15:08:31 +0100 Subject: [PATCH 09/13] Add Documentation Add docs for the ArduinoAdvanced library, including: - DAC class - ADC class - SampleBuffer class --- docs/api.md | 403 +++++++++++++++++++++++++++++++++++++++++++++++++ docs/readme.md | 12 ++ 2 files changed, 415 insertions(+) create mode 100644 docs/api.md create mode 100644 docs/readme.md diff --git a/docs/api.md b/docs/api.md new file mode 100644 index 0000000..a67bf97 --- /dev/null +++ b/docs/api.md @@ -0,0 +1,403 @@ +# Arduino Advanced Analog Library + +## AdvancedADC + +### `AdvancedADC` + +Creates an object associated to a specific pin. + +#### Syntax + +``` +AdvancedADC adc(analogPin); +``` + +#### Parameters + +- Pin `A0` through `A11` can be associated. + +#### Returns + +Nothing. + +### `begin()` + + +Initialises the DAC with the specific parameters. The `begin()` method is firstly used to initialize the library. + +If reconfigured during program execution, use `stop()` first. + +#### Syntax + +``` +adc0.begin(resolution, sample_rate, n_samples, n_buffers) +``` + +#### Parameters + +- `enum` - resolution (choose from 8, 10, 12, 14, 16 bit) + - `AN_RESOLUTION_8` + - `AN_RESOLUTION_10` + - `AN_RESOLUTION_12` + - `AN_RESOLUTION_14` + - `AN_RESOLUTION_16` +- `int` - frequency +- `int` - n_samples +- `int` - n_buffers + +#### Returns + +1 on success, 0 on failure. + +### `available()` + +Bool to check if there's any available data on the ADC channel. + +#### Syntax + +``` +if(adc0.available()){} +``` + +#### Parameters + +None. + +#### Returns + +1 on success, 0 on failure. + +### `read()` + +Reads the first available byte in the buffer. + +### `stop()` + +Stops the ADC and buffer transfer, and releases any memory allocated for the buffer array. + +#### Syntax + +``` +dac.stop() +``` + +#### Returns + +- `1` + +## AdvancedDAC + +### `AdvancedDAC` + + +Creates a DAC object on a specific pin. + +#### Syntax + +``` +AdvancedDAC dac0(A12); +AdvancedDAC dac1(A13); +``` + +#### Parameters + +- `A12` or `A13` (DAC0 or DAC1 channels). + +#### Returns + +Nothing. + +### `begin()` + + +Initialises the DAC with the specific parameters. The `begin()` method is firstly used to initialize the library. + +If reconfigured during program execution, use `stop()` first. + +#### Syntax + +``` +dac0.begin(resolution, frequency, n_samples, n_buffers) +``` + +#### Parameters + +- `enum` - resolution (choose from 8, 10, 12 bit) + - `AN_RESOLUTION_8` + - `AN_RESOLUTION_10` + - `AN_RESOLUTION_12` +- `int` - frequency +- `int` - n_samples +- `int` - n_buffers + +#### Returns + +1 on success, 0 on failure. + +### `available()` + +Checks if the DAC channel is available to write to. + +#### Syntax + +``` +if(dac0.available()){} +``` + +#### Parameters + +None. + +#### Returns + +1 on success, 0 on failure. + + +### `dequeue()` + + +Creates a buffer object and waits until a buffer to become available. + +#### Syntax + +``` +SampleBuffer buf = dac.dequeue(); + +for (size_t i=0; i +``` + From e7edcdd49c27a7b8328bcf56370f41d692a2c8e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20S=C3=B6derby?= <35461661+karlsoderby@users.noreply.github.com> Date: Tue, 21 Mar 2023 15:13:23 +0100 Subject: [PATCH 10/13] spellchk + fix typos --- docs/api.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/api.md b/docs/api.md index a67bf97..fa82b7e 100644 --- a/docs/api.md +++ b/docs/api.md @@ -23,7 +23,7 @@ Nothing. ### `begin()` -Initialises the DAC with the specific parameters. The `begin()` method is firstly used to initialize the library. +Initializes the ADC with the specific parameters. The `begin()` method is firstly used to initialize the library. If reconfigured during program execution, use `stop()` first. @@ -78,7 +78,7 @@ Stops the ADC and buffer transfer, and releases any memory allocated for the buf #### Syntax ``` -dac.stop() +adc.stop() ``` #### Returns @@ -110,7 +110,7 @@ Nothing. ### `begin()` -Initialises the DAC with the specific parameters. The `begin()` method is firstly used to initialize the library. +Initializes the DAC with the specific parameters. The `begin()` method is firstly used to initialize the library. If reconfigured during program execution, use `stop()` first. From f5354392febfa0f730b644d1a76110d70b82de97 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 29 Mar 2023 09:35:49 +0200 Subject: [PATCH 11/13] CI: Fix name of build dependency USBHostMbed5. It's now Arduino_USBHostMbed5, due to renaming the library to be consistent with Arduino library naming. --- .github/workflows/compile-examples.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 4c15e24..7d112a2 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -48,7 +48,7 @@ jobs: libraries: | # Install the library from the local path. - source-path: ./ - - source-url: https://github.com/facchinm/USBHostMbed5.git + - name: Arduino_USBHostMbed5 sketch-paths: | - examples enable-deltas-report: true From 3107fcb4a6cf681c6638f20d20271fa8bf5c3861 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 29 Mar 2023 09:43:26 +0200 Subject: [PATCH 12/13] Fix: rename header include file. --- examples/Beginner/Audio_Playback/Audio_Playback.ino | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/Beginner/Audio_Playback/Audio_Playback.ino b/examples/Beginner/Audio_Playback/Audio_Playback.ino index a860e43..72fcc75 100644 --- a/examples/Beginner/Audio_Playback/Audio_Playback.ino +++ b/examples/Beginner/Audio_Playback/Audio_Playback.ino @@ -6,8 +6,10 @@ */ #include + +#include + #include -#include #include AdvancedDAC dac1(A12); From 80eeb61669f8c45105b973f8b400bb44de80db21 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 29 Mar 2023 09:49:31 +0200 Subject: [PATCH 13/13] Release v1.1.0. --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 7f5ced9..86894c7 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_AdvancedAnalog -version=1.0.0 +version=1.1.0 author=Arduino maintainer=Arduino sentence=Advanced analog functionalities for STM32H7 boards