[stm32f4] [adc] feat: Add async single adc readings #3742
+71
−17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In contrast to the ADC implementations of other series, the STM32F4 series does not yet have an API definition for the asynchronous reading of a single channel. Instead, only the read_blocking() method was available.
In this PR, the API was extended to include an asynchronous read() method. Internal refactorings were also carried out in order to standardize the logic for setting registers and avoid redundant code. The implementation is based on the ADC implementations of other series in embassy_stm32/adc/.
The new method allows asynchronous single conversions to be performed and the ADC to be operated asynchronously in discontinuous mode. This is particularly useful for sporadic queries of an ADC channel, as the read() approach is simpler and more efficient than using a ring buffer DMA transfer.
In addition, the ADC example for the STM32F4 series has been updated. It now demonstrates the use of the read_blocking() method at the beginning and shows the asynchronous use with the new read() method in the infinite loop. This makes it easier to understand the interface and its practical use.