diff --git a/src/capture.rs b/src/capture.rs index 6156680ab4c9fa5bd292da8677bd4cf493434119..89c111ead9d1979106e43721fa9bf268e6816a3d 100644 --- a/src/capture.rs +++ b/src/capture.rs @@ -52,6 +52,18 @@ pub enum Error { _Extensible, } +/// Interrupt event +pub enum Event { + /// Capture on channel 1 + Capture1, + /// Capture on channel 2 + Capture2, + /// Capture on channel 3 + Capture3, + /// Capture on channel 4 + Capture4, +} + /// Input capture interface pub struct Capture<'a, T>(pub &'a T) where @@ -149,6 +161,30 @@ impl<'a> Capture<'a, TIM1> { ); } + /// Starts listening for an interrupt `event` + pub fn listen(&self, event: Event) { + let tim1 = self.0; + + match event { + Event::Capture1 => tim1.dier.modify(|_, w| w.cc1ie().set()), + Event::Capture2 => tim1.dier.modify(|_, w| w.cc2ie().set()), + Event::Capture3 => tim1.dier.modify(|_, w| w.cc3ie().set()), + Event::Capture4 => tim1.dier.modify(|_, w| w.cc4ie().set()), + } + } + + /// Stops listening for an interrupt `event` + pub fn unlisten(&self, event: Event) { + let tim1 = self.0; + + match event { + Event::Capture1 => tim1.dier.modify(|_, w| w.cc1ie().clear()), + Event::Capture2 => tim1.dier.modify(|_, w| w.cc2ie().clear()), + Event::Capture3 => tim1.dier.modify(|_, w| w.cc3ie().clear()), + Event::Capture4 => tim1.dier.modify(|_, w| w.cc4ie().clear()), + } + } + fn _set_resolution(&self, resolution: ::apb2::Ticks) { let psc = u16( resolution.0.checked_sub(1).expect("impossible resolution"), @@ -420,6 +456,30 @@ where ); } + /// Starts listening for an interrupt `event` + pub fn listen(&self, event: Event) { + let tim = self.0; + + match event { + Event::Capture1 => tim.dier.modify(|_, w| w.cc1ie().set()), + Event::Capture2 => tim.dier.modify(|_, w| w.cc2ie().set()), + Event::Capture3 => tim.dier.modify(|_, w| w.cc3ie().set()), + Event::Capture4 => tim.dier.modify(|_, w| w.cc4ie().set()), + } + } + + /// Stops listening for an interrupt `event` + pub fn unlisten(&self, event: Event) { + let tim = self.0; + + match event { + Event::Capture1 => tim.dier.modify(|_, w| w.cc1ie().clear()), + Event::Capture2 => tim.dier.modify(|_, w| w.cc2ie().clear()), + Event::Capture3 => tim.dier.modify(|_, w| w.cc3ie().clear()), + Event::Capture4 => tim.dier.modify(|_, w| w.cc4ie().clear()), + } + } + fn _set_resolution(&self, resolution: ::apb1::Ticks) { let psc = u16( resolution.0.checked_sub(1).expect("impossible resolution"),