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 diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index e1bb5ff..7d112a2 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 @@ -49,8 +48,7 @@ jobs: libraries: | # Install the library from the local path. - source-path: ./ - - source-url: https://github.com/facchinm/USBHostMbed5.git - version: test_hs_in_fs + - name: Arduino_USBHostMbed5 sketch-paths: | - examples enable-deltas-report: true diff --git a/docs/api.md b/docs/api.md new file mode 100644 index 0000000..fa82b7e --- /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()` + + +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. + +#### 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 + +``` +adc.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()` + + +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. + +#### 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 +``` + 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); 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: 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 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..644f500 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; } @@ -182,6 +182,15 @@ int AdvancedDAC::stop() return 1; } +int AdvancedDAC::frequency(uint32_t const 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..da199a6 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 const frequency); }; #endif /* ARDUINO_ADVANCED_DAC_H_ */ 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() {