Skip to content

Conversation

clubby789
Copy link
Contributor

@clubby789 clubby789 commented Jul 23, 2025

This moves the ADC and channel configuration code to a new public function prepare_read, then adds a read_without_preparing function which just starts a DMA transfer and starts conversion. This reduces wasted time reconfiguring the same channels repeatedly.

Tested on my STM32WB55RG

@clubby789
Copy link
Contributor Author

By the way, I didn't touch it because I was unsure if there was a good reason, but why is continuous conversion mode used if we stop the ADC after receiving the first conversion? Wouldn't it be simpler to just use single conversion mode?

}

/// Configure the ADC peripheral with the given channels for reading with DMA
pub async fn prepare_read(&mut self, sequence: impl ExactSizeIterator<Item = (&mut AnyAdcChannel<T>, SampleTime)>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to rename this method to configure_regular_sequence to make the distinction between regular and injected more clear.

/// defmt::info!("measurements: {}", measurements);
/// }
/// ```
pub async fn read_without_preparing(&mut self, rx_dma: Peri<'_, impl RxDma<T>>, readings: &mut [u16]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to rename this to something like "trigger_regular_conversion_and_await_result" (maybe a bit long but I think you get the point).

We may also want to think about how we can add support for non-software triggered ADC measurements in the future by setting the EXTEN bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants