Skip to content

Commit

Permalink
remove Lines
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Jan 7, 2025
1 parent 65e96ee commit 422772b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 33 deletions.
1 change: 1 addition & 0 deletions src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ macro_rules! split {
($(PwmChannelDisabled::<_, $C>::new(),)+)
}
}
#[cfg(not(feature = "gpio-f410"))]
impl SplitCapture for $TIM {
type CaptureChannels = ($(CaptureChannelDisabled<$TIM, $C>,)+);
fn split_capture() -> Self::CaptureChannels {
Expand Down
38 changes: 5 additions & 33 deletions src/timer/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! Timer::new(dp.TIM5, &clocks).capture_hz(24.MHz());
//! ```
//! In the `capture_hz` method, the desired timer counter frequency is specified.
//! For high accuracy, it is recommended to use 32-bit timers (TIM2, TIM5) and to select the highest possible frequency, ideally the maximum frequency equal to the timer's clock frequency.
//! For high accuracy, it is recommended to use 32-bit timers (TIM2, TIM5) and to select the highest possible frequency, ideally the maximum frequency equal to the timer's clock frequency.
//! This returns a `CaptureHzManager` and a tuple of all `CaptureChannel`s supported by the timer. Additionally, the [`CaptureExt`] trait is implemented for `pac::TIMx` to simplify the creation of a new structure.
//!
//! ```rust,ignore
Expand Down Expand Up @@ -102,32 +102,14 @@ where
self.tim.preload_capture(C, CaptureMode::InputCapture);
CaptureChannel {
tim: self.tim,
lines: CaptureLines::One(pin.into()),
}
}
}

#[derive(Debug)]
pub enum CaptureLines<P> {
One(P),
Two(P, P),
Three(P, P, P),
Four(P, P, P, P),
}
impl<P> CaptureLines<P> {
pub fn and(self, pin: P) -> Self {
match self {
Self::One(p) => Self::Two(p, pin),
Self::Two(p1, p2) => Self::Three(p1, p2, pin),
Self::Three(p1, p2, p3) => Self::Four(p1, p2, p3, pin),
Self::Four(_, _, _, _) => unreachable!(),
pin: pin.into(),
}
}
}

pub struct CaptureChannel<TIM: CPin<C>, const C: u8, const COMP: bool = false, Otype = PushPull> {
pub(super) tim: TIM,
lines: CaptureLines<TIM::Ch<Otype>>,
pin: TIM::Ch<Otype>,
// TODO: add complementary pins
}

Expand All @@ -137,9 +119,9 @@ impl<TIM: Instance + WithCapture + CPin<C>, const C: u8, const COMP: bool, Otype
pub const fn channel(&self) -> u8 {
C
}
pub fn release(mut self) -> (CaptureChannelDisabled<TIM, C>, CaptureLines<TIM::Ch<Otype>>) {
pub fn release(mut self) -> (CaptureChannelDisabled<TIM, C>, TIM::Ch<Otype>) {
self.disable();
(CaptureChannelDisabled { tim: self.tim }, self.lines)
(CaptureChannelDisabled { tim: self.tim }, self.pin)
}
pub fn erase(self) -> CaptureErasedChannel<TIM> {
CaptureErasedChannel {
Expand All @@ -156,16 +138,6 @@ impl<TIM: Instance + WithCapture + CPin<C>, const C: u8, const COMP: bool, Otype
self.tim.filter_capture(C, filter);
}
}
impl<TIM: Instance + CPin<C>, const C: u8, const COMP: bool, Otype>
CaptureChannel<TIM, C, COMP, Otype>
{
pub fn with(self, pin: impl Into<TIM::Ch<Otype>>) -> Self {
Self {
tim: self.tim,
lines: self.lines.and(pin.into()),
}
}
}

pub struct CaptureErasedChannel<TIM> {
_tim: TIM,
Expand Down

0 comments on commit 422772b

Please sign in to comment.