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