aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-stm32')
-rw-r--r--embassy-stm32/src/timer/input_capture.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/embassy-stm32/src/timer/input_capture.rs b/embassy-stm32/src/timer/input_capture.rs
index 7a25e6c21..cbb4bb1d4 100644
--- a/embassy-stm32/src/timer/input_capture.rs
+++ b/embassy-stm32/src/timer/input_capture.rs
@@ -155,6 +155,44 @@ impl<'d, T: GeneralInstance4Channel> InputCapture<'d, T> {
155 self.new_future(channel, InputCaptureMode::BothEdges, InputTISelection::Alternate) 155 self.new_future(channel, InputCaptureMode::BothEdges, InputTISelection::Alternate)
156 .await 156 .await
157 } 157 }
158
159 /// Capture a sequence of timer input edges into a buffer using DMA
160 pub async fn receive_waveform<M>(&mut self, dma: Peri<'_, impl super::Dma<T, M>>, buf: &mut [u16])
161 where
162 M: TimerChannel,
163 {
164 #[allow(clippy::let_unit_value)] // eg. stm32f334
165 let req = dma.request();
166
167 let original_enable_state = self.is_enabled(M::CHANNEL);
168 let original_update_dma_state = self.inner.get_update_dma_state();
169
170 if !original_update_dma_state {
171 self.inner.enable_update_dma(true);
172 }
173
174 if !original_enable_state {
175 self.enable(M::CHANNEL);
176 }
177
178 unsafe {
179 use crate::dma::{Transfer, TransferOptions};
180
181 Transfer::new_read(
182 dma,
183 req,
184 self.inner.regs_1ch().ccr(M::CHANNEL.index()).as_ptr() as *mut u16,
185 buf,
186 TransferOptions::default(),
187 )
188 .await
189 };
190
191 // restore output compare state
192 if !original_enable_state {
193 self.disable(M::CHANNEL);
194 }
195 }
158} 196}
159 197
160#[must_use = "futures do nothing unless you `.await` or poll them"] 198#[must_use = "futures do nothing unless you `.await` or poll them"]