aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/timer/input_capture.rs
diff options
context:
space:
mode:
authormelvdl <[email protected]>2025-06-27 01:08:28 +0200
committermelvdl <[email protected]>2025-06-27 01:08:28 +0200
commit6f88c2c73caa63a6e534130f4a064cb95d3e9d7d (patch)
treefdddad93e4f48f32ff15a3b8ad6cd0ae12095fd4 /embassy-stm32/src/timer/input_capture.rs
parentcbd24bf2eece65a787fc085c255e9b2932ea73e3 (diff)
stm32: rename timer channel trait; replace impls via macro with impls generic over timer channels
Diffstat (limited to 'embassy-stm32/src/timer/input_capture.rs')
-rw-r--r--embassy-stm32/src/timer/input_capture.rs41
1 files changed, 18 insertions, 23 deletions
diff --git a/embassy-stm32/src/timer/input_capture.rs b/embassy-stm32/src/timer/input_capture.rs
index da567d504..49e22b10f 100644
--- a/embassy-stm32/src/timer/input_capture.rs
+++ b/embassy-stm32/src/timer/input_capture.rs
@@ -6,12 +6,12 @@ use core::pin::Pin;
6use core::task::{Context, Poll}; 6use core::task::{Context, Poll};
7 7
8use super::low_level::{CountingMode, FilterValue, InputCaptureMode, InputTISelection, Timer}; 8use super::low_level::{CountingMode, FilterValue, InputCaptureMode, InputTISelection, Timer};
9use super::{CaptureCompareInterruptHandler, GeneralInstance4Channel, TimerChannel, TimerPin}; 9use super::{CaptureCompareInterruptHandler, GeneralInstance4Channel, Channel, TimerPin};
10pub use super::{Ch1, Ch2, Ch3, Ch4}; 10pub use super::{Ch1, Ch2, Ch3, Ch4};
11use crate::gpio::{AfType, AnyPin, Pull}; 11use crate::gpio::{AfType, AnyPin, Pull};
12use crate::interrupt::typelevel::{Binding, Interrupt}; 12use crate::interrupt::typelevel::{Binding, Interrupt};
13use crate::time::Hertz; 13use crate::time::Hertz;
14use crate::timer::Channel; 14use crate::timer::TimerChannel;
15use crate::Peri; 15use crate::Peri;
16 16
17/// Capture pin wrapper. 17/// Capture pin wrapper.
@@ -21,7 +21,7 @@ pub struct CapturePin<'d, T, C> {
21 _pin: Peri<'d, AnyPin>, 21 _pin: Peri<'d, AnyPin>,
22 phantom: PhantomData<(T, C)>, 22 phantom: PhantomData<(T, C)>,
23} 23}
24impl<'d, T: GeneralInstance4Channel, C: Channel> CapturePin<'d, T, C> { 24impl<'d, T: GeneralInstance4Channel, C: TimerChannel> CapturePin<'d, T, C> {
25 /// Create a new capture pin instance. 25 /// Create a new capture pin instance.
26 pub fn new(pin: Peri<'d, impl TimerPin<T, C>>, pull: Pull) -> Self { 26 pub fn new(pin: Peri<'d, impl TimerPin<T, C>>, pull: Pull) -> Self {
27 pin.set_as_af(pin.af_num(), AfType::input(pull)); 27 pin.set_as_af(pin.af_num(), AfType::input(pull));
@@ -68,46 +68,41 @@ impl<'d, T: GeneralInstance4Channel> InputCapture<'d, T> {
68 } 68 }
69 69
70 /// Enable the given channel. 70 /// Enable the given channel.
71 pub fn enable(&mut self, channel: TimerChannel) { 71 pub fn enable(&mut self, channel: Channel) {
72 self.inner.enable_channel(channel, true); 72 self.inner.enable_channel(channel, true);
73 } 73 }
74 74
75 /// Disable the given channel. 75 /// Disable the given channel.
76 pub fn disable(&mut self, channel: TimerChannel) { 76 pub fn disable(&mut self, channel: Channel) {
77 self.inner.enable_channel(channel, false); 77 self.inner.enable_channel(channel, false);
78 } 78 }
79 79
80 /// Check whether given channel is enabled 80 /// Check whether given channel is enabled
81 pub fn is_enabled(&self, channel: TimerChannel) -> bool { 81 pub fn is_enabled(&self, channel: Channel) -> bool {
82 self.inner.get_channel_enable_state(channel) 82 self.inner.get_channel_enable_state(channel)
83 } 83 }
84 84
85 /// Set the input capture mode for a given channel. 85 /// Set the input capture mode for a given channel.
86 pub fn set_input_capture_mode(&mut self, channel: TimerChannel, mode: InputCaptureMode) { 86 pub fn set_input_capture_mode(&mut self, channel: Channel, mode: InputCaptureMode) {
87 self.inner.set_input_capture_mode(channel, mode); 87 self.inner.set_input_capture_mode(channel, mode);
88 } 88 }
89 89
90 /// Set input TI selection. 90 /// Set input TI selection.
91 pub fn set_input_ti_selection(&mut self, channel: TimerChannel, tisel: InputTISelection) { 91 pub fn set_input_ti_selection(&mut self, channel: Channel, tisel: InputTISelection) {
92 self.inner.set_input_ti_selection(channel, tisel) 92 self.inner.set_input_ti_selection(channel, tisel)
93 } 93 }
94 94
95 /// Get capture value for a channel. 95 /// Get capture value for a channel.
96 pub fn get_capture_value(&self, channel: TimerChannel) -> u32 { 96 pub fn get_capture_value(&self, channel: Channel) -> u32 {
97 self.inner.get_capture_value(channel) 97 self.inner.get_capture_value(channel)
98 } 98 }
99 99
100 /// Get input interrupt. 100 /// Get input interrupt.
101 pub fn get_input_interrupt(&self, channel: TimerChannel) -> bool { 101 pub fn get_input_interrupt(&self, channel: Channel) -> bool {
102 self.inner.get_input_interrupt(channel) 102 self.inner.get_input_interrupt(channel)
103 } 103 }
104 104
105 fn new_future( 105 fn new_future(&self, channel: Channel, mode: InputCaptureMode, tisel: InputTISelection) -> InputCaptureFuture<T> {
106 &self,
107 channel: TimerChannel,
108 mode: InputCaptureMode,
109 tisel: InputTISelection,
110 ) -> InputCaptureFuture<T> {
111 // Configuration steps from ST RM0390 (STM32F446) chapter 17.3.5 106 // Configuration steps from ST RM0390 (STM32F446) chapter 17.3.5
112 // or ST RM0008 (STM32F103) chapter 15.3.5 Input capture mode 107 // or ST RM0008 (STM32F103) chapter 15.3.5 Input capture mode
113 self.inner.set_input_ti_selection(channel, tisel); 108 self.inner.set_input_ti_selection(channel, tisel);
@@ -124,37 +119,37 @@ impl<'d, T: GeneralInstance4Channel> InputCapture<'d, T> {
124 } 119 }
125 120
126 /// Asynchronously wait until the pin sees a rising edge. 121 /// Asynchronously wait until the pin sees a rising edge.
127 pub async fn wait_for_rising_edge(&mut self, channel: TimerChannel) -> u32 { 122 pub async fn wait_for_rising_edge(&mut self, channel: Channel) -> u32 {
128 self.new_future(channel, InputCaptureMode::Rising, InputTISelection::Normal) 123 self.new_future(channel, InputCaptureMode::Rising, InputTISelection::Normal)
129 .await 124 .await
130 } 125 }
131 126
132 /// Asynchronously wait until the pin sees a falling edge. 127 /// Asynchronously wait until the pin sees a falling edge.
133 pub async fn wait_for_falling_edge(&mut self, channel: TimerChannel) -> u32 { 128 pub async fn wait_for_falling_edge(&mut self, channel: Channel) -> u32 {
134 self.new_future(channel, InputCaptureMode::Falling, InputTISelection::Normal) 129 self.new_future(channel, InputCaptureMode::Falling, InputTISelection::Normal)
135 .await 130 .await
136 } 131 }
137 132
138 /// Asynchronously wait until the pin sees any edge. 133 /// Asynchronously wait until the pin sees any edge.
139 pub async fn wait_for_any_edge(&mut self, channel: TimerChannel) -> u32 { 134 pub async fn wait_for_any_edge(&mut self, channel: Channel) -> u32 {
140 self.new_future(channel, InputCaptureMode::BothEdges, InputTISelection::Normal) 135 self.new_future(channel, InputCaptureMode::BothEdges, InputTISelection::Normal)
141 .await 136 .await
142 } 137 }
143 138
144 /// Asynchronously wait until the (alternate) pin sees a rising edge. 139 /// Asynchronously wait until the (alternate) pin sees a rising edge.
145 pub async fn wait_for_rising_edge_alternate(&mut self, channel: TimerChannel) -> u32 { 140 pub async fn wait_for_rising_edge_alternate(&mut self, channel: Channel) -> u32 {
146 self.new_future(channel, InputCaptureMode::Rising, InputTISelection::Alternate) 141 self.new_future(channel, InputCaptureMode::Rising, InputTISelection::Alternate)
147 .await 142 .await
148 } 143 }
149 144
150 /// Asynchronously wait until the (alternate) pin sees a falling edge. 145 /// Asynchronously wait until the (alternate) pin sees a falling edge.
151 pub async fn wait_for_falling_edge_alternate(&mut self, channel: TimerChannel) -> u32 { 146 pub async fn wait_for_falling_edge_alternate(&mut self, channel: Channel) -> u32 {
152 self.new_future(channel, InputCaptureMode::Falling, InputTISelection::Alternate) 147 self.new_future(channel, InputCaptureMode::Falling, InputTISelection::Alternate)
153 .await 148 .await
154 } 149 }
155 150
156 /// Asynchronously wait until the (alternate) pin sees any edge. 151 /// Asynchronously wait until the (alternate) pin sees any edge.
157 pub async fn wait_for_any_edge_alternate(&mut self, channel: TimerChannel) -> u32 { 152 pub async fn wait_for_any_edge_alternate(&mut self, channel: Channel) -> u32 {
158 self.new_future(channel, InputCaptureMode::BothEdges, InputTISelection::Alternate) 153 self.new_future(channel, InputCaptureMode::BothEdges, InputTISelection::Alternate)
159 .await 154 .await
160 } 155 }
@@ -162,7 +157,7 @@ impl<'d, T: GeneralInstance4Channel> InputCapture<'d, T> {
162 157
163#[must_use = "futures do nothing unless you `.await` or poll them"] 158#[must_use = "futures do nothing unless you `.await` or poll them"]
164struct InputCaptureFuture<T: GeneralInstance4Channel> { 159struct InputCaptureFuture<T: GeneralInstance4Channel> {
165 channel: TimerChannel, 160 channel: Channel,
166 phantom: PhantomData<T>, 161 phantom: PhantomData<T>,
167} 162}
168 163