aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/timer
diff options
context:
space:
mode:
authorxoviat <[email protected]>2025-12-16 18:32:00 +0000
committerGitHub <[email protected]>2025-12-16 18:32:00 +0000
commit4e3e4f44c29d6a5ef93d646b0ae4acc861f1f72e (patch)
treeb2edb2a88ecab33da066b8a1f4b1f6239e7fc817 /embassy-stm32/src/timer
parent9324af6f6a3872fc4ffa5e85a4f3b0a1fd6925b7 (diff)
parentc9a04b4b732b7a3b696eb8223664c1a7942b1875 (diff)
Merge pull request #4726 from RaulIQ/main
[embassy-stm32] add DMA-based input capture for timer channels
Diffstat (limited to 'embassy-stm32/src/timer')
-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"]