diff options
| author | Bruno Bousquet <[email protected]> | 2024-05-30 17:43:38 -0400 |
|---|---|---|
| committer | Bruno Bousquet <[email protected]> | 2024-05-30 17:43:53 -0400 |
| commit | 84707af5d7f3e62caafed06c416cf12fa82e4664 (patch) | |
| tree | 2f5a34ed76944338a5b6634f439df17637e1dba6 /embassy-stm32/src/timer/input_capture.rs | |
| parent | a87b33303403ba3601d0c631b9efe1cb3853c73b (diff) | |
create functions in inner to handle register modification
Diffstat (limited to 'embassy-stm32/src/timer/input_capture.rs')
| -rw-r--r-- | embassy-stm32/src/timer/input_capture.rs | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/embassy-stm32/src/timer/input_capture.rs b/embassy-stm32/src/timer/input_capture.rs index b3434ae63..8d1a77867 100644 --- a/embassy-stm32/src/timer/input_capture.rs +++ b/embassy-stm32/src/timer/input_capture.rs | |||
| @@ -7,7 +7,7 @@ use core::task::{Context, Poll}; | |||
| 7 | 7 | ||
| 8 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 8 | use embassy_hal_internal::{into_ref, PeripheralRef}; |
| 9 | 9 | ||
| 10 | use super::low_level::{CountingMode, InputCaptureMode, InputTISelection, Timer}; | 10 | use super::low_level::{CountingMode, FilterValue, InputCaptureMode, InputTISelection, Timer}; |
| 11 | use super::{ | 11 | use super::{ |
| 12 | CaptureCompareInterruptHandler, Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, | 12 | CaptureCompareInterruptHandler, Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, |
| 13 | GeneralInstance4Channel, | 13 | GeneralInstance4Channel, |
| @@ -40,11 +40,9 @@ macro_rules! channel_impl { | |||
| 40 | #[doc = concat!("Create a new ", stringify!($channel), " capture pin instance.")] | 40 | #[doc = concat!("Create a new ", stringify!($channel), " capture pin instance.")] |
| 41 | pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<T>> + 'd, pull_type: Pull) -> Self { | 41 | pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<T>> + 'd, pull_type: Pull) -> Self { |
| 42 | into_ref!(pin); | 42 | into_ref!(pin); |
| 43 | critical_section::with(|_| { | 43 | |
| 44 | pin.set_as_af_pull(pin.af_num(), AFType::Input, pull_type); | 44 | pin.set_as_af_pull(pin.af_num(), AFType::Input, pull_type); |
| 45 | #[cfg(gpio_v2)] | 45 | |
| 46 | pin.set_speed(crate::gpio::Speed::VeryHigh); | ||
| 47 | }); | ||
| 48 | CapturePin { | 46 | CapturePin { |
| 49 | _pin: pin.map_into(), | 47 | _pin: pin.map_into(), |
| 50 | phantom: PhantomData, | 48 | phantom: PhantomData, |
| @@ -130,8 +128,6 @@ impl<'d, T: GeneralInstance4Channel> InputCapture<'d, T> { | |||
| 130 | } | 128 | } |
| 131 | 129 | ||
| 132 | fn new_future(&self, channel: Channel, mode: InputCaptureMode, tisel: InputTISelection) -> InputCaptureFuture<T> { | 130 | fn new_future(&self, channel: Channel, mode: InputCaptureMode, tisel: InputTISelection) -> InputCaptureFuture<T> { |
| 133 | use stm32_metapac::timer::vals::FilterValue; | ||
| 134 | |||
| 135 | // Configuration steps from ST RM0390 (STM32F446) chapter 17.3.5 | 131 | // Configuration steps from ST RM0390 (STM32F446) chapter 17.3.5 |
| 136 | // or ST RM0008 (STM32F103) chapter 15.3.5 Input capture mode | 132 | // or ST RM0008 (STM32F103) chapter 15.3.5 Input capture mode |
| 137 | self.inner.set_input_ti_selection(channel, tisel); | 133 | self.inner.set_input_ti_selection(channel, tisel); |
| @@ -184,11 +180,6 @@ impl<'d, T: GeneralInstance4Channel> InputCapture<'d, T> { | |||
| 184 | } | 180 | } |
| 185 | } | 181 | } |
| 186 | 182 | ||
| 187 | /// Convert pointer to TIM instance to TimGp16 object | ||
| 188 | fn regs_gp16(ptr: *mut ()) -> crate::pac::timer::TimGp16 { | ||
| 189 | unsafe { crate::pac::timer::TimGp16::from_ptr(ptr) } | ||
| 190 | } | ||
| 191 | |||
| 192 | #[must_use = "futures do nothing unless you `.await` or poll them"] | 183 | #[must_use = "futures do nothing unless you `.await` or poll them"] |
| 193 | struct InputCaptureFuture<T: GeneralInstance4Channel> { | 184 | struct InputCaptureFuture<T: GeneralInstance4Channel> { |
| 194 | channel: Channel, | 185 | channel: Channel, |
| @@ -198,7 +189,7 @@ struct InputCaptureFuture<T: GeneralInstance4Channel> { | |||
| 198 | impl<T: GeneralInstance4Channel> Drop for InputCaptureFuture<T> { | 189 | impl<T: GeneralInstance4Channel> Drop for InputCaptureFuture<T> { |
| 199 | fn drop(&mut self) { | 190 | fn drop(&mut self) { |
| 200 | critical_section::with(|_| { | 191 | critical_section::with(|_| { |
| 201 | let regs = regs_gp16(T::regs()); | 192 | let regs = unsafe { crate::pac::timer::TimGp16::from_ptr(T::regs()) }; |
| 202 | 193 | ||
| 203 | // disable interrupt enable | 194 | // disable interrupt enable |
| 204 | regs.dier().modify(|w| w.set_ccie(self.channel.index(), false)); | 195 | regs.dier().modify(|w| w.set_ccie(self.channel.index(), false)); |
| @@ -212,7 +203,7 @@ impl<T: GeneralInstance4Channel> Future for InputCaptureFuture<T> { | |||
| 212 | fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | 203 | fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { |
| 213 | T::state().cc_waker[self.channel.index()].register(cx.waker()); | 204 | T::state().cc_waker[self.channel.index()].register(cx.waker()); |
| 214 | 205 | ||
| 215 | let regs = regs_gp16(T::regs()); | 206 | let regs = unsafe { crate::pac::timer::TimGp16::from_ptr(T::regs()) }; |
| 216 | 207 | ||
| 217 | let dier = regs.dier().read(); | 208 | let dier = regs.dier().read(); |
| 218 | if !dier.ccie(self.channel.index()) { | 209 | if !dier.ccie(self.channel.index()) { |
